1 /* $NetBSD: osf1_signal.c,v 1.34 2007/12/20 23:03:03 dsl Exp $ */
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
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>
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>
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
)
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
);
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
;
78 if (SCARG(uap
, signum
) < 0 || SCARG(uap
, signum
) > OSF1_NSIG
)
80 nosa
= SCARG(uap
, nsa
);
81 oosa
= SCARG(uap
, osa
);
84 if ((error
= copyin(nosa
, &tmposa
, sizeof(tmposa
))) != 0)
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
),
97 osf1_cvt_sigaction_from_native(&obsa
, &tmposa
);
98 if ((error
= copyout(&tmposa
, oosa
, sizeof(tmposa
))) != 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
);
115 osf1_sys_signal(struct lwp
*l
, const struct osf1_sys_signal_args
*uap
, register_t
*retval
)
117 struct proc
*p
= l
->l_proc
;
121 if (SCARG(uap
, signum
) < 0 || SCARG(uap
, signum
) > OSF1_NSIG
)
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
;
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
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
);
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
);
156 if (signum
!= SIGALRM
)
157 nbsa
.sa_flags
= SA_RESTART
;
159 error
= sigaction1(l
, signum
, &nbsa
, &obsa
, ?, ?);
161 DPRINTF(("signal: sigaction failed: %d\n",
163 *retval
= (int)OSF1_SIG_ERR
;
166 *retval
= (int)obsa
.sa_handler
;
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
);
196 if ((error
= sigaction1(l
, &bsa
, NULL
, ?, ?)) != 0) {
197 DPRINTF(("sigignore: sigaction failed\n"));
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
);
217 osf1_sys_sigpending(struct lwp
*l
, const struct osf1_sys_sigpending_args
*uap
, register_t
*retval
)
219 struct proc
*p
= l
->l_proc
;
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
;
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)
244 if (SCARG(uap
, set
) == NULL
)
248 if ((error
= copyin(SCARG(uap
, set
), &oss
, sizeof(oss
))) != 0)
251 osf1_cvt_sigset_to_native(&oss
, &bss
);
253 mutex_enter(p
->p_lock
);
255 switch (SCARG(uap
, how
)) {
257 *l
->l_sigmask
|= bss
& ~sigcantmask
;
260 case OSF1_SIG_UNBLOCK
:
261 *l
->l_sigmask
&= ~bss
;
263 l
->l_flag
|= LW_PENDSIG
;
267 case OSF1_SIG_SETMASK
:
268 *l
->l_sigmask
= bss
& ~sigcantmask
;
270 l
->l_flag
|= LW_PENDSIG
;
279 mutex_exit(p
->p_lock
);
285 osf1_sys_sigsuspend(struct lwp
*l
, const struct osf1_sys_sigsuspend_args
*uap
, register_t
*retval
)
289 struct sys_sigsuspend_args sa
;
292 if ((error
= copyin(SCARG(uap
, ss
), &oss
, sizeof(oss
))) != 0)
295 osf1_cvt_sigset_to_native(&oss
, &bss
);
297 SCARG(&sa
, mask
) = bss
;
298 return sys_sigsuspend(l
, &sa
, retval
);