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:
parent
b41226001c
commit
251bdc1d5a
2 changed files with 12 additions and 0 deletions
|
|
@ -20,5 +20,10 @@ when defined(nimStrictMode):
|
||||||
switch("hintAsError", "ConvFromXtoItselfNotNeeded")
|
switch("hintAsError", "ConvFromXtoItselfNotNeeded")
|
||||||
# future work: XDeclaredButNotUsed
|
# 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", "nimVersion:" & NimVersion)
|
||||||
switch("define", "nimPreviewDotLikeOps")
|
switch("define", "nimPreviewDotLikeOps")
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ elif defined(nimBuiltinSetjmp):
|
||||||
proc c_builtin_setjmp(jmpb: ptr pointer): cint {.
|
proc c_builtin_setjmp(jmpb: ptr pointer): cint {.
|
||||||
importc: "__builtin_setjmp", nodecl.}
|
importc: "__builtin_setjmp", nodecl.}
|
||||||
c_builtin_setjmp(unsafeAddr jmpb[0])
|
c_builtin_setjmp(unsafeAddr jmpb[0])
|
||||||
|
|
||||||
elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
|
elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
# No `_longjmp()` on 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
|
# prone to stack corruption during unwinding, so we disable that by setting
|
||||||
# it to NULL.
|
# it to NULL.
|
||||||
# More details: https://github.com/status-im/nimbus-eth2/issues/3121
|
# 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*(jmpb: C_JmpBuf): cint =
|
||||||
proc c_setjmp_win(jmpb: C_JmpBuf, ctx: pointer): cint {.
|
proc c_setjmp_win(jmpb: C_JmpBuf, ctx: pointer): cint {.
|
||||||
header: "<setjmp.h>", importc: "_setjmp".}
|
header: "<setjmp.h>", importc: "_setjmp".}
|
||||||
c_setjmp_win(jmpb, nil)
|
c_setjmp_win(jmpb, nil)
|
||||||
|
|
||||||
|
when defined(nimHasStyleChecks):
|
||||||
|
{.pop.}
|
||||||
else:
|
else:
|
||||||
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
|
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
|
||||||
header: "<setjmp.h>", importc: "_longjmp".}
|
header: "<setjmp.h>", importc: "_longjmp".}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue