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: fast/native fork?


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"
 https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/afdf1b68-1f3e-47f5-94cf-51e397afe073/cygwin-fork-and-rtlcloneuserprocess?forum=windowsgeneraldevelopmentissues



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:
  https://www.winvistatips.com/threads/question-about-ntcreateprocess.186504/

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

https://www.cygwin.com/faq.html#faq.api.fork

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

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

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

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

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


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