summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/linux/thread.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-04-08 18:15:30 -0700
committerRuss Cox <rsc@golang.org>2010-04-08 18:15:30 -0700
commit2d19c2d8f2a9d759ecfa73d07ed1bab66f8ac24f (patch)
tree9042a434db46b9ee490ca915723872f355fd60f2 /src/pkg/runtime/linux/thread.c
parent1fa9a0c209f50aa6b8eac0755ce6ccd00ff2cf02 (diff)
downloadgolang-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/linux/thread.c')
-rw-r--r--src/pkg/runtime/linux/thread.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/pkg/runtime/linux/thread.c b/src/pkg/runtime/linux/thread.c
index d6811eb37..a849125f9 100644
--- a/src/pkg/runtime/linux/thread.c
+++ b/src/pkg/runtime/linux/thread.c
@@ -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);
+}