kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 84391328a6db0a49e399438b7899ab18724949f5
parent 6e35c2a0243005dccb9ca712b84de24705e4d0f6
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Mon, 25 May 2026 13:05:09 -0700

core: stabilize panic save layout across C environments

Diffstat:
Msrc/core/core.c | 3+++
Msrc/core/core.h | 9+++++++--
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/core/core.c b/src/core/core.c @@ -13,6 +13,9 @@ #include "core/heap.h" #include "core/pool.h" +_Static_assert(sizeof(jmp_buf) <= COMPILER_PANIC_BYTES, + "Compiler panic save buffer is too small for jmp_buf"); + SourceManager* source_new(Compiler*); void source_free(SourceManager*); diff --git a/src/core/core.h b/src/core/core.h @@ -107,8 +107,9 @@ void source_depiter_free(SourceDepIter*); typedef struct CompilerCleanup CompilerCleanup; +#define COMPILER_PANIC_BYTES 256u + struct CfreeCompiler { - jmp_buf panic; const CfreeContext* ctx; Pool* global; Arena* tu; @@ -120,6 +121,10 @@ struct CfreeCompiler { const CfreeFrontendVTable* frontends[CFREE_LANG_COUNT]; void* cg_api; void (*cg_api_free)(Compiler*); + /* Keep jmp_buf last: its size comes from the including C environment + * (host libc for some tests, rt/include for libcfree), and must not shift + * the offsets of the fields above across those builds. */ + jmp_buf panic; }; void compiler_init(Compiler*, Target, const CfreeContext*); @@ -133,7 +138,7 @@ _Noreturn void compiler_panic(Compiler*, SrcLoc, const char* fmt, ...); _Noreturn void compiler_panicv(Compiler*, SrcLoc, const char* fmt, va_list); typedef struct PanicSave { - jmp_buf buf; + unsigned char buf[COMPILER_PANIC_BYTES]; } PanicSave; void compiler_panic_save(Compiler*, PanicSave* out); void compiler_panic_restore(Compiler*, const PanicSave* saved);