mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-21 12:41:32 +00:00
Support getting/setting metering points and internal fields with a Ctx.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use wasmer_runtime_core::{
|
||||
codegen::{Event, EventSink, FunctionMiddleware, InternalEvent},
|
||||
module::ModuleInfo,
|
||||
vm::InternalField,
|
||||
vm::{Ctx, InternalField},
|
||||
wasmparser::{Operator, Type as WpType},
|
||||
Instance,
|
||||
};
|
||||
@ -111,16 +111,26 @@ impl FunctionMiddleware for Metering {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of points used by a function call for metering
|
||||
/// Returns the number of points used by an Instance.
|
||||
pub fn get_points_used(instance: &Instance) -> u64 {
|
||||
instance.get_internal(&INTERNAL_FIELD)
|
||||
}
|
||||
|
||||
/// Sets the value of points used
|
||||
/// Sets the number of points used by an Instance.
|
||||
pub fn set_points_used(instance: &mut Instance, value: u64) {
|
||||
instance.set_internal(&INTERNAL_FIELD, value);
|
||||
}
|
||||
|
||||
/// Returns the number of points used in a Ctx.
|
||||
pub fn get_points_used_ctx(ctx: &Ctx) -> u64 {
|
||||
ctx.get_internal(&INTERNAL_FIELD)
|
||||
}
|
||||
|
||||
/// Sets the number of points used in a Ctx.
|
||||
pub fn set_points_used_ctx(ctx: &mut Ctx, value: u64) {
|
||||
ctx.set_internal(&INTERNAL_FIELD, value);
|
||||
}
|
||||
|
||||
#[cfg(all(test, feature = "singlepass"))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -350,6 +350,18 @@ impl Ctx {
|
||||
pub fn dynamic_sigindice_count(&self) -> usize {
|
||||
unsafe { (*self.local_backing).dynamic_sigindices.len() }
|
||||
}
|
||||
|
||||
/// Returns the value of the specified internal field.
|
||||
pub fn get_internal(&self, field: &InternalField) -> u64 {
|
||||
unsafe { (*self.internal.internals)[field.index()] }
|
||||
}
|
||||
|
||||
/// Writes the value to the specified internal field.
|
||||
pub fn set_internal(&mut self, field: &InternalField, value: u64) {
|
||||
unsafe {
|
||||
(*self.internal.internals)[field.index()] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
|
Reference in New Issue
Block a user