mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
Use thiserror for MemoryAccessError
This commit is contained in:
committed by
Manos Pitsidianakis
parent
d94745c9fc
commit
dd7808b534
8
lib/api/src/js/externals/memory.rs
vendored
8
lib/api/src/js/externals/memory.rs
vendored
@@ -82,6 +82,9 @@ pub struct Memory {
|
|||||||
view: js_sys::Uint8Array,
|
view: js_sys::Uint8Array,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for Memory {}
|
||||||
|
unsafe impl Sync for Memory {}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
/// Creates a new host `Memory` from the provided [`MemoryType`].
|
/// Creates a new host `Memory` from the provided [`MemoryType`].
|
||||||
///
|
///
|
||||||
@@ -234,8 +237,9 @@ impl Memory {
|
|||||||
Ok(Pages(new_pages))
|
Ok(Pages(new_pages))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
/// Used by tests
|
||||||
pub(crate) fn uint8view(&self) -> js_sys::Uint8Array {
|
#[doc(hidden)]
|
||||||
|
pub fn uint8view(&self) -> js_sys::Uint8Array {
|
||||||
self.view.clone()
|
self.view.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use crate::RuntimeError;
|
use crate::RuntimeError;
|
||||||
use wasmer_types::ValueType;
|
|
||||||
|
|
||||||
use crate::{Memory, Memory32, Memory64, WasmPtr};
|
use crate::{Memory, Memory32, Memory64, WasmPtr};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
error::Error,
|
|
||||||
fmt,
|
fmt,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
mem::{self, MaybeUninit},
|
mem::{self, MaybeUninit},
|
||||||
@@ -12,31 +9,24 @@ use std::{
|
|||||||
slice,
|
slice,
|
||||||
string::FromUtf8Error,
|
string::FromUtf8Error,
|
||||||
};
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
use wasmer_types::ValueType;
|
||||||
|
|
||||||
/// Error for invalid [`Memory`] access.
|
/// Error for invalid [`Memory`] access.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Copy, Debug, Error)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum MemoryAccessError {
|
pub enum MemoryAccessError {
|
||||||
/// Memory access is outside heap bounds.
|
/// Memory access is outside heap bounds.
|
||||||
|
#[error("memory access out of bounds")]
|
||||||
HeapOutOfBounds,
|
HeapOutOfBounds,
|
||||||
/// Address calculation overflow.
|
/// Address calculation overflow.
|
||||||
|
#[error("address calculation overflow")]
|
||||||
Overflow,
|
Overflow,
|
||||||
/// String is not valid UTF-8.
|
/// String is not valid UTF-8.
|
||||||
|
#[error("string is not valid utf-8")]
|
||||||
NonUtf8String,
|
NonUtf8String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for MemoryAccessError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
MemoryAccessError::HeapOutOfBounds => write!(f, "memory access out of bounds"),
|
|
||||||
MemoryAccessError::Overflow => write!(f, "address calculation overflow"),
|
|
||||||
MemoryAccessError::NonUtf8String => write!(f, "string is not valid utf-8"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for MemoryAccessError {}
|
|
||||||
|
|
||||||
impl From<MemoryAccessError> for RuntimeError {
|
impl From<MemoryAccessError> for RuntimeError {
|
||||||
fn from(err: MemoryAccessError) -> Self {
|
fn from(err: MemoryAccessError) -> Self {
|
||||||
RuntimeError::new(err.to_string())
|
RuntimeError::new(err.to_string())
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
use crate::RuntimeError;
|
use crate::RuntimeError;
|
||||||
use wasmer_types::ValueType;
|
|
||||||
|
|
||||||
use crate::{Memory, Memory32, Memory64, WasmPtr};
|
use crate::{Memory, Memory32, Memory64, WasmPtr};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
error::Error,
|
|
||||||
fmt,
|
fmt,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
mem::{self, MaybeUninit},
|
mem::{self, MaybeUninit},
|
||||||
@@ -12,31 +9,24 @@ use std::{
|
|||||||
slice,
|
slice,
|
||||||
string::FromUtf8Error,
|
string::FromUtf8Error,
|
||||||
};
|
};
|
||||||
|
use thiserror::Error;
|
||||||
|
use wasmer_types::ValueType;
|
||||||
|
|
||||||
/// Error for invalid [`Memory`] access.
|
/// Error for invalid [`Memory`] access.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Copy, Debug, Error)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum MemoryAccessError {
|
pub enum MemoryAccessError {
|
||||||
/// Memory access is outside heap bounds.
|
/// Memory access is outside heap bounds.
|
||||||
|
#[error("memory access out of bounds")]
|
||||||
HeapOutOfBounds,
|
HeapOutOfBounds,
|
||||||
/// Address calculation overflow.
|
/// Address calculation overflow.
|
||||||
|
#[error("address calculation overflow")]
|
||||||
Overflow,
|
Overflow,
|
||||||
/// String is not valid UTF-8.
|
/// String is not valid UTF-8.
|
||||||
|
#[error("string is not valid utf-8")]
|
||||||
NonUtf8String,
|
NonUtf8String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for MemoryAccessError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
MemoryAccessError::HeapOutOfBounds => write!(f, "memory access out of bounds"),
|
|
||||||
MemoryAccessError::Overflow => write!(f, "address calculation overflow"),
|
|
||||||
MemoryAccessError::NonUtf8String => write!(f, "string is not valid utf-8"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Error for MemoryAccessError {}
|
|
||||||
|
|
||||||
impl From<MemoryAccessError> for RuntimeError {
|
impl From<MemoryAccessError> for RuntimeError {
|
||||||
fn from(err: MemoryAccessError) -> Self {
|
fn from(err: MemoryAccessError) -> Self {
|
||||||
RuntimeError::new(err.to_string())
|
RuntimeError::new(err.to_string())
|
||||||
|
|||||||
Reference in New Issue
Block a user