This is the mail archive of the cygwin@cygwin.com 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]

RE: Strange fork() behaviour under cygwin v1.3.1



To recap, the program which is causing problems is:

> #include <stdio.h>
>
> void *test(void *arg);
>
> int main(int argc, char* argv[]) {
>   int pid;
>   pth_init();
>
>   pth_join(pth_spawn(PTH_ATTR_DEFAULT, test, NULL), NULL);
> }
>
> void *test(void *arg) {
>   int pid;
>
>   pid = fork();
>   if (pid < 0) {
>     printf("FORKFAILED\n");
>   } else if (pid == 0) {
>     printf("FORKCHILD\n");
>   } else {
>     printf("FORKPARENT\n");
>   }
> }

Running under gnu pth 1.4.0, and cygwin 1.3.2


> > -----Original Message-----
> > From: Andrew de Quincey [mailto:andrew@orbital.co.uk]
> > > Rob wrote
> > > > -----Original Message-----
> > > > From: Andrew de Quincey [mailto:andrew@orbital.co.uk]
> > > > Hi, I've been playing with the jabber server under win32...
> > > > and I've run
> > > > into a slight problem. The following program illustrates it:
> > > >
> > >
> > From the "non-preemptive-ness" & the lack of any pthread or
> > win32 thread
> > functions in it, it sounds like an entirely user-space
> > threading library.
>
> Oh. Well I suggest you build a debug pth library, and optionally a debug
> cygwin library (see the cvs source web page for build instructions), and
> see if pth is doing funky stuff that might confuse fork(). If no actual
> threads are involved, there shouldn't be any particular problems :].
> Also update to cygwin 1.3.2 just-in-case.

OK, I am now using 1.3.2 (which didn't help :(

I've investigated gnu pth a bit more, and it does do some "interesting"
things with the stack when you spawn a new thread (I suppose it would have
to). Could this be confusing cygwin?


I've got cygwin compiled and put tracing statements in it.

A more complete error output from the program is:

C:\tmp\tmp\install\bin\test.exe: *** 1. unable to allocate heap 0xA010000,
heap_chunk_size 268435456, pid 1568, Win32 error 487
      0 [main] test 1516 sync_with_child: child 1568(0xB4) died before
initialization with status code 0x1
    252 [main] test 1516 sync_with_child: *** child state waiting for
longjmp
FORKFAILED



The problem is coming from the DLL init code in dctr0.cc.

A rough trace to the error is:

dll_crt0_1()
 memory_init()
  heap_init()



The error occurs in heap_init() in heap.cc.. in the following:

      char *p;
      for (;;)
        {
          p = (char *) VirtualAlloc (brkbase, reserve_size,
                                     MEM_RESERVE, PAGE_READWRITE);
          if (p)
            break;
          if ((reserve_size -= page_const) <= allocsize)
            break;
        }

The VirtualAlloc just returns an error code, 487, which I believe is
"Attempt to access invalid address. "

As to *why* this is, I have no ideas.. can anyone help?



--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


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