linera_wasmer_vm/
global.rs1use crate::{store::MaybeInstanceOwned, vmcontext::VMGlobalDefinition};
2use derivative::Derivative;
3use std::{cell::UnsafeCell, ptr::NonNull};
4use wasmer_types::GlobalType;
5
6#[derive(Derivative)]
8#[derivative(Debug)]
9pub struct VMGlobal {
10 ty: GlobalType,
11 #[derivative(Debug = "ignore")]
12 vm_global_definition: MaybeInstanceOwned<VMGlobalDefinition>,
13}
14
15impl VMGlobal {
16 pub fn new(global_type: GlobalType) -> Self {
18 Self {
19 ty: global_type,
20 vm_global_definition: MaybeInstanceOwned::Host(Box::new(UnsafeCell::new(
23 VMGlobalDefinition::new(),
24 ))),
25 }
26 }
27
28 pub fn ty(&self) -> &GlobalType {
30 &self.ty
31 }
32
33 pub fn vmglobal(&self) -> NonNull<VMGlobalDefinition> {
35 self.vm_global_definition.as_ptr()
36 }
37
38 pub fn copy_on_write(&self) -> Self {
40 unsafe {
41 Self {
42 ty: self.ty,
43 vm_global_definition: MaybeInstanceOwned::Host(Box::new(UnsafeCell::new(
44 self.vm_global_definition.as_ptr().as_ref().clone(),
45 ))),
46 }
47 }
48 }
49}