[fuchsia] Fuchsia support to Node
diff --git a/src/api/environment.cc b/src/api/environment.cc index 45780d9..35f1d78 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc
@@ -216,6 +216,7 @@ } void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) { +#ifndef __Fuchsia__ const uint64_t constrained_memory = uv_get_constrained_memory(); const uint64_t total_memory = constrained_memory > 0 ? std::min(uv_get_total_memory(), constrained_memory) : @@ -226,6 +227,7 @@ // heap based on the actual physical memory. params->constraints.ConfigureDefaults(total_memory, 0); } +#endif } void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
diff --git a/src/debug_utils.cc b/src/debug_utils.cc index a601c5e..45269b6 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc
@@ -13,7 +13,8 @@ #if defined(__linux__) && !defined(__GLIBC__) || \ defined(__UCLIBC__) || \ - defined(_AIX) + defined(_AIX) || \ + defined(__Fuchsia__) #define HAVE_EXECINFO_H 0 #else #define HAVE_EXECINFO_H 1
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 74b7fc1..d3bb733 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc
@@ -132,11 +132,13 @@ // receiving the signal would terminate the process. return -err; } +#ifndef __Fuchsia__ RegisterSignalHandler(SIGUSR1, StartIoThreadWakeup); // Unblock SIGUSR1. A pending SIGUSR1 signal will now be delivered. sigemptyset(&sigmask); sigaddset(&sigmask, SIGUSR1); CHECK_EQ(0, pthread_sigmask(SIG_UNBLOCK, &sigmask, nullptr)); +#endif return 0; } #endif // __POSIX__
diff --git a/src/node.cc b/src/node.cc index 649ac43..91f2cb3 100644 --- a/src/node.cc +++ b/src/node.cc
@@ -100,7 +100,9 @@ #define STDIN_FILENO 0 #else #include <pthread.h> +#ifndef __Fuchsia__ #include <sys/resource.h> // getrlimit, setrlimit +#endif #include <termios.h> // tcgetattr, tcsetattr #include <unistd.h> // STDIN_FILENO, STDERR_FILENO #endif @@ -492,7 +494,7 @@ } #endif // NODE_USE_V8_WASM_TRAP_HANDLER -#ifdef __POSIX__ +#if defined(POSIX) && !defined(__Fuchsia__) void RegisterSignalHandler(int signal, sigaction_cb handler, bool reset_handler) { @@ -537,6 +539,10 @@ // Make sure file descriptors 0-2 are valid before we start logging anything. for (auto& s : stdio) { const int fd = &s - stdio; +#ifdef __Fuchsia__ + // In fuchsia stdin is not readily available. + if (fd == 0) continue; +#endif if (fstat(fd, &s.stat) == 0) continue; // Anything but EBADF means something is seriously wrong. We don't @@ -554,7 +560,7 @@ #endif // HAVE_INSPECTOR // TODO(addaleax): NODE_SHARED_MODE does not really make sense here. -#ifndef NODE_SHARED_MODE +#if !defined(NODE_SHARED_MODE) && !defined(__Fuchsia__) // Restore signal dispositions, the parent process may have changed them. struct sigaction act; memset(&act, 0, sizeof(act)); @@ -576,6 +582,10 @@ for (auto& s : stdio) { const int fd = &s - stdio; int err; +#ifdef __Fuchsia__ + // In fuchsia stdin is not readily available. + if (fd == 0) continue; +#endif do s.flags = fcntl(fd, F_GETFL); @@ -591,6 +601,7 @@ CHECK_EQ(err, 0); } +#ifndef __Fuchsia__ RegisterSignalHandler(SIGINT, SignalExit, true); RegisterSignalHandler(SIGTERM, SignalExit, true); @@ -628,6 +639,7 @@ } } while (min + 1 < max); } +#endif // __Fuchsia__ #endif // __POSIX__ #ifdef _WIN32 for (int fd = 0; fd <= 2; ++fd) { @@ -652,6 +664,11 @@ for (auto& s : stdio) { const int fd = &s - stdio; +#ifdef __Fuchsia__ + // In fuchsia stdin is not readily available. + if (fd == 0) continue; +#endif + struct stat tmp; if (-1 == fstat(fd, &tmp)) { CHECK_EQ(errno, EBADF); // Program closed file descriptor.
diff --git a/src/node_os.cc b/src/node_os.cc index bd61b4c..2be0b55 100644 --- a/src/node_os.cc +++ b/src/node_os.cc
@@ -78,7 +78,15 @@ static void GetOSInformation(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); uv_utsname_t info; - int err = uv_os_uname(&info); + int err = 0; +#ifdef __Fuchsia__ + // TODO(victor): Update uv_os_uname to get these informations for Fuchsia + info.sysname[0] = 0; + info.version[0] = 0; + info.release[0] = 0; +#else + err = uv_os_uname(&info); +#endif if (err != 0) { CHECK_GE(args.Length(), 1); @@ -330,6 +338,7 @@ args.GetReturnValue().Set(entry); } +#ifndef __Fuchsia__ static void SetPriority(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -369,7 +378,7 @@ args.GetReturnValue().Set(priority); } - +#endif // !__Fuchsia__ void Initialize(Local<Object> target, Local<Value> unused, @@ -385,9 +394,12 @@ env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses); env->SetMethod(target, "getHomeDirectory", GetHomeDirectory); env->SetMethod(target, "getUserInfo", GetUserInfo); +#ifndef __Fuchsia__ env->SetMethod(target, "setPriority", SetPriority); env->SetMethod(target, "getPriority", GetPriority); +#endif env->SetMethod(target, "getOSInformation", GetOSInformation); + target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"), Boolean::New(env->isolate(), IsBigEndian())).Check();
diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 88f4c1c..081b4a0 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc
@@ -25,7 +25,9 @@ typedef int mode_t; #else #include <pthread.h> +#if !defined(__Fuchsia__) #include <sys/resource.h> // getrlimit, setrlimit +#endif #include <termios.h> // tcgetattr, tcsetattr #endif @@ -89,6 +91,7 @@ } } +#ifndef __Fuchsia__ // CPUUsage use libuv's uv_getrusage() this-process resource usage accessor, // to access ru_utime (user CPU time used) and ru_stime (system CPU time used), // which are uv_timeval_t structs (long tv_sec, long tv_usec). @@ -116,6 +119,7 @@ fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec; fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec; } +#endif static void Cwd(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -174,7 +178,7 @@ int sig; if (!args[1]->Int32Value(context).To(&sig)) return; - uv_pid_t own_pid = uv_os_getpid(); + int own_pid = uv_os_getpid(); if (sig > 0 && (pid == 0 || pid == -1 || pid == own_pid || pid == -own_pid) && !HasSignalJSHandler(sig)) { @@ -306,6 +310,7 @@ Array::New(env->isolate(), handle_v.data(), handle_v.size())); } +#ifndef __Fuchsia__ static void ResourceUsage(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -337,6 +342,7 @@ fields[14] = rusage.ru_nvcsw; fields[15] = rusage.ru_nivcsw; } +#endif #ifdef __POSIX__ static void DebugProcess(const FunctionCallbackInfo<Value>& args) { @@ -476,10 +482,15 @@ env->SetMethod(target, "umask", Umask); env->SetMethod(target, "_rawDebug", RawDebug); env->SetMethod(target, "memoryUsage", MemoryUsage); + + #ifndef __Fuchsia__ env->SetMethod(target, "cpuUsage", CPUUsage); + env->SetMethod(target, "resourceUsage", ResourceUsage); + #endif + env->SetMethod(target, "hrtime", Hrtime); env->SetMethod(target, "hrtimeBigInt", HrtimeBigInt); - env->SetMethod(target, "resourceUsage", ResourceUsage); + env->SetMethod(target, "_getActiveRequests", GetActiveRequests); env->SetMethod(target, "_getActiveHandles", GetActiveHandles);
diff --git a/src/node_report.cc b/src/node_report.cc index 98da24c..b3fbee0 100644 --- a/src/node_report.cc +++ b/src/node_report.cc
@@ -12,7 +12,9 @@ #ifdef _WIN32 #include <Windows.h> #else // !_WIN32 +#ifndef __Fuchsia__ #include <sys/resource.h> +#endif #include <cxxabi.h> #include <dlfcn.h> #endif @@ -561,6 +563,7 @@ (uv_hrtime() - node::per_process::node_start_time) / (NANOS_PER_SEC); if (uptime == 0) uptime = 1; // avoid division by zero. +#ifndef __Fuchsia__ // Process and current thread usage statistics uv_rusage_t rusage; writer->json_objectstart("resourceUsage"); @@ -585,6 +588,7 @@ writer->json_objectend(); } writer->json_objectend(); +#endif #ifdef RUSAGE_THREAD struct rusage stats; if (getrusage(RUSAGE_THREAD, &stats) == 0) { @@ -629,7 +633,7 @@ writer->json_objectend(); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__Fuchsia__) static struct { const char* description; int id; @@ -676,7 +680,7 @@ } } writer->json_objectend(); -#endif // _WIN32 +#endif // _WIN32 && __Fuchsia__ PrintLoadedLibraries(writer); }
diff --git a/src/node_watchdog.cc b/src/node_watchdog.cc index 22b09e8..0d48ae4 100644 --- a/src/node_watchdog.cc +++ b/src/node_watchdog.cc
@@ -297,6 +297,7 @@ return 0; } +#ifndef __Fuchsia__ #ifdef __POSIX__ CHECK_EQ(has_running_thread_, false); has_pending_signal_ = false; @@ -322,6 +323,7 @@ SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, TRUE); } #endif +#endif return 0; } @@ -349,6 +351,7 @@ watchdogs_.clear(); } +#ifndef __Fuchsia__ #ifdef __POSIX__ if (!has_running_thread_) { has_pending_signal_ = false; @@ -369,7 +372,7 @@ had_pending_signal = has_pending_signal_; has_pending_signal_ = false; - +#endif return had_pending_signal; }