2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1995 Scott Bartram
5 * Copyright (c) 1995 Steven Wallace
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/mutex.h>
38 #include <sys/signalvar.h>
39 #include <sys/syscallsubr.h>
40 #include <sys/sysproto.h>
42 #include <i386/ibcs2/ibcs2_types.h>
43 #include <i386/ibcs2/ibcs2_signal.h>
44 #include <i386/ibcs2/ibcs2_proto.h>
45 #include <i386/ibcs2/ibcs2_xenix.h>
46 #include <i386/ibcs2/ibcs2_util.h>
48 #define sigemptyset(s) SIGEMPTYSET(*(s))
49 #define sigismember(s, n) SIGISMEMBER(*(s), n)
50 #define sigaddset(s, n) SIGADDSET(*(s), n)
52 #define ibcs2_sigmask(n) (1 << ((n) - 1))
53 #define ibcs2_sigemptyset(s) bzero((s), sizeof(*(s)))
54 #define ibcs2_sigismember(s, n) (*(s) & ibcs2_sigmask(n))
55 #define ibcs2_sigaddset(s, n) (*(s) |= ibcs2_sigmask(n))
57 static void ibcs2_to_bsd_sigset(const ibcs2_sigset_t *, sigset_t *);
58 static void bsd_to_ibcs2_sigset(const sigset_t *, ibcs2_sigset_t *);
59 static void ibcs2_to_bsd_sigaction(struct ibcs2_sigaction *,
61 static void bsd_to_ibcs2_sigaction(struct sigaction *,
62 struct ibcs2_sigaction *);
64 int bsd_to_ibcs2_sig[IBCS2_SIGTBLSZ] = {
67 IBCS2_SIGQUIT, /* 3 */
69 IBCS2_SIGTRAP, /* 5 */
70 IBCS2_SIGABRT, /* 6 */
73 IBCS2_SIGKILL, /* 9 */
74 IBCS2_SIGBUS, /* 10 */
75 IBCS2_SIGSEGV, /* 11 */
76 IBCS2_SIGSYS, /* 12 */
77 IBCS2_SIGPIPE, /* 13 */
78 IBCS2_SIGALRM, /* 14 */
79 IBCS2_SIGTERM, /* 15 */
81 IBCS2_SIGSTOP, /* 17 */
82 IBCS2_SIGTSTP, /* 18 */
83 IBCS2_SIGCONT, /* 19 */
84 IBCS2_SIGCLD, /* 20 */
85 IBCS2_SIGTTIN, /* 21 */
86 IBCS2_SIGTTOU, /* 22 */
87 IBCS2_SIGPOLL, /* 23 */
90 IBCS2_SIGVTALRM, /* 26 */
91 IBCS2_SIGPROF, /* 27 */
92 IBCS2_SIGWINCH, /* 28 */
94 IBCS2_SIGUSR1, /* 30 */
95 IBCS2_SIGUSR2, /* 31 */
99 static int ibcs2_to_bsd_sig[IBCS2_SIGTBLSZ] = {
135 ibcs2_to_bsd_sigset(iss, bss)
136 const ibcs2_sigset_t *iss;
142 for (i = 1; i <= IBCS2_SIGTBLSZ; i++) {
143 if (ibcs2_sigismember(iss, i)) {
144 newsig = ibcs2_to_bsd_sig[_SIG_IDX(i)];
146 sigaddset(bss, newsig);
152 bsd_to_ibcs2_sigset(bss, iss)
158 ibcs2_sigemptyset(iss);
159 for (i = 1; i <= IBCS2_SIGTBLSZ; i++) {
160 if (sigismember(bss, i)) {
161 newsig = bsd_to_ibcs2_sig[_SIG_IDX(i)];
163 ibcs2_sigaddset(iss, newsig);
169 ibcs2_to_bsd_sigaction(isa, bsa)
170 struct ibcs2_sigaction *isa;
171 struct sigaction *bsa;
174 bsa->sa_handler = isa->isa_handler;
175 ibcs2_to_bsd_sigset(&isa->isa_mask, &bsa->sa_mask);
176 bsa->sa_flags = 0; /* ??? SA_NODEFER */
177 if ((isa->isa_flags & IBCS2_SA_NOCLDSTOP) != 0)
178 bsa->sa_flags |= SA_NOCLDSTOP;
182 bsd_to_ibcs2_sigaction(bsa, isa)
183 struct sigaction *bsa;
184 struct ibcs2_sigaction *isa;
187 isa->isa_handler = bsa->sa_handler;
188 bsd_to_ibcs2_sigset(&bsa->sa_mask, &isa->isa_mask);
190 if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
191 isa->isa_flags |= IBCS2_SA_NOCLDSTOP;
195 ibcs2_sigaction(struct thread *td, struct ibcs2_sigaction_args *uap)
197 struct ibcs2_sigaction isa;
198 struct sigaction nbsa, obsa;
199 struct sigaction *nbsap;
202 if (uap->act != NULL) {
203 if ((error = copyin(uap->act, &isa, sizeof(isa))) != 0)
205 ibcs2_to_bsd_sigaction(&isa, &nbsa);
209 if (uap->sig <= 0 || uap->sig > IBCS2_NSIG)
211 error = kern_sigaction(td, ibcs2_to_bsd_sig[_SIG_IDX(uap->sig)], &nbsa,
213 if (error == 0 && uap->oact != NULL) {
214 bsd_to_ibcs2_sigaction(&obsa, &isa);
215 error = copyout(&isa, uap->oact, sizeof(isa));
221 ibcs2_sigsys(struct thread *td, struct ibcs2_sigsys_args *uap)
223 struct proc *p = td->td_proc;
225 int signum = IBCS2_SIGNO(uap->sig);
228 if (signum <= 0 || signum > IBCS2_NSIG) {
229 if (IBCS2_SIGCALL(uap->sig) == IBCS2_SIGNAL_MASK ||
230 IBCS2_SIGCALL(uap->sig) == IBCS2_SIGSET_MASK)
231 td->td_retval[0] = (int)IBCS2_SIG_ERR;
234 signum = ibcs2_to_bsd_sig[_SIG_IDX(signum)];
236 switch (IBCS2_SIGCALL(uap->sig)) {
237 case IBCS2_SIGSET_MASK:
239 * Check for SIG_HOLD action.
240 * Otherwise, perform signal() except with different sa_flags.
242 if (uap->fp != IBCS2_SIG_HOLD) {
243 /* add sig to mask before exececuting signal handler */
247 /* else FALLTHROUGH to sighold */
249 case IBCS2_SIGHOLD_MASK:
254 SIGADDSET(mask, signum);
255 return (kern_sigprocmask(td, SIG_BLOCK, &mask, NULL,
259 case IBCS2_SIGNAL_MASK:
261 struct sigaction osa;
263 /* do not automatically block signal */
264 sa.sa_flags = SA_NODEFER;
266 if((signum != IBCS2_SIGILL) &&
267 (signum != IBCS2_SIGTRAP) &&
268 (signum != IBCS2_SIGPWR))
269 /* set to SIG_DFL before executing handler */
270 sa.sa_flags |= SA_RESETHAND;
273 sa.sa_handler = uap->fp;
274 sigemptyset(&sa.sa_mask);
276 if (signum != SIGALRM)
277 sa.sa_flags |= SA_RESTART;
279 error = kern_sigaction(td, signum, &sa, &osa, 0);
281 DPRINTF(("signal: sigaction failed: %d\n",
283 td->td_retval[0] = (int)IBCS2_SIG_ERR;
286 td->td_retval[0] = (int)osa.sa_handler;
288 /* special sigset() check */
289 if(IBCS2_SIGCALL(uap->sig) == IBCS2_SIGSET_MASK) {
291 /* check to make sure signal is not blocked */
292 if(sigismember(&td->td_sigmask, signum)) {
293 /* return SIG_HOLD and unblock signal*/
294 td->td_retval[0] = (int)IBCS2_SIG_HOLD;
295 SIGDELSET(td->td_sigmask, signum);
304 case IBCS2_SIGRELSE_MASK:
309 SIGADDSET(mask, signum);
310 return (kern_sigprocmask(td, SIG_UNBLOCK, &mask, NULL,
314 case IBCS2_SIGIGNORE_MASK:
316 sa.sa_handler = SIG_IGN;
317 sigemptyset(&sa.sa_mask);
319 error = kern_sigaction(td, signum, &sa, NULL, 0);
321 DPRINTF(("sigignore: sigaction failed\n"));
325 case IBCS2_SIGPAUSE_MASK:
330 mask = td->td_sigmask;
332 SIGDELSET(mask, signum);
333 return kern_sigsuspend(td, mask);
342 ibcs2_sigprocmask(struct thread *td, struct ibcs2_sigprocmask_args *uap)
350 case IBCS2_SIG_BLOCK:
353 case IBCS2_SIG_UNBLOCK:
356 case IBCS2_SIG_SETMASK:
362 if (uap->set != NULL) {
363 if ((error = copyin(uap->set, &iss, sizeof(iss))) != 0)
365 ibcs2_to_bsd_sigset(&iss, &nss);
369 error = kern_sigprocmask(td, how, nssp, &oss, 0);
370 if (error == 0 && uap->oset != NULL) {
371 bsd_to_ibcs2_sigset(&oss, &iss);
372 error = copyout(&iss, uap->oset, sizeof(iss));
378 ibcs2_sigpending(struct thread *td, struct ibcs2_sigpending_args *uap)
380 struct proc *p = td->td_proc;
385 bss = td->td_siglist;
386 SIGSETOR(bss, p->p_siglist);
387 SIGSETAND(bss, td->td_sigmask);
389 bsd_to_ibcs2_sigset(&bss, &iss);
391 return copyout(&iss, uap->mask, sizeof(iss));
395 ibcs2_sigsuspend(struct thread *td, struct ibcs2_sigsuspend_args *uap)
401 if ((error = copyin(uap->mask, &sss, sizeof(sss))) != 0)
404 ibcs2_to_bsd_sigset(&sss, &bss);
405 return kern_sigsuspend(td, bss);
409 ibcs2_pause(struct thread *td, struct ibcs2_pause_args *uap)
413 PROC_LOCK(td->td_proc);
414 mask = td->td_sigmask;
415 PROC_UNLOCK(td->td_proc);
416 return kern_sigsuspend(td, mask);
420 ibcs2_kill(struct thread *td, struct ibcs2_kill_args *uap)
424 if (uap->signo <= 0 || uap->signo > IBCS2_NSIG)
427 ka.signum = ibcs2_to_bsd_sig[_SIG_IDX(uap->signo)];
428 return sys_kill(td, &ka);