Revision: 23513
Author:   [email protected]
Date:     Fri Aug 29 09:39:28 2014 UTC
Log:      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.

[email protected]

Review URL: https://codereview.chromium.org/521473003
https://code.google.com/p/v8/source/detail?r=23513

Modified:
 /branches/bleeding_edge/src/base/platform/platform-linux.cc
 /branches/bleeding_edge/src/base/platform/platform-posix.cc
 /branches/bleeding_edge/src/base/platform/semaphore.cc
 /branches/bleeding_edge/src/base/sys-info.cc
 /branches/bleeding_edge/src/d8-posix.cc
 /branches/bleeding_edge/src/sampler.cc
 /branches/bleeding_edge/test/cctest/test-api.cc

=======================================
--- /branches/bleeding_edge/src/base/platform/platform-linux.cc Mon Aug 4 11:34:54 2014 UTC +++ /branches/bleeding_edge/src/base/platform/platform-linux.cc Fri Aug 29 09:39:28 2014 UTC
@@ -9,9 +9,7 @@
 #include <semaphore.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <sys/prctl.h>
 #include <sys/resource.h>
-#include <sys/syscall.h>
 #include <sys/time.h>
 #include <sys/types.h>

@@ -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 <sys/prctl.h>
+#include <sys/syscall.h>
+#endif

 namespace v8 {
 namespace base {
@@ -95,20 +102,30 @@


 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<time_t>(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<double>(t->tm_gmtoff * msPerSecond -
                              (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
+#endif
 }


@@ -260,18 +277,15 @@
     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 @@


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;
=======================================
--- /branches/bleeding_edge/src/base/platform/platform-posix.cc Wed Aug 27 13:47:19 2014 UTC +++ /branches/bleeding_edge/src/base/platform/platform-posix.cc Fri Aug 29 09:39:28 2014 UTC
@@ -19,14 +19,8 @@
 #include <sys/mman.h>
 #include <sys/resource.h>
 #include <sys/stat.h>
-#if !defined(__pnacl__)
-#include <sys/syscall.h>
-#endif
 #include <sys/time.h>
 #include <sys/types.h>
-#if defined(__linux__) && !defined(__pnacl__)
-#include <sys/prctl.h>  // NOLINT, for prctl
-#endif
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) | | \
     defined(__NetBSD__) || defined(__OpenBSD__)
 #include <sys/sysctl.h>  // NOLINT, for sysctl
@@ -56,6 +50,14 @@
 #include <dlfcn.h>
 #endif

+#if V8_OS_LINUX
+#include <sys/prctl.h>  // NOLINT, for prctl
+#endif
+
+#if !V8_OS_NACL
+#include <sys/syscall.h>
+#endif
+
 namespace v8 {
 namespace base {

@@ -223,11 +225,11 @@
 #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::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
 }


=======================================
--- /branches/bleeding_edge/src/base/platform/semaphore.cc Mon Aug 4 11:34:54 2014 UTC +++ /branches/bleeding_edge/src/base/platform/semaphore.cc Fri Aug 29 09:39:28 2014 UTC
@@ -12,6 +12,7 @@
 #include <errno.h>

 #include "src/base/logging.h"
+#include "src/base/platform/elapsed-timer.h"
 #include "src/base/platform/time.h"

 namespace v8 {
@@ -106,6 +107,17 @@


 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 @@
     DCHECK_EQ(-1, result);
     DCHECK_EQ(EINTR, errno);
   }
+#endif
 }

 #elif V8_OS_WIN
=======================================
--- /branches/bleeding_edge/src/base/sys-info.cc Wed Aug 27 08:29:22 2014 UTC +++ /branches/bleeding_edge/src/base/sys-info.cc Fri Aug 29 09:39:28 2014 UTC
@@ -91,6 +91,9 @@
     return 0;
   }
   return static_cast<int64_t>(stat_buf.st_size);
+#elif V8_OS_NACL
+  // No support for _SC_PHYS_PAGES, assume 2GB.
+  return static_cast<int64_t>(1) << 31;
 #elif V8_OS_POSIX
   long pages = sysconf(_SC_PHYS_PAGES);    // NOLINT(runtime/int)
   long page_size = sysconf(_SC_PAGESIZE);  // NOLINT(runtime/int)
=======================================
--- /branches/bleeding_edge/src/d8-posix.cc     Fri Jun 27 11:02:18 2014 UTC
+++ /branches/bleeding_edge/src/d8-posix.cc     Fri Aug 29 09:39:28 2014 UTC
@@ -7,7 +7,6 @@
 #include <signal.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/select.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/types.h>
@@ -16,6 +15,9 @@

 #include "src/d8.h"

+#if !V8_OS_NACL
+#include <sys/select.h>
+#endif

 namespace v8 {

@@ -102,11 +104,16 @@
   }
   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 @@
     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 {
=======================================
--- /branches/bleeding_edge/src/sampler.cc      Tue Aug 26 13:07:18 2014 UTC
+++ /branches/bleeding_edge/src/sampler.cc      Fri Aug 29 09:39:28 2014 UTC
@@ -13,7 +13,7 @@
 #include <signal.h>
 #include <sys/time.h>

-#if !V8_OS_QNX
+#if !V8_OS_QNX && !V8_OS_NACL
 #include <sys/syscall.h>  // NOLINT
 #endif

@@ -21,8 +21,8 @@
 #include <mach/mach.h>
 // OpenBSD doesn't have <ucontext.h>. ucontext_t lives in <signal.h>
 // 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 <ucontext.h>
 #endif

@@ -294,6 +294,7 @@

  private:
   static void Install() {
+#if !V8_OS_NACL
     struct sigaction sa;
     sa.sa_sigaction = &HandleProfilerSignal;
     sigemptyset(&sa.sa_mask);
@@ -304,16 +305,21 @@
 #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 @@
 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 @@
 #endif  // V8_OS_QNX
 #endif  // USE_SIMULATOR
   sampler->SampleStack(state);
+}
 #endif  // V8_OS_NACL
-}

 #endif

=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Tue Aug 26 13:07:18 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-api.cc Fri Aug 29 09:39:28 2014 UTC
@@ -21621,7 +21621,7 @@
 }


-#if V8_OS_POSIX
+#if V8_OS_POSIX && !V8_OS_NACL
 class ThreadInterruptTest {
  public:
   ThreadInterruptTest() : sem_(0), sem_value_(0) { }

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to