From ea4faa4a01bc268b418f6a574d4464b78aaa5793 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 1 Feb 2020 10:33:30 +0100 Subject: [PATCH] Don't panic on shared memories (#883) * Don't panic on shared memories Instead return a first-class error --- crates/api/src/module.rs | 17 +++++++++++------ tests/misc_testsuite/threads.wast | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 tests/misc_testsuite/threads.wast diff --git a/crates/api/src/module.rs b/crates/api/src/module.rs index 6aa4b10a12..bc275c2aab 100644 --- a/crates/api/src/module.rs +++ b/crates/api/src/module.rs @@ -3,7 +3,7 @@ use crate::types::{ ExportType, ExternType, FuncType, GlobalType, ImportType, Limits, MemoryType, Mutability, TableType, ValType, }; -use anyhow::{Error, Result}; +use anyhow::{bail, Error, Result}; use lazy_static::lazy_static; use std::cell::Cell; use std::collections::HashMap; @@ -16,9 +16,14 @@ use wasmparser::{ }; use wasmtime_jit::CompiledModule; -fn into_memory_type(mt: wasmparser::MemoryType) -> MemoryType { - assert!(!mt.shared); - MemoryType::new(Limits::new(mt.limits.initial, mt.limits.maximum)) +fn into_memory_type(mt: wasmparser::MemoryType) -> Result { + if mt.shared { + 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 { @@ -341,7 +346,7 @@ impl Module { let section = section.get_memory_section_reader()?; memories.reserve_exact(section.get_count() as usize); for entry in section { - memories.push(into_memory_type(entry?)); + memories.push(into_memory_type(entry?)?); } } SectionCode::Type => { @@ -389,7 +394,7 @@ impl Module { ExternType::Table(table) } ImportSectionEntryType::Memory(mt) => { - let memory = into_memory_type(mt); + let memory = into_memory_type(mt)?; memories.push(memory.clone()); ExternType::Memory(memory) } diff --git a/tests/misc_testsuite/threads.wast b/tests/misc_testsuite/threads.wast new file mode 100644 index 0000000000..4c98ae2c3f --- /dev/null +++ b/tests/misc_testsuite/threads.wast @@ -0,0 +1 @@ +(assert_invalid (module (memory 1 1 shared)) "not supported")