aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvassvik <mvassvik@gmail.com>2021-08-28 13:32:13 +0200
committervassvik <mvassvik@gmail.com>2021-08-28 13:32:13 +0200
commit165118c64197bf962e78a9ea354bebe1141b6d7c (patch)
tree7df5019ad06e9f193365262ebdf08adec563d6f4
parent102d080a31f89b5497933ff1622c40df4bcaa6ec (diff)
Fix runtime crash for setjmp in Windows related to an hidden second argument not normally accessible needing to be set to 0.
-rw-r--r--core/c/libc/setjmp.odin35
1 files changed, 27 insertions, 8 deletions
diff --git a/core/c/libc/setjmp.odin b/core/c/libc/setjmp.odin
index e1915c01d..9eb12853c 100644
--- a/core/c/libc/setjmp.odin
+++ b/core/c/libc/setjmp.odin
@@ -8,16 +8,35 @@ when ODIN_OS == "windows" {
foreign import libc "system:c"
}
+when ODIN_OS == "windows" {
+ @(default_calling_convention="c")
+ foreign libc {
+ // 7.13.1 Save calling environment
+ //
+ // NOTE(dweiler): C11 requires setjmp be a macro, which means it won't
+ // necessarily export a symbol named setjmp but rather _setjmp in the case
+ // of musl, glibc, BSD libc, and msvcrt.
+ //
+ // TODO(mv): Some description of the extra argument, and maybe a link describing
+ // it in more detail?
+ @(link_name="_setjmp")
+ setjmp :: proc(env: ^jmp_buf, hack: rawptr = nil) -> int ---;
+ }
+} else {
+ @(default_calling_convention="c")
+ foreign libc {
+ // 7.13.1 Save calling environment
+ //
+ // NOTE(dweiler): C11 requires setjmp be a macro, which means it won't
+ // necessarily export a symbol named setjmp but rather _setjmp in the case
+ // of musl, glibc, BSD libc, and msvcrt.
+ @(link_name="_setjmp")
+ setjmp :: proc(env: ^jmp_buf) -> int ---;
+ }
+}
+
@(default_calling_convention="c")
foreign libc {
- // 7.13.1 Save calling environment
- //
- // NOTE(dweiler): C11 requires setjmp be a macro, which means it won't
- // necessarily export a symbol named setjmp but rather _setjmp in the case
- // of musl, glibc, BSD libc, and msvcrt.
- @(link_name="_setjmp")
- setjmp :: proc(env: ^jmp_buf) -> int ---;
-
// 7.13.2 Restore calling environment
longjmp :: proc(env: ^jmp_buf, val: int) -> ! ---;
}