site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Importance: Normal Hi, I'm trying to make some processes share a quite large block of memory (~8MB). I started using shmget(). It worked well for files ~800KB but not for 8MB. So I moved to shm_open() and mmap(), and now I can't allocate more than a single page of memory, 4096 bytes !! This code shows the problem: #include <stdio.h> #include <errno.h> #include <sys/mman.h> #include <fcntl.h> int main(int argc, char *argv[]) { int err,fd; size_t len=4096; char *shm; fd=shm_open("/1234",O_CREAT|O_RDWR|O_EXCL,0666); if(fd<0) printf ("shm_open() failed: %s\n",strerror(errno)); err=ftruncate(fd,len); if(err<0) printf("ftruncate() failed: %s \n",strerror(errno)); shm=mmap(NULL,len,PROT_READ|PROT_WRITE,MAP_SHARED,fd,(off_t)0); if (shm==(char*)-1) printf("mmap() failed: %s\n",strerror(errno)); err=munmap(shm,len); if(err<0) printf("munmap() failed: %s \n",strerror(errno)); err=shm_unlink("/1234"); if(err<0) printf("shm_unlink() failed: %s \n",strerror(errno)); err=close(fd); if(err<0) printf("clos() failed: %s\n",strerror(errno)); return 0; } I've compiled that in a PB G4 and in a G5 (both 10.4.5, gcc 4.0.0), and it fails at mmap() with and "Invalid argument" error, but if I change sz from 4097 to 4096, it works! Yet, if I read the man page for mmap it says: "The mmap function causes the pages starting at addr [the first argument: NULL] and continuing for at most len bytes to be mapped from the object described by fd, starting at byte offset offset. If offset or len is not a multiple of the pagesize, the mapped region may extend past the specified range." So, it *may* extend beyond one single page.... One year ago someone asked a quite similar question in this list ("shm_open and mmap: Invalid argument", Feb 2005), but the answer there should have the same problem of page-size limit. But I haven't found anything about a 1 page limit nor in google nor in the man pages of shm_open/ftruncate/ mmap (I didn't find for shmget/shmat neither)... there's something that I'm not understanding... Any help/hint/code-snippet will be *very* appreciated. Thank you, Roberto _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com
participants (1)
-
Roberto Toro