From 4168d2e4ca083059739270f4a601ec84c736c28a Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Thu, 9 May 2024 09:47:29 -0700 Subject: [PATCH 1/6] feat: per call context Add `plugin.call_with_context` and `current_plugin.context` methods, enabling per-call context to be looped from the guest invocation to any host functions it calls. In an HTTP server environment, this enables re-using a plugin across multiple requests while switching out backing connections and user information in host functions. (Imagine a host function, `update_user` -- previously the plugin would have to have been aware of the user to pass to the host function. Now that information is ambient.) This is a backwards-compatible change and requires no changes to existing plugins. Implement by adding a global, mutable externref to the extism kernel. Since most programming languages, including Rust, don't let you define these natively, we accomplish this by using `wasm-merge` to combine the kernel Wasm with Wasm generated by a WAT file containing only the global. (This pattern might be useful for other Wasm constructs we can't use directly from Rust, like `v128` in argument parameters.) Wasmtime requires extern refs to be `Any + Send + Sync + 'static`; we additionally add `Clone`. I haven't tried this with an `Arc` directly, but it should work at least for container structs that hold `Arc`'s themselves. --- kernel/build.sh | 5 ++-- kernel/extism-context.wat | 3 ++ runtime/extism.h | 20 +++++++++++++ runtime/src/current_plugin.rs | 17 +++++++++++ runtime/src/extism-runtime.wasm | Bin 3508 -> 3454 bytes runtime/src/plugin.rs | 46 ++++++++++++++++++++++++++--- runtime/src/sdk.rs | 50 +++++++++++++++++++++++++++++++- runtime/src/tests/runtime.rs | 37 +++++++++++++++++++++++ 8 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 kernel/extism-context.wat diff --git a/kernel/build.sh b/kernel/build.sh index e4bbb588c..4697342f7 100755 --- a/kernel/build.sh +++ b/kernel/build.sh @@ -17,6 +17,7 @@ done cargo build --package extism-runtime-kernel --bin extism-runtime --release --target wasm32-unknown-unknown $CARGO_FLAGS cp target/wasm32-unknown-unknown/release/extism-runtime.wasm . -wasm-strip extism-runtime.wasm -mv extism-runtime.wasm ../runtime/src/extism-runtime.wasm +wasm-tools parse extism-context.wat -o extism-context.wasm +wasm-merge --enable-reference-types ./extism-runtime.wasm runtime extism-context.wasm context -o ../runtime/src/extism-runtime.wasm +wasm-strip ../runtime/src/extism-runtime.wasm diff --git a/kernel/extism-context.wat b/kernel/extism-context.wat new file mode 100644 index 000000000..55c362098 --- /dev/null +++ b/kernel/extism-context.wat @@ -0,0 +1,3 @@ +(module + (global (export "extism_context") (mut externref) (ref.null extern)) +) diff --git a/runtime/extism.h b/runtime/extism.h index 3439bc85c..78059b3bc 100644 --- a/runtime/extism.h +++ b/runtime/extism.h @@ -113,6 +113,12 @@ extern "C" { */ const uint8_t *extism_plugin_id(ExtismPlugin *plugin); +/** + * Get the current plugin's associated context data. Returns null if call was made without + * context. + */ +void *extism_current_plugin_context(ExtismCurrentPlugin *plugin); + /** * Returns a pointer to the memory of the currently running plugin * NOTE: this should only be called from host functions. @@ -231,6 +237,20 @@ int32_t extism_plugin_call(ExtismPlugin *plugin, const uint8_t *data, ExtismSize data_len); +/** + * Call a function with per-call context. + * + * `func_name`: is the function to call + * `data`: is the input data + * `data_len`: is the length of `data` + * `context`: a pointer to context data that will be available in host functions + */ +int32_t extism_plugin_call_with_context(ExtismPlugin *plugin, + const char *func_name, + const uint8_t *data, + ExtismSize data_len, + void *context); + /** * Get the error associated with a `Plugin` */ diff --git a/runtime/src/current_plugin.rs b/runtime/src/current_plugin.rs index 29af76ad8..9d9fb3dca 100644 --- a/runtime/src/current_plugin.rs +++ b/runtime/src/current_plugin.rs @@ -186,6 +186,23 @@ impl CurrentPlugin { anyhow::bail!("{} unable to locate extism memory", self.id) } + pub fn context(&mut self) -> Result { + let (linker, mut store) = self.linker_and_store(); + let Some(Extern::Global(xs)) = linker.get(&mut store, EXTISM_ENV_MODULE, "extism_context") + else { + anyhow::bail!("unable to locate an extism kernel global: extism_context",) + }; + + let Val::ExternRef(Some(xs)) = xs.get(store) else { + anyhow::bail!("expected extism_context to be an externref value",) + }; + + match xs.data().downcast_ref::().cloned() { + Some(xs) => Ok(xs.clone()), + None => anyhow::bail!("could not downcast extism_context",), + } + } + pub fn memory_alloc(&mut self, n: u64) -> Result { if n == 0 { return Ok(MemoryHandle { diff --git a/runtime/src/extism-runtime.wasm b/runtime/src/extism-runtime.wasm index 07ce60393f78d2d0e829846af39272101ac52f33..187bd2c9e4b8f0fda65e4e4aad77ee17f8f7b6d4 100755 GIT binary patch delta 504 zcmZXO!Ae3=5QgVJ$9u1M)NEr`1Xnj=B_RZ2MQ~fT3~CowE5Q&mP{KuceT6!R574en zL=m*BC#X%U3R?FDwTR|W7$FDd%zVuJ|9?IGHC3lds{tZHHe4oj%jj|u-7b}75CjMq zkbwcifXYO2A}J+8fW^-iLhvy;AtFnH5_VEH@z_)WdA;5p4S(lSq%IE0_TYt_o3 zzf);dCF0did%xB2cbf-oZY4$DCX%<1U~A|;t|lYok_%TPNIgrNDF-xppncH+&Rzuc ztK7o7UJM-p`XaPBL&}9GmWVvc$+SxwG49r=D06B|>9nJ-8R@F)%a5U#SSa56&mb=Il#FmQ7E-dV?uj)u*A99|ddZ&-~NJdRwHC3Yj# z*7wm`3{%R4$&HZo2q_Io{P(J0$T^G<+r6k1*AJDo)c`=C^Nxvl63vVMW|Kpq=&#VY FA>Rv;Y>WT^ delta 555 zcmZvX(Mm!=5Qb-V-E*{!)B;T-IC^6T4T>%#ir~~;JwSJaER&pt+1YPq|NZwPdNZORS1BO?V8WZ_N-0!XtYTFsXca2U zstR<{N6;96heLXrA#%MuLI^{L$qYkqgn$v@3Y}W50a8KtZeFmkQOcLfJNpbou2?Lu z0XsVQ45Q3s3i;f2W;IvIbJlk?9J442`ckmyM^~Td3 zJoHCo(#3UbiN}BW81u!zfq6)CpL4G(3j%JF9%Mp$Iiq*E(f-eR|9CHVk*P>WIk diff --git a/runtime/src/plugin.rs b/runtime/src/plugin.rs index 686976629..b9f90ffb9 100644 --- a/runtime/src/plugin.rs +++ b/runtime/src/plugin.rs @@ -1,4 +1,5 @@ use std::{ + any::Any, collections::{BTreeMap, BTreeSet}, path::PathBuf, }; @@ -462,7 +463,12 @@ impl Plugin { } // Store input in memory and re-initialize `Internal` pointer - pub(crate) fn set_input(&mut self, input: *const u8, mut len: usize) -> Result<(), Error> { + pub(crate) fn set_input( + &mut self, + input: *const u8, + mut len: usize, + call_context: Option, + ) -> Result<(), Error> { self.output = Output::default(); self.clear_error()?; let id = self.id.to_string(); @@ -496,6 +502,13 @@ impl Plugin { )?; } + if let Some(Extern::Global(ctxt)) = + self.linker + .get(&mut self.store, EXTISM_ENV_MODULE, "extism_context") + { + ctxt.set(&mut self.store, Val::ExternRef(call_context))?; + } + Ok(()) } @@ -673,6 +686,7 @@ impl Plugin { lock: &mut std::sync::MutexGuard>, name: impl AsRef, input: impl AsRef<[u8]>, + call_context: Option, ) -> Result { let name = name.as_ref(); let input = input.as_ref(); @@ -686,7 +700,7 @@ impl Plugin { self.instantiate(lock).map_err(|e| (e, -1))?; - self.set_input(input.as_ptr(), input.len()) + self.set_input(input.as_ptr(), input.len(), call_context) .map_err(|x| (x, -1))?; let func = match self.get_func(lock, name) { @@ -873,11 +887,35 @@ impl Plugin { let lock = self.instance.clone(); let mut lock = lock.lock().unwrap(); let data = input.to_bytes()?; - self.raw_call(&mut lock, name, data) + self.raw_call(&mut lock, name, data, None) .map_err(|e| e.0) .and_then(move |_| self.output()) } + pub fn call_with_context<'a, 'b, T, U, C>( + &'b mut self, + name: impl AsRef, + input: T, + context: C, + ) -> Result + where + T: ToBytes<'a>, + U: FromBytes<'b>, + C: Any + Send + Sync + 'static, + { + let lock = self.instance.clone(); + let mut lock = lock.lock().unwrap(); + let data = input.to_bytes()?; + self.raw_call(&mut lock, name, data, Some(ExternRef::new(context))) + .map_err(|e| e.0) + .and_then(move |_| self.output()) + } + + pub fn invoke(&mut self, name: &str, args: &[wasmtime::Val]) { + let lock = self.instance.clone(); + let mut lock = lock.lock().unwrap(); + } + /// Similar to `Plugin::call`, but returns the Extism error code along with the /// `Error`. It is assumed if `Ok(_)` is returned that the error code was `0`. /// @@ -892,7 +930,7 @@ impl Plugin { let lock = self.instance.clone(); let mut lock = lock.lock().unwrap(); let data = input.to_bytes().map_err(|e| (e, -1))?; - self.raw_call(&mut lock, name, data) + self.raw_call(&mut lock, name, data, None) .and_then(move |_| self.output().map_err(|e| (e, -1))) } diff --git a/runtime/src/sdk.rs b/runtime/src/sdk.rs index 0ed324639..28d0a4871 100644 --- a/runtime/src/sdk.rs +++ b/runtime/src/sdk.rs @@ -84,6 +84,24 @@ pub unsafe extern "C" fn extism_plugin_id(plugin: *mut Plugin) -> *const u8 { plugin.id.as_bytes().as_ptr() } +/// Get the current plugin's associated context data. Returns null if call was made without +/// context. +#[no_mangle] +pub unsafe extern "C" fn extism_current_plugin_context( + plugin: *mut CurrentPlugin, +) -> *mut std::ffi::c_void { + if plugin.is_null() { + return std::ptr::null_mut(); + } + + let plugin = &mut *plugin; + if let Ok(CVoidContainer(ptr)) = plugin.context::() { + ptr + } else { + std::ptr::null_mut() + } +} + /// Returns a pointer to the memory of the currently running plugin /// NOTE: this should only be called from host functions. #[no_mangle] @@ -464,6 +482,31 @@ pub unsafe extern "C" fn extism_plugin_call( func_name: *const c_char, data: *const u8, data_len: Size, +) -> i32 { + extism_plugin_call_with_context(plugin, func_name, data, data_len, std::ptr::null_mut()) +} + +#[derive(Clone)] +#[repr(transparent)] +struct CVoidContainer(*mut std::ffi::c_void); + +// "You break it, you buy it." +unsafe impl Send for CVoidContainer {} +unsafe impl Sync for CVoidContainer {} + +/// Call a function with per-call context. +/// +/// `func_name`: is the function to call +/// `data`: is the input data +/// `data_len`: is the length of `data` +/// `context`: a pointer to context data that will be available in host functions +#[no_mangle] +pub unsafe extern "C" fn extism_plugin_call_with_context( + plugin: *mut Plugin, + func_name: *const c_char, + data: *const u8, + data_len: Size, + context: *mut std::ffi::c_void, ) -> i32 { if plugin.is_null() { return -1; @@ -485,7 +528,12 @@ pub unsafe extern "C" fn extism_plugin_call( name ); let input = std::slice::from_raw_parts(data, data_len as usize); - let res = plugin.raw_call(&mut lock, name, input); + let res = plugin.raw_call( + &mut lock, + name, + input, + Some(ExternRef::new(CVoidContainer(context))), + ); match res { Err((e, rc)) => plugin.return_error(&mut lock, e, rc), diff --git a/runtime/src/tests/runtime.rs b/runtime/src/tests/runtime.rs index 42b86d2fd..34d53a7ab 100644 --- a/runtime/src/tests/runtime.rs +++ b/runtime/src/tests/runtime.rs @@ -307,6 +307,43 @@ fn test_toml_manifest() { assert_eq!(count.get("count").unwrap().as_i64().unwrap(), 1); } +#[test] +fn test_call_with_context() { + // assert!(set_log_file("stdout", Some(log::Level::Trace))); + #[derive(Clone)] + struct Foo { + message: String, + } + + let f = Function::new( + "host_reflect", + [PTR], + [PTR], + UserData::default(), + |current_plugin, _val, ret, _user_data: UserData<()>| { + let foo = current_plugin.context::()?; + let hnd = current_plugin.memory_new(foo.message)?; + ret[0] = current_plugin.memory_to_val(hnd); + Ok(()) + }, + ); + + let mut plugin = Plugin::new(WASM_REFLECT, [f], true).unwrap(); + + let message = "hello world"; + let output: String = plugin + .call_with_context( + "reflect", + "anything, really", + Foo { + message: message.to_string(), + }, + ) + .unwrap(); + + assert_eq!(output, message); +} + #[test] fn test_fuzz_reflect_plugin() { // assert!(set_log_file("stdout", Some(log::Level::Trace))); From 68da28b67cb8cdd3811f6e90c52413a458395e1c Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Thu, 9 May 2024 11:47:54 -0700 Subject: [PATCH 2/6] feat: do not let linked modules access extism kernel memory, tables, or globals --- runtime/src/plugin.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/src/plugin.rs b/runtime/src/plugin.rs index b9f90ffb9..d9d410289 100644 --- a/runtime/src/plugin.rs +++ b/runtime/src/plugin.rs @@ -194,6 +194,12 @@ fn add_module( } for import in module.imports() { + let module = import.module(); + + if module == EXTISM_ENV_MODULE && !matches!(import.ty(), ExternType::Func(_)) { + anyhow::bail!("linked modules cannot access non-function exports of extism kernel"); + } + if !linked.contains(import.module()) { if let Some(m) = modules.get(import.module()) { add_module( From e412d98799e10957583957d6bfd9c4630ccb0c53 Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Thu, 9 May 2024 11:49:32 -0700 Subject: [PATCH 3/6] add wasm-tools to kernel workflow --- .github/workflows/kernel.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/kernel.yml b/.github/workflows/kernel.yml index 32c18fe3f..da87883c7 100644 --- a/.github/workflows/kernel.yml +++ b/.github/workflows/kernel.yml @@ -21,6 +21,9 @@ jobs: target: wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 + - name: install wasm-tools + uses: bytecodealliance/actions/wasm-tools/setup@v1 + - name: Install deps run: | sudo apt install wabt --yes From 3149606d22aa9e1afc651155f7ef2a8bd26fd2bb Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Fri, 10 May 2024 09:38:55 -0700 Subject: [PATCH 4/6] fix: remove intermediate files from kernel build.sh --- kernel/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/build.sh b/kernel/build.sh index 4697342f7..a95265fe3 100755 --- a/kernel/build.sh +++ b/kernel/build.sh @@ -20,4 +20,6 @@ cp target/wasm32-unknown-unknown/release/extism-runtime.wasm . wasm-tools parse extism-context.wat -o extism-context.wasm wasm-merge --enable-reference-types ./extism-runtime.wasm runtime extism-context.wasm context -o ../runtime/src/extism-runtime.wasm +rm extism-context.wasm +rm extism-runtime.wasm wasm-strip ../runtime/src/extism-runtime.wasm From 4794c1933e6d78e25f1a0d21a32b9a306139a257 Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Tue, 21 May 2024 09:47:59 -0700 Subject: [PATCH 5/6] fix: remove unused method --- runtime/src/plugin.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/runtime/src/plugin.rs b/runtime/src/plugin.rs index d9d410289..6ec79a65f 100644 --- a/runtime/src/plugin.rs +++ b/runtime/src/plugin.rs @@ -917,11 +917,6 @@ impl Plugin { .and_then(move |_| self.output()) } - pub fn invoke(&mut self, name: &str, args: &[wasmtime::Val]) { - let lock = self.instance.clone(); - let mut lock = lock.lock().unwrap(); - } - /// Similar to `Plugin::call`, but returns the Extism error code along with the /// `Error`. It is assumed if `Ok(_)` is returned that the error code was `0`. /// From 8a6b78cd3e1801bb703621eef1b61681c5986fbe Mon Sep 17 00:00:00 2001 From: Chris Dickinson Date: Tue, 21 May 2024 10:56:26 -0700 Subject: [PATCH 6/6] s/context/host_context/g --- runtime/extism.h | 20 ++++++++++---------- runtime/src/current_plugin.rs | 2 +- runtime/src/plugin.rs | 14 +++++++------- runtime/src/sdk.rs | 20 ++++++++++---------- runtime/src/tests/runtime.rs | 7 +++---- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/runtime/extism.h b/runtime/extism.h index 78059b3bc..b9f1ec853 100644 --- a/runtime/extism.h +++ b/runtime/extism.h @@ -114,10 +114,10 @@ extern "C" { const uint8_t *extism_plugin_id(ExtismPlugin *plugin); /** - * Get the current plugin's associated context data. Returns null if call was made without - * context. + * Get the current plugin's associated host context data. Returns null if call was made without + * host context. */ -void *extism_current_plugin_context(ExtismCurrentPlugin *plugin); +void *extism_current_plugin_host_context(ExtismCurrentPlugin *plugin); /** * Returns a pointer to the memory of the currently running plugin @@ -238,18 +238,18 @@ int32_t extism_plugin_call(ExtismPlugin *plugin, ExtismSize data_len); /** - * Call a function with per-call context. + * Call a function with host context. * * `func_name`: is the function to call * `data`: is the input data * `data_len`: is the length of `data` - * `context`: a pointer to context data that will be available in host functions + * `host_context`: a pointer to context data that will be available in host functions */ -int32_t extism_plugin_call_with_context(ExtismPlugin *plugin, - const char *func_name, - const uint8_t *data, - ExtismSize data_len, - void *context); +int32_t extism_plugin_call_with_host_context(ExtismPlugin *plugin, + const char *func_name, + const uint8_t *data, + ExtismSize data_len, + void *host_context); /** * Get the error associated with a `Plugin` diff --git a/runtime/src/current_plugin.rs b/runtime/src/current_plugin.rs index 9d9fb3dca..bc6e4a7ba 100644 --- a/runtime/src/current_plugin.rs +++ b/runtime/src/current_plugin.rs @@ -186,7 +186,7 @@ impl CurrentPlugin { anyhow::bail!("{} unable to locate extism memory", self.id) } - pub fn context(&mut self) -> Result { + pub fn host_context(&mut self) -> Result { let (linker, mut store) = self.linker_and_store(); let Some(Extern::Global(xs)) = linker.get(&mut store, EXTISM_ENV_MODULE, "extism_context") else { diff --git a/runtime/src/plugin.rs b/runtime/src/plugin.rs index 6ec79a65f..c33b856e3 100644 --- a/runtime/src/plugin.rs +++ b/runtime/src/plugin.rs @@ -473,7 +473,7 @@ impl Plugin { &mut self, input: *const u8, mut len: usize, - call_context: Option, + host_context: Option, ) -> Result<(), Error> { self.output = Output::default(); self.clear_error()?; @@ -512,7 +512,7 @@ impl Plugin { self.linker .get(&mut self.store, EXTISM_ENV_MODULE, "extism_context") { - ctxt.set(&mut self.store, Val::ExternRef(call_context))?; + ctxt.set(&mut self.store, Val::ExternRef(host_context))?; } Ok(()) @@ -692,7 +692,7 @@ impl Plugin { lock: &mut std::sync::MutexGuard>, name: impl AsRef, input: impl AsRef<[u8]>, - call_context: Option, + host_context: Option, ) -> Result { let name = name.as_ref(); let input = input.as_ref(); @@ -706,7 +706,7 @@ impl Plugin { self.instantiate(lock).map_err(|e| (e, -1))?; - self.set_input(input.as_ptr(), input.len(), call_context) + self.set_input(input.as_ptr(), input.len(), host_context) .map_err(|x| (x, -1))?; let func = match self.get_func(lock, name) { @@ -898,11 +898,11 @@ impl Plugin { .and_then(move |_| self.output()) } - pub fn call_with_context<'a, 'b, T, U, C>( + pub fn call_with_host_context<'a, 'b, T, U, C>( &'b mut self, name: impl AsRef, input: T, - context: C, + host_context: C, ) -> Result where T: ToBytes<'a>, @@ -912,7 +912,7 @@ impl Plugin { let lock = self.instance.clone(); let mut lock = lock.lock().unwrap(); let data = input.to_bytes()?; - self.raw_call(&mut lock, name, data, Some(ExternRef::new(context))) + self.raw_call(&mut lock, name, data, Some(ExternRef::new(host_context))) .map_err(|e| e.0) .and_then(move |_| self.output()) } diff --git a/runtime/src/sdk.rs b/runtime/src/sdk.rs index 28d0a4871..5caa051ef 100644 --- a/runtime/src/sdk.rs +++ b/runtime/src/sdk.rs @@ -84,10 +84,10 @@ pub unsafe extern "C" fn extism_plugin_id(plugin: *mut Plugin) -> *const u8 { plugin.id.as_bytes().as_ptr() } -/// Get the current plugin's associated context data. Returns null if call was made without -/// context. +/// Get the current plugin's associated host context data. Returns null if call was made without +/// host context. #[no_mangle] -pub unsafe extern "C" fn extism_current_plugin_context( +pub unsafe extern "C" fn extism_current_plugin_host_context( plugin: *mut CurrentPlugin, ) -> *mut std::ffi::c_void { if plugin.is_null() { @@ -95,7 +95,7 @@ pub unsafe extern "C" fn extism_current_plugin_context( } let plugin = &mut *plugin; - if let Ok(CVoidContainer(ptr)) = plugin.context::() { + if let Ok(CVoidContainer(ptr)) = plugin.host_context::() { ptr } else { std::ptr::null_mut() @@ -483,7 +483,7 @@ pub unsafe extern "C" fn extism_plugin_call( data: *const u8, data_len: Size, ) -> i32 { - extism_plugin_call_with_context(plugin, func_name, data, data_len, std::ptr::null_mut()) + extism_plugin_call_with_host_context(plugin, func_name, data, data_len, std::ptr::null_mut()) } #[derive(Clone)] @@ -494,19 +494,19 @@ struct CVoidContainer(*mut std::ffi::c_void); unsafe impl Send for CVoidContainer {} unsafe impl Sync for CVoidContainer {} -/// Call a function with per-call context. +/// Call a function with host context. /// /// `func_name`: is the function to call /// `data`: is the input data /// `data_len`: is the length of `data` -/// `context`: a pointer to context data that will be available in host functions +/// `host_context`: a pointer to context data that will be available in host functions #[no_mangle] -pub unsafe extern "C" fn extism_plugin_call_with_context( +pub unsafe extern "C" fn extism_plugin_call_with_host_context( plugin: *mut Plugin, func_name: *const c_char, data: *const u8, data_len: Size, - context: *mut std::ffi::c_void, + host_context: *mut std::ffi::c_void, ) -> i32 { if plugin.is_null() { return -1; @@ -532,7 +532,7 @@ pub unsafe extern "C" fn extism_plugin_call_with_context( &mut lock, name, input, - Some(ExternRef::new(CVoidContainer(context))), + Some(ExternRef::new(CVoidContainer(host_context))), ); match res { diff --git a/runtime/src/tests/runtime.rs b/runtime/src/tests/runtime.rs index 34d53a7ab..42a177212 100644 --- a/runtime/src/tests/runtime.rs +++ b/runtime/src/tests/runtime.rs @@ -308,8 +308,7 @@ fn test_toml_manifest() { } #[test] -fn test_call_with_context() { - // assert!(set_log_file("stdout", Some(log::Level::Trace))); +fn test_call_with_host_context() { #[derive(Clone)] struct Foo { message: String, @@ -321,7 +320,7 @@ fn test_call_with_context() { [PTR], UserData::default(), |current_plugin, _val, ret, _user_data: UserData<()>| { - let foo = current_plugin.context::()?; + let foo = current_plugin.host_context::()?; let hnd = current_plugin.memory_new(foo.message)?; ret[0] = current_plugin.memory_to_val(hnd); Ok(()) @@ -332,7 +331,7 @@ fn test_call_with_context() { let message = "hello world"; let output: String = plugin - .call_with_context( + .call_with_host_context( "reflect", "anything, really", Foo {