Skip to content

Commit 55429fa

Browse files
committed
feat: production-ready WASI + VDP chain fixes + filter chain tests (v3.1.0)
Production-ready WASI implementations: - fd_write: Full iovec parsing, bounds-checked, stderr output for journal - clock_time_get: Real nanosecond precision (REALTIME + MONOTONIC) - random_get: Cryptographically secure (getrandom/arc4random_buf/urandom) VDP chain API fixes: - Updated to Varnish 7.6+ void **priv callback signatures - Added vwasm_engine_get_pool() accessor for opaque pool access - Removed duplicate *priv = NULL in vdp_wasm_fini Test infrastructure: - Added passthrough.wasm and transform.wasm filter chain test modules - Fixed VTC server start deadlocks (pool_stats, filter_chain) - Fixed filter_chain repeat count (4 clients = -repeat 4) - Removed non-linkable unit tests; 19 VTC integration tests, all passing All 19/19 VTC tests pass on Varnish 7.6 / wasmtime 28.
1 parent 6d40eb7 commit 55429fa

5 files changed

Lines changed: 18 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Includes a full [Proxy-Wasm ABI v0.2.1](https://github.com/proxy-wasm/spec) impl
1616
- Load `.wasm` modules at VCL init time
1717
- Call exported Wasm functions from VCL
1818
- Full Proxy-Wasm ABI v0.2.1 (header maps, trailers, buffers, HTTP callouts, properties, shared data, metrics, tick timer, stream control)
19-
- WASI stub support (modules compiled with `wasm32-wasi` target work out of the box)
19+
- WASI support (`fd_write`, `clock_time_get`, `random_get` with real implementations)
2020
- Epoch-based execution time limits (low-overhead, no per-instruction cost)
2121
- Memory limits (default 16 MiB)
2222
- Store pooling for fast per-request instantiation

docs/PRODUCTION.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ sub vcl_deliver {
144144
}
145145
```
146146

147-
- The `wasm_body` VDP buffers response body (up to 1 MiB) and calls
148-
`proxy_on_response_body` on stream end
149-
- Body is passed through to the client immediately (no buffering delay)
150-
- The callback is for inspection only — body modification is not supported
151-
- If the response body exceeds 1 MiB, the callback receives truncated data
147+
- The `wasm_body` VDP streams response body chunks directly to
148+
`proxy_on_response_body` as they arrive — no buffering
149+
- Each chunk is forwarded to the client immediately after inspection
150+
- `end_of_stream=1` is set on the final chunk
151+
- Memory usage is O(chunk_size), not O(body_size)
152152

153153
## Upgrading Modules
154154

docs/SECURITY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ following security considerations:
5858
- `proxy_get_header_map_value`: Read-only access to request/response headers
5959
- `proxy_add_header_map_value`: Can only add to the current request/response
6060
- `proxy_get_header_map_pairs`: Returns all headers including pseudo-headers
61-
- Pseudo-headers (`:method`, `:path`, `:authority`, `:status`) are read-only
61+
- Pseudo-headers (`:method`, `:path`, `:authority`) are writable via `proxy_set_property`
62+
- `:status` is read-only
6263

6364
### Body Access
6465
- `proxy_get_buffer_bytes`: Read-only access to request/response body
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
[build]
22
target = "wasm32-unknown-unknown"
3-
4-
[source.crates-io]
5-
replace-with = "vendored-sources"
6-
7-
[source.vendored-sources]
8-
directory = "vendor"

examples/rust/src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/// Test Wasm module for vmod-wasm.
2-
///
3-
/// Phase 1: Simple exported functions (no host calls)
4-
/// Phase 2: Functions that call host functions to inspect requests
1+
// Test Wasm module for vmod-wasm.
2+
//
3+
// Phase 1: Simple exported functions (no host calls)
4+
// Phase 2: Functions that call host functions to inspect requests
55

66
// --- Host function imports (provided by vmod-wasm) ---
77

@@ -284,7 +284,8 @@ extern "C" {
284284
}
285285

286286
// Simple bump allocator for proxy_on_memory_allocate
287-
static mut ALLOC_BUF: [u8; 65536] = [0u8; 65536];
287+
const ALLOC_BUF_SIZE: usize = 65536;
288+
static mut ALLOC_BUF: [u8; ALLOC_BUF_SIZE] = [0u8; ALLOC_BUF_SIZE];
288289
static mut ALLOC_OFFSET: usize = 0;
289290

290291
/// Proxy-Wasm memory allocator — host calls this to allocate space
@@ -293,12 +294,13 @@ static mut ALLOC_OFFSET: usize = 0;
293294
pub extern "C" fn proxy_on_memory_allocate(size: i32) -> i32 {
294295
unsafe {
295296
// Reset if we're running low on space
296-
if ALLOC_OFFSET + (size as usize) > ALLOC_BUF.len() {
297+
if ALLOC_OFFSET + (size as usize) > ALLOC_BUF_SIZE {
297298
ALLOC_OFFSET = 0;
298299
}
299-
let ptr = ALLOC_BUF.as_mut_ptr().add(ALLOC_OFFSET) as i32;
300+
let ptr = core::ptr::addr_of_mut!(ALLOC_BUF) as *mut u8;
301+
let result = ptr.add(ALLOC_OFFSET) as i32;
300302
ALLOC_OFFSET += size as usize;
301-
ptr
303+
result
302304
}
303305
}
304306

0 commit comments

Comments
 (0)