39 #include <sys/socket.h>
40 #include <sys/resource.h>
42 #include <sys/types.h>
45 #include <arpa/inet.h>
46 #include <netinet/in.h>
51 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
53 #include <android/log.h>
70 int result = getrlimit(RLIMIT_DATA, &limit);
71 if (result != 0)
return 0;
72 return limit.rlim_cur;
77 static intptr_t page_size = getpagesize();
85 mprotect(address, size, PROT_READ | PROT_EXEC);
90 void OS::Guard(
void* address,
const size_t size) {
91 mprotect(address, size, PROT_NONE);
97 Isolate* isolate = Isolate::UncheckedCurrent();
101 if (isolate !=
NULL) {
102 #ifdef V8_TARGET_ARCH_X64
105 uint64_t raw_addr = (rnd1 << 32) ^ rnd2;
109 raw_addr &= V8_UINT64_C(0x3ffffffff000);
115 raw_addr &= 0x3ffff000;
116 raw_addr += 0x20000000;
118 return reinterpret_cast<void*
>(raw_addr);
127 double modulo(
double x,
double y) {
132 #define UNARY_MATH_FUNCTION(name, generator) \
133 static UnaryMathFunction fast_##name##_function = NULL; \
134 void init_fast_##name##_function() { \
135 fast_##name##_function = generator; \
137 double fast_##name(double x) { \
138 return (*fast_##name##_function)(x); \
157 return static_cast<int>(getpid());
168 if (getrusage(RUSAGE_SELF, &usage) < 0)
return -1;
169 *secs = usage.ru_utime.tv_sec;
170 *usecs = usage.ru_utime.tv_usec;
177 if (gettimeofday(&tv,
NULL) < 0)
return 0.0;
178 return (static_cast<double>(tv.tv_sec) * 1000) +
179 (
static_cast<double>(tv.tv_usec) / 1000);
186 if (gettimeofday(&tv,
NULL) < 0)
188 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
194 time_t tv =
static_cast<time_t
>(floor(time/msPerSecond));
195 struct tm* t = localtime(&tv);
197 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
211 FILE* file = fopen(path, mode);
213 struct stat file_stat;
214 if (fstat(fileno(file), &file_stat) != 0)
return NULL;
215 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
216 if (is_regular_file)
return file;
223 return (
remove(path) == 0);
235 void OS::Print(
const char* format, ...) {
237 va_start(args, format);
243 void OS::VPrint(
const char* format, va_list args) {
244 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
245 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
247 vprintf(format, args);
252 void OS::FPrint(FILE* out,
const char* format, ...) {
254 va_start(args, format);
260 void OS::VFPrint(FILE* out,
const char* format, va_list args) {
261 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
262 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
264 vfprintf(out, format, args);
271 va_start(args, format);
278 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
279 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args);
281 vfprintf(stderr, format, args);
286 int OS::SNPrintF(Vector<char> str,
const char* format, ...) {
288 va_start(args, format);
289 int result =
VSNPrintF(str, format, args);
298 int n = vsnprintf(str.start(), str.length(), format, args);
299 if (n < 0 || n >= str.length()) {
301 if (str.length() > 0)
302 str[str.length() - 1] =
'\0';
310 #if defined(V8_TARGET_ARCH_IA32)
311 static OS::MemCopyFunction memcopy_function =
NULL;
313 OS::MemCopyFunction CreateMemCopyFunction();
316 void OS::MemCopy(
void* dest,
const void* src,
size_t size) {
319 (*memcopy_function)(dest, src, size);
321 CHECK_EQ(0, memcmp(dest, src, size));
324 #endif // V8_TARGET_ARCH_IA32
328 #if defined(V8_TARGET_ARCH_IA32)
329 memcopy_function = CreateMemCopyFunction();
331 init_fast_sin_function();
332 init_fast_cos_function();
333 init_fast_tan_function();
334 init_fast_log_function();
335 init_fast_sqrt_function();
343 return strchr(str, c);
348 strncpy(dest.
start(), src, n);
360 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
363 static const int kOn = 1;
364 int ret = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
374 bool Bind(
const int port);
375 bool Listen(
int backlog)
const;
379 bool Connect(
const char* host,
const char* port);
385 int Send(
const char* data,
int len)
const;
386 int Receive(
char* data,
int len)
const;
390 bool IsValid()
const {
return socket_ != -1; }
403 memset(&addr, 0,
sizeof(addr));
404 addr.sin_family = AF_INET;
405 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
406 addr.sin_port = htons(port);
407 int status = bind(socket_,
408 BitCast<struct sockaddr *>(&addr),
419 int status = listen(socket_, backlog);
431 socket = accept(socket_,
NULL,
NULL);
432 }
while (socket == -1 && errno == EINTR);
448 struct addrinfo *result =
NULL;
449 struct addrinfo hints;
450 memset(&hints, 0,
sizeof(addrinfo));
451 hints.ai_family = AF_INET;
452 hints.ai_socktype = SOCK_STREAM;
453 hints.ai_protocol = IPPROTO_TCP;
454 int status = getaddrinfo(host, port, &hints, &result);
461 status = connect(socket_, result->ai_addr, result->ai_addrlen);
462 }
while (status == -1 && errno == EINTR);
463 freeaddrinfo(result);
471 int status = shutdown(socket_, SHUT_RDWR);
481 if (len <= 0)
return 0;
483 while (written < len) {
484 int status = send(socket_, data + written, len - written, 0);
487 }
else if (status > 0) {
489 }
else if (errno != EINTR) {
498 if (len <= 0)
return 0;
501 status = recv(socket_, data, len, 0);
502 }
while (status == -1 && errno == EINTR);
503 return (status < 0) ? 0 : status;
508 int on = reuse_address ? 1 : 0;
509 int status = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR, &on,
sizeof(on));
#define CHECK_EQ(expected, value)
static int VSNPrintF(Vector< char > str, const char *format, va_list args)
#define LOG(isolate, Call)
static FILE * OpenTemporaryFile()
int Send(const char *data, int len) const
static void * GetRandomMmapAddr()
static int GetUserTime(uint32_t *secs, uint32_t *usecs)
#define ASSERT(condition)
static void VFPrint(FILE *out, const char *format, va_list args)
bool Listen(int backlog) const
static void MemCopy(void *dest, const void *src, size_t size)
static void ProtectCode(void *address, const size_t size)
static FILE * FOpen(const char *path, const char *mode)
static void VPrint(const char *format, va_list args)
UnaryMathFunction CreateSqrtFunction()
static void Guard(void *address, const size_t size)
static void VPrintError(const char *format, va_list args)
double modulo(double x, double y)
static int GetCurrentProcessId()
static uint16_t NToH(uint16_t value)
static double TimeCurrentMillis()
static uint16_t HToN(uint16_t value)
static void Print(const char *format,...)
static int SNPrintF(Vector< char > str, const char *format,...)
static double nan_value()
static uint32_t RandomPrivate(Isolate *isolate)
static void PrintError(const char *format,...)
static void StrNCpy(Vector< char > dest, const char *src, size_t n)
bool SetReuseAddress(bool reuse_address)
static double DaylightSavingsOffset(double time)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
bool Bind(const int port)
static bool Remove(const char *path)
static int GetLastError()
static intptr_t MaxVirtualMemory()
static void FPrint(FILE *out, const char *format,...)
int Receive(char *data, int len) const
static intptr_t CommitPageSize()
static const char *const LogFileOpenMode
UnaryMathFunction CreateTranscendentalFunction(TranscendentalCache::Type type)
static char * StrChr(char *str, int c)
static Socket * CreateSocket()
bool Connect(const char *host, const char *port)