This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fork fails after nmap with hint address in an unmapped memory region

On 2017-12-09 11:29, Brian Inglis wrote:
> On 2017-12-09 08:53, Stéphane Mbape via cygwin wrote:
>> Le 09/12/2017 à 16:48, Andrey Repin a écrit :
>>>> While embeding luajit in a c  program, I found myself unable to fork
>>>> processes.
>>>> Investigations prove that it was related to nmap.
>>>> To be accurate, calling nmap with hint address in a unmapped memory
>>>> region will cause all forks to fail with
>>>> "fixup_mmaps_after_fork: ReadProcessMemory failed for MAP_PRIVATE
>>>> address 0x6FFFFFE0000, Win32 error 299"
>>>> There is a sample code below.
>>> You forgot to mention Cygwin version you're using, and please provide the
>>> sample as an attach to save people the copy-pasting issues.
>> Cygwin version: 2.9.0
>> OS: Windows 10
>> Arch: 64bit
>> The sample was also attached.
> Confirmed reproducible; addr2line does not give anything useful from the
> stackdump, but included raw stackdump below, in case it gives hints.
> Complete output after renaming doscript.c to mmap_fork_stc.c, also with addr +
> 4096 as well as addr + 1:
> $ gcc -g -O0 -o mmap_fork_stc{,.c}
> $ ./mmap_fork_stc
> I am master 5464
> nmap() = 0x6fffffe0000, hint_addr = 0x0
> nmap() = 0x6fffffe0000, hint_addr = 0x6fffffe1000
>       1 [main] mmap_fork_stc 11408 fixup_mmaps_after_fork: ReadProcessMemory
> failed for MAP_PRIVATE address 0x6FFFFFE0000, Win32 error 299
>     286 [main] mmap_fork_stc 11408 ...\mmap_fork_stc.exe: *** fatal error in
> forked process - recreate_mmaps_after_fork_failed
>    1298 [main] mmap_fork_stc 11408 cygwin_exception::open_stackdumpfile: Dumping
> stack trace to mmap_fork_stc.exe.stackdump
>       0 [main] mmap_fork_stc 5464 fork: child -1 - forked process 11408 died
> unexpectedly, retry 0, exit code 0x100, errno 11
> fork failed: Resource temporarily unavailable
> master exiting

Test works if you use addr + 65536 or addr + sysconf(_SC_PAGE_SIZE), as another
thread reminded me about mmap region alignment to 64KB boundaries.

$ ./mmap_fork_stc
I am master 1888
nmap() = 0x6fffffe0000, hint_addr = 0x0
nmap() = 0x6ffffff0000, hint_addr = 0x6ffffff0000
I am worker 5168
worker exiting
master exiting

Perhaps mmap() should round up/down address arguments to this alignment when
they should be treated as hints.

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]