forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-ffi-readonly-write.js
More file actions
31 lines (29 loc) · 984 Bytes
/
test-ffi-readonly-write.js
File metadata and controls
31 lines (29 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Flags: --experimental-ffi
'use strict';
const { skipIfFFIMissing, isWindows, skip } = require('../common');
const assert = require('node:assert');
const { spawnSync } = require('node:child_process');
const { test } = require('node:test');
const { fixtureSymbols, libraryPath } = require('./ffi-test-common');
skipIfFFIMissing();
if (isWindows) {
skip('This test currently relies on POSIX APIs');
}
test('writing to readonly memory via buffer fails', () => {
const symbols = JSON.stringify(fixtureSymbols);
const libPath = JSON.stringify(libraryPath);
const { stdout, status } = spawnSync(process.execPath, [
'--experimental-ffi',
'-p',
`
const ffi = require('node:ffi');
const { functions } = ffi.dlopen(${libPath}, ${symbols})
const p = functions.readonly_memory();
const b = ffi.toBuffer(p, 4096, false);
b[0] = 42;
console.log('success');
`,
]);
assert.notStrictEqual(status, 0);
assert.strictEqual(stdout.length, 0);
});