Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Pull signal actions out of struct user, make them a sepa...
details: https://anonhg.NetBSD.org/src/rev/929c8b8d06d1
branches: trunk
changeset: 472508:929c8b8d06d1
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Apr 30 21:23:49 1999 +0000
description:
Pull signal actions out of struct user, make them a separate proc
substructure, and allow them to be shared.
Required for clone(2).
diffstat:
sys/kern/init_main.c | 15 ++++++---
sys/kern/kern_exit.c | 7 +++-
sys/kern/kern_fork.c | 8 ++++-
sys/kern/kern_sig.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++-
sys/sys/signalvar.h | 10 +++++-
sys/sys/user.h | 3 +-
sys/uvm/uvm_glue.c | 9 +---
7 files changed, 118 insertions(+), 17 deletions(-)
diffs (286 lines):
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/kern/init_main.c
--- a/sys/kern/init_main.c Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/kern/init_main.c Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.148 1999/04/30 18:42:59 thorpej Exp $ */
+/* $NetBSD: init_main.c,v 1.149 1999/04/30 21:23:49 thorpej Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou. All rights reserved.
@@ -118,6 +118,7 @@
struct cwdinfo cwdi0;
struct plimit limit0;
struct vmspace vmspace0;
+struct sigacts sigacts0;
#ifndef curproc
struct proc *curproc = &proc0;
#endif
@@ -294,11 +295,10 @@
p->p_addr = proc0paddr; /* XXX */
/*
- * We continue to place resource usage info and signal
- * actions in the user struct so they're pageable.
+ * We continue to place resource usage info in the
+ * user struct so they're pageable.
*/
p->p_stats = &p->p_addr->u_stats;
- p->p_sigacts = &p->p_addr->u_sigacts;
/*
* Charge root for one process.
@@ -395,7 +395,12 @@
p->p_stats->p_start = runtime = mono_time = boottime = time;
p->p_rtime.tv_sec = p->p_rtime.tv_usec = 0;
- /* Initialize signal state for process 0. */
+ /*
+ * Initialize signal-related data structures, and signal state
+ * for proc0.
+ */
+ signal_init();
+ p->p_sigacts = &sigacts0;
siginit(p);
/* Create process 1 (init(8)). */
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/kern/kern_exit.c
--- a/sys/kern/kern_exit.c Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/kern/kern_exit.c Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_exit.c,v 1.66 1999/04/30 20:54:04 thorpej Exp $ */
+/* $NetBSD: kern_exit.c,v 1.67 1999/04/30 21:23:49 thorpej Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -301,6 +301,11 @@
}
/*
+ * Release the process's signal state.
+ */
+ sigactsfree(p);
+
+ /*
* Clear curproc after we've done all operations
* that could block, and before tearing down the rest
* of the process state that might be used from clock, etc.
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/kern/kern_fork.c Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.55 1999/04/30 18:42:59 thorpej Exp $ */
+/* $NetBSD: kern_fork.c,v 1.56 1999/04/30 21:23:49 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -58,6 +58,7 @@
#include <sys/ktrace.h>
#include <sys/vmmeter.h>
#include <sys/sched.h>
+#include <sys/signalvar.h>
#include <sys/syscallargs.h>
@@ -314,6 +315,11 @@
scheduler_fork_hook(p1, p2);
/*
+ * Create signal actions for the child process.
+ */
+ p2->p_sigacts = sigactsinit(p1);
+
+ /*
* This begins the section where we must prevent the parent
* from being swapped.
*/
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/kern/kern_sig.c Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_sig.c,v 1.88 1999/04/30 18:43:00 thorpej Exp $ */
+/* $NetBSD: kern_sig.c,v 1.89 1999/04/30 21:23:49 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -64,6 +64,8 @@
#include <sys/core.h>
#include <sys/ptrace.h>
#include <sys/filedesc.h>
+#include <sys/malloc.h>
+#include <sys/pool.h>
#include <sys/mount.h>
#include <sys/syscallargs.h>
@@ -80,6 +82,8 @@
sigset_t contsigmask, stopsigmask, sigcantmask;
+struct pool sigacts_pool; /* memory pool for sigacts structures */
+
/*
* Can process p, with pcred pc, send the signal signum to process q?
*/
@@ -91,6 +95,80 @@
(pc)->pc_ucred->cr_uid == (q)->p_ucred->cr_uid || \
((signum) == SIGCONT && (q)->p_session == (p)->p_session))
+/*
+ * Initialize signal-related data structures.
+ */
+void
+signal_init()
+{
+
+ pool_init(&sigacts_pool, sizeof(struct sigacts), 0, 0, 0, "sigapl",
+ 0, pool_page_alloc_nointr, pool_page_free_nointr, M_SUBPROC);
+}
+
+/*
+ * Create an initial sigacts structure, using the same signal state
+ * as p.
+ */
+struct sigacts *
+sigactsinit(p)
+ struct proc *p;
+{
+ struct sigacts *ps;
+
+ ps = pool_get(&sigacts_pool, PR_WAITOK);
+ memcpy(ps, p->p_sigacts, sizeof(struct sigacts));
+ ps->ps_refcnt = 1;
+ return (ps);
+}
+
+/*
+ * Make p2 share p1's sigacts.
+ */
+void
+sigactsshare(p1, p2)
+ struct proc *p1, *p2;
+{
+
+ p2->p_sigacts = p1->p_sigacts;
+ p1->p_sigacts->ps_refcnt++;
+}
+
+/*
+ * Make this process not share its sigacts, maintaining all
+ * signal state.
+ */
+void
+sigactsunshare(p)
+ struct proc *p;
+{
+ struct sigacts *newps;
+
+ if (p->p_sigacts->ps_refcnt == 1)
+ return;
+
+ newps = sigactsinit(p);
+ sigactsfree(p);
+ p->p_sigacts = newps;
+}
+
+/*
+ * Release a sigacts structure.
+ */
+void
+sigactsfree(p)
+ struct proc *p;
+{
+ struct sigacts *ps = p->p_sigacts;
+
+ if (--ps->ps_refcnt > 0)
+ return;
+
+ p->p_sigacts = NULL;
+
+ pool_put(&sigacts_pool, ps);
+}
+
int
sigaction1(p, signum, nsa, osa)
struct proc *p;
@@ -238,6 +316,9 @@
ps->ps_sigstk.ss_flags = SS_DISABLE;
ps->ps_sigstk.ss_size = 0;
ps->ps_sigstk.ss_sp = 0;
+
+ /* One reference. */
+ ps->ps_refcnt = 1;
}
/*
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/sys/signalvar.h
--- a/sys/sys/signalvar.h Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/sys/signalvar.h Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: signalvar.h,v 1.21 1998/10/03 14:29:02 drochner Exp $ */
+/* $NetBSD: signalvar.h,v 1.22 1999/04/30 21:23:50 thorpej Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -55,6 +55,7 @@
int ps_sig; /* for core dump/debugger XXX */
long ps_code; /* for core dump/debugger XXX */
void *ps_sigcode; /* address of signal trampoline */
+ int ps_refcnt; /* reference count */
};
/* signal flags */
@@ -162,6 +163,13 @@
int sigaltstack1 __P((struct proc *p, \
const struct sigaltstack *nss, struct sigaltstack *oss));
+void signal_init __P((void));
+
+struct sigacts *sigactsinit __P((struct proc *));
+void sigactsshare __P((struct proc *, struct proc *));
+void sigactsunshare __P((struct proc *));
+void sigactsfree __P((struct proc *));
+
/*
* Machine-dependent functions:
*/
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/sys/user.h
--- a/sys/sys/user.h Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/sys/user.h Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: user.h,v 1.12 1997/10/16 02:32:55 mycroft Exp $ */
+/* $NetBSD: user.h,v 1.13 1999/04/30 21:23:50 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -61,7 +61,6 @@
struct user {
struct pcb u_pcb;
- struct sigacts u_sigacts; /* p_sigacts points here (use it!) */
struct pstats u_stats; /* p_stats points here (use it!) */
};
diff -r 4f76aacf91c3 -r 929c8b8d06d1 sys/uvm/uvm_glue.c
--- a/sys/uvm/uvm_glue.c Fri Apr 30 21:09:50 1999 +0000
+++ b/sys/uvm/uvm_glue.c Fri Apr 30 21:23:49 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_glue.c,v 1.18 1999/03/26 21:58:39 mycroft Exp $ */
+/* $NetBSD: uvm_glue.c,v 1.19 1999/04/30 21:23:50 thorpej Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -288,13 +288,10 @@
panic("uvm_fork: uvm_fault_wire failed: %d", rv);
/*
- * p_stats and p_sigacts currently point at fields in the user
- * struct but not at &u, instead at p_addr. Copy p_sigacts and
- * parts of p_stats; zero the rest of p_stats (statistics).
+ * p_stats currently points at a field in the user struct. Copy
+ * parts of p_stats, and zero out the rest.
*/
p2->p_stats = &up->u_stats;
- p2->p_sigacts = &up->u_sigacts;
- up->u_sigacts = *p1->p_sigacts;
memset(&up->u_stats.pstat_startzero, 0,
(unsigned) ((caddr_t)&up->u_stats.pstat_endzero -
(caddr_t)&up->u_stats.pstat_startzero));
Home |
Main Index |
Thread Index |
Old Index