From dfda8950de977ce32952b187642e7c4a64034868 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Fri, 29 Aug 2014 09:39:28 +0000 Subject: [PATCH] More PNaCL fixes (without GYP/Makefile tweaks) This is basically https://codereview.chromium.org/513923005/ with a few changes: * Makefile.nacl and v8.gyp are untouched. * MAP_NORESERVE-handling is more defensive. * Added ugly busy-wait emulation of sem_timedwait. R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/521473003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23513 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/base/platform/platform-linux.cc | 32 +++++++++++++++++++++++--------- src/base/platform/platform-posix.cc | 23 +++++++++++++++-------- src/base/platform/semaphore.cc | 13 +++++++++++++ src/base/sys-info.cc | 3 +++ src/d8-posix.cc | 17 ++++++++++++++--- src/sampler.cc | 21 ++++++++++++--------- test/cctest/test-api.cc | 2 +- 7 files changed, 81 insertions(+), 30 deletions(-) diff --git a/src/base/platform/platform-linux.cc b/src/base/platform/platform-linux.cc index fca1709..41f3315 100644 --- a/src/base/platform/platform-linux.cc +++ b/src/base/platform/platform-linux.cc @@ -9,9 +9,7 @@ #include #include #include -#include #include -#include #include #include @@ -46,6 +44,15 @@ #include "src/base/macros.h" #include "src/base/platform/platform.h" +#if V8_OS_NACL +#if !defined(MAP_NORESERVE) +// PNaCL doesn't have this, so we always grab all of the memory, which is bad. +#define MAP_NORESERVE 0 +#endif +#else +#include +#include +#endif namespace v8 { namespace base { @@ -95,20 +102,30 @@ bool OS::ArmUsingHardFloat() { const char* OS::LocalTimezone(double time, TimezoneCache* cache) { +#if V8_OS_NACL + // Missing support for tm_zone field. + return ""; +#else if (std::isnan(time)) return ""; time_t tv = static_cast(std::floor(time/msPerSecond)); struct tm* t = localtime(&tv); if (NULL == t) return ""; return t->tm_zone; +#endif } double OS::LocalTimeOffset(TimezoneCache* cache) { +#if V8_OS_NACL + // Missing support for tm_zone field. + return 0; +#else time_t tv = time(NULL); struct tm* t = localtime(&tv); // tm_gmtoff includes any daylight savings offset, so subtract it. return static_cast(t->tm_gmtoff * msPerSecond - (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); +#endif } @@ -260,18 +277,15 @@ void OS::SignalCodeMovingGC() { OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile()); OS::Abort(); } - void* addr = mmap(OS::GetRandomMmapAddr(), - size, -#if defined(__native_client__) + void* addr = mmap(OS::GetRandomMmapAddr(), size, +#if V8_OS_NACL // The Native Client port of V8 uses an interpreter, // so code pages don't need PROT_EXEC. PROT_READ, #else PROT_READ | PROT_EXEC, #endif - MAP_PRIVATE, - fileno(f), - 0); + MAP_PRIVATE, fileno(f), 0); DCHECK(addr != MAP_FAILED); OS::Free(addr, size); fclose(f); @@ -387,7 +401,7 @@ void* VirtualMemory::ReserveRegion(size_t size) { bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { -#if defined(__native_client__) +#if V8_OS_NACL // The Native Client port of V8 uses an interpreter, // so code pages don't need PROT_EXEC. int prot = PROT_READ | PROT_WRITE; diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc index ea06ff5..0fc04fc 100644 --- a/src/base/platform/platform-posix.cc +++ b/src/base/platform/platform-posix.cc @@ -19,14 +19,8 @@ #include #include #include -#if !defined(__pnacl__) -#include -#endif #include #include -#if defined(__linux__) && !defined(__pnacl__) -#include // NOLINT, for prctl -#endif #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \ defined(__NetBSD__) || defined(__OpenBSD__) #include // NOLINT, for sysctl @@ -56,6 +50,14 @@ #include #endif +#if V8_OS_LINUX +#include // NOLINT, for prctl +#endif + +#if !V8_OS_NACL +#include +#endif + namespace v8 { namespace base { @@ -223,11 +225,11 @@ void OS::DebugBreak() { #elif V8_HOST_ARCH_MIPS64 asm("break"); #elif V8_HOST_ARCH_IA32 -#if defined(__native_client__) +#if V8_OS_NACL asm("hlt"); #else asm("int $3"); -#endif // __native_client__ +#endif // V8_OS_NACL #elif V8_HOST_ARCH_X64 asm("int $3"); #else @@ -268,12 +270,17 @@ int OS::GetCurrentThreadId() { // int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { +#if V8_OS_NACL + // Optionally used in Logger::ResourceEvent. + return -1; +#else struct rusage usage; if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; *secs = usage.ru_utime.tv_sec; *usecs = usage.ru_utime.tv_usec; return 0; +#endif } diff --git a/src/base/platform/semaphore.cc b/src/base/platform/semaphore.cc index e11338f..669240e 100644 --- a/src/base/platform/semaphore.cc +++ b/src/base/platform/semaphore.cc @@ -12,6 +12,7 @@ #include #include "src/base/logging.h" +#include "src/base/platform/elapsed-timer.h" #include "src/base/platform/time.h" namespace v8 { @@ -106,6 +107,17 @@ void Semaphore::Wait() { bool Semaphore::WaitFor(const TimeDelta& rel_time) { +#if V8_OS_NACL + // PNaCL doesn't support sem_timedwait, do ugly busy waiting. + ElapsedTimer timer; + timer.Start(); + do { + int result = sem_trywait(&native_handle_); + if (result == 0) return true; + DCHECK(errno == EAGAIN || error == EINTR); + } while (!timer.HasExpired(rel_time)); + return false; +#else // Compute the time for end of timeout. const Time time = Time::NowFromSystemTime() + rel_time; const struct timespec ts = time.ToTimespec(); @@ -129,6 +141,7 @@ bool Semaphore::WaitFor(const TimeDelta& rel_time) { DCHECK_EQ(-1, result); DCHECK_EQ(EINTR, errno); } +#endif } #elif V8_OS_WIN diff --git a/src/base/sys-info.cc b/src/base/sys-info.cc index 203b777..06c4f24 100644 --- a/src/base/sys-info.cc +++ b/src/base/sys-info.cc @@ -91,6 +91,9 @@ int64_t SysInfo::AmountOfPhysicalMemory() { return 0; } return static_cast(stat_buf.st_size); +#elif V8_OS_NACL + // No support for _SC_PHYS_PAGES, assume 2GB. + return static_cast(1) << 31; #elif V8_OS_POSIX long pages = sysconf(_SC_PHYS_PAGES); // NOLINT(runtime/int) long page_size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int) diff --git a/src/d8-posix.cc b/src/d8-posix.cc index 59c50b4..9a20b06 100644 --- a/src/d8-posix.cc +++ b/src/d8-posix.cc @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -16,6 +15,9 @@ #include "src/d8.h" +#if !V8_OS_NACL +#include +#endif namespace v8 { @@ -102,11 +104,16 @@ static bool WaitOnFD(int fd, } timeout.tv_usec = (read_timeout % 1000) * 1000; timeout.tv_sec = read_timeout / 1000; +#if V8_OS_NACL + // PNaCL has no support for select. + int number_of_fds_ready = -1; +#else int number_of_fds_ready = select(fd + 1, &readfds, &writefds, &exceptfds, read_timeout != -1 ? &timeout : NULL); +#endif return number_of_fds_ready == 1; } @@ -547,8 +554,12 @@ void Shell::SetUMask(const v8::FunctionCallbackInfo& args) { return; } if (args[0]->IsNumber()) { - mode_t mask = args[0]->Int32Value(); - int previous = umask(mask); +#if V8_OS_NACL + // PNaCL has no support for umask. + int previous = 0; +#else + int previous = umask(args[0]->Int32Value()); +#endif args.GetReturnValue().Set(previous); return; } else { diff --git a/src/sampler.cc b/src/sampler.cc index 29fe27f..394efeb 100644 --- a/src/sampler.cc +++ b/src/sampler.cc @@ -13,7 +13,7 @@ #include #include -#if !V8_OS_QNX +#if !V8_OS_QNX && !V8_OS_NACL #include // NOLINT #endif @@ -21,8 +21,8 @@ #include // OpenBSD doesn't have . ucontext_t lives in // and is a typedef for struct sigcontext. There is no uc_mcontext. -#elif(!V8_OS_ANDROID || defined(__BIONIC_HAVE_UCONTEXT_T)) \ - && !V8_OS_OPENBSD +#elif(!V8_OS_ANDROID || defined(__BIONIC_HAVE_UCONTEXT_T)) && \ + !V8_OS_OPENBSD && !V8_OS_NACL #include #endif @@ -294,6 +294,7 @@ class SignalHandler : public AllStatic { private: static void Install() { +#if !V8_OS_NACL struct sigaction sa; sa.sa_sigaction = &HandleProfilerSignal; sigemptyset(&sa.sa_mask); @@ -304,16 +305,21 @@ class SignalHandler : public AllStatic { #endif signal_handler_installed_ = (sigaction(SIGPROF, &sa, &old_signal_handler_) == 0); +#endif } static void Restore() { +#if !V8_OS_NACL if (signal_handler_installed_) { sigaction(SIGPROF, &old_signal_handler_, 0); signal_handler_installed_ = false; } +#endif } +#if !V8_OS_NACL static void HandleProfilerSignal(int signal, siginfo_t* info, void* context); +#endif // Protects the process wide state below. static base::Mutex* mutex_; static int client_count_; @@ -328,13 +334,10 @@ struct sigaction SignalHandler::old_signal_handler_; bool SignalHandler::signal_handler_installed_ = false; +// As Native Client does not support signal handling, profiling is disabled. +#if !V8_OS_NACL void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, void* context) { -#if V8_OS_NACL - // As Native Client does not support signal handling, profiling - // is disabled. - return; -#else USE(info); if (signal != SIGPROF) return; Isolate* isolate = Isolate::UnsafeCurrent(); @@ -477,8 +480,8 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, #endif // V8_OS_QNX #endif // USE_SIMULATOR sampler->SampleStack(state); -#endif // V8_OS_NACL } +#endif // V8_OS_NACL #endif diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index f74c1a2..db0831c 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -21621,7 +21621,7 @@ THREADED_TEST(JSONParseNumber) { } -#if V8_OS_POSIX +#if V8_OS_POSIX && !V8_OS_NACL class ThreadInterruptTest { public: ThreadInterruptTest() : sem_(0), sem_value_(0) { } -- 2.7.4