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(td, uap)
194 register struct thread *td;
195 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(td, uap)
222 register struct thread *td;
223 struct ibcs2_sigsys_args *uap;
225 struct proc *p = td->td_proc;
227 int signum = IBCS2_SIGNO(uap->sig);
230 if (signum <= 0 || signum > IBCS2_NSIG) {
231 if (IBCS2_SIGCALL(uap->sig) == IBCS2_SIGNAL_MASK ||
232 IBCS2_SIGCALL(uap->sig) == IBCS2_SIGSET_MASK)
233 td->td_retval[0] = (int)IBCS2_SIG_ERR;
236 signum = ibcs2_to_bsd_sig[_SIG_IDX(signum)];
238 switch (IBCS2_SIGCALL(uap->sig)) {
239 case IBCS2_SIGSET_MASK:
241 * Check for SIG_HOLD action.
242 * Otherwise, perform signal() except with different sa_flags.
244 if (uap->fp != IBCS2_SIG_HOLD) {
245 /* add sig to mask before exececuting signal handler */
249 /* else FALLTHROUGH to sighold */
251 case IBCS2_SIGHOLD_MASK:
256 SIGADDSET(mask, signum);
257 return (kern_sigprocmask(td, SIG_BLOCK, &mask, NULL,
261 case IBCS2_SIGNAL_MASK:
263 struct sigaction osa;
265 /* do not automatically block signal */
266 sa.sa_flags = SA_NODEFER;
268 if((signum != IBCS2_SIGILL) &&
269 (signum != IBCS2_SIGTRAP) &&
270 (signum != IBCS2_SIGPWR))
271 /* set to SIG_DFL before executing handler */
272 sa.sa_flags |= SA_RESETHAND;
275 sa.sa_handler = uap->fp;
276 sigemptyset(&sa.sa_mask);
278 if (signum != SIGALRM)
279 sa.sa_flags |= SA_RESTART;
281 error = kern_sigaction(td, signum, &sa, &osa, 0);
283 DPRINTF(("signal: sigaction failed: %d\n",
285 td->td_retval[0] = (int)IBCS2_SIG_ERR;
288 td->td_retval[0] = (int)osa.sa_handler;
290 /* special sigset() check */
291 if(IBCS2_SIGCALL(uap->sig) == IBCS2_SIGSET_MASK) {
293 /* check to make sure signal is not blocked */
294 if(sigismember(&td->td_sigmask, signum)) {
295 /* return SIG_HOLD and unblock signal*/
296 td->td_retval[0] = (int)IBCS2_SIG_HOLD;
297 SIGDELSET(td->td_sigmask, signum);
306 case IBCS2_SIGRELSE_MASK:
311 SIGADDSET(mask, signum);
312 return (kern_sigprocmask(td, SIG_UNBLOCK, &mask, NULL,
316 case IBCS2_SIGIGNORE_MASK:
318 sa.sa_handler = SIG_IGN;
319 sigemptyset(&sa.sa_mask);
321 error = kern_sigaction(td, signum, &sa, NULL, 0);
323 DPRINTF(("sigignore: sigaction failed\n"));
327 case IBCS2_SIGPAUSE_MASK:
332 mask = td->td_sigmask;
334 SIGDELSET(mask, signum);
335 return kern_sigsuspend(td, mask);
344 ibcs2_sigprocmask(td, uap)
345 register struct thread *td;
346 struct ibcs2_sigprocmask_args *uap;
354 case IBCS2_SIG_BLOCK:
357 case IBCS2_SIG_UNBLOCK:
360 case IBCS2_SIG_SETMASK:
366 if (uap->set != NULL) {
367 if ((error = copyin(uap->set, &iss, sizeof(iss))) != 0)
369 ibcs2_to_bsd_sigset(&iss, &nss);
373 error = kern_sigprocmask(td, how, nssp, &oss, 0);
374 if (error == 0 && uap->oset != NULL) {
375 bsd_to_ibcs2_sigset(&oss, &iss);
376 error = copyout(&iss, uap->oset, sizeof(iss));
382 ibcs2_sigpending(td, uap)
383 register struct thread *td;
384 struct ibcs2_sigpending_args *uap;
386 struct proc *p = td->td_proc;
391 bss = td->td_siglist;
392 SIGSETOR(bss, p->p_siglist);
393 SIGSETAND(bss, td->td_sigmask);
395 bsd_to_ibcs2_sigset(&bss, &iss);
397 return copyout(&iss, uap->mask, sizeof(iss));
401 ibcs2_sigsuspend(td, uap)
402 register struct thread *td;
403 struct ibcs2_sigsuspend_args *uap;
409 if ((error = copyin(uap->mask, &sss, sizeof(sss))) != 0)
412 ibcs2_to_bsd_sigset(&sss, &bss);
413 return kern_sigsuspend(td, bss);
418 register struct thread *td;
419 struct ibcs2_pause_args *uap;
423 PROC_LOCK(td->td_proc);
424 mask = td->td_sigmask;
425 PROC_UNLOCK(td->td_proc);
426 return kern_sigsuspend(td, mask);
431 register struct thread *td;
432 struct ibcs2_kill_args *uap;
436 if (uap->signo <= 0 || uap->signo > IBCS2_NSIG)
439 ka.signum = ibcs2_to_bsd_sig[_SIG_IDX(uap->signo)];
440 return sys_kill(td, &ka);