ffi: throw on fast calls to a closed library - #64855
Closed
trivikr wants to merge 1 commit into
Closed
Conversation
Close() marks every FFIFunction closed, but the generated fast-call path never sees it: V8 embeds the trampoline address when it compiles the call site, so an optimized call jumps into the library that dlclose() unloaded. Freeing the trampoline in Close() instead would leave compiled code calling unmapped memory. Give each library a one-byte flag that Close() sets and test it in the JavaScript wrapper before entering the trampoline. Fast signatures that need no argument conversion were handed to user code as the raw function, so they now get a guard-only wrapper too. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5
Collaborator
|
Review requested:
|
trivikr
marked this pull request as draft
July 31, 2026 03:03
Member
Author
|
Replaced by https://www.github.com/nodejs/node/pull/64860 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #64854
The
closedchecks in the C++ invokers cannot run on the fast-call path, since V8 embeds the trampoline address when it compiles the call site. So eachDynamicLibrarygets a one-byte flag thatClose()sets, and the JS wrapper tests it before entering the trampoline; freeing the trampoline instead would leave compiled code calling unmapped memory.That only works if every fast function is wrapped, so
CreateFunction()now attacheskFastArgumentsto all of them and signatures needing no argument conversion get a guard-only wrapper. For those signatureslib.functionsand friends now return a JS wrapper instead of a native function, withname,length, andpointercarried over.Assisted-by: claude:opus-5