kern_sig_13.c revision 1.16 1 1.16 dsl /* $NetBSD: kern_sig_13.c,v 1.16 2007/12/08 18:35:54 dsl Exp $ */
2 1.1 kleink
3 1.1 kleink /*-
4 1.3 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1 kleink * All rights reserved.
6 1.1 kleink *
7 1.1 kleink * This code is derived from software contributed to The NetBSD Foundation
8 1.3 mycroft * by Charles M. Hannum.
9 1.1 kleink *
10 1.1 kleink * Redistribution and use in source and binary forms, with or without
11 1.1 kleink * modification, are permitted provided that the following conditions
12 1.1 kleink * are met:
13 1.1 kleink * 1. Redistributions of source code must retain the above copyright
14 1.1 kleink * notice, this list of conditions and the following disclaimer.
15 1.1 kleink * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 kleink * notice, this list of conditions and the following disclaimer in the
17 1.1 kleink * documentation and/or other materials provided with the distribution.
18 1.1 kleink * 3. All advertising materials mentioning features or use of this software
19 1.1 kleink * must display the following acknowledgement:
20 1.1 kleink * This product includes software developed by the NetBSD
21 1.1 kleink * Foundation, Inc. and its contributors.
22 1.1 kleink * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 kleink * contributors may be used to endorse or promote products derived
24 1.1 kleink * from this software without specific prior written permission.
25 1.1 kleink *
26 1.1 kleink * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 kleink * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 kleink * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 kleink * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 kleink * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 kleink * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 kleink * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 kleink * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 kleink * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 kleink * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 kleink * POSSIBILITY OF SUCH DAMAGE.
37 1.1 kleink */
38 1.6 lukem
39 1.6 lukem #include <sys/cdefs.h>
40 1.16 dsl __KERNEL_RCSID(0, "$NetBSD: kern_sig_13.c,v 1.16 2007/12/08 18:35:54 dsl Exp $");
41 1.1 kleink
42 1.1 kleink #include <sys/param.h>
43 1.1 kleink #include <sys/proc.h>
44 1.1 kleink #include <sys/signal.h>
45 1.3 mycroft #include <sys/signalvar.h>
46 1.1 kleink #include <sys/systm.h>
47 1.1 kleink
48 1.1 kleink #include <sys/mount.h>
49 1.1 kleink #include <sys/syscallargs.h>
50 1.1 kleink
51 1.2 kleink #include <machine/limits.h>
52 1.2 kleink
53 1.10 christos #include <compat/sys/signal.h>
54 1.10 christos #include <compat/sys/signalvar.h>
55 1.1 kleink #include <compat/common/compat_util.h>
56 1.15 dsl #include <compat/common/compat_sigaltstack.h>
57 1.3 mycroft
58 1.3 mycroft void
59 1.16 dsl native_sigset13_to_sigset(const sigset13_t *oss, sigset_t *ss)
60 1.3 mycroft {
61 1.3 mycroft
62 1.3 mycroft ss->__bits[0] = *oss;
63 1.3 mycroft ss->__bits[1] = 0;
64 1.3 mycroft ss->__bits[2] = 0;
65 1.3 mycroft ss->__bits[3] = 0;
66 1.3 mycroft }
67 1.3 mycroft
68 1.3 mycroft void
69 1.16 dsl native_sigset_to_sigset13(const sigset_t *ss, sigset13_t *oss)
70 1.3 mycroft {
71 1.3 mycroft
72 1.3 mycroft *oss = ss->__bits[0];
73 1.3 mycroft }
74 1.3 mycroft
75 1.3 mycroft void
76 1.16 dsl native_sigaction13_to_sigaction(const struct sigaction13 *osa, struct sigaction *sa)
77 1.3 mycroft {
78 1.3 mycroft
79 1.8 christos sa->sa_handler = osa->osa_handler;
80 1.8 christos native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask);
81 1.8 christos sa->sa_flags = osa->osa_flags;
82 1.3 mycroft }
83 1.3 mycroft
84 1.3 mycroft void
85 1.16 dsl native_sigaction_to_sigaction13(const struct sigaction *sa, struct sigaction13 *osa)
86 1.3 mycroft {
87 1.3 mycroft
88 1.8 christos osa->osa_handler = sa->sa_handler;
89 1.8 christos native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask);
90 1.8 christos osa->osa_flags = sa->sa_flags;
91 1.3 mycroft }
92 1.3 mycroft
93 1.1 kleink int
94 1.13 christos compat_13_sys_sigaltstack(struct lwp *l, void *v, register_t *retval)
95 1.1 kleink {
96 1.1 kleink struct compat_13_sys_sigaltstack_args /* {
97 1.1 kleink syscallarg(const struct sigaltstack13 *) nss;
98 1.1 kleink syscallarg(struct sigaltstack13 *) oss;
99 1.1 kleink } */ *uap = v;
100 1.15 dsl compat_sigaltstack(uap, sigaltstack13, SS_ONSTACK, SS_DISABLE);
101 1.3 mycroft }
102 1.1 kleink
103 1.3 mycroft int
104 1.13 christos compat_13_sys_sigaction(struct lwp *l, void *v, register_t *retval)
105 1.3 mycroft {
106 1.3 mycroft struct compat_13_sys_sigaction_args /* {
107 1.3 mycroft syscallarg(int) signum;
108 1.3 mycroft syscallarg(const struct sigaction13 *) nsa;
109 1.3 mycroft syscallarg(struct sigaction13 *) osa;
110 1.3 mycroft } */ *uap = v;
111 1.3 mycroft struct sigaction13 nesa, oesa;
112 1.3 mycroft struct sigaction nbsa, obsa;
113 1.3 mycroft int error;
114 1.1 kleink
115 1.3 mycroft if (SCARG(uap, nsa)) {
116 1.3 mycroft error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
117 1.3 mycroft if (error)
118 1.1 kleink return (error);
119 1.3 mycroft native_sigaction13_to_sigaction(&nesa, &nbsa);
120 1.3 mycroft }
121 1.14 ad error = sigaction1(l, SCARG(uap, signum),
122 1.7 thorpej SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
123 1.7 thorpej NULL, 0);
124 1.3 mycroft if (error)
125 1.3 mycroft return (error);
126 1.3 mycroft if (SCARG(uap, osa)) {
127 1.3 mycroft native_sigaction_to_sigaction13(&obsa, &oesa);
128 1.3 mycroft error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
129 1.3 mycroft if (error)
130 1.1 kleink return (error);
131 1.3 mycroft }
132 1.3 mycroft return (0);
133 1.3 mycroft }
134 1.1 kleink
135 1.3 mycroft int
136 1.9 thorpej compat_13_sys_sigprocmask(struct lwp *l, void *v, register_t *retval)
137 1.3 mycroft {
138 1.3 mycroft struct compat_13_sys_sigprocmask_args /* {
139 1.3 mycroft syscallarg(int) how;
140 1.3 mycroft syscallarg(int) mask;
141 1.3 mycroft } */ *uap = v;
142 1.9 thorpej struct proc *p = l->l_proc;
143 1.3 mycroft sigset13_t ness, oess;
144 1.3 mycroft sigset_t nbss, obss;
145 1.3 mycroft int error;
146 1.1 kleink
147 1.3 mycroft ness = SCARG(uap, mask);
148 1.3 mycroft native_sigset13_to_sigset(&ness, &nbss);
149 1.14 ad mutex_enter(&p->p_smutex);
150 1.14 ad error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss);
151 1.14 ad mutex_exit(&p->p_smutex);
152 1.3 mycroft if (error)
153 1.1 kleink return (error);
154 1.3 mycroft native_sigset_to_sigset13(&obss, &oess);
155 1.3 mycroft *retval = oess;
156 1.3 mycroft return (0);
157 1.3 mycroft }
158 1.1 kleink
159 1.3 mycroft int
160 1.13 christos compat_13_sys_sigpending(struct lwp *l, void *v, register_t *retval)
161 1.3 mycroft {
162 1.3 mycroft sigset13_t ess;
163 1.3 mycroft sigset_t bss;
164 1.1 kleink
165 1.14 ad sigpending1(l, &bss);
166 1.3 mycroft native_sigset_to_sigset13(&bss, &ess);
167 1.3 mycroft *retval = ess;
168 1.1 kleink return (0);
169 1.3 mycroft }
170 1.3 mycroft
171 1.3 mycroft int
172 1.13 christos compat_13_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
173 1.3 mycroft {
174 1.3 mycroft struct compat_13_sys_sigsuspend_args /* {
175 1.3 mycroft syscallarg(sigset13_t) mask;
176 1.3 mycroft } */ *uap = v;
177 1.3 mycroft sigset13_t ess;
178 1.3 mycroft sigset_t bss;
179 1.3 mycroft
180 1.3 mycroft ess = SCARG(uap, mask);
181 1.3 mycroft native_sigset13_to_sigset(&ess, &bss);
182 1.14 ad return (sigsuspend1(l, &bss));
183 1.1 kleink }
184