1988-04-29 14:38:36 +00:00
|
|
|
/*
|
|
|
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
|
|
|
|
1988-05-03 13:17:20 +00:00
|
|
|
/*
|
|
|
|
Module: Mapping of Unix signals to EM traps
|
2018-06-25 20:22:37 +00:00
|
|
|
(only when not using the MON instruction)
|
1988-05-03 13:17:20 +00:00
|
|
|
Author: Ceriel J.H. Jacobs
|
1994-06-24 14:02:31 +00:00
|
|
|
Version: $Id$
|
1988-04-29 14:38:36 +00:00
|
|
|
*/
|
|
|
|
|
1991-09-04 15:49:34 +00:00
|
|
|
#if !defined(__em22) && !defined(__em24) && !defined(__em44)
|
1988-04-29 14:38:36 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
#define EM_trap(n) TRP(n) /* define to whatever is needed to cause the trap */
|
1988-04-29 14:38:36 +00:00
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
#include "libm2.h"
|
1988-04-29 14:38:36 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
int __signo;
|
|
|
|
|
|
|
|
static int __traps[] = {
|
2018-06-25 20:22:37 +00:00
|
|
|
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
|
|
|
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
|
1988-04-29 14:38:36 +00:00
|
|
|
};
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
static void __ctchsig(int signo)
|
1988-04-29 14:38:36 +00:00
|
|
|
{
|
2018-06-25 20:22:37 +00:00
|
|
|
signal(signo, __ctchsig);
|
1988-04-29 14:38:36 +00:00
|
|
|
#ifdef __BSD4_2
|
2018-06-25 20:22:37 +00:00
|
|
|
sigsetmask(sigblock(0) & ~(1 << (signo - 1)));
|
1988-04-29 14:38:36 +00:00
|
|
|
#endif
|
|
|
|
__signo = signo;
|
|
|
|
EM_trap(__traps[signo]);
|
|
|
|
}
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
int sigtrp(int trapno, int signo)
|
1988-04-29 14:38:36 +00:00
|
|
|
{
|
|
|
|
/* Let Unix signal signo cause EM trap trapno to occur.
|
2018-06-25 20:22:37 +00:00
|
|
|
If trapno = -2, restore default,
|
|
|
|
If trapno = -3, ignore.
|
|
|
|
Return old trapnumber.
|
|
|
|
Careful, this could be -2 or -3; But return value of -1
|
|
|
|
indicates failure, with error number in errno.
|
1988-04-29 14:38:36 +00:00
|
|
|
*/
|
|
|
|
extern int errno;
|
2018-06-25 20:22:37 +00:00
|
|
|
void (*ctch)(int) = __ctchsig;
|
|
|
|
void (*oldctch)(int);
|
1988-04-29 14:38:36 +00:00
|
|
|
int oldtrap;
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
if (signo <= 0 || signo >= sizeof(__traps) / sizeof(__traps[0]))
|
|
|
|
{
|
1988-04-29 14:38:36 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trapno == -3)
|
|
|
|
ctch = SIG_IGN;
|
|
|
|
else if (trapno == -2)
|
|
|
|
ctch = SIG_DFL;
|
|
|
|
else if (trapno >= 0 && trapno <= 252)
|
|
|
|
;
|
2018-06-25 20:22:37 +00:00
|
|
|
else
|
|
|
|
{
|
1988-04-29 14:38:36 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldtrap = __traps[signo];
|
|
|
|
|
2018-06-25 20:22:37 +00:00
|
|
|
if ((oldctch = signal(signo, ctch)) == (void (*)()) - 1) /* errno set by signal */
|
1988-04-29 14:38:36 +00:00
|
|
|
return -1;
|
2018-06-25 20:22:37 +00:00
|
|
|
|
|
|
|
else if (oldctch == SIG_IGN)
|
|
|
|
{
|
1990-08-29 11:44:33 +00:00
|
|
|
signal(signo, SIG_IGN);
|
|
|
|
}
|
2018-06-25 20:22:37 +00:00
|
|
|
else
|
|
|
|
__traps[signo] = trapno;
|
1988-04-29 14:38:36 +00:00
|
|
|
|
|
|
|
return oldtrap;
|
|
|
|
}
|
|
|
|
#endif
|