From: Jakub Jelinek <jakub@redhat.com>
To: Roland McGrath <roland@redhat.com>
Cc: Ulrich Drepper <drepper@redhat.com>,
Andreas Schwab <schwab@suse.de>,
libc-hacker@sources.redhat.com
Subject: Re: getpid/vfork broken
Date: Mon, 08 Mar 2004 13:10:00 -0000 [thread overview]
Message-ID: <20040308110105.GN3822@sunsite.ms.mff.cuni.cz> (raw)
In-Reply-To: <200403080237.i282bXG6004322@magilla.sf.frob.com>
On Sun, Mar 07, 2004 at 06:37:33PM -0800, Roland McGrath wrote:
> The new specification for vfork where you can't even call dup2 is very
> close to useless. The origin of vfork and true standard for its behavior
> that applications have been written for is 4.2BSD, where simple system
> calls were always safe, and getpid has always been the simplest system
> call. The modern BSD specification remains that the address space is
> shared, with all that entails, but since getpid has never relied on data
> contents in the address space before, citing that as license to make it do
> the wrong thing is dubious at best. Since the useless specification has
> been enshrined in POSIX, where vfork in fact never belonged at all, it is
> likely that every historical program will be broken and people will just
> have to adapt to giving up vfork entirely. Progress.
Here is what would be needed to make vfork & getpid work together:
1) vfork needs to:
struct pthread *pd = THREAD_SELF;
int oldval = THREAD_GETMEM (pd, pid);
int newval = oldval ? -oldval : INT_MIN;
THREAD_SETMEM (pd, pid) = newval;
actual vfork syscall (oldval must be saved in a register
preserved accross the syscall)
THREAD_SETMEM (pd, pid) = oldval;
2) raise would need:
/* raise is an async-safe function. It could be called while the
fork function temporarily invalidated the PID field. Adjust for
that. */
if (__builtin_expect (pid <= 0, 0))
- pid = pid == 0 ? selftid : -pid;
+ pid = (pid & INT_MAX) == 0 ? selftid : -pid;
vfork is written in assembly for each architecture, so so that would need to
be coded for each architecture.
->pid field seems to be only accessed in raise, getpid and fork from libc.so
functions, when libpthread is loaded, THREAD_SELF->pid will always be
non-zero, getpid with THREAD_SELF->pid == INT_MIN will always do the real
syscall and while vfork is running, the same program certainly shouldn't
call fork() (neither in a signal handler nor in the vfork child).
Jakub
next prev parent reply other threads:[~2004-03-08 13:10 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-07 23:18 Andreas Schwab
2004-03-07 23:30 ` Ulrich Drepper
2004-03-08 2:22 ` Roland McGrath
2004-03-08 2:28 ` Ulrich Drepper
2004-03-08 2:37 ` Roland McGrath
2004-03-08 13:10 ` Jakub Jelinek [this message]
2004-03-09 1:28 ` Roland McGrath
2004-03-09 2:04 ` Ulrich Drepper
2004-03-09 3:50 ` Richard Henderson
2004-03-09 7:48 ` Ulrich Drepper
2004-03-09 13:01 ` Andreas Schwab
2004-03-09 13:59 ` [PATCH] getpid/vfork/raise fix Jakub Jelinek
2004-03-09 16:44 ` Andreas Schwab
2004-03-09 19:38 ` Jakub Jelinek
2004-03-10 5:53 ` Ulrich Drepper
2004-03-10 10:37 ` Andreas Schwab
2004-03-10 12:24 ` Jakub Jelinek
2004-03-10 14:33 ` Andreas Schwab
2004-03-10 15:01 ` Jakub Jelinek
2004-03-10 15:06 ` Andreas Schwab
2004-03-10 16:56 ` David Mosberger
2004-03-10 17:02 ` Jakub Jelinek
2004-03-10 17:45 ` David Mosberger
2004-03-10 18:19 ` Jakub Jelinek
2004-03-10 19:24 ` David Mosberger
2004-03-10 18:44 ` Ulrich Drepper
2004-03-10 19:18 ` [PATCH] IA-64 pt-vfork fix Jakub Jelinek
2004-03-10 23:10 ` Ulrich Drepper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040308110105.GN3822@sunsite.ms.mff.cuni.cz \
--to=jakub@redhat.com \
--cc=drepper@redhat.com \
--cc=libc-hacker@sources.redhat.com \
--cc=roland@redhat.com \
--cc=schwab@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).