--- Gnu-Mach/kern/debug.c 2020/09/02 04:36:57 1.1 +++ Gnu-Mach/kern/debug.c 2020/09/02 04:47:28 1.1.1.5 @@ -24,30 +24,34 @@ * the rights to redistribute these changes. */ -#include -#include -#include +#include + +#include +#include #include "cpu_number.h" #include -#include #include +#include +#include +#include -extern void cnputc(); -void Debugger(); - -#if MACH_KDB -extern int db_breakpoints_inserted; -#endif +#include #if NCPUS>1 simple_lock_data_t Assert_print_lock; /* uninited, we take our chances */ #endif +static void +do_cnputc(char c, vm_offset_t offset) +{ + cnputc(c); +} + void -Assert(char *exp, char *file, int line) +Assert(const char *exp, const char *file, int line) { #if NCPUS > 1 simple_lock(&Assert_print_lock); @@ -59,23 +63,19 @@ Assert(char *exp, char *file, int line) exp, file, line); #endif -#if MACH_KDB - if (db_breakpoints_inserted) -#endif Debugger("assertion failure"); } -void Debugger(message) - char * message; +void SoftDebugger(message) + const char *message; { + printf("Debugger invoked: %s\n", message); + #if !MACH_KDB - panic("Debugger invoked, but there isn't one!"); + printf("But no debugger, continuing.\n"); + return; #endif -#ifdef lint - message++; -#endif /* lint */ - #if defined(vax) || defined(PC532) asm("bpt"); #endif /* vax */ @@ -89,15 +89,27 @@ void Debugger(message) asm("ta 0x81"); #endif /* sun4 */ -#if defined(mips ) || defined(luna88k) || defined(i860) || defined(alpha) +#if defined(mips ) || defined(i860) || defined(alpha) gimmeabreak(); #endif -#ifdef i386 +#if defined(__i386__) asm("int3"); #endif } +void Debugger(message) + const char *message; +{ +#if !MACH_KDB + panic("Debugger invoked, but there isn't one!"); +#endif + + SoftDebugger(message); + + panic("Debugger returned!"); +} + /* Be prepared to panic anytime, even before panic_init() gets called from the "normal" place in kern/startup.c. (panic_init() still needs to be called from there @@ -105,11 +117,11 @@ void Debugger(message) boolean_t panic_lock_initialized = FALSE; decl_simple_lock_data(, panic_lock) -char *panicstr; +const char *panicstr; int paniccpu; void -panic_init() +panic_init(void) { if (!panic_lock_initialized) { @@ -118,16 +130,15 @@ panic_init() } } +#if ! MACH_KBD +extern boolean_t reboot_on_panic; +#endif + /*VARARGS1*/ void -panic(s, va_alist) - char * s; - va_dcl +panic(const char *s, ...) { va_list listp; -#if NORMA_IPC - extern int _node_self; /* node_self() may not be callable yet */ -#endif /* NORMA_IPC */ panic_init(); @@ -145,29 +156,30 @@ panic(s, va_alist) } simple_unlock(&panic_lock); printf("panic"); -#if NORMA_IPC - printf("(node %U)", _node_self); -#endif #if NCPUS > 1 printf("(cpu %U)", paniccpu); #endif printf(": "); - va_start(listp); - _doprnt(s, &listp, cnputc, 0); + va_start(listp, s); + _doprnt(s, listp, do_cnputc, 0, 0); va_end(listp); printf("\n"); +#if MACH_KDB + Debugger("panic"); +#else +# ifdef MACH_HYP + hyp_crash(); +# else /* Give the user time to see the message */ { - int i = 60; /* seconds */ + int i = 1000; /* seconds */ while (i--) delay (1000000); /* microseconds */ } -#if MACH_KDB - Debugger("panic"); -#else - halt_all_cpus (1); + halt_all_cpus (reboot_on_panic); +# endif /* MACH_HYP */ #endif } @@ -176,17 +188,25 @@ panic(s, va_alist) */ /*VARARGS2*/ void -log(level, fmt, va_alist) - int level; - char * fmt; - va_dcl +log(int level, const char *fmt, ...) { va_list listp; -#ifdef lint - level++; -#endif - va_start(listp); - _doprnt(fmt, &listp, cnputc, 0); + va_start(listp, fmt); + _doprnt(fmt, listp, do_cnputc, 0, 0); va_end(listp); } + +/* GCC references this for stack protection. */ +unsigned char __stack_chk_guard [ sizeof (vm_offset_t) ] = +{ + [ sizeof (vm_offset_t) - 3 ] = '\r', + [ sizeof (vm_offset_t) - 2 ] = '\n', + [ sizeof (vm_offset_t) - 1 ] = 0xff, +}; + +void +__stack_chk_fail (void) +{ + panic("stack smashing detected"); +}