11cb0ef41Sopenharmony_ci#include "async_wrap-inl.h"
21cb0ef41Sopenharmony_ci#include "base_object-inl.h"
31cb0ef41Sopenharmony_ci#include "debug_utils-inl.h"
41cb0ef41Sopenharmony_ci#include "env-inl.h"
51cb0ef41Sopenharmony_ci#include "memory_tracker-inl.h"
61cb0ef41Sopenharmony_ci#include "node.h"
71cb0ef41Sopenharmony_ci#include "node_errors.h"
81cb0ef41Sopenharmony_ci#include "node_external_reference.h"
91cb0ef41Sopenharmony_ci#include "node_internals.h"
101cb0ef41Sopenharmony_ci#include "node_process-inl.h"
111cb0ef41Sopenharmony_ci#include "util-inl.h"
121cb0ef41Sopenharmony_ci#include "uv.h"
131cb0ef41Sopenharmony_ci#include "v8-fast-api-calls.h"
141cb0ef41Sopenharmony_ci#include "v8.h"
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci#include <vector>
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci#if HAVE_INSPECTOR
191cb0ef41Sopenharmony_ci#include "inspector_io.h"
201cb0ef41Sopenharmony_ci#endif
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci#include <climits>  // PATH_MAX
231cb0ef41Sopenharmony_ci#include <cstdio>
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci#if defined(_MSC_VER)
261cb0ef41Sopenharmony_ci#include <direct.h>
271cb0ef41Sopenharmony_ci#include <io.h>
281cb0ef41Sopenharmony_ci#define umask _umask
291cb0ef41Sopenharmony_citypedef int mode_t;
301cb0ef41Sopenharmony_ci#else
311cb0ef41Sopenharmony_ci#include <pthread.h>
321cb0ef41Sopenharmony_ci#include <sys/resource.h>  // getrlimit, setrlimit
331cb0ef41Sopenharmony_ci#include <termios.h>  // tcgetattr, tcsetattr
341cb0ef41Sopenharmony_ci#endif
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cinamespace node {
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ciusing v8::Array;
391cb0ef41Sopenharmony_ciusing v8::ArrayBuffer;
401cb0ef41Sopenharmony_ciusing v8::CFunction;
411cb0ef41Sopenharmony_ciusing v8::Context;
421cb0ef41Sopenharmony_ciusing v8::Float64Array;
431cb0ef41Sopenharmony_ciusing v8::FunctionCallbackInfo;
441cb0ef41Sopenharmony_ciusing v8::HeapStatistics;
451cb0ef41Sopenharmony_ciusing v8::Integer;
461cb0ef41Sopenharmony_ciusing v8::Isolate;
471cb0ef41Sopenharmony_ciusing v8::Local;
481cb0ef41Sopenharmony_ciusing v8::NewStringType;
491cb0ef41Sopenharmony_ciusing v8::Number;
501cb0ef41Sopenharmony_ciusing v8::Object;
511cb0ef41Sopenharmony_ciusing v8::String;
521cb0ef41Sopenharmony_ciusing v8::Uint32;
531cb0ef41Sopenharmony_ciusing v8::Value;
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cinamespace per_process {
561cb0ef41Sopenharmony_ciMutex umask_mutex;
571cb0ef41Sopenharmony_ci}   // namespace per_process
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci// Microseconds in a second, as a float, used in CPUUsage() below
601cb0ef41Sopenharmony_ci#define MICROS_PER_SEC 1e6
611cb0ef41Sopenharmony_ci// used in Hrtime() and Uptime() below
621cb0ef41Sopenharmony_ci#define NANOS_PER_SEC 1000000000
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_cistatic void Abort(const FunctionCallbackInfo<Value>& args) {
651cb0ef41Sopenharmony_ci  Abort();
661cb0ef41Sopenharmony_ci}
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci// For internal testing only, not exposed to userland.
691cb0ef41Sopenharmony_cistatic void CauseSegfault(const FunctionCallbackInfo<Value>& args) {
701cb0ef41Sopenharmony_ci  // This should crash hard all platforms.
711cb0ef41Sopenharmony_ci  volatile void** d = static_cast<volatile void**>(nullptr);
721cb0ef41Sopenharmony_ci  *d = nullptr;
731cb0ef41Sopenharmony_ci}
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_cistatic void Chdir(const FunctionCallbackInfo<Value>& args) {
761cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
771cb0ef41Sopenharmony_ci  CHECK(env->owns_process_state());
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  CHECK_EQ(args.Length(), 1);
801cb0ef41Sopenharmony_ci  CHECK(args[0]->IsString());
811cb0ef41Sopenharmony_ci  Utf8Value path(env->isolate(), args[0]);
821cb0ef41Sopenharmony_ci  int err = uv_chdir(*path);
831cb0ef41Sopenharmony_ci  if (err) {
841cb0ef41Sopenharmony_ci    // Also include the original working directory, since that will usually
851cb0ef41Sopenharmony_ci    // be helpful information when debugging a `chdir()` failure.
861cb0ef41Sopenharmony_ci    char buf[PATH_MAX_BYTES];
871cb0ef41Sopenharmony_ci    size_t cwd_len = sizeof(buf);
881cb0ef41Sopenharmony_ci    uv_cwd(buf, &cwd_len);
891cb0ef41Sopenharmony_ci    return env->ThrowUVException(err, "chdir", nullptr, buf, *path);
901cb0ef41Sopenharmony_ci  }
911cb0ef41Sopenharmony_ci}
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ciinline Local<ArrayBuffer> get_fields_array_buffer(
941cb0ef41Sopenharmony_ci    const FunctionCallbackInfo<Value>& args,
951cb0ef41Sopenharmony_ci    size_t index,
961cb0ef41Sopenharmony_ci    size_t array_length) {
971cb0ef41Sopenharmony_ci  CHECK(args[index]->IsFloat64Array());
981cb0ef41Sopenharmony_ci  Local<Float64Array> arr = args[index].As<Float64Array>();
991cb0ef41Sopenharmony_ci  CHECK_EQ(arr->Length(), array_length);
1001cb0ef41Sopenharmony_ci  return arr->Buffer();
1011cb0ef41Sopenharmony_ci}
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci// CPUUsage use libuv's uv_getrusage() this-process resource usage accessor,
1041cb0ef41Sopenharmony_ci// to access ru_utime (user CPU time used) and ru_stime (system CPU time used),
1051cb0ef41Sopenharmony_ci// which are uv_timeval_t structs (long tv_sec, long tv_usec).
1061cb0ef41Sopenharmony_ci// Returns those values as Float64 microseconds in the elements of the array
1071cb0ef41Sopenharmony_ci// passed to the function.
1081cb0ef41Sopenharmony_cistatic void CPUUsage(const FunctionCallbackInfo<Value>& args) {
1091cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
1101cb0ef41Sopenharmony_ci  uv_rusage_t rusage;
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci  // Call libuv to get the values we'll return.
1131cb0ef41Sopenharmony_ci  int err = uv_getrusage(&rusage);
1141cb0ef41Sopenharmony_ci  if (err)
1151cb0ef41Sopenharmony_ci    return env->ThrowUVException(err, "uv_getrusage");
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci  // Get the double array pointer from the Float64Array argument.
1181cb0ef41Sopenharmony_ci  Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 2);
1191cb0ef41Sopenharmony_ci  double* fields = static_cast<double*>(ab->Data());
1201cb0ef41Sopenharmony_ci
1211cb0ef41Sopenharmony_ci  // Set the Float64Array elements to be user / system values in microseconds.
1221cb0ef41Sopenharmony_ci  fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;
1231cb0ef41Sopenharmony_ci  fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec;
1241cb0ef41Sopenharmony_ci}
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_cistatic void Cwd(const FunctionCallbackInfo<Value>& args) {
1271cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
1281cb0ef41Sopenharmony_ci  CHECK(env->has_run_bootstrapping_code());
1291cb0ef41Sopenharmony_ci  char buf[PATH_MAX_BYTES];
1301cb0ef41Sopenharmony_ci  size_t cwd_len = sizeof(buf);
1311cb0ef41Sopenharmony_ci  int err = uv_cwd(buf, &cwd_len);
1321cb0ef41Sopenharmony_ci  if (err)
1331cb0ef41Sopenharmony_ci    return env->ThrowUVException(err, "uv_cwd");
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_ci  Local<String> cwd = String::NewFromUtf8(env->isolate(),
1361cb0ef41Sopenharmony_ci                                          buf,
1371cb0ef41Sopenharmony_ci                                          NewStringType::kNormal,
1381cb0ef41Sopenharmony_ci                                          cwd_len).ToLocalChecked();
1391cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(cwd);
1401cb0ef41Sopenharmony_ci}
1411cb0ef41Sopenharmony_ci
1421cb0ef41Sopenharmony_cistatic void Kill(const FunctionCallbackInfo<Value>& args) {
1431cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
1441cb0ef41Sopenharmony_ci  Local<Context> context = env->context();
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci  if (args.Length() < 2) {
1471cb0ef41Sopenharmony_ci    THROW_ERR_MISSING_ARGS(env, "Bad argument.");
1481cb0ef41Sopenharmony_ci  }
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_ci  int pid;
1511cb0ef41Sopenharmony_ci  if (!args[0]->Int32Value(context).To(&pid)) return;
1521cb0ef41Sopenharmony_ci  int sig;
1531cb0ef41Sopenharmony_ci  if (!args[1]->Int32Value(context).To(&sig)) return;
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  uv_pid_t own_pid = uv_os_getpid();
1561cb0ef41Sopenharmony_ci  if (sig > 0 &&
1571cb0ef41Sopenharmony_ci      (pid == 0 || pid == -1 || pid == own_pid || pid == -own_pid) &&
1581cb0ef41Sopenharmony_ci      !HasSignalJSHandler(sig)) {
1591cb0ef41Sopenharmony_ci    // This is most likely going to terminate this process.
1601cb0ef41Sopenharmony_ci    // It's not an exact method but it might be close enough.
1611cb0ef41Sopenharmony_ci    RunAtExit(env);
1621cb0ef41Sopenharmony_ci  }
1631cb0ef41Sopenharmony_ci
1641cb0ef41Sopenharmony_ci  int err = uv_kill(pid, sig);
1651cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(err);
1661cb0ef41Sopenharmony_ci}
1671cb0ef41Sopenharmony_ci
1681cb0ef41Sopenharmony_cistatic void Rss(const FunctionCallbackInfo<Value>& args) {
1691cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
1701cb0ef41Sopenharmony_ci
1711cb0ef41Sopenharmony_ci  size_t rss;
1721cb0ef41Sopenharmony_ci  int err = uv_resident_set_memory(&rss);
1731cb0ef41Sopenharmony_ci  if (err)
1741cb0ef41Sopenharmony_ci    return env->ThrowUVException(err, "uv_resident_set_memory");
1751cb0ef41Sopenharmony_ci
1761cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(static_cast<double>(rss));
1771cb0ef41Sopenharmony_ci}
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_cistatic void MemoryUsage(const FunctionCallbackInfo<Value>& args) {
1801cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
1811cb0ef41Sopenharmony_ci
1821cb0ef41Sopenharmony_ci  Isolate* isolate = env->isolate();
1831cb0ef41Sopenharmony_ci  // V8 memory usage
1841cb0ef41Sopenharmony_ci  HeapStatistics v8_heap_stats;
1851cb0ef41Sopenharmony_ci  isolate->GetHeapStatistics(&v8_heap_stats);
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci  NodeArrayBufferAllocator* array_buffer_allocator =
1881cb0ef41Sopenharmony_ci      env->isolate_data()->node_allocator();
1891cb0ef41Sopenharmony_ci
1901cb0ef41Sopenharmony_ci  // Get the double array pointer from the Float64Array argument.
1911cb0ef41Sopenharmony_ci  Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 5);
1921cb0ef41Sopenharmony_ci  double* fields = static_cast<double*>(ab->Data());
1931cb0ef41Sopenharmony_ci
1941cb0ef41Sopenharmony_ci  size_t rss;
1951cb0ef41Sopenharmony_ci  int err = uv_resident_set_memory(&rss);
1961cb0ef41Sopenharmony_ci  if (err)
1971cb0ef41Sopenharmony_ci    return env->ThrowUVException(err, "uv_resident_set_memory");
1981cb0ef41Sopenharmony_ci
1991cb0ef41Sopenharmony_ci  fields[0] = static_cast<double>(rss);
2001cb0ef41Sopenharmony_ci  fields[1] = static_cast<double>(v8_heap_stats.total_heap_size());
2011cb0ef41Sopenharmony_ci  fields[2] = static_cast<double>(v8_heap_stats.used_heap_size());
2021cb0ef41Sopenharmony_ci  fields[3] = static_cast<double>(v8_heap_stats.external_memory());
2031cb0ef41Sopenharmony_ci  fields[4] =
2041cb0ef41Sopenharmony_ci      array_buffer_allocator == nullptr
2051cb0ef41Sopenharmony_ci          ? 0
2061cb0ef41Sopenharmony_ci          : static_cast<double>(array_buffer_allocator->total_mem_usage());
2071cb0ef41Sopenharmony_ci}
2081cb0ef41Sopenharmony_ci
2091cb0ef41Sopenharmony_cistatic void GetConstrainedMemory(const FunctionCallbackInfo<Value>& args) {
2101cb0ef41Sopenharmony_ci  uint64_t value = uv_get_constrained_memory();
2111cb0ef41Sopenharmony_ci  if (value != 0) {
2121cb0ef41Sopenharmony_ci    args.GetReturnValue().Set(static_cast<double>(value));
2131cb0ef41Sopenharmony_ci  }
2141cb0ef41Sopenharmony_ci}
2151cb0ef41Sopenharmony_ci
2161cb0ef41Sopenharmony_civoid RawDebug(const FunctionCallbackInfo<Value>& args) {
2171cb0ef41Sopenharmony_ci  CHECK(args.Length() == 1 && args[0]->IsString() &&
2181cb0ef41Sopenharmony_ci        "must be called with a single string");
2191cb0ef41Sopenharmony_ci  Utf8Value message(args.GetIsolate(), args[0]);
2201cb0ef41Sopenharmony_ci  FPrintF(stderr, "%s\n", message);
2211cb0ef41Sopenharmony_ci  fflush(stderr);
2221cb0ef41Sopenharmony_ci}
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_cistatic void Umask(const FunctionCallbackInfo<Value>& args) {
2251cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
2261cb0ef41Sopenharmony_ci  CHECK(env->has_run_bootstrapping_code());
2271cb0ef41Sopenharmony_ci  CHECK_EQ(args.Length(), 1);
2281cb0ef41Sopenharmony_ci  CHECK(args[0]->IsUndefined() || args[0]->IsUint32());
2291cb0ef41Sopenharmony_ci  Mutex::ScopedLock scoped_lock(per_process::umask_mutex);
2301cb0ef41Sopenharmony_ci
2311cb0ef41Sopenharmony_ci  uint32_t old;
2321cb0ef41Sopenharmony_ci  if (args[0]->IsUndefined()) {
2331cb0ef41Sopenharmony_ci    old = umask(0);
2341cb0ef41Sopenharmony_ci    umask(static_cast<mode_t>(old));
2351cb0ef41Sopenharmony_ci  } else {
2361cb0ef41Sopenharmony_ci    int oct = args[0].As<Uint32>()->Value();
2371cb0ef41Sopenharmony_ci    old = umask(static_cast<mode_t>(oct));
2381cb0ef41Sopenharmony_ci  }
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(old);
2411cb0ef41Sopenharmony_ci}
2421cb0ef41Sopenharmony_ci
2431cb0ef41Sopenharmony_cistatic void Uptime(const FunctionCallbackInfo<Value>& args) {
2441cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
2451cb0ef41Sopenharmony_ci
2461cb0ef41Sopenharmony_ci  uv_update_time(env->event_loop());
2471cb0ef41Sopenharmony_ci  double uptime =
2481cb0ef41Sopenharmony_ci      static_cast<double>(uv_hrtime() - per_process::node_start_time);
2491cb0ef41Sopenharmony_ci  Local<Number> result = Number::New(env->isolate(), uptime / NANOS_PER_SEC);
2501cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(result);
2511cb0ef41Sopenharmony_ci}
2521cb0ef41Sopenharmony_ci
2531cb0ef41Sopenharmony_cistatic void GetActiveRequests(const FunctionCallbackInfo<Value>& args) {
2541cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
2551cb0ef41Sopenharmony_ci
2561cb0ef41Sopenharmony_ci  std::vector<Local<Value>> request_v;
2571cb0ef41Sopenharmony_ci  for (ReqWrapBase* req_wrap : *env->req_wrap_queue()) {
2581cb0ef41Sopenharmony_ci    AsyncWrap* w = req_wrap->GetAsyncWrap();
2591cb0ef41Sopenharmony_ci    if (w->persistent().IsEmpty())
2601cb0ef41Sopenharmony_ci      continue;
2611cb0ef41Sopenharmony_ci    request_v.emplace_back(w->GetOwner());
2621cb0ef41Sopenharmony_ci  }
2631cb0ef41Sopenharmony_ci
2641cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(
2651cb0ef41Sopenharmony_ci      Array::New(env->isolate(), request_v.data(), request_v.size()));
2661cb0ef41Sopenharmony_ci}
2671cb0ef41Sopenharmony_ci
2681cb0ef41Sopenharmony_ci// Non-static, friend of HandleWrap. Could have been a HandleWrap method but
2691cb0ef41Sopenharmony_ci// implemented here for consistency with GetActiveRequests().
2701cb0ef41Sopenharmony_civoid GetActiveHandles(const FunctionCallbackInfo<Value>& args) {
2711cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ci  std::vector<Local<Value>> handle_v;
2741cb0ef41Sopenharmony_ci  for (auto w : *env->handle_wrap_queue()) {
2751cb0ef41Sopenharmony_ci    if (!HandleWrap::HasRef(w))
2761cb0ef41Sopenharmony_ci      continue;
2771cb0ef41Sopenharmony_ci    handle_v.emplace_back(w->GetOwner());
2781cb0ef41Sopenharmony_ci  }
2791cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(
2801cb0ef41Sopenharmony_ci      Array::New(env->isolate(), handle_v.data(), handle_v.size()));
2811cb0ef41Sopenharmony_ci}
2821cb0ef41Sopenharmony_ci
2831cb0ef41Sopenharmony_cistatic void GetActiveResourcesInfo(const FunctionCallbackInfo<Value>& args) {
2841cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
2851cb0ef41Sopenharmony_ci  std::vector<Local<Value>> resources_info;
2861cb0ef41Sopenharmony_ci
2871cb0ef41Sopenharmony_ci  // Active requests
2881cb0ef41Sopenharmony_ci  for (ReqWrapBase* req_wrap : *env->req_wrap_queue()) {
2891cb0ef41Sopenharmony_ci    AsyncWrap* w = req_wrap->GetAsyncWrap();
2901cb0ef41Sopenharmony_ci    if (w->persistent().IsEmpty()) continue;
2911cb0ef41Sopenharmony_ci    resources_info.emplace_back(
2921cb0ef41Sopenharmony_ci        OneByteString(env->isolate(), w->MemoryInfoName()));
2931cb0ef41Sopenharmony_ci  }
2941cb0ef41Sopenharmony_ci
2951cb0ef41Sopenharmony_ci  // Active handles
2961cb0ef41Sopenharmony_ci  for (HandleWrap* w : *env->handle_wrap_queue()) {
2971cb0ef41Sopenharmony_ci    if (w->persistent().IsEmpty() || !HandleWrap::HasRef(w)) continue;
2981cb0ef41Sopenharmony_ci    resources_info.emplace_back(
2991cb0ef41Sopenharmony_ci        OneByteString(env->isolate(), w->MemoryInfoName()));
3001cb0ef41Sopenharmony_ci  }
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci  // Active timeouts
3031cb0ef41Sopenharmony_ci  resources_info.insert(resources_info.end(),
3041cb0ef41Sopenharmony_ci                        env->timeout_info()[0],
3051cb0ef41Sopenharmony_ci                        OneByteString(env->isolate(), "Timeout"));
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci  // Active immediates
3081cb0ef41Sopenharmony_ci  resources_info.insert(resources_info.end(),
3091cb0ef41Sopenharmony_ci                        env->immediate_info()->ref_count(),
3101cb0ef41Sopenharmony_ci                        OneByteString(env->isolate(), "Immediate"));
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci  args.GetReturnValue().Set(
3131cb0ef41Sopenharmony_ci      Array::New(env->isolate(), resources_info.data(), resources_info.size()));
3141cb0ef41Sopenharmony_ci}
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_cistatic void ResourceUsage(const FunctionCallbackInfo<Value>& args) {
3171cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
3181cb0ef41Sopenharmony_ci
3191cb0ef41Sopenharmony_ci  uv_rusage_t rusage;
3201cb0ef41Sopenharmony_ci  int err = uv_getrusage(&rusage);
3211cb0ef41Sopenharmony_ci  if (err)
3221cb0ef41Sopenharmony_ci    return env->ThrowUVException(err, "uv_getrusage");
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci  Local<ArrayBuffer> ab = get_fields_array_buffer(args, 0, 16);
3251cb0ef41Sopenharmony_ci  double* fields = static_cast<double*>(ab->Data());
3261cb0ef41Sopenharmony_ci
3271cb0ef41Sopenharmony_ci  fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;
3281cb0ef41Sopenharmony_ci  fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec;
3291cb0ef41Sopenharmony_ci  fields[2] = static_cast<double>(rusage.ru_maxrss);
3301cb0ef41Sopenharmony_ci  fields[3] = static_cast<double>(rusage.ru_ixrss);
3311cb0ef41Sopenharmony_ci  fields[4] = static_cast<double>(rusage.ru_idrss);
3321cb0ef41Sopenharmony_ci  fields[5] = static_cast<double>(rusage.ru_isrss);
3331cb0ef41Sopenharmony_ci  fields[6] = static_cast<double>(rusage.ru_minflt);
3341cb0ef41Sopenharmony_ci  fields[7] = static_cast<double>(rusage.ru_majflt);
3351cb0ef41Sopenharmony_ci  fields[8] = static_cast<double>(rusage.ru_nswap);
3361cb0ef41Sopenharmony_ci  fields[9] = static_cast<double>(rusage.ru_inblock);
3371cb0ef41Sopenharmony_ci  fields[10] = static_cast<double>(rusage.ru_oublock);
3381cb0ef41Sopenharmony_ci  fields[11] = static_cast<double>(rusage.ru_msgsnd);
3391cb0ef41Sopenharmony_ci  fields[12] = static_cast<double>(rusage.ru_msgrcv);
3401cb0ef41Sopenharmony_ci  fields[13] = static_cast<double>(rusage.ru_nsignals);
3411cb0ef41Sopenharmony_ci  fields[14] = static_cast<double>(rusage.ru_nvcsw);
3421cb0ef41Sopenharmony_ci  fields[15] = static_cast<double>(rusage.ru_nivcsw);
3431cb0ef41Sopenharmony_ci}
3441cb0ef41Sopenharmony_ci
3451cb0ef41Sopenharmony_ci#ifdef __POSIX__
3461cb0ef41Sopenharmony_cistatic void DebugProcess(const FunctionCallbackInfo<Value>& args) {
3471cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_ci  if (args.Length() < 1) {
3501cb0ef41Sopenharmony_ci    return THROW_ERR_MISSING_ARGS(env, "Invalid number of arguments.");
3511cb0ef41Sopenharmony_ci  }
3521cb0ef41Sopenharmony_ci
3531cb0ef41Sopenharmony_ci  CHECK(args[0]->IsNumber());
3541cb0ef41Sopenharmony_ci  pid_t pid = args[0].As<Integer>()->Value();
3551cb0ef41Sopenharmony_ci  int r = kill(pid, SIGUSR1);
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_ci  if (r != 0) {
3581cb0ef41Sopenharmony_ci    return env->ThrowErrnoException(errno, "kill");
3591cb0ef41Sopenharmony_ci  }
3601cb0ef41Sopenharmony_ci}
3611cb0ef41Sopenharmony_ci#endif  // __POSIX__
3621cb0ef41Sopenharmony_ci
3631cb0ef41Sopenharmony_ci#ifdef _WIN32
3641cb0ef41Sopenharmony_cistatic int GetDebugSignalHandlerMappingName(DWORD pid,
3651cb0ef41Sopenharmony_ci                                            wchar_t* buf,
3661cb0ef41Sopenharmony_ci                                            size_t buf_len) {
3671cb0ef41Sopenharmony_ci  return _snwprintf(buf, buf_len, L"node-debug-handler-%u", pid);
3681cb0ef41Sopenharmony_ci}
3691cb0ef41Sopenharmony_ci
3701cb0ef41Sopenharmony_cistatic void DebugProcess(const FunctionCallbackInfo<Value>& args) {
3711cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
3721cb0ef41Sopenharmony_ci  Isolate* isolate = args.GetIsolate();
3731cb0ef41Sopenharmony_ci
3741cb0ef41Sopenharmony_ci  if (args.Length() < 1) {
3751cb0ef41Sopenharmony_ci    return THROW_ERR_MISSING_ARGS(env, "Invalid number of arguments.");
3761cb0ef41Sopenharmony_ci  }
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci  HANDLE process = nullptr;
3791cb0ef41Sopenharmony_ci  HANDLE thread = nullptr;
3801cb0ef41Sopenharmony_ci  HANDLE mapping = nullptr;
3811cb0ef41Sopenharmony_ci  wchar_t mapping_name[32];
3821cb0ef41Sopenharmony_ci  LPTHREAD_START_ROUTINE* handler = nullptr;
3831cb0ef41Sopenharmony_ci  DWORD pid = 0;
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_ci  auto cleanup = OnScopeLeave([&]() {
3861cb0ef41Sopenharmony_ci    if (process != nullptr) CloseHandle(process);
3871cb0ef41Sopenharmony_ci    if (thread != nullptr) CloseHandle(thread);
3881cb0ef41Sopenharmony_ci    if (handler != nullptr) UnmapViewOfFile(handler);
3891cb0ef41Sopenharmony_ci    if (mapping != nullptr) CloseHandle(mapping);
3901cb0ef41Sopenharmony_ci  });
3911cb0ef41Sopenharmony_ci
3921cb0ef41Sopenharmony_ci  CHECK(args[0]->IsNumber());
3931cb0ef41Sopenharmony_ci  pid = static_cast<DWORD>(args[0].As<Integer>()->Value());
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ci  process =
3961cb0ef41Sopenharmony_ci      OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION |
3971cb0ef41Sopenharmony_ci                      PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
3981cb0ef41Sopenharmony_ci                  FALSE,
3991cb0ef41Sopenharmony_ci                  pid);
4001cb0ef41Sopenharmony_ci  if (process == nullptr) {
4011cb0ef41Sopenharmony_ci    isolate->ThrowException(
4021cb0ef41Sopenharmony_ci        WinapiErrnoException(isolate, GetLastError(), "OpenProcess"));
4031cb0ef41Sopenharmony_ci    return;
4041cb0ef41Sopenharmony_ci  }
4051cb0ef41Sopenharmony_ci
4061cb0ef41Sopenharmony_ci  if (GetDebugSignalHandlerMappingName(
4071cb0ef41Sopenharmony_ci          pid, mapping_name, arraysize(mapping_name)) < 0) {
4081cb0ef41Sopenharmony_ci    env->ThrowErrnoException(errno, "sprintf");
4091cb0ef41Sopenharmony_ci    return;
4101cb0ef41Sopenharmony_ci  }
4111cb0ef41Sopenharmony_ci
4121cb0ef41Sopenharmony_ci  mapping = OpenFileMappingW(FILE_MAP_READ, FALSE, mapping_name);
4131cb0ef41Sopenharmony_ci  if (mapping == nullptr) {
4141cb0ef41Sopenharmony_ci    isolate->ThrowException(
4151cb0ef41Sopenharmony_ci        WinapiErrnoException(isolate, GetLastError(), "OpenFileMappingW"));
4161cb0ef41Sopenharmony_ci    return;
4171cb0ef41Sopenharmony_ci  }
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ci  handler = reinterpret_cast<LPTHREAD_START_ROUTINE*>(
4201cb0ef41Sopenharmony_ci      MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, sizeof *handler));
4211cb0ef41Sopenharmony_ci  if (handler == nullptr || *handler == nullptr) {
4221cb0ef41Sopenharmony_ci    isolate->ThrowException(
4231cb0ef41Sopenharmony_ci        WinapiErrnoException(isolate, GetLastError(), "MapViewOfFile"));
4241cb0ef41Sopenharmony_ci    return;
4251cb0ef41Sopenharmony_ci  }
4261cb0ef41Sopenharmony_ci
4271cb0ef41Sopenharmony_ci  thread =
4281cb0ef41Sopenharmony_ci      CreateRemoteThread(process, nullptr, 0, *handler, nullptr, 0, nullptr);
4291cb0ef41Sopenharmony_ci  if (thread == nullptr) {
4301cb0ef41Sopenharmony_ci    isolate->ThrowException(
4311cb0ef41Sopenharmony_ci        WinapiErrnoException(isolate, GetLastError(), "CreateRemoteThread"));
4321cb0ef41Sopenharmony_ci    return;
4331cb0ef41Sopenharmony_ci  }
4341cb0ef41Sopenharmony_ci
4351cb0ef41Sopenharmony_ci  // Wait for the thread to terminate
4361cb0ef41Sopenharmony_ci  if (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0) {
4371cb0ef41Sopenharmony_ci    isolate->ThrowException(
4381cb0ef41Sopenharmony_ci        WinapiErrnoException(isolate, GetLastError(), "WaitForSingleObject"));
4391cb0ef41Sopenharmony_ci    return;
4401cb0ef41Sopenharmony_ci  }
4411cb0ef41Sopenharmony_ci}
4421cb0ef41Sopenharmony_ci#endif  // _WIN32
4431cb0ef41Sopenharmony_ci
4441cb0ef41Sopenharmony_cistatic void DebugEnd(const FunctionCallbackInfo<Value>& args) {
4451cb0ef41Sopenharmony_ci#if HAVE_INSPECTOR
4461cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
4471cb0ef41Sopenharmony_ci  if (env->inspector_agent()->IsListening()) {
4481cb0ef41Sopenharmony_ci    env->inspector_agent()->Stop();
4491cb0ef41Sopenharmony_ci  }
4501cb0ef41Sopenharmony_ci#endif
4511cb0ef41Sopenharmony_ci}
4521cb0ef41Sopenharmony_ci
4531cb0ef41Sopenharmony_cistatic void ReallyExit(const FunctionCallbackInfo<Value>& args) {
4541cb0ef41Sopenharmony_ci  Environment* env = Environment::GetCurrent(args);
4551cb0ef41Sopenharmony_ci  RunAtExit(env);
4561cb0ef41Sopenharmony_ci  int code = args[0]->Int32Value(env->context()).FromMaybe(0);
4571cb0ef41Sopenharmony_ci  env->Exit(code);
4581cb0ef41Sopenharmony_ci}
4591cb0ef41Sopenharmony_ci
4601cb0ef41Sopenharmony_cinamespace process {
4611cb0ef41Sopenharmony_ci
4621cb0ef41Sopenharmony_ciBindingData::BindingData(Realm* realm, v8::Local<v8::Object> object)
4631cb0ef41Sopenharmony_ci    : SnapshotableObject(realm, object, type_int) {
4641cb0ef41Sopenharmony_ci  Isolate* isolate = realm->isolate();
4651cb0ef41Sopenharmony_ci  Local<Context> context = realm->context();
4661cb0ef41Sopenharmony_ci  Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, kBufferSize);
4671cb0ef41Sopenharmony_ci  array_buffer_.Reset(isolate, ab);
4681cb0ef41Sopenharmony_ci  object->Set(context, FIXED_ONE_BYTE_STRING(isolate, "hrtimeBuffer"), ab)
4691cb0ef41Sopenharmony_ci      .ToChecked();
4701cb0ef41Sopenharmony_ci  backing_store_ = ab->GetBackingStore();
4711cb0ef41Sopenharmony_ci}
4721cb0ef41Sopenharmony_ci
4731cb0ef41Sopenharmony_civ8::CFunction BindingData::fast_number_(v8::CFunction::Make(FastNumber));
4741cb0ef41Sopenharmony_civ8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt));
4751cb0ef41Sopenharmony_ci
4761cb0ef41Sopenharmony_civoid BindingData::AddMethods() {
4771cb0ef41Sopenharmony_ci  Local<Context> ctx = env()->context();
4781cb0ef41Sopenharmony_ci  SetFastMethodNoSideEffect(ctx, object(), "hrtime", SlowNumber, &fast_number_);
4791cb0ef41Sopenharmony_ci  SetFastMethodNoSideEffect(
4801cb0ef41Sopenharmony_ci      ctx, object(), "hrtimeBigInt", SlowBigInt, &fast_bigint_);
4811cb0ef41Sopenharmony_ci}
4821cb0ef41Sopenharmony_ci
4831cb0ef41Sopenharmony_civoid BindingData::RegisterExternalReferences(
4841cb0ef41Sopenharmony_ci    ExternalReferenceRegistry* registry) {
4851cb0ef41Sopenharmony_ci  registry->Register(SlowNumber);
4861cb0ef41Sopenharmony_ci  registry->Register(SlowBigInt);
4871cb0ef41Sopenharmony_ci  registry->Register(FastNumber);
4881cb0ef41Sopenharmony_ci  registry->Register(FastBigInt);
4891cb0ef41Sopenharmony_ci  registry->Register(fast_number_.GetTypeInfo());
4901cb0ef41Sopenharmony_ci  registry->Register(fast_bigint_.GetTypeInfo());
4911cb0ef41Sopenharmony_ci}
4921cb0ef41Sopenharmony_ci
4931cb0ef41Sopenharmony_ciBindingData* BindingData::FromV8Value(Local<Value> value) {
4941cb0ef41Sopenharmony_ci  Local<Object> v8_object = value.As<Object>();
4951cb0ef41Sopenharmony_ci  return static_cast<BindingData*>(
4961cb0ef41Sopenharmony_ci      v8_object->GetAlignedPointerFromInternalField(BaseObject::kSlot));
4971cb0ef41Sopenharmony_ci}
4981cb0ef41Sopenharmony_ci
4991cb0ef41Sopenharmony_civoid BindingData::MemoryInfo(MemoryTracker* tracker) const {
5001cb0ef41Sopenharmony_ci  tracker->TrackField("array_buffer", array_buffer_);
5011cb0ef41Sopenharmony_ci}
5021cb0ef41Sopenharmony_ci
5031cb0ef41Sopenharmony_ci// This is the legacy version of hrtime before BigInt was introduced in
5041cb0ef41Sopenharmony_ci// JavaScript.
5051cb0ef41Sopenharmony_ci// The value returned by uv_hrtime() is a 64-bit int representing nanoseconds,
5061cb0ef41Sopenharmony_ci// so this function instead fills in an Uint32Array with 3 entries,
5071cb0ef41Sopenharmony_ci// to avoid any integer overflow possibility.
5081cb0ef41Sopenharmony_ci// The first two entries contain the second part of the value
5091cb0ef41Sopenharmony_ci// broken into the upper/lower 32 bits to be converted back in JS,
5101cb0ef41Sopenharmony_ci// because there is no Uint64Array in JS.
5111cb0ef41Sopenharmony_ci// The third entry contains the remaining nanosecond part of the value.
5121cb0ef41Sopenharmony_civoid BindingData::NumberImpl(BindingData* receiver) {
5131cb0ef41Sopenharmony_ci  // Make sure we don't accidentally access buffers wiped for snapshot.
5141cb0ef41Sopenharmony_ci  CHECK(!receiver->array_buffer_.IsEmpty());
5151cb0ef41Sopenharmony_ci  uint64_t t = uv_hrtime();
5161cb0ef41Sopenharmony_ci  uint32_t* fields = static_cast<uint32_t*>(receiver->backing_store_->Data());
5171cb0ef41Sopenharmony_ci  fields[0] = (t / NANOS_PER_SEC) >> 32;
5181cb0ef41Sopenharmony_ci  fields[1] = (t / NANOS_PER_SEC) & 0xffffffff;
5191cb0ef41Sopenharmony_ci  fields[2] = t % NANOS_PER_SEC;
5201cb0ef41Sopenharmony_ci}
5211cb0ef41Sopenharmony_ci
5221cb0ef41Sopenharmony_civoid BindingData::BigIntImpl(BindingData* receiver) {
5231cb0ef41Sopenharmony_ci  // Make sure we don't accidentally access buffers wiped for snapshot.
5241cb0ef41Sopenharmony_ci  CHECK(!receiver->array_buffer_.IsEmpty());
5251cb0ef41Sopenharmony_ci  uint64_t t = uv_hrtime();
5261cb0ef41Sopenharmony_ci  uint64_t* fields = static_cast<uint64_t*>(receiver->backing_store_->Data());
5271cb0ef41Sopenharmony_ci  fields[0] = t;
5281cb0ef41Sopenharmony_ci}
5291cb0ef41Sopenharmony_ci
5301cb0ef41Sopenharmony_civoid BindingData::SlowBigInt(const FunctionCallbackInfo<Value>& args) {
5311cb0ef41Sopenharmony_ci  BigIntImpl(FromJSObject<BindingData>(args.Holder()));
5321cb0ef41Sopenharmony_ci}
5331cb0ef41Sopenharmony_ci
5341cb0ef41Sopenharmony_civoid BindingData::SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args) {
5351cb0ef41Sopenharmony_ci  NumberImpl(FromJSObject<BindingData>(args.Holder()));
5361cb0ef41Sopenharmony_ci}
5371cb0ef41Sopenharmony_ci
5381cb0ef41Sopenharmony_cibool BindingData::PrepareForSerialization(Local<Context> context,
5391cb0ef41Sopenharmony_ci                                          v8::SnapshotCreator* creator) {
5401cb0ef41Sopenharmony_ci  // It's not worth keeping.
5411cb0ef41Sopenharmony_ci  // Release it, we will recreate it when the instance is dehydrated.
5421cb0ef41Sopenharmony_ci  array_buffer_.Reset();
5431cb0ef41Sopenharmony_ci  // Return true because we need to maintain the reference to the binding from
5441cb0ef41Sopenharmony_ci  // JS land.
5451cb0ef41Sopenharmony_ci  return true;
5461cb0ef41Sopenharmony_ci}
5471cb0ef41Sopenharmony_ci
5481cb0ef41Sopenharmony_ciInternalFieldInfoBase* BindingData::Serialize(int index) {
5491cb0ef41Sopenharmony_ci  DCHECK_EQ(index, BaseObject::kEmbedderType);
5501cb0ef41Sopenharmony_ci  InternalFieldInfo* info =
5511cb0ef41Sopenharmony_ci      InternalFieldInfoBase::New<InternalFieldInfo>(type());
5521cb0ef41Sopenharmony_ci  return info;
5531cb0ef41Sopenharmony_ci}
5541cb0ef41Sopenharmony_ci
5551cb0ef41Sopenharmony_civoid BindingData::Deserialize(Local<Context> context,
5561cb0ef41Sopenharmony_ci                              Local<Object> holder,
5571cb0ef41Sopenharmony_ci                              int index,
5581cb0ef41Sopenharmony_ci                              InternalFieldInfoBase* info) {
5591cb0ef41Sopenharmony_ci  DCHECK_EQ(index, BaseObject::kEmbedderType);
5601cb0ef41Sopenharmony_ci  v8::HandleScope scope(context->GetIsolate());
5611cb0ef41Sopenharmony_ci  Realm* realm = Realm::GetCurrent(context);
5621cb0ef41Sopenharmony_ci  // Recreate the buffer in the constructor.
5631cb0ef41Sopenharmony_ci  BindingData* binding = realm->AddBindingData<BindingData>(context, holder);
5641cb0ef41Sopenharmony_ci  CHECK_NOT_NULL(binding);
5651cb0ef41Sopenharmony_ci}
5661cb0ef41Sopenharmony_ci
5671cb0ef41Sopenharmony_cistatic void Initialize(Local<Object> target,
5681cb0ef41Sopenharmony_ci                       Local<Value> unused,
5691cb0ef41Sopenharmony_ci                       Local<Context> context,
5701cb0ef41Sopenharmony_ci                       void* priv) {
5711cb0ef41Sopenharmony_ci  Realm* realm = Realm::GetCurrent(context);
5721cb0ef41Sopenharmony_ci  Environment* env = realm->env();
5731cb0ef41Sopenharmony_ci  BindingData* const binding_data =
5741cb0ef41Sopenharmony_ci      realm->AddBindingData<BindingData>(context, target);
5751cb0ef41Sopenharmony_ci  if (binding_data == nullptr) return;
5761cb0ef41Sopenharmony_ci  binding_data->AddMethods();
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ci  // define various internal methods
5791cb0ef41Sopenharmony_ci  if (env->owns_process_state()) {
5801cb0ef41Sopenharmony_ci    SetMethod(context, target, "_debugProcess", DebugProcess);
5811cb0ef41Sopenharmony_ci    SetMethod(context, target, "abort", Abort);
5821cb0ef41Sopenharmony_ci    SetMethod(context, target, "causeSegfault", CauseSegfault);
5831cb0ef41Sopenharmony_ci    SetMethod(context, target, "chdir", Chdir);
5841cb0ef41Sopenharmony_ci  }
5851cb0ef41Sopenharmony_ci
5861cb0ef41Sopenharmony_ci  SetMethod(context, target, "umask", Umask);
5871cb0ef41Sopenharmony_ci  SetMethod(context, target, "memoryUsage", MemoryUsage);
5881cb0ef41Sopenharmony_ci  SetMethod(context, target, "constrainedMemory", GetConstrainedMemory);
5891cb0ef41Sopenharmony_ci  SetMethod(context, target, "rss", Rss);
5901cb0ef41Sopenharmony_ci  SetMethod(context, target, "cpuUsage", CPUUsage);
5911cb0ef41Sopenharmony_ci  SetMethod(context, target, "resourceUsage", ResourceUsage);
5921cb0ef41Sopenharmony_ci
5931cb0ef41Sopenharmony_ci  SetMethod(context, target, "_debugEnd", DebugEnd);
5941cb0ef41Sopenharmony_ci  SetMethod(context, target, "_getActiveRequests", GetActiveRequests);
5951cb0ef41Sopenharmony_ci  SetMethod(context, target, "_getActiveHandles", GetActiveHandles);
5961cb0ef41Sopenharmony_ci  SetMethod(context, target, "getActiveResourcesInfo", GetActiveResourcesInfo);
5971cb0ef41Sopenharmony_ci  SetMethod(context, target, "_kill", Kill);
5981cb0ef41Sopenharmony_ci  SetMethod(context, target, "_rawDebug", RawDebug);
5991cb0ef41Sopenharmony_ci
6001cb0ef41Sopenharmony_ci  SetMethodNoSideEffect(context, target, "cwd", Cwd);
6011cb0ef41Sopenharmony_ci  SetMethod(context, target, "dlopen", binding::DLOpen);
6021cb0ef41Sopenharmony_ci  SetMethod(context, target, "reallyExit", ReallyExit);
6031cb0ef41Sopenharmony_ci  SetMethodNoSideEffect(context, target, "uptime", Uptime);
6041cb0ef41Sopenharmony_ci  SetMethod(context, target, "patchProcessObject", PatchProcessObject);
6051cb0ef41Sopenharmony_ci}
6061cb0ef41Sopenharmony_ci
6071cb0ef41Sopenharmony_civoid RegisterExternalReferences(ExternalReferenceRegistry* registry) {
6081cb0ef41Sopenharmony_ci  BindingData::RegisterExternalReferences(registry);
6091cb0ef41Sopenharmony_ci
6101cb0ef41Sopenharmony_ci  registry->Register(DebugProcess);
6111cb0ef41Sopenharmony_ci  registry->Register(DebugEnd);
6121cb0ef41Sopenharmony_ci  registry->Register(Abort);
6131cb0ef41Sopenharmony_ci  registry->Register(CauseSegfault);
6141cb0ef41Sopenharmony_ci  registry->Register(Chdir);
6151cb0ef41Sopenharmony_ci
6161cb0ef41Sopenharmony_ci  registry->Register(Umask);
6171cb0ef41Sopenharmony_ci  registry->Register(RawDebug);
6181cb0ef41Sopenharmony_ci  registry->Register(MemoryUsage);
6191cb0ef41Sopenharmony_ci  registry->Register(GetConstrainedMemory);
6201cb0ef41Sopenharmony_ci  registry->Register(Rss);
6211cb0ef41Sopenharmony_ci  registry->Register(CPUUsage);
6221cb0ef41Sopenharmony_ci  registry->Register(ResourceUsage);
6231cb0ef41Sopenharmony_ci
6241cb0ef41Sopenharmony_ci  registry->Register(GetActiveRequests);
6251cb0ef41Sopenharmony_ci  registry->Register(GetActiveHandles);
6261cb0ef41Sopenharmony_ci  registry->Register(GetActiveResourcesInfo);
6271cb0ef41Sopenharmony_ci  registry->Register(Kill);
6281cb0ef41Sopenharmony_ci
6291cb0ef41Sopenharmony_ci  registry->Register(Cwd);
6301cb0ef41Sopenharmony_ci  registry->Register(binding::DLOpen);
6311cb0ef41Sopenharmony_ci  registry->Register(ReallyExit);
6321cb0ef41Sopenharmony_ci  registry->Register(Uptime);
6331cb0ef41Sopenharmony_ci  registry->Register(PatchProcessObject);
6341cb0ef41Sopenharmony_ci}
6351cb0ef41Sopenharmony_ci
6361cb0ef41Sopenharmony_ci}  // namespace process
6371cb0ef41Sopenharmony_ci}  // namespace node
6381cb0ef41Sopenharmony_ci
6391cb0ef41Sopenharmony_ciNODE_BINDING_CONTEXT_AWARE_INTERNAL(process_methods, node::process::Initialize)
6401cb0ef41Sopenharmony_ciNODE_BINDING_EXTERNAL_REFERENCE(process_methods,
6411cb0ef41Sopenharmony_ci                                node::process::RegisterExternalReferences)
642