Ignore:
Timestamp:
Jun 1, 2009, 6:20:35 PM (16 years ago)
Author:
[email protected]
Message:

2009-06-01 Gavin Barraclough <[email protected]>

Reviewed by Sam "WX" Weinig.

Allow the JIT to operate without relying on use of RWX memory, on platforms where this is supported.

This patch adds a switch to Platform.h (ENABLE_ASSEMBLER_WX_EXCLUSIVE) which enables this mode of operation.
When this flag is set, all executable memory will be allocated RX, and switched to RW only whilst being
modified. Upon completion of code generation the protection is switched back to RX to allow execution.

Further optimization will be required before it is desirable to enable this mode of operation by default;
enabling this presently incurs a 5%-10% regression.

(Submitting disabled - no performance impact).

  • assembler/AbstractMacroAssembler.h: (JSC::AbstractMacroAssembler::CodeLocationInstruction::repatchLoadToLEA): (JSC::AbstractMacroAssembler::CodeLocationLabel::fromFunctionPointer): (JSC::AbstractMacroAssembler::CodeLocationJump::relink): (JSC::AbstractMacroAssembler::CodeLocationCall::relink): (JSC::AbstractMacroAssembler::CodeLocationNearCall::relink): (JSC::AbstractMacroAssembler::CodeLocationDataLabel32::repatch): (JSC::AbstractMacroAssembler::CodeLocationDataLabelPtr::repatch): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkCallerToTrampoline): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkCallerToFunction): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkNearCallerToTrampoline): (JSC::AbstractMacroAssembler::ProcessorReturnAddress::relinkNearCallerToFunction): (JSC::AbstractMacroAssembler::PatchBuffer::PatchBuffer): (JSC::AbstractMacroAssembler::PatchBuffer::~PatchBuffer): (JSC::AbstractMacroAssembler::PatchBuffer::link): (JSC::AbstractMacroAssembler::PatchBuffer::patch): (JSC::AbstractMacroAssembler::PatchBuffer::performFinalization): (JSC::::CodeLocationCommon::nearCallAtOffset): (JSC::::CodeLocationCall::CodeLocationCall): (JSC::::CodeLocationNearCall::CodeLocationNearCall):
  • assembler/AssemblerBuffer.h: (JSC::AssemblerBuffer::executableCopy):
  • assembler/X86Assembler.h: (JSC::CAN_SIGN_EXTEND_U32_64): (JSC::X86Assembler::linkJump): (JSC::X86Assembler::linkCall): (JSC::X86Assembler::patchPointer): (JSC::X86Assembler::relinkJump): (JSC::X86Assembler::relinkCall): (JSC::X86Assembler::repatchInt32): (JSC::X86Assembler::repatchPointer): (JSC::X86Assembler::repatchLoadToLEA): (JSC::X86Assembler::patchInt32): (JSC::X86Assembler::patchRel32):
  • jit/ExecutableAllocator.h: (JSC::ExecutableAllocator::): (JSC::ExecutableAllocator::makeWritable): (JSC::ExecutableAllocator::makeExecutable):
  • jit/ExecutableAllocatorFixedVMPool.cpp: (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
  • jit/ExecutableAllocatorPosix.cpp: (JSC::ExecutablePool::systemAlloc): (JSC::ExecutablePool::systemRelease): (JSC::ExecutableAllocator::reprotectRegion):
  • jit/ExecutableAllocatorWin.cpp:
  • jit/JITPropertyAccess.cpp: (JSC::JIT::patchGetByIdSelf): (JSC::JIT::patchPutByIdReplace):
  • wtf/Platform.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/jit/ExecutableAllocatorPosix.cpp

    r42705 r44341  
    2828#include "ExecutableAllocator.h"
    2929
    30 #if ENABLE(ASSEMBLER) && !(PLATFORM(MAC) && PLATFORM(X86_64))
     30#if ENABLE(ASSEMBLER)
    3131
    3232#include <sys/mman.h>
     
    3535
    3636namespace JSC {
     37
     38#if !(PLATFORM(MAC) && PLATFORM(X86_64))
    3739
    3840void ExecutableAllocator::intializePageSize()
     
    4345ExecutablePool::Allocation ExecutablePool::systemAlloc(size_t n)
    4446{
    45     ExecutablePool::Allocation alloc = { reinterpret_cast<char*>(mmap(NULL, n, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0)), n };
     47    ExecutablePool::Allocation alloc = { reinterpret_cast<char*>(mmap(NULL, n, INITIAL_PROTECTION_FLAGS, MAP_PRIVATE | MAP_ANON, VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY, 0)), n };
    4648    return alloc;
    4749}
    4850
    49 void ExecutablePool::systemRelease(const ExecutablePool::Allocation& alloc) 
     51void ExecutablePool::systemRelease(const ExecutablePool::Allocation& alloc)
    5052{
    5153    int result = munmap(alloc.pages, alloc.size);
     
    5355}
    5456
     57#endif // !(PLATFORM(MAC) && PLATFORM(X86_64))
     58
     59#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
     60void ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSeting setting)
     61{
     62    if (!pageSize)
     63        intializePageSize();
     64
     65    // Calculate the start of the page containing this region,
     66    // and account for this extra memory within size.
     67    intptr_t startPtr = reinterpret_cast<intptr_t>(start);
     68    intptr_t pageStartPtr = startPtr & ~(pageSize - 1);
     69    void* pageStart = reinterpret_cast<void*>(pageStartPtr);
     70    size += (startPtr - pageStartPtr);
     71
     72    // Round size up
     73    size += (pageSize - 1);
     74    size &= ~(pageSize - 1);
     75
     76    mprotect(pageStart, size, (setting == Writable) ? PROTECTION_FLAGS_RW : PROTECTION_FLAGS_RX);
     77}
     78#endif
     79
    5580}
    5681
Note: See TracChangeset for help on using the changeset viewer.