home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20283 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.6 KB  |  64 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!UB.com!pacbell.com!sgiblab!munnari.oz.au!metro!usage!spectrum!roy
  3. From: roy@spectrum.cs.unsw.oz.au (Prabal Kumar Roy)
  4. Subject: =======Problem with mmap command on DECStation========
  5. Message-ID: <1993Jan27.065349.27873@usage.csd.unsw.OZ.AU>
  6. Sender: news@usage.csd.unsw.OZ.AU
  7. Nntp-Posting-Host: sorrel.spectrum.cs.unsw.oz.au
  8. Reply-To: roy@spectrum.cs.unsw.oz.au (Prabal Kumar Roy)
  9. Organization: none
  10. Date: Wed, 27 Jan 1993 06:53:49 GMT
  11. Lines: 51
  12.  
  13.  Greetings:
  14.  
  15.   I am trying to use the mmap command on DECStation 5000.  In the following test 
  16. program I am trying to reserve 1000 bytes of memory and trying to write some stuff
  17. in that area.
  18.  
  19. However, at the statement    *intptr = 1; I am getting the following error.
  20. pid 10810 (a.out) was killed on kernel access, at pc 0x400284.  Bus error (core 
  21. dumped).  
  22.  
  23. So the statement result = (caddr_t) mmap(0,..............) has got me some
  24. memory which is in the kernel area, so when I am trying to access it later I am 
  25. getting a core dump.  Any help will be greatly appreciated.
  26.  
  27. Prabal K. Roy
  28. AI Lab
  29. U. of New South Wales
  30. Sydney 2033
  31. AUSTRALIA
  32. ----------
  33.  
  34. #include <sys/types.h>
  35. #include <stdio.h>
  36. #include <sys/stat.h>
  37. #include <sys/mman.h>
  38. #include <fcntl.h>
  39. #include <string.h>
  40. #include <limits.h>
  41. #define PERMS 0666
  42. #define TRUE 1
  43. #define FALSE 0
  44.  
  45. main ()
  46. {
  47.   int fd;
  48.   caddr_t result;
  49.   int *intptr;
  50.   char *charptr;
  51.  
  52.   fd = creat("myfile", PERMS);
  53.  
  54.   result = (caddr_t) mmap(0, 1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  55.   close(fd);
  56.  
  57.   intptr = (int *) result;
  58.   *intptr = 1;
  59.   result = result + sizeof(int);
  60.   charptr = (char *) result;
  61.   strcpy(charptr, "hello world");
  62.  
  63. }
  64.