public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* fork fails after nmap with hint address in an unmapped memory region
@ 2017-12-09 15:50 Stéphane Mbape via cygwin
  2017-12-09 18:29 ` Andrey Repin
  2017-12-10 16:13 ` Corinna Vinschen
  0 siblings, 2 replies; 14+ messages in thread
From: Stéphane Mbape via cygwin @ 2017-12-09 15:50 UTC (permalink / raw)
  To: cygwin

Hello,

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.

Thank you for reading.


#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdint.h>

#define MMAP_PROT           (PROT_READ|PROT_WRITE)
#define MMAP_FLAGS_PROBE    (MAP_PRIVATE|MAP_ANONYMOUS)

int main() {
     printf("I am master %d\n", (int) getpid());

     size_t size = ((size_t)128U * (size_t)1024U);
     uintptr_t hint_addr = 0;

     void *p = mmap((void *)hint_addr, size, MMAP_PROT, 
MMAP_FLAGS_PROBE, -1, 0);
     printf ("nmap() = %p, hint_addr = %p\n", p, (void *) hint_addr);

     uintptr_t addr = (uintptr_t) p;

     munmap(p, size); // make sure there is an unmapped memory

     // hint_addr = addr; // produces no error
     hint_addr = addr + 1;
     p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS_PROBE, -1, 0);
     printf ("nmap() = %p, hint_addr = %p\n", p, (void *) hint_addr);

     pid_t child_pid = fork();

     if (child_pid < 0) {
         perror("fork failed");
     } else if (child_pid == 0) {
         printf("I am worker %d\n", (int) getpid());
         sleep(2);
         printf("worker exiting\n");
         exit(0);
     }

     wait(NULL);

     printf("master exiting\n");
     return 0;
}


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 15:50 fork fails after nmap with hint address in an unmapped memory region Stéphane Mbape via cygwin
@ 2017-12-09 18:29 ` Andrey Repin
  2017-12-09 20:12   ` Stéphane Mbape via cygwin
                     ` (2 more replies)
  2017-12-10 16:13 ` Corinna Vinschen
  1 sibling, 3 replies; 14+ messages in thread
From: Andrey Repin @ 2017-12-09 18:29 UTC (permalink / raw)
  To: Stéphane Mbape, cygwin

Greetings, Stéphane Mbape!

> 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.


-- 
With best regards,
Andrey Repin
Saturday, December 9, 2017 18:47:12

Sorry for my terrible english...
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 18:29 ` Andrey Repin
@ 2017-12-09 20:12   ` Stéphane Mbape via cygwin
  2017-12-09 21:57     ` Brian Inglis
  2017-12-10 13:30   ` Stéphane Mbape via cygwin
  2017-12-10 18:04   ` Stéphane Mbape via cygwin
  2 siblings, 1 reply; 14+ messages in thread
From: Stéphane Mbape via cygwin @ 2017-12-09 20:12 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 723 bytes --]

Sorry,

Cygwin version: 2.9.0
OS: Windows 10
Arch: 64bit

The sample was also attached.

Le 09/12/2017 à 16:48, Andrey Repin a écrit :
> Greetings, Stéphane Mbape!
>
>> 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.
>
>


[-- Attachment #2: doscript.c --]
[-- Type: text/plain, Size: 1157 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdint.h>

#define MMAP_PROT           (PROT_READ|PROT_WRITE)
#define MMAP_FLAGS_PROBE    (MAP_PRIVATE|MAP_ANONYMOUS)

int main() {
    printf("I am master %d\n", (int) getpid());

    size_t size = ((size_t)128U * (size_t)1024U);
    uintptr_t hint_addr = 0;

    void *p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS_PROBE, -1, 0);
    printf ("nmap() = %p, hint_addr = %p\n", p, (void *) hint_addr);

    uintptr_t addr = (uintptr_t) p;

    munmap(p, size); // make sure there is an unmapped memory

    // hint_addr = addr; // produces no error
    hint_addr = addr + 1;
    p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS_PROBE, -1, 0);
    printf ("nmap() = %p, hint_addr = %p\n", p, (void *) hint_addr);

    pid_t child_pid = fork();

    if (child_pid < 0) {
        perror("fork failed");
    } else if (child_pid == 0) {
        printf("I am worker %d\n", (int) getpid());
        sleep(2);
        printf("worker exiting\n");
        exit(0);
    }

    wait(NULL);

    printf("master exiting\n");
    return 0;
}

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 20:12   ` Stéphane Mbape via cygwin
@ 2017-12-09 21:57     ` Brian Inglis
  2017-12-10  1:23       ` Brian Inglis
  2017-12-10  6:41       ` Jon Turney
  0 siblings, 2 replies; 14+ messages in thread
From: Brian Inglis @ 2017-12-09 21:57 UTC (permalink / raw)
  To: cygwin

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
$ more mmap_fork_stc.exe.stackdump
Stack trace:
Frame        Function    Args
000005FF3A0  0018005CD8E (0018021AE80, 0018021AC46, 00000008000, 000005FB010)
000005FF3A0  001800465F9 (000005FDDE0, 000005FF3A0, 001800B2D10, 00000000000)
000005FF3A0  00180046632 (00000000000, 000005FBE28, 00000008000, 00100402068)
000005FF3A0  00180046B84 (0007FFE0385, 000005FDDE0, 001800B2D10, 00000000000)
000005FF3A0  00180048040 (00000000000, 00000000000, 00000000000, 00000000000)
000005FF3A0  001800B2EDB (00000000000, 00000000000, 00000000000, 00000000000)
000005FF620  7FFF7777485F (00180040000, 00000000001, 00000240022, 000006D20C8)
000005FF620  7FFF7779D762 (7FFF77797900, 000006D2701, 7FFF774A27BA, 000006D2F10)
000005FF620  7FFF7779D5AB (000006D2720, 000005FF5D0, 00000000003, 0000032E000)
000005FF620  7FFF7779D5D1 (00000000003, 000005FF629, 00000000003, 00000000000)
00000000000  7FFF777E1D31 (00000000000, 00000000000, 00000000001, 00000000000)
00000000000  7FFF7781A1FC (00000000000, 00000000000, 0000032E000, 00000000000)
00000000000  7FFF777C9B1B (00000000000, 00000000000, 00000000000, 00000000000)
00000000000  7FFF777C9ACE (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace
$ cygcheck ./mmap_fork_stc
C:\Users\bwi\src\cygwin\mmap_fork_stc.exe
  C:\usr\local\cygwin64\bin\cygwin1.dll
    C:\WINDOWS\system32\KERNEL32.dll
      C:\WINDOWS\system32\ntdll.dll
      C:\WINDOWS\system32\KERNELBASE.dll
      C:\Program Files\TortoiseGit\bin\api-ms-win-core-handle-l1-1-0.dll
      C:\WINDOWS\system32\api-ms-win-core-synch-l1-2-0.dll
      C:\WINDOWS\system32\api-ms-win-core-timezone-l1-1-0.dll
      C:\Program Files\TortoiseGit\bin\api-ms-win-core-string-l1-1-0.dll
      C:\Program Files\TortoiseGit\bin\api-ms-win-core-util-l1-1-0.dll
      C:\Program Files\TortoiseGit\bin\api-ms-win-core-profile-l1-1-0.dll
      C:\WINDOWS\system32\api-ms-win-core-xstate-l2-1-0.dll
      C:\Program Files\TortoiseGit\bin\api-ms-win-core-console-l1-1-0.dll
$ cmd /c ver

Microsoft Windows [Version 10.0.15063]
$ uname -srvmo
CYGWIN_NT-10.0 2.9.0(0.318/5/3) 2017-09-12 10:18 x86_64 Cygwin

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

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 21:57     ` Brian Inglis
@ 2017-12-10  1:23       ` Brian Inglis
  2017-12-10  6:41       ` Jon Turney
  1 sibling, 0 replies; 14+ messages in thread
From: Brian Inglis @ 2017-12-10  1:23 UTC (permalink / raw)
  To: cygwin

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:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 21:57     ` Brian Inglis
  2017-12-10  1:23       ` Brian Inglis
@ 2017-12-10  6:41       ` Jon Turney
  2017-12-10 13:31         ` Brian Inglis
  1 sibling, 1 reply; 14+ messages in thread
From: Jon Turney @ 2017-12-10  6:41 UTC (permalink / raw)
  To: The Cygwin Mailing List; +Cc: Brian.Inglis

On 09/12/2017 18: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.

If you're going to use addr2line to interpret a .stackdump file, I'm 
afraid you're just supposed to know that the cygwin1.dll has an 
ImageBase of 0x0000000180040000 on x86_64

> $ more mmap_fork_stc.exe.stackdump
> Stack trace:
> Frame        Function    Args
> 000005FF3A0  0018005CD8E (0018021AE80, 0018021AC46, 00000008000, 000005FB010)
> 000005FF3A0  001800465F9 (000005FDDE0, 000005FF3A0, 001800B2D10, 00000000000)
> 000005FF3A0  00180046632 (00000000000, 000005FBE28, 00000008000, 00100402068)
> 000005FF3A0  00180046B84 (0007FFE0385, 000005FDDE0, 001800B2D10, 00000000000)
> 000005FF3A0  00180048040 (00000000000, 00000000000, 00000000000, 00000000000)
> 000005FF3A0  001800B2EDB (00000000000, 00000000000, 00000000000, 00000000000)
> 000005FF620  7FFF7777485F (00180040000, 00000000001, 00000240022, 000006D20C8)
> 000005FF620  7FFF7779D762 (7FFF77797900, 000006D2701, 7FFF774A27BA, 000006D2F10)
> 000005FF620  7FFF7779D5AB (000006D2720, 000005FF5D0, 00000000003, 0000032E000)
> 000005FF620  7FFF7779D5D1 (00000000003, 000005FF629, 00000000003, 00000000000)
> 00000000000  7FFF777E1D31 (00000000000, 00000000000, 00000000001, 00000000000)
> 00000000000  7FFF7781A1FC (00000000000, 00000000000, 0000032E000, 00000000000)
> 00000000000  7FFF777C9B1B (00000000000, 00000000000, 00000000000, 00000000000)
> 00000000000  7FFF777C9ACE (00000000000, 00000000000, 00000000000, 00000000000)
> End of stack trace

Sator Arepo Tenet Opera Rotas! [1]

0x000000018005cd8e    cygwin_stackdump                 exceptions.cc:456
0x00000001800465f9    vapi_fatal                        dcrt0.cc:1296
0x0000000180046632    api_fatal                         dcrt0.cc:1305
0x0000000180046b84    child_info_fork::handle_fork()    dcrt0.cc:634
0x0000000180048040    dll_crt0_0()                      dcrt0.cc:777
0x00000001800b2edb    dll_entry                         init.cc:102

[1] https://cygwin.com/ml/cygwin/2015-08/msg00311.html


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 18:29 ` Andrey Repin
  2017-12-09 20:12   ` Stéphane Mbape via cygwin
@ 2017-12-10 13:30   ` Stéphane Mbape via cygwin
  2017-12-10 18:04   ` Stéphane Mbape via cygwin
  2 siblings, 0 replies; 14+ messages in thread
From: Stéphane Mbape via cygwin @ 2017-12-10 13:30 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1292 bytes --]

I used a temporary fix that may give you a hint.

hint_addr = hint_addr - hint_addr % getpagesize(); // temporary fix

I also used it in luajit, which uses a random hint_addr, and everything is fine.

On 09/12/2017 18: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.


[-- Attachment #2: doscript.c --]
[-- Type: text/plain, Size: 1275 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdint.h>
#include <windows.h>

#define MMAP_PROT           (PROT_READ|PROT_WRITE)
#define MMAP_FLAGS_PROBE    (MAP_PRIVATE|MAP_ANONYMOUS)

int main() {
    printf("I am master %d\n", (int) getpid());

    size_t size = ((size_t)128U * (size_t)1024U);
    uintptr_t hint_addr = 0;

    void *p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS_PROBE, -1, 0);
    printf ("nmap() = %p, hint_addr = %p\n", p, (void *) hint_addr);

    uintptr_t addr = (uintptr_t) p;

    munmap(p, size); // make sure there is an unmapped memory

    // hint_addr = addr; // produces no error
    // hint_addr = addr + 1; // produces an error
    hint_addr = hint_addr - hint_addr % getpagesize(); // temporary fix

    p = mmap((void *)hint_addr, size, MMAP_PROT, MMAP_FLAGS_PROBE, -1, 0);
    printf ("nmap() = %p, hint_addr = %p\n", p, (void *) hint_addr);

    pid_t child_pid = fork();

    if (child_pid < 0) {
        perror("fork failed");
    } else if (child_pid == 0) {
        printf("I am worker %d\n", (int) getpid());
        sleep(2);
        printf("worker exiting\n");
        exit(0);
    }

    wait(NULL);

    printf("master exiting\n");
    return 0;
}

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-10  6:41       ` Jon Turney
@ 2017-12-10 13:31         ` Brian Inglis
  2017-12-10 15:29           ` Corinna Vinschen
  0 siblings, 1 reply; 14+ messages in thread
From: Brian Inglis @ 2017-12-10 13:31 UTC (permalink / raw)
  To: cygwin

On 2017-12-09 15:51, Jon Turney wrote:
> On 09/12/2017 18: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.
> 
> If you're going to use addr2line to interpret a .stackdump file, I'm afraid
> you're just supposed to know that the cygwin1.dll has an ImageBase of
> 0x0000000180040000 on x86_64

Who came up with that magic number 6G256K and why - would a round 7/8G not do?

>> $ more mmap_fork_stc.exe.stackdump
>> Stack trace:
>> Frame        Function    Args
>> 000005FF3A0  0018005CD8E (0018021AE80, 0018021AC46, 00000008000, 000005FB010)
>> 000005FF3A0  001800465F9 (000005FDDE0, 000005FF3A0, 001800B2D10, 00000000000)
>> 000005FF3A0  00180046632 (00000000000, 000005FBE28, 00000008000, 00100402068)
>> 000005FF3A0  00180046B84 (0007FFE0385, 000005FDDE0, 001800B2D10, 00000000000)
>> 000005FF3A0  00180048040 (00000000000, 00000000000, 00000000000, 00000000000)
>> 000005FF3A0  001800B2EDB (00000000000, 00000000000, 00000000000, 00000000000)
>> 000005FF620  7FFF7777485F (00180040000, 00000000001, 00000240022, 000006D20C8)
>> 000005FF620  7FFF7779D762 (7FFF77797900, 000006D2701, 7FFF774A27BA, 000006D2F10)
>> 000005FF620  7FFF7779D5AB (000006D2720, 000005FF5D0, 00000000003, 0000032E000)
>> 000005FF620  7FFF7779D5D1 (00000000003, 000005FF629, 00000000003, 00000000000)
>> 00000000000  7FFF777E1D31 (00000000000, 00000000000, 00000000001, 00000000000)
>> 00000000000  7FFF7781A1FC (00000000000, 00000000000, 0000032E000, 00000000000)
>> 00000000000  7FFF777C9B1B (00000000000, 00000000000, 00000000000, 00000000000)
>> 00000000000  7FFF777C9ACE (00000000000, 00000000000, 00000000000, 00000000000)
>> End of stack trace
> 
> Sator Arepo Tenet Opera Rotas! [1]
> 
> 0x000000018005cd8e    cygwin_stackdump                 exceptions.cc:456
> 0x00000001800465f9    vapi_fatal                        dcrt0.cc:1296
> 0x0000000180046632    api_fatal                         dcrt0.cc:1305
> 0x0000000180046b84    child_info_fork::handle_fork()    dcrt0.cc:634
> 0x0000000180048040    dll_crt0_0()                      dcrt0.cc:777
> 0x00000001800b2edb    dll_entry                         init.cc:102
> 
> [1] https://cygwin.com/ml/cygwin/2015-08/msg00311.html

Happen to have an old stackdump script around from 2013 without that magic.
Neither helps more than the original error message, which tells us that there is
a fork problem with the mmaps: either the mmap allocator is saving the wrong
address, as it appears on a segment boundary, or something else in that
structure is not being saved correctly for anonymous private mmap fixup, as
changing the hinted address to a segment boundary keeps the magic smoke in.

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

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-10 13:31         ` Brian Inglis
@ 2017-12-10 15:29           ` Corinna Vinschen
  0 siblings, 0 replies; 14+ messages in thread
From: Corinna Vinschen @ 2017-12-10 15:29 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 2175 bytes --]

On Dec  9 23:40, Brian Inglis wrote:
> On 2017-12-09 15:51, Jon Turney wrote:
> > On 09/12/2017 18: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.
> > 
> > If you're going to use addr2line to interpret a .stackdump file, I'm afraid
> > you're just supposed to know that the cygwin1.dll has an ImageBase of
> > 0x0000000180040000 on x86_64
> 
> Who came up with that magic number 6G256K and why - would a round 7/8G not do?

Long discussion on cygwin-developers way back when we developed the 64
bit version.  Basically:

* Leave lower 32 bit area of 44 bit address space free for Windows
* Leave upper 32 bit area of 44 bit address space free for Windows

The rest just came about:

  0x1:00000000 - 0x1:80000000	Stacks
  0x1:80000000 - 0x2:00000000	Cygwin DLL plus helper space
  0x2:00000000 - 0x4:00000000	Rebased DLLs
  0x4:00000000 - 0x6:00000000	Non-rebased DLLs
  0x6:00000000			Start address heap
  ...
0x700:00000000			Start address of mmap top down allocations

So heap and mmap are growing from different directions.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 15:50 fork fails after nmap with hint address in an unmapped memory region Stéphane Mbape via cygwin
  2017-12-09 18:29 ` Andrey Repin
@ 2017-12-10 16:13 ` Corinna Vinschen
  2017-12-10 18:04   ` Houder
  1 sibling, 1 reply; 14+ messages in thread
From: Corinna Vinschen @ 2017-12-10 16:13 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]

On Dec  9 15:58, Stéphane Mbape via cygwin wrote:
> Hello,
> 
> 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.
> 
> Thank you for reading.

Thank you for the testcase.  I pushed a patch and uploaded new developer
snapshots to https://cygwin.com/snapshots.  Please test.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-09 18:29 ` Andrey Repin
  2017-12-09 20:12   ` Stéphane Mbape via cygwin
  2017-12-10 13:30   ` Stéphane Mbape via cygwin
@ 2017-12-10 18:04   ` Stéphane Mbape via cygwin
  2017-12-11 13:37     ` Corinna Vinschen
  2 siblings, 1 reply; 14+ messages in thread
From: Stéphane Mbape via cygwin @ 2017-12-10 18:04 UTC (permalink / raw)
  To: cygwin

Worked for me.
Thank you.

On Sun, 10 Dec 2017 14:31:09, Corinna Vinschen wrote:
> --0eh6TmSyL6TZE2Uz
> Content-Type: text/plain; charset=utf-8
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
> 
> On Dec  9 15:58, St=C3=A9phane Mbape via cygwin wrote:
> > Hello,
> >=20
> > While embeding luajit in a c=C2=A0 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"
> >=20
> > There is a sample code below.
> >=20
> > Thank you for reading.
> 
> Thank you for the testcase.  I pushed a patch and uploaded new developer
> snapshots to https://cygwin.com/snapshots.  Please test.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-10 16:13 ` Corinna Vinschen
@ 2017-12-10 18:04   ` Houder
  2017-12-11 16:49     ` Corinna Vinschen
  0 siblings, 1 reply; 14+ messages in thread
From: Houder @ 2017-12-10 18:04 UTC (permalink / raw)
  To: cygwin

On Sun, 10 Dec 2017 14:31:09, Corinna Vinschen wrote:
> --0eh6TmSyL6TZE2Uz
> Content-Type: text/plain; charset=utf-8
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
> 
> On Dec  9 15:58, St=C3=A9phane Mbape via cygwin wrote:
> > Hello,
> >=20
> > While embeding luajit in a c=C2=A0 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"
> >=20
> > There is a sample code below.
> >=20
> > Thank you for reading.
> 
> Thank you for the testcase.  I pushed a patch and uploaded new developer
> snapshots to https://cygwin.com/snapshots.  Please test.

Reference:

    https://cygwin.com/ml/cygwin/2017-12/msg00011.html

It might not help Stéphane, but it works for me ...

Henri

-----
64-@@ uname -a
CYGWIN_NT-6.1 Seven 2.10.0(0.323/5/3)  x86_64 Cygwin
64-@@ sort t8150 | head
abcde    1xxxxx0123456789
abcde    2xxxxx0123456789
abcde    3xxxxx0123456789
abcde    4xxxxx0123456789
abcde    5xxxxx0123456789
abcde    6xxxxx0123456789
abcde    7xxxxx0123456789
abcde    8xxxxx0123456789
abcde    9xxxxx0123456789
abcde   10xxxxx0123456789
64-@@ <==== prompt returns ... Good Heavens!

64-@@ uname -a
CYGWIN_NT-6.1 Seven 2.9.0(0.318/5/3) 2017-09-12 10:18 x86_64 Cygwin
64-@@ sort t8150 | head
abcde    1xxxxx0123456789
abcde    2xxxxx0123456789
abcde    3xxxxx0123456789
abcde    4xxxxx0123456789
abcde    5xxxxx0123456789
abcde    6xxxxx0123456789
abcde    7xxxxx0123456789
abcde    8xxxxx0123456789
abcde    9xxxxx0123456789
abcde   10xxxxx0123456789
 <==== prompt does not return

=====


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-10 18:04   ` Stéphane Mbape via cygwin
@ 2017-12-11 13:37     ` Corinna Vinschen
  0 siblings, 0 replies; 14+ messages in thread
From: Corinna Vinschen @ 2017-12-11 13:37 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]

On Dec 10 17:13, Stéphane Mbape via cygwin wrote:
> Worked for me.
> Thank you.
> 
> On Sun, 10 Dec 2017 14:31:09, Corinna Vinschen wrote:
> > --0eh6TmSyL6TZE2Uz
> > Content-Type: text/plain; charset=utf-8
> > Content-Disposition: inline
> > Content-Transfer-Encoding: quoted-printable
> > 
> > On Dec  9 15:58, St=C3=A9phane Mbape via cygwin wrote:
> > > Hello,
> > >=20
> > > While embeding luajit in a c=C2=A0 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"
> > >=20
> > > There is a sample code below.
> > >=20
> > > Thank you for reading.
> > 
> > Thank you for the testcase.  I pushed a patch and uploaded new developer
> > snapshots to https://cygwin.com/snapshots.  Please test.

Thanks for testing,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: fork fails after nmap with hint address in an unmapped memory region
  2017-12-10 18:04   ` Houder
@ 2017-12-11 16:49     ` Corinna Vinschen
  0 siblings, 0 replies; 14+ messages in thread
From: Corinna Vinschen @ 2017-12-11 16:49 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1331 bytes --]

On Dec 10 16:29, Houder wrote:
> On Sun, 10 Dec 2017 14:31:09, Corinna Vinschen wrote:
> > --0eh6TmSyL6TZE2Uz
> > Content-Type: text/plain; charset=utf-8
> > Content-Disposition: inline
> > Content-Transfer-Encoding: quoted-printable
> > 
> > On Dec  9 15:58, St=C3=A9phane Mbape via cygwin wrote:
> > > Hello,
> > >=20
> > > While embeding luajit in a c=C2=A0 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"
> > >=20
> > > There is a sample code below.
> > >=20
> > > Thank you for reading.
> > 
> > Thank you for the testcase.  I pushed a patch and uploaded new developer
> > snapshots to https://cygwin.com/snapshots.  Please test.
> 
> Reference:
> 
>     https://cygwin.com/ml/cygwin/2017-12/msg00011.html
> 
> It might not help Stéphane, but it works for me ...
> 
> Henri

That's... surprising.  But good to know.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-12-10 18:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-09 15:50 fork fails after nmap with hint address in an unmapped memory region Stéphane Mbape via cygwin
2017-12-09 18:29 ` Andrey Repin
2017-12-09 20:12   ` Stéphane Mbape via cygwin
2017-12-09 21:57     ` Brian Inglis
2017-12-10  1:23       ` Brian Inglis
2017-12-10  6:41       ` Jon Turney
2017-12-10 13:31         ` Brian Inglis
2017-12-10 15:29           ` Corinna Vinschen
2017-12-10 13:30   ` Stéphane Mbape via cygwin
2017-12-10 18:04   ` Stéphane Mbape via cygwin
2017-12-11 13:37     ` Corinna Vinschen
2017-12-10 16:13 ` Corinna Vinschen
2017-12-10 18:04   ` Houder
2017-12-11 16:49     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).