Skip to content

Commit 75d55af

Browse files
authored
ffi: reject multi-argument buffer fast trampolines
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 PR-URL: #67046 Reviewed-By: Paolo Insogna <paolo@cowtech.it>
1 parent 04cd8c1 commit 75d55af

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/ffi/platforms/arm64.cc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ extern "C" bool node_ffi_create_fast_trampoline(
257257
if (has_buffer_args && fp_count != 0) {
258258
return false;
259259
}
260+
// The buffer helper call clobbers target registers already loaded for
261+
// earlier arguments, so buffer trampolines support a single argument only.
262+
if (has_buffer_args && argc > 1) {
263+
return false;
264+
}
260265

261266
const size_t incoming_gp_count = gp_count + (has_buffer_args ? 1 : 0);
262267
// When V8 passes FastApiCallbackOptions, it consumes one additional GP

‎src/ffi/platforms/x64.cc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ extern "C" bool node_ffi_create_fast_trampoline(
378378
if (has_buffer_args && fp_count != 0) {
379379
return false;
380380
}
381+
// The buffer helper call clobbers target registers already loaded for
382+
// earlier arguments, so buffer trampolines support a single argument only.
383+
if (has_buffer_args && argc > 1) {
384+
return false;
385+
}
381386

382387
const size_t incoming_gp_count = gp_count + (has_buffer_args ? 1 : 0);
383388
// rdi is occupied by the V8 receiver, leaving rsi, rdx, rcx, r8, and r9 for

0 commit comments

Comments
 (0)