diff options
author | Austin Clements <austin@google.com> | 2018-01-12 12:39:22 -0500 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2018-03-08 22:55:52 +0000 |
commit | 7f1b2738bb7a8863ee78d5357acbc820b7083821 (patch) | |
tree | d677547399574e29efe3fdd4b0d2d87cb566f6d9 /src/runtime/cgocheck.go | |
parent | 9d59234cbe55c32b6b64969a4360ecccfce582fd (diff) | |
download | go-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/cgocheck.go')
-rw-r--r-- | src/runtime/cgocheck.go | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/runtime/cgocheck.go b/src/runtime/cgocheck.go index 95f6522e94..73cb6ecae2 100644 --- a/src/runtime/cgocheck.go +++ b/src/runtime/cgocheck.go @@ -148,9 +148,7 @@ func cgoCheckTypedBlock(typ *_type, src unsafe.Pointer, off, size uintptr) { if i >= off && bits&bitPointer != 0 { v := *(*unsafe.Pointer)(add(src, i)) if cgoIsGoPointer(v) { - systemstack(func() { - throw(cgoWriteBarrierFail) - }) + throw(cgoWriteBarrierFail) } } hbits = hbits.next() @@ -183,9 +181,7 @@ func cgoCheckBits(src unsafe.Pointer, gcbits *byte, off, size uintptr) { if bits&1 != 0 { v := *(*unsafe.Pointer)(add(src, i)) if cgoIsGoPointer(v) { - systemstack(func() { - throw(cgoWriteBarrierFail) - }) + throw(cgoWriteBarrierFail) } } } |