runtime: add Windows vectored exception handler for recoverable panics

Register a vectored exception handler at startup so Windows hardware
exceptions can be translated into Go panics. Access violations become
nil pointer panics, and integer divide-by-zero exceptions become divide
by zero panics, allowing defer/recover to handle them like ordinary
runtime panics.
This commit is contained in:
Jake Bailey
2026-05-10 15:56:22 -07:00
committed by Ron Evans
parent 29b4c6723f
commit 8ffabbea64
3 changed files with 59 additions and 0 deletions
+2
View File
@@ -485,6 +485,8 @@ func defaultTarget(options *Options) (*TargetSpec, error) {
"--no-insert-timestamp",
"--no-dynamicbase",
)
spec.ExtraFiles = append(spec.ExtraFiles,
"src/runtime/runtime_windows.c")
case "wasm", "wasip1", "wasip2":
return nil, fmt.Errorf("GOOS=%s but GOARCH is unset. Please set GOARCH to wasm", options.GOOS)
default: