Skip to content

[Backport #143] Fix callback vtable lifetime#144

Merged
Jauler merged 1 commit intomain-v0.28.3from
LLT-6597_backport_movable_reference_fix
Sep 9, 2025
Merged

[Backport #143] Fix callback vtable lifetime#144
Jauler merged 1 commit intomain-v0.28.3from
LLT-6597_backport_movable_reference_fix

Conversation

@Jauler
Copy link
Contributor

@Jauler Jauler commented Sep 9, 2025

Passing vtable struct via 'ref' may cause invalid memory accesses when GC defragments the heap and may move the vtable struct address. To prevent GC from moving vtable struct, pin vtable struct using GCHandle.

To make the change work, update 'Reference' FFI type to use 'IntPtr' instead of 'ref'. Add some necessary casts from 'IntPtr' in callback implementation to make the code compile (the code previously used ref with concrete types).

@Jauler Jauler changed the title [Backport] Fix callback vtable lifetime [Backport #143] Fix callback vtable lifetime Sep 9, 2025
@Jauler Jauler force-pushed the LLT-6597_backport_movable_reference_fix branch from b3a1c02 to f37fc2a Compare September 9, 2025 07:39
Passing vtable struct via 'ref' may cause invalid memory accesses
when GC defragments the heap and may move the vtable struct address.
To prevent GC from moving vtable struct, pin vtable struct using GCHandle.

To make the change work, update 'Reference' FFI type to use 'IntPtr'
instead of 'ref'. Add some necessary casts from 'IntPtr' in callback
implementation to make the code compile (the code previously used ref
with concrete types).

Signed-off-by: Kristupas Antanavičius <antanaviciuskristupas@gmail.com>
@Jauler Jauler force-pushed the LLT-6597_backport_movable_reference_fix branch from f37fc2a to 751c112 Compare September 9, 2025 07:42
@Jauler Jauler merged commit 3264197 into main-v0.28.3 Sep 9, 2025
3 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.

3 participants

Comments