diff --git a/ffi.nimble b/ffi.nimble index 8312302..9e195a6 100644 --- a/ffi.nimble +++ b/ffi.nimble @@ -1,6 +1,6 @@ # ffi.nimble -version = "0.1.5" +version = "0.1.6" author = "Institute of Free Technology" description = "FFI framework with custom header generation" license = "MIT or Apache License 2.0" @@ -13,8 +13,8 @@ requires "chronicles" requires "taskpools" requires "cbor_serialization" -const nimFlagsOrc = "--mm:orc -d:chronicles_log_level=WARN" -const nimFlagsRefc = "--mm:refc -d:chronicles_log_level=WARN" +const nimFlagsOrc = "--mm:orc -d:chronicles_log_level=WARN -d:ffiAllowSignalHandler" +const nimFlagsRefc = "--mm:refc -d:chronicles_log_level=WARN -d:ffiAllowSignalHandler" import std/[algorithm, os, strutils] diff --git a/ffi/ffi_context.nim b/ffi/ffi_context.nim index 48e5e1b..c05b301 100644 --- a/ffi/ffi_context.nim +++ b/ffi/ffi_context.nim @@ -6,7 +6,20 @@ {.passc: "-fPIC".} -import std/[atomics, locks, options, tables, sequtils] +# Embedded in a foreign host (Go/Rust/...) the host must own OS signal handling; +# Nim installing its own handlers clobbers it (e.g. Go's SIGSEGV -> sigpanic). +# Enforce -d:noSignalHandler; standalone Nim binaries opt out via -d:ffiAllowSignalHandler. +when not defined(noSignalHandler) and not defined(ffiAllowSignalHandler): + {. + error: + "nim-ffi: missing required compile flag. If this library is embedded in a " & + "host process (Go/Rust/...), build with -d:noSignalHandler so the host keeps " & + "ownership of OS signal handlers (it needs SIGSEGV for crash recovery, stack " & + "growth and preemption). If instead this is a standalone Nim program that owns " & + "its own process, build with -d:ffiAllowSignalHandler." + .} + +import std/[atomics, locks, json, tables, sequtils] import chronicles, chronos, chronos/threadsync, taskpools/channels_spsc_single, results import ./ffi_types, ./ffi_thread_request, ./internal/ffi_macro, ./logging