diff options
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/rt.zc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/runtime/rt.zc b/src/runtime/rt.zc index d6dcfb6..ad18f85 100644 --- a/src/runtime/rt.zc +++ b/src/runtime/rt.zc @@ -169,6 +169,9 @@ int get_c() { return asm { , }; } int eof() { return asm { ? }; } // stop the machine now. nothing after it runs, and the exit status is 0. int halt() { asm { q } return 0; } +// stop after a runtime trap (a bounds error, an overflow, out of memory, a bad +// pointer) with exit status 2. a compile error exits 1, a normal halt 0. +int trap() { syscall(7, 2, 0, 0); return 0; } // 7 is SYS_EXIT, defined further down // write a zero-terminated string, one character at a time. it is the same as // put_c on each byte of s, so a capture sees the text too. int put_s(char* s) { @@ -686,7 +689,7 @@ int scan_ptr(int p, int n) { int frame_overflow() { put_s("zy: frame stack overflow\n"); trace_at(1); - halt(); + trap(); return 0; } // choose the minimum size of subsequent frame segments, in words. @@ -731,7 +734,7 @@ int oom() { outmode = 0; outgrow = 0; put_s("zc: out of heap memory\n"); trace_at(1); - halt(); + trap(); return 0; } // n words, untyped and not zeroed. the type word keeps -(n + 1), so fatten @@ -1103,7 +1106,7 @@ int oob(int i, int n) { put_n(n); put_s(")\n"); trace_at(1); - halt(); + trap(); return 0; } // element i of a growable array h. indexing with [] does the same, with the bounds @@ -1417,11 +1420,11 @@ int checkptr(int w) { if (!(dbg & 1) || !w) return 0; if (w < HEAP_LO || w >= hstop) return 0; p = obj_base(w); - if (!p) { put_s("zy: bad heap pointer\n"); trace_at(1); halt(); return 0; } + if (!p) { put_s("zy: bad heap pointer\n"); trace_at(1); trap(); return 0; } if (!(p[-4] & 1)) { put_s("zy: use after free from line "); put_n(site_line_of(p)); put_c(10); trace_at(1); - halt(); + trap(); } return 0; } |
