X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..fb8617cde5834786bd4e4afd579883e4acf5666e:/jit/ExecutableAllocatorPosix.cpp diff --git a/jit/ExecutableAllocatorPosix.cpp b/jit/ExecutableAllocatorPosix.cpp index 21955d7..06375ad 100644 --- a/jit/ExecutableAllocatorPosix.cpp +++ b/jit/ExecutableAllocatorPosix.cpp @@ -27,13 +27,16 @@ #include "ExecutableAllocator.h" -#if ENABLE(ASSEMBLER) +#if ENABLE(ASSEMBLER) && OS(UNIX) && !OS(SYMBIAN) #include #include +#include namespace JSC { +#if !(OS(DARWIN) && CPU(X86_64)) + void ExecutableAllocator::intializePageSize() { ExecutableAllocator::pageSize = getpagesize(); @@ -41,16 +44,42 @@ void ExecutableAllocator::intializePageSize() ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t n) { - ExecutablePool::Allocation alloc = {reinterpret_cast(mmap(NULL, n, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0)), n}; + void* allocation = mmap(NULL, n, INITIAL_PROTECTION_FLAGS, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0); + if (allocation == MAP_FAILED) + CRASH(); + ExecutablePool::Allocation alloc = { reinterpret_cast(allocation), n }; return alloc; } -void ExecutablePool::systemRelease(const ExecutablePool::Allocation& alloc) +void ExecutablePool::systemRelease(const ExecutablePool::Allocation& alloc) { int result = munmap(alloc.pages, alloc.size); ASSERT_UNUSED(result, !result); } +#endif // !(OS(DARWIN) && CPU(X86_64)) + +#if ENABLE(ASSEMBLER_WX_EXCLUSIVE) +void ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSeting setting) +{ + if (!pageSize) + intializePageSize(); + + // Calculate the start of the page containing this region, + // and account for this extra memory within size. + intptr_t startPtr = reinterpret_cast(start); + intptr_t pageStartPtr = startPtr & ~(pageSize - 1); + void* pageStart = reinterpret_cast(pageStartPtr); + size += (startPtr - pageStartPtr); + + // Round size up + size += (pageSize - 1); + size &= ~(pageSize - 1); + + mprotect(pageStart, size, (setting == Writable) ? PROTECTION_FLAGS_RW : PROTECTION_FLAGS_RX); +} +#endif + } #endif // HAVE(ASSEMBLER)