home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / programm / 6067 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.7 KB  |  65 lines

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