diff --git a/userland/include/err.h b/userland/include/err.h index 8d3f9cb..6caab13 100644 --- a/userland/include/err.h +++ b/userland/include/err.h @@ -55,4 +55,6 @@ void vwarnx(const char *fmt, __va_list); __DEAD void verr(int exitcode, const char *fmt, __va_list); __DEAD void verrx(int exitcode, const char *fmt, __va_list); +void crash_prog(void); + #endif /* _ERR_H_ */ diff --git a/userland/lib/libc/unix/err.c b/userland/lib/libc/unix/err.c index a4992d1..85107be 100644 --- a/userland/lib/libc/unix/err.c +++ b/userland/lib/libc/unix/err.c @@ -139,6 +139,8 @@ verr(int exitcode, const char *fmt, va_list ap) { __printerr(1, fmt, ap); exit(exitcode); + // exit() didn't work. + crash_prog(); } /* errx/verrx: don't use errno, but do then exit */ @@ -147,6 +149,8 @@ verrx(int exitcode, const char *fmt, va_list ap) { __printerr(0, fmt, ap); exit(exitcode); + // exit() didn't work. + crash_prog(); } /* @@ -189,3 +193,12 @@ errx(int exitcode, const char *fmt, ...) verrx(exitcode, fmt, ap); va_end(ap); } + +void +crash_prog(void) +{ + // Guru: Since exit() may not yet be implemented, just trigger a + // failure so things don't fall through to a success print + nprintf("Accessing invalid memory location to trigger failure\n"); + tprintf("%d", *((int *) 0xd34db33f)); +}