Add host_state() accessors to InstanceContents and VMContext too.
This commit is contained in:
@@ -409,6 +409,11 @@ impl InstanceContents {
|
|||||||
|
|
||||||
foreign_instance_contents.memory_size(foreign_index)
|
foreign_instance_contents.memory_size(foreign_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a reference to the custom state attached to this instance.
|
||||||
|
pub fn host_state(&mut self) -> &mut Any {
|
||||||
|
return &mut *self.host_state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wrapper around an `Mmap` holding an `InstanceContents`.
|
/// A wrapper around an `Mmap` holding an `InstanceContents`.
|
||||||
@@ -686,7 +691,7 @@ impl Instance {
|
|||||||
|
|
||||||
/// Return a reference to the custom state attached to this instance.
|
/// Return a reference to the custom state attached to this instance.
|
||||||
pub fn host_state(&mut self) -> &mut Any {
|
pub fn host_state(&mut self) -> &mut Any {
|
||||||
return &mut *self.mmap_field.contents_mut().host_state;
|
return self.mmap_field.contents_mut().host_state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
//! fields that compiled wasm code accesses directly.
|
//! fields that compiled wasm code accesses directly.
|
||||||
|
|
||||||
use crate::instance::InstanceContents;
|
use crate::instance::InstanceContents;
|
||||||
|
use core::any::Any;
|
||||||
use core::{ptr, u32};
|
use core::{ptr, u32};
|
||||||
|
|
||||||
/// An imported function.
|
/// An imported function.
|
||||||
@@ -478,9 +479,20 @@ pub struct VMContext {}
|
|||||||
|
|
||||||
impl VMContext {
|
impl VMContext {
|
||||||
/// Return a mutable reference to the associated `Instance`.
|
/// Return a mutable reference to the associated `Instance`.
|
||||||
|
///
|
||||||
|
/// This is unsafe because it doesn't work on just any `VMContext`, it must
|
||||||
|
/// be a `VMContext` allocated as part of an `Instance`.
|
||||||
#[allow(clippy::cast_ptr_alignment)]
|
#[allow(clippy::cast_ptr_alignment)]
|
||||||
pub(crate) unsafe fn instance_contents(&mut self) -> &mut InstanceContents {
|
pub(crate) unsafe fn instance_contents(&mut self) -> &mut InstanceContents {
|
||||||
&mut *((self as *mut Self as *mut u8).offset(-InstanceContents::vmctx_offset())
|
&mut *((self as *mut Self as *mut u8).offset(-InstanceContents::vmctx_offset())
|
||||||
as *mut InstanceContents)
|
as *mut InstanceContents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return a mutable reference to the host state associated with `Instance`.
|
||||||
|
///
|
||||||
|
/// This is unsafe because it doesn't work on just any `VMContext`, it must
|
||||||
|
/// be a `VMContext` allocated as part of an `Instance`.
|
||||||
|
pub unsafe fn host_state(&mut self) -> &mut Any {
|
||||||
|
self.instance_contents().host_state()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user