Commit 85c93e79 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm] Add FLAG_wasm_write_protect_code_memory

This flag is the WebAssembly native heap equivalent to
FLAG_write_protect_code_memory.

R=mstarzinger@chromium.org

Bug: v8:7454
Change-Id: Id4f671af2e8676d08599c8c30ce03b00e9d33780
Reviewed-on: https://chromium-review.googlesource.com/924071
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51330}
parent d0d85832
......@@ -519,6 +519,8 @@ DEFINE_DEBUG_BOOL(wasm_trace_native_heap, false,
"trace wasm native heap events")
DEFINE_BOOL(wasm_jit_to_native, true,
"JIT wasm code to native (not JS GC) memory")
DEFINE_BOOL(wasm_write_protect_code_memory, false,
"write protect code memory on the wasm native heap")
DEFINE_IMPLICATION(future, wasm_jit_to_native)
DEFINE_BOOL(wasm_trace_serialization, false,
"trace serialization/deserialization")
......
......@@ -738,7 +738,11 @@ bool WasmCodeManager::Commit(Address start, size_t size) {
remaining_uncommitted_.Increment(size);
return false;
}
bool ret = SetPermissions(start, size, PageAllocator::kReadWrite);
PageAllocator::Permission permission = FLAG_wasm_write_protect_code_memory
? PageAllocator::kReadWrite
: PageAllocator::kReadWriteExecute;
bool ret = SetPermissions(start, size, permission);
TRACE_HEAP("Setting rw permissions for %p:%p\n",
reinterpret_cast<void*>(start),
reinterpret_cast<void*>(start + size));
......@@ -843,38 +847,40 @@ bool NativeModule::SetExecutable(bool executable) {
PageAllocator::Permission permission =
executable ? PageAllocator::kReadExecute : PageAllocator::kReadWrite;
if (FLAG_wasm_write_protect_code_memory) {
#if V8_OS_WIN
// On windows, we need to switch permissions per separate virtual memory
// reservation. This is really just a problem when the NativeModule is
// growable (meaning can_request_more_memory_). That's 32-bit in production,
// or unittests.
// For now, in that case, we commit at reserved memory granularity.
// Technically, that may be a waste, because we may reserve more than we use.
// On 32-bit though, the scarce resource is the address space - committed or
// not.
if (can_request_more_memory_) {
for (auto& vmem : owned_memory_) {
if (!SetPermissions(vmem.address(), vmem.size(), permission)) {
return false;
// On windows, we need to switch permissions per separate virtual memory
// reservation. This is really just a problem when the NativeModule is
// growable (meaning can_request_more_memory_). That's 32-bit in production,
// or unittests.
// For now, in that case, we commit at reserved memory granularity.
// Technically, that may be a waste, because we may reserve more than we
// use. On 32-bit though, the scarce resource is the address space -
// committed or not.
if (can_request_more_memory_) {
for (auto& vmem : owned_memory_) {
if (!SetPermissions(vmem.address(), vmem.size(), permission)) {
return false;
}
TRACE_HEAP("Set %p:%p to executable:%d\n", vmem.address(), vmem.end(),
executable);
}
TRACE_HEAP("Set %p:%p to executable:%d\n", vmem.address(), vmem.end(),
executable);
is_executable_ = executable;
return true;
}
is_executable_ = executable;
return true;
}
#endif
for (auto& range : allocated_memory_.ranges()) {
// allocated_memory_ is fine-grained, so we need to
// page-align it.
size_t range_size = RoundUp(static_cast<size_t>(range.second - range.first),
AllocatePageSize());
if (!SetPermissions(range.first, range_size, permission)) {
return false;
for (auto& range : allocated_memory_.ranges()) {
// allocated_memory_ is fine-grained, so we need to
// page-align it.
size_t range_size = RoundUp(
static_cast<size_t>(range.second - range.first), AllocatePageSize());
if (!SetPermissions(range.first, range_size, permission)) {
return false;
}
TRACE_HEAP("Set %p:%p to executable:%d\n",
reinterpret_cast<void*>(range.first),
reinterpret_cast<void*>(range.second), executable);
}
TRACE_HEAP("Set %p:%p to executable:%d\n",
reinterpret_cast<void*>(range.first),
reinterpret_cast<void*>(range.second), executable);
}
is_executable_ = executable;
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment