runtime: turn divide by zero, nil dereference into panics

tested on linux/amd64, linux/386, linux/arm, darwin/amd64, darwin/386.
freebsd untested; will finish in a separate CL.

for now all the panics are errorStrings.
richer structures can be added as necessary
once the mechanism is shaked out.

R=r
CC=golang-dev
https://golang.org/cl/906041
This commit is contained in:
Russ Cox 2010-04-08 18:15:30 -07:00
parent 72157c300b
commit 5963dbac08
28 changed files with 837 additions and 70 deletions

View file

@ -4,9 +4,10 @@
#include "runtime.h"
#include "defs.h"
#include "signals.h"
#include "os.h"
extern SigTab sigtab[];
// Linux futex.
//
// futexsleep(uint32 *addr, uint32 val)
@ -270,3 +271,27 @@ minit(void)
m->gsignal = malg(32*1024); // OS X wants >=8K, Linux >=2K
signalstack(m->gsignal->stackguard, 32*1024);
}
void
sigpanic(void)
{
switch(g->sig) {
case SIGBUS:
if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000)
panicstring("invalid memory address or nil pointer dereference");
break;
case SIGSEGV:
if((g->sigcode0 == 0 || g->sigcode0 == SEGV_MAPERR) && g->sigcode1 < 0x1000)
panicstring("invalid memory address or nil pointer dereference");
break;
case SIGFPE:
switch(g->sigcode0) {
case FPE_INTDIV:
panicstring("integer divide by zero");
case FPE_INTOVF:
panicstring("integer overflow");
}
panicstring("floating point error");
}
panicstring(sigtab[g->sig].name);
}