This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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: [PATCH] [BZ #18433] Check file access/existence before forking.


On Fri, Sep 18, 2015 at 06:19:33PM +0300, Alexander Monakov wrote:
> On Fri, 18 Sep 2015, Szabolcs Nagy wrote:
> 
> > On 18/09/15 15:44, Carlos O'Donell wrote:
> > > Note that it is possible to use vfork in certain conditions,
> > > and we do in glibc. So one should not entirely dismiss vfork,
> > > but that's slightly off topic.
> > 
> > are you sure?
> > 
> > i think all use of vfork is invalid c: the compiler can
> > spill registers on the stack then in the child clobber
> > them, then after vfork returns in the parent the
> > clobbered registers are restored breaking the expectations
> > of the compiler. (this can break independently of how
> > the c code around vfork looks like).
> 
> The same argument applies to setjmp,

Not quite. With setjmp, once there's any return from the function
where setjmp was called (or call to a function that's known neither to
return nor call longjmp or throw an exception), the compiler may
rightfully assume that non-reachable data in the setjmp caller is no
longer live and clobber it.

What makes vfork is special is that the data must be treated as live
even when the caller calls _exit.

> and the solution in GCC is the
> same for both: GCC internally recognizes vfork, setjmp, and a few other
> functions as functions that "return twice".

If gcc treats vfork even more specially than setjmp, or slightly
pessimizes behavior around setjmp to force all data to remain live,
then I think it's safe to use vfork as long as your compiler is gcc.
Whether other compilers that are or might become interesting do the
same, I don't know. It's not an assumption I like.

> (after all, if it was broken like you describe, one would expect to witness
> such breakage in practice, for instance with GNU Make prior to 4.0)

I thought the reason GNU make switches was that they encountered
subtle breakage in practice somewhere... Of course GNU make has to be
compatible with basically _all_ compilers, not just gcc, so that might
be the reason.

Rich


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