mirror of
https://github.com/extism/extism.git
synced 2026-01-11 23:08:06 -05:00
Compare commits
7 Commits
custom-htt
...
throwaway
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14d7eae99c | ||
|
|
e89ddd5a2a | ||
|
|
93392e0884 | ||
|
|
4ebd0eb372 | ||
|
|
8feee0c693 | ||
|
|
773ab32a45 | ||
|
|
6a041d0c39 |
4
.github/workflows/release-rust.yaml
vendored
4
.github/workflows/release-rust.yaml
vendored
@@ -29,11 +29,11 @@ jobs:
|
||||
sleep 5
|
||||
|
||||
- name: Release Rust Host SDK
|
||||
if: always()
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_API_TOKEN }}
|
||||
run: |
|
||||
|
||||
cargo publish --manifest-path runtime/Cargo.toml --no-verify
|
||||
#cargo publish --manifest-path runtime/Cargo.toml --no-verify
|
||||
cargo publish --manifest-path rust/Cargo.toml
|
||||
|
||||
|
||||
|
||||
@@ -119,9 +119,13 @@ pub struct MemoryBlock {
|
||||
|
||||
/// Returns the number of pages needed for the given number of bytes
|
||||
pub fn num_pages(nbytes: u64) -> usize {
|
||||
let nbytes = nbytes as f64;
|
||||
let page = PAGE_SIZE as f64;
|
||||
((nbytes / page) + 0.5) as usize
|
||||
let npages = nbytes / PAGE_SIZE as u64;
|
||||
let remainder = nbytes % PAGE_SIZE as u64;
|
||||
if remainder != 0 {
|
||||
(npages + 1) as usize
|
||||
} else {
|
||||
npages as usize
|
||||
}
|
||||
}
|
||||
|
||||
// Get the `MemoryRoot` at the correct offset in memory
|
||||
@@ -242,13 +246,13 @@ impl MemoryRoot {
|
||||
let curr = self.blocks.as_ptr() as u64 + self_position;
|
||||
|
||||
// Get the number of bytes available
|
||||
let mem_left = self_length - self_position;
|
||||
let mem_left = self_length - self_position - core::mem::size_of::<MemoryRoot>() as u64;
|
||||
|
||||
// When the allocation is larger than the number of bytes available
|
||||
// we will need to try to grow the memory
|
||||
if length >= mem_left {
|
||||
// Calculate the number of pages needed to cover the remaining bytes
|
||||
let npages = num_pages(length);
|
||||
let npages = num_pages(length - mem_left);
|
||||
let x = core::arch::wasm32::memory_grow(0, npages);
|
||||
if x == usize::MAX {
|
||||
return None;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "libextism"
|
||||
version = "0.5.0"
|
||||
version = "0.5.2"
|
||||
edition = "2021"
|
||||
authors = ["The Extism Authors", "oss@extism.org"]
|
||||
license = "BSD-3-Clause"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "extism-runtime"
|
||||
version = "0.5.0"
|
||||
version = "0.5.2"
|
||||
edition = "2021"
|
||||
authors = ["The Extism Authors", "oss@extism.org"]
|
||||
license = "BSD-3-Clause"
|
||||
|
||||
@@ -81,7 +81,12 @@ typedef struct {
|
||||
/**
|
||||
* Host function signature
|
||||
*/
|
||||
typedef void (*ExtismFunctionType)(ExtismCurrentPlugin *plugin, const ExtismVal *inputs, ExtismSize n_inputs, ExtismVal *outputs, ExtismSize n_outputs, void *data);
|
||||
typedef void (*ExtismFunctionType)(ExtismCurrentPlugin *plugin,
|
||||
const ExtismVal *inputs,
|
||||
ExtismSize n_inputs,
|
||||
ExtismVal *outputs,
|
||||
ExtismSize n_outputs,
|
||||
void *data);
|
||||
|
||||
typedef int32_t ExtismPlugin;
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "extism"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
edition = "2021"
|
||||
authors = ["The Extism Authors", "oss@extism.org"]
|
||||
license = "BSD-3-Clause"
|
||||
@@ -10,7 +10,7 @@ description = "Extism Host SDK for Rust"
|
||||
|
||||
[dependencies]
|
||||
extism-manifest = { version = "0.5.0", path = "../manifest" }
|
||||
extism-runtime = { version = "0.5.0", path = "../runtime"}
|
||||
extism-runtime = { version = "0.5.2", path = "../runtime"}
|
||||
serde_json = "1"
|
||||
log = "0.4"
|
||||
anyhow = "1"
|
||||
|
||||
@@ -45,6 +45,7 @@ mod tests {
|
||||
const WASM: &[u8] = include_bytes!("../../wasm/code-functions.wasm");
|
||||
const WASM_LOOP: &[u8] = include_bytes!("../../wasm/loop.wasm");
|
||||
const WASM_GLOBALS: &[u8] = include_bytes!("../../wasm/globals.wasm");
|
||||
const REFLECT_WASM: &[u8] = include_bytes!("../../wasm/reflect.wasm");
|
||||
|
||||
fn hello_world(
|
||||
plugin: &mut CurrentPlugin,
|
||||
@@ -53,8 +54,8 @@ mod tests {
|
||||
_user_data: UserData,
|
||||
) -> Result<(), Error> {
|
||||
let input_offs = inputs[0].unwrap_i64() as u64;
|
||||
let input = plugin.memory_read_str(input_offs).unwrap().to_string();
|
||||
|
||||
let length = plugin.memory_length(input_offs);
|
||||
let input = plugin.memory_read(input_offs, length).to_vec();
|
||||
let output = plugin.memory_alloc_bytes(&input).unwrap();
|
||||
outputs[0] = Val::I64(output as i64);
|
||||
Ok(())
|
||||
@@ -319,4 +320,26 @@ mod tests {
|
||||
assert_eq!(count.get("count").unwrap().as_i64().unwrap(), i);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fuzz_reflect_plugin() {
|
||||
// assert!(set_log_file("stdout", Some(log::Level::Trace)));
|
||||
let f = Function::new(
|
||||
"host_reflect",
|
||||
[ValType::I64],
|
||||
[ValType::I64],
|
||||
None,
|
||||
hello_world,
|
||||
);
|
||||
|
||||
let context = Context::new();
|
||||
let mut plugin = Plugin::new(&context, REFLECT_WASM, [f], true).unwrap();
|
||||
|
||||
for i in 1..65540 {
|
||||
let input = "a".repeat(i);
|
||||
let output = plugin.call("reflect", input.clone());
|
||||
let output = std::str::from_utf8(output.unwrap()).unwrap();
|
||||
assert_eq!(output, input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
wasm/reflect.wasm
Normal file
BIN
wasm/reflect.wasm
Normal file
Binary file not shown.
Reference in New Issue
Block a user