From 551ada4742d3df6a24ddab5516fc8646c8a28958 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 20 Sep 2013 15:15:25 -0400 Subject: runtime: avoid allocation of internal panic values If a fault happens in malloc, inevitably the next thing that happens is a deadlock trying to allocate the panic value that says the fault happened. Stop doing that, two ways. First, reject panic in malloc just as we reject panic in garbage collection. Second, runtime.panicstring was using an error implementation backed by a Go string, so the interface held an allocated *string. Since the actual errors are C strings, define a new error implementation backed by a C char*, which needs no indirection and therefore no allocation. This second fix will avoid allocation for errors like nil panic derefs or division by zero, so it is worth doing even though the first fix should take care of faults during malloc. Update #6419 R=golang-dev, dvyukov, dave CC=golang-dev https://golang.org/cl/13774043 --- src/pkg/runtime/panic.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/pkg/runtime/panic.c') diff --git a/src/pkg/runtime/panic.c b/src/pkg/runtime/panic.c index a1e91d3d8f..8227a444d3 100644 --- a/src/pkg/runtime/panic.c +++ b/src/pkg/runtime/panic.c @@ -470,11 +470,15 @@ runtime·panicstring(int8 *s) { Eface err; + if(m->mallocing) { + runtime·printf("panic: %s\n", s); + runtime·throw("panic during malloc"); + } if(m->gcing) { runtime·printf("panic: %s\n", s); runtime·throw("panic during gc"); } - runtime·newErrorString(runtime·gostringnocopy((byte*)s), &err); + runtime·newErrorCString(s, &err); runtime·panic(err); } -- cgit v1.3