aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/stubs.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2018-01-12 12:39:22 -0500
committerAustin Clements <austin@google.com>2018-03-08 22:55:52 +0000
commit7f1b2738bb7a8863ee78d5357acbc820b7083821 (patch)
treed677547399574e29efe3fdd4b0d2d87cb566f6d9 /src/runtime/stubs.go
parent9d59234cbe55c32b6b64969a4360ecccfce582fd (diff)
downloadgo-7f1b2738bb7a8863ee78d5357acbc820b7083821.tar.gz
go-7f1b2738bb7a8863ee78d5357acbc820b7083821.zip
runtime: make throw safer to call
Currently, throw may grow the stack, which means whenever we call it from a context where it's not safe to grow the stack, we first have to switch to the system stack. This is pretty easy to get wrong. Fix this by making throw switch to the system stack so it doesn't grow the stack and is hence safe to call without a system stack switch at the call site. The only thing this complicates is badsystemstack itself, which would now go into an infinite loop before printing anything (previously it would also go into an infinite loop, but would at least print the error first). Fix this by making badsystemstack do a direct write and then crash hard. Change-Id: Ic5b4a610df265e47962dcfa341cabac03c31c049 Reviewed-on: https://go-review.googlesource.com/93659 Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/stubs.go')
-rw-r--r--src/runtime/stubs.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go
index e83064166a..6019005fbe 100644
--- a/src/runtime/stubs.go
+++ b/src/runtime/stubs.go
@@ -53,8 +53,13 @@ func mcall(fn func(*g))
//go:noescape
func systemstack(fn func())
+var badsystemstackMsg = "fatal: systemstack called from unexpected goroutine"
+
+//go:nosplit
+//go:nowritebarrierrec
func badsystemstack() {
- throw("systemstack called from unexpected goroutine")
+ sp := stringStructOf(&badsystemstackMsg)
+ write(2, sp.str, int32(sp.len))
}
// memclrNoHeapPointers clears n bytes starting at ptr.