Windows: enable nimRawSetjmp by default [backport] (#19891)

* Windows: enable nimRawSetjmp by default

See #19197. The default setjmp can randomly segfault on windows

* Attempt to disable the flag for bootstraping

* Disable styleCheck for c_setjmp
This commit is contained in:
Tanguy
2022-06-14 12:37:31 +02:00
committed by GitHub
parent b41226001c
commit 251bdc1d5a
2 changed files with 12 additions and 0 deletions

View File

@@ -20,5 +20,10 @@ when defined(nimStrictMode):
switch("hintAsError", "ConvFromXtoItselfNotNeeded")
# future work: XDeclaredButNotUsed
when defined(windows) and not defined(booting):
# Avoid some rare stack corruption while using exceptions with a SEH-enabled
# toolchain: https://github.com/nim-lang/Nim/pull/19197
switch("define", "nimRawSetjmp")
switch("define", "nimVersion:" & NimVersion)
switch("define", "nimPreviewDotLikeOps")

View File

@@ -116,6 +116,7 @@ elif defined(nimBuiltinSetjmp):
proc c_builtin_setjmp(jmpb: ptr pointer): cint {.
importc: "__builtin_setjmp", nodecl.}
c_builtin_setjmp(unsafeAddr jmpb[0])
elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
when defined(windows):
# No `_longjmp()` on Windows.
@@ -127,10 +128,16 @@ elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
# prone to stack corruption during unwinding, so we disable that by setting
# it to NULL.
# More details: https://github.com/status-im/nimbus-eth2/issues/3121
when defined(nimHasStyleChecks):
{.push styleChecks: off.}
proc c_setjmp*(jmpb: C_JmpBuf): cint =
proc c_setjmp_win(jmpb: C_JmpBuf, ctx: pointer): cint {.
header: "<setjmp.h>", importc: "_setjmp".}
c_setjmp_win(jmpb, nil)
when defined(nimHasStyleChecks):
{.pop.}
else:
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
header: "<setjmp.h>", importc: "_longjmp".}