]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle fault during runtime more like unexpected fault address
authorRuss Cox <rsc@golang.org>
Thu, 3 Apr 2014 23:05:59 +0000 (19:05 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 3 Apr 2014 23:05:59 +0000 (19:05 -0400)
Delaying the runtime.throw until here will print more information.
In particular it will print the signal and code values, which means
it will show the fault address.

The canpanic checks were added recently, in CL 75320043.
They were just not added in exactly the right place.

LGTM=iant
R=dvyukov, iant
CC=golang-codereviews
https://golang.org/cl/83980043

15 files changed:
src/pkg/runtime/os_darwin.c
src/pkg/runtime/os_dragonfly.c
src/pkg/runtime/os_freebsd.c
src/pkg/runtime/os_linux.c
src/pkg/runtime/os_nacl.c
src/pkg/runtime/os_netbsd.c
src/pkg/runtime/os_openbsd.c
src/pkg/runtime/os_plan9.c
src/pkg/runtime/os_plan9_386.c
src/pkg/runtime/os_plan9_amd64.c
src/pkg/runtime/os_solaris.c
src/pkg/runtime/os_windows.c
src/pkg/runtime/signal_386.c
src/pkg/runtime/signal_amd64x.c
src/pkg/runtime/signal_arm.c

index f2262618db50b4dddfc08088a0e6125fe836bedb..a1165dd7be614e05d722217524f905c997ac19f7 100644 (file)
@@ -434,6 +434,9 @@ runtime·mach_semrelease(uint32 sem)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index f96ea894842f34d9743ba25ac5e56ecb4b41edfc..35a7de96fe02d185369b97edda70919a8c38ecb4 100644 (file)
@@ -169,6 +169,9 @@ runtime·unminit(void)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index 7598b13ba51baa953de0cdbcea44550bc3e97375..9a8de4206bb5edd69f797e795a5936e345cad0c5 100644 (file)
@@ -177,6 +177,9 @@ runtime·unminit(void)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index b4be9406ec49184ad02e9d9a578698c427912aa6..8a945242b96af45b28eba74c729573483934b4da 100644 (file)
@@ -218,6 +218,9 @@ runtime·unminit(void)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index 3c5e487ad1278dc02443063399fe05bb248f905d..3196e2ce32658754c389944f73159c14ec485dc8 100644 (file)
@@ -247,6 +247,9 @@ runtime·closeonexec(int32)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        // Native Client only invokes the exception handler for memory faults.
        g->sig = SIGSEGV;
        if(g->sigpc == 0)
index f8ae30985729734c1de68aadf94fa6ec906f110d..7f4b97271c99aa47f8d4c5c0c03c19a751d57142 100644 (file)
@@ -237,6 +237,9 @@ runtime·unminit(void)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index 714f907545c4f368b322535590189e21a73bfc5a..0eec7956cf348c33a07b7e72235eeff90449d492 100644 (file)
@@ -214,6 +214,9 @@ runtime·unminit(void)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index af20ce8db9431a60addc110c709b55ee35c44dad..b634fd73db256c14ccfa086ab94cbe8d4e11232c 100644 (file)
@@ -352,6 +352,9 @@ runtime·sigpanic(void)
 {
        byte *p;
 
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGRFAULT:
        case SIGWFAULT:
index 04be91bf4ec6d459af00454dfe0642d326c02be7..80d711f33828b0fba0122ce29700318fd3b75a1e 100644 (file)
@@ -71,9 +71,6 @@ runtime·sighandler(void *v, int8 *note, G *gp)
                runtime·exits(note+9); // Strip "go: exit " prefix.
 
        if(flags & SigPanic) {
-               if(!runtime·canpanic(gp))
-                       goto Throw;
-
                // Copy the error string from sigtramp's stack into m->notesig so
                // we can reliably access it from the panic routines.
                runtime·memmove(m->notesig, note, len+1);
index 7f4e1187fd7e63526f83c0065658ff041dad623a..b497056c6707a9720915a489979a0781fcaee0fe 100644 (file)
@@ -79,9 +79,6 @@ runtime·sighandler(void *v, int8 *note, G *gp)
                runtime·exits(note+9); // Strip "go: exit " prefix.
 
        if(flags & SigPanic) {
-               if(!runtime·canpanic(gp))
-                       goto Throw;
-
                // Copy the error string from sigtramp's stack into m->notesig so
                // we can reliably access it from the panic routines.
                runtime·memmove(m->notesig, note, len+1);
index b8cd4d90cac8177cf2c14349415b81f9e49516d0..3575f693db1338bba1c17a534748b63b511e0837 100644 (file)
@@ -209,6 +209,9 @@ runtime·unminit(void)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case SIGBUS:
                if(g->sigcode0 == BUS_ADRERR && g->sigcode1 < 0x1000 || g->paniconfault) {
index 8cb6e150304f67b8e93bd145bc489d5fae473158..4d5ea3bf45155a0da2708f8e327255318e4b2324 100644 (file)
@@ -346,6 +346,9 @@ runtime·issigpanic(uint32 code)
 void
 runtime·sigpanic(void)
 {
+       if(!runtime·canpanic(g))
+               runtime·throw("unexpected signal during runtime execution");
+
        switch(g->sig) {
        case EXCEPTION_ACCESS_VIOLATION:
                if(g->sigcode1 < 0x1000 || g->paniconfault) {
index 70790fa0a3ab804b0a02479702b4e2f3d47ea34d..70fcc6a636d3be205d311ef195e78d9172630f9f 100644 (file)
@@ -45,9 +45,6 @@ runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
 
        t = &runtime·sigtab[sig];
        if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) {
-               if(!runtime·canpanic(gp))
-                       goto Throw;
-
                // Make it look like a call to the signal func.
                // Have to pass arguments out of band since
                // augmenting the stack frame would break
@@ -94,7 +91,6 @@ runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
        if(!(t->flags & SigThrow))
                return;
 
-Throw:
        m->throwing = 1;
        m->caughtsig = gp;
        runtime·startpanic();
index b21733871178863a353cd178dba37be87f472597..309bad3ba689bdd7baebda21de8e57754502f65a 100644 (file)
@@ -54,9 +54,6 @@ runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
 
        t = &runtime·sigtab[sig];
        if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) {
-               if(!runtime·canpanic(gp))
-                       goto Throw;
-
                // Make it look like a call to the signal func.
                // Have to pass arguments out of band since
                // augmenting the stack frame would break
@@ -107,7 +104,6 @@ runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
        if(!(t->flags & SigThrow))
                return;
 
-Throw:
        m->throwing = 1;
        m->caughtsig = gp;
        runtime·startpanic();
index 41997dbd85f8ff1ae7a62f9a7cce8db0737eb340..9b2a43d9ba020cf2472db90c140e7d875efdec55 100644 (file)
@@ -52,9 +52,6 @@ runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
 
        t = &runtime·sigtab[sig];
        if(SIG_CODE0(info, ctxt) != SI_USER && (t->flags & SigPanic)) {
-               if(!runtime·canpanic(gp))
-                       goto Throw;
-
                // Make it look like a call to the signal func.
                // Have to pass arguments out of band since
                // augmenting the stack frame would break
@@ -92,7 +89,6 @@ runtime·sighandler(int32 sig, Siginfo *info, void *ctxt, G *gp)
        if(!(t->flags & SigThrow))
                return;
 
-Throw:
        m->throwing = 1;
        m->caughtsig = gp;
        if(runtime·panicking)  // traceback already printed