aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2012-02-21 16:36:15 -0500
committerRuss Cox <rsc@golang.org>2012-02-21 16:36:15 -0500
commitfc7ed45b35d24d6d67720e5085c083041a8dd30e (patch)
tree7756ca497e3bcfeaf42ec8461915959b3e0226aa
parentd86213c3718c300bf1638ab15b0b361212fe68a8 (diff)
downloadgo-fc7ed45b35d24d6d67720e5085c083041a8dd30e.tar.gz
go-fc7ed45b35d24d6d67720e5085c083041a8dd30e.zip
runtime: avoid malloc during malloc
A fault during malloc might lead to the program's first call to findfunc, which would in turn call malloc. Don't do that. Fixes #1777. R=golang-dev, gri CC=golang-dev https://golang.org/cl/5689047
-rw-r--r--src/pkg/runtime/symtab.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/pkg/runtime/symtab.c b/src/pkg/runtime/symtab.c
index df4c9ad76c..f29276bd7f 100644
--- a/src/pkg/runtime/symtab.c
+++ b/src/pkg/runtime/symtab.c
@@ -437,13 +437,17 @@ runtime·findfunc(uintptr addr)
// (Before enabling the signal handler,
// SetCPUProfileRate calls findfunc to trigger
// the initialization outside the handler.)
- if(runtime·atomicload(&funcinit) == 0) {
- runtime·lock(&funclock);
- if(funcinit == 0) {
- buildfuncs();
- runtime·atomicstore(&funcinit, 1);
+ // Avoid deadlock on fault during malloc
+ // by not calling buildfuncs if we're already in malloc.
+ if(!m->mallocing && !m->gcing) {
+ if(runtime·atomicload(&funcinit) == 0) {
+ runtime·lock(&funclock);
+ if(funcinit == 0) {
+ buildfuncs();
+ runtime·atomicstore(&funcinit, 1);
+ }
+ runtime·unlock(&funclock);
}
- runtime·unlock(&funclock);
}
if(nfunc == 0)