lkml.org 
[lkml]   [1998]   [Jan]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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.

\
 
 \ /
  Last update: 2005-03-22 13:41    [W:0.036 / U:1.228 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site