| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_sig.c,v 1.307 2011/01/17 07:13:31 uebayasi Exp $ */ | | 1 | /* $NetBSD: kern_sig.c,v 1.308 2011/04/27 00:38:37 rmind Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -55,28 +55,32 @@ | | | @@ -55,28 +55,32 @@ |
55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
63 | * SUCH DAMAGE. | | 63 | * SUCH DAMAGE. |
64 | * | | 64 | * |
65 | * @(#)kern_sig.c 8.14 (Berkeley) 5/14/95 | | 65 | * @(#)kern_sig.c 8.14 (Berkeley) 5/14/95 |
66 | */ | | 66 | */ |
67 | | | 67 | |
| | | 68 | /* |
| | | 69 | * Signal subsystem. |
| | | 70 | */ |
| | | 71 | |
68 | #include <sys/cdefs.h> | | 72 | #include <sys/cdefs.h> |
69 | __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.307 2011/01/17 07:13:31 uebayasi Exp $"); | | 73 | __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.308 2011/04/27 00:38:37 rmind Exp $"); |
70 | | | 74 | |
71 | #include "opt_ptrace.h" | | 75 | #include "opt_ptrace.h" |
72 | #include "opt_compat_sunos.h" | | 76 | #include "opt_compat_sunos.h" |
73 | #include "opt_compat_netbsd.h" | | 77 | #include "opt_compat_netbsd.h" |
74 | #include "opt_compat_netbsd32.h" | | 78 | #include "opt_compat_netbsd32.h" |
75 | #include "opt_pax.h" | | 79 | #include "opt_pax.h" |
76 | #include "opt_sa.h" | | 80 | #include "opt_sa.h" |
77 | | | 81 | |
78 | #define SIGPROP /* include signal properties table */ | | 82 | #define SIGPROP /* include signal properties table */ |
79 | #include <sys/param.h> | | 83 | #include <sys/param.h> |
80 | #include <sys/signalvar.h> | | 84 | #include <sys/signalvar.h> |
81 | #include <sys/proc.h> | | 85 | #include <sys/proc.h> |
82 | #include <sys/systm.h> | | 86 | #include <sys/systm.h> |
| @@ -95,41 +99,48 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v | | | @@ -95,41 +99,48 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v |
95 | #include <sys/callout.h> | | 99 | #include <sys/callout.h> |
96 | #include <sys/atomic.h> | | 100 | #include <sys/atomic.h> |
97 | #include <sys/cpu.h> | | 101 | #include <sys/cpu.h> |
98 | #include <sys/module.h> | | 102 | #include <sys/module.h> |
99 | #include <sys/sdt.h> | | 103 | #include <sys/sdt.h> |
100 | | | 104 | |
101 | #ifdef PAX_SEGVGUARD | | 105 | #ifdef PAX_SEGVGUARD |
102 | #include <sys/pax.h> | | 106 | #include <sys/pax.h> |
103 | #endif /* PAX_SEGVGUARD */ | | 107 | #endif /* PAX_SEGVGUARD */ |
104 | | | 108 | |
105 | #include <uvm/uvm_extern.h> | | 109 | #include <uvm/uvm_extern.h> |
106 | #include <uvm/uvm_extern.h> | | 110 | #include <uvm/uvm_extern.h> |
107 | | | 111 | |
| | | 112 | static pool_cache_t sigacts_cache __read_mostly; |
| | | 113 | static pool_cache_t ksiginfo_cache __read_mostly; |
| | | 114 | static callout_t proc_stop_ch __cacheline_aligned; |
| | | 115 | |
| | | 116 | #ifdef KERN_SA |
| | | 117 | static pool_cache_t siginfo_cache; |
| | | 118 | #endif |
| | | 119 | |
| | | 120 | sigset_t contsigmask __cacheline_aligned; |
| | | 121 | static sigset_t stopsigmask __cacheline_aligned; |
| | | 122 | sigset_t sigcantmask __cacheline_aligned; |
| | | 123 | |
108 | static void ksiginfo_exechook(struct proc *, void *); | | 124 | static void ksiginfo_exechook(struct proc *, void *); |
109 | static void proc_stop_callout(void *); | | 125 | static void proc_stop_callout(void *); |
110 | static int sigchecktrace(void); | | 126 | static int sigchecktrace(void); |
111 | static int sigpost(struct lwp *, sig_t, int, int, int); | | 127 | static int sigpost(struct lwp *, sig_t, int, int, int); |
112 | static void sigput(sigpend_t *, struct proc *, ksiginfo_t *); | | 128 | static void sigput(sigpend_t *, struct proc *, ksiginfo_t *); |
113 | static int sigunwait(struct proc *, const ksiginfo_t *); | | 129 | static int sigunwait(struct proc *, const ksiginfo_t *); |
114 | static void sigswitch(bool, int, int); | | 130 | static void sigswitch(bool, int, int); |
115 | | | 131 | |
116 | sigset_t contsigmask, stopsigmask, sigcantmask; | | | |
117 | static pool_cache_t sigacts_cache; /* memory pool for sigacts structures */ | | | |
118 | static void sigacts_poolpage_free(struct pool *, void *); | | 132 | static void sigacts_poolpage_free(struct pool *, void *); |
119 | static void *sigacts_poolpage_alloc(struct pool *, int); | | 133 | static void *sigacts_poolpage_alloc(struct pool *, int); |
120 | static callout_t proc_stop_ch; | | | |
121 | static pool_cache_t siginfo_cache; | | | |
122 | static pool_cache_t ksiginfo_cache; | | | |
123 | | | 134 | |
124 | void (*sendsig_sigcontext_vec)(const struct ksiginfo *, const sigset_t *); | | 135 | void (*sendsig_sigcontext_vec)(const struct ksiginfo *, const sigset_t *); |
125 | int (*coredump_vec)(struct lwp *, const char *) = | | 136 | int (*coredump_vec)(struct lwp *, const char *) = |
126 | (int (*)(struct lwp *, const char *))enosys; | | 137 | (int (*)(struct lwp *, const char *))enosys; |
127 | | | 138 | |
128 | /* | | 139 | /* |
129 | * DTrace SDT provider definitions | | 140 | * DTrace SDT provider definitions |
130 | */ | | 141 | */ |
131 | SDT_PROBE_DEFINE(proc,,,signal_send, | | 142 | SDT_PROBE_DEFINE(proc,,,signal_send, |
132 | "struct lwp *", NULL, /* target thread */ | | 143 | "struct lwp *", NULL, /* target thread */ |
133 | "struct proc *", NULL, /* target process */ | | 144 | "struct proc *", NULL, /* target process */ |
134 | "int", NULL, /* signal */ | | 145 | "int", NULL, /* signal */ |
135 | NULL, NULL, NULL, NULL); | | 146 | NULL, NULL, NULL, NULL); |
| @@ -192,30 +203,30 @@ signal_listener_cb(kauth_cred_t cred, ka | | | @@ -192,30 +203,30 @@ signal_listener_cb(kauth_cred_t cred, ka |
192 | * signal_init: | | 203 | * signal_init: |
193 | * | | 204 | * |
194 | * Initialize global signal-related data structures. | | 205 | * Initialize global signal-related data structures. |
195 | */ | | 206 | */ |
196 | void | | 207 | void |
197 | signal_init(void) | | 208 | signal_init(void) |
198 | { | | 209 | { |
199 | | | 210 | |
200 | sigactspool_allocator.pa_pagesz = (PAGE_SIZE)*2; | | 211 | sigactspool_allocator.pa_pagesz = (PAGE_SIZE)*2; |
201 | | | 212 | |
202 | sigacts_cache = pool_cache_init(sizeof(struct sigacts), 0, 0, 0, | | 213 | sigacts_cache = pool_cache_init(sizeof(struct sigacts), 0, 0, 0, |
203 | "sigacts", sizeof(struct sigacts) > PAGE_SIZE ? | | 214 | "sigacts", sizeof(struct sigacts) > PAGE_SIZE ? |
204 | &sigactspool_allocator : NULL, IPL_NONE, NULL, NULL, NULL); | | 215 | &sigactspool_allocator : NULL, IPL_NONE, NULL, NULL, NULL); |
205 | | | 216 | #ifdef KERN_SA |
206 | siginfo_cache = pool_cache_init(sizeof(siginfo_t), 0, 0, 0, | | 217 | siginfo_cache = pool_cache_init(sizeof(siginfo_t), 0, 0, 0, |
207 | "siginfo", NULL, IPL_NONE, NULL, NULL, NULL); | | 218 | "siginfo", NULL, IPL_NONE, NULL, NULL, NULL); |
208 | | | 219 | #endif |
209 | ksiginfo_cache = pool_cache_init(sizeof(ksiginfo_t), 0, 0, 0, | | 220 | ksiginfo_cache = pool_cache_init(sizeof(ksiginfo_t), 0, 0, 0, |
210 | "ksiginfo", NULL, IPL_VM, NULL, NULL, NULL); | | 221 | "ksiginfo", NULL, IPL_VM, NULL, NULL, NULL); |
211 | | | 222 | |
212 | exechook_establish(ksiginfo_exechook, NULL); | | 223 | exechook_establish(ksiginfo_exechook, NULL); |
213 | | | 224 | |
214 | callout_init(&proc_stop_ch, CALLOUT_MPSAFE); | | 225 | callout_init(&proc_stop_ch, CALLOUT_MPSAFE); |
215 | callout_setfunc(&proc_stop_ch, proc_stop_callout, NULL); | | 226 | callout_setfunc(&proc_stop_ch, proc_stop_callout, NULL); |
216 | | | 227 | |
217 | signal_listener = kauth_listen_scope(KAUTH_SCOPE_PROCESS, | | 228 | signal_listener = kauth_listen_scope(KAUTH_SCOPE_PROCESS, |
218 | signal_listener_cb, NULL); | | 229 | signal_listener_cb, NULL); |
219 | } | | 230 | } |
220 | | | 231 | |
221 | /* | | 232 | /* |