fast/native fork?

Kaz Kylheku
Wed Jan 24 00:02:00 GMT 2018

On 2018-01-21 00:32, Jay K wrote:
> I have some desire to discuss fork.
> I know it is an old and difficult topic.
> I found this:
>  "Cygwin fork and RtlCloneUserProcess"
> NT has had fork since v1.
> The Posix subsystem used it.
> You didn't need Vista's introduction of RtlCloneUserProcess.
> This from 2005 alludes to how to make it work:
> but I have difficult questions for you -- anyone, but including 
> Corinna.
> What do you expect it to do?
> I mean, consider that there is no pthread_atfork or an analog in Win32.

That's the last of your problems; pthread_atfork doesn't require kernel 
> Dlls at all levels of the Win32 stack, might have
> process-specific state, that needs to be reinitialized.

That issue affects any implementation of fork, including the current 
Cygwin one.

> ntdll.dll is special. It somehow knows fork occured and can 
> reinitialize itself.

> "Somehow" probably being the fact that
> ntdll.dll is special

Or, rather "Somehow" being the fact that ntdll.dll is where the
RtlCloneUserProcess function lives, so of course ntdll.dll is notified
when a fork takes place: it's taking a direct function call.
You don't get any more more notified than that.

> But no other dll expects this.

But under the current implementation of fork in Cygwin, no regular 
Windows DLL
expects to be attached to a Cygwin process which forks by copying .bss
and .data and executing a longjmp in the child to recover the stack 

Moreover, ntdll.dll does not know about Cygwin fork, unlike its own 

So it really just boils down to this forking mechanism just not being

An idea might be to have fork be switchable between the current 
(default) and the RtlCloneUserProcess (experimental, run-time 
Just to get it to users to experiment with while keeping things stable,
and without requiring special builds.

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list