From 7f1b2738bb7a8863ee78d5357acbc820b7083821 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 12 Jan 2018 12:39:22 -0500 Subject: 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/stack.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/runtime/stack.go') diff --git a/src/runtime/stack.go b/src/runtime/stack.go index b5dda0d9e6..5a6259c6e2 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -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") } -- cgit v1.3-5-g9baa