absl.c
halt.c
transfer.e
+init.c
+sigtrp.c
store.c
confarray.c
load.c
END SetStreamBuffering;
PROCEDURE FlushStream(stream: Stream; VAR result: StreamResult);
+ VAR cnt1: INTEGER;
BEGIN
result := succeeded;
IF (stream = NIL) OR (stream^.kind = none) THEN
result := illegaloperation;
RETURN;
END;
- IF (cnt > 0) AND (Unix.write(fildes, ADR(buf), cnt) < 0) THEN
- ;
+ IF (cnt > 0) THEN
+ cnt1 := cnt;
+ cnt := 0;
+ IF Unix.write(fildes, ADR(buf), cnt) < 0) THEN END;
END;
- cnt := 0;
END;
END FlushStream;
*)
ERRCARDUVFL = 69; (* CARDINAL underflow *)
ERRINTERNAL = 70; (* Internal error; should not happen *)
+ ERRUNIXSIG = 71; (* received unix signal *)
TYPE TrapHandler = EM.TrapHandler;
*)
VAR p, q: POINTER TO CHAR;
l: CARDINAL;
- dummy, lino: INTEGER;
+ lino: INTEGER;
buf, buf2: ARRAY [0..255] OF CHAR;
i, j: CARDINAL;
BEGIN
WHILE p^ # 0C DO
p := ADDRESS(p) + 1;
END;
- dummy := Unix.write(2, q, ADDRESS(p) - ADDRESS(q));
+ IF Unix.write(2, q, ADDRESS(p) - ADDRESS(q)) < 0 THEN END;
ELSE
l := Argv(0, buf);
- dummy := Unix.write(2, ADR(buf), l);
+ IF Unix.write(2, ADR(buf), l) < 0 THEN END;
END;
lino := EM.LINO();
i := 0;
END;
buf[i] := ':';
buf[i+1] := ' ';
- dummy := Unix.write(2, ADR(buf), i+2);
+ IF Unix.write(2, ADR(buf), i+2) < 0 THEN END;
i := 0;
WHILE (i <= HIGH(str)) AND (str[i] # 0C) DO
INC(i);
END;
- dummy := Unix.write(2, ADR(str), i);
+ IF Unix.write(2, ADR(str), i) < 0 THEN END;
buf[0] := 12C;
- dummy := Unix.write(2, ADR(buf), 1);
+ IF Unix.write(2, ADR(buf), 1) < 0 THEN END;
END Message;
PROCEDURE Trap(n: INTEGER);
PROCEDURE signal(sig: INTEGER;
func: SignalPrc;
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 fstat(fildes: INTEGER; statbuf: ADDRESS) : INTEGER;
PROCEDURE stime(t: LONGINT) : INTEGER;
*/
#include <em_abs.h>
#include <m2_traps.h>
+#include <signal.h>
static struct errm {
int errno;
{ M2_FORCH, "Warning: FOR-loop control variable was changed in the body"},
{ M2_UUVFL, "cardinal underflow"},
{ M2_INTERNAL, "internal error; ask an expert for help"},
+ { M2_UNIXSIG, "got a unix signal"},
{ -1, 0}
};
*p = 0;
_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);
SIG(catch);
}
exa MainLB
exa StackSize
exp $catch
+ exp $init
inp $trap_handler
handler
lpi $trap_handler
sig
asp EM_PSIZE
+ cal $init
cal $__M2M_
cal $halt
loc 0 ; should not get here
lae handler
loi EM_PSIZE
lpi $catch
+ lae handler
sti EM_PSIZE
cai
asp EM_PSIZE+EM_WSIZE
--- /dev/null
+/*
+ (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);
+}
--- /dev/null
+/*
+ (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