Skip to content

Conversation

@tsujamin
Copy link
Contributor

@tsujamin tsujamin commented Dec 1, 2025

The MSVC /RTCs argument instruments alloca() to prepend stack allocations with metadata used to check for memory corruption during the function prologue. This causes stack-based FFI arguments in janet_ffi_win64 to become mis-aligned, and also for the alloca()-prepended header to be corrupted leading to a fatal exception.

This change fixes the fatal error (#1675) by disabling /RTCs during janet_ffi_win64 codegen.

The MSVC /RTCs argument instrument alloca() to prepend stack allocations
with metadata used to check for memory corruption during the function
prologue. This causes stack-based FFI arguments in janet_ffi_win64 to
become mis-aligned, and also for the alloca()-prepended header to be
corrupted leading to a fatal exception.
@tsujamin
Copy link
Contributor Author

tsujamin commented Dec 1, 2025

Apologies for the fix being based on an older tag, I've got 1.38 vendored into another project. The bug and the fix repro correctly on current master.

@bakpakin
Copy link
Member

bakpakin commented Dec 2, 2025

LGTM, thanks for the fix. I was wondering why MSVC was adding extra padding bytes to the stack when using alloca, and this illustrates one use of that extra space.

@bakpakin bakpakin merged commit c2cbfa4 into janet-lang:master Dec 2, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants