зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset f48cb748519b (bug 1701620) for bustage on Memory.cpp. CLOSED TREE
This commit is contained in:
Родитель
4e5ae46c03
Коммит
91bd333c25
|
@ -11,8 +11,6 @@
|
||||||
|
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
# include "util/Windows.h"
|
# include "util/Windows.h"
|
||||||
#elif defined(__wasi__)
|
|
||||||
// Nothing.
|
|
||||||
#elif defined(XP_UNIX) && !defined(XP_DARWIN)
|
#elif defined(XP_UNIX) && !defined(XP_DARWIN)
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
|
@ -123,8 +121,6 @@ bool MemoryProtectionExceptionHandler::isDisabled() {
|
||||||
#elif !defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
|
#elif !defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED)
|
||||||
// Disable the exception handler for Beta and Release builds.
|
// Disable the exception handler for Beta and Release builds.
|
||||||
return true;
|
return true;
|
||||||
#elif defined(__wasi__)
|
|
||||||
return true;
|
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -236,12 +232,6 @@ void MemoryProtectionExceptionHandler::uninstall() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__wasi__)
|
|
||||||
|
|
||||||
bool MemoryProtectionExceptionHandler::install() { return true; }
|
|
||||||
|
|
||||||
void MemoryProtectionExceptionHandler::uninstall() {}
|
|
||||||
|
|
||||||
#elif defined(XP_UNIX) && !defined(XP_DARWIN)
|
#elif defined(XP_UNIX) && !defined(XP_DARWIN)
|
||||||
|
|
||||||
static struct sigaction sPrevSEGVHandler = {};
|
static struct sigaction sPrevSEGVHandler = {};
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#if !defined(XP_WIN) && !defined(__wasi__)
|
#ifndef XP_WIN
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,10 +20,6 @@
|
||||||
# include "util/Windows.h"
|
# include "util/Windows.h"
|
||||||
# include <psapi.h>
|
# include <psapi.h>
|
||||||
|
|
||||||
#elif defined(__wasi__)
|
|
||||||
|
|
||||||
/* nothing */
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
# include <algorithm>
|
# include <algorithm>
|
||||||
|
@ -144,15 +140,6 @@ enum class PageAccess : DWORD {
|
||||||
ReadExecute = PAGE_EXECUTE_READ,
|
ReadExecute = PAGE_EXECUTE_READ,
|
||||||
ReadWriteExecute = PAGE_EXECUTE_READWRITE,
|
ReadWriteExecute = PAGE_EXECUTE_READWRITE,
|
||||||
};
|
};
|
||||||
#elif defined(__wasi__)
|
|
||||||
enum class PageAccess : int {
|
|
||||||
None = 0,
|
|
||||||
Read = 0,
|
|
||||||
ReadWrite = 0,
|
|
||||||
Execute = 0,
|
|
||||||
ReadExecute = 0,
|
|
||||||
ReadWriteExecute = 0,
|
|
||||||
};
|
|
||||||
#else
|
#else
|
||||||
enum class PageAccess : int {
|
enum class PageAccess : int {
|
||||||
None = PROT_NONE,
|
None = PROT_NONE,
|
||||||
|
@ -168,9 +155,7 @@ template <bool AlwaysGetNew = true>
|
||||||
static bool TryToAlignChunk(void** aRegion, void** aRetainedRegion,
|
static bool TryToAlignChunk(void** aRegion, void** aRetainedRegion,
|
||||||
size_t length, size_t alignment);
|
size_t length, size_t alignment);
|
||||||
|
|
||||||
#ifndef __wasi__
|
|
||||||
static void* MapAlignedPagesSlow(size_t length, size_t alignment);
|
static void* MapAlignedPagesSlow(size_t length, size_t alignment);
|
||||||
#endif // wasi
|
|
||||||
static void* MapAlignedPagesLastDitch(size_t length, size_t alignment);
|
static void* MapAlignedPagesLastDitch(size_t length, size_t alignment);
|
||||||
|
|
||||||
#ifdef JS_64BIT
|
#ifdef JS_64BIT
|
||||||
|
@ -195,14 +180,6 @@ static inline void* MapInternal(void* desired, size_t length) {
|
||||||
DWORD flags =
|
DWORD flags =
|
||||||
(commit == Commit::Yes ? MEM_RESERVE | MEM_COMMIT : MEM_RESERVE);
|
(commit == Commit::Yes ? MEM_RESERVE | MEM_COMMIT : MEM_RESERVE);
|
||||||
region = VirtualAlloc(desired, length, flags, DWORD(prot));
|
region = VirtualAlloc(desired, length, flags, DWORD(prot));
|
||||||
#elif defined(__wasi__)
|
|
||||||
if (int err = posix_memalign(®ion, gc::SystemPageSize(), length)) {
|
|
||||||
MOZ_RELEASE_ASSERT(err == ENOMEM);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (region) {
|
|
||||||
memset(region, 0, length);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
int flags = MAP_PRIVATE | MAP_ANON;
|
int flags = MAP_PRIVATE | MAP_ANON;
|
||||||
region = MozTaggedAnonymousMmap(desired, length, int(prot), flags, -1, 0,
|
region = MozTaggedAnonymousMmap(desired, length, int(prot), flags, -1, 0,
|
||||||
|
@ -220,8 +197,6 @@ static inline void UnmapInternal(void* region, size_t length) {
|
||||||
|
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
MOZ_RELEASE_ASSERT(VirtualFree(region, 0, MEM_RELEASE) != 0);
|
MOZ_RELEASE_ASSERT(VirtualFree(region, 0, MEM_RELEASE) != 0);
|
||||||
#elif defined(__wasi__)
|
|
||||||
free(region);
|
|
||||||
#else
|
#else
|
||||||
if (munmap(region, length)) {
|
if (munmap(region, length)) {
|
||||||
MOZ_RELEASE_ASSERT(errno == ENOMEM);
|
MOZ_RELEASE_ASSERT(errno == ENOMEM);
|
||||||
|
@ -432,18 +407,7 @@ void* MapAlignedPages(size_t length, size_t alignment) {
|
||||||
alignment = allocGranularity;
|
alignment = allocGranularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __wasi__
|
#ifdef JS_64BIT
|
||||||
void* region = nullptr;
|
|
||||||
if (int err = posix_memalign(®ion, alignment, length)) {
|
|
||||||
MOZ_ASSERT(err == ENOMEM);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
MOZ_ASSERT(region != nullptr);
|
|
||||||
memset(region, 0, length);
|
|
||||||
return region;
|
|
||||||
#else
|
|
||||||
|
|
||||||
# ifdef JS_64BIT
|
|
||||||
// Use the scattershot allocator if the address range is large enough.
|
// Use the scattershot allocator if the address range is large enough.
|
||||||
if (UsingScattershotAllocator()) {
|
if (UsingScattershotAllocator()) {
|
||||||
void* region = MapAlignedPagesRandom(length, alignment);
|
void* region = MapAlignedPagesRandom(length, alignment);
|
||||||
|
@ -453,7 +417,7 @@ void* MapAlignedPages(size_t length, size_t alignment) {
|
||||||
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
// Try to allocate the region. If the returned address is aligned,
|
// Try to allocate the region. If the returned address is aligned,
|
||||||
// either we OOMed (region is nullptr) or we're done.
|
// either we OOMed (region is nullptr) or we're done.
|
||||||
|
@ -496,7 +460,6 @@ void* MapAlignedPages(size_t length, size_t alignment) {
|
||||||
// At this point we should either have an aligned region or nullptr.
|
// At this point we should either have an aligned region or nullptr.
|
||||||
MOZ_ASSERT(OffsetFromAligned(region, alignment) == 0);
|
MOZ_ASSERT(OffsetFromAligned(region, alignment) == 0);
|
||||||
return region;
|
return region;
|
||||||
#endif // !__wasi__
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef JS_64BIT
|
#ifdef JS_64BIT
|
||||||
|
@ -583,28 +546,27 @@ static void* MapAlignedPagesRandom(size_t length, size_t alignment) {
|
||||||
|
|
||||||
#endif // defined(JS_64BIT)
|
#endif // defined(JS_64BIT)
|
||||||
|
|
||||||
#ifndef __wasi__
|
|
||||||
static void* MapAlignedPagesSlow(size_t length, size_t alignment) {
|
static void* MapAlignedPagesSlow(size_t length, size_t alignment) {
|
||||||
void* alignedRegion = nullptr;
|
void* alignedRegion = nullptr;
|
||||||
do {
|
do {
|
||||||
size_t reserveLength = length + alignment - pageSize;
|
size_t reserveLength = length + alignment - pageSize;
|
||||||
# ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
// Don't commit the requested pages as we won't use the region directly.
|
// Don't commit the requested pages as we won't use the region directly.
|
||||||
void* region = MapMemory<Commit::No>(reserveLength);
|
void* region = MapMemory<Commit::No>(reserveLength);
|
||||||
# else
|
#else
|
||||||
void* region = MapMemory(reserveLength);
|
void* region = MapMemory(reserveLength);
|
||||||
# endif
|
#endif
|
||||||
if (!region) {
|
if (!region) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
alignedRegion =
|
alignedRegion =
|
||||||
reinterpret_cast<void*>(AlignBytes(uintptr_t(region), alignment));
|
reinterpret_cast<void*>(AlignBytes(uintptr_t(region), alignment));
|
||||||
# ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
// Windows requires that map and unmap calls be matched, so deallocate
|
// Windows requires that map and unmap calls be matched, so deallocate
|
||||||
// and immediately reallocate at the desired (aligned) address.
|
// and immediately reallocate at the desired (aligned) address.
|
||||||
UnmapInternal(region, reserveLength);
|
UnmapInternal(region, reserveLength);
|
||||||
alignedRegion = MapMemoryAt(alignedRegion, length);
|
alignedRegion = MapMemoryAt(alignedRegion, length);
|
||||||
# else
|
#else
|
||||||
// munmap allows us to simply unmap the pages that don't interest us.
|
// munmap allows us to simply unmap the pages that don't interest us.
|
||||||
if (alignedRegion != region) {
|
if (alignedRegion != region) {
|
||||||
UnmapInternal(region, uintptr_t(alignedRegion) - uintptr_t(region));
|
UnmapInternal(region, uintptr_t(alignedRegion) - uintptr_t(region));
|
||||||
|
@ -616,13 +578,12 @@ static void* MapAlignedPagesSlow(size_t length, size_t alignment) {
|
||||||
if (alignedEnd != regionEnd) {
|
if (alignedEnd != regionEnd) {
|
||||||
UnmapInternal(alignedEnd, uintptr_t(regionEnd) - uintptr_t(alignedEnd));
|
UnmapInternal(alignedEnd, uintptr_t(regionEnd) - uintptr_t(alignedEnd));
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
// On Windows we may have raced with another thread; if so, try again.
|
// On Windows we may have raced with another thread; if so, try again.
|
||||||
} while (!alignedRegion);
|
} while (!alignedRegion);
|
||||||
|
|
||||||
return alignedRegion;
|
return alignedRegion;
|
||||||
}
|
}
|
||||||
#endif // wasi
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In a low memory or high fragmentation situation, alignable chunks of the
|
* In a low memory or high fragmentation situation, alignable chunks of the
|
||||||
|
@ -806,8 +767,6 @@ bool MarkPagesUnusedSoft(void* region, size_t length) {
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
return VirtualAlloc(region, length, MEM_RESET,
|
return VirtualAlloc(region, length, MEM_RESET,
|
||||||
DWORD(PageAccess::ReadWrite)) == region;
|
DWORD(PageAccess::ReadWrite)) == region;
|
||||||
#elif defined(__wasi__)
|
|
||||||
return 0;
|
|
||||||
#else
|
#else
|
||||||
int status;
|
int status;
|
||||||
do {
|
do {
|
||||||
|
@ -879,8 +838,6 @@ size_t GetPageFaultCount() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return pmc.PageFaultCount;
|
return pmc.PageFaultCount;
|
||||||
#elif defined(__wasi__)
|
|
||||||
return 0;
|
|
||||||
#else
|
#else
|
||||||
struct rusage usage;
|
struct rusage usage;
|
||||||
int err = getrusage(RUSAGE_SELF, &usage);
|
int err = getrusage(RUSAGE_SELF, &usage);
|
||||||
|
@ -893,9 +850,6 @@ size_t GetPageFaultCount() {
|
||||||
|
|
||||||
void* AllocateMappedContent(int fd, size_t offset, size_t length,
|
void* AllocateMappedContent(int fd, size_t offset, size_t length,
|
||||||
size_t alignment) {
|
size_t alignment) {
|
||||||
#ifdef __wasi__
|
|
||||||
MOZ_CRASH("Not yet supported for WASI");
|
|
||||||
#else
|
|
||||||
if (length == 0 || alignment == 0 || offset % alignment != 0 ||
|
if (length == 0 || alignment == 0 || offset % alignment != 0 ||
|
||||||
std::max(alignment, allocGranularity) %
|
std::max(alignment, allocGranularity) %
|
||||||
std::min(alignment, allocGranularity) !=
|
std::min(alignment, allocGranularity) !=
|
||||||
|
@ -913,7 +867,7 @@ void* AllocateMappedContent(int fd, size_t offset, size_t length,
|
||||||
mappedLength += pageSize - alignedLength % pageSize;
|
mappedLength += pageSize - alignedLength % pageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
HANDLE hFile = reinterpret_cast<HANDLE>(intptr_t(fd));
|
HANDLE hFile = reinterpret_cast<HANDLE>(intptr_t(fd));
|
||||||
|
|
||||||
// This call will fail if the file does not exist.
|
// This call will fail if the file does not exist.
|
||||||
|
@ -952,7 +906,7 @@ void* AllocateMappedContent(int fd, size_t offset, size_t length,
|
||||||
if (!map) {
|
if (!map) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
# else // !defined(XP_WIN)
|
#else // !defined(XP_WIN)
|
||||||
// Sanity check the offset and length, as mmap does not do this for us.
|
// Sanity check the offset and length, as mmap does not do this for us.
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (fstat(fd, &st) || offset >= uint64_t(st.st_size) ||
|
if (fstat(fd, &st) || offset >= uint64_t(st.st_size) ||
|
||||||
|
@ -974,9 +928,9 @@ void* AllocateMappedContent(int fd, size_t offset, size_t length,
|
||||||
UnmapInternal(region, mappedLength);
|
UnmapInternal(region, mappedLength);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
# ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Zero out data before and after the desired mapping to catch errors early.
|
// Zero out data before and after the desired mapping to catch errors early.
|
||||||
if (offset != alignedOffset) {
|
if (offset != alignedOffset) {
|
||||||
memset(map, 0, offset - alignedOffset);
|
memset(map, 0, offset - alignedOffset);
|
||||||
|
@ -984,37 +938,32 @@ void* AllocateMappedContent(int fd, size_t offset, size_t length,
|
||||||
if (alignedLength % pageSize) {
|
if (alignedLength % pageSize) {
|
||||||
memset(map + alignedLength, 0, pageSize - (alignedLength % pageSize));
|
memset(map + alignedLength, 0, pageSize - (alignedLength % pageSize));
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
|
|
||||||
return map + (offset - alignedOffset);
|
return map + (offset - alignedOffset);
|
||||||
#endif // __wasi__
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeallocateMappedContent(void* region, size_t length) {
|
void DeallocateMappedContent(void* region, size_t length) {
|
||||||
#ifdef __wasi__
|
|
||||||
MOZ_CRASH("Not yet supported for WASI");
|
|
||||||
#else
|
|
||||||
if (!region) {
|
if (!region) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Due to bug 1502562, the following assertion does not currently hold.
|
// Due to bug 1502562, the following assertion does not currently hold.
|
||||||
// MOZ_RELEASE_ASSERT(length > 0);
|
// MOZ_RELEASE_ASSERT(length > 0);
|
||||||
# ifdef XP_WIN
|
|
||||||
MOZ_RELEASE_ASSERT(UnmapViewOfFile(reinterpret_cast<void*>(map)) != 0);
|
|
||||||
# else
|
|
||||||
// Calculate the address originally returned by the system call.
|
// Calculate the address originally returned by the system call.
|
||||||
// This is needed because AllocateMappedContent returns a pointer
|
// This is needed because AllocateMappedContent returns a pointer
|
||||||
// that might be offset from the mapping, as the beginning of a
|
// that might be offset from the mapping, as the beginning of a
|
||||||
// mapping must be aligned with the allocation granularity.
|
// mapping must be aligned with the allocation granularity.
|
||||||
uintptr_t map = uintptr_t(region) - (uintptr_t(region) % allocGranularity);
|
uintptr_t map = uintptr_t(region) - (uintptr_t(region) % allocGranularity);
|
||||||
|
#ifdef XP_WIN
|
||||||
|
MOZ_RELEASE_ASSERT(UnmapViewOfFile(reinterpret_cast<void*>(map)) != 0);
|
||||||
|
#else
|
||||||
size_t alignedLength = length + (uintptr_t(region) % allocGranularity);
|
size_t alignedLength = length + (uintptr_t(region) % allocGranularity);
|
||||||
if (munmap(reinterpret_cast<void*>(map), alignedLength)) {
|
if (munmap(reinterpret_cast<void*>(map), alignedLength)) {
|
||||||
MOZ_RELEASE_ASSERT(errno == ENOMEM);
|
MOZ_RELEASE_ASSERT(errno == ENOMEM);
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
#endif // __wasi__
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ProtectMemory(void* region, size_t length, PageAccess prot) {
|
static inline void ProtectMemory(void* region, size_t length, PageAccess prot) {
|
||||||
|
@ -1024,8 +973,6 @@ static inline void ProtectMemory(void* region, size_t length, PageAccess prot) {
|
||||||
DWORD oldProtect;
|
DWORD oldProtect;
|
||||||
MOZ_RELEASE_ASSERT(VirtualProtect(region, length, DWORD(prot), &oldProtect) !=
|
MOZ_RELEASE_ASSERT(VirtualProtect(region, length, DWORD(prot), &oldProtect) !=
|
||||||
0);
|
0);
|
||||||
#elif defined(__wasi__)
|
|
||||||
/* nothing */
|
|
||||||
#else
|
#else
|
||||||
MOZ_RELEASE_ASSERT(mprotect(region, length, int(prot)) == 0);
|
MOZ_RELEASE_ASSERT(mprotect(region, length, int(prot)) == 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
# include "mozilla/StackWalk_windows.h"
|
# include "mozilla/StackWalk_windows.h"
|
||||||
# include "mozilla/WindowsVersion.h"
|
# include "mozilla/WindowsVersion.h"
|
||||||
#elif defined(__wasi__)
|
|
||||||
// Nothing.
|
|
||||||
#else
|
#else
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
@ -326,20 +324,7 @@ static void DecommitPages(void* addr, size_t bytes) {
|
||||||
MOZ_CRASH("DecommitPages failed");
|
MOZ_CRASH("DecommitPages failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(__wasi__)
|
#else // !XP_WIN
|
||||||
static void* ReserveProcessExecutableMemory(size_t bytes) {
|
|
||||||
MOZ_CRASH("NYI for WASI.");
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
[[nodiscard]] static bool CommitPages(void* addr, size_t bytes,
|
|
||||||
ProtectionSetting protection) {
|
|
||||||
MOZ_CRASH("NYI for WASI.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
static void DecommitPages(void* addr, size_t bytes) {
|
|
||||||
MOZ_CRASH("NYI for WASI.");
|
|
||||||
}
|
|
||||||
#else // !XP_WIN && !__wasi__
|
|
||||||
# ifndef MAP_NORESERVE
|
# ifndef MAP_NORESERVE
|
||||||
# define MAP_NORESERVE 0
|
# define MAP_NORESERVE 0
|
||||||
# endif
|
# endif
|
||||||
|
@ -571,9 +556,6 @@ class ProcessExecutableMemory {
|
||||||
}
|
}
|
||||||
|
|
||||||
void release() {
|
void release() {
|
||||||
#if defined(__wasi__)
|
|
||||||
MOZ_ASSERT(!initialized());
|
|
||||||
#else
|
|
||||||
MOZ_ASSERT(initialized());
|
MOZ_ASSERT(initialized());
|
||||||
MOZ_ASSERT(pages_.empty());
|
MOZ_ASSERT(pages_.empty());
|
||||||
MOZ_ASSERT(pagesAllocated_ == 0);
|
MOZ_ASSERT(pagesAllocated_ == 0);
|
||||||
|
@ -581,7 +563,6 @@ class ProcessExecutableMemory {
|
||||||
base_ = nullptr;
|
base_ = nullptr;
|
||||||
rng_.reset();
|
rng_.reset();
|
||||||
MOZ_ASSERT(!initialized());
|
MOZ_ASSERT(!initialized());
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void assertValidAddress(void* p, size_t bytes) const {
|
void assertValidAddress(void* p, size_t bytes) const {
|
||||||
|
@ -728,8 +709,6 @@ bool js::jit::InitProcessExecutableMemory() {
|
||||||
#ifdef JS_CODEGEN_ARM64
|
#ifdef JS_CODEGEN_ARM64
|
||||||
// Initialize instruction cache flushing.
|
// Initialize instruction cache flushing.
|
||||||
vixl::CPU::SetUp();
|
vixl::CPU::SetUp();
|
||||||
#elif defined(__wasi__)
|
|
||||||
return true;
|
|
||||||
#endif
|
#endif
|
||||||
return execMemory.init();
|
return execMemory.init();
|
||||||
}
|
}
|
||||||
|
@ -793,24 +772,20 @@ bool js::jit::ReprotectRegion(void* start, size_t size,
|
||||||
// We use the C++ fence here -- and not AtomicOperations::fenceSeqCst() --
|
// We use the C++ fence here -- and not AtomicOperations::fenceSeqCst() --
|
||||||
// primarily because ReprotectRegion will be called while we construct our own
|
// primarily because ReprotectRegion will be called while we construct our own
|
||||||
// jitted atomics. But the C++ fence is sufficient and correct, too.
|
// jitted atomics. But the C++ fence is sufficient and correct, too.
|
||||||
#ifdef __wasi__
|
|
||||||
MOZ_CRASH("NYI FOR WASI.");
|
|
||||||
#else
|
|
||||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||||
|
|
||||||
# ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
DWORD oldProtect;
|
DWORD oldProtect;
|
||||||
DWORD flags = ProtectionSettingToFlags(protection);
|
DWORD flags = ProtectionSettingToFlags(protection);
|
||||||
if (!VirtualProtect(pageStart, size, flags, &oldProtect)) {
|
if (!VirtualProtect(pageStart, size, flags, &oldProtect)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
# else
|
#else
|
||||||
unsigned flags = ProtectionSettingToFlags(protection);
|
unsigned flags = ProtectionSettingToFlags(protection);
|
||||||
if (mprotect(pageStart, size, flags)) {
|
if (mprotect(pageStart, size, flags)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
# endif
|
#endif
|
||||||
#endif // __wasi__
|
|
||||||
|
|
||||||
execMemory.assertValidAddress(pageStart, size);
|
execMemory.assertValidAddress(pageStart, size);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
# include "util/Windows.h"
|
# include "util/Windows.h"
|
||||||
# include <psapi.h>
|
# include <psapi.h>
|
||||||
#elif defined(__wasi__)
|
|
||||||
// Nothing.
|
|
||||||
#else
|
#else
|
||||||
# include <algorithm>
|
# include <algorithm>
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
|
@ -298,22 +296,6 @@ void unmapPages(void* p, size_t size) {
|
||||||
MOZ_ALWAYS_TRUE(VirtualFree(p, 0, MEM_RELEASE));
|
MOZ_ALWAYS_TRUE(VirtualFree(p, 0, MEM_RELEASE));
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__wasi__)
|
|
||||||
|
|
||||||
void* mapMemoryAt(void* desired, size_t length) { return nullptr; }
|
|
||||||
|
|
||||||
void* mapMemory(size_t length) {
|
|
||||||
void* addr = nullptr;
|
|
||||||
if (int err = posix_memalign(&addr, js::gc::SystemPageSize(), length)) {
|
|
||||||
MOZ_ASSERT(err == ENOMEM);
|
|
||||||
}
|
|
||||||
MOZ_ASSERT(addr);
|
|
||||||
memset(addr, 0, length);
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void unmapPages(void* p, size_t size) { free(p); }
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void* mapMemoryAt(void* desired, size_t length) {
|
void* mapMemoryAt(void* desired, size_t length) {
|
||||||
|
|
|
@ -1505,28 +1505,21 @@ JS_GetExternalStringCallbacks(JSString* str) {
|
||||||
|
|
||||||
static void SetNativeStackLimit(JSContext* cx, JS::StackKind kind,
|
static void SetNativeStackLimit(JSContext* cx, JS::StackKind kind,
|
||||||
size_t stackSize) {
|
size_t stackSize) {
|
||||||
#ifdef __wasi__
|
#if JS_STACK_GROWTH_DIRECTION > 0
|
||||||
// WASI makes this easy: we build with the "stack-first" wasm-ld option, so
|
|
||||||
// the stack grows downward toward zero. Let's set a limit just a bit above
|
|
||||||
// this so that we catch an overflow before a Wasm trap occurs.
|
|
||||||
cx->nativeStackLimit[kind] = 1024;
|
|
||||||
#else // __wasi__
|
|
||||||
# if JS_STACK_GROWTH_DIRECTION > 0
|
|
||||||
if (stackSize == 0) {
|
if (stackSize == 0) {
|
||||||
cx->nativeStackLimit[kind] = UINTPTR_MAX;
|
cx->nativeStackLimit[kind] = UINTPTR_MAX;
|
||||||
} else {
|
} else {
|
||||||
MOZ_ASSERT(cx->nativeStackBase() <= size_t(-1) - stackSize);
|
MOZ_ASSERT(cx->nativeStackBase() <= size_t(-1) - stackSize);
|
||||||
cx->nativeStackLimit[kind] = cx->nativeStackBase() + stackSize - 1;
|
cx->nativeStackLimit[kind] = cx->nativeStackBase() + stackSize - 1;
|
||||||
}
|
}
|
||||||
# else // stack grows up
|
#else
|
||||||
if (stackSize == 0) {
|
if (stackSize == 0) {
|
||||||
cx->nativeStackLimit[kind] = 0;
|
cx->nativeStackLimit[kind] = 0;
|
||||||
} else {
|
} else {
|
||||||
MOZ_ASSERT(cx->nativeStackBase() >= stackSize);
|
MOZ_ASSERT(cx->nativeStackBase() >= stackSize);
|
||||||
cx->nativeStackLimit[kind] = cx->nativeStackBase() - (stackSize - 1);
|
cx->nativeStackLimit[kind] = cx->nativeStackBase() - (stackSize - 1);
|
||||||
}
|
}
|
||||||
# endif // stack grows down
|
#endif
|
||||||
#endif // !__wasi__
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_PUBLIC_API void JS_SetNativeStackQuota(JSContext* cx,
|
JS_PUBLIC_API void JS_SetNativeStackQuota(JSContext* cx,
|
||||||
|
|
|
@ -47,11 +47,9 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#ifdef XP_UNIX
|
#ifdef XP_UNIX
|
||||||
# ifndef __wasi__
|
# include <sys/mman.h>
|
||||||
# include <sys/mman.h>
|
|
||||||
# include <sys/wait.h>
|
|
||||||
# endif
|
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
|
# include <sys/wait.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef XP_LINUX
|
#ifdef XP_LINUX
|
||||||
|
|
|
@ -10,8 +10,6 @@
|
||||||
|
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
# include "util/Windows.h"
|
# include "util/Windows.h"
|
||||||
#elif defined(__wasi__)
|
|
||||||
// Nothing
|
|
||||||
#elif defined(XP_DARWIN) || defined(DARWIN) || defined(XP_UNIX)
|
#elif defined(XP_DARWIN) || defined(DARWIN) || defined(XP_UNIX)
|
||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
# if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
# if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
||||||
|
@ -117,18 +115,7 @@ void* js::GetNativeStackBaseImpl() {
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__wasi__)
|
#else /* XP_UNIX */
|
||||||
|
|
||||||
// Since we rearrange the layout for wasi via --stack-first flag for the linker
|
|
||||||
// the final layout is: 0x00 | <- stack | data | heap -> |.
|
|
||||||
static void* NativeStackBase = __builtin_frame_address(0);
|
|
||||||
|
|
||||||
void* js::GetNativeStackBaseImpl() {
|
|
||||||
MOZ_ASSERT(JS_STACK_GROWTH_DIRECTION < 0);
|
|
||||||
return NativeStackBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // __wasi__
|
|
||||||
|
|
||||||
void* js::GetNativeStackBaseImpl() {
|
void* js::GetNativeStackBaseImpl() {
|
||||||
pthread_t thread = pthread_self();
|
pthread_t thread = pthread_self();
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <algorithm> // std::max, std::min
|
#include <algorithm> // std::max, std::min
|
||||||
#include <memory> // std::uninitialized_copy_n
|
#include <memory> // std::uninitialized_copy_n
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if !defined(XP_WIN) && !defined(__wasi__)
|
#ifndef XP_WIN
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
#include <tuple> // std::tuple
|
#include <tuple> // std::tuple
|
||||||
|
@ -180,15 +180,7 @@ void* js::MapBufferMemory(size_t mappedSize, size_t initialCommittedSize) {
|
||||||
VirtualFree(data, 0, MEM_RELEASE);
|
VirtualFree(data, 0, MEM_RELEASE);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
#elif defined(__wasi__)
|
#else // XP_WIN
|
||||||
void* data = nullptr;
|
|
||||||
if (int err = posix_memalign(&data, gc::SystemPageSize(), mappedSize)) {
|
|
||||||
MOZ_ASSERT(err == ENOMEM);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
MOZ_ASSERT(data);
|
|
||||||
memset(data, 0, mappedSize);
|
|
||||||
#else // !XP_WIN && !__wasi__
|
|
||||||
void* data =
|
void* data =
|
||||||
MozTaggedAnonymousMmap(nullptr, mappedSize, PROT_NONE,
|
MozTaggedAnonymousMmap(nullptr, mappedSize, PROT_NONE,
|
||||||
MAP_PRIVATE | MAP_ANON, -1, 0, "wasm-reserved");
|
MAP_PRIVATE | MAP_ANON, -1, 0, "wasm-reserved");
|
||||||
|
@ -201,7 +193,7 @@ void* js::MapBufferMemory(size_t mappedSize, size_t initialCommittedSize) {
|
||||||
munmap(data, mappedSize);
|
munmap(data, mappedSize);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
#endif // !XP_WIN && !__wasi__
|
#endif // !XP_WIN
|
||||||
|
|
||||||
#if defined(MOZ_VALGRIND) && \
|
#if defined(MOZ_VALGRIND) && \
|
||||||
defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
|
defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
|
||||||
|
@ -222,14 +214,11 @@ bool js::CommitBufferMemory(void* dataEnd, size_t delta) {
|
||||||
if (!VirtualAlloc(dataEnd, delta, MEM_COMMIT, PAGE_READWRITE)) {
|
if (!VirtualAlloc(dataEnd, delta, MEM_COMMIT, PAGE_READWRITE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#elif defined(__wasi__)
|
#else // XP_WIN
|
||||||
// posix_memalign'd memory is already committed
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
if (mprotect(dataEnd, delta, PROT_READ | PROT_WRITE)) {
|
if (mprotect(dataEnd, delta, PROT_READ | PROT_WRITE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif // XP_WIN
|
#endif // !XP_WIN
|
||||||
|
|
||||||
#if defined(MOZ_VALGRIND) && \
|
#if defined(MOZ_VALGRIND) && \
|
||||||
defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
|
defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
|
||||||
|
@ -252,8 +241,6 @@ bool js::ExtendBufferMapping(void* dataPointer, size_t mappedSize,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
#elif defined(__wasi__)
|
|
||||||
return false;
|
|
||||||
#elif defined(XP_LINUX)
|
#elif defined(XP_LINUX)
|
||||||
// Note this will not move memory (no MREMAP_MAYMOVE specified)
|
// Note this will not move memory (no MREMAP_MAYMOVE specified)
|
||||||
if (MAP_FAILED == mremap(dataPointer, mappedSize, newMappedSize, 0)) {
|
if (MAP_FAILED == mremap(dataPointer, mappedSize, newMappedSize, 0)) {
|
||||||
|
@ -272,11 +259,9 @@ void js::UnmapBufferMemory(void* base, size_t mappedSize) {
|
||||||
|
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
VirtualFree(base, 0, MEM_RELEASE);
|
VirtualFree(base, 0, MEM_RELEASE);
|
||||||
#elif defined(__wasi__)
|
#else // XP_WIN
|
||||||
free(base);
|
|
||||||
#else
|
|
||||||
munmap(base, mappedSize);
|
munmap(base, mappedSize);
|
||||||
#endif // XP_WIN
|
#endif // !XP_WIN
|
||||||
|
|
||||||
#if defined(MOZ_VALGRIND) && \
|
#if defined(MOZ_VALGRIND) && \
|
||||||
defined(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE)
|
defined(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if !defined(XP_WIN) && !defined(__wasi__)
|
#ifndef XP_WIN
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#ifndef __wasi__
|
#include "jit/ProcessExecutableMemory.h"
|
||||||
# include "jit/ProcessExecutableMemory.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "util/Text.h"
|
#include "util/Text.h"
|
||||||
#include "vm/HelperThreadState.h"
|
#include "vm/HelperThreadState.h"
|
||||||
#include "vm/Realm.h"
|
#include "vm/Realm.h"
|
||||||
|
|
|
@ -16,14 +16,12 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#elif !defined(__OS2__)
|
#elif !defined(__OS2__)
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# ifndef __wasi__
|
# include <sys/mman.h>
|
||||||
# include <sys/mman.h>
|
# ifndef MAP_ANON
|
||||||
# ifndef MAP_ANON
|
# ifdef MAP_ANONYMOUS
|
||||||
# ifdef MAP_ANONYMOUS
|
# define MAP_ANON MAP_ANONYMOUS
|
||||||
# define MAP_ANON MAP_ANONYMOUS
|
# else
|
||||||
# else
|
# error "Don't know how to get anonymous memory"
|
||||||
# error "Don't know how to get anonymous memory"
|
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -86,26 +84,7 @@ static uintptr_t GetDesiredRegionSize() {
|
||||||
|
|
||||||
# define RESERVE_FAILED 0
|
# define RESERVE_FAILED 0
|
||||||
|
|
||||||
#elif defined(__wasi__)
|
#else // Unix
|
||||||
|
|
||||||
# define RESERVE_FAILED 0
|
|
||||||
|
|
||||||
static void* ReserveRegion(uintptr_t aRegion, uintptr_t aSize) {
|
|
||||||
return RESERVE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ReleaseRegion(void* aRegion, uintptr_t aSize) { return; }
|
|
||||||
|
|
||||||
static bool ProbeRegion(uintptr_t aRegion, uintptr_t aSize) {
|
|
||||||
const auto pageSize = 1 << 16;
|
|
||||||
MOZ_ASSERT(pageSize == sysconf(_SC_PAGESIZE));
|
|
||||||
auto heapSize = __builtin_wasm_memory_size(0) * pageSize;
|
|
||||||
return aRegion + aSize < heapSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uintptr_t GetDesiredRegionSize() { return 0; }
|
|
||||||
|
|
||||||
#else // __wasi__
|
|
||||||
|
|
||||||
# include "mozilla/TaggedAnonymousMemory.h"
|
# include "mozilla/TaggedAnonymousMemory.h"
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,8 @@
|
||||||
|
|
||||||
#ifndef XP_WIN
|
#ifndef XP_WIN
|
||||||
|
|
||||||
# ifdef __wasi__
|
# include <sys/types.h>
|
||||||
# include <stdlib.h>
|
# include <sys/mman.h>
|
||||||
# else
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <sys/mman.h>
|
|
||||||
# endif // __wasi__
|
|
||||||
|
|
||||||
# include "mozilla/Types.h"
|
# include "mozilla/Types.h"
|
||||||
|
|
||||||
|
@ -70,12 +66,7 @@ static inline void MozTagAnonymousMemory(const void* aPtr, size_t aLength,
|
||||||
static inline void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength,
|
static inline void* MozTaggedAnonymousMmap(void* aAddr, size_t aLength,
|
||||||
int aProt, int aFlags, int aFd,
|
int aProt, int aFlags, int aFd,
|
||||||
off_t aOffset, const char* aTag) {
|
off_t aOffset, const char* aTag) {
|
||||||
# ifdef __wasi__
|
|
||||||
MOZ_CRASH("We don't use this memory for WASI right now.");
|
|
||||||
return nullptr;
|
|
||||||
# else
|
|
||||||
return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset);
|
return mmap(aAddr, aLength, aProt, aFlags, aFd, aOffset);
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int MozTaggedMemoryIsSupported(void) { return 0; }
|
static inline int MozTaggedMemoryIsSupported(void) { return 0; }
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include "MmapFaultHandler.h"
|
#include "MmapFaultHandler.h"
|
||||||
|
|
||||||
#if defined(XP_UNIX) && !defined(XP_DARWIN) && !defined(__wasi__)
|
#if defined(XP_UNIX) && !defined(XP_DARWIN)
|
||||||
|
|
||||||
# include "PlatformMutex.h"
|
# include "PlatformMutex.h"
|
||||||
# include "mozilla/Atomics.h"
|
# include "mozilla/Atomics.h"
|
||||||
|
|
|
@ -33,12 +33,6 @@
|
||||||
# define MMAP_FAULT_HANDLER_BEGIN_BUFFER(buf, bufLen) {
|
# define MMAP_FAULT_HANDLER_BEGIN_BUFFER(buf, bufLen) {
|
||||||
# define MMAP_FAULT_HANDLER_CATCH(retval) }
|
# define MMAP_FAULT_HANDLER_CATCH(retval) }
|
||||||
|
|
||||||
#elif defined(__wasi__)
|
|
||||||
|
|
||||||
# define MMAP_FAULT_HANDLER_BEGIN_HANDLE(fd) {
|
|
||||||
# define MMAP_FAULT_HANDLER_BEGIN_BUFFER(buf, bufLen) {
|
|
||||||
# define MMAP_FAULT_HANDLER_CATCH(retval) }
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// Linux
|
// Linux
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче