5#ifndef V8_BASE_PLATFORM_PLATFORM_H_
6#define V8_BASE_PLATFORM_PLATFORM_H_
37#include "testing/gtest/include/gtest/gtest_prod.h"
48#include <zircon/types.h>
51#ifdef V8_USE_ADDRESS_SANITIZER
52#include <sanitizer/asan_interface.h>
56#if V8_CC_MSVC && V8_HOST_ARCH_IA32
62extern "C" unsigned long __readfsdword(
unsigned long);
67#define PERMISSION_MUTABLE_SECTION __attribute__((section(".openbsd.mutable")))
69#define PERMISSION_MUTABLE_SECTION
83#if V8_CC_MSVC && V8_HOST_ARCH_IA32
85#define V8_FAST_TLS_SUPPORTED 1
87V8_INLINE intptr_t InternalGetExistingThreadLocal(intptr_t index) {
88 const intptr_t kTibInlineTlsOffset = 0xE10;
89 const intptr_t kTibExtraTlsOffset = 0xF94;
90 const intptr_t kMaxInlineSlots = 64;
91 const intptr_t kMaxSlots = kMaxInlineSlots + 1024;
92 const intptr_t kSystemPointerSize =
sizeof(
void*);
93 DCHECK(0 <= index && index < kMaxSlots);
95 if (index < kMaxInlineSlots) {
96 return static_cast<intptr_t
>(
97 __readfsdword(kTibInlineTlsOffset + kSystemPointerSize * index));
99 intptr_t extra =
static_cast<intptr_t
>(__readfsdword(kTibExtraTlsOffset));
100 if (!extra)
return 0;
102 (index - kMaxInlineSlots));
107#elif defined(__APPLE__) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64)
110#if !defined(V8_OS_STARBOARD) || !defined(TARGET_OS_SIMULATOR)
112#define V8_FAST_TLS_SUPPORTED 1
114V8_INLINE intptr_t InternalGetExistingThreadLocal(intptr_t index) {
117 asm(
"movl %%gs:(,%1,4), %0;"
121 asm(
"movq %%gs:(,%1,8), %0;" :
"=r"(
result) :
"r"(
index));
132class AddressSpaceReservation;
135class VirtualAddressSpace;
136class VirtualAddressSubspace;
150 static void Initialize(
AbortMode abort_mode,
const char*
const gc_fake_mmap);
160 static void EnsureWin32MemoryAPILoaded();
164 static bool IsHardwareEnforcedShadowStacksEnabled();
170 static int GetUserTime(uint32_t* secs, uint32_t* usecs);
173 static int GetPeakMemoryUsageKb();
177 static double TimeCurrentMillis();
182 static int GetLastError();
184 static FILE* FOpen(
const char* path,
const char* mode);
185 static bool Remove(
const char* path);
187 static char DirectorySeparator();
188 static bool isDirectorySeparator(
const char ch);
191 static FILE* OpenTemporaryFile();
223 kNoAccessWillJitLater
231 static bool HasLazyCommits();
237 [[noreturn]]
static void Abort();
240 static void DebugBreak();
243 static const int kStackWalkError = -1;
244 static const int kStackWalkMaxNameLen = 256;
245 static const int kStackWalkMaxTextLen = 256;
248 char text[kStackWalkMaxTextLen];
257 virtual size_t size()
const = 0;
260 FileMode mode = FileMode::kReadWrite);
268 const
char* format, ...);
270 const
char* format, va_list
args);
272 static
void StrNCpy(
char* dest,
int length, const
char* src,
size_t n);
281 uintptr_t
end, intptr_t aslr_slide)
282 : library_path(library_path),
285 aslr_slide(aslr_slide) {}
299 static void SignalCodeMovingGC();
307 static int ActivationFrameAlignment();
309 static int GetCurrentProcessId();
311 static int GetCurrentThreadId();
313 static void AdjustSchedulingParams();
325 static std::optional<MemoryRange> GetFirstFreeMemoryRangeWithin(
326 Address boundary_start,
Address boundary_end,
size_t minimum_size,
329 [[noreturn]]
static void ExitProcess(
int exit_code);
334#if (defined(V8_OS_MACOS) || defined(V8_OS_LINUX)) && \
335 !(defined(V8_TARGET_ARCH_PPC64) || defined(V8_TARGET_ARCH_S390X))
355 MemoryPermission access);
358 static void SetDataReadOnly(
void* address,
size_t size);
361 static int GetCurrentThreadIdInternal();
372 static size_t AllocatePageSize();
374 static size_t CommitPageSize();
376 static void SetRandomMmapSeed(int64_t seed);
378 static void* GetRandomMmapAddr();
391 static void Free(
void* address,
size_t size);
397 static void FreeShared(
void* address,
size_t size);
399 static void Release(
void* address,
size_t size);
417 CreateAddressSpaceReservation(
void* hint,
size_t size,
size_t alignment,
422 static const int msPerSecond = 1000;
425 static const char* GetGCFakeMMapFile();
431#if defined(V8_OS_WIN)
436#if defined(V8_OS_WIN)
439 EnsureConsoleOutputWin32();
459 bool Contains(
void* region_addr,
size_t region_size)
const {
462 return (region_base >=
base) &&
463 ((region_base + region_size) <= (
base +
size_));
489 CreateSubReservation(
void* address,
size_t size,
521 zx_handle_t vmar_ = ZX_HANDLE_INVALID;
551 explicit Options(
const char* name,
int stack_size = 0)
554 :
name_(name), priority_(
priority), stack_size_(stack_size) {}
578 if (!Start())
return false;
579 start_semaphore_->Wait();
580 delete start_semaphore_;
581 start_semaphore_ =
nullptr;
588 inline const char*
name()
const {
601 return GetThreadLocal(
key) !=
nullptr;
604#ifdef V8_FAST_TLS_SUPPORTED
605 static inline void* GetExistingThreadLocal(LocalStorageKey
key) {
606 void*
result =
reinterpret_cast<void*
>(
607 InternalGetExistingThreadLocal(
static_cast<intptr_t
>(
key)));
613 return GetThreadLocal(
key);
619 static const int kMaxThreadNameLength = 16;
626 if (start_semaphore_) start_semaphore_->Signal();
631 void set_name(
const char* name);
648 StackSlot(
void* value) : value(reinterpret_cast<uintptr_t>(value)) {}
652 operator void*()
const {
return reinterpret_cast<void*
>(
value); }
653 operator uintptr_t()
const {
return value; }
672 return _AddressOfReturnAddress();
674 return __builtin_frame_address(0);
681#ifdef V8_USE_ADDRESS_SANITIZER
686 constexpr size_t kAsanRealFrameOffsetBytes = 32;
687 void* real_frame = __asan_addr_is_in_fake_stack(
688 __asan_get_current_fake_stack(), slot,
nullptr,
nullptr);
689 return real_frame ?
StackSlot(
static_cast<char*
>(real_frame) +
690 kAsanRealFrameOffsetBytes)
698 static StackSlot GetStackStartUnchecked();
704#if V8_HAS_PTHREAD_JIT_WRITE_PROTECT
uint8_t data_[MAX_STACK_LENGTH]
bool Contains(void *region_addr, size_t region_size) const
AddressSpaceReservation(void *base, size_t size)
virtual ~MemoryMappedFile()=default
virtual size_t size() const =0
virtual void * memory() const =0
static bool ArmUsingHardFloat()
static const char *const LogFileOpenMode
static V8_WARN_UNUSED_RESULT constexpr bool IsRemapPageSupported()
FRIEND_TEST(OS, RemapPages)
DISALLOW_IMPLICIT_CONSTRUCTORS(OS)
static PRINTF_FORMAT(1, 2) void Print(const char *format
static V8_INLINE StackSlot GetCurrentFrameAddress()
static StackSlot GetRealStackAddressForSlot(StackSlot slot)
Options(const char *name, Priority priority, int stack_size=0)
const char * name() const
Priority priority() const
Options(const char *name, int stack_size=0)
Thread & operator=(const Thread &)=delete
Semaphore * start_semaphore_
Thread(const Thread &)=delete
Priority priority() const
bool StartSynchronously()
static void * GetExistingThreadLocal(LocalStorageKey key)
static bool HasThreadLocal(LocalStorageKey key)
const char * name() const
void NotifyStartedAndRun()
base::Vector< const DirectHandle< Object > > args
ZoneVector< RpoNumber > & result
v8::PageAllocator PageAllocator
void * Allocate(void *address, size_t size, OS::MemoryPermission access)
std::vector< OS::SharedLibraryAddress > GetSharedLibraryAddresses(FILE *fp)
void EnsureConsoleOutput()
constexpr int kSystemPointerSize
intptr_t PlatformSharedMemoryHandle
#define PRINTF_FORMAT(format_param, dots_param)
#define DCHECK(condition)
SharedLibraryAddress(const std::string &library_path, uintptr_t start, uintptr_t end)
SharedLibraryAddress(const std::string &library_path, uintptr_t start, uintptr_t end, intptr_t aslr_slide)
StackSlot(uintptr_t value)
#define V8_WARN_UNUSED_RESULT
std::unique_ptr< ValueMirror > value
std::unique_ptr< ValueMirror > key