site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com On Nov 24, 2005, at 6:35 PM, Brad Parker wrote: You must first increase the length of the file by one means or another. shm_open creates a 0-length file. Are you calling ftruncate() with the size you are passing in to mmap()? This seems to work: #include <stdio.h> #include <sys/file.h> #include <sys/mman.h> static const char *shm_filename = "/tmp/flarm"; #define MAX_BITMAP_OFFSET 8192 int main(void) { int ret, shm_fd, mprot, mflags, ps; size_t size; void *shm_fb; ret = shm_unlink(shm_filename); printf("shm_unlink ret %d\n", ret); shm_fd = shm_open(shm_filename, O_RDWR | O_CREAT, 0666); if (shm_fd < 0) { perror("shm_open"); return 1; } size = MAX_BITMAP_OFFSET*4; mprot = PROT_READ|PROT_WRITE; mflags = MAP_FILE|MAP_SHARED; ps = getpagesize(); printf("pagesize %d\n", ps); size = ((size+ps-1)/ps) * ps; if (ftruncate(shm_fd, size) < 0) { perror("ftruncate"); return 1; } printf("shm_fd %d, size %d\n", shm_fd, size); shm_fb = mmap(NULL, size, mprot, mflags, shm_fd, (off_t)0); if (shm_fb == (void *)-1) { fprintf(stderr, "mmap of %s failed\n", shm_filename); perror("mmap"); return 1; } printf("shm_fb = %p\n", shm_fb); return 0; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Solra Bizna wrote: I tried that using ftruncate and it's didn't help. This email sent to site_archiver@lists.apple.com
participants (1)
-
Matt Watson