[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug hurd/19903] New: Shared mappings not being inherited by children pr
From: |
avarzille at riseup dot net |
Subject: |
[Bug hurd/19903] New: Shared mappings not being inherited by children processes |
Date: |
Mon, 04 Apr 2016 01:31:54 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=19903
Bug ID: 19903
Summary: Shared mappings not being inherited by children
processes
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: hurd
Assignee: unassigned at sourceware dot org
Reporter: avarzille at riseup dot net
CC: bug-hurd at gnu dot org, roland at gnu dot org,
tschwinge at sourceware dot org
Target Milestone: ---
Hello, everyone.
It appears that in GNU/Hurd, memory mappings obtained by 'mmap' with MAP_SHARED
and MAP_ANON as its flags are not being inherited by children processes.
Here's a simple program that illustrates the issue:
===============================
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/wait.h>
int main (void)
{
void *p = mmap (0, 4096, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANON, -1, 0);
if (p == MAP_FAILED)
{
puts ("mmap failed.");
return (1);
}
int pid = fork ();
if (pid < 0)
{
puts ("fork failed.");
return (1);
}
else if (pid == 0)
{
*(int *)p = 69;
puts ("value was set.");
}
else
{
int r;
wait (&r);
printf ("done waiting for the child"
"\nvalue is: %d\n", *(int *)p);
}
return (0);
}
==================================
The parent process ends up printing zero, which is wrong.
A quick inspection at the source code tells me that this code ends up calling
'vm_allocate' as an optimization when it sees that the user requested an
anonymous mapping with protection RW. However, it's not taking into account
that 'vm_allocate' has a default inheritance value of 'COPY'.
An easy workaround is to simply remove the 'vm_allocate' optimization, and
always use 'vm_map' by removing the
if ((flags & (MAP_TYPE|MAP_INHERIT)) == MAP_ANON
block.
--
You are receiving this mail because:
You are on the CC list for the bug.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug hurd/19903] New: Shared mappings not being inherited by children processes,
avarzille at riseup dot net <=