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>
This commit is contained in:
Austin Clements 2018-01-12 12:39:22 -05:00
parent 9d59234cbe
commit 7f1b2738bb
14 changed files with 27 additions and 26 deletions

View file

@ -1184,7 +1184,5 @@ func freeStackSpans() {
//go:nosplit
func morestackc() {
systemstack(func() {
throw("attempt to execute system stack code on user stack")
})
throw("attempt to execute system stack code on user stack")
}