Commit f84d5dd4 authored by Russ Cox's avatar Russ Cox

runtime: make panic possible before malloc is ready

Otherwise startup problems can be difficult to debug.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7522046
parent 5b79aa82
...@@ -31,6 +31,11 @@ runtime·FixAlloc_Alloc(FixAlloc *f) ...@@ -31,6 +31,11 @@ runtime·FixAlloc_Alloc(FixAlloc *f)
{ {
void *v; 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) { if(f->list) {
v = f->list; v = f->list;
f->list = *(void**)f->list; f->list = *(void**)f->list;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "runtime.h" #include "runtime.h"
#include "arch_GOARCH.h" #include "arch_GOARCH.h"
#include "stack.h" #include "stack.h"
#include "malloc.h"
// Code related to defer, panic and recover. // Code related to defer, panic and recover.
...@@ -383,7 +384,10 @@ nomatch: ...@@ -383,7 +384,10 @@ nomatch:
void void
runtime·startpanic(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(); m->mcache = runtime·allocmcache();
if(m->dying) { if(m->dying) {
runtime·printf("panic during panic\n"); runtime·printf("panic during panic\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment