mirror of
https://github.com/golang/go
synced 2024-11-21 23:44:39 -07:00
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
This commit is contained in:
parent
d86213c371
commit
fc7ed45b35
@ -437,13 +437,17 @@ runtime·findfunc(uintptr addr)
|
|||||||
// (Before enabling the signal handler,
|
// (Before enabling the signal handler,
|
||||||
// SetCPUProfileRate calls findfunc to trigger
|
// SetCPUProfileRate calls findfunc to trigger
|
||||||
// the initialization outside the handler.)
|
// the initialization outside the handler.)
|
||||||
if(runtime·atomicload(&funcinit) == 0) {
|
// Avoid deadlock on fault during malloc
|
||||||
runtime·lock(&funclock);
|
// by not calling buildfuncs if we're already in malloc.
|
||||||
if(funcinit == 0) {
|
if(!m->mallocing && !m->gcing) {
|
||||||
buildfuncs();
|
if(runtime·atomicload(&funcinit) == 0) {
|
||||||
runtime·atomicstore(&funcinit, 1);
|
runtime·lock(&funclock);
|
||||||
|
if(funcinit == 0) {
|
||||||
|
buildfuncs();
|
||||||
|
runtime·atomicstore(&funcinit, 1);
|
||||||
|
}
|
||||||
|
runtime·unlock(&funclock);
|
||||||
}
|
}
|
||||||
runtime·unlock(&funclock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nfunc == 0)
|
if(nfunc == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user