Messages in this thread | | | Date | Fri, 9 Jan 1998 14:49:19 -0500 | From | Jim Nance <> | Subject | Re: [test patch] dirty shared mappings |
| |
> And I thought that _everything_ shared the same page pool with no > protection checks (ie different processes that aren't related would get > the same shared pages). > > But if the above only gets a "private" shared memory area (ie only passed > down as a shared memory area through fork(), not accessible through other > unrelated processes doing the same mmap()), then it is not as braindamaged > as I thought it was.
I think only children can get it. To test this I wrote the test program which is appended to the end of this email.
When I run it under Digital Unix I get:
ptr contains the string ""
Which indicates that other processes can not get to your anonymous shared memory.
#include <stdlib.h> #include <stdio.h> #include <sys/mman.h>
int main(void) { int perms = PROT_READ|PROT_WRITE; int flags = MAP_SHARED | MAP_ANONYMOUS; int fd[2]; void *ptr; char emp[8];
pipe(fd);
if(fork()) { close(fd[0]); ptr = mmap(0, 8192, perms, flags, -1, 0); strcpy(ptr, "I am shared"); close(fd[1]); } else { close(fd[1]); ptr = mmap(0, 8192, perms, flags, -1, 0); read(fd[0], emp, sizeof(emp)); printf("ptr contains the string \"%s\" \n", ptr); } return 0; }
-- ---------------------------------------------------------------------------- Jim Nance Avant! Corporation (919) 941-6655 Do you have sweet iced tea? jim_nance@avanticorp.com No, but theres sugar on the table.
| |