Class: Wasmtime::Store
- Inherits:
-
Object
- Object
- Wasmtime::Store
- Defined in:
- ext/src/ruby_api/store.rs
Overview
Represents a WebAssembly store.
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Boolean
Closes the store, immediately freeing its WebAssembly memory.
-
#closed? ⇒ Boolean
Whether this store has been closed via #close.
-
#data ⇒ Object
The passed in value in Store.new.
-
#get_fuel ⇒ Integer
Returns the amount of fuel in the Store.
-
#linear_memory_limit_hit? ⇒ Boolean
Returns whether the linear memory limit has been hit.
-
#max_linear_memory_consumed ⇒ Integer
Returns the maximum linear memory consumed.
-
#set_epoch_deadline(ticks_beyond_current) ⇒ nil
Sets the epoch deadline to a certain number of ticks in the future.
-
#set_fuel(fuel) ⇒ Object
Sets fuel to the Store.
Class Method Details
.new(engine, data = nil, wasi_config: nil, wasi_p1_config: nil, limits: nil) ⇒ Wasmtime::Store
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'ext/src/ruby_api/store.rs', line 183
pub fn new(args: &[Value]) -> Result<Self, Error> {
let ruby = Ruby::get().unwrap();
let args = scan_args::scan_args::<(&Engine,), (Option<Value>,), (), (), _, ()>(args)?;
let kw = scan_args::get_kwargs::<
_,
(),
(Option<&WasiConfig>, Option<&WasiConfig>, Option<RHash>),
(),
>(
args.keywords,
&[],
&[*WASI_CONFIG, *WASI_P1_CONFIG, *LIMITS],
)?;
let (engine,) = args.required;
let (user_data,) = args.optional;
let user_data = user_data.unwrap_or_else(|| ().into_value_with(&ruby));
let wasi_config = kw.optional.0;
let wasi_p1_config = kw.optional.1;
let (wasi, wasi_retained) = wasi_config
.map(|wasi_config| wasi_config.build(&ruby))
.transpose()?
.unzip();
let (wasi_p1, wasi_p1_retained) = wasi_p1_config
.map(|wasi_config| wasi_config.build_p1(&ruby))
.transpose()?
.unzip();
// Store all WasiRetainedData to support both wasi and wasi_p1 configs
let wasi_retained_data: Vec<WasiRetainedData> = [wasi_retained, wasi_p1_retained]
.into_iter()
.flatten()
.flatten()
.collect();
let limiter = match kw.optional.2 {
None => StoreLimitsBuilder::new(),
Some(limits) => hash_to_store_limits_builder(&ruby, limits)?,
}
.build();
let limiter = TrackingResourceLimiter::new(limiter);
let eng = engine.get();
let store_data = StoreData {
user_data,
wasi_p1,
wasi,
refs: Default::default(),
wasi_retained_data,
last_error: Default::default(),
store_limits: limiter,
resource_table: Default::default(),
};
let store = Self {
inner: UnsafeCell::new(Some(StoreImpl::new(eng, store_data))),
};
unsafe { (*store.inner.get()).as_mut().unwrap() }.limiter(|data| &mut data.store_limits);
Ok(store)
}
|
Instance Method Details
#close ⇒ Boolean
Closes the store, immediately freeing its WebAssembly memory.
In Wasmtime the linear memory of every instance lives in the Wasmtime::Store, so
this is the way to reclaim that memory deterministically once a job is
done. Any subsequent use of this store raises an error. The same applies
to instances, memories, funcs, globals and tables created from it.
Calling close on an already-closed store is a no-op.
326 327 328 |
# File 'ext/src/ruby_api/store.rs', line 326
pub fn close(&self) -> bool {
unsafe { (*self.inner.get()).take() }.is_some()
}
|
#closed? ⇒ Boolean
Returns Whether this store has been closed via #close.
333 334 335 |
# File 'ext/src/ruby_api/store.rs', line 333
pub fn closed(&self) -> bool {
unsafe { (*self.inner.get()).is_none() }
}
|
#data ⇒ Object
Returns The passed in value in new.
248 249 250 |
# File 'ext/src/ruby_api/store.rs', line 248
pub fn data(&self) -> Result<Value, Error> {
Ok(self.context()?.data().user_data())
}
|
#get_fuel ⇒ Integer
Returns the amount of fuel in the Wasmtime::Store.
257 258 259 |
# File 'ext/src/ruby_api/store.rs', line 257
pub fn get_fuel(&self) -> Result<u64, Error> {
self.inner_ref()?.get_fuel().map_err(|e| error!("{}", e))
}
|
#linear_memory_limit_hit? ⇒ Boolean
Returns whether the linear memory limit has been hit.
294 295 296 297 298 299 300 |
# File 'ext/src/ruby_api/store.rs', line 294
pub fn linear_memory_limit_hit(&self) -> Result<bool, Error> {
Ok(self
.context()?
.data()
.store_limits
.linear_memory_limit_hit())
}
|
#max_linear_memory_consumed ⇒ Integer
Returns the maximum linear memory consumed.
306 307 308 309 310 311 312 |
# File 'ext/src/ruby_api/store.rs', line 306
pub fn max_linear_memory_consumed(&self) -> Result<usize, Error> {
Ok(self
.context()?
.data()
.store_limits
.max_linear_memory_consumed())
}
|
#set_epoch_deadline(ticks_beyond_current) ⇒ nil
Sets the epoch deadline to a certain number of ticks in the future.
Raises if there isn't enough fuel left in the Wasmtime::Store, or when the Engine's config does not have fuel enabled.
284 285 286 287 |
# File 'ext/src/ruby_api/store.rs', line 284
pub fn set_epoch_deadline(&self, ticks_beyond_current: u64) -> Result<(), Error> {
self.inner_mut()?.set_epoch_deadline(ticks_beyond_current);
Ok(())
}
|
#set_fuel(fuel) ⇒ Object
Sets fuel to the Wasmtime::Store.
266 267 268 269 270 271 272 |
# File 'ext/src/ruby_api/store.rs', line 266
pub fn set_fuel(&self, fuel: u64) -> Result<(), Error> {
self.inner_mut()?
.set_fuel(fuel)
.map_err(|e| error!("{}", e))?;
Ok(())
}
|