aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_windows_amd64.s
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2023-09-04 17:30:08 +0200
committerQuim Muntal <quimmuntal@gmail.com>2023-10-05 08:26:52 +0000
commitbc15070085ec417d4254f8a4eda62b42de88fb37 (patch)
treee0678a8d064fc84b978510f7ccc2f52ebb80f51b /src/runtime/sys_windows_amd64.s
parent36ecff0893e8f30c2ff659acf8c62401f4dcebf7 (diff)
downloadgo-bc15070085ec417d4254f8a4eda62b42de88fb37.tar.xz
runtime: support SetUnhandledExceptionFilter on Windows
The Windows unhandled exception mechanism fails to call the callback set in SetUnhandledExceptionFilter if the stack can't be correctly unwound. Some cgo glue code was not properly chaining the frame pointer, making the stack unwind to fail in case of an exception inside a cgo call. This CL fix that and adds a test case to avoid regressions. Fixes #50951 Change-Id: Ic782b5257fe90b05e3def8dbf0bb8d4ed37a190b Reviewed-on: https://go-review.googlesource.com/c/go/+/525475 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/sys_windows_amd64.s')
-rw-r--r--src/runtime/sys_windows_amd64.s34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s
index 6cc8e91952..c1b78e3976 100644
--- a/src/runtime/sys_windows_amd64.s
+++ b/src/runtime/sys_windows_amd64.s
@@ -102,7 +102,7 @@ TEXT runtime·getlasterror(SB),NOSPLIT,$0
// exception record and context pointers.
// DX is the kind of sigtramp function.
// Return value of sigtrampgo is stored in AX.
-TEXT sigtramp<>(SB),NOSPLIT|NOFRAME,$0-0
+TEXT sigtramp<>(SB),NOSPLIT,$0-0
// Switch from the host ABI to the Go ABI.
PUSH_REGS_HOST_TO_ABI0()
@@ -155,6 +155,38 @@ TEXT runtime·lastcontinuetramp(SB),NOSPLIT|NOFRAME,$0-0
MOVQ $const_callbackLastVCH, DX
JMP sigtramp<>(SB)
+TEXT runtime·sehtramp(SB),NOSPLIT,$40-0
+ // CX: PEXCEPTION_RECORD ExceptionRecord
+ // DX: ULONG64 EstablisherFrame
+ // R8: PCONTEXT ContextRecord
+ // R9: PDISPATCHER_CONTEXT DispatcherContext
+ // Switch from the host ABI to the Go ABI.
+ PUSH_REGS_HOST_TO_ABI0()
+
+ get_tls(AX)
+ CMPQ AX, $0
+ JNE 2(PC)
+ // This shouldn't happen, sehtramp is only attached to functions
+ // called from Go, and exception handlers are only called from
+ // the thread that threw the exception.
+ INT $3
+
+ // Exception from Go thread, set R14.
+ MOVQ g(AX), R14
+
+ ADJSP $40
+ MOVQ CX, 0(SP)
+ MOVQ DX, 8(SP)
+ MOVQ R8, 16(SP)
+ MOVQ R9, 24(SP)
+ CALL runtime·sehhandler(SB)
+ MOVL 32(SP), AX
+
+ ADJSP $-40
+
+ POP_REGS_HOST_TO_ABI0()
+ RET
+
TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0
// Construct args vector for cgocallback().
// By windows/amd64 calling convention first 4 args are in CX, DX, R8, R9