aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/proc.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-09-20 15:15:25 -0400
committerRuss Cox <rsc@golang.org>2013-09-20 15:15:25 -0400
commit551ada4742d3df6a24ddab5516fc8646c8a28958 (patch)
tree12604181fe8e0a6dce528997e76109fba2b793ca /src/pkg/runtime/proc.c
parent81dc0b65b2f6b5b86fa4f4b02a5c26c8956ff3d8 (diff)
downloadgo-551ada4742d3df6a24ddab5516fc8646c8a28958.tar.xz
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
Diffstat (limited to 'src/pkg/runtime/proc.c')
-rw-r--r--src/pkg/runtime/proc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c
index e34e9e5067..d5fc2dcac5 100644
--- a/src/pkg/runtime/proc.c
+++ b/src/pkg/runtime/proc.c
@@ -128,6 +128,7 @@ runtime·schedinit(void)
{
int32 n, procs;
byte *p;
+ Eface i;
runtime·sched.maxmcount = 10000;
runtime·precisestack = haveexperiment("precisestack");
@@ -136,6 +137,12 @@ runtime·schedinit(void)
runtime·mprofinit();
runtime·mallocinit();
mcommoninit(m);
+
+ // Initialize the itable value for newErrorCString,
+ // so that the next time it gets called, possibly
+ // in a fault during a garbage collection, it will not
+ // need to allocated memory.
+ runtime·newErrorCString(0, &i);
runtime·goargs();
runtime·goenvs();