#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>
#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 {
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
}
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);
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;
#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
#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 {
#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
//
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
}
#include <errno.h>
#include "src/base/logging.h"
+#include "src/base/platform/elapsed-timer.h"
#include "src/base/platform/time.h"
namespace v8 {
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();
DCHECK_EQ(-1, result);
DCHECK_EQ(EINTR, errno);
}
+#endif
}
#elif V8_OS_WIN
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)
#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>
#include "src/d8.h"
+#if !V8_OS_NACL
+#include <sys/select.h>
+#endif
namespace v8 {
}
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;
}
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 {
#include <signal.h>
#include <sys/time.h>
-#if !V8_OS_QNX
+#if !V8_OS_QNX && !V8_OS_NACL
#include <sys/syscall.h> // NOLINT
#endif
#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
private:
static void Install() {
+#if !V8_OS_NACL
struct sigaction sa;
sa.sa_sigaction = &HandleProfilerSignal;
sigemptyset(&sa.sa_mask);
#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_;
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();
#endif // V8_OS_QNX
#endif // USE_SIMULATOR
sampler->SampleStack(state);
-#endif // V8_OS_NACL
}
+#endif // V8_OS_NACL
#endif
}
-#if V8_OS_POSIX
+#if V8_OS_POSIX && !V8_OS_NACL
class ThreadInterruptTest {
public:
ThreadInterruptTest() : sem_(0), sem_value_(0) { }