]> Cypherpunks repositories - gostls13.git/commit
runtime: avoid gentraceback of self on user goroutine stack
authorRuss Cox <rsc@golang.org>
Thu, 6 Nov 2014 04:01:48 +0000 (23:01 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 6 Nov 2014 04:01:48 +0000 (23:01 -0500)
commit39bcbb353c6bf2e13eb0d3585fe82d3cab6df78d
tree6cc99e45ddff3a889208f3f238044ea4dc85fa8a
parent2d0db8e591513a1123057b8c330c946ddcb4fbc8
runtime: avoid gentraceback of self on user goroutine stack

Gentraceback may grow the stack.
One of the gentraceback wrappers may grow the stack.
One of the gentraceback callback calls may grow the stack.
Various stack pointers are stored in various stack locations
as type uintptr during the execution of these calls.
If the stack does grow, these stack pointers will not be
updated and will start trying to decode stack memory that
is no longer valid.

It may be possible to change the type of the stack pointer
variables to be unsafe.Pointer, but that's pretty subtle and
may still have problems, even if we catch every last one.
An easier, more obviously correct fix is to require that
gentraceback of the currently running goroutine must run
on the g0 stack, not on the goroutine's own stack.

Not doing this causes faults when you set
        StackFromSystem = 1
        StackFaultOnFree = 1

The new check in gentraceback will catch future lapses.

The more general problem is calling getcallersp but then
calling a function that might relocate the stack, which would
invalidate the result of getcallersp. Add note to stubs.go
declaration of getcallersp explaining the problem, and
check all existing calls to getcallersp. Most needed fixes.

This affects Callers, Stack, and nearly all the runtime
profiling routines. It does not affect stack copying directly
nor garbage collection.

LGTM=khr
R=khr, bradfitz
CC=golang-codereviews, r
https://golang.org/cl/167060043
src/runtime/mprof.go
src/runtime/stubs.go
src/runtime/traceback.go