Commit 2e7193f8 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Implement correct OS and CC detection.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/20734002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15923 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 70901202
......@@ -28,6 +28,8 @@
#ifndef V8_COMPILER_INTRINSICS_H_
#define V8_COMPILER_INTRINSICS_H_
#include "globals.h"
namespace v8 {
namespace internal {
......@@ -45,7 +47,8 @@ class CompilerIntrinsics {
INLINE(static int CountSetBits(uint32_t value));
};
#ifdef __GNUC__
#if V8_CC_GNU
int CompilerIntrinsics::CountTrailingZeros(uint32_t value) {
return __builtin_ctz(value);
}
......@@ -58,7 +61,7 @@ int CompilerIntrinsics::CountSetBits(uint32_t value) {
return __builtin_popcount(value);
}
#elif defined(_MSC_VER)
#elif V8_CC_MSVC
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
......
......@@ -366,12 +366,10 @@ static Handle<Value> GetStdout(int child_fd,
// We're disabling usage of waitid in Mac OS X because it doens't work for us:
// a parent process hangs on waiting while a child process is already a zombie.
// See http://code.google.com/p/v8/issues/detail?id=401.
#if defined(WNOWAIT) && !defined(ANDROID) && !defined(__APPLE__) \
&& !defined(__NetBSD__)
#if !defined(__FreeBSD__)
#if defined(WNOWAIT) && !V8_OS_ANDROID && !V8_OS_DARWN && \
!V8_OS_NETBSD && !V8_OS_FREEBSD
#define HAS_WAITID 1
#endif
#endif
// Get exit status of child.
......
......@@ -68,7 +68,7 @@
#include "v8.h"
#endif // V8_SHARED
#if !defined(_WIN32) && !defined(_WIN64)
#if V8_OS_UNIX
#include <unistd.h> // NOLINT
#endif
......@@ -868,7 +868,7 @@ Handle<ObjectTemplate> Shell::CreateGlobalTemplate(Isolate* isolate) {
RealmSharedGet, RealmSharedSet);
global_template->Set(String::New("Realm"), realm_template);
#if !defined(V8_SHARED) && !defined(_WIN32) && !defined(_WIN64)
#if !defined(V8_SHARED) && V8_OS_UNIX
Handle<ObjectTemplate> os_templ = ObjectTemplate::New();
AddOSMethods(os_templ);
global_template->Set(String::New("os"), os_templ);
......@@ -1020,7 +1020,7 @@ void Shell::OnExit() {
static FILE* FOpen(const char* path, const char* mode) {
#if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64))
#if V8_CC_MSVC
FILE* result;
if (fopen_s(&result, path, mode) == 0) {
return result;
......
......@@ -42,7 +42,7 @@
namespace v8 {
namespace internal {
#ifdef __APPLE__
#if V8_OS_DARWIN
#define __MACH_O
class MachO;
class MachOSection;
......
......@@ -28,46 +28,120 @@
#ifndef V8_GLOBALS_H_
#define V8_GLOBALS_H_
// Define V8_INFINITY
#define V8_INFINITY INFINITY
// ----------------------------------------------------------------------------
// Operating system detection (V8_OS_x)
//
// ANDROID - Android
// BSD4 - Any BSD 4.4 system
// CYGWIN - Cygwin
// DARWIN - Darwin / Mac OS X
// FREEBSD - FreeBSD
// LINUX - Linux
// NACL - Native Client
// NETBSD - NetBSD
// OPENBSD - OpenBSD
// SOLARIS - Solaris
// UNIX - Any UNIX BSD/SYSV system
// WIN32 - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008)
#if defined(ANDROID) || defined(__ANDROID__)
# define V8_OS_ANDROID 1
# define V8_OS_LINUX 1
# define V8_OS_UNIX 1
#elif defined(__APPLE__) && defined(__MACH__)
# define V8_OS_DARWIN 1
# define V8_OS_BSD4 1
# define V8_OS_UNIX 1
#elif defined(__CYGWIN__)
# define V8_OS_CYGWIN 1
# define V8_OS_UNIX 1
#elif defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
# define V8_OS_WIN32 1
# define V8_OS_WIN64 1
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || \
(defined(__MWERKS__) && defined(__INTEL__))
# define V8_OS_WIN32 1
#elif defined(__sun) || defined(sun)
# define V8_OS_SOLARIS 1
# define V8_OS_UNIX 1
#elif defined(__native_client__)
# define V8_OS_NACL 1
#elif defined(__linux__) || defined(__linux)
# define V8_OS_LINUX 1
# define V8_OS_UNIX 1
#elif defined(__FreeBSD__) || defined(__DragonFly__)
# define V8_OS_FREEBSD 1
# define V8_OS_BSD4 1
# define V8_OS_UNIX 1
#elif defined(__NetBSD__)
# define V8_OS_NETBSD 1
# define V8_OS_BSD4 1
# define V8_OS_UNIX 1
#elif defined(__OpenBSD__)
# define V8_OS_OPENBSD 1
# define V8_OS_BSD4 1
# define V8_OS_UNIX 1
#else
# error Operating system was not detected as supported by v8
#endif
// GCC specific stuff
#ifdef __GNUC__
#define __GNUC_VERSION_FOR_INFTY__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
// ----------------------------------------------------------------------------
// Compiler detection (V8_CC_x)
//
// CLANG - C++ front-end for the LLVM compiler
// GNU - GNU C++ or compatible
// INTEL - Intel C++ for Linux or Windows
// MINGW - Minimalistic GNU for Windows Compiler
// MIPS - MIPSpro C++
// MSVC - Microsoft Visual C/C++ or compatible
// RVCT - ARM Realview Compiler Suite
// Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
// warning flag and certain versions of GCC due to a bug:
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
// For now, we use the more involved template-based version from <limits>, but
// only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
// __GNUC_PREREQ is not defined in GCC for Mac OS X, so we define our own macro
#if __GNUC_VERSION_FOR_INFTY__ >= 29600 && __GNUC_VERSION_FOR_INFTY__ < 40100
#include <limits>
#undef V8_INFINITY
#define V8_INFINITY std::numeric_limits<double>::infinity()
#if defined(_MSC_VER)
# define V8_CC_MSVC 1
# if defined(__INTEL_COMPILER)
# define V8_CC_INTEL 1
# endif
#elif defined(__GNUC__)
# define V8_CC_GNU 1
# define V8_GNUC_PREREQ(major, minor) \
((major) > __GNUC__ || ((major) == __GNUC__ && (minor) >= __GNUC_MINOR__))
# if defined(__MINGW64__)
# define V8_CC_MINGW 1
# define V8_CC_MINGW64 1
# elif defined(__MINGW32__)
# define V8_CC_MINGW 1
# define V8_CC_MINGW32 1
# elif defined(__ARMCC__) || defined(__CC_ARM)
# define V8_CC_RVCT 1 // ARM Realview Compiler Suite also masquerades as GCC
# elif defined(__INTEL_COMPILER)
# define V8_CC_INTEL 1 // Intel C++ also masquerades as GCC 3.2.0
# elif defined(__clang__)
# define V8_CC_CLANG 1 // Clang also masquerades as GCC 4.2.1
# endif
#elif defined(__ARMCC__) || defined(__CC_ARM)
# define V8_CC_RVCT 1
#elif defined(__INTEL_COMPILER)
# define V8_CC_INTEL 1
#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C)
# define V8_CC_SUN 1
#else
# error Compiler was not detected as supported by v8
#endif
#undef __GNUC_VERSION_FOR_INFTY__
#endif // __GNUC__
#ifdef _MSC_VER
#undef V8_INFINITY
#define V8_INFINITY HUGE_VAL
#ifndef V8_GNUC_PREREQ
#define V8_GNUC_PREREQ(major, minor) 0
#endif
#include "../include/v8stdint.h"
namespace v8 {
namespace internal {
// ----------------------------------------------------------------------------
// Processor architecture detection. For more info on what's defined, see:
// http://msdn.microsoft.com/en-us/library/b0084kay.aspx
// http://www.agner.org/optimize/calling_conventions.pdf
// or with gcc, run: "echo | gcc -E -dM -"
#if defined(_M_X64) || defined(__x86_64__)
#if defined(__native_client__)
#if V8_OS_NACL
// For Native Client builds of V8, use V8_TARGET_ARCH_ARM, so that V8
// generates ARM machine code, together with a portable ARM simulator
// compiled for the host architecture in question.
......@@ -81,7 +155,7 @@ namespace internal {
#define V8_HOST_ARCH_X64 1
#define V8_HOST_ARCH_64_BIT 1
#define V8_HOST_CAN_READ_UNALIGNED 1
#endif // __native_client__
#endif // V8_OS_NACL
#elif defined(_M_IX86) || defined(__i386__)
#define V8_HOST_ARCH_IA32 1
#define V8_HOST_ARCH_32_BIT 1
......@@ -101,7 +175,7 @@ namespace internal {
defined(__ARM_ARCH_7__)
# define CAN_USE_ARMV7_INSTRUCTIONS 1
# ifndef CAN_USE_VFP3_INSTRUCTIONS
# define CAN_USE_VFP3_INSTRUCTIONS
# define CAN_USE_VFP3_INSTRUCTIONS 1
# endif
#endif
......@@ -111,13 +185,13 @@ namespace internal {
// environment as presented by the compiler.
#if !V8_TARGET_ARCH_X64 && !V8_TARGET_ARCH_IA32 && \
!V8_TARGET_ARCH_ARM && !V8_TARGET_ARCH_MIPS
#if defined(_M_X64) || defined(__x86_64__)
#if V8_HOST_ARCH_X64
#define V8_TARGET_ARCH_X64 1
#elif defined(_M_IX86) || defined(__i386__)
#elif V8_HOST_ARCH_IA32
#define V8_TARGET_ARCH_IA32 1
#elif defined(__ARMEL__)
#elif V8_HOST_ARCH_ARM
#define V8_TARGET_ARCH_ARM 1
#elif defined(__MIPSEL__)
#elif V8_HOST_ARCH_MIPS
#define V8_TARGET_ARCH_MIPS 1
#else
#error Target architecture was not detected as supported by v8
......@@ -163,6 +237,27 @@ namespace internal {
#error Unknown target architecture endiannes
#endif
// Define V8_INFINITY
#if V8_CC_GNU && V8_GNUC_PREREQ(2, 96) && !V8_GNUC_PREREQ(4, 1)
// Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
// warning flag and certain versions of GCC due to a bug:
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
// For now, we use the more involved template-based version from <limits>, but
// only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
#include <limits>
#define V8_INFINITY std::numeric_limits<double>::infinity()
#elif V8_CC_MSVC
#define V8_INFINITY HUGE_VAL
#else
#define V8_INFINITY INFINITY
#endif
#include "../include/v8stdint.h"
namespace v8 {
namespace internal {
// Support for alternative bool type. This is only enabled if the code is
// compiled with USE_MYBOOL defined. This catches some nasty type bugs.
// For instance, 'bool b = "false";' results in b == true! This is a hidden
......@@ -187,12 +282,12 @@ typedef byte* Address;
// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
// works on compilers that don't have it (like MSVC).
#if V8_HOST_ARCH_64_BIT
#if defined(_MSC_VER)
#if V8_CC_MSVC
#define V8_UINT64_C(x) (x ## UI64)
#define V8_INT64_C(x) (x ## I64)
#define V8_INTPTR_C(x) (x ## I64)
#define V8_PTR_PREFIX "ll"
#elif defined(__MINGW64__)
#elif V8_CC_MINGW64
#define V8_UINT64_C(x) (x ## ULL)
#define V8_INT64_C(x) (x ## LL)
#define V8_INTPTR_C(x) (x ## LL)
......@@ -218,16 +313,11 @@ typedef byte* Address;
#define V8PRIuPTR V8_PTR_PREFIX "u"
// Fix for Mac OS X defining uintptr_t as "unsigned long":
#if defined(__APPLE__) && defined(__MACH__)
#if V8_OS_DARWIN
#undef V8PRIxPTR
#define V8PRIxPTR "lx"
#endif
#if (defined(__APPLE__) && defined(__MACH__)) || \
defined(__FreeBSD__) || defined(__OpenBSD__)
#define USING_BSD_ABI
#endif
// -----------------------------------------------------------------------------
// Constants
......@@ -358,15 +448,15 @@ F FUNCTION_CAST(Address addr) {
// Define used for helping GCC to make better inlining. Don't bother for debug
// builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
// errors in debug build.
#if defined(__GNUC__) && !defined(DEBUG)
#if (__GNUC__ >= 4)
#if V8_CC_GNU && !defined(DEBUG)
#if V8_GNUC_PREREQ(4, 0)
#define INLINE(header) inline header __attribute__((always_inline))
#define NO_INLINE(header) header __attribute__((noinline))
#else
#define INLINE(header) inline __attribute__((always_inline)) header
#define NO_INLINE(header) __attribute__((noinline)) header
#endif
#elif defined(_MSC_VER) && !defined(DEBUG)
#elif V8_CC_MSVC && !defined(DEBUG)
#define INLINE(header) __forceinline header
#define NO_INLINE(header) header
#else
......@@ -375,7 +465,7 @@ F FUNCTION_CAST(Address addr) {
#endif
#if defined(__GNUC__) && __GNUC__ >= 4
#if V8_GNUC_PREREQ(4, 0)
#define MUST_USE_RESULT __attribute__ ((warn_unused_result))
#else
#define MUST_USE_RESULT
......
......@@ -1933,7 +1933,7 @@ void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid,
// If false, it is returned as a pointer to a preallocated by caller memory
// region. Pointer to this region should be passed to a function as an
// implicit first argument.
#if defined(USING_BSD_ABI) || defined(__MINGW32__) || defined(__CYGWIN__)
#if V8_OS_BSD4 || V8_OS_CYGWIN || V8_CC_MINGW32
static const bool kReturnHandlesDirectly = true;
#else
static const bool kReturnHandlesDirectly = false;
......
......@@ -39,7 +39,7 @@ namespace internal {
SaveContext::SaveContext(Isolate* isolate) : prev_(isolate->save_context()) {
if (isolate->context() != NULL) {
context_ = Handle<Context>(isolate->context());
#if __GNUC_VERSION__ >= 40100 && __GNUC_VERSION__ < 40300
#if V8_GNUC_PREREQ(4, 1) && !V8_GNUC_PREREQ(4, 3)
dummy_ = Handle<Context>(isolate->context());
#endif
}
......
......@@ -1413,7 +1413,7 @@ class SaveContext BASE_EMBEDDED {
private:
Handle<Context> context_;
#if __GNUC_VERSION__ >= 40100 && __GNUC_VERSION__ < 40300
#if V8_GNUC_PREREQ(4, 1) && !V8_GNUC_PREREQ(4, 3)
Handle<Context> dummy_;
#endif
SaveContext* prev_;
......
......@@ -111,9 +111,9 @@ struct LeakyInstanceTrait {
// Traits that define how an instance is allocated and accessed.
// TODO(kalmard): __alignof__ is only defined for GCC > 4.2. Fix alignment issue
// on MIPS with other compilers.
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
// TODO(kalmard): __alignof__ is only defined for GCC >= 4.3.
// Fix alignment issue on MIPS with other compilers.
#if V8_GNUC_PREREQ(4, 3)
#define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x))))
#else
#define LAZY_ALIGN(x)
......
......@@ -39,13 +39,13 @@ namespace internal {
// Result is undefined if input is zero.
int IntegerLog2(uint32_t value);
#if defined(__GNUC__)
#if V8_CC_GNU
inline int IntegerLog2(uint32_t value) {
return 31 - __builtin_clz(value);
}
#elif defined(_MSC_VER)
#elif V8_CC_MSVC
#pragma intrinsic(_BitScanReverse)
......
......@@ -28,6 +28,8 @@
// Platform specific code for Linux goes here. For the POSIX comaptible parts
// the implementation is in platform-posix.cc.
#include "platform.h"
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
......@@ -57,8 +59,8 @@
// GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'.
// Old versions of the C library <signal.h> didn't define the type.
#if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
#if V8_OS_ANDROID && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
V8_HOST_ARCH_ARM && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
#include <asm/sigcontext.h>
#endif
......@@ -67,7 +69,6 @@
#include "v8.h"
#include "platform-posix.h"
#include "platform.h"
#include "v8threads.h"
#include "vm-state-inl.h"
......@@ -79,7 +80,7 @@ namespace internal {
static Mutex* limit_mutex = NULL;
#ifdef __arm__
#if V8_HOST_ARCH_ARM
static bool CPUInfoContainsString(const char * search_string) {
const char* file_name = "/proc/cpuinfo";
// This is written as a straight shot one pass parser
......@@ -222,39 +223,23 @@ bool OS::ArmUsingHardFloat() {
// GCC versions 4.4 and below don't support hard-fp.
// GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
// __ARM_PCS_VFP.
#define GCC_VERSION (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
#if GCC_VERSION >= 40600
#if defined(__ARM_PCS_VFP)
return true;
#else
return false;
#endif
#elif GCC_VERSION < 40500
#elif V8_CC_GNU && (V8_GNUC_PREREQ(4, 6) || !V8_GNUC_PREREQ(4, 5))
return false;
#else
#if defined(__ARM_PCS_VFP)
return true;
#elif defined(__ARM_PCS) || defined(__SOFTFP) || !defined(__VFP_FP__)
return false;
#else
#error "Your version of GCC does not report the FP ABI compiled for." \
"Please report it on this issue" \
"http://code.google.com/p/v8/issues/detail?id=2140"
#endif
#endif
#undef GCC_VERSION
}
#endif // def __arm__
#endif // V8_HOST_ARCH_ARM
#ifdef __mips__
#if V8_HOST_ARCH_MIPS
bool OS::MipsCpuHasFeature(CpuFeature feature) {
const char* search_string = NULL;
const char* file_name = "/proc/cpuinfo";
......@@ -305,7 +290,7 @@ bool OS::MipsCpuHasFeature(CpuFeature feature) {
// Did not find string in the proc file.
return false;
}
#endif // def __mips__
#endif // V8_HOST_ARCH_MIPS
const char* OS::LocalTimezone(double time) {
......
......@@ -33,7 +33,7 @@
#include <dlfcn.h>
#include <pthread.h>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#if V8_OS_FREEBSD || V8_OS_OPENBSD
#include <pthread_np.h> // for pthread_set_name_np
#endif
#include <sched.h> // for sched_yield
......@@ -47,11 +47,9 @@
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined(__linux__)
#if V8_OS_LINUX
#include <sys/prctl.h> // for prctl
#endif
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__OpenBSD__)
#elif V8_OS_BSD4
#include <sys/sysctl.h> // for sysctl
#endif
......@@ -61,7 +59,7 @@
#undef MAP_TYPE
#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
#if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
#define LOG_TAG "v8"
#include <android/log.h>
#endif
......@@ -79,7 +77,7 @@ static const pthread_t kNoThread = (pthread_t) 0;
uint64_t OS::CpuFeaturesImpliedByPlatform() {
#if defined(__APPLE__)
#if V8_OS_DARWIN
// Mac OS X requires all these to install so we can assume they are present.
// These constants are defined by the CPUid instructions.
const uint64_t one = 1;
......@@ -135,10 +133,10 @@ void OS::Free(void* address, const size_t size) {
// Get rid of writable permission on code allocations.
void OS::ProtectCode(void* address, const size_t size) {
#if defined(__CYGWIN__)
#if V8_OS_CYGWIN
DWORD old_protect;
VirtualProtect(address, size, PAGE_EXECUTE_READ, &old_protect);
#elif defined(__native_client__)
#elif V8_OS_NACL
// The Native Client port of V8 uses an interpreter, so
// code pages don't need PROT_EXEC.
mprotect(address, size, PROT_READ);
......@@ -150,7 +148,7 @@ void OS::ProtectCode(void* address, const size_t size) {
// Create guard pages.
void OS::Guard(void* address, const size_t size) {
#if defined(__CYGWIN__)
#if V8_OS_CYGWIN
DWORD oldprotect;
VirtualProtect(address, size, PAGE_READONLY | PAGE_GUARD, &oldprotect);
#else
......@@ -160,7 +158,7 @@ void OS::Guard(void* address, const size_t size) {
void* OS::GetRandomMmapAddr() {
#if defined(__native_client__)
#if V8_OS_NACL
// TODO(bradchen): restore randomization once Native Client gets
// smarter about using mmap address hints.
// See http://code.google.com/p/nativeclient/issues/3341
......@@ -171,7 +169,7 @@ void* OS::GetRandomMmapAddr() {
// CpuFeatures::Probe. We don't care about randomization in this case because
// the code page is immediately freed.
if (isolate != NULL) {
#if V8_TARGET_ARCH_X64
#if V8_HOST_ARCH_64_BIT
uint64_t rnd1 = V8::RandomPrivate(isolate);
uint64_t rnd2 = V8::RandomPrivate(isolate);
uint64_t raw_addr = (rnd1 << 32) ^ rnd2;
......@@ -184,7 +182,7 @@ void* OS::GetRandomMmapAddr() {
raw_addr &= 0x3ffff000;
# ifdef __sun
#if V8_OS_SOLARIS
// For our Solaris/illumos mmap hint, we pick a random address in the bottom
// half of the top half of the address space (that is, the third quarter).
// Because we do not MAP_FIXED, this will be treated only as a hint -- the
......@@ -195,13 +193,13 @@ void* OS::GetRandomMmapAddr() {
// no hint at all. The high hint prevents the break from getting hemmed in
// at low values, ceding half of the address space to the system heap.
raw_addr += 0x80000000;
# else
#else
// The range 0x20000000 - 0x60000000 is relatively unpopulated across a
// variety of ASLR modes (PAE kernel, NX compat mode, etc) and on macos
// 10.6 and 10.7.
raw_addr += 0x20000000;
# endif
#endif
#endif // V8_OS_SOLARIS
#endif // V8_HOST_ARCH_64_BIT
return reinterpret_cast<void*>(raw_addr);
}
return NULL;
......@@ -239,11 +237,11 @@ void OS::DebugBreak() {
#elif V8_HOST_ARCH_MIPS
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
......@@ -386,7 +384,7 @@ void OS::Print(const char* format, ...) {
void OS::VPrint(const char* format, va_list args) {
#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
#if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
__android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
#else
vprintf(format, args);
......@@ -403,7 +401,7 @@ void OS::FPrint(FILE* out, const char* format, ...) {
void OS::VFPrint(FILE* out, const char* format, va_list args) {
#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
#if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
__android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, args);
#else
vfprintf(out, format, args);
......@@ -420,7 +418,7 @@ void OS::PrintError(const char* format, ...) {
void OS::VPrintError(const char* format, va_list args) {
#if defined(ANDROID) && !defined(V8_ANDROID_LOG_STDOUT)
#if V8_OS_ANDROID && !defined(V8_ANDROID_LOG_STDOUT)
__android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, args);
#else
vfprintf(stderr, format, args);
......@@ -472,7 +470,7 @@ void OS::MemMove(void* dest, const void* src, size_t size) {
(*memmove_function)(dest, src, size);
}
#elif defined(V8_HOST_ARCH_ARM)
#elif V8_HOST_ARCH_ARM
void OS::MemCopyUint16Uint8Wrapper(uint16_t* dest,
const uint8_t* src,
size_t chars) {
......@@ -500,7 +498,7 @@ void OS::PostSetUp() {
if (generated_memmove != NULL) {
memmove_function = generated_memmove;
}
#elif defined(V8_HOST_ARCH_ARM)
#elif V8_HOST_ARCH_ARM
OS::memcopy_uint8_function =
CreateMemCopyUint8Function(&OS::MemCopyUint8Wrapper);
OS::memcopy_uint16_uint8_function =
......@@ -553,12 +551,12 @@ Thread::~Thread() {
static void SetThreadName(const char* name) {
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#if V8_OS_FREEBSD || V8_OS_OPENBSD
pthread_set_name_np(pthread_self(), name);
#elif defined(__NetBSD__)
#elif V8_OS_NETBSD
STATIC_ASSERT(Thread::kMaxThreadNameLength <= PTHREAD_MAX_NAMELEN_NP);
pthread_setname_np(pthread_self(), "%s", name);
#elif defined(__APPLE__)
#elif V8_OS_DARWIN
// pthread_setname_np is only available in 10.6 or later, so test
// for it at runtime.
int (*dynamic_pthread_setname_np)(const char*);
......@@ -605,7 +603,7 @@ void Thread::Start() {
result = pthread_attr_init(&attr);
ASSERT_EQ(0, result);
// Native client uses default stack size.
#if !defined(__native_client__)
#if !V8_OS_NACL
if (stack_size_ > 0) {
result = pthread_attr_setstacksize(&attr, static_cast<size_t>(stack_size_));
ASSERT_EQ(0, result);
......@@ -633,7 +631,7 @@ void Thread::YieldCPU() {
static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) {
#if defined(__CYGWIN__)
#if V8_OS_CYGWIN
// We need to cast pthread_key_t to Thread::LocalStorageKey in two steps
// because pthread_key_t is a pointer type on Cygwin. This will probably not
// work on 64-bit platforms, but Cygwin doesn't support 64-bit anyway.
......@@ -647,7 +645,7 @@ static Thread::LocalStorageKey PthreadKeyToLocalKey(pthread_key_t pthread_key) {
static pthread_key_t LocalKeyToPthreadKey(Thread::LocalStorageKey local_key) {
#if defined(__CYGWIN__)
#if V8_OS_CYGWIN
STATIC_ASSERT(sizeof(Thread::LocalStorageKey) == sizeof(pthread_key_t));
intptr_t ptr_key = static_cast<intptr_t>(local_key);
return reinterpret_cast<pthread_key_t>(ptr_key);
......
......@@ -28,13 +28,13 @@
#ifndef V8_PLATFORM_POSIX_H_
#define V8_PLATFORM_POSIX_H_
#if !defined(ANDROID)
#include "platform.h"
#if !V8_OS_ANDROID
#include <cxxabi.h>
#endif
#include <stdio.h>
#include "platform.h"
namespace v8 {
namespace internal {
......@@ -58,7 +58,7 @@ struct POSIXBacktraceHelper {
char mangled[201];
if (sscanf(symbols[i], "%*[^(]%*[(]%200[^)+]", mangled) == 1) {// NOLINT
char* demangled = NULL;
#if !defined(ANDROID)
#if !V8_OS_ANDROID
int status;
size_t length;
demangled = abi::__cxa_demangle(mangled, NULL, &length, &status);
......
......@@ -48,7 +48,7 @@
#include "simulator.h"
#include "vm-state-inl.h"
#ifdef _MSC_VER
#if V8_CC_MSVC
// Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually
// defined in strings.h.
......@@ -56,7 +56,7 @@ int strncasecmp(const char* s1, const char* s2, int n) {
return _strnicmp(s1, s2, n);
}
#endif // _MSC_VER
#endif // V8_CC_MSVC
// Extra functions for MinGW. Most of these are the _s functions which are in
......@@ -169,7 +169,7 @@ void OS::MemMove(void* dest, const void* src, size_t size) {
#endif // V8_TARGET_ARCH_IA32
#ifdef _WIN64
#if V8_OS_WIN64
typedef double (*ModuloFunction)(double, double);
static ModuloFunction modulo_function = NULL;
// Defined in codegen-x64.cc.
......@@ -185,8 +185,7 @@ double modulo(double x, double y) {
// on all architectures we currently support.
return (*modulo_function)(x, y);
}
#else // Win32
#else
double modulo(double x, double y) {
// Workaround MS fmod bugs. ECMA-262 says:
// dividend is finite and divisor is an infinity => result equals dividend
......@@ -197,8 +196,7 @@ double modulo(double x, double y) {
}
return x;
}
#endif // _WIN64
#endif // V8_OS_WIN64
#define UNARY_MATH_FUNCTION(name, generator) \
......@@ -228,7 +226,7 @@ void lazily_initialize_fast_exp() {
void MathSetup() {
#ifdef _WIN64
#if V8_OS_WIN64
init_modulo_function();
#endif
init_fast_sin_function();
......@@ -1009,11 +1007,11 @@ void OS::Abort() {
void OS::DebugBreak() {
#ifdef _MSC_VER
#if V8_CC_MSVC
__debugbreak();
#else
::DebugBreak();
#endif
#endif // V8_CC_MSVC
}
......@@ -1361,7 +1359,7 @@ int OS::StackWalk(Vector<OS::StackFrame> frames) {
// Initialize the stack walking
STACKFRAME64 stack_frame;
memset(&stack_frame, 0, sizeof(stack_frame));
#ifdef _WIN64
#if V8_OS _WIN64
stack_frame.AddrPC.Offset = context.Rip;
stack_frame.AddrFrame.Offset = context.Rbp;
stack_frame.AddrStack.Offset = context.Rsp;
......@@ -1470,21 +1468,21 @@ uint64_t OS::CpuFeaturesImpliedByPlatform() {
double OS::nan_value() {
#ifdef _MSC_VER
#if V8_CC_MSVC
// Positive Quiet NaN with no payload (aka. Indeterminate) has all bits
// in mask set, so value equals mask.
static const __int64 nanval = kQuietNaNMask;
return *reinterpret_cast<const double*>(&nanval);
#else // _MSC_VER
#else // V8_CC_MSVC
return NAN;
#endif // _MSC_VER
#endif // V8_CC_MSVC
}
int OS::ActivationFrameAlignment() {
#ifdef _WIN64
#if V8_OS__WIN64
return 16; // Windows 64-bit ABI requires the stack to be 16-byte aligned.
#elif defined(__MINGW32__)
#elif V8_CC_MINGW
// With gcc 4.4 the tree vectorization optimizer can generate code
// that requires 16 byte alignment such as movdqa on x86.
return 16;
......
......@@ -44,6 +44,8 @@
#ifndef V8_PLATFORM_H_
#define V8_PLATFORM_H_
#include <stdarg.h>
#ifdef __sun
# ifndef signbit
namespace std {
......@@ -52,16 +54,6 @@ int signbit(double x);
# endif
#endif
// GCC specific stuff
#ifdef __GNUC__
// Needed for va_list on at least MinGW and Android.
#include <stdarg.h>
#define __GNUC_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
#endif // __GNUC__
// Windows specific stuff.
#ifdef WIN32
......@@ -132,7 +124,7 @@ class Socket;
#ifndef V8_NO_FAST_TLS
#if defined(_MSC_VER) && V8_HOST_ARCH_IA32
#if V8_CC_MSVC && V8_HOST_ARCH_IA32
#define V8_FAST_TLS_SUPPORTED 1
......@@ -154,7 +146,7 @@ inline intptr_t InternalGetExistingThreadLocal(intptr_t index) {
kPointerSize * (index - kMaxInlineSlots));
}
#elif defined(__APPLE__) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64)
#elif V8_OS_DARWIN && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64)
#define V8_FAST_TLS_SUPPORTED 1
......@@ -385,7 +377,7 @@ class OS {
// the platform doesn't care. Guaranteed to be a power of two.
static int ActivationFrameAlignment();
#if defined(V8_TARGET_ARCH_IA32)
#if V8_TARGET_ARCH_IA32
// Limit below which the extra overhead of the MemCopy function is likely
// to outweigh the benefits of faster copying.
static const int kMinComplexMemCopy = 64;
......@@ -399,7 +391,7 @@ class OS {
static void MemCopy(void* dest, const void* src, size_t size) {
MemMove(dest, src, size);
}
#elif defined(V8_HOST_ARCH_ARM)
#elif V8_HOST_ARCH_ARM
typedef void (*MemCopyUint8Function)(uint8_t* dest,
const uint8_t* src,
size_t size);
......
......@@ -42,7 +42,7 @@
#include "unicode.h"
#include "utils.h"
#ifdef _MSC_VER
#if V8_CC_MSVC
namespace std {
// Usually defined in math.h, but not in MSVC.
......
......@@ -27,9 +27,11 @@
#include "sampler.h"
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) \
|| defined(__NetBSD__) || defined(__sun) || defined(__ANDROID__) \
|| defined(__native_client__)
#if V8_OS_DARWIN
#include <mach/mach.h>
#elif V8_OS_UNIX && !V8_OS_CYGWIN
#define USE_SIGNALS
......@@ -38,23 +40,19 @@
#include <signal.h>
#include <sys/time.h>
#include <sys/syscall.h>
#if !defined(__ANDROID__) || defined(__BIONIC_HAVE_UCONTEXT_T)
#if !V8_OS_ANDROID || defined(__BIONIC_HAVE_UCONTEXT_T)
#include <ucontext.h>
#endif
#include <unistd.h>
// GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'.
// Old versions of the C library <signal.h> didn't define the type.
#if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
defined(__arm__) && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
#if V8_OS_ANDROID && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
V8_HOST_ARCH_ARM && !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
#include <asm/sigcontext.h>
#endif
#elif defined(__MACH__)
#include <mach/mach.h>
#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#elif V8_OS_CYGWIN || V8_OS_WIN32
#include "win32-headers.h"
......@@ -72,7 +70,7 @@
#include "vm-state-inl.h"
#if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T)
#if V8_OS_ANDROID && !defined(__BIONIC_HAVE_UCONTEXT_T)
// Not all versions of Android's C library provide ucontext_t.
// Detect this and provide custom but compatible definitions. Note that these
......@@ -81,7 +79,7 @@
//
// See http://code.google.com/p/android/issues/detail?id=34784
#if defined(__arm__)
#if V8_HOST_ARCH_ARM
typedef struct sigcontext mcontext_t;
......@@ -93,7 +91,7 @@ typedef struct ucontext {
// Other fields are not used by V8, don't define them here.
} ucontext_t;
#elif defined(__mips__)
#elif V8_HOST_ARCH_MIPS
// MIPS version of sigcontext, for Android bionic.
typedef struct {
uint32_t regmask;
......@@ -124,7 +122,7 @@ typedef struct ucontext {
// Other fields are not used by V8, don't define them here.
} ucontext_t;
#elif defined(__i386__)
#elif V8_HOST_ARCH_IA32
// x86 version for Android.
typedef struct {
uint32_t gregs[19];
......@@ -144,7 +142,7 @@ typedef struct ucontext {
enum { REG_EBP = 6, REG_ESP = 7, REG_EIP = 14 };
#endif
#endif // __ANDROID__ && !defined(__BIONIC_HAVE_UCONTEXT_T)
#endif // V8_OS_ANDROID && !defined(__BIONIC_HAVE_UCONTEXT_T)
namespace v8 {
......@@ -177,7 +175,7 @@ class Sampler::PlatformData : public PlatformDataCommon {
pthread_t vm_tid_;
};
#elif defined(__MACH__)
#elif V8_OS_DARWIN
class Sampler::PlatformData : public PlatformDataCommon {
public:
......@@ -197,7 +195,7 @@ class Sampler::PlatformData : public PlatformDataCommon {
thread_act_t profiled_thread_;
};
#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#elif V8_OS_CYGWIN || V8_OS_WIN32
// ----------------------------------------------------------------------------
// Win32 profiler support. On Cygwin we use the same sampler implementation as
......@@ -301,7 +299,7 @@ bool SignalHandler::signal_handler_installed_ = false;
void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
void* context) {
#if defined(__native_client__)
#if V8_OS_NACL
// As Native Client does not support signal handling, profiling
// is disabled.
return;
......@@ -331,7 +329,7 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
// Extracting the sample from the context is extremely machine dependent.
ucontext_t* ucontext = reinterpret_cast<ucontext_t*>(context);
mcontext_t& mcontext = ucontext->uc_mcontext;
#if defined(__linux__) || defined(__ANDROID__)
#if V8_OS_LINUX
#if V8_HOST_ARCH_IA32
state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_EIP]);
state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_ESP]);
......@@ -359,7 +357,7 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
state.sp = reinterpret_cast<Address>(mcontext.gregs[29]);
state.fp = reinterpret_cast<Address>(mcontext.gregs[30]);
#endif // V8_HOST_ARCH_*
#elif defined(__FreeBSD__)
#elif V8_OS_FREEBSD
#if V8_HOST_ARCH_IA32
state.pc = reinterpret_cast<Address>(mcontext.mc_eip);
state.sp = reinterpret_cast<Address>(mcontext.mc_esp);
......@@ -373,7 +371,7 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
state.sp = reinterpret_cast<Address>(mcontext.mc_r13);
state.fp = reinterpret_cast<Address>(mcontext.mc_r11);
#endif // V8_HOST_ARCH_*
#elif defined(__NetBSD__)
#elif V8_OS_NETBSD
#if V8_HOST_ARCH_IA32
state.pc = reinterpret_cast<Address>(mcontext.__gregs[_REG_EIP]);
state.sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_ESP]);
......@@ -383,7 +381,7 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
state.sp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RSP]);
state.fp = reinterpret_cast<Address>(mcontext.__gregs[_REG_RBP]);
#endif // V8_HOST_ARCH_*
#elif defined(__OpenBSD__)
#elif V8_OS_OPENBSD
USE(mcontext);
#if V8_HOST_ARCH_IA32
state.pc = reinterpret_cast<Address>(ucontext->sc_eip);
......@@ -394,11 +392,11 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
state.sp = reinterpret_cast<Address>(ucontext->sc_rsp);
state.fp = reinterpret_cast<Address>(ucontext->sc_rbp);
#endif // V8_HOST_ARCH_*
#elif defined(__sun)
#elif V8_OS_SOLARIS
state.pc = reinterpret_cast<Address>(mcontext.gregs[REG_PC]);
state.sp = reinterpret_cast<Address>(mcontext.gregs[REG_SP]);
state.fp = reinterpret_cast<Address>(mcontext.gregs[REG_FP]);
#endif // __sun
#endif // V8_OS_SOLARIS
#endif // USE_SIMULATOR
sampler->SampleStack(state);
#endif // __native_client__
......@@ -493,7 +491,7 @@ class SamplerThread : public Thread {
pthread_kill(tid, SIGPROF);
}
#elif defined(__MACH__)
#elif V8_OS_DARWIN
void SampleContext(Sampler* sampler) {
thread_act_t profiled_thread = sampler->platform_data()->profiled_thread();
......@@ -546,7 +544,7 @@ class SamplerThread : public Thread {
thread_resume(profiled_thread);
}
#elif defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
#elif V8_OS_CYGWIN || V8_OS_WIN32
void SampleContext(Sampler* sampler) {
HANDLE profiled_thread = sampler->platform_data()->profiled_thread();
......
......@@ -47,7 +47,7 @@ static void ReserveSpaceForSnapshot(Deserializer* deserializer,
CHECK_NE(NULL, fp);
int new_size, pointer_size, data_size, code_size, map_size, cell_size,
property_cell_size;
#ifdef _MSC_VER
#if V8_CC_MSVC
// Avoid warning about unsafe fscanf from MSVC.
// Please note that this is only fine if %c and %s are not being used.
#define fscanf fscanf_s
......@@ -59,7 +59,7 @@ static void ReserveSpaceForSnapshot(Deserializer* deserializer,
CHECK_EQ(1, fscanf(fp, "map %d\n", &map_size));
CHECK_EQ(1, fscanf(fp, "cell %d\n", &cell_size));
CHECK_EQ(1, fscanf(fp, "property cell %d\n", &property_cell_size));
#ifdef _MSC_VER
#if V8_CC_MSVC
#undef fscanf
#endif
fclose(fp);
......
......@@ -176,7 +176,7 @@ static void ReadDiyFp(Vector<const char> buffer,
static bool DoubleStrtod(Vector<const char> trimmed,
int exponent,
double* result) {
#if (V8_TARGET_ARCH_IA32 || defined(USE_SIMULATOR)) && !defined(_MSC_VER)
#if (V8_TARGET_ARCH_IA32 || defined(USE_SIMULATOR)) && !V8_CC_MSVC
// On x86 the floating-point stack can be 64 or 80 bits wide. If it is
// 80 bits wide (as is the case on Linux) then double-rounding occurs and the
// result is not accurate.
......
......@@ -37,11 +37,11 @@ namespace internal {
// ----------------------------------------------------------------------------
// I/O support.
#if __GNUC__ >= 4
#if V8_GNUC_PREREQ(4, 0)
// On gcc we can ask the compiler to check the types of %d-style format
// specifiers and their associated arguments. TODO(erikcorry) fix this
// so it works on MacOSX.
#if defined(__MACH__) && defined(__APPLE__)
#if V8_OS_DARWIN
#define PRINTF_CHECKING
#define FPRINTF_CHECKING
#else // MacOsX.
......@@ -262,7 +262,7 @@ inline void MemsetPointer(T** dest, U* value, int counter) {
#elif V8_HOST_ARCH_X64
#define STOS "stosq"
#endif
#if defined(__native_client__)
#if V8_OS_NACL
// This STOS sequence does not validate for x86_64 Native Client.
// Here we #undef STOS to force use of the slower C version.
// TODO(bradchen): Profile V8 and implement a faster REP STOS
......@@ -270,7 +270,7 @@ inline void MemsetPointer(T** dest, U* value, int counter) {
#undef STOS
#endif
#if defined(__GNUC__) && defined(STOS)
#if V8_CC_GNU && defined(STOS)
asm volatile(
"cld;"
"rep ; " STOS
......@@ -317,7 +317,7 @@ template <typename sourcechar, typename sinkchar>
INLINE(static void CopyCharsUnsigned(sinkchar* dest,
const sourcechar* src,
int chars));
#if defined(V8_HOST_ARCH_ARM)
#if V8_HOST_ARCH_ARM
INLINE(void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars));
INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint8_t* src, int chars));
INLINE(void CopyCharsUnsigned(uint16_t* dest, const uint16_t* src, int chars));
......@@ -380,7 +380,7 @@ void CopyCharsUnsigned(sinkchar* dest, const sourcechar* src, int chars) {
}
#if defined(V8_HOST_ARCH_ARM)
#if V8_HOST_ARCH_ARM
void CopyCharsUnsigned(uint8_t* dest, const uint8_t* src, int chars) {
switch (static_cast<unsigned>(chars)) {
case 0:
......
......@@ -473,7 +473,7 @@ TEST(AssemblerMultiByteNop) {
}
#ifdef __GNUC__
#if V8_CC_GNU
#define ELEMENT_COUNT 4
void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) {
......@@ -561,7 +561,7 @@ TEST(StackAlignmentForSSE2) {
}
#undef ELEMENT_COUNT
#endif // __GNUC__
#endif // V8_CC_GNU
#undef __
......@@ -436,7 +436,7 @@ TEST(AssemblerMultiByteNop) {
}
#ifdef __GNUC__
#if V8_CC_GNU
#define ELEMENT_COUNT 4
void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) {
......@@ -521,7 +521,7 @@ TEST(StackAlignmentForSSE2) {
}
#undef ELEMENT_COUNT
#endif // __GNUC__
#endif // V8_CC_GNU
#undef __
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment