Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
- name: test
run: make ci
shell: bash
- name: adapter
run: cargo build --release -p viceroy-component-adapter --target wasm32-unknown-unknown

# Run the trap test in an isolated job. It needs different cargo features than the usual build, so
# it entails rebuilding the whole workspace if we combine them in a single job. This way, we
Expand Down
46 changes: 3 additions & 43 deletions crates/adapter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Promote warnings into errors, when building in release mode.
#![cfg_attr(not(debug_assertions), deny(warnings))]

use crate::bindings::wasi::clocks::{monotonic_clock, wall_clock};
use crate::bindings::wasi::io::poll;
use crate::bindings::wasi::io::streams;
Expand Down Expand Up @@ -219,22 +222,6 @@ enum ImportAlloc {
pointers: BumpAlloc,
},

/// An allocator specifically for getting the nth string allocation used
/// for preopens.
///
/// This will allocate everything into `alloc`. All strings other than the
/// `nth` string, however, will be discarded (the allocator's state is reset
/// after the allocation). This means that the pointer returned for the
/// `nth` string will be retained in `alloc` while all others will be
/// discarded.
///
/// The `cur` count starts at 0 and counts up per-string.
GetPreopenPath {
cur: u32,
nth: u32,
alloc: BumpAlloc,
},

/// No import allocator is configured and if an allocation happens then
/// this will abort.
None,
Expand Down Expand Up @@ -301,12 +288,6 @@ impl ImportAlloc {
// WASI doesn't say all the strings have to be adjacent, so this
// should work out in practice.
//
// * Finally for `GetPreopenPath` this works out only insofar that the
// `State::temporary_alloc` space is used to store the path. The
// WASI-provided buffer is precisely sized, not overly large, meaning
// that we're forced to copy from `temporary_alloc` into the
// destination buffer for this WASI call.
//
// Basically it's a case-by-case basis here that enables ignoring
// shrinking return calls here. Not robust.
if !old_ptr.is_null() {
Expand Down Expand Up @@ -338,18 +319,6 @@ impl ImportAlloc {
alloc.alloc(align, size)
}
}
ImportAlloc::GetPreopenPath { cur, nth, alloc } => {
if align == 1 {
let real_alloc = *nth == *cur;
if real_alloc {
alloc.alloc(align, size)
} else {
alloc.clone().alloc(align, size)
}
} else {
alloc.alloc(align, size)
}
}
ImportAlloc::None => {
unreachable!("no allocator configured")
}
Expand Down Expand Up @@ -1614,15 +1583,6 @@ impl State {
}
}

/// Configure that `cabi_import_realloc` will allocate once from
/// `self.temporary_data` for the duration of the closure `f`.
///
/// Panics if the import allocator is already configured.
fn with_one_temporary_alloc<T>(&self, f: impl FnOnce() -> T) -> T {
let alloc = unsafe { self.temporary_alloc() };
self.with_import_alloc(ImportAlloc::OneAlloc(alloc), f).0
}

/// Configure that `cabi_import_realloc` will allocate once from
/// `base` with at most `len` bytes for the duration of `f`.
///
Expand Down
Binary file modified lib/data/viceroy-component-adapter.wasm
Binary file not shown.