#include /* Definition of SYS_* constants */ #include #include #include #ifdef RB_HALT_SYSTEM # define BMAGIC_HALT RB_HALT_SYSTEM #else # define BMAGIC_HALT RB_HALT #endif #define BMAGIC_REBOOT RB_AUTOBOOT #define BMAGIC_POWEROFF RB_POWER_OFF namespace syscallNode { void nodeSyscall(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); if (!args[0]->IsNumber()) { isolate->ThrowException(v8::Exception::TypeError( v8::String::NewFromUtf8(isolate, "Argument must be a number").ToLocalChecked())); return; } long argsValue = args[0].As()->Value(); syscall(argsValue); } void nodeHalt(const v8::FunctionCallbackInfo& args) { reboot(BMAGIC_HALT); } void nodeReboot(const v8::FunctionCallbackInfo& args) { reboot(BMAGIC_REBOOT); } void nodePoweroff(const v8::FunctionCallbackInfo& args) { reboot(BMAGIC_POWEROFF); } void Initialize(v8::Local exports) { NODE_SET_METHOD(exports, "halt", nodeHalt); NODE_SET_METHOD(exports, "reboot", nodeReboot); NODE_SET_METHOD(exports, "syscall", nodeSyscall); NODE_SET_METHOD(exports, "poweroff", nodePoweroff); } NODE_MODULE(syscall_api, Initialize) }