Skip to content

Commit 843c479

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 7b35ce9 commit 843c479

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

config/config.nims

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ cppDefine "NAN_INFINITY"
99
cppDefine "INF"
1010
cppDefine "NAN"
1111

12+
when defined(windows) and not defined(booting):
13+
# Avoid some rare stack corruption while using exceptions with a SEH-enabled
14+
# toolchain: https://github.com/nim-lang/Nim/pull/19197
15+
switch("define", "nimRawSetjmp")

lib/system/ansi_c.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ elif defined(nimBuiltinSetjmp):
113113
proc c_builtin_setjmp(jmpb: ptr pointer): cint {.
114114
importc: "__builtin_setjmp", nodecl.}
115115
c_builtin_setjmp(unsafeAddr jmpb[0])
116+
116117
elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
117118
when defined(windows):
118119
# No `_longjmp()` on Windows.
@@ -124,10 +125,16 @@ elif defined(nimRawSetjmp) and not defined(nimStdSetjmp):
124125
# prone to stack corruption during unwinding, so we disable that by setting
125126
# it to NULL.
126127
# More details: https://github.com/status-im/nimbus-eth2/issues/3121
128+
when defined(nimHasStyleChecks):
129+
{.push styleChecks: off.}
130+
127131
proc c_setjmp*(jmpb: C_JmpBuf): cint =
128132
proc c_setjmp_win(jmpb: C_JmpBuf, ctx: pointer): cint {.
129133
header: "<setjmp.h>", importc: "_setjmp".}
130134
c_setjmp_win(jmpb, nil)
135+
136+
when defined(nimHasStyleChecks):
137+
{.pop.}
131138
else:
132139
proc c_longjmp*(jmpb: C_JmpBuf, retval: cint) {.
133140
header: "<setjmp.h>", importc: "_longjmp".}

0 commit comments

Comments
 (0)