2020-01-01 08:14:33 +08:00
|
|
|
|
/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
|
1997-02-15 12:31:36 +08:00
|
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 12:58:11 +08:00
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1997-02-15 12:31:36 +08:00
|
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 12:58:11 +08:00
|
|
|
|
Lesser General Public License for more details.
|
1997-02-15 12:31:36 +08:00
|
|
|
|
|
2001-07-06 12:58:11 +08:00
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 07:18:22 +08:00
|
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 13:40:42 +08:00
|
|
|
|
<https://www.gnu.org/licenses/>. */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
|
|
|
|
#include <hurd.h>
|
|
|
|
|
#include <hurd/msg_server.h>
|
|
|
|
|
#include <hurd/fd.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <string.h>
|
1996-05-04 17:46:57 +08:00
|
|
|
|
#include <argz.h>
|
1995-02-18 09:27:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define AUTHCHECK \
|
|
|
|
|
if (auth != mach_task_self () && ! __USEPORT (AUTH, port == auth)) \
|
|
|
|
|
return EPERM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Snarfing and frobbing the init ports. */
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
1995-11-04 06:42:06 +08:00
|
|
|
|
_S_msg_get_init_port (mach_port_t msgport, mach_port_t auth, int which,
|
|
|
|
|
mach_port_t *result, mach_msg_type_name_t *result_type)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
*result_type = MACH_MSG_TYPE_MOVE_SEND;
|
|
|
|
|
/* This function adds a new user reference for the *RESULT it gives back.
|
|
|
|
|
Our reply message uses a move-send right that consumes this reference. */
|
|
|
|
|
return _hurd_ports_get (which, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_init_port (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
int which, mach_port_t port)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
error_t err;
|
|
|
|
|
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
err = _hurd_ports_set (which, port);
|
|
|
|
|
if (err == 0)
|
|
|
|
|
__mach_port_deallocate (__mach_task_self (), port);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_get_init_ports (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
mach_port_t **ports,
|
|
|
|
|
mach_msg_type_name_t *ports_type,
|
|
|
|
|
mach_msg_type_number_t *nports)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
mach_msg_type_number_t i;
|
|
|
|
|
error_t err;
|
|
|
|
|
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
if (err = __vm_allocate (__mach_task_self (), (vm_address_t *) ports,
|
|
|
|
|
_hurd_nports * sizeof (mach_port_t), 1))
|
|
|
|
|
return err;
|
|
|
|
|
*nports = _hurd_nports;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < _hurd_nports; ++i)
|
|
|
|
|
/* This function adds a new user ref for the *RESULT it gives back.
|
|
|
|
|
Our reply message uses move-send rights that consumes this ref. */
|
|
|
|
|
if (err = _hurd_ports_get (i, &(*ports)[i]))
|
|
|
|
|
{
|
|
|
|
|
/* Died part way through. Deallocate the ports already fetched. */
|
|
|
|
|
while (i-- > 0)
|
|
|
|
|
__mach_port_deallocate (__mach_task_self (), (*ports)[i]);
|
|
|
|
|
__vm_deallocate (__mach_task_self (),
|
|
|
|
|
(vm_address_t) *ports,
|
|
|
|
|
*nports * sizeof (mach_port_t));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*ports_type = MACH_MSG_TYPE_MOVE_SEND;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_init_ports (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
mach_port_t *ports, mach_msg_type_number_t nports)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
mach_msg_type_number_t i;
|
|
|
|
|
error_t err;
|
|
|
|
|
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < _hurd_nports; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (err = _hurd_ports_set (i, ports[i]))
|
|
|
|
|
return err;
|
|
|
|
|
else
|
|
|
|
|
__mach_port_deallocate (__mach_task_self (), ports[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Snarfing and frobbing the init ints. */
|
|
|
|
|
|
|
|
|
|
static kern_return_t
|
|
|
|
|
get_int (int which, int *value)
|
|
|
|
|
{
|
|
|
|
|
switch (which)
|
|
|
|
|
{
|
|
|
|
|
case INIT_UMASK:
|
|
|
|
|
*value = _hurd_umask;
|
|
|
|
|
return 0;
|
|
|
|
|
case INIT_SIGPENDING:
|
|
|
|
|
{
|
hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.
This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.
This also updates all the glibc code accordingly.
This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.
During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork. This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.
To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.
When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create). This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal. In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked). Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive. Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.
Options seem to be:
* Move the locking of _hurd_siglock earlier in post_signal -- but that
may generally impact performance, if this locking isn't generally
needed anyway?
On the other hand, would it actually make sense to wait here until we
are not any longer in a critical section (which is meant to disable
signal delivery anyway (but not for preempted signals?))?
* Clear the global sigstate in the fork's child with the rationale that
we're anyway restarting the signal thread from a clean state. This
has now been implemented.
Why has this problem not been observed before Jérémie's patches? (Or has
it? Perhaps even more rarely?) In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*. The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section? (Not completely analyzed and verified.)
Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
2019-12-30 00:59:55 +08:00
|
|
|
|
struct hurd_sigstate *ss = _hurd_global_sigstate;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
__spin_lock (&ss->lock);
|
|
|
|
|
*value = ss->pending;
|
|
|
|
|
__spin_unlock (&ss->lock);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
case INIT_SIGIGN:
|
|
|
|
|
{
|
hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.
This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.
This also updates all the glibc code accordingly.
This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.
During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork. This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.
To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.
When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create). This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal. In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked). Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive. Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.
Options seem to be:
* Move the locking of _hurd_siglock earlier in post_signal -- but that
may generally impact performance, if this locking isn't generally
needed anyway?
On the other hand, would it actually make sense to wait here until we
are not any longer in a critical section (which is meant to disable
signal delivery anyway (but not for preempted signals?))?
* Clear the global sigstate in the fork's child with the rationale that
we're anyway restarting the signal thread from a clean state. This
has now been implemented.
Why has this problem not been observed before Jérémie's patches? (Or has
it? Perhaps even more rarely?) In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*. The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section? (Not completely analyzed and verified.)
Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
2019-12-30 00:59:55 +08:00
|
|
|
|
struct hurd_sigstate *ss = _hurd_global_sigstate;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
sigset_t ign;
|
|
|
|
|
int sig;
|
|
|
|
|
__spin_lock (&ss->lock);
|
|
|
|
|
__sigemptyset (&ign);
|
|
|
|
|
for (sig = 1; sig < NSIG; ++sig)
|
|
|
|
|
if (ss->actions[sig].sa_handler == SIG_IGN)
|
|
|
|
|
__sigaddset (&ign, sig);
|
|
|
|
|
__spin_unlock (&ss->lock);
|
|
|
|
|
*value = ign;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_get_init_int (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
int which, int *value)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
return get_int (which, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_get_init_ints (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
int **values, mach_msg_type_number_t *nvalues)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
error_t err;
|
|
|
|
|
mach_msg_type_number_t i;
|
|
|
|
|
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
if (err = __vm_allocate (__mach_task_self (), (vm_address_t *) values,
|
|
|
|
|
INIT_INT_MAX * sizeof (int), 1))
|
|
|
|
|
return err;
|
|
|
|
|
*nvalues = INIT_INT_MAX;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < INIT_INT_MAX; ++i)
|
|
|
|
|
switch (err = get_int (i, &(*values)[i]))
|
|
|
|
|
{
|
|
|
|
|
case 0: /* Success. */
|
|
|
|
|
break;
|
|
|
|
|
case EINVAL: /* Unknown index. */
|
|
|
|
|
(*values)[i] = 0;
|
|
|
|
|
break;
|
|
|
|
|
default: /* Lossage. */
|
|
|
|
|
__vm_deallocate (__mach_task_self (),
|
|
|
|
|
(vm_address_t) *values, INIT_INT_MAX * sizeof (int));
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static kern_return_t
|
|
|
|
|
set_int (int which, int value)
|
|
|
|
|
{
|
|
|
|
|
switch (which)
|
|
|
|
|
{
|
|
|
|
|
case INIT_UMASK:
|
|
|
|
|
_hurd_umask = value;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* These are pretty odd things to do. But you asked for it. */
|
|
|
|
|
case INIT_SIGPENDING:
|
|
|
|
|
{
|
hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.
This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.
This also updates all the glibc code accordingly.
This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.
During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork. This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.
To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.
When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create). This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal. In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked). Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive. Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.
Options seem to be:
* Move the locking of _hurd_siglock earlier in post_signal -- but that
may generally impact performance, if this locking isn't generally
needed anyway?
On the other hand, would it actually make sense to wait here until we
are not any longer in a critical section (which is meant to disable
signal delivery anyway (but not for preempted signals?))?
* Clear the global sigstate in the fork's child with the rationale that
we're anyway restarting the signal thread from a clean state. This
has now been implemented.
Why has this problem not been observed before Jérémie's patches? (Or has
it? Perhaps even more rarely?) In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*. The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section? (Not completely analyzed and verified.)
Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
2019-12-30 00:59:55 +08:00
|
|
|
|
struct hurd_sigstate *ss = _hurd_global_sigstate;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
__spin_lock (&ss->lock);
|
|
|
|
|
ss->pending = value;
|
|
|
|
|
__spin_unlock (&ss->lock);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
case INIT_SIGIGN:
|
|
|
|
|
{
|
hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.
This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.
This also updates all the glibc code accordingly.
This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.
During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork. This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.
To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.
When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create). This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal. In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked). Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive. Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.
Options seem to be:
* Move the locking of _hurd_siglock earlier in post_signal -- but that
may generally impact performance, if this locking isn't generally
needed anyway?
On the other hand, would it actually make sense to wait here until we
are not any longer in a critical section (which is meant to disable
signal delivery anyway (but not for preempted signals?))?
* Clear the global sigstate in the fork's child with the rationale that
we're anyway restarting the signal thread from a clean state. This
has now been implemented.
Why has this problem not been observed before Jérémie's patches? (Or has
it? Perhaps even more rarely?) In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*. The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section? (Not completely analyzed and verified.)
Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
2019-12-30 00:59:55 +08:00
|
|
|
|
struct hurd_sigstate *ss = _hurd_global_sigstate;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
int sig;
|
|
|
|
|
const sigset_t ign = value;
|
|
|
|
|
__spin_lock (&ss->lock);
|
|
|
|
|
for (sig = 1; sig < NSIG; ++sig)
|
|
|
|
|
{
|
|
|
|
|
if (__sigismember (&ign, sig))
|
|
|
|
|
ss->actions[sig].sa_handler = SIG_IGN;
|
|
|
|
|
else if (ss->actions[sig].sa_handler == SIG_IGN)
|
|
|
|
|
ss->actions[sig].sa_handler = SIG_DFL;
|
|
|
|
|
}
|
|
|
|
|
__spin_unlock (&ss->lock);
|
|
|
|
|
return 0;
|
1996-05-23 08:08:54 +08:00
|
|
|
|
|
|
|
|
|
case INIT_TRACEMASK:
|
|
|
|
|
_hurdsig_traced = value;
|
|
|
|
|
return 0;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_init_int (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
int which, int value)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
return set_int (which, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_init_ints (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
int *values, mach_msg_type_number_t nvalues)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
error_t err;
|
|
|
|
|
mach_msg_type_number_t i;
|
|
|
|
|
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < INIT_INT_MAX; ++i)
|
|
|
|
|
switch (err = set_int (i, values[i]))
|
|
|
|
|
{
|
|
|
|
|
case 0: /* Success. */
|
|
|
|
|
break;
|
|
|
|
|
case EINVAL: /* Unknown index. */
|
|
|
|
|
break;
|
|
|
|
|
default: /* Lossage. */
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
1995-11-04 06:42:06 +08:00
|
|
|
|
_S_msg_get_fd (mach_port_t msgport, mach_port_t auth, int which,
|
|
|
|
|
mach_port_t *result, mach_msg_type_name_t *result_type)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
/* This creates a new user reference for the send right.
|
|
|
|
|
Our reply message will move that reference to the caller. */
|
|
|
|
|
*result = __getdport (which);
|
|
|
|
|
if (*result == MACH_PORT_NULL)
|
|
|
|
|
return errno;
|
|
|
|
|
*result_type = MACH_MSG_TYPE_MOVE_SEND;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_fd (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
int which, mach_port_t port)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
|
|
|
|
/* We consume the reference if successful. */
|
|
|
|
|
return HURD_FD_USE (which, (_hurd_port2fd (descriptor, port, 0), 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Snarfing and frobbing environment variables. */
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_get_env_variable (mach_port_t msgport,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
char *variable,
|
|
|
|
|
char **data, mach_msg_type_number_t *datalen)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
1998-07-21 18:36:59 +08:00
|
|
|
|
error_t err;
|
|
|
|
|
mach_msg_type_number_t valuelen;
|
1995-02-18 09:27:10 +08:00
|
|
|
|
const char *value = getenv (variable);
|
|
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
|
return ENOENT;
|
|
|
|
|
|
1998-07-21 18:36:59 +08:00
|
|
|
|
valuelen = strlen (value);
|
|
|
|
|
if (valuelen > *datalen)
|
|
|
|
|
{
|
2013-06-06 04:44:03 +08:00
|
|
|
|
if (err = __vm_allocate (__mach_task_self (),
|
1998-07-21 18:36:59 +08:00
|
|
|
|
(vm_address_t *) data, valuelen, 1))
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy (*data, value, valuelen);
|
|
|
|
|
*datalen = valuelen;
|
|
|
|
|
|
1995-02-18 09:27:10 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_env_variable (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
char *variable,
|
|
|
|
|
char *value,
|
|
|
|
|
int replace)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
2018-04-03 03:07:52 +08:00
|
|
|
|
if (__setenv (variable, value, replace)) /* XXX name space */
|
1995-02-18 09:27:10 +08:00
|
|
|
|
return errno;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_get_environment (mach_port_t msgport,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
char **data, mach_msg_type_number_t *datalen)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
/* Pack the environment into an array with nulls separating elements. */
|
|
|
|
|
if (__environ != NULL)
|
|
|
|
|
{
|
|
|
|
|
char *ap, **p;
|
|
|
|
|
size_t envlen = 0;
|
|
|
|
|
|
|
|
|
|
for (p = __environ; *p != NULL; ++p)
|
|
|
|
|
envlen += strlen (*p) + 1;
|
|
|
|
|
|
|
|
|
|
if (envlen > *datalen)
|
|
|
|
|
{
|
|
|
|
|
if (__vm_allocate (__mach_task_self (),
|
|
|
|
|
(vm_address_t *) data, envlen, 1))
|
|
|
|
|
return ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ap = *data;
|
|
|
|
|
for (p = __environ; *p != NULL; ++p)
|
|
|
|
|
ap = __memccpy (ap, *p, '\0', ULONG_MAX);
|
|
|
|
|
|
|
|
|
|
*datalen = envlen;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*datalen = 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_environment (mach_port_t msgport, mach_port_t auth,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
char *data, mach_msg_type_number_t datalen)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{
|
|
|
|
|
int _hurd_split_args (char *, mach_msg_type_number_t, char **);
|
|
|
|
|
int envc;
|
|
|
|
|
char **envp;
|
|
|
|
|
|
|
|
|
|
AUTHCHECK;
|
|
|
|
|
|
1996-05-04 17:46:57 +08:00
|
|
|
|
envc = __argz_count (data, datalen);
|
1995-02-18 09:27:10 +08:00
|
|
|
|
envp = malloc ((envc + 1) * sizeof (char *));
|
|
|
|
|
if (envp == NULL)
|
|
|
|
|
return errno;
|
1996-05-04 17:46:57 +08:00
|
|
|
|
__argz_extract (data, datalen, envp);
|
1995-02-18 09:27:10 +08:00
|
|
|
|
__environ = envp; /* XXX cooperate with loadenv et al */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX */
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_get_dtable (mach_port_t process,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
mach_port_t refport,
|
|
|
|
|
portarray_t *dtable,
|
|
|
|
|
mach_msg_type_name_t *dtablePoly,
|
|
|
|
|
mach_msg_type_number_t *dtableCnt)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{ return EOPNOTSUPP; }
|
|
|
|
|
|
|
|
|
|
kern_return_t
|
|
|
|
|
_S_msg_set_dtable (mach_port_t process,
|
1995-11-04 06:42:06 +08:00
|
|
|
|
mach_port_t refport,
|
|
|
|
|
portarray_t dtable,
|
|
|
|
|
mach_msg_type_number_t dtableCnt)
|
1995-02-18 09:27:10 +08:00
|
|
|
|
{ return EOPNOTSUPP; }
|