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: default modula-2 trap handler
|
---|
8 | Author: Ceriel J.H. Jacobs
|
---|
9 | Version: $Header: /cvsup/minix/src/lib/ack/libm2/catch.c,v 1.1 2005/10/10 15:27:46 beng Exp $
|
---|
10 | */
|
---|
11 | #include <em_abs.h>
|
---|
12 | #include <m2_traps.h>
|
---|
13 | #include <signal.h>
|
---|
14 |
|
---|
15 | static struct errm {
|
---|
16 | int errno;
|
---|
17 | char *errmes;
|
---|
18 | } errors[] = {
|
---|
19 | { EARRAY, "array bound error"},
|
---|
20 | { ERANGE, "range bound error"},
|
---|
21 | { ESET, "set bound error"},
|
---|
22 | { EIOVFL, "integer overflow"},
|
---|
23 | { EFOVFL, "real overflow"},
|
---|
24 | { EFUNFL, "real underflow"},
|
---|
25 | { EIDIVZ, "divide by 0"},
|
---|
26 | { EFDIVZ, "divide by 0.0"},
|
---|
27 | { EIUND, "undefined integer"},
|
---|
28 | { EFUND, "undefined real"},
|
---|
29 | { ECONV, "conversion error"},
|
---|
30 |
|
---|
31 | { ESTACK, "stack overflow"},
|
---|
32 | { EHEAP, "heap overflow"},
|
---|
33 | { EILLINS, "illegal instruction"},
|
---|
34 | { EODDZ, "illegal size argument"},
|
---|
35 | { ECASE, "case error"},
|
---|
36 | { EMEMFLT, "addressing non existent memory"},
|
---|
37 | { EBADPTR, "bad pointer used"},
|
---|
38 | { EBADPC, "program counter out of range"},
|
---|
39 | { EBADLAE, "bad argument of lae"},
|
---|
40 | { EBADMON, "bad monitor call"},
|
---|
41 | { EBADLIN, "argument if LIN too high"},
|
---|
42 | { EBADGTO, "GTO descriptor error"},
|
---|
43 |
|
---|
44 | { M2_TOOLARGE, "stack size of process too large"},
|
---|
45 | { M2_TOOMANY, "too many nested traps + handlers"},
|
---|
46 | { M2_NORESULT, "no RETURN from function procedure"},
|
---|
47 | { M2_UOVFL, "cardinal overflow"},
|
---|
48 | { M2_FORCH, "(warning) FOR-loop control variable was changed in the body"},
|
---|
49 | { M2_UUVFL, "cardinal underflow"},
|
---|
50 | { M2_INTERNAL, "internal error; ask an expert for help"},
|
---|
51 | { M2_UNIXSIG, "got a unix signal"},
|
---|
52 | { -1, 0}
|
---|
53 | };
|
---|
54 |
|
---|
55 | catch(trapno)
|
---|
56 | int trapno;
|
---|
57 | {
|
---|
58 | register struct errm *ep = &errors[0];
|
---|
59 | char *errmessage;
|
---|
60 | char buf[20];
|
---|
61 | register char *p, *s;
|
---|
62 |
|
---|
63 | while (ep->errno != trapno && ep->errmes != 0) ep++;
|
---|
64 | if (p = ep->errmes) {
|
---|
65 | while (*p) p++;
|
---|
66 | _Traps__Message(ep->errmes, 0, (int) (p - ep->errmes), 1);
|
---|
67 | }
|
---|
68 | else {
|
---|
69 | int i = trapno;
|
---|
70 | static char q[] = "error number xxxxxxxxxxxxx";
|
---|
71 |
|
---|
72 | p = &q[13];
|
---|
73 | s = buf;
|
---|
74 | if (i < 0) {
|
---|
75 | i = -i;
|
---|
76 | *p++ = '-';
|
---|
77 | }
|
---|
78 | do
|
---|
79 | *s++ = i % 10 + '0';
|
---|
80 | while (i /= 10);
|
---|
81 | while (s > buf) *p++ = *--s;
|
---|
82 | *p = 0;
|
---|
83 | _Traps__Message(q, 0, (int) (p - q), 1);
|
---|
84 | }
|
---|
85 | #if !defined(__em24) && !defined(__em44) && !defined(__em22)
|
---|
86 | if (trapno == M2_UNIXSIG) {
|
---|
87 | extern int __signo;
|
---|
88 | signal(__signo, SIG_DFL);
|
---|
89 | _cleanup();
|
---|
90 | kill(getpid(), __signo);
|
---|
91 | _exit(trapno);
|
---|
92 | }
|
---|
93 | #endif
|
---|
94 | if (trapno != M2_FORCH) {
|
---|
95 | _cleanup();
|
---|
96 | _exit(trapno);
|
---|
97 | }
|
---|
98 | SIG(catch);
|
---|
99 | }
|
---|