Move StoreId to common wasmer_types

This commit is contained in:
Syrus Akbary
2023-02-09 19:22:33 +01:00
parent 83313eb098
commit 30f4589f23
6 changed files with 35 additions and 58 deletions

View File

@@ -234,30 +234,8 @@ mod objects {
use wasm_bindgen::JsValue;
use crate::js::{function_env::VMFunctionEnvironment, vm::VMGlobal};
use std::{
fmt,
marker::PhantomData,
num::{NonZeroU64, NonZeroUsize},
sync::atomic::{AtomicU64, Ordering},
};
/// Unique ID to identify a context.
///
/// Every handle to an object managed by a context also contains the ID of the
/// context. This is used to check that a handle is always used with the
/// correct context.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct StoreId(NonZeroU64);
impl Default for StoreId {
// Allocates a unique ID for a new context.
fn default() -> Self {
// No overflow checking is needed here: overflowing this would take
// thousands of years.
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
Self(NonZeroU64::new(NEXT_ID.fetch_add(1, Ordering::Relaxed)).unwrap())
}
}
use std::{fmt, marker::PhantomData, num::NonZeroUsize};
pub use wasmer_types::StoreId;
/// Trait to represent an object managed by a context. This is implemented on
/// the VM types managed by the context.

View File

@@ -3,9 +3,10 @@ use crate::sys::engine::{default_engine, Engine};
use derivative::Derivative;
use std::fmt;
use wasmer_compiler::Tunables;
use wasmer_types::OnCalledAction;
use wasmer_vm::{init_traps, StoreId, TrapHandlerFn};
use wasmer_types::{OnCalledAction, StoreId};
use wasmer_vm::{init_traps, TrapHandlerFn};
#[cfg(feature = "sys")]
use wasmer_vm::StoreObjects;
/// Call handler for a store.

View File

@@ -62,6 +62,7 @@ mod libcalls;
mod memory;
mod module;
mod serialize;
mod store_id;
mod table;
mod trapcode;
mod types;
@@ -129,6 +130,8 @@ pub use crate::compilation::symbols::{Symbol, SymbolRegistry};
pub use crate::compilation::trap::TrapInformation;
pub use crate::compilation::unwind::CompiledFunctionUnwindInfo;
pub use crate::store_id::StoreId;
/// Offset in bytes from the beginning of the function.
pub type CodeOffset = u32;

22
lib/types/src/store_id.rs Normal file
View File

@@ -0,0 +1,22 @@
use std::{
num::NonZeroU64,
sync::atomic::{AtomicU64, Ordering},
};
/// Unique ID to identify a context.
///
/// Every handle to an object managed by a context also contains the ID of the
/// context. This is used to check that a handle is always used with the
/// correct context.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct StoreId(NonZeroU64);
impl Default for StoreId {
// Allocates a unique ID for a new context.
fn default() -> Self {
// No overflow checking is needed here: overflowing this would take
// thousands of years.
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
Self(NonZeroU64::new(NEXT_ID.fetch_add(1, Ordering::Relaxed)).unwrap())
}
}

View File

@@ -52,9 +52,7 @@ pub use crate::memory::{
pub use crate::mmap::Mmap;
pub use crate::probestack::PROBESTACK;
pub use crate::sig_registry::SignatureRegistry;
pub use crate::store::{
InternalStoreHandle, MaybeInstanceOwned, StoreHandle, StoreId, StoreObjects,
};
pub use crate::store::{InternalStoreHandle, MaybeInstanceOwned, StoreHandle, StoreObjects};
pub use crate::table::{TableElement, VMTable};
pub use crate::trap::*;
pub use crate::vmcontext::{
@@ -67,7 +65,7 @@ pub use wasmer_types::MemoryError;
pub use wasmer_types::MemoryStyle;
use wasmer_types::RawValue;
pub use wasmer_types::TableStyle;
pub use wasmer_types::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
pub use wasmer_types::{StoreId, TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
#[deprecated(
since = "2.1.0",

View File

@@ -1,34 +1,9 @@
use core::slice::Iter;
use std::{
cell::UnsafeCell,
fmt,
marker::PhantomData,
num::{NonZeroU64, NonZeroUsize},
ptr::NonNull,
sync::atomic::{AtomicU64, Ordering},
};
use crate::{
VMExternObj, VMFunction, VMFunctionEnvironment, VMGlobal, VMInstance, VMMemory, VMTable,
};
/// Unique ID to identify a context.
///
/// Every handle to an object managed by a context also contains the ID of the
/// context. This is used to check that a handle is always used with the
/// correct context.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct StoreId(NonZeroU64);
impl Default for StoreId {
// Allocates a unique ID for a new context.
fn default() -> Self {
// No overflow checking is needed here: overflowing this would take
// thousands of years.
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
Self(NonZeroU64::new(NEXT_ID.fetch_add(1, Ordering::Relaxed)).unwrap())
}
}
use core::slice::Iter;
use std::{cell::UnsafeCell, fmt, marker::PhantomData, num::NonZeroUsize, ptr::NonNull};
use wasmer_types::StoreId;
/// Trait to represent an object managed by a context. This is implemented on
/// the VM types managed by the context.