mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-20 04:06:30 +00:00
Add comments explaining the unsafe impls and simplify the code, too
This commit is contained in:
@ -54,6 +54,7 @@ pub struct LocalBacking {
|
||||
pub(crate) internals: Internals,
|
||||
}
|
||||
|
||||
// Manually implemented because LocalBacking contains raw pointers directly
|
||||
unsafe impl Send for LocalBacking {}
|
||||
|
||||
impl LocalBacking {
|
||||
@ -463,6 +464,7 @@ pub struct ImportBacking {
|
||||
pub(crate) vm_globals: BoxedMap<ImportedGlobalIndex, *mut vm::LocalGlobal>,
|
||||
}
|
||||
|
||||
// manually implemented because ImportBacking contains raw pointers directly
|
||||
unsafe impl Send for ImportBacking {}
|
||||
|
||||
impl ImportBacking {
|
||||
|
@ -11,6 +11,7 @@ pub enum Context {
|
||||
Internal,
|
||||
}
|
||||
|
||||
// Manually implemented because context contains a raw pointer to Ctx
|
||||
unsafe impl Send for Context {}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -28,6 +29,7 @@ pub enum Export {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FuncPointer(*const vm::Func);
|
||||
|
||||
// Manually implemented because FuncPointer contains a raw pointer to Ctx
|
||||
unsafe impl Send for FuncPointer {}
|
||||
|
||||
impl FuncPointer {
|
||||
|
@ -107,17 +107,6 @@ impl ImportObject {
|
||||
}
|
||||
}
|
||||
|
||||
/*pub fn get_namespace(
|
||||
&self,
|
||||
namespace: &str,
|
||||
) -> Option<
|
||||
MutexGuardRef<HashMap<String, Box<dyn LikeNamespace + Send>>, &(dyn LikeNamespace + Send)>,
|
||||
> {
|
||||
MutexGuardRef::new(self.map.lock().unwrap())
|
||||
.try_map(|mg| mg.get(namespace).map(|ns| &ns.as_ref()).ok_or(()))
|
||||
.ok()
|
||||
}*/
|
||||
|
||||
/// Apply a function on the namespace if it exists
|
||||
/// If your function can fail, consider using `maybe_with_namespace`
|
||||
pub fn with_namespace<Func, InnerRet>(&self, namespace: &str, f: Func) -> Option<InnerRet>
|
||||
|
@ -25,6 +25,7 @@ pub(crate) struct InstanceInner {
|
||||
pub(crate) vmctx: *mut vm::Ctx,
|
||||
}
|
||||
|
||||
// manually implemented because InstanceInner contains a raw pointer to Ctx
|
||||
unsafe impl Send for InstanceInner {}
|
||||
|
||||
impl Drop for InstanceInner {
|
||||
|
@ -213,7 +213,8 @@ struct UnsharedMemoryInternal {
|
||||
local: Cell<vm::LocalMemory>,
|
||||
}
|
||||
|
||||
unsafe impl Send for UnsharedMemoryInternal {}
|
||||
// Manually implemented because UnsharedMemoryInternal uses `Cell` and is used in an Arc;
|
||||
// this is safe because the lock for storage can be used to protect (seems like a weak reason: PLEASE REVIEW!)
|
||||
unsafe impl Sync for UnsharedMemoryInternal {}
|
||||
|
||||
impl UnsharedMemory {
|
||||
@ -291,7 +292,8 @@ pub struct SharedMemoryInternal {
|
||||
lock: Mutex<()>,
|
||||
}
|
||||
|
||||
unsafe impl Send for SharedMemoryInternal {}
|
||||
// Manually implemented because SharedMemoryInternal uses `Cell` and is used in Arc;
|
||||
// this is safe because of `lock`; accesing `local` without locking `lock` is not safe (Maybe we could put the lock on Local then?)
|
||||
unsafe impl Sync for SharedMemoryInternal {}
|
||||
|
||||
impl SharedMemory {
|
||||
|
@ -474,6 +474,7 @@ pub struct ImportedFunc {
|
||||
pub vmctx: *mut Ctx,
|
||||
}
|
||||
|
||||
// manually implemented because ImportedFunc contains raw pointers directly; `Func` is marked Send (But `Ctx` actually isn't! (TODO: review this, shouldn't `Ctx` be Send?))
|
||||
unsafe impl Send for ImportedFunc {}
|
||||
|
||||
impl ImportedFunc {
|
||||
@ -503,6 +504,7 @@ pub struct LocalTable {
|
||||
pub table: *mut (),
|
||||
}
|
||||
|
||||
// manually implemented because LocalTable contains raw pointers directly
|
||||
unsafe impl Send for LocalTable {}
|
||||
|
||||
impl LocalTable {
|
||||
@ -534,6 +536,9 @@ pub struct LocalMemory {
|
||||
pub memory: *mut (),
|
||||
}
|
||||
|
||||
// manually implemented because LocalMemory contains raw pointers
|
||||
unsafe impl Send for LocalMemory {}
|
||||
|
||||
impl LocalMemory {
|
||||
#[allow(clippy::erasing_op)] // TODO
|
||||
pub fn offset_base() -> u8 {
|
||||
@ -584,6 +589,7 @@ pub struct Anyfunc {
|
||||
pub sig_id: SigId,
|
||||
}
|
||||
|
||||
// manually implemented because Anyfunc contains raw pointers directly
|
||||
unsafe impl Send for Anyfunc {}
|
||||
|
||||
impl Anyfunc {
|
||||
|
Reference in New Issue
Block a user