- Propagate the signal mask from the ucontext_t to the newly created thread

as specified by _lwp_create(2)
- Reset the signal stack for threads created with _lwp_create(2)
This commit is contained in:
christos 2017-04-21 15:10:34 +00:00
parent e555bfe3f6
commit d7746f2ee3
12 changed files with 59 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_sched.c,v 1.68 2015/07/03 02:24:28 christos Exp $ */
/* $NetBSD: linux_sched.c,v 1.69 2017/04/21 15:10:34 christos Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.68 2015/07/03 02:24:28 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.69 2017/04/21 15:10:34 christos Exp $");
#include <sys/param.h>
#include <sys/mount.h>
@ -207,7 +207,8 @@ linux_clone_nptl(struct lwp *l, const struct linux_sys_clone_args *uap, register
}
error = lwp_create(l, p, uaddr, LWP_DETACHED | LWP_PIDLID,
SCARG(uap, stack), 0, child_return, NULL, &l2, l->l_class);
SCARG(uap, stack), 0, child_return, NULL, &l2, l->l_class,
&l->l_sigmask, &l->l_sigstk);
if (__predict_false(error)) {
DPRINTF(("%s: lwp_create error=%d\n", __func__, error));
atomic_dec_uint(&nprocs);

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_lwp.c,v 1.18 2015/05/15 07:56:25 matt Exp $ */
/* $NetBSD: netbsd32_lwp.c,v 1.19 2017/04/21 15:10:34 christos Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.18 2015/05/15 07:56:25 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.19 2017/04/21 15:10:34 christos Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -74,7 +74,11 @@ netbsd32__lwp_create(struct lwp *l, const struct netbsd32__lwp_create_args *uap,
if (error)
goto fail;
error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid);
const sigset_t *sigmask = newuc->uc_flags & _UC_SIGMASK ?
&newuc->uc_sigmask : &l->l_sigmask;
error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid, sigmask,
&SS_INIT);
if (error)
goto fail;

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.441 2017/01/25 17:57:14 christos Exp $ */
/* $NetBSD: kern_exec.c,v 1.442 2017/04/21 15:10:34 christos Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -59,7 +59,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.441 2017/01/25 17:57:14 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.442 2017/04/21 15:10:34 christos Exp $");
#include "opt_exec.h"
#include "opt_execfmt.h"
@ -2531,7 +2531,7 @@ do_posix_spawn(struct lwp *l1, pid_t *pid_res, bool *child_ok, const char *path,
/* create LWP */
lwp_create(l1, p2, uaddr, 0, NULL, 0, spawn_return, spawn_data,
&l2, l1->l_class);
&l2, l1->l_class, &l1->l_sigmask, &l1->l_sigstk);
l2->l_ctxlink = NULL; /* reset ucontext link */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_fork.c,v 1.201 2017/03/31 08:50:54 skrll Exp $ */
/* $NetBSD: kern_fork.c,v 1.202 2017/04/21 15:10:34 christos Exp $ */
/*-
* Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.201 2017/03/31 08:50:54 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.202 2017/04/21 15:10:34 christos Exp $");
#include "opt_ktrace.h"
#include "opt_dtrace.h"
@ -434,7 +434,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
*/
lwp_create(l1, p2, uaddr, (flags & FORK_PPWAIT) ? LWP_VFORK : 0,
stack, stacksize, (func != NULL) ? func : child_return, arg, &l2,
l1->l_class);
l1->l_class, &l1->l_sigmask, &l1->l_sigstk);
/*
* Inherit l_private from the parent.

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_kthread.c,v 1.41 2015/04/21 11:10:29 pooka Exp $ */
/* $NetBSD: kern_kthread.c,v 1.42 2017/04/21 15:10:34 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_kthread.c,v 1.41 2015/04/21 11:10:29 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_kthread.c,v 1.42 2017/04/21 15:10:34 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -82,7 +82,7 @@ kthread_create(pri_t pri, int flag, struct cpu_info *ci,
}
error = lwp_create(&lwp0, &proc0, uaddr, LWP_DETACHED, NULL,
0, func, arg, &l, lc);
0, func, arg, &l, lc, &lwp0.l_sigmask, &lwp0.l_sigstk);
if (error) {
uvm_uarea_system_free(uaddr);
return error;

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_lwp.c,v 1.187 2017/01/14 19:32:10 kamil Exp $ */
/* $NetBSD: kern_lwp.c,v 1.188 2017/04/21 15:10:34 christos Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -211,7 +211,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.187 2017/01/14 19:32:10 kamil Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.188 2017/04/21 15:10:34 christos Exp $");
#include "opt_ddb.h"
#include "opt_lockdebug.h"
@ -760,8 +760,9 @@ lwp_find_free_lid(lwpid_t try_lid, lwp_t * new_lwp, proc_t *p)
*/
int
lwp_create(lwp_t *l1, proc_t *p2, vaddr_t uaddr, int flags,
void *stack, size_t stacksize, void (*func)(void *), void *arg,
lwp_t **rnewlwpp, int sclass)
void *stack, size_t stacksize, void (*func)(void *), void *arg,
lwp_t **rnewlwpp, int sclass, const sigset_t *sigmask,
const stack_t *sigstk)
{
struct lwp *l2, *isfree;
turnstile_t *ts;
@ -904,8 +905,8 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_t uaddr, int flags,
} else
l2->l_prflag = 0;
l2->l_sigstk = l1->l_sigstk;
l2->l_sigmask = l1->l_sigmask;
l2->l_sigstk = *sigstk;
l2->l_sigmask = *sigmask;
TAILQ_INIT(&l2->l_sigpend.sp_info);
sigemptyset(&l2->l_sigpend.sp_set);

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_sig.c,v 1.335 2017/03/31 08:47:04 martin Exp $ */
/* $NetBSD: kern_sig.c,v 1.336 2017/04/21 15:10:35 christos Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.335 2017/03/31 08:47:04 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.336 2017/04/21 15:10:35 christos Exp $");
#include "opt_ptrace.h"
#include "opt_dtrace.h"
@ -347,9 +347,7 @@ siginit(struct proc *p)
*/
l = LIST_FIRST(&p->p_lwps);
l->l_sigwaited = NULL;
l->l_sigstk.ss_flags = SS_DISABLE;
l->l_sigstk.ss_size = 0;
l->l_sigstk.ss_sp = 0;
l->l_sigstk = SS_INIT;
ksiginfo_queue_init(&l->l_sigpend.sp_info);
sigemptyset(&l->l_sigpend.sp_set);
@ -417,9 +415,7 @@ execsigs(struct proc *p)
*/
l = LIST_FIRST(&p->p_lwps);
l->l_sigwaited = NULL;
l->l_sigstk.ss_flags = SS_DISABLE;
l->l_sigstk.ss_size = 0;
l->l_sigstk.ss_sp = 0;
l->l_sigstk = SS_INIT;
ksiginfo_queue_init(&l->l_sigpend.sp_info);
sigemptyset(&l->l_sigpend.sp_set);
mutex_exit(p->p_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_aio.c,v 1.41 2016/07/07 06:55:43 msaitoh Exp $ */
/* $NetBSD: sys_aio.c,v 1.42 2017/04/21 15:10:35 christos Exp $ */
/*
* Copyright (c) 2007 Mindaugas Rasiukevicius <rmind at NetBSD org>
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_aio.c,v 1.41 2016/07/07 06:55:43 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_aio.c,v 1.42 2017/04/21 15:10:35 christos Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@ -211,7 +211,7 @@ aio_procinit(struct proc *p)
return EAGAIN;
}
error = lwp_create(curlwp, p, uaddr, 0, NULL, 0, aio_worker,
NULL, &l, curlwp->l_class);
NULL, &l, curlwp->l_class, &curlwp->l_sigmask, &curlwp->l_sigstk);
if (error != 0) {
uvm_uarea_free(uaddr);
aio_exit(p, aio);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_lwp.c,v 1.58 2017/01/15 01:28:14 maya Exp $ */
/* $NetBSD: sys_lwp.c,v 1.59 2017/04/21 15:10:35 christos Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.58 2017/01/15 01:28:14 maya Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.59 2017/04/21 15:10:35 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -70,7 +70,8 @@ lwp_sys_init(void)
}
int
do_lwp_create(lwp_t *l, void *arg, u_long flags, lwpid_t *new_lwp)
do_lwp_create(lwp_t *l, void *arg, u_long flags, lwpid_t *new_lwp,
const sigset_t *sigmask, const stack_t *sigstk)
{
struct proc *p = l->l_proc;
struct lwp *l2;
@ -84,8 +85,8 @@ do_lwp_create(lwp_t *l, void *arg, u_long flags, lwpid_t *new_lwp)
if (__predict_false(uaddr == 0))
return ENOMEM;
error = lwp_create(l, p, uaddr, flags & LWP_DETACHED,
NULL, 0, p->p_emul->e_startlwp, arg, &l2, l->l_class);
error = lwp_create(l, p, uaddr, flags & LWP_DETACHED, NULL, 0,
p->p_emul->e_startlwp, arg, &l2, l->l_class, sigmask);
if (__predict_false(error)) {
uvm_uarea_free(uaddr);
return error;
@ -152,7 +153,10 @@ sys__lwp_create(struct lwp *l, const struct sys__lwp_create_args *uap,
if (error)
goto fail;
error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid);
const sigset_t *sigmask = newuc->uc_flags & _UC_SIGMASK ?
&newuc->uc_sigmask : &l->l_sigmask;
error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid, sigmask,
&SS_INIT);
if (error)
goto fail;

View File

@ -1,4 +1,4 @@
/* $NetBSD: threads.c,v 1.24 2016/01/26 23:12:18 pooka Exp $ */
/* $NetBSD: threads.c,v 1.25 2017/04/21 15:10:35 christos Exp $ */
/*
* Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved.
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.24 2016/01/26 23:12:18 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.25 2017/04/21 15:10:35 christos Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -293,8 +293,9 @@ lwpbouncer(void *arg)
int
lwp_create(struct lwp *l1, struct proc *p2, vaddr_t uaddr, int flags,
void *stack, size_t stacksize, void (*func)(void *), void *arg,
struct lwp **newlwpp, int sclass)
void *stack, size_t stacksize, void (*func)(void *), void *arg,
struct lwp **newlwpp, int sclass, const sigmask_t *sigmask,
const stack_t *sigstk)
{
struct thrdesc *td;
struct lwp *l;

View File

@ -1,4 +1,4 @@
/* $NetBSD: lwp.h,v 1.173 2017/04/08 00:25:50 kamil Exp $ */
/* $NetBSD: lwp.h,v 1.174 2017/04/21 15:10:35 christos Exp $ */
/*-
* Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010
@ -341,7 +341,8 @@ void lwp_need_userret(lwp_t *);
void lwp_free(lwp_t *, bool, bool);
uint64_t lwp_pctr(void);
int lwp_setprivate(lwp_t *, void *);
int do_lwp_create(lwp_t *, void *, u_long, lwpid_t *);
int do_lwp_create(lwp_t *, void *, u_long, lwpid_t *, const sigset_t *,
const stack_t *);
void lwpinit_specificdata(void);
int lwp_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
@ -422,8 +423,8 @@ lwp_eprio(lwp_t *l)
return MAX(l->l_auxprio, pri);
}
int lwp_create(lwp_t *, struct proc *, vaddr_t, int,
void *, size_t, void (*)(void *), void *, lwp_t **, int);
int lwp_create(lwp_t *, struct proc *, vaddr_t, int, void *, size_t,
void (*)(void *), void *, lwp_t **, int, const sigset_t *, const stack_t *);
/*
* XXX _MODULE

View File

@ -1,4 +1,4 @@
/* $NetBSD: signal.h,v 1.71 2016/08/04 06:43:43 christos Exp $ */
/* $NetBSD: signal.h,v 1.72 2017/04/21 15:10:35 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@ -170,6 +170,10 @@ struct sigaction {
#if defined(_NETBSD_SOURCE)
typedef void (*sig_t)(int); /* type of signal function */
#define SS_INIT /* Initializer for stack_t */ \
((stack_t) { .ss_sp = NULL, .ss_flags = SS_DISABLE, .ss_size = 0 })
#endif
#if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \