1use crate::{store::MaybeInstanceOwned, vmcontext::VMGlobalDefinition};
2use std::{cell::UnsafeCell, ptr::NonNull};
3use wasmer_types::GlobalType;
4
5#[derive(Debug)]
7pub struct VMGlobal {
8 ty: GlobalType,
9 vm_global_definition: MaybeInstanceOwned<VMGlobalDefinition>,
10}
11
12impl VMGlobal {
13 pub fn new(global_type: GlobalType) -> Self {
15 Self {
16 ty: global_type,
17 vm_global_definition: MaybeInstanceOwned::Host(Box::new(UnsafeCell::new(
20 VMGlobalDefinition::new(),
21 ))),
22 }
23 }
24
25 pub fn ty(&self) -> &GlobalType {
27 &self.ty
28 }
29
30 pub fn vmglobal(&self) -> NonNull<VMGlobalDefinition> {
32 self.vm_global_definition.as_ptr()
33 }
34
35 pub fn copy_on_write(&self) -> Self {
37 unsafe {
38 Self {
39 ty: self.ty,
40 vm_global_definition: MaybeInstanceOwned::Host(Box::new(UnsafeCell::new(
41 self.vm_global_definition.as_ptr().as_ref().clone(),
42 ))),
43 }
44 }
45 }
46}