Skip to content

ffi: reject multi-argument buffer fast trampolines - #67046

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
trivikr:ffi-arm64-fast-api-buffer-trampoline-args-2
Nov 9, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
trivikr:ffi-arm64-fast-api-buffer-trampoline-args-2

Conversation

@trivikr

@trivikr trivikr commented Oct 27, 2026

Copy link
Copy Markdown
Member

The arm64 and x86_64 SysV Fast API emitters convert a buffer argument by calling node_ffi_fast_buffer_data(). Arguments before the buffer are already in their target registers at that point, and the call clobbers them. For (i32, buffer) on arm64, the target receives (ptr, ptr).

No JS call can reach this today. Buffer-typed trampolines are only generated for single-argument signatures (SignatureNeedsFastBufferInvoke()), and the primary trampoline rewrites buffer to pointer.

This change makes both emitters reject buffer signatures with more than one argument. That matches the only shape generated today, so a future multi-argument caller falls back to another call path instead of getting a broken trampoline. Win64 already rejects buffer arguments.

No test is added because no JS call can reach the rejected signature.


Assisted-by: claude:opus-5.5

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Oct 27, 2026
@trivikr trivikr added ffi Issues and PRs related to experimental Foreign Function Interface support. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 27, 2026
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.71%. Comparing base (f344e7f) to head (5b8d358).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/ffi/platforms/arm64.cc 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67046      +/-   ##
==========================================
- Coverage   90.73%   90.71%   -0.02%     
==========================================
  Files         798      798              
  Lines      279993   279995       +2     
  Branches    53866    53857       -9     
==========================================
- Hits       254047   254004      -43     
- Misses      16229    16298      +69     
+ Partials     9717     9693      -24     
Files with missing lines Coverage Δ
src/ffi/platforms/arm64.cc 84.49% <0.00%> (-0.92%) ⬇️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The arm64 and x86_64 SysV emitters convert each buffer argument with a
helper call after loading earlier arguments into their target registers.
The call clobbers those registers, so the target would receive wrong
values for every argument before the buffer.

This is not reachable today: buffer-typed trampolines are generated only
for single-argument signatures. Reject other shapes in the emitters so a
future caller falls back instead of miscompiling.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
@trivikr
trivikr force-pushed the ffi-arm64-fast-api-buffer-trampoline-args-2 branch from 579dd76 to 5b8d358 Compare November 9, 2026 07:18
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 9, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added author ready PRs with CI started, the required approvals, and no outstanding review comments. resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. labels Nov 9, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 9, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 9, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 75d55af into nodejs:main Nov 9, 2026
76 of 78 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 75d55af

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants