Added some unix signal handling
This commit is contained in:
parent
f7efb51155
commit
4d528bbc24
9 changed files with 140 additions and 9 deletions
|
@ -27,6 +27,8 @@ absi.c
|
||||||
absl.c
|
absl.c
|
||||||
halt.c
|
halt.c
|
||||||
transfer.e
|
transfer.e
|
||||||
|
init.c
|
||||||
|
sigtrp.c
|
||||||
store.c
|
store.c
|
||||||
confarray.c
|
confarray.c
|
||||||
load.c
|
load.c
|
||||||
|
|
|
@ -135,6 +135,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
END SetStreamBuffering;
|
END SetStreamBuffering;
|
||||||
|
|
||||||
PROCEDURE FlushStream(stream: Stream; VAR result: StreamResult);
|
PROCEDURE FlushStream(stream: Stream; VAR result: StreamResult);
|
||||||
|
VAR cnt1: INTEGER;
|
||||||
BEGIN
|
BEGIN
|
||||||
result := succeeded;
|
result := succeeded;
|
||||||
IF (stream = NIL) OR (stream^.kind = none) THEN
|
IF (stream = NIL) OR (stream^.kind = none) THEN
|
||||||
|
@ -146,10 +147,11 @@ IMPLEMENTATION MODULE Streams;
|
||||||
result := illegaloperation;
|
result := illegaloperation;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
IF (cnt > 0) AND (Unix.write(fildes, ADR(buf), cnt) < 0) THEN
|
IF (cnt > 0) THEN
|
||||||
;
|
cnt1 := cnt;
|
||||||
END;
|
|
||||||
cnt := 0;
|
cnt := 0;
|
||||||
|
IF Unix.write(fildes, ADR(buf), cnt) < 0) THEN END;
|
||||||
|
END;
|
||||||
END;
|
END;
|
||||||
END FlushStream;
|
END FlushStream;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ DEFINITION MODULE Traps;
|
||||||
*)
|
*)
|
||||||
ERRCARDUVFL = 69; (* CARDINAL underflow *)
|
ERRCARDUVFL = 69; (* CARDINAL underflow *)
|
||||||
ERRINTERNAL = 70; (* Internal error; should not happen *)
|
ERRINTERNAL = 70; (* Internal error; should not happen *)
|
||||||
|
ERRUNIXSIG = 71; (* received unix signal *)
|
||||||
|
|
||||||
TYPE TrapHandler = EM.TrapHandler;
|
TYPE TrapHandler = EM.TrapHandler;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ IMPLEMENTATION MODULE Traps;
|
||||||
*)
|
*)
|
||||||
VAR p, q: POINTER TO CHAR;
|
VAR p, q: POINTER TO CHAR;
|
||||||
l: CARDINAL;
|
l: CARDINAL;
|
||||||
dummy, lino: INTEGER;
|
lino: INTEGER;
|
||||||
buf, buf2: ARRAY [0..255] OF CHAR;
|
buf, buf2: ARRAY [0..255] OF CHAR;
|
||||||
i, j: CARDINAL;
|
i, j: CARDINAL;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
@ -40,10 +40,10 @@ IMPLEMENTATION MODULE Traps;
|
||||||
WHILE p^ # 0C DO
|
WHILE p^ # 0C DO
|
||||||
p := ADDRESS(p) + 1;
|
p := ADDRESS(p) + 1;
|
||||||
END;
|
END;
|
||||||
dummy := Unix.write(2, q, ADDRESS(p) - ADDRESS(q));
|
IF Unix.write(2, q, ADDRESS(p) - ADDRESS(q)) < 0 THEN END;
|
||||||
ELSE
|
ELSE
|
||||||
l := Argv(0, buf);
|
l := Argv(0, buf);
|
||||||
dummy := Unix.write(2, ADR(buf), l);
|
IF Unix.write(2, ADR(buf), l) < 0 THEN END;
|
||||||
END;
|
END;
|
||||||
lino := EM.LINO();
|
lino := EM.LINO();
|
||||||
i := 0;
|
i := 0;
|
||||||
|
@ -70,14 +70,14 @@ IMPLEMENTATION MODULE Traps;
|
||||||
END;
|
END;
|
||||||
buf[i] := ':';
|
buf[i] := ':';
|
||||||
buf[i+1] := ' ';
|
buf[i+1] := ' ';
|
||||||
dummy := Unix.write(2, ADR(buf), i+2);
|
IF Unix.write(2, ADR(buf), i+2) < 0 THEN END;
|
||||||
i := 0;
|
i := 0;
|
||||||
WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO
|
WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO
|
||||||
INC(i);
|
INC(i);
|
||||||
END;
|
END;
|
||||||
dummy := Unix.write(2, ADR(str), i);
|
IF Unix.write(2, ADR(str), i) < 0 THEN END;
|
||||||
buf[0] := 12C;
|
buf[0] := 12C;
|
||||||
dummy := Unix.write(2, ADR(buf), 1);
|
IF Unix.write(2, ADR(buf), 1) < 0 THEN END;
|
||||||
END Message;
|
END Message;
|
||||||
|
|
||||||
PROCEDURE Trap(n: INTEGER);
|
PROCEDURE Trap(n: INTEGER);
|
||||||
|
|
|
@ -99,6 +99,8 @@ DEFINITION MODULE Unix;
|
||||||
PROCEDURE signal(sig: INTEGER;
|
PROCEDURE signal(sig: INTEGER;
|
||||||
func: SignalPrc;
|
func: SignalPrc;
|
||||||
VAR oldfunc: SignalPrc) : INTEGER;
|
VAR oldfunc: SignalPrc) : INTEGER;
|
||||||
|
PROCEDURE sigtrp(trapno, signo: INTEGER) : INTEGER;
|
||||||
|
(* Let Unix signal signo cause EM trap trapno to occur *)
|
||||||
PROCEDURE stat(path: ADDRESS; statbuf: ADDRESS) : INTEGER;
|
PROCEDURE stat(path: ADDRESS; statbuf: ADDRESS) : INTEGER;
|
||||||
PROCEDURE fstat(fildes: INTEGER; statbuf: ADDRESS) : INTEGER;
|
PROCEDURE fstat(fildes: INTEGER; statbuf: ADDRESS) : INTEGER;
|
||||||
PROCEDURE stime(t: LONGINT) : INTEGER;
|
PROCEDURE stime(t: LONGINT) : INTEGER;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
*/
|
*/
|
||||||
#include <em_abs.h>
|
#include <em_abs.h>
|
||||||
#include <m2_traps.h>
|
#include <m2_traps.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
static struct errm {
|
static struct errm {
|
||||||
int errno;
|
int errno;
|
||||||
|
@ -47,6 +48,7 @@ static struct errm {
|
||||||
{ M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
|
{ M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
|
||||||
{ M2_UUVFL, "cardinal underflow"},
|
{ M2_UUVFL, "cardinal underflow"},
|
||||||
{ M2_INTERNAL, "internal error; ask an expert for help"},
|
{ M2_INTERNAL, "internal error; ask an expert for help"},
|
||||||
|
{ M2_UNIXSIG, "got a unix signal"},
|
||||||
{ -1, 0}
|
{ -1, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,6 +85,19 @@ catch(trapno)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
_Traps__Message(q, 0, (int) (p - q), 1);
|
_Traps__Message(q, 0, (int) (p - q), 1);
|
||||||
}
|
}
|
||||||
|
#ifndef int24
|
||||||
|
#ifndef int44
|
||||||
|
#ifndef int22
|
||||||
|
if (trapno == M2_UNIXSIG) {
|
||||||
|
extern int __signo;
|
||||||
|
signal(__signo, SIG_DFL);
|
||||||
|
_cleanup();
|
||||||
|
kill(getpid(), __signo);
|
||||||
|
_exit(trapno);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
if (trapno != M2_FORCH) exit(trapno);
|
if (trapno != M2_FORCH) exit(trapno);
|
||||||
SIG(catch);
|
SIG(catch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
exa MainLB
|
exa MainLB
|
||||||
exa StackSize
|
exa StackSize
|
||||||
exp $catch
|
exp $catch
|
||||||
|
exp $init
|
||||||
inp $trap_handler
|
inp $trap_handler
|
||||||
|
|
||||||
handler
|
handler
|
||||||
|
@ -85,6 +86,7 @@ mainroutine
|
||||||
lpi $trap_handler
|
lpi $trap_handler
|
||||||
sig
|
sig
|
||||||
asp EM_PSIZE
|
asp EM_PSIZE
|
||||||
|
cal $init
|
||||||
cal $__M2M_
|
cal $__M2M_
|
||||||
cal $halt
|
cal $halt
|
||||||
loc 0 ; should not get here
|
loc 0 ; should not get here
|
||||||
|
@ -98,6 +100,7 @@ mainroutine
|
||||||
lae handler
|
lae handler
|
||||||
loi EM_PSIZE
|
loi EM_PSIZE
|
||||||
lpi $catch
|
lpi $catch
|
||||||
|
lae handler
|
||||||
sti EM_PSIZE
|
sti EM_PSIZE
|
||||||
cai
|
cai
|
||||||
asp EM_PSIZE+EM_WSIZE
|
asp EM_PSIZE+EM_WSIZE
|
||||||
|
|
27
lang/m2/libm2/init.c
Normal file
27
lang/m2/libm2/init.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <em_abs.h>
|
||||||
|
#include <m2_traps.h>
|
||||||
|
|
||||||
|
/* map unix signals onto EM traps */
|
||||||
|
init()
|
||||||
|
{
|
||||||
|
sigtrp(M2_UNIXSIG, SIGHUP);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGINT);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGQUIT);
|
||||||
|
sigtrp(EILLINS, SIGILL);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGTRAP);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGIOT);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGEMT);
|
||||||
|
/* sigtrp(M2_UNIXSIG, SIGFPE); leave this one for EM runtime startoff*/
|
||||||
|
sigtrp(M2_UNIXSIG, SIGBUS);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGSEGV);
|
||||||
|
sigtrp(EBADMON, SIGSYS);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGPIPE);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGALRM);
|
||||||
|
sigtrp(M2_UNIXSIG, SIGTERM);
|
||||||
|
}
|
79
lang/m2/libm2/sigtrp.c
Normal file
79
lang/m2/libm2/sigtrp.c
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||||
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Mapping of Unix signals to EM traps;
|
||||||
|
Use this only when you don't use the MON instruction
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef int22
|
||||||
|
#ifndef int24
|
||||||
|
#ifndef int44
|
||||||
|
|
||||||
|
#define EM_trap(n) TRP(n) /* define to whatever is needed to cause the trap */
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int __signo;
|
||||||
|
|
||||||
|
static int __traps[] = {
|
||||||
|
-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,
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
__ctchsig(signo)
|
||||||
|
{
|
||||||
|
signal(signo,__ctchsig);
|
||||||
|
#ifdef __BSD4_2
|
||||||
|
sigsetmask(sigblock(0) & ~(1<<(signo - 1)));
|
||||||
|
#endif
|
||||||
|
__signo = signo;
|
||||||
|
EM_trap(__traps[signo]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sigtrp(trapno, signo)
|
||||||
|
{
|
||||||
|
/* Let Unix signal signo cause EM trap trapno to occur.
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
extern int errno;
|
||||||
|
int (*ctch)() = __ctchsig;
|
||||||
|
int oldtrap;
|
||||||
|
|
||||||
|
if (signo <= 0 || signo >= sizeof(__traps)/sizeof(__traps[0])) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trapno == -3)
|
||||||
|
ctch = SIG_IGN;
|
||||||
|
else if (trapno == -2)
|
||||||
|
ctch = SIG_DFL;
|
||||||
|
else if (trapno >= 0 && trapno <= 252)
|
||||||
|
;
|
||||||
|
else {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldtrap = __traps[signo];
|
||||||
|
|
||||||
|
if (signal(signo, ctch) == -1) /* errno set by signal */
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
__traps[signo] = trapno;
|
||||||
|
|
||||||
|
return oldtrap;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
Loading…
Reference in a new issue