Bug 1235868 - Change nonWritableJITCode to ifdefs. r=jandem

This commit is contained in:
Tom Schuster 2015-12-30 22:15:03 +01:00
Родитель 9137c3ddf5
Коммит 04de56a8e6
6 изменённых файлов: 28 добавлений и 31 удалений

Просмотреть файл

@ -340,27 +340,25 @@ ExecutableAllocator::addSizeOfCode(JS::CodeSizes* sizes) const
void void
ExecutableAllocator::reprotectAll(ProtectionSetting protection) ExecutableAllocator::reprotectAll(ProtectionSetting protection)
{ {
if (!nonWritableJitCode) #ifdef NON_WRITABLE_JIT_CODE
return;
if (!m_pools.initialized()) if (!m_pools.initialized())
return; return;
for (ExecPoolHashSet::Range r = m_pools.all(); !r.empty(); r.popFront()) for (ExecPoolHashSet::Range r = m_pools.all(); !r.empty(); r.popFront())
reprotectPool(rt_, r.front(), protection); reprotectPool(rt_, r.front(), protection);
#endif
} }
/* static */ void /* static */ void
ExecutableAllocator::reprotectPool(JSRuntime* rt, ExecutablePool* pool, ProtectionSetting protection) ExecutableAllocator::reprotectPool(JSRuntime* rt, ExecutablePool* pool, ProtectionSetting protection)
{ {
#ifdef NON_WRITABLE_JIT_CODE
// Don't race with reprotectAll called from the signal handler. // Don't race with reprotectAll called from the signal handler.
MOZ_ASSERT(rt->jitRuntime()->preventBackedgePatching() || rt->handlingJitInterrupt()); MOZ_ASSERT(rt->jitRuntime()->preventBackedgePatching() || rt->handlingJitInterrupt());
if (!nonWritableJitCode)
return;
char* start = pool->m_allocation.pages; char* start = pool->m_allocation.pages;
reprotectRegion(start, pool->m_freePtr - start, protection); reprotectRegion(start, pool->m_freePtr - start, protection);
#endif
} }
/* static */ void /* static */ void
@ -407,5 +405,3 @@ ExecutableAllocator::poisonCode(JSRuntime* rt, JitPoisonRangeVector& ranges)
pool->release(); pool->release();
} }
} }
bool ExecutableAllocator::nonWritableJitCode = true;

Просмотреть файл

@ -157,6 +157,8 @@ struct JitPoisonRange
typedef Vector<JitPoisonRange, 0, SystemAllocPolicy> JitPoisonRangeVector; typedef Vector<JitPoisonRange, 0, SystemAllocPolicy> JitPoisonRangeVector;
#define NON_WRITABLE_JIT_CODE 1
class ExecutableAllocator class ExecutableAllocator
{ {
#ifdef XP_WIN #ifdef XP_WIN
@ -183,8 +185,6 @@ class ExecutableAllocator
static void initStatic(); static void initStatic();
static bool nonWritableJitCode;
private: private:
static size_t pageSize; static size_t pageSize;
static size_t largeAllocSize; static size_t largeAllocSize;
@ -206,14 +206,16 @@ class ExecutableAllocator
public: public:
static void makeWritable(void* start, size_t size) static void makeWritable(void* start, size_t size)
{ {
if (nonWritableJitCode) #ifdef NON_WRITABLE_JIT_CODE
reprotectRegion(start, size, Writable); reprotectRegion(start, size, Writable);
#endif
} }
static void makeExecutable(void* start, size_t size) static void makeExecutable(void* start, size_t size)
{ {
if (nonWritableJitCode) #ifdef NON_WRITABLE_JIT_CODE
reprotectRegion(start, size, Executable); reprotectRegion(start, size, Executable);
#endif
} }
void makeAllWritable() { void makeAllWritable() {

Просмотреть файл

@ -81,7 +81,7 @@ static const unsigned FLAGS_RX = PROT_READ | PROT_EXEC;
void void
ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting setting) ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting setting)
{ {
MOZ_ASSERT(nonWritableJitCode); MOZ_ASSERT(NON_WRITABLE_JIT_CODE);
MOZ_ASSERT(pageSize); MOZ_ASSERT(pageSize);
// Calculate the start of the page containing this region, // Calculate the start of the page containing this region,
@ -101,8 +101,9 @@ ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting
/* static */ unsigned /* static */ unsigned
ExecutableAllocator::initialProtectionFlags(ProtectionSetting protection) ExecutableAllocator::initialProtectionFlags(ProtectionSetting protection)
{ {
if (!nonWritableJitCode) #ifdef NON_WRITABLE_JIT_CODE
return FLAGS_RW | FLAGS_RX;
return (protection == Writable) ? FLAGS_RW : FLAGS_RX; return (protection == Writable) ? FLAGS_RW : FLAGS_RX;
#else
return FLAGS_RW | FLAGS_RX;
#endif
} }

Просмотреть файл

@ -242,7 +242,7 @@ ExecutableAllocator::systemRelease(const ExecutablePool::Allocation& alloc)
void void
ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting setting) ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting setting)
{ {
MOZ_ASSERT(nonWritableJitCode); MOZ_ASSERT(NON_WRITABLE_JIT_CODE);
MOZ_ASSERT(pageSize); MOZ_ASSERT(pageSize);
// Calculate the start of the page containing this region, // Calculate the start of the page containing this region,
@ -265,8 +265,9 @@ ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting
/* static */ unsigned /* static */ unsigned
ExecutableAllocator::initialProtectionFlags(ProtectionSetting protection) ExecutableAllocator::initialProtectionFlags(ProtectionSetting protection)
{ {
if (!nonWritableJitCode) #ifdef NON_WRITABLE_JIT_CODE
return PAGE_EXECUTE_READWRITE;
return (protection == Writable) ? PAGE_READWRITE : PAGE_EXECUTE_READ; return (protection == Writable) ? PAGE_READWRITE : PAGE_EXECUTE_READ;
#else
return PAGE_EXECUTE_READWRITE;
#endif
} }

Просмотреть файл

@ -526,9 +526,9 @@ void FinishInvalidation(FreeOp* fop, JSScript* script);
const unsigned WINDOWS_BIG_FRAME_TOUCH_INCREMENT = 4096 - 1; const unsigned WINDOWS_BIG_FRAME_TOUCH_INCREMENT = 4096 - 1;
#endif #endif
// If ExecutableAllocator::nonWritableJitCode is |true|, this class will ensure // If NON_WRITABLE_JIT_CODE is enabled, this class will ensure
// JIT code is writable (has RW permissions) in its scope. If nonWritableJitCode // JIT code is writable (has RW permissions) in its scope.
// is |false|, it's a no-op. // Otherwise it's a no-op.
class MOZ_STACK_CLASS AutoWritableJitCode class MOZ_STACK_CLASS AutoWritableJitCode
{ {
// Backedge patching from the signal handler will change memory protection // Backedge patching from the signal handler will change memory protection

Просмотреть файл

@ -3781,11 +3781,13 @@ EscapeForShell(AutoCStringVector& argv)
static Vector<const char*, 4, js::SystemAllocPolicy> sPropagatedFlags; static Vector<const char*, 4, js::SystemAllocPolicy> sPropagatedFlags;
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
static bool static bool
PropagateFlagToNestedShells(const char* flag) PropagateFlagToNestedShells(const char* flag)
{ {
return sPropagatedFlags.append(flag); return sPropagatedFlags.append(flag);
} }
#endif
static bool static bool
NestedShell(JSContext* cx, unsigned argc, Value* vp) NestedShell(JSContext* cx, unsigned argc, Value* vp)
@ -6690,7 +6692,7 @@ main(int argc, char** argv, char** envp)
|| !op.addIntOption('\0', "baseline-warmup-threshold", "COUNT", || !op.addIntOption('\0', "baseline-warmup-threshold", "COUNT",
"Wait for COUNT calls or iterations before baseline-compiling " "Wait for COUNT calls or iterations before baseline-compiling "
"(default: 10)", -1) "(default: 10)", -1)
|| !op.addBoolOption('\0', "non-writable-jitcode", "Allocate JIT code as non-writable memory.") || !op.addBoolOption('\0', "non-writable-jitcode", "(NOP for fuzzers) Allocate JIT code as non-writable memory.")
|| !op.addBoolOption('\0', "no-fpu", "Pretend CPU does not support floating-point operations " || !op.addBoolOption('\0', "no-fpu", "Pretend CPU does not support floating-point operations "
"to test JIT codegen (no-op on platforms other than x86).") "to test JIT codegen (no-op on platforms other than x86).")
|| !op.addBoolOption('\0', "no-sse3", "Pretend CPU does not support SSE3 instructions and above " || !op.addBoolOption('\0', "no-sse3", "Pretend CPU does not support SSE3 instructions and above "
@ -6769,11 +6771,6 @@ main(int argc, char** argv, char** envp)
OOM_printAllocationCount = op.getBoolOption('O'); OOM_printAllocationCount = op.getBoolOption('O');
#endif #endif
if (op.getBoolOption("non-writable-jitcode")) {
js::jit::ExecutableAllocator::nonWritableJitCode = true;
PropagateFlagToNestedShells("--non-writable-jitcode");
}
#ifdef JS_CODEGEN_X86 #ifdef JS_CODEGEN_X86
if (op.getBoolOption("no-fpu")) if (op.getBoolOption("no-fpu"))
js::jit::CPUInfo::SetFloatingPointDisabled(); js::jit::CPUInfo::SetFloatingPointDisabled();