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); \
163 if (getrusage(RUSAGE_SELF, &usage) < 0)
return -1;
164 *secs = usage.ru_utime.tv_sec;
165 *usecs = usage.ru_utime.tv_usec;
172 if (gettimeofday(&tv,
NULL) < 0)
return 0.0;
173 return (static_cast<double>(tv.tv_sec) * 1000) +
174 (
static_cast<double>(tv.tv_usec) / 1000);
181 if (gettimeofday(&tv,
NULL) < 0)
183 return (static_cast<int64_t>(tv.tv_sec) * 1000000) + tv.tv_usec;
189 time_t tv =
static_cast<time_t
>(floor(time/msPerSecond));
190 struct tm* t = localtime(&tv);
192 return t->tm_isdst > 0 ? 3600 * msPerSecond : 0;
206 FILE* file = fopen(path, mode);
208 struct stat file_stat;
209 if (fstat(fileno(file), &file_stat) != 0)
return NULL;
210 bool is_regular_file = ((file_stat.st_mode & S_IFREG) != 0);
211 if (is_regular_file)
return file;
218 return (
remove(path) == 0);
230 void OS::Print(
const char* format, ...) {
232 va_start(args, format);
238 void OS::VPrint(
const char* format, va_list args) {
239 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
240 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
242 vprintf(format, args);
247 void OS::FPrint(FILE* out,
const char* format, ...) {
249 va_start(args, format);
255 void OS::VFPrint(FILE* out,
const char* format, va_list args) {
256 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
257 __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
259 vfprintf(out, format, args);
266 va_start(args, format);
273 #if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
274 __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args);
276 vfprintf(stderr, format, args);
281 int OS::SNPrintF(Vector<char> str,
const char* format, ...) {
283 va_start(args, format);
284 int result =
VSNPrintF(str, format, args);
293 int n = vsnprintf(str.start(), str.length(), format, args);
294 if (n < 0 || n >= str.length()) {
296 if (str.length() > 0)
297 str[str.length() - 1] =
'\0';
305 #if defined(V8_TARGET_ARCH_IA32)
306 static OS::MemCopyFunction memcopy_function =
NULL;
308 OS::MemCopyFunction CreateMemCopyFunction();
311 void OS::MemCopy(
void* dest,
const void* src,
size_t size) {
314 (*memcopy_function)(dest, src, size);
316 CHECK_EQ(0, memcmp(dest, src, size));
319 #endif // V8_TARGET_ARCH_IA32
323 #if defined(V8_TARGET_ARCH_IA32)
324 memcopy_function = CreateMemCopyFunction();
326 init_fast_sin_function();
327 init_fast_cos_function();
328 init_fast_tan_function();
329 init_fast_log_function();
330 init_fast_sqrt_function();
338 return strchr(str, c);
343 strncpy(dest.
start(), src, n);
355 socket_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
358 static const int kOn = 1;
359 int ret = setsockopt(socket_, SOL_SOCKET, SO_REUSEADDR,
369 bool Bind(
const int port);
370 bool Listen(
int backlog)
const;
374 bool Connect(
const char* host,
const char* port);
380 int Send(
const char* data,
int len)
const;
381 int Receive(
char* data,
int len)
const;
385 bool IsValid()
const {
return socket_ != -1; }
398 memset(&addr, 0,
sizeof(addr));
399 addr.sin_family = AF_INET;
400 addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
401 addr.sin_port = htons(port);
402 int status = bind(socket_,
403 BitCast<struct sockaddr *>(&addr),
414 int status = listen(socket_, backlog);
426 socket = accept(socket_,
NULL,
NULL);
427 }
while (socket == -1 && errno == EINTR);
443 struct addrinfo *result =
NULL;
444 struct addrinfo hints;
445 memset(&hints, 0,
sizeof(addrinfo));
446 hints.ai_family = AF_INET;
447 hints.ai_socktype = SOCK_STREAM;
448 hints.ai_protocol = IPPROTO_TCP;
449 int status = getaddrinfo(host, port, &hints, &result);
456 status = connect(socket_, result->ai_addr, result->ai_addrlen);
457 }
while (status == -1 && errno == EINTR);
458 freeaddrinfo(result);
466 int status = shutdown(socket_, SHUT_RDWR);
476 if (len <= 0)
return 0;
478 while (written < len) {
479 int status = send(socket_, data + written, len - written, 0);
482 }
else if (status > 0) {
484 }
else if (errno != EINTR) {
493 if (len <= 0)
return 0;
496 status = recv(socket_, data, len, 0);
497 }
while (status == -1 && errno == EINTR);
498 return (status < 0) ? 0 : status;
503 int on = reuse_address ? 1 : 0;
504 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 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,...)
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 trace on stack replacement optimize closures functions with arguments object optimize functions containing for in loops profiler considers IC stability primitive functions trigger their own optimization re try self optimization if it failed insert an interrupt check at function exit execution budget before interrupt is triggered call count before self optimization self_optimization count_based_interrupts weighted_back_edges trace_opt 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 enable use of ARMv7 instructions if enable use of MIPS FPU instructions if NULL
static void StrNCpy(Vector< char > dest, const char *src, size_t n)
bool SetReuseAddress(bool reuse_address)
static double DaylightSavingsOffset(double time)
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)