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

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

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

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

@ -81,7 +81,7 @@ static const unsigned FLAGS_RX = PROT_READ | PROT_EXEC;
void
ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting setting)
{
MOZ_ASSERT(nonWritableJitCode);
MOZ_ASSERT(NON_WRITABLE_JIT_CODE);
MOZ_ASSERT(pageSize);
// Calculate the start of the page containing this region,
@ -101,8 +101,9 @@ ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting
/* static */ unsigned
ExecutableAllocator::initialProtectionFlags(ProtectionSetting protection)
{
if (!nonWritableJitCode)
return FLAGS_RW | FLAGS_RX;
#ifdef NON_WRITABLE_JIT_CODE
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
ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting setting)
{
MOZ_ASSERT(nonWritableJitCode);
MOZ_ASSERT(NON_WRITABLE_JIT_CODE);
MOZ_ASSERT(pageSize);
// Calculate the start of the page containing this region,
@ -265,8 +265,9 @@ ExecutableAllocator::reprotectRegion(void* start, size_t size, ProtectionSetting
/* static */ unsigned
ExecutableAllocator::initialProtectionFlags(ProtectionSetting protection)
{
if (!nonWritableJitCode)
return PAGE_EXECUTE_READWRITE;
#ifdef NON_WRITABLE_JIT_CODE
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;
#endif
// If ExecutableAllocator::nonWritableJitCode is |true|, this class will ensure
// JIT code is writable (has RW permissions) in its scope. If nonWritableJitCode
// is |false|, it's a no-op.
// If NON_WRITABLE_JIT_CODE is enabled, this class will ensure
// JIT code is writable (has RW permissions) in its scope.
// Otherwise it's a no-op.
class MOZ_STACK_CLASS AutoWritableJitCode
{
// 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;
#if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64)
static bool
PropagateFlagToNestedShells(const char* flag)
{
return sPropagatedFlags.append(flag);
}
#endif
static bool
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",
"Wait for COUNT calls or iterations before baseline-compiling "
"(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 "
"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 "
@ -6769,11 +6771,6 @@ main(int argc, char** argv, char** envp)
OOM_printAllocationCount = op.getBoolOption('O');
#endif
if (op.getBoolOption("non-writable-jitcode")) {
js::jit::ExecutableAllocator::nonWritableJitCode = true;
PropagateFlagToNestedShells("--non-writable-jitcode");
}
#ifdef JS_CODEGEN_X86
if (op.getBoolOption("no-fpu"))
js::jit::CPUInfo::SetFloatingPointDisabled();