6#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX) || \
7 defined(DART_HOST_OS_MACOS)
15#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
28#define MAP_FAILED reinterpret_cast<void*>(-1)
30uword VirtualMemory::page_size_ = 0;
32intptr_t VirtualMemory::CalculatePageSize() {
33 const intptr_t page_size = getpagesize();
44 const int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
46 int map_flags = MAP_PRIVATE | MAP_ANONYMOUS;
47#if (defined(DART_HOST_OS_MACOS) && !defined(DART_HOST_OS_IOS))
48 if (is_executable && IsAtLeastOS10_14()) {
58 void* hint = is_executable ?
reinterpret_cast<void*
>(&
Allocate) : nullptr;
59 void*
address = mmap(hint,
size, prot, map_flags, -1, 0);
60#if defined(DART_HOST_OS_LINUX)
66 if (
address == MAP_FAILED && hint !=
nullptr &&
67 Utils::IsWindowsSubsystemForLinux()) {
68 address = mmap(
nullptr,
size, prot, map_flags, -1, 0);
75#if defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_LINUX)
78#if !defined(PR_SET_VMA)
79#define PR_SET_VMA 0x53564d41
81#if !defined(PR_SET_VMA_ANON_NAME)
82#define PR_SET_VMA_ANON_NAME 0
91 if (address_ !=
nullptr) {
92 if (munmap(address_, size_) != 0) {
104 uword end_address = start_address +
size;
115 prot = PROT_READ | PROT_WRITE;
118 prot = PROT_READ | PROT_EXEC;
121 prot = PROT_READ | PROT_WRITE | PROT_EXEC;
124 if (mprotect(
reinterpret_cast<void*
>(page_address),
125 end_address - page_address, prot) != 0) {
static const size_t kBufferSize
static char * StrError(int err, char *buffer, size_t bufsize)
static constexpr T RoundDown(T x, intptr_t alignment)
static constexpr bool IsAligned(T x, uintptr_t alignment, uintptr_t offset=0)
static constexpr bool IsPowerOfTwo(T x)
static VirtualMemory * Allocate(intptr_t size, bool is_executable, const char *name)
static void Protect(void *address, intptr_t size, Protection mode)
static intptr_t PageSize()
const uint8_t uint32_t uint32_t GError ** error