2 * Copyright (c) 1995 Scott Bartram
3 * Copyright (c) 1995 Steven Wallace
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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/mutex.h>
36 #include <sys/signalvar.h>
37 #include <sys/syscallsubr.h>
38 #include <sys/sysproto.h>
40 #include <i386/ibcs2/ibcs2_types.h>
41 #include <i386/ibcs2/ibcs2_signal.h>
42 #include <i386/ibcs2/ibcs2_proto.h>
43 #include <i386/ibcs2/ibcs2_xenix.h>
44 #include <i386/ibcs2/ibcs2_util.h>
46 #define sigemptyset(s) SIGEMPTYSET(*(s))
47 #define sigismember(s, n) SIGISMEMBER(*(s), n)
48 #define sigaddset(s, n) SIGADDSET(*(s), n)
50 #define ibcs2_sigmask(n) (1 << ((n) - 1))
51 #define ibcs2_sigemptyset(s) bzero((s), sizeof(*(s)))
52 #define ibcs2_sigismember(s, n) (*(s) & ibcs2_sigmask(n))
53 #define ibcs2_sigaddset(s, n) (*(s) |= ibcs2_sigmask(n))
55 static void ibcs2_to_bsd_sigset(const ibcs2_sigset_t *, sigset_t *);
56 static void bsd_to_ibcs2_sigset(const sigset_t *, ibcs2_sigset_t *);
57 static void ibcs2_to_bsd_sigaction(struct ibcs2_sigaction *,
59 static void bsd_to_ibcs2_sigaction(struct sigaction *,
60 struct ibcs2_sigaction *);
62 int bsd_to_ibcs2_sig[IBCS2_SIGTBLSZ] = {
65 IBCS2_SIGQUIT, /* 3 */
67 IBCS2_SIGTRAP, /* 5 */
68 IBCS2_SIGABRT, /* 6 */
71 IBCS2_SIGKILL, /* 9 */
72 IBCS2_SIGBUS, /* 10 */
73 IBCS2_SIGSEGV, /* 11 */
74 IBCS2_SIGSYS, /* 12 */
75 IBCS2_SIGPIPE, /* 13 */
76 IBCS2_SIGALRM, /* 14 */
77 IBCS2_SIGTERM, /* 15 */
79 IBCS2_SIGSTOP, /* 17 */
80 IBCS2_SIGTSTP, /* 18 */
81 IBCS2_SIGCONT, /* 19 */
82 IBCS2_SIGCLD, /* 20 */
83 IBCS2_SIGTTIN, /* 21 */
84 IBCS2_SIGTTOU, /* 22 */
85 IBCS2_SIGPOLL, /* 23 */
88 IBCS2_SIGVTALRM, /* 26 */
89 IBCS2_SIGPROF, /* 27 */
90 IBCS2_SIGWINCH, /* 28 */
92 IBCS2_SIGUSR1, /* 30 */
93 IBCS2_SIGUSR2, /* 31 */
97 static int ibcs2_to_bsd_sig[IBCS2_SIGTBLSZ] = {
133 ibcs2_to_bsd_sigset(iss, bss)
134 const ibcs2_sigset_t *iss;
140 for (i = 1; i <= IBCS2_SIGTBLSZ; i++) {
141 if (ibcs2_sigismember(iss, i)) {
142 newsig = ibcs2_to_bsd_sig[_SIG_IDX(i)];
144 sigaddset(bss, newsig);
150 bsd_to_ibcs2_sigset(bss, iss)
156 ibcs2_sigemptyset(iss);
157 for (i = 1; i <= IBCS2_SIGTBLSZ; i++) {
158 if (sigismember(bss, i)) {
159 newsig = bsd_to_ibcs2_sig[_SIG_IDX(i)];
161 ibcs2_sigaddset(iss, newsig);
167 ibcs2_to_bsd_sigaction(isa, bsa)
168 struct ibcs2_sigaction *isa;
169 struct sigaction *bsa;
172 bsa->sa_handler = isa->isa_handler;
173 ibcs2_to_bsd_sigset(&isa->isa_mask, &bsa->sa_mask);
174 bsa->sa_flags = 0; /* ??? SA_NODEFER */
175 if ((isa->isa_flags & IBCS2_SA_NOCLDSTOP) != 0)
176 bsa->sa_flags |= SA_NOCLDSTOP;
180 bsd_to_ibcs2_sigaction(bsa, isa)
181 struct sigaction *bsa;
182 struct ibcs2_sigaction *isa;
185 isa->isa_handler = bsa->sa_handler;
186 bsd_to_ibcs2_sigset(&bsa->sa_mask, &isa->isa_mask);
188 if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
189 isa->isa_flags |= IBCS2_SA_NOCLDSTOP;
193 ibcs2_sigaction(struct thread *td, struct ibcs2_sigaction_args *uap)
195 struct ibcs2_sigaction isa;
196 struct sigaction nbsa, obsa;
197 struct sigaction *nbsap;
200 if (uap->act != NULL) {
201 if ((error = copyin(uap->act, &isa, sizeof(isa))) != 0)
203 ibcs2_to_bsd_sigaction(&isa, &nbsa);
207 if (uap->sig <= 0 || uap->sig > IBCS2_NSIG)
209 error = kern_sigaction(td, ibcs2_to_bsd_sig[_SIG_IDX(uap->sig)], &nbsa,
211 if (error == 0 && uap->oact != NULL) {
212 bsd_to_ibcs2_sigaction(&obsa, &isa);
213 error = copyout(&isa, uap->oact, sizeof(isa));
219 ibcs2_sigsys(struct thread *td, struct ibcs2_sigsys_args *uap)
221 struct proc *p = td->td_proc;
223 int signum = IBCS2_SIGNO(uap->sig);
226 if (signum <= 0 || signum > IBCS2_NSIG) {
227 if (IBCS2_SIGCALL(uap->sig) == IBCS2_SIGNAL_MASK ||
228 IBCS2_SIGCALL(uap->sig) == IBCS2_SIGSET_MASK)
229 td->td_retval[0] = (int)IBCS2_SIG_ERR;
232 signum = ibcs2_to_bsd_sig[_SIG_IDX(signum)];
234 switch (IBCS2_SIGCALL(uap->sig)) {
235 case IBCS2_SIGSET_MASK:
237 * Check for SIG_HOLD action.
238 * Otherwise, perform signal() except with different sa_flags.
240 if (uap->fp != IBCS2_SIG_HOLD) {
241 /* add sig to mask before exececuting signal handler */
245 /* else FALLTHROUGH to sighold */
247 case IBCS2_SIGHOLD_MASK:
252 SIGADDSET(mask, signum);
253 return (kern_sigprocmask(td, SIG_BLOCK, &mask, NULL,
257 case IBCS2_SIGNAL_MASK:
259 struct sigaction osa;
261 /* do not automatically block signal */
262 sa.sa_flags = SA_NODEFER;
264 if((signum != IBCS2_SIGILL) &&
265 (signum != IBCS2_SIGTRAP) &&
266 (signum != IBCS2_SIGPWR))
267 /* set to SIG_DFL before executing handler */
268 sa.sa_flags |= SA_RESETHAND;
271 sa.sa_handler = uap->fp;
272 sigemptyset(&sa.sa_mask);
274 if (signum != SIGALRM)
275 sa.sa_flags |= SA_RESTART;
277 error = kern_sigaction(td, signum, &sa, &osa, 0);
279 DPRINTF(("signal: sigaction failed: %d\n",
281 td->td_retval[0] = (int)IBCS2_SIG_ERR;
284 td->td_retval[0] = (int)osa.sa_handler;
286 /* special sigset() check */
287 if(IBCS2_SIGCALL(uap->sig) == IBCS2_SIGSET_MASK) {
289 /* check to make sure signal is not blocked */
290 if(sigismember(&td->td_sigmask, signum)) {
291 /* return SIG_HOLD and unblock signal*/
292 td->td_retval[0] = (int)IBCS2_SIG_HOLD;
293 SIGDELSET(td->td_sigmask, signum);
302 case IBCS2_SIGRELSE_MASK:
307 SIGADDSET(mask, signum);
308 return (kern_sigprocmask(td, SIG_UNBLOCK, &mask, NULL,
312 case IBCS2_SIGIGNORE_MASK:
314 sa.sa_handler = SIG_IGN;
315 sigemptyset(&sa.sa_mask);
317 error = kern_sigaction(td, signum, &sa, NULL, 0);
319 DPRINTF(("sigignore: sigaction failed\n"));
323 case IBCS2_SIGPAUSE_MASK:
328 mask = td->td_sigmask;
330 SIGDELSET(mask, signum);
331 return kern_sigsuspend(td, mask);
340 ibcs2_sigprocmask(struct thread *td, struct ibcs2_sigprocmask_args *uap)
348 case IBCS2_SIG_BLOCK:
351 case IBCS2_SIG_UNBLOCK:
354 case IBCS2_SIG_SETMASK:
360 if (uap->set != NULL) {
361 if ((error = copyin(uap->set, &iss, sizeof(iss))) != 0)
363 ibcs2_to_bsd_sigset(&iss, &nss);
367 error = kern_sigprocmask(td, how, nssp, &oss, 0);
368 if (error == 0 && uap->oset != NULL) {
369 bsd_to_ibcs2_sigset(&oss, &iss);
370 error = copyout(&iss, uap->oset, sizeof(iss));
376 ibcs2_sigpending(struct thread *td, struct ibcs2_sigpending_args *uap)
378 struct proc *p = td->td_proc;
383 bss = td->td_siglist;
384 SIGSETOR(bss, p->p_siglist);
385 SIGSETAND(bss, td->td_sigmask);
387 bsd_to_ibcs2_sigset(&bss, &iss);
389 return copyout(&iss, uap->mask, sizeof(iss));
393 ibcs2_sigsuspend(struct thread *td, struct ibcs2_sigsuspend_args *uap)
399 if ((error = copyin(uap->mask, &sss, sizeof(sss))) != 0)
402 ibcs2_to_bsd_sigset(&sss, &bss);
403 return kern_sigsuspend(td, bss);
407 ibcs2_pause(struct thread *td, struct ibcs2_pause_args *uap)
411 PROC_LOCK(td->td_proc);
412 mask = td->td_sigmask;
413 PROC_UNLOCK(td->td_proc);
414 return kern_sigsuspend(td, mask);
418 ibcs2_kill(struct thread *td, struct ibcs2_kill_args *uap)
422 if (uap->signo <= 0 || uap->signo > IBCS2_NSIG)
425 ka.signum = ibcs2_to_bsd_sig[_SIG_IDX(uap->signo)];
426 return sys_kill(td, &ka);