Skip to content

Commit 70546f6

Browse files
zx2c4rsc
authored andcommitted
runtime: allow arm64 SEH to be called if illegal instruction
DLLs built with recent Microsoft toolchains for ARM64 test for ARMv8.1 atomics by potentially calling an illegal instruction, and then trapping the exception to disable use of them by way of a structured exception handler. However, vectored exception handlers are always called before structured exception handlers. When LoadLibrary-ing DLLs that do this probing during initialization, our lastcontinuehandler winds up being called, and then crashing, but actually it should give execution back to the library to handle the exception and fix up the state. So special case this for arm64 with illegal instructions, and hope that we're not masking other things in external DLLs that might more fatally trigger an illegal instruction exception. Updates #47576. Change-Id: I341ab99cd8d513ae999b75596749d49779072022 Reviewed-on: https://go-review.googlesource.com/c/go/+/340070 Trust: Jason A. Donenfeld <[email protected]> Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent fd45e26 commit 70546f6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/runtime/signal_windows.go

+11
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ func lastcontinuehandler(info *exceptionrecord, r *context, gp *g) int32 {
183183
return _EXCEPTION_CONTINUE_SEARCH
184184
}
185185

186+
// VEH is called before SEH, but arm64 MSVC DLLs use SEH to trap
187+
// illegal instructions during runtime initialization to determine
188+
// CPU features, so if we make it to the last handler and we're
189+
// arm64 and it's an illegal instruction and this is coming from
190+
// non-Go code, then assume it's this runtime probing happen, and
191+
// pass that onward to SEH.
192+
if GOARCH == "arm64" && info.exceptioncode == _EXCEPTION_ILLEGAL_INSTRUCTION &&
193+
(r.ip() < firstmoduledata.text || firstmoduledata.etext < r.ip()) {
194+
return _EXCEPTION_CONTINUE_SEARCH
195+
}
196+
186197
winthrow(info, r, gp)
187198
return 0 // not reached
188199
}

0 commit comments

Comments
 (0)