40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#include <sys/syscall.h> /* Definition of SYS_* constants */
|
|
#include <sys/reboot.h>
|
|
#include <unistd.h>
|
|
#include <node.h>
|
|
|
|
namespace syscallNode {
|
|
void nodeSyscall(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Number>()->Value();
|
|
syscall(argsValue);
|
|
}
|
|
|
|
void nodeReboot(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::Number>()->Value();
|
|
reboot(argsValue);
|
|
}
|
|
|
|
|
|
void Initialize(v8::Local<v8::Object> exports) {
|
|
NODE_SET_METHOD(exports, "reboot", nodeReboot);
|
|
NODE_SET_METHOD(exports, "syscall", nodeSyscall);
|
|
}
|
|
|
|
NODE_MODULE(syscall_api, Initialize)
|
|
}
|