Commit 2a71b320 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Rename {ValidateFlag} constants

As a preparation to add a "boolean validation" mode, rename the existing
flags. This removes many unrelated changes from the follow-up change and
makes it easier to review.

R=thibaudm@chromium.org

Bug: v8:10969
Change-Id: I5f71405b525a7caa91be46c035e31d4d960e4e4c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2440036Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70224}
parent 7b24b139
...@@ -258,7 +258,7 @@ class DebugSideTableBuilder { ...@@ -258,7 +258,7 @@ class DebugSideTableBuilder {
class LiftoffCompiler { class LiftoffCompiler {
public: public:
// TODO(clemensb): Make this a template parameter. // TODO(clemensb): Make this a template parameter.
static constexpr Decoder::ValidateFlag validate = Decoder::kValidate; static constexpr Decoder::ValidateFlag validate = Decoder::kFullValidation;
using Value = ValueBase; using Value = ValueBase;
...@@ -843,7 +843,8 @@ class LiftoffCompiler { ...@@ -843,7 +843,8 @@ class LiftoffCompiler {
#ifdef DEBUG #ifdef DEBUG
SLOW_DCHECK(__ ValidateCacheState()); SLOW_DCHECK(__ ValidateCacheState());
if (WasmOpcodes::IsPrefixOpcode(opcode)) { if (WasmOpcodes::IsPrefixOpcode(opcode)) {
opcode = decoder->read_prefixed_opcode<Decoder::kValidate>(decoder->pc()); opcode = decoder->read_prefixed_opcode<Decoder::kFullValidation>(
decoder->pc());
} }
DEBUG_CODE_COMMENT(WasmOpcodes::OpcodeName(opcode)); DEBUG_CODE_COMMENT(WasmOpcodes::OpcodeName(opcode));
#endif #endif
...@@ -4115,7 +4116,7 @@ WasmCompilationResult ExecuteLiftoffCompilation( ...@@ -4115,7 +4116,7 @@ WasmCompilationResult ExecuteLiftoffCompilation(
if (debug_sidetable) { if (debug_sidetable) {
debug_sidetable_builder = std::make_unique<DebugSideTableBuilder>(); debug_sidetable_builder = std::make_unique<DebugSideTableBuilder>();
} }
WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder( WasmFullDecoder<Decoder::kFullValidation, LiftoffCompiler> decoder(
&zone, env->module, env->enabled_features, detected, func_body, &zone, env->module, env->enabled_features, detected, func_body,
call_descriptor, env, &zone, instruction_buffer->CreateView(), call_descriptor, env, &zone, instruction_buffer->CreateView(),
debug_sidetable_builder.get(), for_debugging, func_index, breakpoints, debug_sidetable_builder.get(), for_debugging, func_index, breakpoints,
...@@ -4172,7 +4173,7 @@ std::unique_ptr<DebugSideTable> GenerateLiftoffDebugSideTable( ...@@ -4172,7 +4173,7 @@ std::unique_ptr<DebugSideTable> GenerateLiftoffDebugSideTable(
auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, func_body.sig); auto call_descriptor = compiler::GetWasmCallDescriptor(&zone, func_body.sig);
DebugSideTableBuilder debug_sidetable_builder; DebugSideTableBuilder debug_sidetable_builder;
WasmFeatures detected; WasmFeatures detected;
WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder( WasmFullDecoder<Decoder::kFullValidation, LiftoffCompiler> decoder(
&zone, env->module, env->enabled_features, &detected, func_body, &zone, env->module, env->enabled_features, &detected, func_body,
call_descriptor, env, &zone, call_descriptor, env, &zone,
NewAssemblerBuffer(AssemblerBase::kDefaultBufferSize), NewAssemblerBuffer(AssemblerBase::kDefaultBufferSize),
......
...@@ -39,7 +39,13 @@ using DecodeResult = VoidResult; ...@@ -39,7 +39,13 @@ using DecodeResult = VoidResult;
// a buffer of bytes. // a buffer of bytes.
class Decoder { class Decoder {
public: public:
enum ValidateFlag : bool { kValidate = true, kNoValidate = false }; // {ValidateFlag} can be used in a boolean manner ({if (!validate) ...}).
// TODO(clemensb): Introduce a "boolean validation" mode where error messages
// are locations are not tracked.
enum ValidateFlag : int8_t {
kNoValidation = 0, // Don't run validation, assume valid input.
kFullValidation // Run full validation with error message and location.
};
enum AdvancePCFlag : bool { kAdvancePc = true, kNoAdvancePc = false }; enum AdvancePCFlag : bool { kAdvancePc = true, kNoAdvancePc = false };
...@@ -160,7 +166,7 @@ class Decoder { ...@@ -160,7 +166,7 @@ class Decoder {
index = *(pc + 1); index = *(pc + 1);
*length = 1; *length = 1;
} else { } else {
// If kValidate and size validation fails. // If size validation fails.
index = 0; index = 0;
*length = 0; *length = 0;
} }
...@@ -186,21 +192,22 @@ class Decoder { ...@@ -186,21 +192,22 @@ class Decoder {
// Reads a LEB128 variable-length unsigned 32-bit integer and advances {pc_}. // Reads a LEB128 variable-length unsigned 32-bit integer and advances {pc_}.
uint32_t consume_u32v(const char* name = nullptr) { uint32_t consume_u32v(const char* name = nullptr) {
uint32_t length = 0; uint32_t length = 0;
return read_leb<uint32_t, kValidate, kAdvancePc, kTrace>(pc_, &length, return read_leb<uint32_t, kFullValidation, kAdvancePc, kTrace>(pc_, &length,
name); name);
} }
// Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}. // Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}.
int32_t consume_i32v(const char* name = nullptr) { int32_t consume_i32v(const char* name = nullptr) {
uint32_t length = 0; uint32_t length = 0;
return read_leb<int32_t, kValidate, kAdvancePc, kTrace>(pc_, &length, name); return read_leb<int32_t, kFullValidation, kAdvancePc, kTrace>(pc_, &length,
name);
} }
// Reads a LEB128 variable-length unsigned 64-bit integer and advances {pc_}. // Reads a LEB128 variable-length unsigned 64-bit integer and advances {pc_}.
uint64_t consume_u64v(const char* name = nullptr) { uint64_t consume_u64v(const char* name = nullptr) {
uint32_t length = 0; uint32_t length = 0;
return read_leb<uint64_t, kValidate, kAdvancePc, kTrace>(pc_, &length, return read_leb<uint64_t, kFullValidation, kAdvancePc, kTrace>(pc_, &length,
name); name);
} }
// Consume {size} bytes and send them to the bit bucket, advancing {pc_}. // Consume {size} bytes and send them to the bit bucket, advancing {pc_}.
......
...@@ -1035,7 +1035,8 @@ class WasmDecoder : public Decoder { ...@@ -1035,7 +1035,8 @@ class WasmDecoder : public Decoder {
: local_types_.begin(); : local_types_.begin();
// Decode local declarations, if any. // Decode local declarations, if any.
uint32_t entries = read_u32v<kValidate>(pc, &length, "local decls count"); uint32_t entries =
read_u32v<kFullValidation>(pc, &length, "local decls count");
if (!VALIDATE(ok())) { if (!VALIDATE(ok())) {
error(pc + *total_length, "invalid local decls count"); error(pc + *total_length, "invalid local decls count");
return false; return false;
...@@ -1049,8 +1050,8 @@ class WasmDecoder : public Decoder { ...@@ -1049,8 +1050,8 @@ class WasmDecoder : public Decoder {
error(end(), "expected more local decls but reached end of input"); error(end(), "expected more local decls but reached end of input");
return false; return false;
} }
uint32_t count = uint32_t count = read_u32v<kFullValidation>(pc + *total_length, &length,
read_u32v<kValidate>(pc + *total_length, &length, "local count"); "local count");
if (!VALIDATE(ok())) { if (!VALIDATE(ok())) {
error(pc + *total_length, "invalid local count"); error(pc + *total_length, "invalid local count");
return false; return false;
...@@ -1062,7 +1063,7 @@ class WasmDecoder : public Decoder { ...@@ -1062,7 +1063,7 @@ class WasmDecoder : public Decoder {
} }
*total_length += length; *total_length += length;
ValueType type = value_type_reader::read_value_type<kValidate>( ValueType type = value_type_reader::read_value_type<kFullValidation>(
this, pc + *total_length, &length, enabled_); this, pc + *total_length, &length, enabled_);
if (!VALIDATE(type != kWasmBottom)) { if (!VALIDATE(type != kWasmBottom)) {
error(pc + *total_length, "invalid local type"); error(pc + *total_length, "invalid local type");
...@@ -2006,7 +2007,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2006,7 +2007,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (!WasmOpcodes::IsPrefixOpcode(opcode)) { if (!WasmOpcodes::IsPrefixOpcode(opcode)) {
return WasmOpcodes::OpcodeName(static_cast<WasmOpcode>(opcode)); return WasmOpcodes::OpcodeName(static_cast<WasmOpcode>(opcode));
} }
opcode = this->template read_prefixed_opcode<Decoder::kValidate>(pc); opcode = this->template read_prefixed_opcode<Decoder::kFullValidation>(pc);
return WasmOpcodes::OpcodeName(opcode); return WasmOpcodes::OpcodeName(opcode);
} }
...@@ -2157,7 +2158,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2157,7 +2158,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
WasmOpcode val_opcode = static_cast<WasmOpcode>(*val.pc); WasmOpcode val_opcode = static_cast<WasmOpcode>(*val.pc);
if (WasmOpcodes::IsPrefixOpcode(val_opcode)) { if (WasmOpcodes::IsPrefixOpcode(val_opcode)) {
val_opcode = val_opcode =
decoder_->template read_prefixed_opcode<Decoder::kNoValidate>( decoder_->template read_prefixed_opcode<Decoder::kNoValidation>(
val.pc); val.pc);
} }
Append(" %c@%d:%s", val.type.short_name(), Append(" %c@%d:%s", val.type.short_name(),
...@@ -2168,21 +2169,22 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2168,21 +2169,22 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (decoder_->failed()) continue; if (decoder_->failed()) continue;
switch (val_opcode) { switch (val_opcode) {
case kExprI32Const: { case kExprI32Const: {
ImmI32Immediate<Decoder::kNoValidate> imm(decoder_, val.pc + 1); ImmI32Immediate<Decoder::kNoValidation> imm(decoder_, val.pc + 1);
Append("[%d]", imm.value); Append("[%d]", imm.value);
break; break;
} }
case kExprLocalGet: case kExprLocalGet:
case kExprLocalSet: case kExprLocalSet:
case kExprLocalTee: { case kExprLocalTee: {
LocalIndexImmediate<Decoder::kNoValidate> imm(decoder_, val.pc + 1); LocalIndexImmediate<Decoder::kNoValidation> imm(decoder_,
val.pc + 1);
Append("[%u]", imm.index); Append("[%u]", imm.index);
break; break;
} }
case kExprGlobalGet: case kExprGlobalGet:
case kExprGlobalSet: { case kExprGlobalSet: {
GlobalIndexImmediate<Decoder::kNoValidate> imm(decoder_, GlobalIndexImmediate<Decoder::kNoValidation> imm(decoder_,
val.pc + 1); val.pc + 1);
Append("[%u]", imm.index); Append("[%u]", imm.index);
break; break;
} }
...@@ -4350,7 +4352,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -4350,7 +4352,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
class EmptyInterface { class EmptyInterface {
public: public:
static constexpr Decoder::ValidateFlag validate = Decoder::kValidate; static constexpr Decoder::ValidateFlag validate = Decoder::kFullValidation;
using Value = ValueBase; using Value = ValueBase;
using Control = ControlBase<Value>; using Control = ControlBase<Value>;
using FullDecoder = WasmFullDecoder<validate, EmptyInterface>; using FullDecoder = WasmFullDecoder<validate, EmptyInterface>;
......
...@@ -23,8 +23,8 @@ bool DecodeLocalDecls(const WasmFeatures& enabled, BodyLocalDecls* decls, ...@@ -23,8 +23,8 @@ bool DecodeLocalDecls(const WasmFeatures& enabled, BodyLocalDecls* decls,
const byte* start, const byte* end) { const byte* start, const byte* end) {
WasmFeatures no_features = WasmFeatures::None(); WasmFeatures no_features = WasmFeatures::None();
Zone* zone = decls->type_list.get_allocator().zone(); Zone* zone = decls->type_list.get_allocator().zone();
WasmDecoder<Decoder::kValidate> decoder(zone, nullptr, enabled, &no_features, WasmDecoder<Decoder::kFullValidation> decoder(
nullptr, start, end, 0); zone, nullptr, enabled, &no_features, nullptr, start, end, 0);
uint32_t length; uint32_t length;
if (!decoder.DecodeLocals(decoder.pc(), &length, 0)) { if (!decoder.DecodeLocals(decoder.pc(), &length, 0)) {
decls->encoded_size = 0; decls->encoded_size = 0;
...@@ -54,7 +54,7 @@ DecodeResult VerifyWasmCode(AccountingAllocator* allocator, ...@@ -54,7 +54,7 @@ DecodeResult VerifyWasmCode(AccountingAllocator* allocator,
const WasmModule* module, WasmFeatures* detected, const WasmModule* module, WasmFeatures* detected,
const FunctionBody& body) { const FunctionBody& body) {
Zone zone(allocator, ZONE_NAME); Zone zone(allocator, ZONE_NAME);
WasmFullDecoder<Decoder::kValidate, EmptyInterface> decoder( WasmFullDecoder<Decoder::kFullValidation, EmptyInterface> decoder(
&zone, module, enabled, detected, body); &zone, module, enabled, detected, body);
decoder.Decode(); decoder.Decode();
return decoder.toResult(nullptr); return decoder.toResult(nullptr);
...@@ -65,9 +65,9 @@ unsigned OpcodeLength(const byte* pc, const byte* end) { ...@@ -65,9 +65,9 @@ unsigned OpcodeLength(const byte* pc, const byte* end) {
Zone* no_zone = nullptr; Zone* no_zone = nullptr;
WasmModule* no_module = nullptr; WasmModule* no_module = nullptr;
FunctionSig* no_sig = nullptr; FunctionSig* no_sig = nullptr;
WasmDecoder<Decoder::kNoValidate> decoder(no_zone, no_module, no_features, WasmDecoder<Decoder::kNoValidation> decoder(no_zone, no_module, no_features,
&no_features, no_sig, pc, end, 0); &no_features, no_sig, pc, end, 0);
return WasmDecoder<Decoder::kNoValidate>::OpcodeLength(&decoder, pc); return WasmDecoder<Decoder::kNoValidation>::OpcodeLength(&decoder, pc);
} }
std::pair<uint32_t, uint32_t> StackEffect(const WasmModule* module, std::pair<uint32_t, uint32_t> StackEffect(const WasmModule* module,
...@@ -75,7 +75,7 @@ std::pair<uint32_t, uint32_t> StackEffect(const WasmModule* module, ...@@ -75,7 +75,7 @@ std::pair<uint32_t, uint32_t> StackEffect(const WasmModule* module,
const byte* pc, const byte* end) { const byte* pc, const byte* end) {
WasmFeatures unused_detected_features = WasmFeatures::None(); WasmFeatures unused_detected_features = WasmFeatures::None();
Zone* no_zone = nullptr; Zone* no_zone = nullptr;
WasmDecoder<Decoder::kNoValidate> decoder( WasmDecoder<Decoder::kNoValidation> decoder(
no_zone, module, WasmFeatures::All(), &unused_detected_features, sig, pc, no_zone, module, WasmFeatures::All(), &unused_detected_features, sig, pc,
end); end);
return decoder.StackEffect(pc); return decoder.StackEffect(pc);
...@@ -124,9 +124,9 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, ...@@ -124,9 +124,9 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
std::ostream& os, std::vector<int>* line_numbers) { std::ostream& os, std::vector<int>* line_numbers) {
Zone zone(allocator, ZONE_NAME); Zone zone(allocator, ZONE_NAME);
WasmFeatures unused_detected_features = WasmFeatures::None(); WasmFeatures unused_detected_features = WasmFeatures::None();
WasmDecoder<Decoder::kNoValidate> decoder(&zone, module, WasmFeatures::All(), WasmDecoder<Decoder::kNoValidation> decoder(
&unused_detected_features, body.sig, &zone, module, WasmFeatures::All(), &unused_detected_features, body.sig,
body.start, body.end); body.start, body.end);
int line_nr = 0; int line_nr = 0;
constexpr int kNoByteCode = -1; constexpr int kNoByteCode = -1;
...@@ -174,7 +174,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, ...@@ -174,7 +174,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
unsigned control_depth = 0; unsigned control_depth = 0;
for (; i.has_next(); i.next()) { for (; i.has_next(); i.next()) {
unsigned length = unsigned length =
WasmDecoder<Decoder::kNoValidate>::OpcodeLength(&decoder, i.pc()); WasmDecoder<Decoder::kNoValidation>::OpcodeLength(&decoder, i.pc());
unsigned offset = 1; unsigned offset = 1;
WasmOpcode opcode = i.current(); WasmOpcode opcode = i.current();
...@@ -243,8 +243,8 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, ...@@ -243,8 +243,8 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
case kExprIf: case kExprIf:
case kExprBlock: case kExprBlock:
case kExprTry: { case kExprTry: {
BlockTypeImmediate<Decoder::kNoValidate> imm(WasmFeatures::All(), &i, BlockTypeImmediate<Decoder::kNoValidation> imm(WasmFeatures::All(), &i,
i.pc() + 1); i.pc() + 1);
os << " @" << i.pc_offset(); os << " @" << i.pc_offset();
if (decoder.Complete(imm)) { if (decoder.Complete(imm)) {
for (uint32_t i = 0; i < imm.out_arity(); i++) { for (uint32_t i = 0; i < imm.out_arity(); i++) {
...@@ -259,23 +259,23 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, ...@@ -259,23 +259,23 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
control_depth--; control_depth--;
break; break;
case kExprBr: { case kExprBr: {
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc() + 1); BranchDepthImmediate<Decoder::kNoValidation> imm(&i, i.pc() + 1);
os << " depth=" << imm.depth; os << " depth=" << imm.depth;
break; break;
} }
case kExprBrIf: { case kExprBrIf: {
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc() + 1); BranchDepthImmediate<Decoder::kNoValidation> imm(&i, i.pc() + 1);
os << " depth=" << imm.depth; os << " depth=" << imm.depth;
break; break;
} }
case kExprBrTable: { case kExprBrTable: {
BranchTableImmediate<Decoder::kNoValidate> imm(&i, i.pc() + 1); BranchTableImmediate<Decoder::kNoValidation> imm(&i, i.pc() + 1);
os << " entries=" << imm.table_count; os << " entries=" << imm.table_count;
break; break;
} }
case kExprCallIndirect: { case kExprCallIndirect: {
CallIndirectImmediate<Decoder::kNoValidate> imm(WasmFeatures::All(), &i, CallIndirectImmediate<Decoder::kNoValidation> imm(WasmFeatures::All(),
i.pc() + 1); &i, i.pc() + 1);
os << " sig #" << imm.sig_index; os << " sig #" << imm.sig_index;
if (decoder.Complete(imm)) { if (decoder.Complete(imm)) {
os << ": " << *imm.sig; os << ": " << *imm.sig;
...@@ -283,7 +283,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, ...@@ -283,7 +283,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
break; break;
} }
case kExprCallFunction: { case kExprCallFunction: {
CallFunctionImmediate<Decoder::kNoValidate> imm(&i, i.pc() + 1); CallFunctionImmediate<Decoder::kNoValidation> imm(&i, i.pc() + 1);
os << " function #" << imm.index; os << " function #" << imm.index;
if (decoder.Complete(imm)) { if (decoder.Complete(imm)) {
os << ": " << *imm.sig; os << ": " << *imm.sig;
...@@ -304,9 +304,9 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, ...@@ -304,9 +304,9 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
const byte* start, const byte* end) { const byte* start, const byte* end) {
WasmFeatures no_features = WasmFeatures::None(); WasmFeatures no_features = WasmFeatures::None();
WasmDecoder<Decoder::kValidate> decoder(zone, nullptr, no_features, WasmDecoder<Decoder::kFullValidation> decoder(
&no_features, nullptr, start, end, 0); zone, nullptr, no_features, &no_features, nullptr, start, end, 0);
return WasmDecoder<Decoder::kValidate>::AnalyzeLoopAssignment( return WasmDecoder<Decoder::kFullValidation>::AnalyzeLoopAssignment(
&decoder, start, static_cast<uint32_t>(num_locals), zone); &decoder, start, static_cast<uint32_t>(num_locals), zone);
} }
......
...@@ -163,7 +163,7 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) { ...@@ -163,7 +163,7 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
WasmOpcode current() { WasmOpcode current() {
return static_cast<WasmOpcode>( return static_cast<WasmOpcode>(
read_u8<Decoder::kNoValidate>(pc_, "expected bytecode")); read_u8<Decoder::kNoValidation>(pc_, "expected bytecode"));
} }
void next() { void next() {
...@@ -176,7 +176,7 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) { ...@@ -176,7 +176,7 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
bool has_next() { return pc_ < end_; } bool has_next() { return pc_ < end_; }
WasmOpcode prefixed_opcode() { WasmOpcode prefixed_opcode() {
return read_prefixed_opcode<Decoder::kNoValidate>(pc_); return read_prefixed_opcode<Decoder::kNoValidation>(pc_);
} }
}; };
......
...@@ -74,7 +74,7 @@ constexpr uint32_t kNullCatch = static_cast<uint32_t>(-1); ...@@ -74,7 +74,7 @@ constexpr uint32_t kNullCatch = static_cast<uint32_t>(-1);
class WasmGraphBuildingInterface { class WasmGraphBuildingInterface {
public: public:
static constexpr Decoder::ValidateFlag validate = Decoder::kValidate; static constexpr Decoder::ValidateFlag validate = Decoder::kFullValidation;
using FullDecoder = WasmFullDecoder<validate, WasmGraphBuildingInterface>; using FullDecoder = WasmFullDecoder<validate, WasmGraphBuildingInterface>;
using CheckForNull = compiler::WasmGraphBuilder::CheckForNull; using CheckForNull = compiler::WasmGraphBuilder::CheckForNull;
...@@ -1200,7 +1200,7 @@ DecodeResult BuildTFGraph(AccountingAllocator* allocator, ...@@ -1200,7 +1200,7 @@ DecodeResult BuildTFGraph(AccountingAllocator* allocator,
WasmFeatures* detected, const FunctionBody& body, WasmFeatures* detected, const FunctionBody& body,
compiler::NodeOriginTable* node_origins) { compiler::NodeOriginTable* node_origins) {
Zone zone(allocator, ZONE_NAME); Zone zone(allocator, ZONE_NAME);
WasmFullDecoder<Decoder::kValidate, WasmGraphBuildingInterface> decoder( WasmFullDecoder<Decoder::kFullValidation, WasmGraphBuildingInterface> decoder(
&zone, module, enabled, detected, body, builder); &zone, module, enabled, detected, body, builder);
if (node_origins) { if (node_origins) {
builder->AddBytecodePositionDecorator(node_origins, &decoder); builder->AddBytecodePositionDecorator(node_origins, &decoder);
......
...@@ -1618,7 +1618,8 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1618,7 +1618,8 @@ class ModuleDecoderImpl : public Decoder {
// TODO(manoskouk): This is copy-modified from function-body-decoder-impl.h. // TODO(manoskouk): This is copy-modified from function-body-decoder-impl.h.
// We should find a way to share this code. // We should find a way to share this code.
V8_INLINE bool Validate(const byte* pc, HeapTypeImmediate<kValidate>& imm) { V8_INLINE bool Validate(const byte* pc,
HeapTypeImmediate<kFullValidation>& imm) {
if (V8_UNLIKELY(imm.type.is_bottom())) { if (V8_UNLIKELY(imm.type.is_bottom())) {
error(pc, "invalid heap type"); error(pc, "invalid heap type");
return false; return false;
...@@ -1633,7 +1634,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1633,7 +1634,7 @@ class ModuleDecoderImpl : public Decoder {
WasmInitExpr consume_init_expr(WasmModule* module, ValueType expected, WasmInitExpr consume_init_expr(WasmModule* module, ValueType expected,
size_t current_global_index) { size_t current_global_index) {
constexpr Decoder::ValidateFlag validate = Decoder::kValidate; constexpr Decoder::ValidateFlag validate = Decoder::kFullValidation;
WasmOpcode opcode = kExprNop; WasmOpcode opcode = kExprNop;
std::vector<WasmInitExpr> stack; std::vector<WasmInitExpr> stack;
while (pc() < end() && opcode != kExprEnd) { while (pc() < end() && opcode != kExprEnd) {
...@@ -1670,25 +1671,25 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1670,25 +1671,25 @@ class ModuleDecoderImpl : public Decoder {
break; break;
} }
case kExprI32Const: { case kExprI32Const: {
ImmI32Immediate<Decoder::kValidate> imm(this, pc() + 1); ImmI32Immediate<Decoder::kFullValidation> imm(this, pc() + 1);
stack.emplace_back(imm.value); stack.emplace_back(imm.value);
len = 1 + imm.length; len = 1 + imm.length;
break; break;
} }
case kExprF32Const: { case kExprF32Const: {
ImmF32Immediate<Decoder::kValidate> imm(this, pc() + 1); ImmF32Immediate<Decoder::kFullValidation> imm(this, pc() + 1);
stack.emplace_back(imm.value); stack.emplace_back(imm.value);
len = 1 + imm.length; len = 1 + imm.length;
break; break;
} }
case kExprI64Const: { case kExprI64Const: {
ImmI64Immediate<Decoder::kValidate> imm(this, pc() + 1); ImmI64Immediate<Decoder::kFullValidation> imm(this, pc() + 1);
stack.emplace_back(imm.value); stack.emplace_back(imm.value);
len = 1 + imm.length; len = 1 + imm.length;
break; break;
} }
case kExprF64Const: { case kExprF64Const: {
ImmF64Immediate<Decoder::kValidate> imm(this, pc() + 1); ImmF64Immediate<Decoder::kFullValidation> imm(this, pc() + 1);
stack.emplace_back(imm.value); stack.emplace_back(imm.value);
len = 1 + imm.length; len = 1 + imm.length;
break; break;
...@@ -1702,8 +1703,8 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1702,8 +1703,8 @@ class ModuleDecoderImpl : public Decoder {
kExprRefNull); kExprRefNull);
return {}; return {};
} }
HeapTypeImmediate<Decoder::kValidate> imm(enabled_features_, this, HeapTypeImmediate<Decoder::kFullValidation> imm(enabled_features_,
pc() + 1); this, pc() + 1);
len = 1 + imm.length; len = 1 + imm.length;
if (!Validate(pc() + 1, imm)) return {}; if (!Validate(pc() + 1, imm)) return {};
stack.push_back( stack.push_back(
...@@ -1719,7 +1720,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1719,7 +1720,7 @@ class ModuleDecoderImpl : public Decoder {
return {}; return {};
} }
FunctionIndexImmediate<Decoder::kValidate> imm(this, pc() + 1); FunctionIndexImmediate<Decoder::kFullValidation> imm(this, pc() + 1);
len = 1 + imm.length; len = 1 + imm.length;
if (V8_UNLIKELY(module->functions.size() <= imm.index)) { if (V8_UNLIKELY(module->functions.size() <= imm.index)) {
errorf(pc(), "invalid function index: %u", imm.index); errorf(pc(), "invalid function index: %u", imm.index);
...@@ -1836,7 +1837,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1836,7 +1837,7 @@ class ModuleDecoderImpl : public Decoder {
ValueType consume_value_type() { ValueType consume_value_type() {
uint32_t type_length; uint32_t type_length;
ValueType result = value_type_reader::read_value_type<kValidate>( ValueType result = value_type_reader::read_value_type<kFullValidation>(
this, this->pc(), &type_length, this, this->pc(), &type_length,
origin_ == kWasmOrigin ? enabled_features_ : WasmFeatures::None()); origin_ == kWasmOrigin ? enabled_features_ : WasmFeatures::None());
if (result == kWasmBottom) error(pc_, "invalid value type"); if (result == kWasmBottom) error(pc_, "invalid value type");
...@@ -1850,7 +1851,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1850,7 +1851,7 @@ class ModuleDecoderImpl : public Decoder {
} }
ValueType consume_storage_type() { ValueType consume_storage_type() {
uint8_t opcode = read_u8<kValidate>(this->pc()); uint8_t opcode = read_u8<kFullValidation>(this->pc());
switch (opcode) { switch (opcode) {
case kI8Code: case kI8Code:
consume_bytes(1, "i8"); consume_bytes(1, "i8");
...@@ -2133,7 +2134,8 @@ class ModuleDecoderImpl : public Decoder { ...@@ -2133,7 +2134,8 @@ class ModuleDecoderImpl : public Decoder {
if (failed()) return index; if (failed()) return index;
switch (opcode) { switch (opcode) {
case kExprRefNull: { case kExprRefNull: {
HeapTypeImmediate<kValidate> imm(WasmFeatures::All(), this, this->pc()); HeapTypeImmediate<kFullValidation> imm(WasmFeatures::All(), this,
this->pc());
consume_bytes(imm.length, "ref.null immediate"); consume_bytes(imm.length, "ref.null immediate");
index = WasmElemSegment::kNullIndex; index = WasmElemSegment::kNullIndex;
break; break;
......
This diff is collapsed.
This diff is collapsed.
...@@ -4258,15 +4258,15 @@ class BranchTableIteratorTest : public TestWithZone { ...@@ -4258,15 +4258,15 @@ class BranchTableIteratorTest : public TestWithZone {
BranchTableIteratorTest() : TestWithZone() {} BranchTableIteratorTest() : TestWithZone() {}
void CheckBrTableSize(const byte* start, const byte* end) { void CheckBrTableSize(const byte* start, const byte* end) {
Decoder decoder(start, end); Decoder decoder(start, end);
BranchTableImmediate<Decoder::kValidate> operand(&decoder, start + 1); BranchTableImmediate<Decoder::kFullValidation> operand(&decoder, start + 1);
BranchTableIterator<Decoder::kValidate> iterator(&decoder, operand); BranchTableIterator<Decoder::kFullValidation> iterator(&decoder, operand);
EXPECT_EQ(end - start - 1u, iterator.length()); EXPECT_EQ(end - start - 1u, iterator.length());
EXPECT_OK(decoder); EXPECT_OK(decoder);
} }
void CheckBrTableError(const byte* start, const byte* end) { void CheckBrTableError(const byte* start, const byte* end) {
Decoder decoder(start, end); Decoder decoder(start, end);
BranchTableImmediate<Decoder::kValidate> operand(&decoder, start + 1); BranchTableImmediate<Decoder::kFullValidation> operand(&decoder, start + 1);
BranchTableIterator<Decoder::kValidate> iterator(&decoder, operand); BranchTableIterator<Decoder::kFullValidation> iterator(&decoder, operand);
iterator.length(); iterator.length();
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -4360,10 +4360,10 @@ class WasmOpcodeLengthTest : public TestWithZone { ...@@ -4360,10 +4360,10 @@ class WasmOpcodeLengthTest : public TestWithZone {
void ExpectFailure(Bytes... bytes) { void ExpectFailure(Bytes... bytes) {
const byte code[] = {bytes..., 0, 0, 0, 0, 0, 0, 0, 0}; const byte code[] = {bytes..., 0, 0, 0, 0, 0, 0, 0, 0};
WasmFeatures no_features = WasmFeatures::None(); WasmFeatures no_features = WasmFeatures::None();
WasmDecoder<Decoder::kValidate> decoder(this->zone(), nullptr, no_features, WasmDecoder<Decoder::kFullValidation> decoder(
&no_features, nullptr, code, this->zone(), nullptr, no_features, &no_features, nullptr, code,
code + sizeof(code), 0); code + sizeof(code), 0);
WasmDecoder<Decoder::kValidate>::OpcodeLength(&decoder, code); WasmDecoder<Decoder::kFullValidation>::OpcodeLength(&decoder, code);
EXPECT_EQ(decoder.failed(), true); EXPECT_EQ(decoder.failed(), true);
} }
}; };
......
...@@ -88,19 +88,20 @@ TEST_F(LEBHelperTest, sizeof_i32v) { ...@@ -88,19 +88,20 @@ TEST_F(LEBHelperTest, sizeof_i32v) {
} }
} }
#define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \ #define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \
static void CheckEncodeDecode_##name(ctype val) { \ static void CheckEncodeDecode_##name(ctype val) { \
static const int kSize = 16; \ static const int kSize = 16; \
static byte buffer[kSize]; \ static byte buffer[kSize]; \
byte* ptr = buffer; \ byte* ptr = buffer; \
LEBHelper::write_##name(&ptr, val); \ LEBHelper::write_##name(&ptr, val); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), \ EXPECT_EQ(LEBHelper::sizeof_##name(val), \
static_cast<size_t>(ptr - buffer)); \ static_cast<size_t>(ptr - buffer)); \
Decoder decoder(buffer, buffer + kSize); \ Decoder decoder(buffer, buffer + kSize); \
unsigned length = 0; \ unsigned length = 0; \
ctype result = decoder.read_##name<Decoder::kNoValidate>(buffer, &length); \ ctype result = \
EXPECT_EQ(val, result); \ decoder.read_##name<Decoder::kNoValidation>(buffer, &length); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \ EXPECT_EQ(val, result); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \
} }
DECLARE_ENCODE_DECODE_CHECKER(int32_t, i32v) DECLARE_ENCODE_DECODE_CHECKER(int32_t, i32v)
......
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