shm_open + mmap?
shm_open + mmap?
- Subject: shm_open + mmap?
- From: Brad Parker <email@hidden>
- Date: Thu, 24 Nov 2005 20:30:25 -0500
- Organization: Heeltoe Consulting
Can anyone explain why this doesn't work on darwin?
I want to create shared memory space which two processes can access.
The shm_open works but the mmap fails. I can't figure out why (but have
not looked at the sources yet)
I've tried all manner of mprot and mflags. I did find the mmap would
work if I used "open" instead of "shm_open" *and* the file size was >=
the mmap size.
The code below always fails at the mmap. I thought shm_open + mmap would
work on os 10.4...
int
shared_fb_init(void)
{
int ret, shm_fd, mprot, mflags, ps;
size_t size;
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_filename);
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;
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(shm_filename);
return -1;
}
...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden