Don't panic on shared memories (#883)

* Don't panic on shared memories

Instead return a first-class error
This commit is contained in:
Alex Crichton
2020-02-01 10:33:30 +01:00
committed by GitHub
parent f2fa484abf
commit ea4faa4a01
2 changed files with 12 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ use crate::types::{
ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability, ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability,
TableType, ValType, TableType, ValType,
}; };
use anyhow::{Error, Result}; use anyhow::{bail, Error, Result};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::cell::Cell; use std::cell::Cell;
use std::collections::HashMap; use std::collections::HashMap;
@@ -16,9 +16,14 @@ use wasmparser::{
}; };
use wasmtime_jit::CompiledModule; use wasmtime_jit::CompiledModule;
fn into_memory_type(mt: wasmparser::MemoryType) -> MemoryType { fn into_memory_type(mt: wasmparser::MemoryType) -> Result<MemoryType> {
assert!(!mt.shared); if mt.shared {
MemoryType::new(Limits::new(mt.limits.initial, mt.limits.maximum)) bail!("shared memories are not supported yet");
}
Ok(MemoryType::new(Limits::new(
mt.limits.initial,
mt.limits.maximum,
)))
} }
fn into_global_type(gt: wasmparser::GlobalType) -> GlobalType { fn into_global_type(gt: wasmparser::GlobalType) -> GlobalType {
@@ -341,7 +346,7 @@ impl Module {
let section = section.get_memory_section_reader()?; let section = section.get_memory_section_reader()?;
memories.reserve_exact(section.get_count() as usize); memories.reserve_exact(section.get_count() as usize);
for entry in section { for entry in section {
memories.push(into_memory_type(entry?)); memories.push(into_memory_type(entry?)?);
} }
} }
SectionCode::Type => { SectionCode::Type => {
@@ -389,7 +394,7 @@ impl Module {
ExternType::Table(table) ExternType::Table(table)
} }
ImportSectionEntryType::Memory(mt) => { ImportSectionEntryType::Memory(mt) => {
let memory = into_memory_type(mt); let memory = into_memory_type(mt)?;
memories.push(memory.clone()); memories.push(memory.clone());
ExternType::Memory(memory) ExternType::Memory(memory)
} }

View File

@@ -0,0 +1 @@
(assert_invalid (module (memory 1 1 shared)) "not supported")