Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / compat / osf1 / osf1_signal.c
blob30a19216554ca68ab1809c9730dfe1c346ea640e
1 /* $NetBSD: osf1_signal.c,v 1.34 2007/12/20 23:03:03 dsl Exp $ */
3 /*
4 * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Christopher G. Demetriou
17 * for the NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: osf1_signal.c,v 1.34 2007/12/20 23:03:03 dsl Exp $");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/namei.h>
39 #include <sys/proc.h>
40 #include <sys/filedesc.h>
41 #include <sys/ioctl.h>
42 #include <sys/mount.h>
43 #include <sys/kernel.h>
44 #include <sys/signal.h>
45 #include <sys/signalvar.h>
46 #include <sys/malloc.h>
48 #include <sys/syscallargs.h>
50 #include <compat/osf1/osf1.h>
51 #include <compat/osf1/osf1_signal.h>
52 #include <compat/osf1/osf1_syscallargs.h>
53 #include <compat/common/compat_util.h>
54 #include <compat/common/compat_sigaltstack.h>
55 #include <compat/osf1/osf1_cvt.h>
57 #if 0
58 int
59 osf1_sys_kill(struct lwp *l, const struct osf1_sys_kill_args *uap, register_t *retval)
61 struct sys_kill_args ka;
63 if (SCARG(uap, signum) < 0 || SCARG(uap, signum) > OSF1_NSIG)
64 return EINVAL;
65 SCARG(&ka, pid) = SCARG(uap, pid);
66 SCARG(&ka, signum) = osf1_to_native_signo[SCARG(uap, signum)];
67 return sys_kill(l, &ka, retval);
69 #endif
71 int
72 osf1_sys_sigaction(struct lwp *l, const struct osf1_sys_sigaction_args *uap, register_t *retval)
74 struct osf1_sigaction *nosa, *oosa, tmposa;
75 struct sigaction nbsa, obsa;
76 int error;
78 if (SCARG(uap, signum) < 0 || SCARG(uap, signum) > OSF1_NSIG)
79 return EINVAL;
80 nosa = SCARG(uap, nsa);
81 oosa = SCARG(uap, osa);
83 if (nosa != NULL) {
84 if ((error = copyin(nosa, &tmposa, sizeof(tmposa))) != 0)
85 return error;
86 osf1_cvt_sigaction_to_native(&tmposa, &nbsa);
89 if ((error = sigaction1(l,
90 osf1_to_native_signo[SCARG(uap, signum)],
91 (nosa ? &nbsa : NULL),
92 (oosa ? &obsa : NULL),
93 NULL, 0)) != 0)
94 return error;
96 if (oosa != NULL) {
97 osf1_cvt_sigaction_from_native(&obsa, &tmposa);
98 if ((error = copyout(&tmposa, oosa, sizeof(tmposa))) != 0)
99 return error;
102 return 0;
106 osf1_sys_sigaltstack(struct lwp *l, const struct osf1_sys_sigaltstack_args *uap, register_t *retval)
108 /* We silently ignore OSF1_SS_NOMASK and OSF1_SS_UCONTEXT */
109 compat_sigaltstack(uap, osf1_sigaltstack,
110 OSF1_SS_ONSTACK, OSF1_SS_DISABLE);
113 #if 0
115 osf1_sys_signal(struct lwp *l, const struct osf1_sys_signal_args *uap, register_t *retval)
117 struct proc *p = l->l_proc;
118 int signum;
119 int error;
121 if (SCARG(uap, signum) < 0 || SCARG(uap, signum) > OSF1_NSIG)
122 return EINVAL;
123 signum = osf1_to_native_signo[OSF1_SIGNO(SCARG(uap, signum))];
124 if (signum <= 0 || signum >= OSF1_NSIG) {
125 if (OSF1_SIGCALL(SCARG(uap, signum)) == OSF1_SIGNAL_MASK ||
126 OSF1_SIGCALL(SCARG(uap, signum)) == OSF1_SIGDEFER_MASK)
127 *retval = (int)OSF1_SIG_ERR;
128 return EINVAL;
131 switch (OSF1_SIGCALL(SCARG(uap, signum))) {
132 case OSF1_SIGDEFER_MASK:
134 * sigset is identical to signal() except
135 * that SIG_HOLD is allowed as
136 * an action.
138 if (SCARG(uap, handler) == OSF1_SIG_HOLD) {
139 struct sys_sigprocmask_args sa;
141 SCARG(&sa, how) = SIG_BLOCK;
142 SCARG(&sa, mask) = sigmask(signum);
143 return sys_sigprocmask(l, &sa, retval);
145 /* FALLTHROUGH */
147 case OSF1_SIGNAL_MASK:
149 struct sys_sigaction_args sa_args;
150 struct sigaction nbsa, obsa;
152 nbsa.sa_handler = SCARG(uap, handler);
153 sigemptyset(&nbsa.sa_mask);
154 nbsa.sa_flags = 0;
155 #if 0
156 if (signum != SIGALRM)
157 nbsa.sa_flags = SA_RESTART;
158 #endif
159 error = sigaction1(l, signum, &nbsa, &obsa, ?, ?);
160 if (error != 0) {
161 DPRINTF(("signal: sigaction failed: %d\n",
162 error));
163 *retval = (int)OSF1_SIG_ERR;
164 return error;
166 *retval = (int)obsa.sa_handler;
167 return 0;
170 case OSF1_SIGHOLD_MASK:
172 struct sys_sigprocmask_args sa;
174 SCARG(&sa, how) = SIG_BLOCK;
175 SCARG(&sa, mask) = sigmask(signum);
176 return sys_sigprocmask(l, &sa, retval);
179 case OSF1_SIGRELSE_MASK:
181 struct sys_sigprocmask_args sa;
183 SCARG(&sa, how) = SIG_UNBLOCK;
184 SCARG(&sa, mask) = sigmask(signum);
185 return sys_sigprocmask(l, &sa, retval);
188 case OSF1_SIGIGNORE_MASK:
190 struct sys_sigaction_args sa_args;
191 struct sigaction bsa;
193 bsa.sa_handler = SIG_IGN;
194 sigemptyset(&bsa.sa_mask);
195 bsa.sa_flags = 0;
196 if ((error = sigaction1(l, &bsa, NULL, ?, ?)) != 0) {
197 DPRINTF(("sigignore: sigaction failed\n"));
198 return error;
200 return 0;
203 case OSF1_SIGPAUSE_MASK:
205 struct sys_sigsuspend_args sa;
207 SCARG(&sa, mask) = p->p_sigmask & ~sigmask(signum);
208 return sys_sigsuspend(l, &sa, retval);
211 default:
212 return ENOSYS;
217 osf1_sys_sigpending(struct lwp *l, const struct osf1_sys_sigpending_args *uap, register_t *retval)
219 struct proc *p = l->l_proc;
220 sigset_t bss;
221 osf1_sigset_t oss;
223 bss = p->p_siglist & p->p_sigmask;
224 osf1_cvt_sigset_from_native(&bss, &oss);
226 return copyout(&oss, SCARG(uap, mask), sizeof(oss));
230 osf1_sys_sigprocmask(struct lwp *l, const struct osf1_sys_sigprocmask_args *uap, register_t *retval)
232 struct proc *p = l->l_proc;
233 osf1_sigset_t oss;
234 sigset_t bss;
235 int error = 0;
237 if (SCARG(uap, oset) != NULL) {
238 /* Fix the return value first if needed */
239 osf1_cvt_sigset_from_native(&p->p_sigmask, &oss);
240 if ((error = copyout(&oss, SCARG(uap, oset), sizeof(oss))) != 0)
241 return error;
244 if (SCARG(uap, set) == NULL)
245 /* Just examine */
246 return 0;
248 if ((error = copyin(SCARG(uap, set), &oss, sizeof(oss))) != 0)
249 return error;
251 osf1_cvt_sigset_to_native(&oss, &bss);
253 mutex_enter(p->p_lock);
255 switch (SCARG(uap, how)) {
256 case OSF1_SIG_BLOCK:
257 *l->l_sigmask |= bss & ~sigcantmask;
258 break;
260 case OSF1_SIG_UNBLOCK:
261 *l->l_sigmask &= ~bss;
262 lwp_lock(l);
263 l->l_flag |= LW_PENDSIG;
264 lwp_unlock(l);
265 break;
267 case OSF1_SIG_SETMASK:
268 *l->l_sigmask = bss & ~sigcantmask;
269 lwp_lock(l);
270 l->l_flag |= LW_PENDSIG;
271 lwp_unlock(l);
272 break;
274 default:
275 error = EINVAL;
276 break;
279 mutex_exit(p->p_lock);
281 return error;
285 osf1_sys_sigsuspend(struct lwp *l, const struct osf1_sys_sigsuspend_args *uap, register_t *retval)
287 osf1_sigset_t oss;
288 sigset_t bss;
289 struct sys_sigsuspend_args sa;
290 int error;
292 if ((error = copyin(SCARG(uap, ss), &oss, sizeof(oss))) != 0)
293 return error;
295 osf1_cvt_sigset_to_native(&oss, &bss);
297 SCARG(&sa, mask) = bss;
298 return sys_sigsuspend(l, &sa, retval);
300 #endif