source: trunk/minix/lib/ack/libm2/sigtrp.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.8 KB
Line 
1/*
2 (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 See the copyright notice in the ACK home directory, in the file "Copyright".
4*/
5
6/*
7 Module: Mapping of Unix signals to EM traps
8 (only when not using the MON instruction)
9 Author: Ceriel J.H. Jacobs
10 Version: $Header: /cvsup/minix/src/lib/ack/libm2/sigtrp.c,v 1.1 2005/10/10 15:27:46 beng Exp $
11*/
12
13#if !defined(__em22) && !defined(__em24) && !defined(__em44)
14
15#define EM_trap(n) TRP(n) /* define to whatever is needed to cause the trap */
16
17#include <signal.h>
18#include <errno.h>
19
20int __signo;
21
22static int __traps[] = {
23 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
24 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
25 -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
26};
27
28static void
29__ctchsig(signo)
30{
31 signal(signo,__ctchsig);
32#ifdef __BSD4_2
33 sigsetmask(sigblock(0) & ~(1<<(signo - 1)));
34#endif
35 __signo = signo;
36 EM_trap(__traps[signo]);
37}
38
39int
40sigtrp(trapno, signo)
41{
42 /* Let Unix signal signo cause EM trap trapno to occur.
43 If trapno = -2, restore default,
44 If trapno = -3, ignore.
45 Return old trapnumber.
46 Careful, this could be -2 or -3; But return value of -1
47 indicates failure, with error number in errno.
48 */
49 extern int errno;
50 void (*ctch)() = __ctchsig;
51 void (*oldctch)();
52 int oldtrap;
53
54 if (signo <= 0 || signo >= sizeof(__traps)/sizeof(__traps[0])) {
55 errno = EINVAL;
56 return -1;
57 }
58
59 if (trapno == -3)
60 ctch = SIG_IGN;
61 else if (trapno == -2)
62 ctch = SIG_DFL;
63 else if (trapno >= 0 && trapno <= 252)
64 ;
65 else {
66 errno = EINVAL;
67 return -1;
68 }
69
70 oldtrap = __traps[signo];
71
72 if ((oldctch = signal(signo, ctch)) == (void (*)())-1) /* errno set by signal */
73 return -1;
74
75 else if (oldctch == SIG_IGN) {
76 signal(signo, SIG_IGN);
77 }
78 else __traps[signo] = trapno;
79
80 return oldtrap;
81}
82#endif
Note: See TracBrowser for help on using the repository browser.