diff options
| author | Russ Cox <rsc@golang.org> | 2010-04-08 18:15:30 -0700 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2010-04-08 18:15:30 -0700 |
| commit | 2d19c2d8f2a9d759ecfa73d07ed1bab66f8ac24f (patch) | |
| tree | 9042a434db46b9ee490ca915723872f355fd60f2 /src/pkg/runtime/darwin/amd64 | |
| parent | 1fa9a0c209f50aa6b8eac0755ce6ccd00ff2cf02 (diff) | |
| download | golang-2d19c2d8f2a9d759ecfa73d07ed1bab66f8ac24f.tar.gz | |
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
http://codereview.appspot.com/906041
Diffstat (limited to 'src/pkg/runtime/darwin/amd64')
| -rw-r--r-- | src/pkg/runtime/darwin/amd64/defs.h | 44 | ||||
| -rw-r--r-- | src/pkg/runtime/darwin/amd64/signal.c | 39 |
2 files changed, 78 insertions, 5 deletions
diff --git a/src/pkg/runtime/darwin/amd64/defs.h b/src/pkg/runtime/darwin/amd64/defs.h index 1076e4c10..0b5fde85c 100644 --- a/src/pkg/runtime/darwin/amd64/defs.h +++ b/src/pkg/runtime/darwin/amd64/defs.h @@ -44,6 +44,50 @@ enum { SA_ONSTACK = 0x1, SA_USERTRAMP = 0x100, SA_64REGSET = 0x200, + SIGHUP = 0x1, + SIGINT = 0x2, + SIGQUIT = 0x3, + SIGILL = 0x4, + SIGTRAP = 0x5, + SIGABRT = 0x6, + SIGEMT = 0x7, + SIGFPE = 0x8, + SIGKILL = 0x9, + SIGBUS = 0xa, + SIGSEGV = 0xb, + SIGSYS = 0xc, + SIGPIPE = 0xd, + SIGALRM = 0xe, + SIGTERM = 0xf, + SIGURG = 0x10, + SIGSTOP = 0x11, + SIGTSTP = 0x12, + SIGCONT = 0x13, + SIGCHLD = 0x14, + SIGTTIN = 0x15, + SIGTTOU = 0x16, + SIGIO = 0x17, + SIGXCPU = 0x18, + SIGXFSZ = 0x19, + SIGVTALRM = 0x1a, + SIGPROF = 0x1b, + SIGWINCH = 0x1c, + SIGINFO = 0x1d, + SIGUSR1 = 0x1e, + SIGUSR2 = 0x1f, + FPE_INTDIV = 0x7, + FPE_INTOVF = 0x8, + FPE_FLTDIV = 0x1, + FPE_FLTOVF = 0x2, + FPE_FLTUND = 0x3, + FPE_FLTRES = 0x4, + FPE_FLTINV = 0x5, + FPE_FLTSUB = 0x6, + BUS_ADRALN = 0x1, + BUS_ADRERR = 0x2, + BUS_OBJERR = 0x3, + SEGV_MAPERR = 0x1, + SEGV_ACCERR = 0x2, }; // Types diff --git a/src/pkg/runtime/darwin/amd64/signal.c b/src/pkg/runtime/darwin/amd64/signal.c index beb55decf..9c4f0dc14 100644 --- a/src/pkg/runtime/darwin/amd64/signal.c +++ b/src/pkg/runtime/darwin/amd64/signal.c @@ -47,6 +47,40 @@ sighandler(int32 sig, Siginfo *info, void *context) Ucontext *uc; Mcontext *mc; Regs *r; + G *gp; + uintptr *sp; + byte *pc; + + uc = context; + mc = uc->uc_mcontext; + r = &mc->ss; + + if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { + // Work around Leopard bug that doesn't set FPE_INTDIV. + // Look at instruction to see if it is a divide. + // Not necessary in Snow Leopard (si_code will be != 0). + if(sig == SIGFPE && info->si_code == 0) { + pc = (byte*)r->rip; + if((pc[0]&0xF0) == 0x40) // 64-bit REX prefix + pc++; + if(pc[0] == 0xF7) + info->si_code = FPE_INTDIV; + } + + // Make it look like a call to the signal func. + // Have to pass arguments out of band since + // augmenting the stack frame would break + // the unwinding code. + gp->sig = sig; + gp->sigcode0 = info->si_code; + gp->sigcode1 = (uintptr)info->si_addr; + + sp = (uintptr*)r->rsp; + *--sp = r->rip; + r->rip = (uintptr)sigpanic; + r->rsp = (uintptr)sp; + return; + } if(sigtab[sig].flags & SigQueue) { if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) @@ -64,11 +98,6 @@ sighandler(int32 sig, Siginfo *info, void *context) printf("%s\n", sigtab[sig].name); } - uc = context; - mc = uc->uc_mcontext; - r = &mc->ss; - - printf("Faulting address: %p\n", info->si_addr); printf("pc: %X\n", r->rip); printf("\n"); |
