syscall-napi 0.0.1 → 0.0.6

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.
@@ -0,0 +1,267 @@
1
+ export default {
2
+ __NR_io_setup: 206n,
3
+ __NR_io_destroy: 207n,
4
+ __NR_io_submit: 209n,
5
+ __NR_io_cancel: 210n,
6
+ __NR_io_getevents: 208n,
7
+ __NR_setxattr: 188n,
8
+ __NR_lsetxattr: 189n,
9
+ __NR_fsetxattr: 190n,
10
+ __NR_getxattr: 191n,
11
+ __NR_lgetxattr: 192n,
12
+ __NR_fgetxattr: 193n,
13
+ __NR_listxattr: 194n,
14
+ __NR_llistxattr: 195n,
15
+ __NR_flistxattr: 196n,
16
+ __NR_removexattr: 197n,
17
+ __NR_lremovexattr: 198n,
18
+ __NR_fremovexattr: 199n,
19
+ __NR_getcwd: 79n,
20
+ __NR_lookup_dcookie: 212n,
21
+ __NR_eventfd2: 290n,
22
+ __NR_epoll_create1: 291n,
23
+ __NR_epoll_ctl: 233n,
24
+ __NR_epoll_pwait: 281n,
25
+ __NR_dup: 32n,
26
+ __NR_dup3: 292n,
27
+ __NR_inotify_init1: 294n,
28
+ __NR_inotify_add_watch: 254n,
29
+ __NR_inotify_rm_watch: 255n,
30
+ __NR_ioctl: 16n,
31
+ __NR_ioprio_set: 251n,
32
+ __NR_ioprio_get: 252n,
33
+ __NR_flock: 73n,
34
+ __NR_mknodat: 259n,
35
+ __NR_mkdirat: 258n,
36
+ __NR_unlinkat: 263n,
37
+ __NR_symlinkat: 266n,
38
+ __NR_linkat: 265n,
39
+ __NR_renameat: 264n,
40
+ __NR_umount2: 166n,
41
+ __NR_mount: 165n,
42
+ __NR_pivot_root: 155n,
43
+ __NR_nfsservctl: 180n,
44
+ __NR_fallocate: 285n,
45
+ __NR_faccessat: 269n,
46
+ __NR_chdir: 80n,
47
+ __NR_fchdir: 81n,
48
+ __NR_chroot: 161n,
49
+ __NR_fchmod: 91n,
50
+ __NR_fchmodat: 268n,
51
+ __NR_fchownat: 260n,
52
+ __NR_fchown: 93n,
53
+ __NR_openat: 257n,
54
+ __NR_close: 3n,
55
+ __NR_vhangup: 153n,
56
+ __NR_pipe2: 293n,
57
+ __NR_quotactl: 179n,
58
+ __NR_getdents64: 217n,
59
+ __NR_read: 0n,
60
+ __NR_write: 1n,
61
+ __NR_readv: 19n,
62
+ __NR_writev: 20n,
63
+ __NR_pread64: 17n,
64
+ __NR_pwrite64: 18n,
65
+ __NR_preadv: 295n,
66
+ __NR_pwritev: 296n,
67
+ __NR_pselect6: 270n,
68
+ __NR_ppoll: 271n,
69
+ __NR_signalfd4: 289n,
70
+ __NR_vmsplice: 278n,
71
+ __NR_splice: 275n,
72
+ __NR_tee: 276n,
73
+ __NR_readlinkat: 267n,
74
+ __NR_sync: 162n,
75
+ __NR_fsync: 74n,
76
+ __NR_fdatasync: 75n,
77
+ __NR_sync_file_range: 277n,
78
+ __NR_timerfd_create: 283n,
79
+ __NR_timerfd_settime: 286n,
80
+ __NR_timerfd_gettime: 287n,
81
+ __NR_utimensat: 280n,
82
+ __NR_acct: 163n,
83
+ __NR_capget: 125n,
84
+ __NR_capset: 126n,
85
+ __NR_personality: 135n,
86
+ __NR_exit: 60n,
87
+ __NR_exit_group: 231n,
88
+ __NR_waitid: 247n,
89
+ __NR_set_tid_address: 218n,
90
+ __NR_unshare: 272n,
91
+ __NR_futex: 202n,
92
+ __NR_set_robust_list: 273n,
93
+ __NR_get_robust_list: 274n,
94
+ __NR_nanosleep: 35n,
95
+ __NR_getitimer: 36n,
96
+ __NR_setitimer: 38n,
97
+ __NR_kexec_load: 246n,
98
+ __NR_init_module: 175n,
99
+ __NR_delete_module: 176n,
100
+ __NR_timer_create: 222n,
101
+ __NR_timer_gettime: 224n,
102
+ __NR_timer_getoverrun: 225n,
103
+ __NR_timer_settime: 223n,
104
+ __NR_timer_delete: 226n,
105
+ __NR_clock_settime: 227n,
106
+ __NR_clock_gettime: 228n,
107
+ __NR_clock_getres: 229n,
108
+ __NR_clock_nanosleep: 230n,
109
+ __NR_syslog: 103n,
110
+ __NR_ptrace: 101n,
111
+ __NR_sched_setparam: 142n,
112
+ __NR_sched_setscheduler: 144n,
113
+ __NR_sched_getscheduler: 145n,
114
+ __NR_sched_getparam: 143n,
115
+ __NR_sched_setaffinity: 203n,
116
+ __NR_sched_getaffinity: 204n,
117
+ __NR_sched_yield: 24n,
118
+ __NR_sched_get_priority_max: 146n,
119
+ __NR_sched_get_priority_min: 147n,
120
+ __NR_sched_rr_get_interval: 148n,
121
+ __NR_restart_syscall: 219n,
122
+ __NR_kill: 62n,
123
+ __NR_tkill: 200n,
124
+ __NR_tgkill: 234n,
125
+ __NR_sigaltstack: 131n,
126
+ __NR_rt_sigsuspend: 130n,
127
+ __NR_rt_sigaction: 13n,
128
+ __NR_rt_sigprocmask: 14n,
129
+ __NR_rt_sigpending: 127n,
130
+ __NR_rt_sigtimedwait: 128n,
131
+ __NR_rt_sigqueueinfo: 129n,
132
+ __NR_rt_sigreturn: 15n,
133
+ __NR_setpriority: 141n,
134
+ __NR_getpriority: 140n,
135
+ __NR_reboot: 169n,
136
+ __NR_setregid: 114n,
137
+ __NR_setgid: 106n,
138
+ __NR_setreuid: 113n,
139
+ __NR_setuid: 105n,
140
+ __NR_setresuid: 117n,
141
+ __NR_getresuid: 118n,
142
+ __NR_setresgid: 119n,
143
+ __NR_getresgid: 120n,
144
+ __NR_setfsuid: 122n,
145
+ __NR_setfsgid: 123n,
146
+ __NR_times: 100n,
147
+ __NR_setpgid: 109n,
148
+ __NR_getpgid: 121n,
149
+ __NR_getsid: 124n,
150
+ __NR_setsid: 112n,
151
+ __NR_getgroups: 115n,
152
+ __NR_setgroups: 116n,
153
+ __NR_uname: 63n,
154
+ __NR_sethostname: 170n,
155
+ __NR_setdomainname: 171n,
156
+ __NR_getrlimit: 97n,
157
+ __NR_setrlimit: 160n,
158
+ __NR_getrusage: 98n,
159
+ __NR_umask: 95n,
160
+ __NR_prctl: 157n,
161
+ __NR_getcpu: 309n,
162
+ __NR_gettimeofday: 96n,
163
+ __NR_settimeofday: 164n,
164
+ __NR_adjtimex: 159n,
165
+ __NR_getpid: 39n,
166
+ __NR_getppid: 110n,
167
+ __NR_getuid: 102n,
168
+ __NR_geteuid: 107n,
169
+ __NR_getgid: 104n,
170
+ __NR_getegid: 108n,
171
+ __NR_gettid: 186n,
172
+ __NR_sysinfo: 99n,
173
+ __NR_mq_open: 240n,
174
+ __NR_mq_unlink: 241n,
175
+ __NR_mq_timedsend: 242n,
176
+ __NR_mq_timedreceive: 243n,
177
+ __NR_mq_notify: 244n,
178
+ __NR_mq_getsetattr: 245n,
179
+ __NR_msgget: 68n,
180
+ __NR_msgctl: 71n,
181
+ __NR_msgrcv: 70n,
182
+ __NR_msgsnd: 69n,
183
+ __NR_semget: 64n,
184
+ __NR_semctl: 66n,
185
+ __NR_semtimedop: 220n,
186
+ __NR_semop: 65n,
187
+ __NR_shmget: 29n,
188
+ __NR_shmctl: 31n,
189
+ __NR_shmat: 30n,
190
+ __NR_shmdt: 67n,
191
+ __NR_socket: 41n,
192
+ __NR_socketpair: 53n,
193
+ __NR_bind: 49n,
194
+ __NR_listen: 50n,
195
+ __NR_accept: 43n,
196
+ __NR_connect: 42n,
197
+ __NR_getsockname: 51n,
198
+ __NR_getpeername: 52n,
199
+ __NR_sendto: 44n,
200
+ __NR_recvfrom: 45n,
201
+ __NR_setsockopt: 54n,
202
+ __NR_getsockopt: 55n,
203
+ __NR_shutdown: 48n,
204
+ __NR_sendmsg: 46n,
205
+ __NR_recvmsg: 47n,
206
+ __NR_readahead: 187n,
207
+ __NR_brk: 12n,
208
+ __NR_munmap: 11n,
209
+ __NR_mremap: 25n,
210
+ __NR_add_key: 248n,
211
+ __NR_request_key: 249n,
212
+ __NR_keyctl: 250n,
213
+ __NR_clone: 56n,
214
+ __NR_execve: 59n,
215
+ __NR_swapon: 167n,
216
+ __NR_swapoff: 168n,
217
+ __NR_mprotect: 10n,
218
+ __NR_msync: 26n,
219
+ __NR_mlock: 149n,
220
+ __NR_munlock: 150n,
221
+ __NR_mlockall: 151n,
222
+ __NR_munlockall: 152n,
223
+ __NR_mincore: 27n,
224
+ __NR_madvise: 28n,
225
+ __NR_remap_file_pages: 216n,
226
+ __NR_mbind: 237n,
227
+ __NR_get_mempolicy: 239n,
228
+ __NR_set_mempolicy: 238n,
229
+ __NR_migrate_pages: 256n,
230
+ __NR_move_pages: 279n,
231
+ __NR_rt_tgsigqueueinfo: 297n,
232
+ __NR_perf_event_open: 298n,
233
+ __NR_accept4: 288n,
234
+ __NR_recvmmsg: 299n,
235
+ __NR_wait4: 61n,
236
+ __NR_prlimit64: 302n,
237
+ __NR_fanotify_init: 300n,
238
+ __NR_fanotify_mark: 301n,
239
+ __NR_name_to_handle_at: 303n,
240
+ __NR_open_by_handle_at: 304n,
241
+ __NR_clock_adjtime: 305n,
242
+ __NR_syncfs: 306n,
243
+ __NR_setns: 308n,
244
+ __NR_sendmmsg: 307n,
245
+ __NR_process_vm_readv: 310n,
246
+ __NR_process_vm_writev: 311n,
247
+ __NR_kcmp: 312n,
248
+ __NR_finit_module: 313n,
249
+ __NR_sched_setattr: 314n,
250
+ __NR_sched_getattr: 315n,
251
+ __NR_renameat2: 316n,
252
+ __NR_seccomp: 317n,
253
+ __NR_getrandom: 318n,
254
+ __NR_memfd_create: 319n,
255
+ __NR_bpf: 321n,
256
+ __NR_execveat: 322n,
257
+ __NR_userfaultfd: 323n,
258
+ __NR_membarrier: 324n,
259
+ __NR_mlock2: 325n,
260
+ __NR_copy_file_range: 326n,
261
+ __NR_preadv2: 327n,
262
+ __NR_pwritev2: 328n,
263
+ __NR_pkey_mprotect: 329n,
264
+ __NR_pkey_alloc: 330n,
265
+ __NR_pkey_free: 331n,
266
+ __NR_statx: 332n,
267
+ };
package/lib/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import constants from "./constants/index.js";
2
+
1
3
  import { createRequire } from "module";
2
4
  const require = createRequire(import.meta.url);
3
5
 
@@ -9,4 +11,16 @@ try {
9
11
  native = require("../build/Debug/syscall.node");
10
12
  }
11
13
 
12
- export default native;
14
+ const { syscall_async, syscall_sync } = native;
15
+
16
+ const syscall = (...args) => {
17
+ return syscall_async(...args);
18
+ };
19
+ syscall.sync = (...args) => {
20
+ return syscall_sync(...args);
21
+ };
22
+
23
+ export default {
24
+ syscall,
25
+ ...constants,
26
+ };
package/native/napilib.h CHANGED
@@ -51,15 +51,6 @@ static napi_status napilib_throw_error_by_errno(napi_env env, int err) {
51
51
  return napi_pending_exception;
52
52
  }
53
53
 
54
- static napi_status napilib_set_named_bigint_int64_property(napi_env env, napi_value obj, const char* property_name, int64_t value) {
55
- napi_value bigint_int64_val;
56
-
57
- NAPILIB_CHECK(napi_create_bigint_int64(env, value, &bigint_int64_val));
58
- NAPILIB_CHECK(napi_set_named_property(env, obj, property_name, bigint_int64_val));
59
-
60
- return napi_ok;
61
- }
62
-
63
54
  typedef void (*napilib_work_t)(void* opaque);
64
55
  typedef napi_status (*napilib_work_done_t)(napi_env env, void* opaque, napi_deferred deferred);
65
56
 
@@ -177,19 +168,6 @@ static napi_status napilib_set_named_simple_function_property(napi_env env, napi
177
168
  return napi_ok;
178
169
  }
179
170
 
180
- // static napi_status napilib_throw_simple_error(napi_env env, const char* message) {
181
- // napi_value code;
182
- // napi_value message;
183
- // napi_value error;
184
- // napi_status status;
185
- //
186
- // NAPILIB_CHECK(napi_create_string_utf8(env, "", -1, &code));
187
- // NAPILIB_CHECK(napi_create_string_utf8(env, strerror(error_code), -1, &message));
188
- // NAPILIB_CHECK(napi_create_error(env, code, message, &error));
189
- //
190
- // return napi_pending_exception;
191
- // }
192
-
193
171
  static napi_status napilib_require_bigint_int64(napi_env env, napi_value value, int64_t* result) {
194
172
  napi_status status;
195
173
  bool lossless = 0;
package/native/syscall.c CHANGED
@@ -63,7 +63,7 @@ static napi_status syscall_done(napi_env env, void* opaque, napi_deferred deferr
63
63
  return napi_ok;
64
64
  }
65
65
 
66
- static napi_status syscall_entry(napi_env env, napi_value* args, int arg_count, napi_value* result) {
66
+ static napi_status syscall_async_entry(napi_env env, napi_value* args, int arg_count, napi_value* result) {
67
67
  int i;
68
68
  struct syscall_ctx* ctx = (struct syscall_ctx*) malloc(sizeof(*ctx));
69
69
  memset(ctx, 0, sizeof(*ctx));
@@ -107,274 +107,53 @@ static napi_status syscall_entry(napi_env env, napi_value* args, int arg_count,
107
107
  return napi_ok;
108
108
  }
109
109
 
110
- #define DEF_SYS_CONSTANT(env, obj, name) NAPILIB_CHECK(napilib_set_named_bigint_int64_property(env, obj, #name, name))
111
-
112
- static napi_status add_syscall_constants_to(napi_env env, napi_value target) {
113
- DEF_SYS_CONSTANT(env, target, __NR_io_setup);
114
- DEF_SYS_CONSTANT(env, target, __NR_io_destroy);
115
- DEF_SYS_CONSTANT(env, target, __NR_io_submit);
116
- DEF_SYS_CONSTANT(env, target, __NR_io_cancel);
117
- DEF_SYS_CONSTANT(env, target, __NR_io_getevents);
118
- DEF_SYS_CONSTANT(env, target, __NR_setxattr);
119
- DEF_SYS_CONSTANT(env, target, __NR_lsetxattr);
120
- DEF_SYS_CONSTANT(env, target, __NR_fsetxattr);
121
- DEF_SYS_CONSTANT(env, target, __NR_getxattr);
122
- DEF_SYS_CONSTANT(env, target, __NR_lgetxattr);
123
- DEF_SYS_CONSTANT(env, target, __NR_fgetxattr);
124
- DEF_SYS_CONSTANT(env, target, __NR_listxattr);
125
- DEF_SYS_CONSTANT(env, target, __NR_llistxattr);
126
- DEF_SYS_CONSTANT(env, target, __NR_flistxattr);
127
- DEF_SYS_CONSTANT(env, target, __NR_removexattr);
128
- DEF_SYS_CONSTANT(env, target, __NR_lremovexattr);
129
- DEF_SYS_CONSTANT(env, target, __NR_fremovexattr);
130
- DEF_SYS_CONSTANT(env, target, __NR_getcwd);
131
- DEF_SYS_CONSTANT(env, target, __NR_lookup_dcookie);
132
- DEF_SYS_CONSTANT(env, target, __NR_eventfd2);
133
- DEF_SYS_CONSTANT(env, target, __NR_epoll_create1);
134
- DEF_SYS_CONSTANT(env, target, __NR_epoll_ctl);
135
- DEF_SYS_CONSTANT(env, target, __NR_epoll_pwait);
136
- DEF_SYS_CONSTANT(env, target, __NR_dup);
137
- DEF_SYS_CONSTANT(env, target, __NR_dup3);
138
- DEF_SYS_CONSTANT(env, target, __NR_inotify_init1);
139
- DEF_SYS_CONSTANT(env, target, __NR_inotify_add_watch);
140
- DEF_SYS_CONSTANT(env, target, __NR_inotify_rm_watch);
141
- DEF_SYS_CONSTANT(env, target, __NR_ioctl);
142
- DEF_SYS_CONSTANT(env, target, __NR_ioprio_set);
143
- DEF_SYS_CONSTANT(env, target, __NR_ioprio_get);
144
- DEF_SYS_CONSTANT(env, target, __NR_flock);
145
- DEF_SYS_CONSTANT(env, target, __NR_mknodat);
146
- DEF_SYS_CONSTANT(env, target, __NR_mkdirat);
147
- DEF_SYS_CONSTANT(env, target, __NR_unlinkat);
148
- DEF_SYS_CONSTANT(env, target, __NR_symlinkat);
149
- DEF_SYS_CONSTANT(env, target, __NR_linkat);
150
- DEF_SYS_CONSTANT(env, target, __NR_renameat);
151
- DEF_SYS_CONSTANT(env, target, __NR_umount2);
152
- DEF_SYS_CONSTANT(env, target, __NR_mount);
153
- DEF_SYS_CONSTANT(env, target, __NR_pivot_root);
154
- DEF_SYS_CONSTANT(env, target, __NR_nfsservctl);
155
- DEF_SYS_CONSTANT(env, target, __NR_fallocate);
156
- DEF_SYS_CONSTANT(env, target, __NR_faccessat);
157
- DEF_SYS_CONSTANT(env, target, __NR_chdir);
158
- DEF_SYS_CONSTANT(env, target, __NR_fchdir);
159
- DEF_SYS_CONSTANT(env, target, __NR_chroot);
160
- DEF_SYS_CONSTANT(env, target, __NR_fchmod);
161
- DEF_SYS_CONSTANT(env, target, __NR_fchmodat);
162
- DEF_SYS_CONSTANT(env, target, __NR_fchownat);
163
- DEF_SYS_CONSTANT(env, target, __NR_fchown);
164
- DEF_SYS_CONSTANT(env, target, __NR_openat);
165
- DEF_SYS_CONSTANT(env, target, __NR_close);
166
- DEF_SYS_CONSTANT(env, target, __NR_vhangup);
167
- DEF_SYS_CONSTANT(env, target, __NR_pipe2);
168
- DEF_SYS_CONSTANT(env, target, __NR_quotactl);
169
- DEF_SYS_CONSTANT(env, target, __NR_getdents64);
170
- DEF_SYS_CONSTANT(env, target, __NR_read);
171
- DEF_SYS_CONSTANT(env, target, __NR_write);
172
- DEF_SYS_CONSTANT(env, target, __NR_readv);
173
- DEF_SYS_CONSTANT(env, target, __NR_writev);
174
- DEF_SYS_CONSTANT(env, target, __NR_pread64);
175
- DEF_SYS_CONSTANT(env, target, __NR_pwrite64);
176
- DEF_SYS_CONSTANT(env, target, __NR_preadv);
177
- DEF_SYS_CONSTANT(env, target, __NR_pwritev);
178
- DEF_SYS_CONSTANT(env, target, __NR_pselect6);
179
- DEF_SYS_CONSTANT(env, target, __NR_ppoll);
180
- DEF_SYS_CONSTANT(env, target, __NR_signalfd4);
181
- DEF_SYS_CONSTANT(env, target, __NR_vmsplice);
182
- DEF_SYS_CONSTANT(env, target, __NR_splice);
183
- DEF_SYS_CONSTANT(env, target, __NR_tee);
184
- DEF_SYS_CONSTANT(env, target, __NR_readlinkat);
185
- DEF_SYS_CONSTANT(env, target, __NR_sync);
186
- DEF_SYS_CONSTANT(env, target, __NR_fsync);
187
- DEF_SYS_CONSTANT(env, target, __NR_fdatasync);
188
- // DEF_SYS_CONSTANT(env, target, __NR_sync_file_range);
189
- DEF_SYS_CONSTANT(env, target, __NR_timerfd_create);
190
- DEF_SYS_CONSTANT(env, target, __NR_timerfd_settime);
191
- DEF_SYS_CONSTANT(env, target, __NR_timerfd_gettime);
192
- DEF_SYS_CONSTANT(env, target, __NR_utimensat);
193
- DEF_SYS_CONSTANT(env, target, __NR_acct);
194
- DEF_SYS_CONSTANT(env, target, __NR_capget);
195
- DEF_SYS_CONSTANT(env, target, __NR_capset);
196
- DEF_SYS_CONSTANT(env, target, __NR_personality);
197
- DEF_SYS_CONSTANT(env, target, __NR_exit);
198
- DEF_SYS_CONSTANT(env, target, __NR_exit_group);
199
- DEF_SYS_CONSTANT(env, target, __NR_waitid);
200
- DEF_SYS_CONSTANT(env, target, __NR_set_tid_address);
201
- DEF_SYS_CONSTANT(env, target, __NR_unshare);
202
- DEF_SYS_CONSTANT(env, target, __NR_futex);
203
- DEF_SYS_CONSTANT(env, target, __NR_set_robust_list);
204
- DEF_SYS_CONSTANT(env, target, __NR_get_robust_list);
205
- DEF_SYS_CONSTANT(env, target, __NR_nanosleep);
206
- DEF_SYS_CONSTANT(env, target, __NR_getitimer);
207
- DEF_SYS_CONSTANT(env, target, __NR_setitimer);
208
- DEF_SYS_CONSTANT(env, target, __NR_kexec_load);
209
- DEF_SYS_CONSTANT(env, target, __NR_init_module);
210
- DEF_SYS_CONSTANT(env, target, __NR_delete_module);
211
- DEF_SYS_CONSTANT(env, target, __NR_timer_create);
212
- DEF_SYS_CONSTANT(env, target, __NR_timer_gettime);
213
- DEF_SYS_CONSTANT(env, target, __NR_timer_getoverrun);
214
- DEF_SYS_CONSTANT(env, target, __NR_timer_settime);
215
- DEF_SYS_CONSTANT(env, target, __NR_timer_delete);
216
- DEF_SYS_CONSTANT(env, target, __NR_clock_settime);
217
- DEF_SYS_CONSTANT(env, target, __NR_clock_gettime);
218
- DEF_SYS_CONSTANT(env, target, __NR_clock_getres);
219
- DEF_SYS_CONSTANT(env, target, __NR_clock_nanosleep);
220
- DEF_SYS_CONSTANT(env, target, __NR_syslog);
221
- DEF_SYS_CONSTANT(env, target, __NR_ptrace);
222
- DEF_SYS_CONSTANT(env, target, __NR_sched_setparam);
223
- DEF_SYS_CONSTANT(env, target, __NR_sched_setscheduler);
224
- DEF_SYS_CONSTANT(env, target, __NR_sched_getscheduler);
225
- DEF_SYS_CONSTANT(env, target, __NR_sched_getparam);
226
- DEF_SYS_CONSTANT(env, target, __NR_sched_setaffinity);
227
- DEF_SYS_CONSTANT(env, target, __NR_sched_getaffinity);
228
- DEF_SYS_CONSTANT(env, target, __NR_sched_yield);
229
- DEF_SYS_CONSTANT(env, target, __NR_sched_get_priority_max);
230
- DEF_SYS_CONSTANT(env, target, __NR_sched_get_priority_min);
231
- DEF_SYS_CONSTANT(env, target, __NR_sched_rr_get_interval);
232
- DEF_SYS_CONSTANT(env, target, __NR_restart_syscall);
233
- DEF_SYS_CONSTANT(env, target, __NR_kill);
234
- DEF_SYS_CONSTANT(env, target, __NR_tkill);
235
- DEF_SYS_CONSTANT(env, target, __NR_tgkill);
236
- DEF_SYS_CONSTANT(env, target, __NR_sigaltstack);
237
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigsuspend);
238
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigaction);
239
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigprocmask);
240
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigpending);
241
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigtimedwait);
242
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigqueueinfo);
243
- DEF_SYS_CONSTANT(env, target, __NR_rt_sigreturn);
244
- DEF_SYS_CONSTANT(env, target, __NR_setpriority);
245
- DEF_SYS_CONSTANT(env, target, __NR_getpriority);
246
- DEF_SYS_CONSTANT(env, target, __NR_reboot);
247
- DEF_SYS_CONSTANT(env, target, __NR_setregid);
248
- DEF_SYS_CONSTANT(env, target, __NR_setgid);
249
- DEF_SYS_CONSTANT(env, target, __NR_setreuid);
250
- DEF_SYS_CONSTANT(env, target, __NR_setuid);
251
- DEF_SYS_CONSTANT(env, target, __NR_setresuid);
252
- DEF_SYS_CONSTANT(env, target, __NR_getresuid);
253
- DEF_SYS_CONSTANT(env, target, __NR_setresgid);
254
- DEF_SYS_CONSTANT(env, target, __NR_getresgid);
255
- DEF_SYS_CONSTANT(env, target, __NR_setfsuid);
256
- DEF_SYS_CONSTANT(env, target, __NR_setfsgid);
257
- DEF_SYS_CONSTANT(env, target, __NR_times);
258
- DEF_SYS_CONSTANT(env, target, __NR_setpgid);
259
- DEF_SYS_CONSTANT(env, target, __NR_getpgid);
260
- DEF_SYS_CONSTANT(env, target, __NR_getsid);
261
- DEF_SYS_CONSTANT(env, target, __NR_setsid);
262
- DEF_SYS_CONSTANT(env, target, __NR_getgroups);
263
- DEF_SYS_CONSTANT(env, target, __NR_setgroups);
264
- DEF_SYS_CONSTANT(env, target, __NR_uname);
265
- DEF_SYS_CONSTANT(env, target, __NR_sethostname);
266
- DEF_SYS_CONSTANT(env, target, __NR_setdomainname);
267
- // DEF_SYS_CONSTANT(env, target, __NR_getrlimit);
268
- DEF_SYS_CONSTANT(env, target, __NR_setrlimit);
269
- DEF_SYS_CONSTANT(env, target, __NR_getrusage);
270
- DEF_SYS_CONSTANT(env, target, __NR_umask);
271
- DEF_SYS_CONSTANT(env, target, __NR_prctl);
272
- DEF_SYS_CONSTANT(env, target, __NR_getcpu);
273
- DEF_SYS_CONSTANT(env, target, __NR_gettimeofday);
274
- DEF_SYS_CONSTANT(env, target, __NR_settimeofday);
275
- DEF_SYS_CONSTANT(env, target, __NR_adjtimex);
276
- DEF_SYS_CONSTANT(env, target, __NR_getpid);
277
- DEF_SYS_CONSTANT(env, target, __NR_getppid);
278
- DEF_SYS_CONSTANT(env, target, __NR_getuid);
279
- DEF_SYS_CONSTANT(env, target, __NR_geteuid);
280
- DEF_SYS_CONSTANT(env, target, __NR_getgid);
281
- DEF_SYS_CONSTANT(env, target, __NR_getegid);
282
- DEF_SYS_CONSTANT(env, target, __NR_gettid);
283
- DEF_SYS_CONSTANT(env, target, __NR_sysinfo);
284
- DEF_SYS_CONSTANT(env, target, __NR_mq_open);
285
- DEF_SYS_CONSTANT(env, target, __NR_mq_unlink);
286
- DEF_SYS_CONSTANT(env, target, __NR_mq_timedsend);
287
- DEF_SYS_CONSTANT(env, target, __NR_mq_timedreceive);
288
- DEF_SYS_CONSTANT(env, target, __NR_mq_notify);
289
- DEF_SYS_CONSTANT(env, target, __NR_mq_getsetattr);
290
- DEF_SYS_CONSTANT(env, target, __NR_msgget);
291
- DEF_SYS_CONSTANT(env, target, __NR_msgctl);
292
- DEF_SYS_CONSTANT(env, target, __NR_msgrcv);
293
- DEF_SYS_CONSTANT(env, target, __NR_msgsnd);
294
- DEF_SYS_CONSTANT(env, target, __NR_semget);
295
- DEF_SYS_CONSTANT(env, target, __NR_semctl);
296
- DEF_SYS_CONSTANT(env, target, __NR_semtimedop);
297
- DEF_SYS_CONSTANT(env, target, __NR_semop);
298
- DEF_SYS_CONSTANT(env, target, __NR_shmget);
299
- DEF_SYS_CONSTANT(env, target, __NR_shmctl);
300
- DEF_SYS_CONSTANT(env, target, __NR_shmat);
301
- DEF_SYS_CONSTANT(env, target, __NR_shmdt);
302
- DEF_SYS_CONSTANT(env, target, __NR_socket);
303
- DEF_SYS_CONSTANT(env, target, __NR_socketpair);
304
- DEF_SYS_CONSTANT(env, target, __NR_bind);
305
- DEF_SYS_CONSTANT(env, target, __NR_listen);
306
- DEF_SYS_CONSTANT(env, target, __NR_accept);
307
- DEF_SYS_CONSTANT(env, target, __NR_connect);
308
- DEF_SYS_CONSTANT(env, target, __NR_getsockname);
309
- DEF_SYS_CONSTANT(env, target, __NR_getpeername);
310
- DEF_SYS_CONSTANT(env, target, __NR_sendto);
311
- DEF_SYS_CONSTANT(env, target, __NR_recvfrom);
312
- DEF_SYS_CONSTANT(env, target, __NR_setsockopt);
313
- DEF_SYS_CONSTANT(env, target, __NR_getsockopt);
314
- DEF_SYS_CONSTANT(env, target, __NR_shutdown);
315
- DEF_SYS_CONSTANT(env, target, __NR_sendmsg);
316
- DEF_SYS_CONSTANT(env, target, __NR_recvmsg);
317
- DEF_SYS_CONSTANT(env, target, __NR_readahead);
318
- DEF_SYS_CONSTANT(env, target, __NR_brk);
319
- DEF_SYS_CONSTANT(env, target, __NR_munmap);
320
- DEF_SYS_CONSTANT(env, target, __NR_mremap);
321
- DEF_SYS_CONSTANT(env, target, __NR_add_key);
322
- DEF_SYS_CONSTANT(env, target, __NR_request_key);
323
- DEF_SYS_CONSTANT(env, target, __NR_keyctl);
324
- DEF_SYS_CONSTANT(env, target, __NR_clone);
325
- DEF_SYS_CONSTANT(env, target, __NR_execve);
326
- DEF_SYS_CONSTANT(env, target, __NR_swapon);
327
- DEF_SYS_CONSTANT(env, target, __NR_swapoff);
328
- DEF_SYS_CONSTANT(env, target, __NR_mprotect);
329
- DEF_SYS_CONSTANT(env, target, __NR_msync);
330
- DEF_SYS_CONSTANT(env, target, __NR_mlock);
331
- DEF_SYS_CONSTANT(env, target, __NR_munlock);
332
- DEF_SYS_CONSTANT(env, target, __NR_mlockall);
333
- DEF_SYS_CONSTANT(env, target, __NR_munlockall);
334
- DEF_SYS_CONSTANT(env, target, __NR_mincore);
335
- DEF_SYS_CONSTANT(env, target, __NR_madvise);
336
- DEF_SYS_CONSTANT(env, target, __NR_remap_file_pages);
337
- DEF_SYS_CONSTANT(env, target, __NR_mbind);
338
- DEF_SYS_CONSTANT(env, target, __NR_get_mempolicy);
339
- DEF_SYS_CONSTANT(env, target, __NR_set_mempolicy);
340
- // DEF_SYS_CONSTANT(env, target, __NR_migrate_pages);
341
- DEF_SYS_CONSTANT(env, target, __NR_move_pages);
342
- DEF_SYS_CONSTANT(env, target, __NR_rt_tgsigqueueinfo);
343
- DEF_SYS_CONSTANT(env, target, __NR_perf_event_open);
344
- DEF_SYS_CONSTANT(env, target, __NR_accept4);
345
- DEF_SYS_CONSTANT(env, target, __NR_recvmmsg);
346
- DEF_SYS_CONSTANT(env, target, __NR_wait4);
347
- DEF_SYS_CONSTANT(env, target, __NR_prlimit64);
348
- DEF_SYS_CONSTANT(env, target, __NR_fanotify_init);
349
- DEF_SYS_CONSTANT(env, target, __NR_fanotify_mark);
350
- DEF_SYS_CONSTANT(env, target, __NR_name_to_handle_at);
351
- DEF_SYS_CONSTANT(env, target, __NR_open_by_handle_at);
352
- DEF_SYS_CONSTANT(env, target, __NR_clock_adjtime);
353
- DEF_SYS_CONSTANT(env, target, __NR_syncfs);
354
- DEF_SYS_CONSTANT(env, target, __NR_setns);
355
- DEF_SYS_CONSTANT(env, target, __NR_sendmmsg);
356
- DEF_SYS_CONSTANT(env, target, __NR_process_vm_readv);
357
- DEF_SYS_CONSTANT(env, target, __NR_process_vm_writev);
358
- DEF_SYS_CONSTANT(env, target, __NR_kcmp);
359
- DEF_SYS_CONSTANT(env, target, __NR_finit_module);
360
- DEF_SYS_CONSTANT(env, target, __NR_sched_setattr);
361
- DEF_SYS_CONSTANT(env, target, __NR_sched_getattr);
362
- DEF_SYS_CONSTANT(env, target, __NR_renameat2);
363
- DEF_SYS_CONSTANT(env, target, __NR_seccomp);
364
- DEF_SYS_CONSTANT(env, target, __NR_getrandom);
365
- DEF_SYS_CONSTANT(env, target, __NR_memfd_create);
366
- DEF_SYS_CONSTANT(env, target, __NR_bpf);
367
- DEF_SYS_CONSTANT(env, target, __NR_execveat);
368
- DEF_SYS_CONSTANT(env, target, __NR_userfaultfd);
369
- DEF_SYS_CONSTANT(env, target, __NR_membarrier);
370
- DEF_SYS_CONSTANT(env, target, __NR_mlock2);
371
- DEF_SYS_CONSTANT(env, target, __NR_copy_file_range);
372
- DEF_SYS_CONSTANT(env, target, __NR_preadv2);
373
- DEF_SYS_CONSTANT(env, target, __NR_pwritev2);
374
- DEF_SYS_CONSTANT(env, target, __NR_pkey_mprotect);
375
- DEF_SYS_CONSTANT(env, target, __NR_pkey_alloc);
376
- DEF_SYS_CONSTANT(env, target, __NR_pkey_free);
377
- DEF_SYS_CONSTANT(env, target, __NR_statx);
110
+ static napi_status syscall_sync_entry(napi_env env, napi_value* args, int arg_count, napi_value* result) {
111
+ int i;
112
+ struct syscall_ctx ctx;
113
+ memset(&ctx, 0, sizeof(ctx));
114
+
115
+ if(arg_count < 1) {
116
+ return napi_throw_error(env, NULL, "minimum required argument count for syscall() is 1");
117
+ }
118
+
119
+ if(arg_count > 8) {
120
+ return napi_throw_error(env, NULL, "maximum supported argument count for syscall() is 8");
121
+ }
122
+
123
+ NAPILIB_CHECK(napilib_require_bigint_int64(env, args[0], &ctx.num));
124
+
125
+ for(i = 1; i < arg_count; i += 1) {
126
+ int arg_idx = i - 1;
127
+ bool is_buffer = 0;
128
+
129
+ NAPILIB_CHECK(napi_is_buffer(env, args[i], &is_buffer));
130
+ if(is_buffer) {
131
+ void* data;
132
+ size_t length;
133
+
134
+ NAPILIB_CHECK(napi_get_buffer_info(env, args[i], &data, &length));
135
+ ctx.native_args[arg_idx] = (long) data;
136
+ } else {
137
+ NAPILIB_CHECK(napilib_require_bigint_int64(env, args[i], &ctx.native_args[arg_idx]));
138
+ }
139
+ }
140
+
141
+ ctx.res = syscall(ctx.num,
142
+ ctx.native_args[0],
143
+ ctx.native_args[1],
144
+ ctx.native_args[2],
145
+ ctx.native_args[3],
146
+ ctx.native_args[4],
147
+ ctx.native_args[5],
148
+ ctx.native_args[6]);
149
+
150
+ if(ctx.res < 0) {
151
+ napi_value error;
152
+ NAPILIB_CHECK(napilib_create_error_by_errno(env, errno, &error));
153
+ NAPILIB_CHECK(napi_throw(env, error));
154
+ } else {
155
+ NAPILIB_CHECK(napi_create_bigint_int64(env, ctx.res, result));
156
+ }
378
157
 
379
158
  return napi_ok;
380
159
  }
@@ -384,8 +163,8 @@ static napi_status create_module_instance(napi_env env, napi_value* res) {
384
163
 
385
164
  NAPILIB_CHECK(napi_create_object(env, &exports));
386
165
 
387
- NAPILIB_CHECK(add_syscall_constants_to(env, exports));
388
- NAPILIB_CHECK(napilib_set_named_simple_function_property(env, exports, "syscall", syscall_entry));
166
+ NAPILIB_CHECK(napilib_set_named_simple_function_property(env, exports, "syscall_async", syscall_async_entry));
167
+ NAPILIB_CHECK(napilib_set_named_simple_function_property(env, exports, "syscall_sync", syscall_sync_entry));
389
168
 
390
169
  *res = exports;
391
170
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "syscall-napi",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.6",
5
5
  "description": "Node.js module to perform promise-based asynchronous syscalls",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -20,11 +20,9 @@
20
20
  },
21
21
  "homepage": "https://github.com/k13-engineering/node-syscall-napi#readme",
22
22
  "devDependencies": {
23
- "@babel/core": "^7.12.3",
24
- "@babel/eslint-parser": "^7.12.1",
25
- "c8": "^7.3.0",
26
- "eslint": "^7.9.0",
27
- "mocha": "^8.1.3",
23
+ "c8": "^7.9.0",
24
+ "eslint": "^7.32.0",
25
+ "mocha": "^9.1.1",
28
26
  "node-archibald": "^0.0.5"
29
27
  }
30
28
  }