shared memory + mmap problem
shared memory + mmap problem
- Subject: shared memory + mmap problem
- From: Michael Heins <email@hidden>
- Date: Fri, 21 Jan 2005 14:57:14 -0700
I'm having trouble on my 10.3.7 system mapping more than 1 page of
memory. Below is my little command line test program that illustrates
the problem. I run it like this: prog abc 4096, where "abc" is the
shared memory segment name, and 4096 is the segment size in bytes.
On my system, the mmap succeeds for sizes between 1-4096 and fails for
sizes above 4096. Is this a known bug in Darwin? Am I overlooking a
problem in my code?
Thanks.
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
//
// Run with two arguments, the name of the shared memory segment, and
the size.
//
int
main( int argc, char **argv)
{
char *id = argv[1], *buf;
int fd, size = atoi( argv[2]);
if ((fd = shm_open( id, O_RDWR | O_CREAT, 0666)) == -1) {
perror( "shm_open");
return -1;
}
ftruncate( fd, size); // ignore return status
buf = mmap( 0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if ((int)buf == -1) {
perror( "mmap");
} else {
printf( "mmap returned %x\n", buf);
munmap( buf, size);
}
shm_unlink( id);
return 0;
}
Michael Heins AA7XY
_______________________________________________
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