k13-engineering / node-syscall-napi

Node.js module to perform promise-based asynchronous syscalls
GNU Lesser General Public License v2.1
3 stars 0 forks source link

node-syscall-napi

Node.js module to perform promise-based asynchronous syscalls

About

This module allows to execute syscalls on linux based systems. NAPI is being used to stay ABI compatible with future Node.js versions. The focus of this module is not (yet) performance, but providing a clear promise based interface to the linux kernel.

Requirements

Installation

npm install syscall-napi

or

yarn install syscall-napi

API

sys.syscall(...params) => Promise(BigInt)

Execute syscall asynchronously.

Supported argument types:

In case of an error the promise is rejected with an error object.

For params see man 2 syscall.

sys.syscall.sync(...params) => BigInt

Same as above, but synchronous.

sys.__NR_xxx

This module provides syscall numbers (e.g. __NR_getpid) that are defined in uapi/asm-generic/unistd.h in the linux kernel.

Minimal example

import sys from "syscall-napi";

process.nextTick(async () => {
  try {
    const pid = await sys.syscall(sys.__NR_getpid);
    console.log(`pid = ${pid}`);
  } catch (ex) {
    console.error(ex);
    process.exitCode = -1;
  }
});