]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make panic possible before malloc is ready
authorRuss Cox <rsc@golang.org>
Thu, 14 Mar 2013 14:10:12 +0000 (10:10 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 14 Mar 2013 14:10:12 +0000 (10:10 -0400)
Otherwise startup problems can be difficult to debug.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7522046

src/pkg/runtime/mfixalloc.c
src/pkg/runtime/panic.c

index c916d588fdfd292a059d4760ebd11cd52d4e02f3..c7dab8aea802202af1eb82942380f768952727ea 100644 (file)
@@ -30,6 +30,11 @@ void*
 runtime·FixAlloc_Alloc(FixAlloc *f)
 {
        void *v;
+       
+       if(f->size == 0) {
+               runtime·printf("runtime: use of FixAlloc_Alloc before FixAlloc_Init\n");
+               runtime·throw("runtime: internal error");
+       }
 
        if(f->list) {
                v = f->list;
index 2f553f417e342d1cfd16c98dbfb4e63d016afaff..fbcf6a572dbf4f3485cf67dffda4b3c6d3af266f 100644 (file)
@@ -5,6 +5,7 @@
 #include "runtime.h"
 #include "arch_GOARCH.h"
 #include "stack.h"
+#include "malloc.h"
 
 // Code related to defer, panic and recover.
 
@@ -383,7 +384,10 @@ nomatch:
 void
 runtime·startpanic(void)
 {
-       if(m->mcache == nil)  // can happen if called from signal handler or throw
+       if(runtime·mheap == 0 || runtime·mheap->cachealloc.size == 0) { // very early
+               runtime·printf("runtime: panic before malloc heap initialized\n");
+               m->mallocing = 1; // tell rest of panic not to try to malloc
+       } else if(m->mcache == nil) // can happen if called from signal handler or throw
                m->mcache = runtime·allocmcache();
        if(m->dying) {
                runtime·printf("panic during panic\n");