Skip to content

Commit a1f413b

Browse files
Menduistnarimiran
authored andcommitted
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 (cherry picked from commit 251bdc1)
1 parent 2064fda commit a1f413b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

config/config.nims

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ when defined(nimStrictMode):
2020
switch("hintAsError", "ConvFromXtoItselfNotNeeded")
2121
# future work: XDeclaredButNotUsed
2222

23+
when defined(windows) and not defined(booting):
24+
# Avoid some rare stack corruption while using exceptions with a SEH-enabled
25+
# toolchain: https://github.com/nim-lang/Nim/pull/19197
26+
switch("define", "nimRawSetjmp")
27+
2328
switch("define", "nimVersion:" & NimVersion)

lib/system/ansi_c.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ elif defined(nimBuiltinSetjmp):
116116
proc c_builtin_setjmp(jmpb: ptr pointer): cint {.
117117
importc: "__builtin_setjmp", nodecl.}
118118
c_builtin_setjmp(unsafeAddr jmpb[0])
119+
119120
elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
120121
when defined(windows):
121122
# No `_longjmp()` on Windows.
@@ -127,10 +128,16 @@ elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
127128
# prone to stack corruption during unwinding, so we disable that by setting
128129
# it to NULL.
129130
# More details: https://github.com/status-im/nimbus-eth2/issues/3121
131+
when defined(nimHasStyleChecks):
132+
{.push styleChecks: off.}
133+
130134
proc c_setjmp*(jmpb: C_JmpBuf): cint =
131135
proc c_setjmp_win(jmpb: C_JmpBuf, ctx: pointer): cint {.
132136
header: "<setjmp.h>", importc: "_setjmp".}
133137
c_setjmp_win(jmpb, nil)
138+
139+
when defined(nimHasStyleChecks):
140+
{.pop.}
134141
else:
135142
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
136143
header: "<setjmp.h>", importc: "_longjmp".}

0 commit comments

Comments
 (0)