2019-03-17 14:42:00 +00:00
|
|
|
/** @file
|
|
|
|
* Dedicated treatment of the sigtrp system call, MON 48.
|
|
|
|
*/
|
1988-06-22 16:57:09 +00:00
|
|
|
|
1994-06-24 11:31:16 +00:00
|
|
|
/* $Id$ */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "warn.h"
|
|
|
|
#include "trap.h"
|
2019-03-17 14:42:00 +00:00
|
|
|
#include "m_sigtrp.h"
|
|
|
|
#include "io.h"
|
Cut down some clang warnings
Edit C code to reduce warnings from clang. Most warnings are for
implicit declarations of functions, but some warnings want me to add
parentheses or curly braces, or to cast arguments for printf().
Make a few other changes, like declaring float_cst() in h/con_float to
be static, and using C99 bool in ego/ra/makeitems.c and
ego/share/makecldef.c. Such changes don't silence warnings; I make
such changes while I silence warnings in the same file. In
float_cst(), rename parameter `str` to `float_str`, so it doesn't
share a name with the global variable `str`.
Remove `const` from `newmodule(const char *)` in mach/proto/as to
silence a warning. I wrongly added the `const` in d347207.
For warnings about implicit declarations of functions, the fix is to
declare the function before calling it. For example, my OpenBSD
system needs <sys/wait.h> to declare wait().
In util/int, add "whatever.h" to declare more functions. Remove old
declarations from "mem.h", to prefer the newer declarations of the
same functions in "data.h" and "stack.h".
2019-10-23 20:06:36 +00:00
|
|
|
#include "whatever.h"
|
1988-06-22 16:57:09 +00:00
|
|
|
|
|
|
|
/*************************** SIGTRP *************************************
|
|
|
|
* The monitor call "sigtrp()" is handled by "do_sigtrp()". The first *
|
|
|
|
* argument is a EM-trap number (0<=tn<=252), the second a UNIX signal *
|
|
|
|
* number. The user wants trap "tn" to be generated, in case signal *
|
|
|
|
* "sn" occurs. The report about this interpreter has a section, *
|
|
|
|
* giving all details about signal handling. Do_sigtrp() returns the *
|
|
|
|
* previous trap-number "sn" was mapped onto. A return value of -1 *
|
|
|
|
* indicates an error. *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#define UNIX_trap(sn) (SIGILL <= sn && sn <= SIGSYS)
|
|
|
|
|
1991-10-22 09:07:31 +00:00
|
|
|
#ifndef NSIG
|
|
|
|
#define NSIG _NSIG
|
|
|
|
#endif
|
2019-03-17 14:42:00 +00:00
|
|
|
PRIVATE int sig_map[NSIG + 1]; /* maps signals onto trap numbers */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
PRIVATE void HndlIntSig(int); /* handle signal to interpreter */
|
|
|
|
PRIVATE void HndlEmSig(int); /* handle signal to user program */
|
1988-06-22 16:57:09 +00:00
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
void init_signals(void)
|
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
int sn;
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
for (sn = 0; sn < NSIG + 1; sn++)
|
|
|
|
{
|
|
|
|
sig_map[sn] = -2; /* Default EM trap number */
|
1988-06-22 16:57:09 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
for (sn = 0; sn < NSIG + 1; sn++)
|
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
/* for all signals that would cause termination */
|
2019-03-17 14:42:00 +00:00
|
|
|
if (!UNIX_trap(sn))
|
|
|
|
{
|
1989-11-13 15:36:12 +00:00
|
|
|
#ifdef SIGCHLD
|
2019-03-17 14:42:00 +00:00
|
|
|
if (sn == SIGCHLD)
|
|
|
|
continue;
|
1989-11-13 15:36:12 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
2019-03-17 14:42:00 +00:00
|
|
|
if (sn == SIGIO)
|
|
|
|
continue;
|
1989-11-13 15:36:12 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
2019-03-17 14:42:00 +00:00
|
|
|
if (sn == SIGWINCH)
|
|
|
|
continue;
|
1989-11-13 15:36:12 +00:00
|
|
|
#endif
|
2019-03-17 14:42:00 +00:00
|
|
|
if (signal(sn, SIG_IGN) != SIG_IGN)
|
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
/* we take our fate in our own hand */
|
|
|
|
signal(sn, HndlIntSig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
int do_sigtrp(
|
|
|
|
int tn, /* EM trap number */
|
|
|
|
int sn /* UNIX signal number */
|
|
|
|
)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
register int old_tn;
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
if (sn <= 0 || sn > NSIG)
|
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
einval(WILLSN);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
if (UNIX_trap(sn))
|
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
einval(WUNIXTR);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
old_tn = sig_map[sn];
|
|
|
|
sig_map[sn] = tn;
|
2019-03-17 14:42:00 +00:00
|
|
|
if (tn == -2)
|
|
|
|
{ /* reset default for signal sn */
|
1988-06-22 16:57:09 +00:00
|
|
|
signal(sn, SIG_DFL);
|
|
|
|
}
|
2019-03-17 14:42:00 +00:00
|
|
|
else if (tn == -3)
|
|
|
|
{ /* ignore signal sn */
|
1988-06-22 16:57:09 +00:00
|
|
|
signal(sn, SIG_IGN);
|
|
|
|
}
|
2019-03-17 14:42:00 +00:00
|
|
|
else if (tn >= 0 && tn <= 252)
|
|
|
|
{/* legal tn */
|
2022-08-01 20:08:23 +00:00
|
|
|
if (signal(sn, HndlEmSig) == SIG_ERR)
|
2019-03-17 14:42:00 +00:00
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
sig_map[sn] = old_tn;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
}
|
2019-03-17 14:42:00 +00:00
|
|
|
else
|
|
|
|
{
|
1988-06-22 16:57:09 +00:00
|
|
|
/* illegal trap number */
|
|
|
|
einval(WILLTN);
|
2019-03-17 14:42:00 +00:00
|
|
|
sig_map[sn] = old_tn; /* restore sig_map */
|
1988-06-22 16:57:09 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (old_tn);
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
/** Execute the trap belonging to the signal that came in during
|
|
|
|
* the last instruction
|
|
|
|
*/
|
|
|
|
void trap_signal(void)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
register int old_sig = signalled;
|
|
|
|
|
|
|
|
signalled = 0;
|
|
|
|
trap(sig_map[old_sig]);
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
PRIVATE void HndlIntSig(int sn)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* The interpreter got the signal */
|
2019-03-17 14:42:00 +00:00
|
|
|
signal(sn, SIG_IGN); /* peace and quiet for close_down() */
|
1988-06-22 16:57:09 +00:00
|
|
|
LOG(("@t1 signal %d caught by interpreter", sn));
|
2019-03-17 14:42:00 +00:00
|
|
|
message(
|
|
|
|
"interpreter received signal %d, which was not caught by the interpreted program",
|
|
|
|
sn);
|
1988-06-22 16:57:09 +00:00
|
|
|
close_down(1);
|
|
|
|
}
|
|
|
|
|
2019-03-17 14:42:00 +00:00
|
|
|
PRIVATE void HndlEmSig(int sn)
|
1988-06-22 16:57:09 +00:00
|
|
|
{
|
|
|
|
/* The EM machine got the signal */
|
2019-03-17 14:42:00 +00:00
|
|
|
signal(sn, HndlIntSig); /* Revert to old situation */
|
1988-06-22 16:57:09 +00:00
|
|
|
signalled = sn;
|
|
|
|
}
|
|
|
|
|