summaryrefslogtreecommitdiff
path: root/deps/v8/src/base/platform
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-03-07 08:54:53 +0100
committerMichaël Zasso <targos@protonmail.com>2018-03-07 16:48:52 +0100
commit88786fecff336342a56e6f2e7ff3b286be716e47 (patch)
tree92e6ba5b8ac8dae1a058988d20c9d27bfa654390 /deps/v8/src/base/platform
parent4e86f9b5ab83cbabf43839385bf383e6a7ef7d19 (diff)
downloadnode-new-88786fecff336342a56e6f2e7ff3b286be716e47.tar.gz
deps: update V8 to 6.5.254.31
PR-URL: https://github.com/nodejs/node/pull/18453 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yang Guo <yangguo@chromium.org> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Diffstat (limited to 'deps/v8/src/base/platform')
-rw-r--r--deps/v8/src/base/platform/platform-fuchsia.cc5
-rw-r--r--deps/v8/src/base/platform/platform-posix.cc58
-rw-r--r--deps/v8/src/base/platform/platform-win32.cc33
-rw-r--r--deps/v8/src/base/platform/platform.h68
-rw-r--r--deps/v8/src/base/platform/semaphore.cc2
-rw-r--r--deps/v8/src/base/platform/time.cc3
6 files changed, 89 insertions, 80 deletions
diff --git a/deps/v8/src/base/platform/platform-fuchsia.cc b/deps/v8/src/base/platform/platform-fuchsia.cc
index 83a8a23c48..38a7070e85 100644
--- a/deps/v8/src/base/platform/platform-fuchsia.cc
+++ b/deps/v8/src/base/platform/platform-fuchsia.cc
@@ -124,12 +124,11 @@ bool OS::HasLazyCommits() {
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
- CHECK(false); // TODO(scottmg): Port, https://crbug.com/731217.
- return std::vector<SharedLibraryAddress>();
+ UNREACHABLE(); // TODO(scottmg): Port, https://crbug.com/731217.
}
void OS::SignalCodeMovingGC() {
- CHECK(false); // TODO(scottmg): Port, https://crbug.com/731217.
+ UNREACHABLE(); // TODO(scottmg): Port, https://crbug.com/731217.
}
} // namespace base
diff --git a/deps/v8/src/base/platform/platform-posix.cc b/deps/v8/src/base/platform/platform-posix.cc
index b873197d3b..5edbd7648b 100644
--- a/deps/v8/src/base/platform/platform-posix.cc
+++ b/deps/v8/src/base/platform/platform-posix.cc
@@ -89,6 +89,7 @@ const char* g_gc_fake_mmap = nullptr;
static LazyInstance<RandomNumberGenerator>::type
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
+static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
#if !V8_OS_FUCHSIA
#if V8_OS_MACOSX
@@ -130,11 +131,9 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
}
void* Allocate(void* address, size_t size, OS::MemoryPermission access) {
- const size_t actual_size = RoundUp(size, OS::AllocatePageSize());
int prot = GetProtectionFromMemoryPermission(access);
int flags = GetFlagsForMemoryPermission(access);
- void* result =
- mmap(address, actual_size, prot, flags, kMmapFd, kMmapFdOffset);
+ void* result = mmap(address, size, prot, flags, kMmapFd, kMmapFdOffset);
if (result == MAP_FAILED) return nullptr;
return result;
}
@@ -167,11 +166,7 @@ int ReclaimInaccessibleMemory(void* address, size_t size) {
} // namespace
-void OS::Initialize(int64_t random_seed, bool hard_abort,
- const char* const gc_fake_mmap) {
- if (random_seed) {
- platform_random_number_generator.Pointer()->SetSeed(random_seed);
- }
+void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
g_hard_abort = hard_abort;
g_gc_fake_mmap = gc_fake_mmap;
}
@@ -207,45 +202,60 @@ size_t OS::CommitPageSize() {
}
// static
+void OS::SetRandomMmapSeed(int64_t seed) {
+ if (seed) {
+ LockGuard<Mutex> guard(rng_mutex.Pointer());
+ platform_random_number_generator.Pointer()->SetSeed(seed);
+ }
+}
+
+// static
void* OS::GetRandomMmapAddr() {
-#if defined(ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
- defined(THREAD_SANITIZER)
- // Dynamic tools do not support custom mmap addresses.
- return nullptr;
-#endif
uintptr_t raw_addr;
- platform_random_number_generator.Pointer()->NextBytes(&raw_addr,
- sizeof(raw_addr));
+ {
+ LockGuard<Mutex> guard(rng_mutex.Pointer());
+ platform_random_number_generator.Pointer()->NextBytes(&raw_addr,
+ sizeof(raw_addr));
+ }
+#if defined(V8_USE_ADDRESS_SANITIZER) || defined(MEMORY_SANITIZER) || \
+ defined(THREAD_SANITIZER) || defined(LEAK_SANITIZER)
+ // If random hint addresses interfere with address ranges hard coded in
+ // sanitizers, bad things happen. This address range is copied from TSAN
+ // source but works with all tools.
+ // See crbug.com/539863.
+ raw_addr &= 0x007fffff0000ULL;
+ raw_addr += 0x7e8000000000ULL;
+#else
#if V8_TARGET_ARCH_X64
// Currently available CPUs have 48 bits of virtual addressing. Truncate
// the hint address to 46 bits to give the kernel a fighting chance of
// fulfilling our placement request.
- raw_addr &= V8_UINT64_C(0x3ffffffff000);
+ raw_addr &= uint64_t{0x3FFFFFFFF000};
#elif V8_TARGET_ARCH_PPC64
#if V8_OS_AIX
// AIX: 64 bits of virtual addressing, but we limit address range to:
// a) minimize Segment Lookaside Buffer (SLB) misses and
- raw_addr &= V8_UINT64_C(0x3ffff000);
+ raw_addr &= uint64_t{0x3FFFF000};
// Use extra address space to isolate the mmap regions.
- raw_addr += V8_UINT64_C(0x400000000000);
+ raw_addr += uint64_t{0x400000000000};
#elif V8_TARGET_BIG_ENDIAN
// Big-endian Linux: 44 bits of virtual addressing.
- raw_addr &= V8_UINT64_C(0x03fffffff000);
+ raw_addr &= uint64_t{0x03FFFFFFF000};
#else
// Little-endian Linux: 48 bits of virtual addressing.
- raw_addr &= V8_UINT64_C(0x3ffffffff000);
+ raw_addr &= uint64_t{0x3FFFFFFFF000};
#endif
#elif V8_TARGET_ARCH_S390X
// Linux on Z uses bits 22-32 for Region Indexing, which translates to 42 bits
// of virtual addressing. Truncate to 40 bits to allow kernel chance to
// fulfill request.
- raw_addr &= V8_UINT64_C(0xfffffff000);
+ raw_addr &= uint64_t{0xFFFFFFF000};
#elif V8_TARGET_ARCH_S390
// 31 bits of virtual addressing. Truncate to 29 bits to allow kernel chance
// to fulfill request.
- raw_addr &= 0x1ffff000;
+ raw_addr &= 0x1FFFF000;
#else
- raw_addr &= 0x3ffff000;
+ raw_addr &= 0x3FFFF000;
#ifdef __sun
// For our Solaris/illumos mmap hint, we pick a random address in the bottom
@@ -269,6 +279,7 @@ void* OS::GetRandomMmapAddr() {
raw_addr += 0x20000000;
#endif
#endif
+#endif
return reinterpret_cast<void*>(raw_addr);
}
@@ -283,6 +294,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
address = AlignedAddress(address, alignment);
// Add the maximum misalignment so we are guaranteed an aligned base address.
size_t request_size = size + (alignment - page_size);
+ request_size = RoundUp(request_size, OS::AllocatePageSize());
void* result = base::Allocate(address, request_size, access);
if (result == nullptr) return nullptr;
diff --git a/deps/v8/src/base/platform/platform-win32.cc b/deps/v8/src/base/platform/platform-win32.cc
index e026d7edae..22580cc407 100644
--- a/deps/v8/src/base/platform/platform-win32.cc
+++ b/deps/v8/src/base/platform/platform-win32.cc
@@ -674,8 +674,15 @@ void OS::StrNCpy(char* dest, int length, const char* src, size_t n) {
#undef _TRUNCATE
#undef STRUNCATE
-// The allocation alignment is the guaranteed alignment for
-// VirtualAlloc'ed blocks of memory.
+static LazyInstance<RandomNumberGenerator>::type
+ platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
+static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
+
+void OS::Initialize(bool hard_abort, const char* const gc_fake_mmap) {
+ g_hard_abort = hard_abort;
+}
+
+// static
size_t OS::AllocatePageSize() {
static size_t allocate_alignment = 0;
if (allocate_alignment == 0) {
@@ -686,6 +693,7 @@ size_t OS::AllocatePageSize() {
return allocate_alignment;
}
+// static
size_t OS::CommitPageSize() {
static size_t page_size = 0;
if (page_size == 0) {
@@ -697,17 +705,15 @@ size_t OS::CommitPageSize() {
return page_size;
}
-static LazyInstance<RandomNumberGenerator>::type
- platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
-
-void OS::Initialize(int64_t random_seed, bool hard_abort,
- const char* const gc_fake_mmap) {
- if (random_seed) {
- platform_random_number_generator.Pointer()->SetSeed(random_seed);
+// static
+void OS::SetRandomMmapSeed(int64_t seed) {
+ if (seed) {
+ LockGuard<Mutex> guard(rng_mutex.Pointer());
+ platform_random_number_generator.Pointer()->SetSeed(seed);
}
- g_hard_abort = hard_abort;
}
+// static
void* OS::GetRandomMmapAddr() {
// The address range used to randomize RWX allocations in OS::Allocate
// Try not to map pages into the default range that windows loads DLLs
@@ -722,8 +728,11 @@ void* OS::GetRandomMmapAddr() {
static const uintptr_t kAllocationRandomAddressMax = 0x3FFF0000;
#endif
uintptr_t address;
- platform_random_number_generator.Pointer()->NextBytes(&address,
- sizeof(address));
+ {
+ LockGuard<Mutex> guard(rng_mutex.Pointer());
+ platform_random_number_generator.Pointer()->NextBytes(&address,
+ sizeof(address));
+ }
address <<= kPageSizeBits;
address += kAllocationRandomAddressMin;
address &= kAllocationRandomAddressMax;
diff --git a/deps/v8/src/base/platform/platform.h b/deps/v8/src/base/platform/platform.h
index dd454ecd43..8a4545c607 100644
--- a/deps/v8/src/base/platform/platform.h
+++ b/deps/v8/src/base/platform/platform.h
@@ -36,6 +36,7 @@
#endif
namespace v8 {
+
namespace base {
// ----------------------------------------------------------------------------
@@ -93,10 +94,9 @@ inline intptr_t InternalGetExistingThreadLocal(intptr_t index) {
#endif // V8_NO_FAST_TLS
-
+class PageAllocator;
class TimezoneCache;
-
// ----------------------------------------------------------------------------
// OS
//
@@ -107,11 +107,9 @@ class TimezoneCache;
class V8_BASE_EXPORT OS {
public:
// Initialize the OS class.
- // - random_seed: Used for the GetRandomMmapAddress() if non-zero.
// - hard_abort: If true, OS::Abort() will crash instead of aborting.
// - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof.
- static void Initialize(int64_t random_seed, bool hard_abort,
- const char* const gc_fake_mmap);
+ static void Initialize(bool hard_abort, const char* const gc_fake_mmap);
// Returns the accumulated user time for thread. This routine
// can be used for profiling. The implementation should
@@ -157,6 +155,8 @@ class V8_BASE_EXPORT OS {
static PRINTF_FORMAT(1, 2) void PrintError(const char* format, ...);
static PRINTF_FORMAT(1, 0) void VPrintError(const char* format, va_list args);
+ // Memory permissions. These should be kept in sync with the ones in
+ // v8::PageAllocator.
enum class MemoryPermission {
kNoAccess,
kReadWrite,
@@ -165,40 +165,6 @@ class V8_BASE_EXPORT OS {
kReadExecute
};
- // Gets the page granularity for Allocate. Addresses returned by Allocate are
- // aligned to this size.
- static size_t AllocatePageSize();
-
- // Gets the granularity at which the permissions and commit calls can be made.
- static size_t CommitPageSize();
-
- // Generate a random address to be used for hinting allocation calls.
- static void* GetRandomMmapAddr();
-
- // Allocates memory. Permissions are set according to the access argument.
- // The address parameter is a hint. The size and alignment parameters must be
- // multiples of AllocatePageSize(). Returns the address of the allocated
- // memory, with the specified size and alignment, or nullptr on failure.
- V8_WARN_UNUSED_RESULT static void* Allocate(void* address, size_t size,
- size_t alignment,
- MemoryPermission access);
-
- // Frees memory allocated by a call to Allocate. address and size must be
- // multiples of AllocatePageSize(). Returns true on success, otherwise false.
- V8_WARN_UNUSED_RESULT static bool Free(void* address, const size_t size);
-
- // Releases memory that is no longer needed. The range specified by address
- // and size must be part of an allocated memory region, and must be multiples
- // of CommitPageSize(). Released memory is left in an undefined state, so it
- // should not be accessed. Returns true on success, otherwise false.
- V8_WARN_UNUSED_RESULT static bool Release(void* address, size_t size);
-
- // Sets permissions according to the access argument. address and size must be
- // multiples of CommitPageSize(). Setting permission to kNoAccess may cause
- // the memory contents to be lost. Returns true on success, otherwise false.
- V8_WARN_UNUSED_RESULT static bool SetPermissions(void* address, size_t size,
- MemoryPermission access);
-
static bool HasLazyCommits();
// Sleep for a specified time interval.
@@ -280,6 +246,30 @@ class V8_BASE_EXPORT OS {
static int GetCurrentThreadId();
private:
+ // These classes use the private memory management API below.
+ friend class MemoryMappedFile;
+ friend class PosixMemoryMappedFile;
+ friend class v8::base::PageAllocator;
+
+ static size_t AllocatePageSize();
+
+ static size_t CommitPageSize();
+
+ static void SetRandomMmapSeed(int64_t seed);
+
+ static void* GetRandomMmapAddr();
+
+ V8_WARN_UNUSED_RESULT static void* Allocate(void* address, size_t size,
+ size_t alignment,
+ MemoryPermission access);
+
+ V8_WARN_UNUSED_RESULT static bool Free(void* address, const size_t size);
+
+ V8_WARN_UNUSED_RESULT static bool Release(void* address, size_t size);
+
+ V8_WARN_UNUSED_RESULT static bool SetPermissions(void* address, size_t size,
+ MemoryPermission access);
+
static const int msPerSecond = 1000;
#if V8_OS_POSIX
diff --git a/deps/v8/src/base/platform/semaphore.cc b/deps/v8/src/base/platform/semaphore.cc
index 9a7ef7a8f4..5950664523 100644
--- a/deps/v8/src/base/platform/semaphore.cc
+++ b/deps/v8/src/base/platform/semaphore.cc
@@ -136,7 +136,7 @@ bool Semaphore::WaitFor(const TimeDelta& rel_time) {
Semaphore::Semaphore(int count) {
DCHECK_GE(count, 0);
- native_handle_ = ::CreateSemaphoreA(nullptr, count, 0x7fffffff, nullptr);
+ native_handle_ = ::CreateSemaphoreA(nullptr, count, 0x7FFFFFFF, nullptr);
DCHECK_NOT_NULL(native_handle_);
}
diff --git a/deps/v8/src/base/platform/time.cc b/deps/v8/src/base/platform/time.cc
index 3529d55875..1fcd7aecce 100644
--- a/deps/v8/src/base/platform/time.cc
+++ b/deps/v8/src/base/platform/time.cc
@@ -298,8 +298,7 @@ Time Time::NowFromSystemTime() {
// Time between windows epoch and standard epoch.
-static const int64_t kTimeToEpochInMicroseconds = V8_INT64_C(11644473600000000);
-
+static const int64_t kTimeToEpochInMicroseconds = int64_t{11644473600000000};
Time Time::FromFiletime(FILETIME ft) {
if (ft.dwLowDateTime == 0 && ft.dwHighDateTime == 0) {