Struct wasmtime_environ::wasm::wasmparser::Validator [−][src]
pub struct Validator { /* fields omitted */ }
Expand description
Validator for a WebAssembly binary module.
This structure encapsulates state necessary to validate a WebAssembly
binary. This implements validation as defined by the core
specification. A Validator
is designed, like
Parser
, to accept incremental input over time.
Additionally a Validator
is also designed for parallel validation of
functions as they are received.
It’s expected that you’ll be using a Parser
in tandem with a
Validator
. As each Payload
is received from a
Parser
you’ll pass it into a Validator
to test the validity of the
payload. Note that all payloads received from a Parser
are expected to
be passed to a Validator
. For example if you receive
Payload::TypeSection
you’ll call
Validator::type_section
to validate this.
The design of Validator
is intended that you’ll interleave, in your own
application’s processing, calls to validation. Each variant, after it’s
received, will be validated and then your application would proceed as
usual. At all times, however, you’ll have access to the Validator
and
the validation context up to that point. This enables applications to check
the types of functions and learn how many globals there are, for example.
Implementations
Configures the enabled WebAssembly features for this Validator
.
Validates an entire in-memory module with this validator.
This function will internally create a Parser
to parse the bytes
provided. The entire wasm module specified by bytes
will be parsed and
validated. Parse and validation errors will be returned through
Err(_)
, and otherwise a successful validation means Ok(())
is
returned.
pub fn payload(
&mut self,
payload: &Payload<'a>
) -> Result<ValidPayload<'a>, BinaryReaderError>
[src]
pub fn payload(
&mut self,
payload: &Payload<'a>
) -> Result<ValidPayload<'a>, BinaryReaderError>
[src]Convenience function to validate a single Payload
.
This function is intended to be used as a convenience. It will
internally perform any validation necessary to validate the Payload
provided. The convenience part is that you’re likely already going to
be matching on Payload
in your application, at which point it’s more
appropriate to call the individual methods on Validator
per-variant
in Payload
, such as Validator::type_section
.
This function returns a ValidPayload
variant on success, indicating
one of a few possible actions that need to be taken after a payload is
validated. For example function contents are not validated here, they’re
returned through ValidPayload
for validation by the caller.
Validates Payload::Version
pub fn type_section(
&mut self,
section: &TypeSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn type_section(
&mut self,
section: &TypeSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::TypeSection
pub fn import_section(
&mut self,
section: &ImportSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn import_section(
&mut self,
section: &ImportSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::ImportSection
pub fn module_section_start(
&mut self,
count: u32,
range: &Range
) -> Result<(), BinaryReaderError>
[src]
pub fn module_section_start(
&mut self,
count: u32,
range: &Range
) -> Result<(), BinaryReaderError>
[src]Validates Payload::ModuleSectionStart
Validates Payload::ModuleSectionEntry
.
Note that this does not actually perform any validation itself. The
ModuleSectionEntry
payload is associated with a sub-parser for the
sub-module, and it’s expected that the events from the Parser
are fed into this validator.
pub fn alias_section(
&mut self,
section: &AliasSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn alias_section(
&mut self,
section: &AliasSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::AliasSection
pub fn instance_section(
&mut self,
section: &InstanceSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn instance_section(
&mut self,
section: &InstanceSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::InstanceSection
pub fn function_section(
&mut self,
section: &FunctionSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn function_section(
&mut self,
section: &FunctionSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::FunctionSection
pub fn table_section(
&mut self,
section: &TableSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn table_section(
&mut self,
section: &TableSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::TableSection
pub fn memory_section(
&mut self,
section: &MemorySectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]pub fn event_section(
&mut self,
section: &EventSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]pub fn global_section(
&mut self,
section: &GlobalSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn global_section(
&mut self,
section: &GlobalSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::GlobalSection
pub fn export_section(
&mut self,
section: &ExportSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn export_section(
&mut self,
section: &ExportSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::ExportSection
Validates Payload::StartSection
pub fn element_section(
&mut self,
section: &ElementSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn element_section(
&mut self,
section: &ElementSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::ElementSection
pub fn data_count_section(
&mut self,
count: u32,
range: &Range
) -> Result<(), BinaryReaderError>
[src]
pub fn data_count_section(
&mut self,
count: u32,
range: &Range
) -> Result<(), BinaryReaderError>
[src]Validates Payload::DataCountSection
pub fn code_section_start(
&mut self,
count: u32,
range: &Range
) -> Result<(), BinaryReaderError>
[src]
pub fn code_section_start(
&mut self,
count: u32,
range: &Range
) -> Result<(), BinaryReaderError>
[src]Validates Payload::CodeSectionStart
.
pub fn code_section_entry(
&mut self
) -> Result<FuncValidator<ValidatorResources>, BinaryReaderError>
[src]
pub fn code_section_entry(
&mut self
) -> Result<FuncValidator<ValidatorResources>, BinaryReaderError>
[src]Validates Payload::CodeSectionEntry
.
This function will prepare a FuncValidator
which can be used to
validate the function. The function body provided will be parsed only
enough to create the function validation context. After this the
OperatorsReader
returned can be used to read the
opcodes of the function as well as feed information into the validator.
Note that the returned FuncValidator
is “connected” to this
Validator
in that it uses the internal context of this validator for
validating the function. The FuncValidator
can be sent to
another thread, for example, to offload actual processing of functions
elsewhere.
pub fn data_section(
&mut self,
section: &DataSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]
pub fn data_section(
&mut self,
section: &DataSectionReader<'_>
) -> Result<(), BinaryReaderError>
[src]Validates Payload::DataSection
.
Validates Payload::UnknownSection
.
Currently always returns an error.
Validates Payload::End
.
Trait Implementations
Returns the linear memory at given index.
Returns the event at given index.
Returns the global variable at given index.
pub fn func_type_at(
&self,
type_idx: u32
) -> Option<&<Validator as WasmModuleResources>::FuncType>
[src]
pub fn func_type_at(
&self,
type_idx: u32
) -> Option<&<Validator as WasmModuleResources>::FuncType>
[src]Returns the FuncType
associated with the given type index.
pub fn type_of_function(
&self,
func_idx: u32
) -> Option<&<Validator as WasmModuleResources>::FuncType>
[src]
pub fn type_of_function(
&self,
func_idx: u32
) -> Option<&<Validator as WasmModuleResources>::FuncType>
[src]Returns the FuncType
associated with the given function index.
Returns the element type at the given index.
Returns the number of elements.
Returns the number of bytes in the Wasm data section.
Returns whether the function index is referenced in the module anywhere outside of the start/function sections. Read more
Auto Trait Implementations
impl RefUnwindSafe for Validator
impl UnwindSafe for Validator