Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 12 Jun 2017 10:30:12 +0200
From: u-uy74@...ey.se
To: musl@...ts.openwall.com
Subject: Re: more fun with non-Linux Linux ABI

On Sun, Jun 11, 2017 at 05:50:20PM -0400, Rich Felker wrote:
> On Sun, Jun 11, 2017 at 08:01:58PM +0200, u-uy74@...ey.se wrote:
> > FWIIW: when running under Linux ABI on FreeBSD
> > in musl-linked programs the child processes segfault right after a
> > vfork(), before doing anything else:
> 
> My first guess is that this is a FreeBSD bug...

I agree.

> > Remarkably this apparently does not affect glibc-based builds
> > (I have not tested right now but otherwise it would have been known).
> > Wonder what makes the difference.
> 
> Is it possible that FreeBSD's Linux syscall emulation uses the
> userspace stack to store some state during syscalls? For example maybe

I am not sufficiently familiar with the FreeBSD internals to tell this.
The linux_fork() and linux_vfork() functions are about 30 lines each
and the only difference is

--- fork
+++ vfork
 ...
         struct fork_req fr;
 ...
         bzero(&fr, sizeof(fr));
-        fr.fr_flags = RFFDG | RFPROC | RFSTOPPED;
+        fr.fr_flags = RFFDG | RFPROC | RFMEM | RFPPWAIT | RFSTOPPED;
         fr.fr_procp = &p2;
         if ((error = fork1(td, &fr)) != 0)
                 return (error);
 ...

I guess the musl vs glibc difference can happen if the latter implements
vfork() in terms of clone() (?)

linux_clone() has a much larger implementation in FreeBSD than
linux_vfork() which could explain why the one works and the other
does not.

> > Otherwise a simple workaround would be an option to make vfork()
> > a fork() synonym while building musl. (I do the this at applications
> > build time instead, which helps.)
> > 
> > Such an option would most probably result in a pretty small performance
> > impact on modern (native) Linux.
> 
> It's actually a pretty large impact; recent (4.x+ IIRC) versions of
> GNU makes are considerably slower because they dropped use of vfork
> and switched to fork rather than making it use posix_spawn like it
> should.

Thanks, good to know. Then I have to live with this impact on Linux
or convince the FreeBSD team to fix linux_vfork().

Rune

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.