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/ExecutableAllocator.h

    r43338 r44341  
    3737#define JIT_ALLOCATOR_LARGE_ALLOC_SIZE (ExecutableAllocator::pageSize * 4)
    3838
     39#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
     40#define PROTECTION_FLAGS_RW (PROT_READ | PROT_WRITE)
     41#define PROTECTION_FLAGS_RX (PROT_READ | PROT_EXEC)
     42#define INITIAL_PROTECTION_FLAGS PROTECTION_FLAGS_RX
     43#else
     44#define INITIAL_PROTECTION_FLAGS (PROT_READ | PROT_WRITE | PROT_EXEC)
     45#endif
     46
    3947namespace JSC {
    4048
     
    113121
    114122class ExecutableAllocator {
     123    enum ProtectionSeting { Writable, Executable };
     124
    115125public:
    116126    static size_t pageSize;
     
    142152    }
    143153
     154#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
     155    static void makeWritable(void* start, size_t size) { reprotectRegion(start, size, Writable); }
     156    static void makeExecutable(void* start, size_t size) { reprotectRegion(start, size, Executable); }
     157
     158    class MakeWritable {
     159    public:
     160        MakeWritable(void* start, size_t size)
     161            : m_start(start)
     162            , m_size(size)
     163        {
     164            makeWritable(start, size);
     165        }
     166
     167        ~MakeWritable()
     168        {
     169            makeExecutable(m_start, m_size);
     170        }
     171
     172    private:
     173        void* m_start;
     174        size_t m_size;
     175    };
     176#else
     177    static void makeWritable(void*, size_t) {}
     178    static void makeExecutable(void*, size_t) {}
     179    class MakeWritable { public: MakeWritable(void*, size_t) {} };
     180#endif
     181
    144182private:
     183
     184#if ENABLE(ASSEMBLER_WX_EXCLUSIVE)
     185    static void reprotectRegion(void*, size_t, ProtectionSeting);
     186#endif
     187
    145188    RefPtr<ExecutablePool> m_smallAllocationPool;
    146189    static void intializePageSize();
Note: See TracChangeset for help on using the changeset viewer.