diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-12-13 00:52:20 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2014-12-13 00:52:20 +0000 |
commit | c1b4ce5c752d8315aa3ce45772827497e5fb5dee (patch) | |
tree | f27977d0c1474482f97c4598f9e95541c5b85073 /libgo | |
parent | b9fd3adf17cf8b03df10288f053615d7411d5fb5 (diff) | |
download | gcc-c1b4ce5c752d8315aa3ce45772827497e5fb5dee.tar.gz |
runtime: Clear stack pointers for extra G's.
Fix an unusual C to Go callback case. Newly created C threads
call into Go code, forcing the Go code to allocate new M and G
structures. While executing Go code, the stack is split. The
Go code then returns. Returning from a Go callback is treated
as entering a system call, so the G gcstack field is set to
point to the Go stack. In this case, though, we were called
from a newly created C thread, so we drop the extra M and G
structures. The C thread then exits.
Then a new C thread calls into Go code, reusing the previously
created M and G. The Go code requires a larger stack frame,
causing the old stack segment to be unmapped and a new stack
segment allocated. At this point the gcstack field is
pointing to the old stack segment.
Then a garbage collection occurs. The garbage collector sees
that the gcstack field is not nil, so it scans it as the first
stack segment. Unfortunately it points to memory that was
unmapped. So the program crashes.
The fix is simple: when handling extra G structures created
for callbacks from new C threads, clear the gcstack field.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218699 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo')
-rw-r--r-- | libgo/runtime/proc.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c index 8907c3aa520..03d1c1a271c 100644 --- a/libgo/runtime/proc.c +++ b/libgo/runtime/proc.c @@ -1150,6 +1150,7 @@ runtime_needm(void) __splitstack_getcontext(&g->stack_context[0]); #else g->gcinitial_sp = ∓ + g->gcstack = nil; g->gcstack_size = 0; g->gcnext_sp = ∓ #endif @@ -1251,6 +1252,8 @@ runtime_dropm(void) runtime_setmg(nil, nil); mp->curg->status = Gdead; + mp->curg->gcstack = nil; + mp->curg->gcnext_sp = nil; mnext = lockextra(true); mp->schedlink = mnext; |