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/freebsd/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/freebsd/amd64')
| -rw-r--r-- | src/pkg/runtime/freebsd/amd64/signal.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/pkg/runtime/freebsd/amd64/signal.c b/src/pkg/runtime/freebsd/amd64/signal.c index dc0e1eb58..ea15922c6 100644 --- a/src/pkg/runtime/freebsd/amd64/signal.c +++ b/src/pkg/runtime/freebsd/amd64/signal.c @@ -56,7 +56,26 @@ void sighandler(int32 sig, Siginfo* info, void* context) { Ucontext *uc; - Mcontext *mc; + Mcontext *r; + + uc = context; + r = &uc->uc_mcontext; + + if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { + // 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->mc_rsp; + *--sp = r->mc_rip; + r->mc_rip = (uintptr)sigpanic; + r->mc_rsp = (uintptr)sp; + return; + } if(sigtab[sig].flags & SigQueue) { if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) @@ -68,21 +87,17 @@ sighandler(int32 sig, Siginfo* info, void* context) exit(2); panicking = 1; - uc = context; - mc = &uc->uc_mcontext; - if(sig < 0 || sig >= NSIG) printf("Signal %d\n", sig); else printf("%s\n", sigtab[sig].name); - printf("Faulting address: %p\n", info->si_addr); - printf("PC=%X\n", mc->mc_rip); + printf("PC=%X\n", r->mc_rip); printf("\n"); if(gotraceback()){ - traceback((void*)mc->mc_rip, (void*)mc->mc_rsp, 0, (void*)mc->mc_r15); - tracebackothers((void*)mc->mc_r15); + traceback((void*)r->mc_rip, (void*)r->mc_rsp, 0, (void*)r->mc_r15); + tracebackothers((void*)r->mc_r15); dumpregs(mc); } |
