Fix closures using FFI_REGISTER ABI (#949)

* Fix closures using FFI_REGISTER ABI

ffi_closure_REGISTER had the positions of the closure and return address
switched, resulting in a segfault when calling a closure created with
the FFI_REGISTER ABI.

* Fix comment and remove redundant assembly

* After fixing closures using FFI_REGISTER ABI, the comments were
  incorrect, not reflecting the value that was actually loaded into eax
  and ecx.
* Additionally, ecx was loaded with the data at esp + closure_FS only
  to write it back to esp + closure_FS. Both commands were removed as
  they end up not having any effect as ecx is overwritten during
  FFI_CLOSURE_COPY_TRAMP_DATA.
This commit is contained in:
Emil Taylor Bye 2025-12-26 16:04:51 +01:00 committed by GitHub
parent f067aef649
commit 2263d6037f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 6 deletions

View File

@ -458,9 +458,7 @@ L(UW24):
L(UW25):
# cfi_def_cfa_offset(closure_FS + 4)
FFI_CLOSURE_SAVE_REGS
movl closure_FS-4(%esp), %ecx /* load retaddr */
movl closure_FS(%esp), %eax /* load closure */
movl %ecx, closure_FS(%esp) /* move retaddr */
movl closure_FS-4(%esp), %eax /* load closure */
jmp L(do_closure_REGISTER)
L(UW26):
# cfi_endproc

View File

@ -394,9 +394,7 @@ L(UW24):
L(UW25):
/* cfi_def_cfa_offset(closure_FS + 4) */
FFI_CLOSURE_SAVE_REGS
mov ecx, [esp+closure_FS-4] /* load retaddr */
mov eax, [esp+closure_FS] /* load closure */
mov [esp+closure_FS], ecx /* move retaddr */
mov eax, [esp+closure_FS-4] /* load closure */
jmp L(do_closure_REGISTER)
L(UW26):
/* cfi_endproc */