From 78e1f82f403ed6e665c45bfa08a9791dac7f60fd Mon Sep 17 00:00:00 2001 From: Arshia Ghafoori Date: Tue, 9 Jul 2024 16:37:18 +0400 Subject: [PATCH] Fix stack_low detection when data_end is above stack_pointer and stack_lower is missing --- lib/wasix/src/state/func_env.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/wasix/src/state/func_env.rs b/lib/wasix/src/state/func_env.rs index fb7dee2c6da..5d728aff5cb 100644 --- a/lib/wasix/src/state/func_env.rs +++ b/lib/wasix/src/state/func_env.rs @@ -191,10 +191,17 @@ impl WasiFunctionEnv { _ => 0, } } else if let Some(data_end) = data_end { - match data_end.get(store) { + let data_end = match data_end.get(store) { wasmer::Value::I32(a) => a as u64, wasmer::Value::I64(a) => a as u64, _ => 0, + }; + // It's possible for the data section to be above the stack, we check for that here and + // if it is, we'll assume the stack starts at address 0 + if data_end >= stack_base { + 0 + } else { + data_end } } else { // clang-16 and higher generate the `__stack_low` global, and it can be exported with