]> Cypherpunks repositories - gostls13.git/commit
liblink, runtime: diagnose and fix C code running on Go stack
authorRuss Cox <rsc@golang.org>
Mon, 8 Sep 2014 18:05:23 +0000 (14:05 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 8 Sep 2014 18:05:23 +0000 (14:05 -0400)
commitc81a0ed3c50606d1ada0fd9b571611b3687c90e1
treea35c5747f012a3c7d5ec16286298e87be53b86c6
parent526319830bf0d7778226fa9ef558f51ebe67aaa6
liblink, runtime: diagnose and fix C code running on Go stack

This CL contains compiler+runtime changes that detect C code
running on Go (not g0, not gsignal) stacks, and it contains
corrections for what it detected.

The detection works by changing the C prologue to use a different
stack guard word in the G than Go prologue does. On the g0 and
gsignal stacks, that stack guard word is set to the usual
stack guard value. But on ordinary Go stacks, that stack
guard word is set to ^0, which will make any stack split
check fail. The C prologue then calls morestackc instead
of morestack, and morestackc aborts the program with
a message about running C code on a Go stack.

This check catches all C code running on the Go stack
except NOSPLIT code. The NOSPLIT code is allowed,
so the check is complete. Since it is a dynamic check,
the code must execute to be caught. But unlike the static
checks we've been using in cmd/ld, the dynamic check
works with function pointers and other indirect calls.
For example it caught sigpanic being pushed onto Go
stacks in the signal handlers.

Fixes #8667.

LGTM=khr, iant
R=golang-codereviews, khr, iant
CC=golang-codereviews, r
https://golang.org/cl/133700043
36 files changed:
src/liblink/obj5.c
src/liblink/obj6.c
src/liblink/obj8.c
src/runtime/cgo/callbacks.c
src/runtime/cgo/cgo.go
src/runtime/cgocallback.go [new file with mode: 0644]
src/runtime/heapdump.c
src/runtime/mgc0.c
src/runtime/mgc0.go
src/runtime/os_darwin.c
src/runtime/os_dragonfly.c
src/runtime/os_freebsd.c
src/runtime/os_linux.c
src/runtime/os_nacl.c
src/runtime/os_nacl.go
src/runtime/os_netbsd.c
src/runtime/os_openbsd.c
src/runtime/os_plan9.c
src/runtime/os_plan9.go
src/runtime/os_solaris.c
src/runtime/os_windows.c
src/runtime/os_windows.go
src/runtime/panic.c
src/runtime/panic.go
src/runtime/print1.go
src/runtime/proc.c
src/runtime/proc.go
src/runtime/race.go
src/runtime/runtime.h
src/runtime/sigpanic_unix.go [new file with mode: 0644]
src/runtime/stack.c
src/runtime/string.c
src/runtime/string.go
src/runtime/stubs.go
src/runtime/thunk.s
src/runtime/traceback.go