Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ResourceLimiter API #737

Merged
merged 23 commits into from
Jul 4, 2023
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
71fa9d4
Sketch of support for ResourceLimiter API
graydon Jun 29, 2023
c4d66ee
Address review comments.
graydon Jun 30, 2023
8e0da23
Handle the 3 separate ResourceLimiter response types more correctly.
graydon Jun 30, 2023
6afb5ef
Fix typo in existing error message.
graydon Jun 30, 2023
610fae7
Add StoreLimits, StoreLimitsBuilder and docs from wasmtime.
graydon Jun 30, 2023
5f0a428
Fix unused-variable warnings.
graydon Jun 30, 2023
15ab197
Conditionalize ResourceLimiter on cfg(feature="std")
graydon Jun 30, 2023
bcfb80b
Add ResourceLimiter test and fix bugs it uncovered.
graydon Jun 30, 2023
09aaf8d
Avoid redundant limit and size storage in previous wasmtime-like design.
graydon Jun 30, 2023
8eeea83
Thread an ever-so-smaller &mut ResourceLimiterRef into the Executor
graydon Jun 30, 2023
7dc0251
Support no_std differently (import alloc::boxed::Box)
graydon Jul 1, 2023
071df16
Avoid storing &ResourceLimiterRef in Executor (maybe breaks SROA?)
graydon Jul 1, 2023
32da9ff
Fix no_std a little harder.
graydon Jul 1, 2023
9f68c38
Restore TableError::GrowOutOfBounds fields
graydon Jul 3, 2023
14b3c07
Remove now-redundant pub(crate)
graydon Jul 3, 2023
11a0739
Remove unnecessary cfg guard on alloc::boxed::Box
graydon Jul 3, 2023
8436a1c
Address clippy warnings
graydon Jul 3, 2023
1b07fa4
Fix doc reference.
graydon Jul 3, 2023
c005b8f
Some cleanups as requested in review.
graydon Jul 4, 2023
831ec46
Fix wasmi_core doc-link to wasmi, deps do not go that way.
graydon Jul 4, 2023
61d8e45
Fix s/State/Store/ doc typo
graydon Jul 4, 2023
a11d8c1
Add docs on Store::limiter
graydon Jul 4, 2023
25b4e7a
Fix new nightly clippy nit
graydon Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions crates/wasmi/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "std")]
use crate::{
engine::DedupFuncType,
externref::{ExternObject, ExternObjectEntity, ExternObjectIdx},
Expand Down Expand Up @@ -29,6 +28,8 @@ use crate::{
TableEntity,
TableIdx,
};
#[cfg(feature = "std")]
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
use alloc::boxed::Box;
use core::{
fmt::{self, Debug},
sync::atomic::{AtomicU32, Ordering},
Expand Down Expand Up @@ -83,11 +84,9 @@ impl<'a> ResourceLimiterRef<'a> {
}
}

#[cfg(feature = "std")]
struct ResourceLimiterQuery<T>(
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
Box<dyn FnMut(&mut T) -> &mut (dyn crate::ResourceLimiter) + Send + Sync>,
);
#[cfg(feature = "std")]
impl<T> core::fmt::Debug for ResourceLimiterQuery<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ResourceLimiterQuery(...)")
Expand All @@ -109,7 +108,6 @@ pub struct Store<T> {
/// User provided host data owned by the [`Store`].
data: T,
/// User provided hook to retrieve a [`ResourceLimiter`].
#[cfg(feature = "std")]
limiter: Option<ResourceLimiterQuery<T>>,
}

Expand Down Expand Up @@ -721,7 +719,6 @@ impl<T> Store<T> {
inner: StoreInner::new(engine),
trampolines: Arena::new(),
data,
#[cfg(feature = "std")]
limiter: None,
}
}
Expand All @@ -746,7 +743,6 @@ impl<T> Store<T> {
self.data
}

#[cfg(feature = "std")]
pub fn limiter(
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
&mut self,
limiter: impl FnMut(&mut T) -> &mut (dyn crate::ResourceLimiter) + Send + Sync + 'static,
Expand Down Expand Up @@ -793,7 +789,6 @@ impl<T> Store<T> {
Ok(())
}

#[cfg(feature = "std")]
pub(crate) fn store_inner_and_resource_limiter_ref(
&mut self,
) -> (&mut StoreInner, ResourceLimiterRef) {
Expand All @@ -804,13 +799,6 @@ impl<T> Store<T> {
(&mut self.inner, resource_limiter)
}

#[cfg(not(feature = "std"))]
pub(crate) fn store_inner_and_resource_limiter_ref(
&mut self,
) -> (&mut StoreInner, ResourceLimiterRef) {
(&mut self.inner, ResourceLimiterRef(None))
}

/// Returns `true` if fuel metering has been enabled.
fn is_fuel_metering_enabled(&self) -> bool {
self.engine().config().get_consume_fuel()
Expand Down