mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
linux: Add clone3 CLONE_CLEAR_SIGHAND optimization to posix_spawn
The clone3 flag resets all signal handlers of the child not set to SIG_IGN to SIG_DFL. It allows to skip most of the sigaction calls to setup child signal handling, where previously a posix_spawn had to issue 2 times NSIG sigaction calls (one to obtain the current disposition and another to set either SIG_DFL or SIG_IGN). With POSIX_SPAWN_SETSIGDEF the child will setup the signal for the case where the disposition is SIG_IGN. The code must handle the fallback where clone3 is not available. This is done by splitting __clone_internal_fallback from __clone_internal. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
committed by
Adhemerval Zanella
parent
2290cf73cc
commit
2053c11331
@ -44,27 +44,15 @@ _Static_assert (sizeof (struct clone_args) == CLONE_ARGS_SIZE_VER2,
|
||||
"sizeof (struct clone_args) != CLONE_ARGS_SIZE_VER2");
|
||||
|
||||
int
|
||||
__clone_internal (struct clone_args *cl_args,
|
||||
int (*func) (void *arg), void *arg)
|
||||
__clone_internal_fallback (struct clone_args *cl_args,
|
||||
int (*func) (void *arg), void *arg)
|
||||
{
|
||||
int ret;
|
||||
#ifdef HAVE_CLONE3_WRAPPER
|
||||
/* Try clone3 first. */
|
||||
int saved_errno = errno;
|
||||
ret = __clone3 (cl_args, sizeof (*cl_args), func, arg);
|
||||
if (ret != -1 || errno != ENOSYS)
|
||||
return ret;
|
||||
|
||||
/* NB: Restore errno since errno may be checked against non-zero
|
||||
return value. */
|
||||
__set_errno (saved_errno);
|
||||
#endif
|
||||
|
||||
/* Map clone3 arguments to clone arguments. NB: No need to check
|
||||
invalid clone3 specific bits in flags nor exit_signal since this
|
||||
is an internal function. */
|
||||
int flags = cl_args->flags | cl_args->exit_signal;
|
||||
void *stack = cast_to_pointer (cl_args->stack);
|
||||
int ret;
|
||||
|
||||
#ifdef __ia64__
|
||||
ret = __clone2 (func, stack, cl_args->stack_size,
|
||||
@ -88,4 +76,23 @@ __clone_internal (struct clone_args *cl_args,
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
__clone_internal (struct clone_args *cl_args,
|
||||
int (*func) (void *arg), void *arg)
|
||||
{
|
||||
#ifdef HAVE_CLONE3_WRAPPER
|
||||
int saved_errno = errno;
|
||||
int ret = __clone3 (cl_args, sizeof (*cl_args), func, arg);
|
||||
if (ret != -1 || errno != ENOSYS)
|
||||
return ret;
|
||||
|
||||
/* NB: Restore errno since errno may be checked against non-zero
|
||||
return value. */
|
||||
__set_errno (saved_errno);
|
||||
#endif
|
||||
|
||||
return __clone_internal_fallback (cl_args, func, arg);
|
||||
}
|
||||
|
||||
libc_hidden_def (__clone_internal)
|
||||
|
Reference in New Issue
Block a user