Deduplicate listings of traps in Wasmtime (#5299)
This commit replaces `wasmtime_environ::TrapCode` with `wasmtime::Trap`. This is possible with past refactorings which slimmed down the `Trap` definition in the `wasmtime` crate to a simple `enum`. This means that there's one less place that all the various trap opcodes need to be listed in Wasmtime.
This commit is contained in:
@@ -8,7 +8,7 @@ use anyhow::{bail, format_err, Error, Result};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::ops::Range;
|
||||
use std::ptr;
|
||||
use wasmtime_environ::{TablePlan, TrapCode, WasmType, FUNCREF_INIT_BIT, FUNCREF_MASK};
|
||||
use wasmtime_environ::{TablePlan, Trap, WasmType, FUNCREF_INIT_BIT, FUNCREF_MASK};
|
||||
|
||||
/// An element going into or coming out of a table.
|
||||
///
|
||||
@@ -267,7 +267,7 @@ impl Table {
|
||||
&mut self,
|
||||
dst: u32,
|
||||
items: impl ExactSizeIterator<Item = *mut VMCallerCheckedAnyfunc>,
|
||||
) -> Result<(), TrapCode> {
|
||||
) -> Result<(), Trap> {
|
||||
assert!(self.element_type() == TableElementType::Func);
|
||||
|
||||
let elements = match self
|
||||
@@ -276,7 +276,7 @@ impl Table {
|
||||
.and_then(|s| s.get_mut(..items.len()))
|
||||
{
|
||||
Some(elements) => elements,
|
||||
None => return Err(TrapCode::TableOutOfBounds),
|
||||
None => return Err(Trap::TableOutOfBounds),
|
||||
};
|
||||
|
||||
for (item, slot) in items.zip(elements) {
|
||||
@@ -290,14 +290,14 @@ impl Table {
|
||||
/// Fill `table[dst..dst + len]` with `val`.
|
||||
///
|
||||
/// Returns a trap error on out-of-bounds accesses.
|
||||
pub fn fill(&mut self, dst: u32, val: TableElement, len: u32) -> Result<(), TrapCode> {
|
||||
pub fn fill(&mut self, dst: u32, val: TableElement, len: u32) -> Result<(), Trap> {
|
||||
let start = dst as usize;
|
||||
let end = start
|
||||
.checked_add(len as usize)
|
||||
.ok_or_else(|| TrapCode::TableOutOfBounds)?;
|
||||
.ok_or_else(|| Trap::TableOutOfBounds)?;
|
||||
|
||||
if end > self.size() as usize {
|
||||
return Err(TrapCode::TableOutOfBounds);
|
||||
return Err(Trap::TableOutOfBounds);
|
||||
}
|
||||
|
||||
debug_assert!(self.type_matches(&val));
|
||||
@@ -412,7 +412,7 @@ impl Table {
|
||||
dst_index: u32,
|
||||
src_index: u32,
|
||||
len: u32,
|
||||
) -> Result<(), TrapCode> {
|
||||
) -> Result<(), Trap> {
|
||||
// https://webassembly.github.io/bulk-memory-operations/core/exec/instructions.html#exec-table-copy
|
||||
|
||||
if src_index
|
||||
@@ -422,7 +422,7 @@ impl Table {
|
||||
.checked_add(len)
|
||||
.map_or(true, |m| m > (*dst_table).size())
|
||||
{
|
||||
return Err(TrapCode::TableOutOfBounds);
|
||||
return Err(Trap::TableOutOfBounds);
|
||||
}
|
||||
|
||||
debug_assert!(
|
||||
|
||||
Reference in New Issue
Block a user