| 1 | /* Copyright 2018 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 | use craterust-analyzer cargo wasmparser 0.239.0 crate/::{BinaryReaderrust-analyzer cargo wasmparser 0.239.0 binary_reader/BinaryReader#, FromReaderrust-analyzer cargo wasmparser 0.239.0 readers/FromReader#, MemoryTyperust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#, Resultrust-analyzer cargo wasmparser 0.239.0 binary_reader/Result#, SectionLimitedrust-analyzer cargo wasmparser 0.239.0 readers/SectionLimited#}; |
| 17 | |
| 18 | /// A reader for the memory section of a WebAssembly module. |
| 19 | pub type MemorySectionReaderrust-analyzer cargo wasmparser 0.239.0 readers/core/memories/MemorySectionReader#<'a> = SectionLimitedrust-analyzer cargo wasmparser 0.239.0 readers/SectionLimited#<'a, MemoryTyperust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#>; |
| 20 | |
| 21 | impl<'a> FromReaderrust-analyzer cargo wasmparser 0.239.0 readers/FromReader#<'a> for MemoryTyperust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType# { |
| 22 | fn from_readerrust-analyzer cargo wasmparser 0.239.0 readers/core/memories/impl#[MemoryType][`FromReader<'a>`]from_reader().(reader: &mut BinaryReaderrust-analyzer cargo wasmparser 0.239.0 binary_reader/BinaryReader#<'a>) -> Resultrust-analyzer cargo wasmparser 0.239.0 binary_reader/Result#<Selfrust-analyzer cargo wasmparser 0.239.0 readers/core/memories/impl#[MemoryType][`FromReader<'a>`]> { |
| 23 | let pos = reader.original_positionrust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]original_position().(); |
| 24 | let flags = reader.read_u8rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]read_u8().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 25 | |
| 26 | if (flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][Not]not().0b1111) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 27 | bailrust-analyzer cargo wasmparser 0.239.0 bail!!(pos, "invalid memory limits flags"); |
| 28 | } |
| 29 | |
| 30 | let memory64 = flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b0100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0; |
| 31 | let shared = flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b0010 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0; |
| 32 | let has_max = flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b0001 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0; |
| 33 | let has_page_size = flags rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b1000 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0; |
| 34 | |
| 35 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(MemoryTyperust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType# { |
| 36 | memory64rust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#memory64., |
| 37 | sharedrust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#shared., |
| 38 | initialrust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#initial.: if reader.memory64rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'_>`]memory64().() { |
| 39 | reader.read_var_u64rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]read_var_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 40 | } else { |
| 41 | reader.read_var_u32rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]read_var_u32().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 42 | }, |
| 43 | maximumrust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#maximum.: if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().has_max { |
| 44 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 45 | } else if reader.memory64rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'_>`]memory64().() { |
| 46 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reader.read_var_u64rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]read_var_u64().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 47 | } else { |
| 48 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(reader.read_var_u32rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]read_var_u32().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 49 | }, |
| 50 | page_size_log2rust-analyzer cargo wasmparser 0.239.0 readers/core/types/MemoryType#page_size_log2.: if has_page_size { |
| 51 | let val = reader.read_var_u32rust-analyzer cargo wasmparser 0.239.0 binary_reader/impl#[`BinaryReader<'a>`]read_var_u32().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 52 | if val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().64 { |
| 53 | bailrust-analyzer cargo wasmparser 0.239.0 bail!!(pos, "invalid custom page size"); |
| 54 | } |
| 55 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(val) |
| 56 | } else { |
| 57 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 58 | }, |
| 59 | }) |
| 60 | } |
| 61 | } |