Preview1 state lives in the host, so Go modules (esbuild) work. esbuild bundles byte-identical to native; uutils and QuickJS-ng file tests pass. The failed guest-side adapter attempt (T7) moves to spikes/s7-preview1-adapter/.
55 lines
1.9 KiB
Diff
55 lines
1.9 KiB
Diff
diff --git a/crates/wasi-preview1-component-adapter/src/lib.rs b/crates/wasi-preview1-component-adapter/src/lib.rs
|
|
index 7ce52c6..ed23010 100644
|
|
--- a/crates/wasi-preview1-component-adapter/src/lib.rs
|
|
+++ b/crates/wasi-preview1-component-adapter/src/lib.rs
|
|
@@ -129,6 +129,11 @@ pub extern "C" fn run() -> u32 {
|
|
unsafe extern "C" {
|
|
safe fn _start();
|
|
}
|
|
+ // Reserve adapter state before Go snapshots the linear-memory heap extent.
|
|
+ // Lazy memory.grow allocations otherwise overlap Go's sbrk allocator.
|
|
+ let state = State::ptr();
|
|
+ eprint!("before _start: ");
|
|
+ state.trace();
|
|
_start();
|
|
0
|
|
}
|
|
@@ -2852,8 +2857,24 @@ unsafe extern "C" {
|
|
}
|
|
|
|
impl State {
|
|
+ fn trace(&self) {
|
|
+ eprint!("ptr=");
|
|
+ crate::macros::eprint_u32(self as *const Self as u32);
|
|
+ eprint!(" magic1=");
|
|
+ crate::macros::eprint_u32(self.magic1);
|
|
+ eprint!(" magic2=");
|
|
+ crate::macros::eprint_u32(self.magic2);
|
|
+ eprint!(" memory_pages=");
|
|
+ crate::macros::eprint_u32(core::arch::wasm32::memory_size::<0>() as u32);
|
|
+ eprintln!("");
|
|
+ }
|
|
+
|
|
fn with(f: impl FnOnce(&State) -> Result<(), Errno>) -> Errno {
|
|
let state_ref = State::ptr();
|
|
+ if state_ref.magic1 != MAGIC || state_ref.magic2 != MAGIC {
|
|
+ eprint!("corrupt state: ");
|
|
+ state_ref.trace();
|
|
+ }
|
|
assert_eq!(state_ref.magic1, MAGIC);
|
|
assert_eq!(state_ref.magic2, MAGIC);
|
|
let ret = f(state_ref);
|
|
diff --git a/crates/wasi-preview1-component-adapter/src/macros.rs b/crates/wasi-preview1-component-adapter/src/macros.rs
|
|
index d5649f4..3b5adf4 100644
|
|
--- a/crates/wasi-preview1-component-adapter/src/macros.rs
|
|
+++ b/crates/wasi-preview1-component-adapter/src/macros.rs
|
|
@@ -40,7 +40,7 @@ pub fn eprint_unreachable(line: u32) {
|
|
crate::macros::eprint_u32(line);
|
|
}
|
|
|
|
-fn eprint_u32(x: u32) {
|
|
+pub(crate) fn eprint_u32(x: u32) {
|
|
if x == 0 {
|
|
eprint!("0");
|
|
} else {
|