diff options
| author | Dmitriy Vyukov <dvyukov@google.com> | 2014-03-13 13:25:59 +0400 |
|---|---|---|
| committer | Dmitriy Vyukov <dvyukov@google.com> | 2014-03-13 13:25:59 +0400 |
| commit | 156962872575382697a0487030cd5777312d6d0c (patch) | |
| tree | 8cc2d344a0794664ebec45a29fefdfea1a507a2f /src/pkg/runtime/panic.c | |
| parent | 5daffee17fdd8c10ead83a87861d99c39f05561d (diff) | |
| download | go-156962872575382697a0487030cd5777312d6d0c.tar.xz | |
runtime: harden conditions when runtime panics on crash
This is especially important for SetPanicOnCrash,
but also useful for e.g. nil deref in mallocgc.
Panics on such crashes can't lead to anything useful,
only to deadlocks, hangs and obscure crashes.
This is a copy of broken but already LGTMed
https://golang.org/cl/68540043/
TBR=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/75320043
Diffstat (limited to 'src/pkg/runtime/panic.c')
| -rw-r--r-- | src/pkg/runtime/panic.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/pkg/runtime/panic.c b/src/pkg/runtime/panic.c index 29bf7de27f..d35f7800a3 100644 --- a/src/pkg/runtime/panic.c +++ b/src/pkg/runtime/panic.c @@ -485,6 +485,29 @@ runtime·throwinit(void) runtime·throw("recursive call during initialization - linker skew"); } +bool +runtime·canpanic(G *gp) +{ + byte g; + + USED(&g); // don't use global g, it points to gsignal + + // Is it okay for gp to panic instead of crashing the program? + // Yes, as long as it is running Go code, not runtime code, + // and not stuck in a system call. + if(gp == nil || gp != m->curg) + return false; + if(m->locks != 0 || m->mallocing != 0 || m->throwing != 0 || m->gcing != 0 || m->dying != 0) + return false; + if(gp->status != Grunning || gp->syscallsp != 0) + return false; +#ifdef GOOS_windows + if(m->libcallsp != 0) + return false; +#endif + return true; +} + void runtime·throw(int8 *s) { |
