mirror of
https://github.com/golang/go
synced 2024-11-12 08:20:22 -07:00
runtime: fix crash during cpu profiling
mp->mcache can be concurrently modified by runtime·helpgc. In such case sigprof can remember mcache=nil, then helpgc sets it to non-nil, then sigprof restores it back to nil, GC crashes with nil mcache. R=rsc CC=golang-codereviews https://golang.org/cl/58860044
This commit is contained in:
parent
e56e4e0193
commit
373e1e94d8
@ -2115,7 +2115,6 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
|
|||||||
{
|
{
|
||||||
int32 n;
|
int32 n;
|
||||||
bool traceback;
|
bool traceback;
|
||||||
MCache *mcache;
|
|
||||||
// Do not use global m in this function, use mp instead.
|
// Do not use global m in this function, use mp instead.
|
||||||
// On windows one m is sending reports about all the g's, so m means a wrong thing.
|
// On windows one m is sending reports about all the g's, so m means a wrong thing.
|
||||||
byte m;
|
byte m;
|
||||||
@ -2127,8 +2126,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Profiling runs concurrently with GC, so it must not allocate.
|
// Profiling runs concurrently with GC, so it must not allocate.
|
||||||
mcache = mp->mcache;
|
mp->mallocing++;
|
||||||
mp->mcache = nil;
|
|
||||||
|
|
||||||
// Define that a "user g" is a user-created goroutine, and a "system g"
|
// Define that a "user g" is a user-created goroutine, and a "system g"
|
||||||
// is one that is m->g0 or m->gsignal. We've only made sure that we
|
// is one that is m->g0 or m->gsignal. We've only made sure that we
|
||||||
@ -2216,7 +2214,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
|
|||||||
runtime·lock(&prof);
|
runtime·lock(&prof);
|
||||||
if(prof.fn == nil) {
|
if(prof.fn == nil) {
|
||||||
runtime·unlock(&prof);
|
runtime·unlock(&prof);
|
||||||
mp->mcache = mcache;
|
mp->mallocing--;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -2229,7 +2227,7 @@ runtime·sigprof(uint8 *pc, uint8 *sp, uint8 *lr, G *gp, M *mp)
|
|||||||
}
|
}
|
||||||
prof.fn(prof.pcbuf, n);
|
prof.fn(prof.pcbuf, n);
|
||||||
runtime·unlock(&prof);
|
runtime·unlock(&prof);
|
||||||
mp->mcache = mcache;
|
mp->mallocing--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Arrange to call fn with a traceback hz times a second.
|
// Arrange to call fn with a traceback hz times a second.
|
||||||
|
Loading…
Reference in New Issue
Block a user