mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 05:18:43 +00:00
Export wasmer::{BaseTunables, Tunables}
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
- [#1851](https://github.com/wasmerio/wasmer/pull/1851) Improve test suite and documentation of the Wasmer C API
|
- [#1851](https://github.com/wasmerio/wasmer/pull/1851) Improve test suite and documentation of the Wasmer C API
|
||||||
- [#1874](https://github.com/wasmerio/wasmer/pull/1874) Set `CompilerConfig` to be owned (following wasm-c-api)
|
- [#1874](https://github.com/wasmerio/wasmer/pull/1874) Set `CompilerConfig` to be owned (following wasm-c-api)
|
||||||
- [#1880](https://github.com/wasmerio/wasmer/pull/1880) Remove cmake dependency for tests
|
- [#1880](https://github.com/wasmerio/wasmer/pull/1880) Remove cmake dependency for tests
|
||||||
|
- [#1924](https://github.com/wasmerio/wasmer/pull/1924) Rename reference implementation `wasmer::Tunables` to `wasmer::BaseTunables`. Export trait `wasmer_engine::Tunables` as `wasmer::Tunables`.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ use std::sync::Arc;
|
|||||||
use wasmer::{
|
use wasmer::{
|
||||||
imports,
|
imports,
|
||||||
vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition},
|
vm::{self, MemoryError, MemoryStyle, TableStyle, VMMemoryDefinition, VMTableDefinition},
|
||||||
wat2wasm, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target,
|
wat2wasm, BaseTunables, Instance, Memory, MemoryType, Module, Pages, Store, TableType, Target,
|
||||||
Tunables as ReferenceTunables,
|
Tunables,
|
||||||
};
|
};
|
||||||
use wasmer_compiler_cranelift::Cranelift;
|
use wasmer_compiler_cranelift::Cranelift;
|
||||||
use wasmer_engine::Tunables;
|
|
||||||
use wasmer_engine_jit::JIT;
|
use wasmer_engine_jit::JIT;
|
||||||
|
|
||||||
/// A custom tunables that allows you to set a memory limit.
|
/// A custom tunables that allows you to set a memory limit.
|
||||||
@@ -147,7 +146,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
// Here is where the fun begins
|
// Here is where the fun begins
|
||||||
|
|
||||||
let base = ReferenceTunables::for_target(&Target::default());
|
let base = BaseTunables::for_target(&Target::default());
|
||||||
let tunables = LimitingTunables::new(base, Pages(24));
|
let tunables = LimitingTunables::new(base, Pages(24));
|
||||||
|
|
||||||
// Create a store, that holds the engine and our custom tunables
|
// Create a store, that holds the engine and our custom tunables
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ pub use crate::module::Module;
|
|||||||
pub use crate::native::NativeFunc;
|
pub use crate::native::NativeFunc;
|
||||||
pub use crate::ptr::{Array, Item, WasmPtr};
|
pub use crate::ptr::{Array, Item, WasmPtr};
|
||||||
pub use crate::store::{Store, StoreObject};
|
pub use crate::store::{Store, StoreObject};
|
||||||
pub use crate::tunables::Tunables;
|
pub use crate::tunables::BaseTunables;
|
||||||
pub use crate::types::{
|
pub use crate::types::{
|
||||||
ExportType, ExternRef, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
|
ExportType, ExternRef, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
|
||||||
MemoryType, Mutability, TableType, Val, ValType,
|
MemoryType, Mutability, TableType, Val, ValType,
|
||||||
@@ -311,7 +311,7 @@ pub use wasmer_compiler::{
|
|||||||
};
|
};
|
||||||
pub use wasmer_engine::{
|
pub use wasmer_engine::{
|
||||||
ChainableNamedResolver, DeserializeError, Engine, Export, FrameInfo, LinkError, NamedResolver,
|
ChainableNamedResolver, DeserializeError, Engine, Export, FrameInfo, LinkError, NamedResolver,
|
||||||
NamedResolverChain, Resolver, RuntimeError, SerializeError,
|
NamedResolverChain, Resolver, RuntimeError, SerializeError, Tunables,
|
||||||
};
|
};
|
||||||
pub use wasmer_types::{
|
pub use wasmer_types::{
|
||||||
Atomically, Bytes, ExportIndex, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,
|
Atomically, Bytes, ExportIndex, GlobalInit, LocalFunctionIndex, MemoryView, Pages, ValueType,
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
use crate::tunables::Tunables;
|
use crate::tunables::BaseTunables;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
#[cfg(all(feature = "compiler", feature = "engine"))]
|
#[cfg(all(feature = "compiler", feature = "engine"))]
|
||||||
use wasmer_compiler::CompilerConfig;
|
use wasmer_compiler::CompilerConfig;
|
||||||
use wasmer_engine::Engine;
|
use wasmer_engine::{Engine, Tunables};
|
||||||
use wasmer_engine::Tunables as BaseTunables;
|
|
||||||
|
|
||||||
/// The store represents all global state that can be manipulated by
|
/// The store represents all global state that can be manipulated by
|
||||||
/// WebAssembly programs. It consists of the runtime representation
|
/// WebAssembly programs. It consists of the runtime representation
|
||||||
@@ -19,7 +18,7 @@ use wasmer_engine::Tunables as BaseTunables;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Store {
|
pub struct Store {
|
||||||
engine: Arc<dyn Engine + Send + Sync>,
|
engine: Arc<dyn Engine + Send + Sync>,
|
||||||
tunables: Arc<dyn BaseTunables + Send + Sync>,
|
tunables: Arc<dyn Tunables + Send + Sync>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
@@ -30,15 +29,12 @@ impl Store {
|
|||||||
{
|
{
|
||||||
Self {
|
Self {
|
||||||
engine: engine.cloned(),
|
engine: engine.cloned(),
|
||||||
tunables: Arc::new(Tunables::for_target(engine.target())),
|
tunables: Arc::new(BaseTunables::for_target(engine.target())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new `Store` with a specific [`Engine`] and [`Tunables`].
|
/// Creates a new `Store` with a specific [`Engine`] and [`Tunables`].
|
||||||
pub fn new_with_tunables<E>(
|
pub fn new_with_tunables<E>(engine: &E, tunables: impl Tunables + Send + Sync + 'static) -> Self
|
||||||
engine: &E,
|
|
||||||
tunables: impl BaseTunables + Send + Sync + 'static,
|
|
||||||
) -> Self
|
|
||||||
where
|
where
|
||||||
E: Engine + ?Sized,
|
E: Engine + ?Sized,
|
||||||
{
|
{
|
||||||
@@ -49,7 +45,7 @@ impl Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`Tunables`].
|
/// Returns the [`Tunables`].
|
||||||
pub fn tunables(&self) -> &dyn BaseTunables {
|
pub fn tunables(&self) -> &dyn Tunables {
|
||||||
self.tunables.as_ref()
|
self.tunables.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +107,7 @@ impl Default for Store {
|
|||||||
|
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
let engine = get_engine(config);
|
let engine = get_engine(config);
|
||||||
let tunables = Tunables::for_target(engine.target());
|
let tunables = BaseTunables::for_target(engine.target());
|
||||||
Store {
|
Store {
|
||||||
engine: Arc::new(engine),
|
engine: Arc::new(engine),
|
||||||
tunables: Arc::new(tunables),
|
tunables: Arc::new(tunables),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::ptr::NonNull;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use target_lexicon::{OperatingSystem, PointerWidth};
|
use target_lexicon::{OperatingSystem, PointerWidth};
|
||||||
use wasmer_compiler::Target;
|
use wasmer_compiler::Target;
|
||||||
use wasmer_engine::Tunables as BaseTunables;
|
use wasmer_engine::Tunables;
|
||||||
use wasmer_vm::MemoryError;
|
use wasmer_vm::MemoryError;
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
LinearMemory, LinearTable, Memory, MemoryStyle, Table, TableStyle, VMMemoryDefinition,
|
LinearMemory, LinearTable, Memory, MemoryStyle, Table, TableStyle, VMMemoryDefinition,
|
||||||
@@ -12,8 +12,15 @@ use wasmer_vm::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Tunable parameters for WebAssembly compilation.
|
/// Tunable parameters for WebAssembly compilation.
|
||||||
|
/// This is the reference implementation of the `Tunables` trait,
|
||||||
|
/// used by default.
|
||||||
|
///
|
||||||
|
/// You can use this as a template for creating a custom Tunables
|
||||||
|
/// implementation or use composition to wrap your Tunables around
|
||||||
|
/// this one. The later approach is demonstrated in the
|
||||||
|
/// tunables-limit-memory example.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Tunables {
|
pub struct BaseTunables {
|
||||||
/// For static heaps, the size in wasm pages of the heap protected by bounds checking.
|
/// For static heaps, the size in wasm pages of the heap protected by bounds checking.
|
||||||
pub static_memory_bound: Pages,
|
pub static_memory_bound: Pages,
|
||||||
|
|
||||||
@@ -24,8 +31,8 @@ pub struct Tunables {
|
|||||||
pub dynamic_memory_offset_guard_size: u64,
|
pub dynamic_memory_offset_guard_size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tunables {
|
impl BaseTunables {
|
||||||
/// Get the `Tunables` for a specific Target
|
/// Get the `BaseTunables` for a specific Target
|
||||||
pub fn for_target(target: &Target) -> Self {
|
pub fn for_target(target: &Target) -> Self {
|
||||||
let triple = target.triple();
|
let triple = target.triple();
|
||||||
let pointer_width: PointerWidth = triple.pointer_width().unwrap();
|
let pointer_width: PointerWidth = triple.pointer_width().unwrap();
|
||||||
@@ -61,7 +68,7 @@ impl Tunables {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BaseTunables for Tunables {
|
impl Tunables for BaseTunables {
|
||||||
/// Get a `MemoryStyle` for the provided `MemoryType`
|
/// Get a `MemoryStyle` for the provided `MemoryType`
|
||||||
fn memory_style(&self, memory: &MemoryType) -> MemoryStyle {
|
fn memory_style(&self, memory: &MemoryType) -> MemoryStyle {
|
||||||
// A heap with a maximum that doesn't exceed the static memory bound specified by the
|
// A heap with a maximum that doesn't exceed the static memory bound specified by the
|
||||||
@@ -148,7 +155,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn memory_style() {
|
fn memory_style() {
|
||||||
let tunables = Tunables {
|
let tunables = BaseTunables {
|
||||||
static_memory_bound: Pages(2048),
|
static_memory_bound: Pages(2048),
|
||||||
static_memory_offset_guard_size: 128,
|
static_memory_offset_guard_size: 128,
|
||||||
dynamic_memory_offset_guard_size: 256,
|
dynamic_memory_offset_guard_size: 256,
|
||||||
|
|||||||
Reference in New Issue
Block a user