blob: 9462f001b7224b0350276fa14eb06de7ca467c73 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34/* ugly hack to make header file do what I want - davidw */
35#ifdef __arm__
36#undef __USE_POSIX199309
37#endif
38
39#include <signal.h>
40#include <sys/user.h>
41#include <fcntl.h>
Wichert Akkerman90470761999-03-17 00:42:25 +000042#if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 && (defined(I386) || defined(M68K))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043# include <sys/reg.h>
44#endif
45
46#ifdef SVR4
47#include <sys/ucontext.h>
48#endif /* SVR4 */
49
50#ifdef LINUX
51#include <linux/ptrace.h>
52#ifdef HAVE_ASM_SIGCONTEXT_H
53#include <asm/sigcontext.h>
54#ifdef SPARC
55typedef struct {
56 struct pt_regs si_regs;
57 int si_mask;
58} m_siginfo_t;
59#endif
60#else /* !HAVE_ASM_SIGCONTEXT_H */
61#ifdef I386
62struct sigcontext_struct {
63 unsigned short gs, __gsh;
64 unsigned short fs, __fsh;
65 unsigned short es, __esh;
66 unsigned short ds, __dsh;
67 unsigned long edi;
68 unsigned long esi;
69 unsigned long ebp;
70 unsigned long esp;
71 unsigned long ebx;
72 unsigned long edx;
73 unsigned long ecx;
74 unsigned long eax;
75 unsigned long trapno;
76 unsigned long err;
77 unsigned long eip;
78 unsigned short cs, __csh;
79 unsigned long eflags;
80 unsigned long esp_at_signal;
81 unsigned short ss, __ssh;
82 unsigned long i387;
83 unsigned long oldmask;
84 unsigned long cr2;
85};
86#else /* !I386 */
87#ifdef M68K
88struct sigcontext_struct
89{
90 unsigned long sc_mask;
91 unsigned long sc_usp;
92 unsigned long sc_d0;
93 unsigned long sc_d1;
94 unsigned long sc_a0;
95 unsigned long sc_a1;
96 unsigned short sc_sr;
97 unsigned long sc_pc;
98 unsigned short sc_formatvec;
99};
100#endif /* M68K */
101#endif /* !I386 */
102#endif /* !HAVE_ASM_SIGCONTEXT_H */
103#ifndef NSIG
104#define NSIG 32
105#endif
106#ifdef ARM
107#undef NSIG
108#define NSIG 32
109#endif
110#endif /* LINUX */
111
112char *signalent0[] = {
113#include "signalent.h"
114};
115int nsignals0 = sizeof signalent0 / sizeof signalent0[0];
116
117#if SUPPORTED_PERSONALITIES >= 2
118char *signalent1[] = {
119#include "signalent1.h"
120};
121int nsignals1 = sizeof signalent1 / sizeof signalent1[0];
122#endif /* SUPPORTED_PERSONALITIES >= 2 */
123
124#if SUPPORTED_PERSONALITIES >= 3
125char *signalent2[] = {
126#include "signalent2.h"
127};
128int nsignals2 = sizeof signalent2 / sizeof signalent2[0];
129#endif /* SUPPORTED_PERSONALITIES >= 3 */
130
131char **signalent;
132int nsignals;
133
134#ifdef SUNOS4
135
136static struct xlat sigvec_flags[] = {
137 { SV_ONSTACK, "SV_ONSTACK" },
138 { SV_INTERRUPT, "SV_INTERRUPT" },
139 { SV_RESETHAND, "SV_RESETHAND" },
140 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
141 { 0, NULL },
142};
143
144#endif /* SUNOS4 */
145
146#ifdef HAVE_SIGACTION
147
148static struct xlat sigact_flags[] = {
149#ifdef SA_STACK
150 { SA_STACK, "SA_STACK" },
151#endif
152#ifdef SA_RESTART
153 { SA_RESTART, "SA_RESTART" },
154#endif
155#ifdef SA_INTERRUPT
156 { SA_INTERRUPT, "SA_INTERRUPT" },
157#endif
158#ifdef SA_NOMASK
159 { SA_NOMASK, "SA_NOMASK" },
160#endif
161#ifdef SA_ONESHOT
162 { SA_ONESHOT, "SA_ONESHOT" },
163#endif
164#ifdef SA_SIGINFO
165 { SA_SIGINFO, "SA_SIGINFO" },
166#endif
167#ifdef SA_RESETHAND
168 { SA_RESETHAND, "SA_RESETHAND" },
169#endif
170#ifdef SA_ONSTACK
171 { SA_ONSTACK, "SA_ONSTACK" },
172#endif
173#ifdef SA_NODEFER
174 { SA_NODEFER, "SA_NODEFER" },
175#endif
176#ifdef SA_NOCLDSTOP
177 { SA_NOCLDSTOP, "SA_NOCLDSTOP" },
178#endif
179#ifdef SA_NOCLDWAIT
180 { SA_NOCLDWAIT, "SA_NOCLDWAIT" },
181#endif
182#ifdef _SA_BSDCALL
183 { _SA_BSDCALL, "_SA_BSDCALL" },
184#endif
185 { 0, NULL },
186};
187
188static struct xlat sigprocmaskcmds[] = {
189 { SIG_BLOCK, "SIG_BLOCK" },
190 { SIG_UNBLOCK, "SIG_UNBLOCK" },
191 { SIG_SETMASK, "SIG_SETMASK" },
192#ifdef SIG_SETMASK32
193 { SIG_SETMASK32,"SIG_SETMASK32" },
194#endif
195 { 0, NULL },
196};
197
198#endif /* HAVE_SIGACTION */
199
Nate Sammonsce780fc1999-03-29 23:23:13 +0000200/* Anonymous realtime signals. */
201/* Under glibc 2.1, SIGRTMIN et al are functions, but __SIGRTMIN is a
202 constant. This is what we want. Otherwise, just use SIGRTMIN. */
203#ifdef SIGRTMIN
204#ifndef __SIGRTMIN
205#define __SIGRTMIN SIGRTMIN
206#define __SIGRTMAX SIGRTMAX /* likewise */
207#endif
208#endif
209
210char *
211signame(sig)
212int sig;
213{
214 static char buf[30];
215 if (sig < nsignals) {
216 return signalent[sig];
217#ifdef SIGRTMIN
Nate Sammons3080aa41999-03-30 00:16:41 +0000218 } else if (sig >= __SIGRTMIN && sig <= __SIGRTMAX) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000219 sprintf(buf, "SIGRT_%d", sig);
220 return buf;
221#endif /* SIGRTMIN */
222 } else {
223 sprintf(buf, "%d", sig);
224 return buf;
225 }
226}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227
Nate Sammons4a121431999-04-06 01:19:39 +0000228static void
229long_to_sigset(l, s)
230long l;
231sigset_t *s;
232{
233 sigemptyset(s);
234 *(long *)s = l;
235}
236
237static int
238copy_sigset_len(tcp, addr, s, len)
239struct tcb *tcp;
240int addr;
241sigset_t *s;
242int len;
243{
244 if (len > sizeof(*s))
245 len = sizeof(*s);
246 sigemptyset(s);
247 if (umoven(tcp, addr, len, (char *)s) < 0)
248 return -1;
249 return 0;
250}
251
252#ifdef LINUX
253/* Original sigset is unsigned long */
254#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(long))
255#else
256#define copy_sigset(tcp, addr, s) copy_sigset_len(tcp, addr, s, sizeof(sigset_t))
257#endif
258
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259static char *
Nate Sammons4a121431999-04-06 01:19:39 +0000260sprintsigmask(s, mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000261char *s;
262sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000263int rt; /* set might include realtime sigs */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264{
265 int i, nsigs;
Nate Sammons4a121431999-04-06 01:19:39 +0000266 int maxsigs;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267 char *format;
268 static char outstr[256];
269
270 strcpy(outstr, s);
271 s = outstr + strlen(outstr);
272 nsigs = 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000273 maxsigs = nsignals;
274#ifdef __SIGRTMAX
275 if (rt)
276 maxsigs = __SIGRTMAX; /* instead */
277#endif
278 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279 if (sigismember(mask, i) == 1)
280 nsigs++;
281 }
282 if (nsigs >= nsignals * 2 / 3) {
283 *s++ = '~';
Nate Sammons4a121431999-04-06 01:19:39 +0000284 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285 switch (sigismember(mask, i)) {
286 case 1:
287 sigdelset(mask, i);
288 break;
289 case 0:
290 sigaddset(mask, i);
291 break;
292 }
293 }
294 }
295 format = "%s";
296 *s++ = '[';
Nate Sammons4a121431999-04-06 01:19:39 +0000297 for (i = 1; i < maxsigs; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000298 if (sigismember(mask, i) == 1) {
Nate Sammonsce780fc1999-03-29 23:23:13 +0000299 sprintf(s, format, signame(i) + 3); s += strlen(s);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000300 format = " %s";
301 }
302 }
303 *s++ = ']';
304 *s = '\0';
305 return outstr;
306}
307
308static void
Nate Sammons4a121431999-04-06 01:19:39 +0000309printsigmask(mask, rt)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000310sigset_t *mask;
Nate Sammons4a121431999-04-06 01:19:39 +0000311int rt;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312{
Nate Sammons4a121431999-04-06 01:19:39 +0000313 tprintf("%s", sprintsigmask("", mask, rt));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314}
315
316void
317printsignal(nr)
318int nr;
319{
Nate Sammonsce780fc1999-03-29 23:23:13 +0000320 tprintf(signame(nr));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321}
322
323/*
324 * Check process TCP for the disposition of signal SIG.
325 * Return 1 if the process would somehow manage to survive signal SIG,
326 * else return 0. This routine will never be called with SIGKILL.
327 */
328int
329sigishandled(tcp, sig)
330struct tcb *tcp;
331int sig;
332{
333#ifdef LINUX
334 int sfd;
335 char sname[32];
336 char buf[1024];
337 char *s;
338 int i;
339 int signalled, blocked, ignored, caught;
340
341 /* This is incredibly costly but it's worth it. */
342 sprintf(sname, "/proc/%d/stat", tcp->pid);
343 if ((sfd = open(sname, O_RDONLY)) == -1) {
344 perror(sname);
345 return 1;
346 }
347 i = read(sfd, buf, 1024);
348 buf[i] = '\0';
349 close(sfd);
350 /*
351 * Skip the extraneous fields. This loses if the
352 * command name has any spaces in it. So be it.
353 */
354 for (i = 0, s = buf; i < 30; i++) {
355 while (*++s != ' ') {
356 if (!*s)
357 break;
358 }
359 }
360 if (sscanf(s, "%d%d%d%d",
361 &signalled, &blocked, &ignored, &caught) != 4) {
362 fprintf(stderr, "/proc/pid/stat format error\n");
363 return 1;
364 }
365#ifdef DEBUG
366 fprintf(stderr, "sigs: %08x %08x %08x %08x\n",
367 signalled, blocked, ignored, caught);
368#endif
369 if ((ignored & sigmask(sig)) || (caught & sigmask(sig)))
370 return 1;
371#endif /* LINUX */
372
373#ifdef SUNOS4
374 void (*u_signal)();
375
376 if (upeek(tcp->pid, uoff(u_signal[0]) + sig*sizeof(u_signal),
377 (long *) &u_signal) < 0) {
378 return 0;
379 }
380 if (u_signal != SIG_DFL)
381 return 1;
382#endif /* SUNOS4 */
383
384#ifdef SVR4
385 /*
386 * Since procfs doesn't interfere with wait I think it is safe
387 * to punt on this question. If not, the information is there.
388 */
389 return 1;
390#else /* !SVR4 */
391 switch (sig) {
392 case SIGCONT:
393 case SIGSTOP:
394 case SIGTSTP:
395 case SIGTTIN:
396 case SIGTTOU:
397 case SIGCHLD:
398 case SIGIO:
399#if defined(SIGURG) && SIGURG != SIGIO
400 case SIGURG:
401#endif
402 case SIGWINCH:
403 /* Gloria Gaynor says ... */
404 return 1;
405 default:
406 break;
407 }
408 return 0;
409#endif /* !SVR4 */
410}
411
412#if defined(SUNOS4)
413
414int
415sys_sigvec(tcp)
416struct tcb *tcp;
417{
418 struct sigvec sv;
419 long addr;
420
421 if (entering(tcp)) {
422 printsignal(tcp->u_arg[0]);
423 tprintf(", ");
424 addr = tcp->u_arg[1];
425 } else {
426 addr = tcp->u_arg[2];
427 }
428 if (addr == 0)
429 tprintf("NULL");
430 else if (!verbose(tcp))
431 tprintf("%#lx", addr);
432 else if (umove(tcp, addr, &sv) < 0)
433 tprintf("{...}");
434 else {
435 switch ((int) sv.sv_handler) {
436 case (int) SIG_ERR:
437 tprintf("{SIG_ERR}");
438 break;
439 case (int) SIG_DFL:
440 tprintf("{SIG_DFL}");
441 break;
442 case (int) SIG_IGN:
443 if (tcp->u_arg[0] == SIGTRAP) {
444 tcp->flags |= TCB_SIGTRAPPED;
445 kill(tcp->pid, SIGSTOP);
446 }
447 tprintf("{SIG_IGN}");
448 break;
449 case (int) SIG_HOLD:
450 if (tcp->u_arg[0] == SIGTRAP) {
451 tcp->flags |= TCB_SIGTRAPPED;
452 kill(tcp->pid, SIGSTOP);
453 }
454 tprintf("SIG_HOLD");
455 break;
456 default:
457 if (tcp->u_arg[0] == SIGTRAP) {
458 tcp->flags |= TCB_SIGTRAPPED;
459 kill(tcp->pid, SIGSTOP);
460 }
461 tprintf("{%#lx, ", (unsigned long) sv.sv_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000462 printsigmask(&sv.sv_mask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463 tprintf(", ");
464 if (!printflags(sigvec_flags, sv.sv_flags))
465 tprintf("0");
466 tprintf("}");
467 }
468 }
469 if (entering(tcp))
470 tprintf(", ");
471 return 0;
472}
473
474int
475sys_sigpause(tcp)
476struct tcb *tcp;
477{
478 if (entering(tcp)) { /* WTA: UD had a bug here: he forgot the braces */
Nate Sammons4a121431999-04-06 01:19:39 +0000479 sigset_t sigm;
480 long_to_sigset(tcp->u_arg[0], &sigm);
481 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482 }
483 return 0;
484}
485
486int
487sys_sigstack(tcp)
488struct tcb *tcp;
489{
490 struct sigstack ss;
491 long addr;
492
493 if (entering(tcp))
494 addr = tcp->u_arg[0];
495 else
496 addr = tcp->u_arg[1];
497 if (addr == 0)
498 tprintf("NULL");
499 else if (umove(tcp, addr, &ss) < 0)
500 tprintf("%#lx", addr);
501 else {
502 tprintf("{ss_sp %#lx ", (unsigned long) ss.ss_sp);
503 tprintf("ss_onstack %s}", ss.ss_onstack ? "YES" : "NO");
504 }
505 if (entering(tcp))
506 tprintf(", ");
507 return 0;
508}
509
510int
511sys_sigcleanup(tcp)
512struct tcb *tcp;
513{
514 return 0;
515}
516
517#endif /* SUNOS4 */
518
519#ifndef SVR4
520
521int
522sys_sigsetmask(tcp)
523struct tcb *tcp;
524{
525 if (entering(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000527 long_to_sigset(tcp->u_arg[0], &sigm);
528 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 if ((tcp->u_arg[0] & sigmask(SIGTRAP))) {
530 /* Mark attempt to block SIGTRAP */
531 tcp->flags |= TCB_SIGTRAPPED;
532 /* Send unblockable signal */
533 kill(tcp->pid, SIGSTOP);
534 }
535 }
536 else if (!syserror(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000538 long_to_sigset(tcp->u_rval, &sigm);
539 tcp->auxstr = sprintsigmask("old mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540
541 return RVAL_HEX | RVAL_STR;
542 }
543 return 0;
544}
545
546int
547sys_sigblock(tcp)
548struct tcb *tcp;
549{
550 return sys_sigsetmask(tcp);
551}
552
553#endif /* !SVR4 */
554
555#ifdef HAVE_SIGACTION
556
557#ifdef LINUX
558struct old_sigaction {
559 __sighandler_t __sa_handler;
560 unsigned long sa_mask;
561 unsigned long sa_flags;
562 void (*sa_restorer)(void);
563};
564#endif
565
566int
567sys_sigaction(tcp)
568struct tcb *tcp;
569{
570 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 sigset_t sigset;
Nate Sammons4a121431999-04-06 01:19:39 +0000572#ifdef LINUX
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000573 struct old_sigaction sa;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574#else
575 struct sigaction sa;
576#endif
577
578
579 if (entering(tcp)) {
580 printsignal(tcp->u_arg[0]);
581 tprintf(", ");
582 addr = tcp->u_arg[1];
583 } else
584 addr = tcp->u_arg[2];
585 if (addr == 0)
586 tprintf("NULL");
587 else if (!verbose(tcp))
588 tprintf("%#lx", addr);
589 else if (umove(tcp, addr, &sa) < 0)
590 tprintf("{...}");
591 else {
592 switch ((long) sa.__sa_handler) {
593 case (long) SIG_ERR:
594 tprintf("{SIG_ERR}");
595 break;
596 case (long) SIG_DFL:
597 tprintf("{SIG_DFL}");
598 break;
599 case (long) SIG_IGN:
600#ifndef SVR4
601 if (tcp->u_arg[0] == SIGTRAP) {
602 tcp->flags |= TCB_SIGTRAPPED;
603 kill(tcp->pid, SIGSTOP);
604 }
605#endif /* !SVR4 */
606 tprintf("{SIG_IGN}");
607 break;
608 default:
609#ifndef SVR4
610 if (tcp->u_arg[0] == SIGTRAP) {
611 tcp->flags |= TCB_SIGTRAPPED;
612 kill(tcp->pid, SIGSTOP);
613 }
614#endif /* !SVR4 */
615 tprintf("{%#lx, ", (long) sa.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +0000616 long_to_sigset(sa.sa_mask, &sigset);
617 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618 tprintf(", ");
619 if (!printflags(sigact_flags, sa.sa_flags))
620 tprintf("0");
621 tprintf("}");
622 }
623 }
624 if (entering(tcp))
625 tprintf(", ");
626#ifdef LINUX
627 else
628 tprintf(", %#lx", (unsigned long) sa.sa_restorer);
629#endif
630 return 0;
631}
632
633int
634sys_signal(tcp)
635struct tcb *tcp;
636{
637 if (entering(tcp)) {
638 printsignal(tcp->u_arg[0]);
639 switch (tcp->u_arg[1]) {
640 case (int) SIG_ERR:
641 tprintf("SIG_ERR");
642 break;
643 case (int) SIG_DFL:
644 tprintf("SIG_DFL");
645 break;
646 case (int) SIG_IGN:
647#ifndef SVR4
648 if (tcp->u_arg[0] == SIGTRAP) {
649 tcp->flags |= TCB_SIGTRAPPED;
650 kill(tcp->pid, SIGSTOP);
651 }
652#endif /* !SVR4 */
653 tprintf("SIG_IGN");
654 break;
655 default:
656#ifndef SVR4
657 if (tcp->u_arg[0] == SIGTRAP) {
658 tcp->flags |= TCB_SIGTRAPPED;
659 kill(tcp->pid, SIGSTOP);
660 }
661#endif /* !SVR4 */
662 tprintf("%#lx", tcp->u_arg[1]);
663 }
664 }
665 return 0;
666}
667
668#endif /* HAVE_SIGACTION */
669
670#ifdef LINUX
671
672int
673sys_sigreturn(tcp)
674struct tcb *tcp;
675{
676#ifdef I386
677 long esp;
678 struct sigcontext_struct sc;
679
680 if (entering(tcp)) {
681 tcp->u_arg[0] = 0;
682 if (upeek(tcp->pid, 4*UESP, &esp) < 0)
683 return 0;
684 if (umove(tcp, esp, &sc) < 0)
685 return 0;
686 tcp->u_arg[0] = 1;
687 tcp->u_arg[1] = sc.oldmask;
688 }
689 else {
690 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000691 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000692 tcp->u_rval = tcp->u_error = 0;
693 if (tcp->u_arg[0] == 0)
694 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000695 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000696 return RVAL_NONE | RVAL_STR;
697 }
698 return 0;
699#else /* !I386 */
700#ifdef POWERPC
701 long esp;
702 struct sigcontext_struct sc;
703
704 if (entering(tcp)) {
705 tcp->u_arg[0] = 0;
706 if (upeek(tcp->pid, 4*PT_R1, &esp) < 0)
707 return 0;
708 if (umove(tcp, esp, &sc) < 0)
709 return 0;
710 tcp->u_arg[0] = 1;
711 tcp->u_arg[1] = sc.oldmask;
712 }
713 else {
714 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000715 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000716 tcp->u_rval = tcp->u_error = 0;
717 if (tcp->u_arg[0] == 0)
718 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000719 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000720 return RVAL_NONE | RVAL_STR;
721 }
722 return 0;
723#else /* !POWERPC */
724#ifdef M68K
725 long usp;
726 struct sigcontext_struct sc;
727
728 if (entering(tcp)) {
729 tcp->u_arg[0] = 0;
730 if (upeek(tcp->pid, 4*PT_USP, &usp) < 0)
731 return 0;
732 if (umove(tcp, usp, &sc) < 0)
733 return 0;
734 tcp->u_arg[0] = 1;
735 tcp->u_arg[1] = sc.sc_mask;
736 }
737 else {
738 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000739 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000740 tcp->u_rval = tcp->u_error = 0;
741 if (tcp->u_arg[0] == 0)
742 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000743 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000744 return RVAL_NONE | RVAL_STR;
745 }
746 return 0;
747#else /* !M68K */
748#ifdef ALPHA
749 long fp;
750 struct sigcontext_struct sc;
751
752 if (entering(tcp)) {
753 tcp->u_arg[0] = 0;
754 if (upeek(tcp->pid, REG_FP, &fp) < 0)
755 return 0;
756 if (umove(tcp, fp, &sc) < 0)
757 return 0;
758 tcp->u_arg[0] = 1;
759 tcp->u_arg[1] = sc.sc_mask;
760 }
761 else {
762 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000763 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000764 tcp->u_rval = tcp->u_error = 0;
765 if (tcp->u_arg[0] == 0)
766 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000767 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000768 return RVAL_NONE | RVAL_STR;
769 }
770 return 0;
771#else
772#ifdef SPARC
773 long i1;
774 struct pt_regs regs;
775 m_siginfo_t si;
776
777 if(ptrace(PTRACE_GETREGS, tcp->pid, (char *)&regs, 0) < 0) {
778 perror("sigreturn: PTRACE_GETREGS ");
779 return 0;
780 }
781 memmove (&regs.u_regs [1], &regs.u_regs [0],
782 sizeof (regs.u_regs) - sizeof (regs.u_regs [0]));
783 if(entering(tcp)) {
784 tcp->u_arg[0] = 0;
785 i1 = regs.u_regs[UREG_I1];
786 if(umove(tcp, i1, &si) < 0) {
787 perror("sigreturn: umove ");
788 return 0;
789 }
790 tcp->u_arg[0] = 1;
791 tcp->u_arg[1] = si.si_mask;
792 } else {
793 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000794 long_to_sigset(tcp->u_arg[1], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000795 tcp->u_rval = tcp->u_error = 0;
796 if(tcp->u_arg[0] == 0)
797 return 0;
Nate Sammons4a121431999-04-06 01:19:39 +0000798 tcp->auxstr = sprintsigmask("mask now ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000799 return RVAL_NONE | RVAL_STR;
800 }
801 return 0;
802#endif /* SPARC */
803#endif /* ALPHA */
804#endif /* !M68K */
805#endif /* !POWERPC */
806#endif /* !I386 */
807}
808
809int
810sys_siggetmask(tcp)
811struct tcb *tcp;
812{
813 if (exiting(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000814 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000815 long_to_sigset(tcp->u_rval, &sigm);
816 tcp->auxstr = sprintsigmask("mask ", &sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000817 }
818 return RVAL_HEX | RVAL_STR;
819}
820
821int
822sys_sigsuspend(tcp)
823struct tcb *tcp;
824{
825 if (entering(tcp)) {
826 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +0000827 long_to_sigset(tcp->u_arg[2], &sigm);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000828#if 0
829 /* first two are not really arguments, but print them anyway */
830 /* nevermind, they are an anachronism now, too bad... */
831 tprintf("%d, %#x, ", tcp->u_arg[0], tcp->u_arg[1]);
832#endif
Nate Sammons4a121431999-04-06 01:19:39 +0000833 printsigmask(&sigm, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834 }
835 return 0;
836}
837
838#endif /* LINUX */
839
840#ifdef SVR4
841
842int
843sys_sigsuspend(tcp)
844struct tcb *tcp;
845{
846 sigset_t sigset;
847
848 if (entering(tcp)) {
849 if (umove(tcp, tcp->u_arg[0], &sigset) < 0)
850 tprintf("[?]");
851 else
Nate Sammons4a121431999-04-06 01:19:39 +0000852 printsigmask(sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000853 }
854 return 0;
855}
856static struct xlat ucontext_flags[] = {
857 { UC_SIGMASK, "UC_SIGMASK" },
858 { UC_STACK, "UC_STACK" },
859 { UC_CPU, "UC_CPU" },
860#ifdef UC_FPU
861 { UC_FPU, "UC_FPU" },
862#endif
863#ifdef UC_INTR
864 { UC_INTR, "UC_INTR" },
865#endif
866 { 0, NULL },
867};
868
869#endif
870
871#if defined SVR4 || defined LINUX
872#if defined LINUX && !defined SS_ONSTACK
873#define SS_ONSTACK 1
874#define SS_DISABLE 2
875#if __GLIBC_MINOR__ == 0
876typedef struct
877{
878 __ptr_t ss_sp;
879 int ss_flags;
880 size_t ss_size;
881} stack_t;
882#endif
883#endif
884
885static struct xlat sigaltstack_flags[] = {
886 { SS_ONSTACK, "SS_ONSTACK" },
887 { SS_DISABLE, "SS_DISABLE" },
888 { 0, NULL },
889};
890#endif
891
892#ifdef SVR4
893static void
894printcontext(tcp, ucp)
895struct tcb *tcp;
896ucontext_t *ucp;
897{
898 tprintf("{");
899 if (!abbrev(tcp)) {
900 tprintf("uc_flags=");
901 if (!printflags(ucontext_flags, ucp->uc_flags))
902 tprintf("0");
903 tprintf(", uc_link=%#lx, ", (unsigned long) ucp->uc_link);
904 }
905 tprintf("uc_sigmask=");
Nate Sammons4a121431999-04-06 01:19:39 +0000906 printsigmask(ucp->uc_sigmask, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000907 if (!abbrev(tcp)) {
908 tprintf(", uc_stack={ss_sp=%#lx, ss_size=%d, ss_flags=",
909 (unsigned long) ucp->uc_stack.ss_sp,
910 ucp->uc_stack.ss_size);
911 if (!printflags(sigaltstack_flags, ucp->uc_stack.ss_flags))
912 tprintf("0");
913 tprintf("}");
914 }
915 tprintf(", ...}");
916}
917
918int
919sys_getcontext(tcp)
920struct tcb *tcp;
921{
922 ucontext_t uc;
923
924 if (entering(tcp)) {
925 if (!tcp->u_arg[0])
926 tprintf("NULL");
927 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
928 tprintf("{...}");
929 else
930 printcontext(tcp, &uc);
931 }
932 return 0;
933}
934
935int
936sys_setcontext(tcp)
937struct tcb *tcp;
938{
939 ucontext_t uc;
940
941 if (entering(tcp)) {
942 if (!tcp->u_arg[0])
943 tprintf("NULL");
944 else if (umove(tcp, tcp->u_arg[0], &uc) < 0)
945 tprintf("{...}");
946 else
947 printcontext(tcp, &uc);
948 }
949 else {
950 tcp->u_rval = tcp->u_error = 0;
951 if (tcp->u_arg[0] == 0)
952 return 0;
953 return RVAL_NONE;
954 }
955 return 0;
956}
957
958#endif /* SVR4 */
959
960#ifdef LINUX
961
962static int
963print_stack_t(tcp, addr)
964struct tcb *tcp;
965unsigned long addr;
966{
967 stack_t ss;
968 if (umove(tcp, addr, &ss) < 0)
969 return -1;
970 tprintf("{ss_sp=%#lx, ss_flags=", (unsigned long) ss.ss_sp);
971 if (!printflags(sigaltstack_flags, ss.ss_flags))
972 tprintf("0");
973 tprintf(", ss_size=%lu}", (unsigned long) ss.ss_size);
974 return 0;
975}
976
977int
978sys_sigaltstack(tcp)
979 struct tcb *tcp;
980{
981 if (entering(tcp)) {
982 if (tcp->u_arg[0] == 0)
983 tprintf("NULL");
984 else if (print_stack_t(tcp, tcp->u_arg[0]) < 0)
985 return -1;
986 }
987 else {
988 tprintf(", ");
989 if (tcp->u_arg[1] == 0)
990 tprintf("NULL");
991 else if (print_stack_t(tcp, tcp->u_arg[1]) < 0)
992 return -1;
993 }
994 return 0;
995}
996#endif
997
998#ifdef HAVE_SIGACTION
999
1000int
1001sys_sigprocmask(tcp)
1002struct tcb *tcp;
1003{
1004#ifdef ALPHA
1005 if (entering(tcp)) {
1006 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1007 tprintf(", ");
Nate Sammons4a121431999-04-06 01:19:39 +00001008 printsigmask(tcp->u_arg[1], 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001009 }
1010 else if (!syserror(tcp)) {
Nate Sammons4a121431999-04-06 01:19:39 +00001011 tcp->auxstr = sprintsigmask("old mask ", tcp->u_rval, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001012 return RVAL_HEX | RVAL_STR;
1013 }
1014#else /* !ALPHA */
1015 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001016
1017 if (entering(tcp)) {
1018#ifdef SVR4
1019 if (tcp->u_arg[0] == 0)
1020 tprintf("0");
1021 else
1022#endif /* SVR4 */
1023 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1024 tprintf(", ");
1025 if (!tcp->u_arg[1])
1026 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001027 else if (copy_sigset(tcp, tcp->u_arg[1], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001028 tprintf("%#lx, ", tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001030 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001031 tprintf(", ");
1032 }
1033 }
1034 else {
1035 if (!tcp->u_arg[2])
1036 tprintf("NULL");
1037 else if (syserror(tcp))
1038 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001039 else if (copy_sigset(tcp, tcp->u_arg[2], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001041 else
Nate Sammons4a121431999-04-06 01:19:39 +00001042 printsigmask(&sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001043 }
1044#endif /* !ALPHA */
1045 return 0;
1046}
1047
1048#endif /* HAVE_SIGACTION */
1049
1050int
1051sys_kill(tcp)
1052struct tcb *tcp;
1053{
1054 if (entering(tcp)) {
Nate Sammonsce780fc1999-03-29 23:23:13 +00001055 tprintf("%ld, %s", tcp->u_arg[0], signame(tcp->u_arg[1]));
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001056 }
1057 return 0;
1058}
1059
1060int
1061sys_killpg(tcp)
1062struct tcb *tcp;
1063{
1064 return sys_kill(tcp);
1065}
1066
1067int
1068sys_sigpending(tcp)
1069struct tcb *tcp;
1070{
1071 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001072
1073 if (exiting(tcp)) {
1074 if (syserror(tcp))
1075 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001076 else if (copy_sigset(tcp, tcp->u_arg[0], &sigset) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001077 tprintf("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001078 else
Nate Sammons4a121431999-04-06 01:19:39 +00001079 printsigmask(sigset, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001080 }
1081 return 0;
1082}
1083
1084#ifdef LINUX
1085
1086 int
1087sys_rt_sigprocmask(tcp)
1088 struct tcb *tcp;
1089{
1090 sigset_t sigset;
1091
Nate Sammons4a121431999-04-06 01:19:39 +00001092 /* Note: arg[3] is the length of the sigset. */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001093 if (entering(tcp)) {
1094 printxval(sigprocmaskcmds, tcp->u_arg[0], "SIG_???");
1095 tprintf(", ");
1096 if (!tcp->u_arg[1])
1097 tprintf("NULL, ");
Nate Sammons4a121431999-04-06 01:19:39 +00001098 else if (copy_sigset_len(tcp, tcp->u_arg[1], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001099 tprintf("%#lx, ", tcp->u_arg[1]);
1100 else {
Nate Sammons4a121431999-04-06 01:19:39 +00001101 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001102 tprintf(", ");
1103 }
1104 }
1105 else {
1106 if (!tcp->u_arg[2])
1107
1108 tprintf("NULL");
1109 else if (syserror(tcp))
1110 tprintf("%#lx", tcp->u_arg[2]);
Nate Sammons4a121431999-04-06 01:19:39 +00001111 else if (copy_sigset_len(tcp, tcp->u_arg[2], &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001112 tprintf("[?]");
1113 else
Nate Sammons4a121431999-04-06 01:19:39 +00001114 printsigmask(&sigset, 1);
Nate Sammonsdab325a1999-03-29 23:33:35 +00001115 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001116 }
1117 return 0;
1118}
1119
1120#if __GLIBC_MINOR__ < 1
1121/* Type for data associated with a signal. */
1122typedef union sigval
1123{
1124 int sival_int;
1125 void *sival_ptr;
1126} sigval_t;
1127
1128# define __SI_MAX_SIZE 128
1129# define __SI_PAD_SIZE ((__SI_MAX_SIZE / sizeof (int)) - 3)
1130
1131typedef struct siginfo
1132{
1133 int si_signo; /* Signal number. */
1134 int si_errno; /* If non-zero, an errno value associated with
1135 this signal, as defined in <errno.h>. */
1136 int si_code; /* Signal code. */
1137
1138 union
1139 {
1140 int _pad[__SI_PAD_SIZE];
1141
1142 /* kill(). */
1143 struct
1144 {
1145 __pid_t si_pid; /* Sending process ID. */
1146 __uid_t si_uid; /* Real user ID of sending process. */
1147 } _kill;
1148
1149 /* POSIX.1b timers. */
1150 struct
1151 {
1152 unsigned int _timer1;
1153 unsigned int _timer2;
1154 } _timer;
1155
1156 /* POSIX.1b signals. */
1157 struct
1158 {
1159 __pid_t si_pid; /* Sending process ID. */
1160 __uid_t si_uid; /* Real user ID of sending process. */
1161 sigval_t si_sigval; /* Signal value. */
1162 } _rt;
1163
1164 /* SIGCHLD. */
1165 struct
1166 {
1167 __pid_t si_pid; /* Which child. */
1168 int si_status; /* Exit value or signal. */
1169 __clock_t si_utime;
1170 __clock_t si_stime;
1171 } _sigchld;
1172
1173 /* SIGILL, SIGFPE, SIGSEGV, SIGBUS. */
1174 struct
1175 {
1176 void *si_addr; /* Faulting insn/memory ref. */
1177 } _sigfault;
1178
1179 /* SIGPOLL. */
1180 struct
1181 {
1182 int si_band; /* Band event for SIGPOLL. */
1183 int si_fd;
1184 } _sigpoll;
1185 } _sifields;
1186} siginfo_t;
1187#endif
1188
1189/* Structure describing the action to be taken when a signal arrives. */
1190struct new_sigaction
1191{
1192 union
1193 {
1194 __sighandler_t __sa_handler;
1195 void (*__sa_sigaction) (int, siginfo_t *, void *);
1196 }
1197 __sigaction_handler;
1198 unsigned long sa_flags;
1199 void (*sa_restorer) (void);
1200 unsigned long int sa_mask[2];
1201};
1202
1203
1204 int
1205sys_rt_sigaction(tcp)
1206 struct tcb *tcp;
1207{
1208 struct new_sigaction sa;
1209 sigset_t sigset;
1210 long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001211
1212 if (entering(tcp)) {
1213 printsignal(tcp->u_arg[0]);
1214 tprintf(", ");
1215 addr = tcp->u_arg[1];
1216 } else
1217 addr = tcp->u_arg[2];
1218 if (addr == 0)
1219 tprintf("NULL");
1220 else if (!verbose(tcp))
1221 tprintf("%#lx", addr);
1222 else if (umove(tcp, addr, &sa) < 0)
1223 tprintf("{...}");
1224 else {
1225 switch ((long) sa.__sigaction_handler.__sa_handler) {
1226 case (long) SIG_ERR:
1227 tprintf("{SIG_ERR}");
1228 break;
1229 case (long) SIG_DFL:
1230 tprintf("{SIG_DFL}");
1231 break;
1232 case (long) SIG_IGN:
1233 tprintf("{SIG_IGN}");
1234 break;
1235 default:
1236 tprintf("{%#lx, ",
1237 (long) sa.__sigaction_handler.__sa_handler);
Nate Sammons4a121431999-04-06 01:19:39 +00001238 sigemptyset(&sigset);
1239 if (tcp->u_arg[3] <= sizeof(sigset))
1240 memcpy(&sigset, &sa.sa_mask, tcp->u_arg[3]);
1241 else
1242 memcpy(&sigset, &sa.sa_mask, sizeof(sigset));
1243 printsigmask(&sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001244 tprintf(", ");
1245 if (!printflags(sigact_flags, sa.sa_flags))
1246 tprintf("0");
1247 tprintf("}");
1248 }
1249 }
1250 if (entering(tcp))
1251 tprintf(", ");
1252 else
1253 tprintf(", %lu", addr = tcp->u_arg[3]);
1254 return 0;
1255}
1256
1257 int
1258sys_rt_sigpending(tcp)
1259 struct tcb *tcp;
1260{
1261 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001262
1263 if (exiting(tcp)) {
1264 if (syserror(tcp))
1265 tprintf("%#lx", tcp->u_arg[0]);
Nate Sammons4a121431999-04-06 01:19:39 +00001266 else if (copy_sigset_len(tcp, tcp->u_arg[0],
1267 &sigset, tcp->u_arg[1]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001268 tprintf("[?]");
1269 else
Nate Sammons4a121431999-04-06 01:19:39 +00001270 printsigmask(sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001271 }
1272 return 0;
1273}
1274 int
1275sys_rt_sigsuspend(tcp)
1276 struct tcb *tcp;
1277{
1278 if (entering(tcp)) {
1279 sigset_t sigm;
Nate Sammons4a121431999-04-06 01:19:39 +00001280 if (copy_sigset_len(tcp, tcp->u_arg[0], &sigm, tcp->u_arg[1]) < 0)
1281 tprintf("[?]");
1282 else
1283 printsigmask(&sigm, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001284 }
1285 return 0;
1286}
1287#ifndef ILL_ILLOPC
1288#define ILL_ILLOPC 1 /* illegal opcode */
1289#define ILL_ILLOPN 2 /* illegal operand */
1290#define ILL_ILLADR 3 /* illegal addressing mode */
1291#define ILL_ILLTRP 4 /* illegal trap */
1292#define ILL_PRVOPC 5 /* privileged opcode */
1293#define ILL_PRVREG 6 /* privileged register */
1294#define ILL_COPROC 7 /* coprocessor error */
1295#define ILL_BADSTK 8 /* internal stack error */
1296#define FPE_INTDIV 1 /* integer divide by zero */
1297#define FPE_INTOVF 2 /* integer overflow */
1298#define FPE_FLTDIV 3 /* floating point divide by zero */
1299#define FPE_FLTOVF 4 /* floating point overflow */
1300#define FPE_FLTUND 5 /* floating point underflow */
1301#define FPE_FLTRES 6 /* floating point inexact result */
1302#define FPE_FLTINV 7 /* floating point invalid operation */
1303#define FPE_FLTSUB 8 /* subscript out of range */
1304#define SEGV_MAPERR 1 /* address not mapped to object */
1305#define SEGV_ACCERR 2 /* invalid permissions for mapped object */
1306#define BUS_ADRALN 1 /* invalid address alignment */
1307#define BUS_ADRERR 2 /* non-existant physical address */
1308#define BUS_OBJERR 3 /* object specific hardware error */
1309#define TRAP_BRKPT 1 /* process breakpoint */
1310#define TRAP_TRACE 2 /* process trace trap */
1311#define CLD_EXITED 1 /* child has exited */
1312#define CLD_KILLED 2 /* child was killed */
1313#define CLD_DUMPED 3 /* child terminated abnormally */
1314#define CLD_TRAPPED 4 /* traced child has trapped */
1315#define CLD_STOPPED 5 /* child has stopped */
1316#define CLD_CONTINUED 6 /* stopped child has continued */
1317#define POLL_IN 1 /* data input available */
1318#define POLL_OUT 2 /* output buffers available */
1319#define POLL_MSG 3 /* input message available */
1320#define POLL_ERR 4 /* i/o error */
1321#define POLL_PRI 5 /* high priority input available */
1322#define POLL_HUP 6 /* device disconnected */
1323#define SI_USER 0 /* sent by kill, sigsend, raise */
1324#define SI_QUEUE -1 /* sent by sigqueue */
1325#define SI_TIMER -2 /* sent by timer expiration */
1326#define SI_MESGQ -3 /* sent by real time mesq state change */
1327#define SI_ASYNCIO -4 /* sent by AIO completion */
1328#else
1329#undef si_pid
1330#undef si_uid
1331#undef si_status
1332#undef si_utime
1333#undef si_stime
1334#undef si_value
1335#undef si_int
1336#undef si_ptr
1337#undef si_addr
1338#undef si_band
1339#undef si_fd
1340#endif
1341
1342static struct xlat sigill_flags[] = {
1343 {ILL_ILLOPC, "ILL_ILLOPC"},
1344 {ILL_ILLOPN, "ILL_ILLOPN"},
1345 {ILL_ILLADR, "ILL_ILLADR"},
1346 {ILL_ILLTRP, "ILL_ILLTRP"},
1347 {ILL_PRVOPC, "ILL_PRVOPC"},
1348 {ILL_PRVREG, "ILL_PRVREG"},
1349 {ILL_COPROC, "ILL_COPROC"},
1350 {ILL_BADSTK, "ILL_BADSTK"},
1351 {0, NULL}
1352};
1353
1354static struct xlat sigfpe_flags[] = {
1355 {FPE_INTDIV, "FPE_INTDIV"},
1356 {FPE_INTOVF, "FPE_INTOVF"},
1357 {FPE_FLTDIV, "FPE_FLTDIV"},
1358 {FPE_FLTOVF, "FPE_FLTOVF"},
1359 {FPE_FLTUND, "FPE_FLTUND"},
1360 {FPE_FLTRES, "FPE_FLTRES"},
1361 {FPE_FLTINV, "FPE_FLTINV"},
1362 {FPE_FLTSUB, "FPE_FLTSUB"},
1363 {0, NULL}
1364};
1365
1366static struct xlat sigsegv_flags[] = {
1367 {SEGV_MAPERR, "SEGV_MAPERR"},
1368 {SEGV_ACCERR, "SEGV_ACCERR"},
1369 {0, NULL}
1370};
1371
1372static struct xlat sigbus_flags[] = {
1373 {BUS_ADRALN, "BUS_ADRALN"},
1374 {BUS_ADRERR, "BUS_ADRERR"},
1375 {BUS_OBJERR, "BUS_OBJERR"},
1376 {0, NULL}
1377};
1378
1379static struct xlat sigtrap_flags[] = {
1380 {TRAP_BRKPT, "TRAP_BRKPT"},
1381 {TRAP_TRACE, "TRAP_TRACE"},
1382 {0, NULL}
1383};
1384
1385static struct xlat sigchld_flags[] = {
1386 {CLD_EXITED, "CLD_EXITED"},
1387 {CLD_KILLED, "CLD_KILLED"},
1388 {CLD_DUMPED, "CLD_DUMPED"},
1389 {CLD_TRAPPED, "CLD_TRAPPED"},
1390 {CLD_STOPPED, "CLD_STOPPED"},
1391 {CLD_CONTINUED, "CLD_CONTINUED"},
1392 {0, NULL}
1393};
1394
1395static struct xlat sigpoll_flags[] = {
1396 {POLL_IN, "POLL_IN"},
1397 {POLL_OUT, "POLL_OUT"},
1398 {POLL_MSG, "POLL_MSG"},
1399 {POLL_ERR, "POLL_ERR"},
1400 {POLL_PRI, "POLL_PRI"},
1401 {POLL_HUP, "POLL_HUP"},
1402 {0, NULL}
1403};
1404
1405static struct xlat siginfo_flags[] = {
1406 {SI_USER, "SI_USER"},
1407 {SI_QUEUE, "SI_QUEUE"},
1408 {SI_TIMER, "SI_TIMER"},
1409 {SI_MESGQ, "SI_MESGQ"},
1410 {SI_ASYNCIO, "SI_ASYNCIO"},
1411 {0, NULL}
1412};
1413
1414 static void
1415printsiginfo(tcp, si)
1416 struct tcb *tcp;
1417 siginfo_t *si;
1418{
1419 tprintf("{si_signo=");
1420 printsignal(si->si_signo);
1421 tprintf(", si_errno=%d, si_code=", si->si_errno);
1422 switch(si->si_signo)
1423 {
1424 case SIGILL:
1425 if (!printflags(sigill_flags, si->si_code))
1426 tprintf("%d /* ILL_??? */", si->si_code);
1427 tprintf(", si_addr=%lx",
1428 (unsigned long) si->_sifields._sigfault.si_addr);
1429 break;
1430 case SIGFPE:
1431 if (!printflags(sigfpe_flags, si->si_code))
1432 tprintf("%d /* FPE_??? */", si->si_code);
1433 tprintf(", si_addr=%lx",
1434 (unsigned long) si->_sifields._sigfault.si_addr);
1435 break;
1436 case SIGSEGV:
1437 if (!printflags(sigsegv_flags, si->si_code))
1438 tprintf("%d /* SEGV_??? */", si->si_code);
1439 tprintf(", si_addr=%lx",
1440 (unsigned long) si->_sifields._sigfault.si_addr);
1441 break;
1442 case SIGBUS:
1443 if (!printflags(sigbus_flags, si->si_code))
1444 tprintf("%d /* BUS_??? */", si->si_code);
1445 tprintf(", si_addr=%lx",
1446 (unsigned long) si->_sifields._sigfault.si_addr);
1447 break;
1448 case SIGTRAP:
1449 if (!printflags(sigtrap_flags, si->si_code))
1450 tprintf("%d /* TRAP_??? */", si->si_code);
1451 break;
1452 case SIGCHLD:
1453 if (!printflags(sigchld_flags, si->si_code))
1454 tprintf("%d /* CLD_??? */", si->si_code);
1455 if (!verbose(tcp))
1456 tprintf(", ...");
1457 else
1458 tprintf(", si_pid=%d, si_uid=%d, si_status=%d, si_utime=%lu, si_stime=%lu",
1459 si->_sifields._kill.si_pid,
1460 si->_sifields._kill.si_uid,
1461 si->_sifields._sigchld.si_status,
1462 si->_sifields._sigchld.si_utime,
1463 si->_sifields._sigchld.si_stime);
1464 break;
1465 case SIGPOLL:
1466 if (!printflags(sigpoll_flags, si->si_code))
1467 tprintf("%d /* POLL_??? */", si->si_code);
1468 if (si->si_code == POLL_IN
1469 || si->si_code == POLL_OUT
1470 || si->si_code == POLL_MSG)
1471 tprintf(", si_bind=%lu, si_fd=%d",
1472 (unsigned long) si->_sifields._sigpoll.si_band,
1473 si->_sifields._sigpoll.si_fd);
1474 break;
1475 default:
1476 if (!printflags(siginfo_flags, si->si_code))
1477 tprintf("%d /* SI_??? */", si->si_code);
1478 tprintf(", si_pid=%lu, si_uid=%lu, si_value={",
1479 (unsigned long) si->_sifields._rt.si_pid,
1480 (unsigned long) si->_sifields._rt.si_uid);
1481 if (!verbose(tcp))
1482 tprintf("...");
1483 else {
1484 tprintf("sival_int=%u, sival_ptr=%#lx",
1485 si->_sifields._rt.si_sigval.sival_int,
1486 (unsigned long) si->_sifields._rt.si_sigval.sival_ptr);
1487 }
1488 tprintf("}");
1489 break;
1490 }
1491 tprintf("}");
1492}
1493
1494 int
1495sys_rt_sigqueueinfo(tcp)
1496 struct tcb *tcp;
1497{
1498 if (entering(tcp)) {
1499 siginfo_t si;
1500 tprintf("%lu, ", tcp->u_arg[0]);
1501 printsignal(tcp->u_arg[1]);
1502 tprintf(", ");
1503 if (umove(tcp, tcp->u_arg[2], &si) < 0)
1504 tprintf("%#lx", tcp->u_arg[2]);
1505 else
1506 printsiginfo(&si);
1507 }
1508 return 0;
1509}
1510
1511int sys_rt_sigtimedwait(tcp)
1512 struct tcb *tcp;
1513{
1514 if (entering(tcp)) {
1515 sigset_t sigset;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001516
Nate Sammons4a121431999-04-06 01:19:39 +00001517 if (copy_sigset_len(tcp, tcp->u_arg[0],
1518 &sigset, tcp->u_arg[3]) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001519 tprintf("[?]");
1520 else
Nate Sammons4a121431999-04-06 01:19:39 +00001521 printsigmask(sigset, 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001522 tprintf(", ");
1523 }
1524 else {
1525 if (syserror(tcp))
1526 tprintf("%#lx", tcp->u_arg[0]);
1527 else {
1528 siginfo_t si;
1529 if (umove(tcp, tcp->u_arg[1], &si) < 0)
1530 tprintf("%#lx", tcp->u_arg[1]);
1531 else
1532 printsiginfo(&si);
1533 /* XXX For now */
1534 tprintf(", %#lx", tcp->u_arg[2]);
1535 tprintf(", %d", (int) tcp->u_arg[3]);
1536 }
1537 }
1538 return 0;
1539};
1540
1541#endif /* LINUX */
1542