[wasm] Move all V8-specific limitations to wasm-limits.h

R=clemensh@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2551463002
Cr-Commit-Position: refs/heads/master@{#41477}
This commit is contained in:
titzer 2016-12-05 02:02:26 -08:00 committed by Commit bot
parent 8f9bb9b8d6
commit d9cfd7757e
9 changed files with 63 additions and 37 deletions

View File

@ -1748,6 +1748,7 @@ v8_source_set("v8_base") {
"src/wasm/wasm-interpreter.h",
"src/wasm/wasm-js.cc",
"src/wasm/wasm-js.h",
"src/wasm/wasm-limits.h",
"src/wasm/wasm-macro-gen.h",
"src/wasm/wasm-module-builder.cc",
"src/wasm/wasm-module-builder.h",

View File

@ -34,6 +34,7 @@
#include "src/log-inl.h"
#include "src/wasm/ast-decoder.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-text.h"
@ -1723,9 +1724,8 @@ Node* WasmGraphBuilder::BuildFloatToIntConversionInstruction(
Node* WasmGraphBuilder::GrowMemory(Node* input) {
Diamond check_input_range(
graph(), jsgraph()->common(),
graph()->NewNode(
jsgraph()->machine()->Uint32LessThanOrEqual(), input,
jsgraph()->Uint32Constant(wasm::WasmModule::kV8MaxPages)),
graph()->NewNode(jsgraph()->machine()->Uint32LessThanOrEqual(), input,
jsgraph()->Uint32Constant(wasm::kV8MaxWasmMemoryPages)),
BranchHint::kTrue);
check_input_range.Chain(*control_);

View File

@ -1284,6 +1284,7 @@
'wasm/wasm-external-refs.h',
'wasm/wasm-js.cc',
'wasm/wasm-js.h',
'wasm/wasm-limits.h',
'wasm/wasm-macro-gen.h',
'wasm/wasm-module.cc',
'wasm/wasm-module.h',

View File

@ -12,6 +12,7 @@
#include "src/v8.h"
#include "src/wasm/decoder.h"
#include "src/wasm/wasm-limits.h"
namespace v8 {
namespace internal {
@ -312,18 +313,18 @@ class ModuleDecoder : public Decoder {
false, SignatureMap()});
expect_u8("element type", kWasmAnyFunctionTypeForm);
WasmIndirectFunctionTable* table = &module->function_tables.back();
consume_resizable_limits(
"element count", "elements", WasmModule::kV8MaxTableSize,
&table->min_size, &table->has_max, WasmModule::kV8MaxTableSize,
&table->max_size);
consume_resizable_limits("element count", "elements",
kV8MaxWasmTableSize, &table->min_size,
&table->has_max, kV8MaxWasmTableSize,
&table->max_size);
break;
}
case kExternalMemory: {
// ===== Imported memory =========================================
bool has_max = false;
consume_resizable_limits("memory", "pages", WasmModule::kV8MaxPages,
consume_resizable_limits("memory", "pages", kV8MaxWasmMemoryPages,
&module->min_mem_pages, &has_max,
WasmModule::kSpecMaxPages,
kSpecMaxWasmMemoryPages,
&module->max_mem_pages);
module->has_memory = true;
break;
@ -387,10 +388,9 @@ class ModuleDecoder : public Decoder {
for (uint32_t i = 0; ok() && i < table_count; i++) {
WasmIndirectFunctionTable* table = &module->function_tables.back();
expect_u8("table type", kWasmAnyFunctionTypeForm);
consume_resizable_limits("table elements", "elements",
WasmModule::kV8MaxTableSize, &table->min_size,
&table->has_max, WasmModule::kV8MaxTableSize,
&table->max_size);
consume_resizable_limits(
"table elements", "elements", kV8MaxWasmTableSize, &table->min_size,
&table->has_max, kV8MaxWasmTableSize, &table->max_size);
}
section_iter.advance();
}
@ -407,8 +407,8 @@ class ModuleDecoder : public Decoder {
for (uint32_t i = 0; ok() && i < memory_count; i++) {
bool has_max = false;
consume_resizable_limits(
"memory", "pages", WasmModule::kV8MaxPages, &module->min_mem_pages,
&has_max, WasmModule::kSpecMaxPages, &module->max_mem_pages);
"memory", "pages", kV8MaxWasmMemoryPages, &module->min_mem_pages,
&has_max, kSpecMaxWasmMemoryPages, &module->max_mem_pages);
}
module->has_memory = true;
section_iter.advance();
@ -1109,7 +1109,8 @@ ModuleResult DecodeWasmModule(Isolate* isolate, const byte* module_start,
isolate->counters()->wasm_decode_module_time());
size_t size = module_end - module_start;
if (module_start > module_end) return ModuleError("start > end");
if (size >= kMaxModuleSize) return ModuleError("size > maximum module size");
if (size >= kV8MaxWasmModuleSize)
return ModuleError("size > maximum module size");
// TODO(bradnelson): Improve histogram handling of size_t.
isolate->counters()->wasm_module_size_bytes()->AddSample(
static_cast<int>(size));
@ -1148,7 +1149,7 @@ FunctionResult DecodeWasmFunction(Isolate* isolate, Zone* zone,
isolate->counters()->wasm_decode_function_time());
size_t size = function_end - function_start;
if (function_start > function_end) return FunctionError("start > end");
if (size > kMaxFunctionSize)
if (size > kV8MaxWasmFunctionSize)
return FunctionError("size > maximum function size");
isolate->counters()->wasm_function_size_bytes()->AddSample(
static_cast<int>(size));

View File

@ -8,6 +8,7 @@
#include "src/wasm/ast-decoder.h"
#include "src/wasm/decoder.h"
#include "src/wasm/wasm-external-refs.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/zone/accounting-allocator.h"
@ -663,7 +664,7 @@ static inline int32_t ExecuteGrowMemory(uint32_t delta_pages,
WasmInstance* instance) {
// TODO(ahaas): Move memory allocation to wasm-module.cc for better
// encapsulation.
if (delta_pages > wasm::WasmModule::kV8MaxPages) {
if (delta_pages > wasm::kV8MaxWasmMemoryPages) {
return -1;
}
uint32_t old_size = instance->mem_size;
@ -679,8 +680,7 @@ static inline int32_t ExecuteGrowMemory(uint32_t delta_pages,
} else {
DCHECK_NOT_NULL(instance->mem_start);
new_size = old_size + delta_pages * wasm::WasmModule::kPageSize;
if (new_size >
wasm::WasmModule::kV8MaxPages * wasm::WasmModule::kPageSize) {
if (new_size > wasm::kV8MaxWasmMemoryPages * wasm::WasmModule::kPageSize) {
return -1;
}
new_mem_start = static_cast<byte*>(realloc(instance->mem_start, new_size));

View File

@ -18,6 +18,7 @@
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
@ -315,7 +316,7 @@ void WebAssemblyTable(const v8::FunctionCallbackInfo<v8::Value>& args) {
return;
}
} else {
maximum = static_cast<int>(i::wasm::WasmModule::kV8MaxTableSize);
maximum = static_cast<int>(i::wasm::kV8MaxWasmTableSize);
}
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);

32
src/wasm/wasm-limits.h Normal file
View File

@ -0,0 +1,32 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_WASM_LIMITS_H_
#define V8_WASM_WASM_LIMITS_H_
namespace v8 {
namespace internal {
namespace wasm {
const size_t kV8MaxWasmSignatures = 10000000;
const size_t kV8MaxWasmFunctions = 10000000;
const size_t kV8MaxWasmMemoryPages = 16384; // = 1 GiB
const size_t kV8MaxWasmStringSize = 256;
const size_t kV8MaxWasmModuleSize = 1024 * 1024 * 1024; // = 1 GiB
const size_t kV8MaxWasmFunctionSize = 128 * 1024;
const size_t kV8MaxWasmFunctionLocals = 50000;
const size_t kV8MaxWasmTableSize = 16 * 1024 * 1024;
const size_t kSpecMaxWasmMemoryPages = 65536;
const uint64_t kWasmMaxHeapOffset =
static_cast<uint64_t>(
std::numeric_limits<uint32_t>::max()) // maximum base value
+ std::numeric_limits<uint32_t>::max(); // maximum index value
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_WASM_LIMITS_H_

View File

@ -17,6 +17,7 @@
#include "src/wasm/ast-decoder.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
@ -687,7 +688,7 @@ std::pair<int, int> GetFunctionOffsetAndLength(
Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size,
bool enable_guard_regions) {
if (size > (WasmModule::kV8MaxPages * WasmModule::kPageSize)) {
if (size > (kV8MaxWasmMemoryPages * WasmModule::kPageSize)) {
// TODO(titzer): lift restriction on maximum memory allocated here.
return Handle<JSArrayBuffer>::null();
}
@ -1690,7 +1691,7 @@ class WasmInstanceBuilder {
// Allocate memory for a module instance as a new JSArrayBuffer.
Handle<JSArrayBuffer> AllocateMemory(uint32_t min_mem_pages) {
if (min_mem_pages > WasmModule::kV8MaxPages) {
if (min_mem_pages > kV8MaxWasmMemoryPages) {
thrower_->RangeError("Out of memory: wasm memory too large");
return Handle<JSArrayBuffer>::null();
}
@ -1777,7 +1778,7 @@ class WasmInstanceBuilder {
module_->function_tables[exp.index];
if (table_instance.table_object.is_null()) {
uint32_t maximum =
table.has_max ? table.max_size : WasmModule::kV8MaxTableSize;
table.has_max ? table.max_size : kV8MaxWasmTableSize;
table_instance.table_object = WasmTableObject::New(
isolate_, table.min_size, maximum, &table_instance.js_wrappers);
}
@ -2145,7 +2146,7 @@ uint32_t GetMaxInstanceMemorySize(Isolate* isolate,
isolate->counters()->wasm_max_mem_pages_count()->AddSample(
compiled_max_pages);
if (compiled_max_pages != 0) return compiled_max_pages;
return WasmModule::kV8MaxPages;
return kV8MaxWasmMemoryPages;
}
Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
@ -2163,7 +2164,7 @@ Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
std::numeric_limits<uint32_t>::max());
uint32_t new_size = old_size + pages * WasmModule::kPageSize;
if (new_size <= old_size || max_pages * WasmModule::kPageSize < new_size ||
WasmModule::kV8MaxPages * WasmModule::kPageSize < new_size) {
kV8MaxWasmMemoryPages * WasmModule::kPageSize < new_size) {
return Handle<JSArrayBuffer>::null();
}

View File

@ -32,20 +32,12 @@ class WasmCompilationUnit;
namespace wasm {
class ErrorThrower;
const size_t kMaxModuleSize = 1024 * 1024 * 1024;
const size_t kMaxFunctionSize = 128 * 1024;
const size_t kMaxStringSize = 256;
const uint32_t kWasmMagic = 0x6d736100;
const uint32_t kWasmVersion = 0x0d;
const uint8_t kWasmFunctionTypeForm = 0x60;
const uint8_t kWasmAnyFunctionTypeForm = 0x70;
const uint64_t kWasmMaxHeapOffset =
static_cast<uint64_t>(
std::numeric_limits<uint32_t>::max()) // maximum base value
+ std::numeric_limits<uint32_t>::max(); // maximum index value
enum WasmSectionCode {
kUnknownSectionCode = 0, // code for unknown sections
kTypeSectionCode = 1, // Function signature declarations
@ -183,9 +175,6 @@ struct ModuleWireBytes;
struct V8_EXPORT_PRIVATE WasmModule {
static const uint32_t kPageSize = 0x10000; // Page size, 64kb.
static const uint32_t kMinMemPages = 1; // Minimum memory size = 64kb
static const size_t kV8MaxPages = 16384; // Maximum memory size = 1gb
static const size_t kSpecMaxPages = 65536; // Maximum according to the spec
static const size_t kV8MaxTableSize = 16 * 1024 * 1024;
Zone* owned_zone;
uint32_t min_mem_pages = 0; // minimum size of the memory in 64k pages