On Mar 18 14:46, Jeremy Drake via Cygwin-developers wrote: > On Tue, 18 Mar 2025, Corinna Vinschen wrote: > > > One of the biggies here is the way descriptor passing works in Cygwin. > > > > We're coming from a historical API model which didn't know the > > STARTUPINFOEX datatype, nor the UpdateProcThreadAttribute function > > and PROC_THREAD_ATTRIBUTE_HANDLE_LIST. Thus, Cygwin is handling > > handles free-form. Some handles required for Cygwin internally are > > simply inherited, FD_CLOEXEC is implemented by closing the handles > > in the forked child, etc. > > > > For posix_spawn without forking, this complicates matters. For > > instance, we don't want having to close FD_CLOEXEC handles in the > > spawned child because that's a security problem. > > Plus, the spawned process may not be Cygwin, so fixing this up in the > Cygwin startup code wouldn't catch that case. Hmm, I had thought of some > of this, but I figured it already had to have been solved for spawn. I > would have guessed FD_CLOEXEC handles would be marked as no-inherit, and > DuplicateHandle'd into forked children.
Duh, I shouldn't write about technical stuff when it's late. You're right of course. O_CLOEXEC descriptors are non-inherit and just duplicated in the forked child in the fixup_after_fork() methods. > But I don't remember > PROC_THREAD_ATTRIBUTE_HANDLE_LIST either. Good to know. Having an all-handle bookkeeping structure could allow to keep all handles inheritable and just create the matching PROC_THREAD_ATTRIBUTE_HANDLE_LIST. For the internal handles that's a fixed thing, for the fhandler handles it depends on FD_CLOEXEC and FD_CLOFORK. That could simplify the fork/exec handling (getting rid of fixup_after_fork) and make sure we're not inheriting handles accidentally. Hmm... FD_CLOFORK also adds a new twist to cygheap_fixup_in_child(), if I'm not mistaken. The fhandler has to be free'd after fork. However, this is just idle musing at this point. It could well be that all-handle bookkeeping only replaces one bookkeeping overhead with another one. Corinna