syscall-napi 0.0.8 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -21
- package/lib/constants/arm.ts +340 -0
- package/lib/constants/arm64.ts +314 -0
- package/lib/constants/index.ts +32 -0
- package/lib/constants/x64.ts +314 -0
- package/lib/index.ts +49 -0
- package/native/syscall.c +0 -93
- package/package.json +18 -8
- package/samples/getpid.ts +12 -0
- package/.jsbeautifyrc +0 -24
- package/binding.gyp +0 -8
- package/eslint.config.js +0 -81
- package/lib/constants/arm.js +0 -263
- package/lib/constants/arm64.js +0 -266
- package/lib/constants/index.js +0 -23
- package/lib/constants/x64.js +0 -267
- package/lib/index.js +0 -26
- package/samples/getpid.js +0 -11
- package/test/basic.js +0 -19
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { syscallNumbers as syscallNumbersX86_64 } from "./x64.ts";
|
|
2
|
+
import { syscallNumbers as syscallNumbersArm64 } from "./arm64.ts";
|
|
3
|
+
import { syscallNumbers as syscallNumbersArm } from "./arm.ts";
|
|
4
|
+
import nodeProcess from "node:process";
|
|
5
|
+
|
|
6
|
+
if (nodeProcess.platform !== "linux") {
|
|
7
|
+
throw Error("only supported on linux");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type Common<T, U> = Pick<T, Extract<keyof T, keyof U>>;
|
|
11
|
+
|
|
12
|
+
type TCommonSyscallConstants = Common<Common<typeof syscallNumbersX86_64, typeof syscallNumbersArm64>, typeof syscallNumbersArm>;
|
|
13
|
+
|
|
14
|
+
type TSyscallConstants = TCommonSyscallConstants &
|
|
15
|
+
(Partial<typeof syscallNumbersX86_64> & Partial<typeof syscallNumbersArm64> & Partial<typeof syscallNumbersArm>);
|
|
16
|
+
|
|
17
|
+
const syscallNumbersByArch: Partial<{ [key in NodeJS.Architecture]: TSyscallConstants }> = {
|
|
18
|
+
x64: syscallNumbersX86_64,
|
|
19
|
+
arm64: syscallNumbersArm64,
|
|
20
|
+
arm: syscallNumbersArm,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const syscallNumbersOfArch = syscallNumbersByArch[nodeProcess.arch];
|
|
24
|
+
if (syscallNumbersOfArch === undefined) {
|
|
25
|
+
throw Error(`unsupported architecture: ${nodeProcess.arch}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const syscallNumbers = syscallNumbersOfArch!;
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
syscallNumbers
|
|
32
|
+
};
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
const syscallNumbers = {
|
|
2
|
+
io_setup: 206n,
|
|
3
|
+
io_destroy: 207n,
|
|
4
|
+
io_submit: 209n,
|
|
5
|
+
io_cancel: 210n,
|
|
6
|
+
io_getevents: 208n,
|
|
7
|
+
setxattr: 188n,
|
|
8
|
+
lsetxattr: 189n,
|
|
9
|
+
fsetxattr: 190n,
|
|
10
|
+
getxattr: 191n,
|
|
11
|
+
lgetxattr: 192n,
|
|
12
|
+
fgetxattr: 193n,
|
|
13
|
+
listxattr: 194n,
|
|
14
|
+
llistxattr: 195n,
|
|
15
|
+
flistxattr: 196n,
|
|
16
|
+
removexattr: 197n,
|
|
17
|
+
lremovexattr: 198n,
|
|
18
|
+
fremovexattr: 199n,
|
|
19
|
+
getcwd: 79n,
|
|
20
|
+
lookup_dcookie: 212n,
|
|
21
|
+
eventfd2: 290n,
|
|
22
|
+
epoll_create1: 291n,
|
|
23
|
+
epoll_ctl: 233n,
|
|
24
|
+
epoll_pwait: 281n,
|
|
25
|
+
dup: 32n,
|
|
26
|
+
dup3: 292n,
|
|
27
|
+
inotify_init1: 294n,
|
|
28
|
+
inotify_add_watch: 254n,
|
|
29
|
+
inotify_rm_watch: 255n,
|
|
30
|
+
ioctl: 16n,
|
|
31
|
+
ioprio_set: 251n,
|
|
32
|
+
ioprio_get: 252n,
|
|
33
|
+
flock: 73n,
|
|
34
|
+
mknodat: 259n,
|
|
35
|
+
mkdirat: 258n,
|
|
36
|
+
unlinkat: 263n,
|
|
37
|
+
symlinkat: 266n,
|
|
38
|
+
linkat: 265n,
|
|
39
|
+
renameat: 264n,
|
|
40
|
+
umount2: 166n,
|
|
41
|
+
mount: 165n,
|
|
42
|
+
pivot_root: 155n,
|
|
43
|
+
nfsservctl: 180n,
|
|
44
|
+
fallocate: 285n,
|
|
45
|
+
faccessat: 269n,
|
|
46
|
+
chdir: 80n,
|
|
47
|
+
fchdir: 81n,
|
|
48
|
+
chroot: 161n,
|
|
49
|
+
fchmod: 91n,
|
|
50
|
+
fchmodat: 268n,
|
|
51
|
+
fchownat: 260n,
|
|
52
|
+
fchown: 93n,
|
|
53
|
+
openat: 257n,
|
|
54
|
+
close: 3n,
|
|
55
|
+
vhangup: 153n,
|
|
56
|
+
pipe2: 293n,
|
|
57
|
+
quotactl: 179n,
|
|
58
|
+
getdents64: 217n,
|
|
59
|
+
read: 0n,
|
|
60
|
+
write: 1n,
|
|
61
|
+
readv: 19n,
|
|
62
|
+
writev: 20n,
|
|
63
|
+
pread64: 17n,
|
|
64
|
+
pwrite64: 18n,
|
|
65
|
+
preadv: 295n,
|
|
66
|
+
pwritev: 296n,
|
|
67
|
+
pselect6: 270n,
|
|
68
|
+
ppoll: 271n,
|
|
69
|
+
signalfd4: 289n,
|
|
70
|
+
vmsplice: 278n,
|
|
71
|
+
splice: 275n,
|
|
72
|
+
tee: 276n,
|
|
73
|
+
readlinkat: 267n,
|
|
74
|
+
sync: 162n,
|
|
75
|
+
fsync: 74n,
|
|
76
|
+
fdatasync: 75n,
|
|
77
|
+
sync_file_range: 277n,
|
|
78
|
+
timerfd_create: 283n,
|
|
79
|
+
timerfd_settime: 286n,
|
|
80
|
+
timerfd_gettime: 287n,
|
|
81
|
+
utimensat: 280n,
|
|
82
|
+
acct: 163n,
|
|
83
|
+
capget: 125n,
|
|
84
|
+
capset: 126n,
|
|
85
|
+
personality: 135n,
|
|
86
|
+
exit: 60n,
|
|
87
|
+
exit_group: 231n,
|
|
88
|
+
waitid: 247n,
|
|
89
|
+
set_tid_address: 218n,
|
|
90
|
+
unshare: 272n,
|
|
91
|
+
futex: 202n,
|
|
92
|
+
set_robust_list: 273n,
|
|
93
|
+
get_robust_list: 274n,
|
|
94
|
+
nanosleep: 35n,
|
|
95
|
+
getitimer: 36n,
|
|
96
|
+
setitimer: 38n,
|
|
97
|
+
kexec_load: 246n,
|
|
98
|
+
init_module: 175n,
|
|
99
|
+
delete_module: 176n,
|
|
100
|
+
timer_create: 222n,
|
|
101
|
+
timer_gettime: 224n,
|
|
102
|
+
timer_getoverrun: 225n,
|
|
103
|
+
timer_settime: 223n,
|
|
104
|
+
timer_delete: 226n,
|
|
105
|
+
clock_settime: 227n,
|
|
106
|
+
clock_gettime: 228n,
|
|
107
|
+
clock_getres: 229n,
|
|
108
|
+
clock_nanosleep: 230n,
|
|
109
|
+
syslog: 103n,
|
|
110
|
+
ptrace: 101n,
|
|
111
|
+
sched_setparam: 142n,
|
|
112
|
+
sched_setscheduler: 144n,
|
|
113
|
+
sched_getscheduler: 145n,
|
|
114
|
+
sched_getparam: 143n,
|
|
115
|
+
sched_setaffinity: 203n,
|
|
116
|
+
sched_getaffinity: 204n,
|
|
117
|
+
sched_yield: 24n,
|
|
118
|
+
sched_get_priority_max: 146n,
|
|
119
|
+
sched_get_priority_min: 147n,
|
|
120
|
+
sched_rr_get_interval: 148n,
|
|
121
|
+
restart_syscall: 219n,
|
|
122
|
+
kill: 62n,
|
|
123
|
+
tkill: 200n,
|
|
124
|
+
tgkill: 234n,
|
|
125
|
+
sigaltstack: 131n,
|
|
126
|
+
rt_sigsuspend: 130n,
|
|
127
|
+
rt_sigaction: 13n,
|
|
128
|
+
rt_sigprocmask: 14n,
|
|
129
|
+
rt_sigpending: 127n,
|
|
130
|
+
rt_sigtimedwait: 128n,
|
|
131
|
+
rt_sigqueueinfo: 129n,
|
|
132
|
+
rt_sigreturn: 15n,
|
|
133
|
+
setpriority: 141n,
|
|
134
|
+
getpriority: 140n,
|
|
135
|
+
reboot: 169n,
|
|
136
|
+
setregid: 114n,
|
|
137
|
+
setgid: 106n,
|
|
138
|
+
setreuid: 113n,
|
|
139
|
+
setuid: 105n,
|
|
140
|
+
setresuid: 117n,
|
|
141
|
+
getresuid: 118n,
|
|
142
|
+
setresgid: 119n,
|
|
143
|
+
getresgid: 120n,
|
|
144
|
+
setfsuid: 122n,
|
|
145
|
+
setfsgid: 123n,
|
|
146
|
+
times: 100n,
|
|
147
|
+
setpgid: 109n,
|
|
148
|
+
getpgid: 121n,
|
|
149
|
+
getsid: 124n,
|
|
150
|
+
setsid: 112n,
|
|
151
|
+
getgroups: 115n,
|
|
152
|
+
setgroups: 116n,
|
|
153
|
+
uname: 63n,
|
|
154
|
+
sethostname: 170n,
|
|
155
|
+
setdomainname: 171n,
|
|
156
|
+
getrlimit: 97n,
|
|
157
|
+
setrlimit: 160n,
|
|
158
|
+
getrusage: 98n,
|
|
159
|
+
umask: 95n,
|
|
160
|
+
prctl: 157n,
|
|
161
|
+
getcpu: 309n,
|
|
162
|
+
gettimeofday: 96n,
|
|
163
|
+
settimeofday: 164n,
|
|
164
|
+
adjtimex: 159n,
|
|
165
|
+
getpid: 39n,
|
|
166
|
+
getppid: 110n,
|
|
167
|
+
getuid: 102n,
|
|
168
|
+
geteuid: 107n,
|
|
169
|
+
getgid: 104n,
|
|
170
|
+
getegid: 108n,
|
|
171
|
+
gettid: 186n,
|
|
172
|
+
sysinfo: 99n,
|
|
173
|
+
mq_open: 240n,
|
|
174
|
+
mq_unlink: 241n,
|
|
175
|
+
mq_timedsend: 242n,
|
|
176
|
+
mq_timedreceive: 243n,
|
|
177
|
+
mq_notify: 244n,
|
|
178
|
+
mq_getsetattr: 245n,
|
|
179
|
+
msgget: 68n,
|
|
180
|
+
msgctl: 71n,
|
|
181
|
+
msgrcv: 70n,
|
|
182
|
+
msgsnd: 69n,
|
|
183
|
+
semget: 64n,
|
|
184
|
+
semctl: 66n,
|
|
185
|
+
semtimedop: 220n,
|
|
186
|
+
semop: 65n,
|
|
187
|
+
shmget: 29n,
|
|
188
|
+
shmctl: 31n,
|
|
189
|
+
shmat: 30n,
|
|
190
|
+
shmdt: 67n,
|
|
191
|
+
socket: 41n,
|
|
192
|
+
socketpair: 53n,
|
|
193
|
+
bind: 49n,
|
|
194
|
+
listen: 50n,
|
|
195
|
+
accept: 43n,
|
|
196
|
+
connect: 42n,
|
|
197
|
+
getsockname: 51n,
|
|
198
|
+
getpeername: 52n,
|
|
199
|
+
sendto: 44n,
|
|
200
|
+
recvfrom: 45n,
|
|
201
|
+
setsockopt: 54n,
|
|
202
|
+
getsockopt: 55n,
|
|
203
|
+
shutdown: 48n,
|
|
204
|
+
sendmsg: 46n,
|
|
205
|
+
recvmsg: 47n,
|
|
206
|
+
readahead: 187n,
|
|
207
|
+
brk: 12n,
|
|
208
|
+
munmap: 11n,
|
|
209
|
+
mremap: 25n,
|
|
210
|
+
add_key: 248n,
|
|
211
|
+
request_key: 249n,
|
|
212
|
+
keyctl: 250n,
|
|
213
|
+
clone: 56n,
|
|
214
|
+
execve: 59n,
|
|
215
|
+
swapon: 167n,
|
|
216
|
+
swapoff: 168n,
|
|
217
|
+
mprotect: 10n,
|
|
218
|
+
msync: 26n,
|
|
219
|
+
mlock: 149n,
|
|
220
|
+
munlock: 150n,
|
|
221
|
+
mlockall: 151n,
|
|
222
|
+
munlockall: 152n,
|
|
223
|
+
mincore: 27n,
|
|
224
|
+
madvise: 28n,
|
|
225
|
+
remap_file_pages: 216n,
|
|
226
|
+
mbind: 237n,
|
|
227
|
+
get_mempolicy: 239n,
|
|
228
|
+
set_mempolicy: 238n,
|
|
229
|
+
migrate_pages: 256n,
|
|
230
|
+
move_pages: 279n,
|
|
231
|
+
rt_tgsigqueueinfo: 297n,
|
|
232
|
+
perf_event_open: 298n,
|
|
233
|
+
accept4: 288n,
|
|
234
|
+
recvmmsg: 299n,
|
|
235
|
+
wait4: 61n,
|
|
236
|
+
prlimit64: 302n,
|
|
237
|
+
fanotify_init: 300n,
|
|
238
|
+
fanotify_mark: 301n,
|
|
239
|
+
name_to_handle_at: 303n,
|
|
240
|
+
open_by_handle_at: 304n,
|
|
241
|
+
clock_adjtime: 305n,
|
|
242
|
+
syncfs: 306n,
|
|
243
|
+
setns: 308n,
|
|
244
|
+
sendmmsg: 307n,
|
|
245
|
+
process_vm_readv: 310n,
|
|
246
|
+
process_vm_writev: 311n,
|
|
247
|
+
kcmp: 312n,
|
|
248
|
+
finit_module: 313n,
|
|
249
|
+
sched_setattr: 314n,
|
|
250
|
+
sched_getattr: 315n,
|
|
251
|
+
renameat2: 316n,
|
|
252
|
+
seccomp: 317n,
|
|
253
|
+
getrandom: 318n,
|
|
254
|
+
memfd_create: 319n,
|
|
255
|
+
bpf: 321n,
|
|
256
|
+
execveat: 322n,
|
|
257
|
+
userfaultfd: 323n,
|
|
258
|
+
membarrier: 324n,
|
|
259
|
+
mlock2: 325n,
|
|
260
|
+
copy_file_range: 326n,
|
|
261
|
+
preadv2: 327n,
|
|
262
|
+
pwritev2: 328n,
|
|
263
|
+
pkey_mprotect: 329n,
|
|
264
|
+
pkey_alloc: 330n,
|
|
265
|
+
pkey_free: 331n,
|
|
266
|
+
statx: 332n,
|
|
267
|
+
io_pgetevents: 333n,
|
|
268
|
+
rseq: 334n,
|
|
269
|
+
kexec_file_load: 320n,
|
|
270
|
+
pidfd_send_signal: 424n,
|
|
271
|
+
io_uring_setup: 425n,
|
|
272
|
+
io_uring_enter: 426n,
|
|
273
|
+
io_uring_register: 427n,
|
|
274
|
+
open_tree: 428n,
|
|
275
|
+
move_mount: 429n,
|
|
276
|
+
fsopen: 430n,
|
|
277
|
+
fsconfig: 431n,
|
|
278
|
+
fsmount: 432n,
|
|
279
|
+
fspick: 433n,
|
|
280
|
+
pidfd_open: 434n,
|
|
281
|
+
clone3: 435n,
|
|
282
|
+
close_range: 436n,
|
|
283
|
+
openat2: 437n,
|
|
284
|
+
pidfd_getfd: 438n,
|
|
285
|
+
faccessat2: 439n,
|
|
286
|
+
process_madvise: 440n,
|
|
287
|
+
epoll_pwait2: 441n,
|
|
288
|
+
mount_setattr: 442n,
|
|
289
|
+
quotactl_fd: 443n,
|
|
290
|
+
landlock_create_ruleset: 444n,
|
|
291
|
+
landlock_add_rule: 445n,
|
|
292
|
+
landlock_restrict_self: 446n,
|
|
293
|
+
memfd_secret: 447n,
|
|
294
|
+
process_mrelease: 448n,
|
|
295
|
+
futex_waitv: 449n,
|
|
296
|
+
set_mempolicy_home_node: 450n,
|
|
297
|
+
fcntl: 72n,
|
|
298
|
+
statfs: 137n,
|
|
299
|
+
fstatfs: 138n,
|
|
300
|
+
truncate: 76n,
|
|
301
|
+
ftruncate: 77n,
|
|
302
|
+
lseek: 8n,
|
|
303
|
+
sendfile: 40n,
|
|
304
|
+
newfstatat: 262n,
|
|
305
|
+
fstat: 5n,
|
|
306
|
+
mmap: 9n,
|
|
307
|
+
fadvise64: 221n,
|
|
308
|
+
stat: 4n,
|
|
309
|
+
lstat: 6n,
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export {
|
|
313
|
+
syscallNumbers
|
|
314
|
+
};
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { syscallNumbers } from "./constants/index.ts";
|
|
2
|
+
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
let native;
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
native = require("../build/Release/syscall.node");
|
|
10
|
+
} catch {
|
|
11
|
+
native = require("../build/Debug/syscall.node");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { syscall_sync } = native;
|
|
15
|
+
|
|
16
|
+
type TSyscallResult = {
|
|
17
|
+
errno: undefined;
|
|
18
|
+
ret: bigint;
|
|
19
|
+
} | {
|
|
20
|
+
errno: number;
|
|
21
|
+
ret: undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const syscall = ({
|
|
25
|
+
syscallNumber,
|
|
26
|
+
args
|
|
27
|
+
}: {
|
|
28
|
+
syscallNumber: bigint;
|
|
29
|
+
args: (bigint | Uint8Array)[];
|
|
30
|
+
}): TSyscallResult => {
|
|
31
|
+
const { errno, ret } = syscall_sync(syscallNumber, ...args);
|
|
32
|
+
|
|
33
|
+
if (errno !== 0) {
|
|
34
|
+
return {
|
|
35
|
+
errno,
|
|
36
|
+
ret: undefined
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
errno: undefined,
|
|
42
|
+
ret
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
syscall,
|
|
48
|
+
syscallNumbers
|
|
49
|
+
};
|
package/native/syscall.c
CHANGED
|
@@ -14,98 +14,6 @@ struct syscall_ctx {
|
|
|
14
14
|
napi_ref arg_refs[7];
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
static void syscall_work(void* opaque) {
|
|
18
|
-
struct syscall_ctx* ctx = (struct syscall_ctx*) opaque;
|
|
19
|
-
|
|
20
|
-
ctx->res = syscall(ctx->num,
|
|
21
|
-
ctx->native_args[0],
|
|
22
|
-
ctx->native_args[1],
|
|
23
|
-
ctx->native_args[2],
|
|
24
|
-
ctx->native_args[3],
|
|
25
|
-
ctx->native_args[4],
|
|
26
|
-
ctx->native_args[5],
|
|
27
|
-
ctx->native_args[6]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static napi_status syscall_done(napi_env env, void* opaque, napi_deferred deferred) {
|
|
31
|
-
struct syscall_ctx* ctx = (struct syscall_ctx*) opaque;
|
|
32
|
-
long res = ctx->res;
|
|
33
|
-
napi_value result;
|
|
34
|
-
napi_value js_errno;
|
|
35
|
-
napi_value js_ret;
|
|
36
|
-
unsigned int i;
|
|
37
|
-
|
|
38
|
-
for(i = 0; i < sizeof(ctx->arg_refs) / sizeof(ctx->arg_refs[0]); i += 1) {
|
|
39
|
-
if(ctx->arg_refs[i] != NULL) {
|
|
40
|
-
// do not check error here as we could not handle it anyway
|
|
41
|
-
napi_delete_reference(env, ctx->arg_refs[i]);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
free(ctx);
|
|
46
|
-
|
|
47
|
-
NAPILIB_CHECK(napi_create_object(env, &result));
|
|
48
|
-
|
|
49
|
-
if (res < 0) {
|
|
50
|
-
NAPILIB_CHECK(napi_create_int32(env, errno, &js_errno));
|
|
51
|
-
NAPILIB_CHECK(napi_set_named_property(env, result, "errno", js_errno));
|
|
52
|
-
} else {
|
|
53
|
-
NAPILIB_CHECK(napi_create_int32(env, 0, &js_errno));
|
|
54
|
-
NAPILIB_CHECK(napi_set_named_property(env, result, "errno", js_errno));
|
|
55
|
-
|
|
56
|
-
NAPILIB_CHECK(napi_create_bigint_int64(env, res, &js_ret));
|
|
57
|
-
NAPILIB_CHECK(napi_set_named_property(env, result, "ret", js_ret));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
NAPILIB_CHECK(napi_resolve_deferred(env, deferred, result));
|
|
61
|
-
|
|
62
|
-
return napi_ok;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static napi_status syscall_async_entry(napi_env env, napi_value* args, int arg_count, napi_value* result) {
|
|
66
|
-
int i;
|
|
67
|
-
struct syscall_ctx* ctx = (struct syscall_ctx*) malloc(sizeof(*ctx));
|
|
68
|
-
memset(ctx, 0, sizeof(*ctx));
|
|
69
|
-
|
|
70
|
-
if(arg_count < 1) {
|
|
71
|
-
return napi_throw_error(env, NULL, "minimum required argument count for syscall() is 1");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if(arg_count > 8) {
|
|
75
|
-
return napi_throw_error(env, NULL, "maximum supported argument count for syscall() is 8");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
NAPILIB_CHECK(napilib_require_bigint_int64(env, args[0], &ctx->num));
|
|
79
|
-
|
|
80
|
-
for(i = 1; i < arg_count; i += 1) {
|
|
81
|
-
int arg_idx = i - 1;
|
|
82
|
-
bool is_buffer = 0;
|
|
83
|
-
|
|
84
|
-
NAPILIB_CHECK(napi_is_buffer(env, args[i], &is_buffer));
|
|
85
|
-
if(is_buffer) {
|
|
86
|
-
void* data;
|
|
87
|
-
size_t length;
|
|
88
|
-
|
|
89
|
-
NAPILIB_CHECK(napi_get_buffer_info(env, args[i], &data, &length));
|
|
90
|
-
ctx->native_args[arg_idx] = (long) data;
|
|
91
|
-
NAPILIB_CHECK(napi_create_reference(env, args[i], 1, &ctx->arg_refs[arg_idx]));
|
|
92
|
-
} else {
|
|
93
|
-
NAPILIB_CHECK(napilib_require_bigint_int64(env, args[i], &ctx->native_args[arg_idx]));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
NAPILIB_CHECK(napilib_execute_async(
|
|
98
|
-
env,
|
|
99
|
-
"syscall",
|
|
100
|
-
syscall_work,
|
|
101
|
-
syscall_done,
|
|
102
|
-
ctx,
|
|
103
|
-
result
|
|
104
|
-
));
|
|
105
|
-
|
|
106
|
-
return napi_ok;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
17
|
static napi_status syscall_sync_entry(napi_env env, napi_value* args, int arg_count, napi_value* result_ptr) {
|
|
110
18
|
int i;
|
|
111
19
|
napi_value result;
|
|
@@ -172,7 +80,6 @@ static napi_status create_module_instance(napi_env env, napi_value* res) {
|
|
|
172
80
|
|
|
173
81
|
NAPILIB_CHECK(napi_create_object(env, &exports));
|
|
174
82
|
|
|
175
|
-
NAPILIB_CHECK(napilib_set_named_simple_function_property(env, exports, "syscall_async", syscall_async_entry));
|
|
176
83
|
NAPILIB_CHECK(napilib_set_named_simple_function_property(env, exports, "syscall_sync", syscall_sync_entry));
|
|
177
84
|
|
|
178
85
|
*res = exports;
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "syscall-napi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "Node.js module to perform
|
|
6
|
-
"main": "lib/index.
|
|
4
|
+
"version": "0.1.1",
|
|
5
|
+
"description": "Node.js module to perform synchronous syscalls",
|
|
6
|
+
"main": "lib/index.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "c8 --reporter lcov --reporter html --reporter text mocha",
|
|
8
|
+
"test": "c8 --reporter lcov --reporter html --reporter text mocha test/**/*.ts",
|
|
9
9
|
"eslint": "eslint ."
|
|
10
10
|
},
|
|
11
|
+
"files": [
|
|
12
|
+
"lib/**/*",
|
|
13
|
+
"native/**/*",
|
|
14
|
+
"samples/**/*"
|
|
15
|
+
],
|
|
11
16
|
"repository": {
|
|
12
17
|
"type": "git",
|
|
13
18
|
"url": "git+https://github.com/k13-engineering/node-syscall-napi.git"
|
|
@@ -20,11 +25,16 @@
|
|
|
20
25
|
},
|
|
21
26
|
"homepage": "https://github.com/k13-engineering/node-syscall-napi#readme",
|
|
22
27
|
"devDependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
28
|
+
"@eslint/js": "^9.39.2",
|
|
29
|
+
"@types/mocha": "^10.0.10",
|
|
30
|
+
"@types/node": "^25.0.3",
|
|
31
|
+
"c8": "^10.1.3",
|
|
32
|
+
"eslint": "^9.39.2",
|
|
33
|
+
"mocha": "^11.7.1",
|
|
34
|
+
"node-archibald": "^0.0.7",
|
|
35
|
+
"typescript-eslint": "^8.51.0"
|
|
26
36
|
},
|
|
27
37
|
"dependencies": {
|
|
28
|
-
|
|
38
|
+
|
|
29
39
|
}
|
|
30
40
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { syscall, syscallNumbers } from "../lib/index.ts";
|
|
2
|
+
|
|
3
|
+
const { errno, ret: pid } = syscall({
|
|
4
|
+
syscallNumber: syscallNumbers.getpid,
|
|
5
|
+
args: []
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
if (errno === undefined) {
|
|
9
|
+
console.log(`pid = ${pid}`);
|
|
10
|
+
} else {
|
|
11
|
+
console.log(`errno = ${errno}`);
|
|
12
|
+
}
|
package/.jsbeautifyrc
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"js": {
|
|
3
|
-
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
|
|
4
|
-
"brace_style": "collapse-preserve-inline",
|
|
5
|
-
"break_chained_methods": false,
|
|
6
|
-
"e4x": false,
|
|
7
|
-
"end_with_newline": true,
|
|
8
|
-
"indent_char": " ",
|
|
9
|
-
"indent_level": 0,
|
|
10
|
-
"indent_size": 2,
|
|
11
|
-
"indent_with_tabs": false,
|
|
12
|
-
"jslint_happy": false,
|
|
13
|
-
"keep_array_indentation": false,
|
|
14
|
-
"keep_function_indentation": false,
|
|
15
|
-
"max_preserve_newlines": 0,
|
|
16
|
-
"preserve_newlines": true,
|
|
17
|
-
"space_after_anon_function": true,
|
|
18
|
-
"space_before_conditional": true,
|
|
19
|
-
"space_in_empty_paren": false,
|
|
20
|
-
"space_in_paren": false,
|
|
21
|
-
"unescape_strings": false,
|
|
22
|
-
"wrap_line_length": 0
|
|
23
|
-
}
|
|
24
|
-
}
|
package/binding.gyp
DELETED
package/eslint.config.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
rules: {
|
|
3
|
-
"global-require": "off",
|
|
4
|
-
"quote-props": ["warn", "consistent-as-needed"],
|
|
5
|
-
"comma-dangle": ["error", { arrays: "always-multiline", objects: "always-multiline", functions: "never" }],
|
|
6
|
-
"id-length": ["error", { min: 2, properties: "always", exceptions: ["i"] }],
|
|
7
|
-
"quotes": ["error", "double", { allowTemplateLiterals: true }],
|
|
8
|
-
"no-plusplus": "error",
|
|
9
|
-
"no-nested-ternary": "error",
|
|
10
|
-
"no-multiple-empty-lines": "error",
|
|
11
|
-
"no-inline-comments": "error",
|
|
12
|
-
"no-lonely-if": "error",
|
|
13
|
-
"no-array-constructor": "error",
|
|
14
|
-
"no-delete-var": "error",
|
|
15
|
-
"no-param-reassign": "error",
|
|
16
|
-
"no-return-assign": "error",
|
|
17
|
-
"no-import-assign": "error",
|
|
18
|
-
"no-multi-assign": "error",
|
|
19
|
-
"keyword-spacing": "error",
|
|
20
|
-
"max-len": [ "warn", { code: 140 } ],
|
|
21
|
-
"max-params": ["error", 4],
|
|
22
|
-
"max-statements": ["error", 15],
|
|
23
|
-
"no-loss-of-precision": "error",
|
|
24
|
-
"no-unreachable-loop": "error",
|
|
25
|
-
"require-atomic-updates": "error",
|
|
26
|
-
"complexity": ["error", 4],
|
|
27
|
-
"max-statements-per-line": ["error", { max: 1 }],
|
|
28
|
-
"no-tabs": "error",
|
|
29
|
-
"no-negated-condition": "error",
|
|
30
|
-
"no-use-before-define": "error",
|
|
31
|
-
"no-shadow": "error",
|
|
32
|
-
"no-labels": "error",
|
|
33
|
-
"no-throw-literal": "error",
|
|
34
|
-
"default-case": "error",
|
|
35
|
-
"default-case-last": "error",
|
|
36
|
-
"no-caller": "error",
|
|
37
|
-
"no-eval": "error",
|
|
38
|
-
"no-implied-eval": "error",
|
|
39
|
-
"no-new": "error",
|
|
40
|
-
"no-new-func": "error",
|
|
41
|
-
"no-new-object": "error",
|
|
42
|
-
"no-new-wrappers": "error",
|
|
43
|
-
"no-useless-concat": "error",
|
|
44
|
-
"no-unused-vars": ["error", { ignoreRestSiblings: true }],
|
|
45
|
-
"array-bracket-newline": ["error", "consistent"],
|
|
46
|
-
"func-names": ["error", "never"],
|
|
47
|
-
"func-style": ["error", "expression", { allowArrowFunctions: true }],
|
|
48
|
-
"max-depth": ["error", 4],
|
|
49
|
-
"arrow-parens": "error",
|
|
50
|
-
"no-confusing-arrow": "error",
|
|
51
|
-
"prefer-const": "error",
|
|
52
|
-
"rest-spread-spacing": ["error", "never"],
|
|
53
|
-
"template-curly-spacing": ["error", "never"],
|
|
54
|
-
"prefer-rest-params": "error",
|
|
55
|
-
"prefer-spread": "error",
|
|
56
|
-
"prefer-template": "error",
|
|
57
|
-
"object-shorthand": ["error", "properties"],
|
|
58
|
-
"no-var": "error",
|
|
59
|
-
"no-useless-computed-key": "error",
|
|
60
|
-
"array-callback-return": "error",
|
|
61
|
-
"consistent-return": "error",
|
|
62
|
-
"dot-notation": "error",
|
|
63
|
-
"eqeqeq": "error",
|
|
64
|
-
"no-eq-null": "error",
|
|
65
|
-
"no-implicit-coercion": "error",
|
|
66
|
-
"no-multi-spaces": "error",
|
|
67
|
-
"no-proto": "error",
|
|
68
|
-
"yoda": "error",
|
|
69
|
-
"indent": ["error", 2],
|
|
70
|
-
"object-curly-spacing": [ "error", "always" ],
|
|
71
|
-
"object-curly-newline": ["error", { consistent: true, multiline: true }],
|
|
72
|
-
"space-before-blocks": "error",
|
|
73
|
-
"space-before-function-paren": [ "error", "always" ],
|
|
74
|
-
"spaced-comment": "error",
|
|
75
|
-
"no-whitespace-before-property": "error",
|
|
76
|
-
"brace-style": ["error", "1tbs", { allowSingleLine: false }],
|
|
77
|
-
"eol-last": ["error", "always"],
|
|
78
|
-
"func-call-spacing": ["error", "never"],
|
|
79
|
-
"semi": ["error", "always"],
|
|
80
|
-
},
|
|
81
|
-
};
|