pub struct Global<T> { /* private fields */ }Expand description
A global variable of type T at an address in a Module.
Generated bindings declare one per IR global; it holds only the address,
one per build when they were generated from several. When T is
Plain, read and write access it
safely; otherwise use ptr.
§Data races
Each read or write is a single volatile access that doesn’t synchronise with the target. If the target uses the global on another thread at the same time, a value larger than a machine word can be seen half-updated.
§Examples
use imping_runtime::{Build, Global, Module};
static TARGET: Module = Module::new(
"target.exe",
&[Build { timestamp: 0x64b8f2a1, image_size: 0xa2b000 }],
);
static GRAVITY: Global<f32> = Global::new(&TARGET, 0x3a1200);
// SAFETY: this build of `target.exe` keeps an `f32` at RVA 0x3a1200.
unsafe { TARGET.init() }?;
let gravity = GRAVITY.read();
GRAVITY.write(gravity / 2.0);Implementations§
Source§impl<T> Global<T>
impl<T> Global<T>
Sourcepub const fn new(module: &'static Module, rva: u32) -> Self
pub const fn new(module: &'static Module, rva: u32) -> Self
Describes the global at rva, an address relative to module’s base.
Sourcepub fn try_ptr(&self) -> Option<*mut T>
pub fn try_ptr(&self) -> Option<*mut T>
Returns a pointer to the global in this process, or None if the
module’s init has not succeeded or the loaded build’s
IR lacks the global.
On a build none of the IRs is, after
init_any_build, it’s the first build’s
address that has the global, unchecked, as nothing can search for a
global.