Enum wasmtime_environ::wasmparser::Payload [−][src]
pub enum Payload<'a> {
Show 22 variants
Version {
num: u32,
range: Range,
},
TypeSection(TypeSectionReader<'a>),
ImportSection(ImportSectionReader<'a>),
AliasSection(AliasSectionReader<'a>),
InstanceSection(InstanceSectionReader<'a>),
FunctionSection(FunctionSectionReader<'a>),
TableSection(TableSectionReader<'a>),
MemorySection(MemorySectionReader<'a>),
TagSection(TagSectionReader<'a>),
GlobalSection(GlobalSectionReader<'a>),
ExportSection(ExportSectionReader<'a>),
StartSection {
func: u32,
range: Range,
},
ElementSection(ElementSectionReader<'a>),
DataCountSection {
count: u32,
range: Range,
},
DataSection(DataSectionReader<'a>),
CustomSection {
name: &'a str,
data_offset: usize,
data: &'a [u8],
range: Range,
},
CodeSectionStart {
count: u32,
range: Range,
size: u32,
},
CodeSectionEntry(FunctionBody<'a>),
ModuleSectionStart {
count: u32,
range: Range,
size: u32,
},
ModuleSectionEntry {
parser: Parser,
range: Range,
},
UnknownSection {
id: u8,
contents: &'a [u8],
range: Range,
},
End,
}
Expand description
Values that can be parsed from a wasm module.
This enumeration is all possible chunks of pieces that can be parsed by a
Parser
from a binary WebAssembly module. Note that for many sections the
entire section is parsed all at once, whereas other functions, like the code
section, are parsed incrementally. This is a distinction where some
sections, like the type section, are required to be fully resident in memory
(fully downloaded) before proceeding. Other sections, like the code section,
can be processed in a streaming fashion where each function is extracted
individually so it can possibly be shipped to another thread while you wait
for more functions to get downloaded.
Note that payloads, when returned, do not indicate that the wasm module is
valid. For example when you receive a Payload::TypeSection
the type
section itself has not yet actually been parsed. The reader returned will be
able to parse it, but you’ll have to actually iterate the reader to do the
full parse. Each payload returned is intended to be a window into the
original data
passed to Parser::parse
which can be further processed
if necessary.
Variants
Indicates the header of a WebAssembly binary.
This header also indicates the version number that was parsed, which is currently always 1.
Fields of Version
TypeSection(TypeSectionReader<'a>)
A type section was received, and the provided reader can be used to parse the contents of the type section.
Tuple Fields of TypeSection
0: TypeSectionReader<'a>
ImportSection(ImportSectionReader<'a>)
A import section was received, and the provided reader can be used to parse the contents of the import section.
Tuple Fields of ImportSection
0: ImportSectionReader<'a>
AliasSection(AliasSectionReader<'a>)
An alias section was received, and the provided reader can be used to parse the contents of the alias section.
Tuple Fields of AliasSection
0: AliasSectionReader<'a>
InstanceSection(InstanceSectionReader<'a>)
An instance section was received, and the provided reader can be used to parse the contents of the instance section.
Tuple Fields of InstanceSection
0: InstanceSectionReader<'a>
FunctionSection(FunctionSectionReader<'a>)
A function section was received, and the provided reader can be used to parse the contents of the function section.
Tuple Fields of FunctionSection
0: FunctionSectionReader<'a>
TableSection(TableSectionReader<'a>)
A table section was received, and the provided reader can be used to parse the contents of the table section.
Tuple Fields of TableSection
0: TableSectionReader<'a>
MemorySection(MemorySectionReader<'a>)
A memory section was received, and the provided reader can be used to parse the contents of the memory section.
Tuple Fields of MemorySection
0: MemorySectionReader<'a>
TagSection(TagSectionReader<'a>)
An tag section was received, and the provided reader can be used to parse the contents of the tag section.
Tuple Fields of TagSection
0: TagSectionReader<'a>
GlobalSection(GlobalSectionReader<'a>)
A global section was received, and the provided reader can be used to parse the contents of the global section.
Tuple Fields of GlobalSection
0: GlobalSectionReader<'a>
ExportSection(ExportSectionReader<'a>)
An export section was received, and the provided reader can be used to parse the contents of the export section.
Tuple Fields of ExportSection
0: ExportSectionReader<'a>
A start section was received, and the u32
here is the index of the
start function.
Fields of StartSection
ElementSection(ElementSectionReader<'a>)
An element section was received, and the provided reader can be used to parse the contents of the element section.
Tuple Fields of ElementSection
0: ElementSectionReader<'a>
A data count section was received, and the u32
here is the contents of
the data count section.
Fields of DataCountSection
DataSection(DataSectionReader<'a>)
A data section was received, and the provided reader can be used to parse the contents of the data section.
Tuple Fields of DataSection
0: DataSectionReader<'a>
A custom section was found.
Fields of CustomSection
name: &'a str
The name of the custom section.
data_offset: usize
The offset, relative to the start of the original module, that the
data
payload for this custom section starts at.
data: &'a [u8]
The actual contents of the custom section.
range: Range
The range of bytes that specify this whole custom section (including both the name of this custom section and its data) specified in offsets relative to the start of the byte stream.
Indicator of the start of the code section.
This entry is returned whenever the code section starts. The count
field indicates how many entries are in this code section. After
receiving this start marker you’re guaranteed that the next count
items will be either CodeSectionEntry
or an error will be returned.
This, unlike other sections, is intended to be used for streaming the
contents of the code section. The code section is not required to be
fully resident in memory when we parse it. Instead a Parser
is
capable of parsing piece-by-piece of a code section.
Fields of CodeSectionStart
count: u32
The number of functions in this section.
range: Range
The range of bytes that represent this section, specified in offsets relative to the start of the byte stream.
size: u32
The size, in bytes, of the remaining contents of this section.
This can be used in combination with Parser::skip_section
where the caller will know how many bytes to skip before feeding
bytes into Parser
again.
CodeSectionEntry(FunctionBody<'a>)
An entry of the code section, a function, was parsed.
This entry indicates that a function was successfully received from the
code section, and the payload here is the window into the original input
where the function resides. Note that the function itself has not been
parsed, it’s only been outlined. You’ll need to process the
FunctionBody
provided to test whether it parses and/or is valid.
Tuple Fields of CodeSectionEntry
0: FunctionBody<'a>
Indicator of the start of the module code section.
This behaves the same as the CodeSectionStart
payload being returned.
You’re guaranteed the next count
items will be of type
ModuleSectionEntry
.
Fields of ModuleSectionStart
An entry of the module code section, a module, was parsed.
This variant is special in that it returns a sub-Parser
. Upon
receiving a ModuleSectionEntry
it is expected that the returned
Parser
will be used instead of the parent Parser
until the parse has
finished. You’ll need to feed data into the Parser
returned until it
returns Payload::End
. After that you’ll switch back to the parent
parser to resume parsing the rest of the module code section.
Note that binaries will not be parsed correctly if you feed the data for
a nested module into the parent Parser
.
Fields of ModuleSectionEntry
An unknown section was found.
This variant is returned for all unknown sections in a wasm file. This likely wants to be interpreted as an error by consumers of the parser, but this can also be used to parse sections unknown to wasmparser at this time.
Fields of UnknownSection
The end of the WebAssembly module was reached.