Skip to content

Commit fe8170e

Browse files
ShogunPandacjihrig
authored andcommitted
fix: Various improvements.
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 91d97f7 commit fe8170e

32 files changed

Lines changed: 502 additions & 95 deletions

.github/workflows/tools.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ on:
2626
- histogram
2727
- icu
2828
- inspector_protocol
29+
- libffi
2930
- libuv
3031
- llhttp
3132
- minimatch
@@ -169,6 +170,14 @@ jobs:
169170
cat temp-output
170171
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
171172
rm temp-output
173+
- id: libffi
174+
subsystem: deps
175+
label: dependencies, ffi
176+
run: |
177+
./tools/dep_updaters/update-libffi.sh > temp-output
178+
cat temp-output
179+
tail -n1 temp-output | grep "NEW_VERSION=" >> "$GITHUB_ENV" || true
180+
rm temp-output
172181
- id: libuv
173182
subsystem: deps
174183
label: dependencies

configure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,8 +2212,8 @@ def without_sqlite_error(option):
22122212

22132213
def bundled_ffi_supported(os_name, target_arch):
22142214
supported = {
2215-
'freebsd': {'arm', 'arm64', 'ia32', 'x64'},
2216-
'linux': {'arm', 'arm64', 'ia32', 'x64'},
2215+
'freebsd': {'arm', 'arm64', 'x64'},
2216+
'linux': {'arm', 'arm64', 'x64'},
22172217
'mac': {'arm64', 'x64'},
22182218
'win': {'arm', 'arm64', 'x64'},
22192219
}

deps/libffi/generate-headers.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@
1111
TARGETS = {
1212
('freebsd', 'arm'): ('ARM', 'arm'),
1313
('freebsd', 'arm64'): ('AARCH64', 'aarch64'),
14-
('freebsd', 'ia32'): ('X86_FREEBSD', 'x86'),
1514
('freebsd', 'x64'): ('X86_64', 'x86'),
16-
('freebsd', 'x86'): ('X86_FREEBSD', 'x86'),
1715
('linux', 'arm'): ('ARM', 'arm'),
1816
('linux', 'arm64'): ('AARCH64', 'aarch64'),
19-
('linux', 'ia32'): ('X86', 'x86'),
2017
('linux', 'x64'): ('X86_64', 'x86'),
21-
('linux', 'x86'): ('X86', 'x86'),
2218
('mac', 'arm64'): ('AARCH64', 'aarch64'),
2319
('mac', 'x64'): ('X86_64', 'x86'),
2420
('win', 'arm'): ('ARM_WIN32', 'arm'),
2521
('win', 'arm64'): ('ARM_WIN64', 'aarch64'),
26-
('win', 'ia32'): ('X86', 'x86'),
2722
('win', 'x64'): ('X86_WIN64', 'x86'),
2823
}
2924

deps/libffi/libffi.gyp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
],
4848
},
4949
}],
50-
['target_arch == "ia32" or target_arch == "x86"', {
51-
# Windows x86 is not supported by libffi
52-
'variables': {
53-
'libffi_arch_sources': [],
54-
},
55-
}],
5650
],
5751
}],
5852
['OS == "linux" or OS == "freebsd"', {
@@ -65,14 +59,6 @@
6559
],
6660
},
6761
}],
68-
['target_arch == "ia32" or target_arch == "x86"', {
69-
'variables': {
70-
'libffi_arch_sources': [
71-
'src/x86/ffi.c',
72-
'src/x86/sysv.S',
73-
],
74-
},
75-
}],
7662
['target_arch == "arm"', {
7763
'variables': {
7864
'libffi_arch_sources': [

doc/api/cli.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ added: REPLACEME
202202
When using the [Permission Model][], the process will not be able to use FFI
203203
APIs by default. Attempts to use FFI APIs will throw an `ERR_ACCESS_DENIED`
204204
exception unless the user explicitly passes the `--allow-ffi` flag when
205-
starting Node.js.
205+
starting Node.js. The [`node:ffi`][] module also requires the
206+
`--experimental-ffi` flag and is only available in builds with FFI support.
206207

207208
Example:
208209

@@ -1186,6 +1187,8 @@ added: REPLACEME
11861187
11871188
Enable the experimental [`node:ffi`][] module.
11881189

1190+
This flag is only available in builds with FFI support.
1191+
11891192
### `--experimental-import-meta-resolve`
11901193

11911194
<!-- YAML
@@ -1987,6 +1990,8 @@ added: REPLACEME
19871990

19881991
Disable the experimental [`node:ffi`][] module.
19891992

1993+
This flag is only available in builds with FFI support.
1994+
19901995
### `--no-experimental-sqlite`
19911996

19921997
<!-- YAML

doc/api/ffi.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import ffi from 'node:ffi';
2727
const ffi = require('node:ffi');
2828
```
2929

30-
This module is only available under the `node:` scheme and is gated by the
31-
`--experimental-ffi` flag.
30+
This module is only available under the `node:` scheme in builds with FFI
31+
support and is gated by the `--experimental-ffi` flag.
3232

3333
When using the [Permission Model][], FFI APIs are restricted unless the
3434
[`--allow-ffi`][] flag is provided.
@@ -69,6 +69,12 @@ Supported type names:
6969
Pointer-like types (`pointer`, `string`, `buffer`, `arraybuffer`, and
7070
`function`) are all passed through the native layer as pointers.
7171

72+
The `char` type follows the platform C ABI. On platforms where plain C `char`
73+
is signed it behaves like `i8`; otherwise it behaves like `u8`.
74+
75+
The `bool` type is marshaled as an 8-bit unsigned integer. Pass numeric values
76+
such as `0` and `1`; JavaScript `true` and `false` are not accepted.
77+
7278
## Signature objects
7379

7480
Functions and callbacks are described with signature objects.

doc/api/permissions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ using the [`--allow-child-process`][] and [`--allow-worker`][] respectively.
7171
To allow network access, use [`--allow-net`][] and for allowing native addons
7272
when using permission model, use the [`--allow-addons`][]
7373
flag. For WASI, use the [`--allow-wasi`][] flag. For FFI, use the
74-
[`--allow-ffi`][] flag.
74+
[`--allow-ffi`][] flag. The [`node:ffi`][] module also requires the
75+
`--experimental-ffi` flag and is only available in builds with FFI support.
7576

7677
#### Runtime API
7778

doc/contributing/maintaining/maintaining-dependencies.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This a list of all the dependencies:
2020
* [histogram][]
2121
* [icu-small][]
2222
* [inspector\_protocol][inspector_protocol]
23+
* [libffi][]
2324
* [libuv][]
2425
* [llhttp][]
2526
* [minimatch][]
@@ -278,6 +279,11 @@ The [inspector\_protocol](https://chromium.googlesource.com/deps/inspector_proto
278279
is Chromium's of code generators and templates for the inspector protocol.
279280
See [this doc](../../../tools/inspector_protocol/README.md) for more information.
280281

282+
### libffi
283+
284+
The [libffi](https://github.com/libffi/libffi) dependency is a portable foreign
285+
function interface library used by `node:ffi`.
286+
281287
### libuv
282288

283289
The [libuv](https://github.com/libuv/libuv) dependency is a
@@ -412,6 +418,7 @@ according to [RFC 8878](https://datatracker.ietf.org/doc/html/rfc8878).
412418
[histogram]: #histogram
413419
[icu-small]: #icu-small
414420
[inspector_protocol]: #inspector_protocol
421+
[libffi]: #libffi
415422
[libuv]: #libuv
416423
[llhttp]: #llhttp
417424
[maintaining-V8]: ./maintaining-V8.md

doc/node-config-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"allow-ffi": {
2626
"type": "boolean",
27-
"description": "allow use of FFI when any permissions are set"
27+
"description": "allow use of FFI when any permissions are set (only in builds with FFI support)"
2828
},
2929
"allow-fs-read": {
3030
"oneOf": [
@@ -176,7 +176,7 @@
176176
},
177177
"experimental-ffi": {
178178
"type": "boolean",
179-
"description": "experimental node:ffi module"
179+
"description": "experimental node:ffi module (only in builds with FFI support)"
180180
},
181181
"experimental-global-navigator": {
182182
"type": "boolean",
@@ -766,7 +766,7 @@
766766
},
767767
"allow-ffi": {
768768
"type": "boolean",
769-
"description": "allow use of FFI when any permissions are set"
769+
"description": "allow use of FFI when any permissions are set (only in builds with FFI support)"
770770
},
771771
"allow-child-process": {
772772
"type": "boolean",

lib/ffi.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
} = require('internal/errors');
99
const permission = require('internal/process/permission');
1010
const {
11+
validateInteger,
1112
validateString,
1213
} = require('internal/validators');
1314

@@ -45,7 +46,9 @@ function checkFFIPermission() {
4546
return;
4647
}
4748

48-
throw new ERR_ACCESS_DENIED('Access to this API has been restricted', 'FFI');
49+
throw new ERR_ACCESS_DENIED(
50+
'Access to this API has been restricted. Use --allow-ffi to manage permissions.',
51+
'FFI');
4952
}
5053

5154
function dlopen(path, definitions) {
@@ -58,6 +61,7 @@ function dlopen(path, definitions) {
5861
}
5962

6063
function dlclose(handle) {
64+
checkFFIPermission();
6165
handle.close();
6266
}
6367

@@ -70,8 +74,9 @@ function exportString(str, data, len, encoding = 'utf8') {
7074
checkFFIPermission();
7175
validateString(str, 'string');
7276
validateString(encoding, 'encoding');
77+
validateInteger(len, 'len', 0);
7378

74-
if (len <= 0) {
79+
if (len === 0) {
7580
return;
7681
}
7782

@@ -90,7 +95,9 @@ function exportBuffer(buffer, data, len) {
9095
throw new ERR_INVALID_ARG_TYPE('buffer', 'Buffer', buffer);
9196
}
9297

93-
if (len <= 0) {
98+
validateInteger(len, 'len', 0);
99+
100+
if (len === 0) {
94101
return;
95102
}
96103

0 commit comments

Comments
 (0)