1 /* Copyright 2017 Mozilla Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 //! A simple event-driven library for parsing WebAssembly binary files
17 //! (or streams).
18 //!
19 //! The parser library reports events as they happend and only stores
20 //! parsing information for a brief period of time, making it very fast
21 //! and memory-efficient. The event-driven model, however, has some drawbacks.
22 //! If you need random access to the entire WebAssembly data-structure,
23 //! this is not the right library for you. You could however, build such
24 //! a data-structure using this library.
25 
26 #![cfg_attr(not(feature = "std"), no_std)]
27 
28 #[cfg(not(feature = "std"))]
29 #[macro_use]
30 extern crate alloc as std;
31 #[cfg(feature = "std")]
32 #[macro_use]
33 extern crate std;
34 
35 #[cfg(not(feature = "std"))]
36 use hashbrown::HashSet;
37 #[cfg(feature = "std")]
38 use std::collections::HashSet;
39 
40 pub use crate::binary_reader::BinaryReader;
41 pub use crate::binary_reader::Range;
42 use crate::binary_reader::SectionHeader;
43 
44 pub use crate::parser::LocalName;
45 pub use crate::parser::NameEntry;
46 pub use crate::parser::Parser;
47 pub use crate::parser::ParserInput;
48 pub use crate::parser::ParserState;
49 pub use crate::parser::RelocEntry;
50 pub use crate::parser::WasmDecoder;
51 
52 pub use crate::primitives::BinaryReaderError;
53 pub use crate::primitives::BrTable;
54 pub use crate::primitives::CustomSectionKind;
55 pub use crate::primitives::ExternalKind;
56 pub use crate::primitives::FuncType;
57 pub use crate::primitives::GlobalType;
58 pub use crate::primitives::Ieee32;
59 pub use crate::primitives::Ieee64;
60 pub use crate::primitives::ImportSectionEntryType;
61 pub use crate::primitives::LinkingType;
62 pub use crate::primitives::MemoryImmediate;
63 pub use crate::primitives::MemoryType;
64 pub use crate::primitives::NameType;
65 pub use crate::primitives::Naming;
66 pub use crate::primitives::Operator;
67 pub use crate::primitives::RelocType;
68 pub use crate::primitives::ResizableLimits;
69 pub use crate::primitives::Result;
70 pub use crate::primitives::SectionCode;
71 pub use crate::primitives::TableType;
72 pub use crate::primitives::Type;
73 pub use crate::primitives::TypeOrFuncType;
74 pub use crate::primitives::V128;
75 
76 pub use crate::validator::validate;
77 pub use crate::validator::validate_function_body;
78 pub use crate::validator::ValidatingOperatorParser;
79 pub use crate::validator::ValidatingParser;
80 pub use crate::validator::ValidatingParserConfig;
81 
82 pub use crate::operators_validator::OperatorValidatorConfig;
83 pub use crate::operators_validator::WasmModuleResources;
84 
85 pub use crate::readers::CodeSectionReader;
86 pub use crate::readers::CustomSectionContent;
87 pub use crate::readers::Data;
88 pub use crate::readers::DataKind;
89 pub use crate::readers::DataSectionReader;
90 pub use crate::readers::Element;
91 pub use crate::readers::ElementItems;
92 pub use crate::readers::ElementItemsReader;
93 pub use crate::readers::ElementKind;
94 pub use crate::readers::ElementSectionReader;
95 pub use crate::readers::Export;
96 pub use crate::readers::ExportSectionReader;
97 pub use crate::readers::FunctionBody;
98 pub use crate::readers::FunctionSectionReader;
99 pub use crate::readers::Global;
100 pub use crate::readers::GlobalSectionReader;
101 pub use crate::readers::Import;
102 pub use crate::readers::ImportSectionReader;
103 pub use crate::readers::InitExpr;
104 pub use crate::readers::LinkingSectionReader;
105 pub use crate::readers::LocalsReader;
106 pub use crate::readers::MemorySectionReader;
107 pub use crate::readers::ModuleReader;
108 pub use crate::readers::Name;
109 pub use crate::readers::NameSectionReader;
110 pub use crate::readers::NamingReader;
111 pub use crate::readers::OperatorsReader;
112 pub use crate::readers::ProducersField;
113 pub use crate::readers::ProducersFieldValue;
114 pub use crate::readers::ProducersSectionReader;
115 pub use crate::readers::Reloc;
116 pub use crate::readers::RelocSectionReader;
117 pub use crate::readers::Section;
118 pub use crate::readers::SectionContent;
119 pub use crate::readers::SectionIterator;
120 pub use crate::readers::SectionIteratorLimited;
121 pub use crate::readers::SectionReader;
122 pub use crate::readers::SectionWithLimitedItems;
123 pub use crate::readers::TableSectionReader;
124 pub use crate::readers::TypeSectionReader;
125 
126 mod binary_reader;
127 mod limits;
128 mod operators_validator;
129 mod parser;
130 mod primitives;
131 mod readers;
132 mod tests;
133 mod validator;
134