Commit Graph
15 Commits
Author SHA1 Message Date
Junsoo Ha 7cb4e7fc46 ffi: support SharedArrayBuffer in getRawPointer
Signed-off-by: Junsoo Ha <junsoo2018@naver.com>
PR-URL: https://github.com/nodejs/node/pull/64864
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-08-04 15:58:10 +00:00
Antoine du Hamel a24bd2769f 2026-08-03, Version 26.6.0 (Current)
Notable changes:

doc:
  * add MikeMcC399 as collaborator (Mike McCready) https://github.com/nodejs/node/pull/64656
ffi:
  * (SEMVER-MINOR) add `getCurrentEventLoop` (Paolo Insogna) https://github.com/nodejs/node/pull/64323
test_runner:
  * (SEMVER-MINOR) add `context.log()` and `test:log` event (Moshe Atlow) https://github.com/nodejs/node/pull/64389
  * (SEMVER-MINOR) report `entryFile` in `TestStream` events (Moshe Atlow) https://github.com/nodejs/node/pull/64309

PR-URL: https://github.com/nodejs/node/pull/64655
2026-08-03 15:30:47 +02:00
Trivikram Kamat f43086d1e4 ffi: fix crash in refCallback and unrefCallback
Both handlers called fn.ClearWeak() and fn.SetWeak() without checking
whether the persistent handle was still populated. After the callback
function is garbage collected following an earlier unrefCallback()
call, the handle is empty and both V8 methods dereference a null slot.

InvokeCallback() already guarded against this. Add the same check to
both handlers and throw ERR_INVALID_ARG_VALUE, matching the existing
behavior for a pointer that is not in the callback map.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5
PR-URL: https://github.com/nodejs/node/pull/64881
Fixes: https://github.com/nodejs/node/issues/64880
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
2026-08-02 20:18:19 +00:00
Soul Lee 7c6bce0fea doc: add missing float32/float64 FFI type names
`ToFFIType()` accepts `float32` and `float64` as aliases for `float`
and `double`, and both names already appear in the `ffi.types`
constants list further down the same page, but they were missing from
the list of supported type names.

Also split `char` onto its own line. Unlike `u8`, `uint8` and `bool`,
which always map to `ffi_type_uint8`, `char` maps to either
`ffi_type_sint8` or `ffi_type_uint8` depending on the platform C ABI,
as the paragraph below the list already explains.

Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64874
Refs: https://github.com/nodejs/node/pull/62892
Refs: https://github.com/nodejs/node/issues/64848
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
2026-08-02 14:31:14 +00:00
Junsoo Ha cacd7a2662 doc: use ffi.suffix for library paths in examples
Replace hardcoded .so library paths with ffi.suffix
in the FFI documentation examples.

Signed-off-by: Junsoo Ha <junsoo2018@naver.com>
PR-URL: https://github.com/nodejs/node/pull/64805
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2026-07-30 12:56:43 +00:00
Paolo Insogna 3e8aa7de27 ffi: add getCurrentEventLoop
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Assisted-By: OpenAI:GPT-5.5 <openai/gpt-5.5>
PR-URL: https://github.com/nodejs/node/pull/64323
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
2026-07-08 13:24:50 +00:00
Daijiro Wachi ed33235bda doc: fix Fast FFI argument count in ffi.md
The text said functions with more than 7 arguments fall back to the
generic call path, contradicting the preceding sentence that Fast FFI
calls support up to 8 arguments.

The real limit is architecture- and type-dependent: the hard cap is 8
public arguments (src/ffi/fast.cc), but register pressure lowers the
effective count to 7 integer/pointer arguments on AArch64 and 6 on
x86-64, while floating-point arguments can use up to 8 on both. Describe
this instead of the previous, inaccurate single threshold.

Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63960
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-07-01 11:49:20 +00:00
Paolo InsognaandBryan English 3e55527eef ffi: add experimental fast FFI call API for AArch64 and x86_64
Add fast API trampolines for AArch64 and x86_64.

IsJitMemorySupported() maps an RW page, writes a ret instruction
(0xD65F03C0 AArch64 / 0xC3 x86_64), and mprotects it to RX. A
successful RX transition is treated as the support signal. The page is
deliberately not executed: this check may run during normal operation
(when an FFI function is first created), and executing freshly written
code from a capability probe could SIGSEGV/SIGKILL the process on
systems that block executable memory. The real trampoline emitter
performs the same mprotect at creation time and falls back to libffi
when it is rejected.

The result is computed once via std::call_once and cached for the
lifetime of the process, so concurrent callers never observe a
provisional value.

Wired into CreateFastFFIMetadata() for early nullptr bail-out when
JIT memory is unavailable.

Windows stub returns false (no trampolines yet on this branch).

IsFastCallEligible() validates at parse time whether a signature can
use the fast-call path, covering:

- Return and argument type eligibility (numeric, pointer; no structs)
- Argument count cap (8, matching V8 fast-call limit)
- Per-ABI register pressure limits that mirror the trampoline emitters
  (AArch64 and x86_64 SysV). Platforms without an emitter, including
  Win64, are reported ineligible.
- Buffer and float args cannot coexist, and buffer args additionally
  consume an extra GP register slot on both supported ABIs.

The arg/arg-name lengths are checked before the per-arg loop so a
malformed signature cannot index out of bounds.

Returns nullptr from CreateFastFFIMetadata() for ineligible signatures,
falling back to libffi.

Co-authored-by: Bryan English <bryan@bryanenglish.com>
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Signed-off-by: Bryan English <bryan@bryanenglish.com>
Assisted-By: OpenAI:GPT-5.5 <openai/gpt-5.5>
PR-URL: https://github.com/nodejs/node/pull/63068
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
2026-06-16 09:35:02 +00:00
René df09b2a48c ffi: remove function signature property aliases
Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
PR-URL: https://github.com/nodejs/node/pull/63482
Refs: https://github.com/nodejs/node/pull/62072/changes#r3067834658
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2026-05-24 12:39:53 +00:00
Paolo Insogna a2aeb72bff deps: add missing static linking targets for libffi
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
PR-URL: https://github.com/nodejs/node/pull/63168
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Richard Lau <richard.lau@ibm.com>
2026-05-11 17:30:23 +00:00
Antoine du Hamel a725fe1389 2026-05-07, Version 26.1.0 (Current)
Notable changes:

buffer:
  * (SEMVER-MINOR) add `end` parameter (Robert Nagy) https://github.com/nodejs/node/pull/62390
crypto:
  * (SEMVER-MINOR) accept key data in `crypto.diffieHellman()` and cleanup DH jobs (Filip Skokan) https://github.com/nodejs/node/pull/62527
  * (SEMVER-MINOR) implement `randomUUIDv7()` (nabeel378) https://github.com/nodejs/node/pull/62553
debugger:
  * (SEMVER-MINOR) add edit-free runtime expression probes to `node inspect` (Joyee Cheung) https://github.com/nodejs/node/pull/62713
fs:
  * (SEMVER-MINOR) add `signal` option to `fs.stat()` (Mert Can Altin) https://github.com/nodejs/node/pull/57775
  * (SEMVER-MINOR) expose frsize field in statfs (Jinho Jang) https://github.com/nodejs/node/pull/62277
http:
  * (SEMVER-MINOR) harden `ClientRequest` options merge (Matteo Collina) https://github.com/nodejs/node/pull/63082
  * (SEMVER-MINOR) add `req.signal` to `IncomingMessage` (Akshat) https://github.com/nodejs/node/pull/62541
lib,src,test,doc:
  * (SEMVER-MINOR) add `node:ffi` module (Colin Ihrig) https://github.com/nodejs/node/pull/62072
process:
  * (SEMVER-MINOR) throw on `execve(2)` failure instead of aborting (Bryan English) https://github.com/nodejs/node/pull/62878
src:
  * (SEMVER-MINOR) allow empty `--experimental-config-file` (Marco Ippolito) https://github.com/nodejs/node/pull/61610
stream:
  * (SEMVER-MINOR) propagate destruction in `duplexPair` (Ahmed Elhor) https://github.com/nodejs/node/pull/61098
test_runner:
  * (SEMVER-MINOR) align mock timeout api (sangwook) https://github.com/nodejs/node/pull/62820
  * (SEMVER-MINOR) add mock-timers support for `AbortSignal.timeout` (DeveloperViraj) https://github.com/nodejs/node/pull/60751
  * (SEMVER-MINOR) support test order randomization (Pietro Marchini) https://github.com/nodejs/node/pull/61747
util:
  * (SEMVER-MINOR) colorize text with hex colors (Guilherme Araújo) https://github.com/nodejs/node/pull/61556

PR-URL: https://github.com/nodejs/node/pull/63137
2026-05-07 12:01:50 +02:00
Matteo Collina 61db2609e3 ffi: support Symbol.dispose on DynamicLibrary
Install [Symbol.dispose]() on DynamicLibrary.prototype (calling close())
and on the object returned from ffi.dlopen(), so both can be used with
the `using` declaration for automatic cleanup.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/62925
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2026-04-29 11:13:47 +00:00
Bryan English 3a5344710a doc,test: mem protection must be observed in ffi
When using ffi.toBuffer, memory protection on any memory pages exposed
must be observed by the caller, otherwise crashes will occur.

Now documented, and tested.

PR-URL: https://github.com/nodejs/node/pull/62818
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-04-22 08:18:11 +00:00
Paolo Insogna 14e16db1bf lib: add new methods and error codes
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
PR-URL: https://github.com/nodejs/node/pull/62762
Reviewed-By: Xuguang Mei <meixuguang@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
2026-04-19 18:39:01 +00:00
cjihrigandPaolo Insogna d0fa608c07 lib,src,test,doc: add node:ffi module
PR-URL: https://github.com/nodejs/node/pull/62072
Co-authored-by: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
2026-04-14 10:44:30 +01:00