Skip to content

Commit 17e9732

Browse files
committed
runtime: overwrite asyncPreempt PC when injecting sigpanic on Windows
On Windows, it might be possible that SuspendThread suspends a thread right between when an exception happens and when the exception handler runs. (This is my guess. I don't know the implementation detail of Windows exceptions to be sure.) In this case, we may inject a call to asyncPreempt before the exception handler runs. The exception handler will inject a sigpanic call, which will make the stack trace looks like sigpanic asyncPreempt actual panicking function i.e. it appears asyncPreempt panicked. Instead, just overwrite the PC, without pushing another frame. Fixes #35773. Change-Id: Ief4e964dcb7f45670b5f93c4dcf285cc1c737514 Reviewed-on: https://go-review.googlesource.com/c/go/+/213879 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
1 parent 817afe8 commit 17e9732

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/runtime/signal_windows.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ func exceptionhandler(info *exceptionrecord, r *context, gp *g) int32 {
129129
// make the trace look like a call to runtime·sigpanic instead.
130130
// (Otherwise the trace will end at runtime·sigpanic and we
131131
// won't get to see who faulted.)
132-
if r.ip() != 0 {
132+
// Also don't push a sigpanic frame if the faulting PC
133+
// is the entry of asyncPreempt. In this case, we suspended
134+
// the thread right between the fault and the exception handler
135+
// starting to run, and we have pushed an asyncPreempt call.
136+
// The exception is not from asyncPreempt, so not to push a
137+
// sigpanic call to make it look like that. Instead, just
138+
// overwrite the PC. (See issue #35773)
139+
if r.ip() != 0 && r.ip() != funcPC(asyncPreempt) {
133140
sp := unsafe.Pointer(r.sp())
134141
sp = add(sp, ^(unsafe.Sizeof(uintptr(0)) - 1)) // sp--
135142
r.set_sp(uintptr(sp))

0 commit comments

Comments
 (0)