1.5.10: Possible fork() bug: certain addresses inaccessible to child (Win2000)

Ren Fur renfur@hotmail.com
Sun Jul 4 23:51:00 GMT 2004


I have a program written in SML (fork.sml) and compiled with MLton 
(www.mlton.org) that relies on fork() and uses a foreign function call to a 
C wrapper (fork_wrapper() in fork.c).

When I run the program, both parent and child return from the fork() call 
and from the C wrapper function. However, the child is terminated soon after 
because it tries to access an "illegal" memory address (but this address is 
visible to the parent before and after the fork). I have stepped through the 
parent and child's execution with gdb and found that the memory the child 
tries to access is in the parent's address space but not in the child's.

I haven't found any Cygwin reports of this problem, but it's known to the 
MLton developers since the library fork function (Posix.Process.fork) is 
disabled on the Cygwin version of MLton.

I have been able to repeat this behavior on several Windows 2000 computers 
running Cygwin 1.5.10. I'm using the MLton 20040227 compiler for Cygwin.
www.mlton.org/download/index.html
www.mlton.org/download/mlton-20040227-1.i386-cygwin.tgz

After compiling the SML program, I disassembled the binary and found the 
following. (The numbers and addresses here are host- and run-dependent.)
-The block with label L_1047 calls fork_wrapper().
-Before calling fork_wrapper(), %esp and %ebp are stored at 0x41d560 and 
0x41d568, respectively.
-After fork_wrapper() returns, %esp and %ebp are restored from those 
adresses.
-On one run, before calling fork_wrapper(), the parent had %esp = 0x00a92e4c 
and %ebp = 0x00a90b9c, and both addresses could be dereferenced. After 
fork_wrapper() returned, the child could dereference 0x00a90b9c (%ebp) but 
not 0x00a92e4c (%esp). gdb would report the memory at that address was 
inaccessible, and if the child continued it would get a SIGSEGV. I don't 
know what page size Windows uses, but it seems like those two addresses 
would be in the same page, which makes the problem stranger.

Also, fork() does work if it's used in a regular C program.
Is this a Cygwin bug or am I missing something when using fork()?

Thank you.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 66 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20040704/ffa25dc3/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fork.sml
Type: application/octet-stream
Size: 244 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20040704/ffa25dc3/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fork.c
Type: application/octet-stream
Size: 202 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20040704/ffa25dc3/attachment-0002.obj>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list