Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only warn if needed #4749

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions lib/wasix/src/state/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ pub struct WasiInstanceHandles {
/// when a CTRL-C is pressed.
pub(crate) signal_set: bool,

/// Flag that indicates if the stack capture exports are being used by
/// this WASM process which means that it will be using asyncify
pub(crate) has_stack_checkpoint: bool,

/// asyncify_start_unwind(data : i32): call this to start unwinding the
/// stack from the current location. "data" must point to a data
/// structure as described above (with fields containing valid data).
Expand Down Expand Up @@ -143,6 +147,10 @@ pub struct WasiInstanceHandles {

impl WasiInstanceHandles {
pub fn new(memory: Memory, store: &impl AsStoreRef, instance: Instance) -> Self {
let has_stack_checkpoint = instance
.module()
.imports()
.any(|f| f.name() == "stack_checkpoint");
WasiInstanceHandles {
memory,
stack_pointer: instance
Expand Down Expand Up @@ -178,6 +186,7 @@ impl WasiInstanceHandles {
.exports
.get_typed_function(&store, "__wasm_signal")
.ok(),
has_stack_checkpoint,
signal_set: false,
asyncify_start_unwind: instance
.exports
Expand Down Expand Up @@ -439,6 +448,12 @@ impl WasiEnv {
self.thread.tid()
}

/// Returns true if this WASM process will need and try to use
/// asyncify while its running which normally means.
pub fn will_use_asyncify(&self) -> bool {
syrusakbary marked this conversation as resolved.
Show resolved Hide resolved
self.enable_deep_sleep || unsafe { self.inner().has_stack_checkpoint }
}

/// Re-initializes this environment so that it can be executed again
pub fn reinit(&mut self) -> Result<(), WasiStateCreationError> {
// If the cleanup logic is enabled then we need to rebuild the
Expand Down
15 changes: 10 additions & 5 deletions lib/wasix/src/state/func_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl WasiFunctionEnv {
)?;

let new_inner = WasiInstanceHandles::new(memory, store, instance);

let stack_pointer = new_inner.stack_pointer.clone();
let data_end = new_inner.data_end.clone();
let stack_low = new_inner.stack_low.clone();
Expand Down Expand Up @@ -199,15 +200,19 @@ impl WasiFunctionEnv {
// clang-16 and higher generate the `__stack_low` global, and it can be exported with
// `-Wl,--export=__stack_low`. clang-15 generates `__data_end`, which should be identical
// and can be exported if `__stack_low` is not available.
tracing::warn!("Missing both __stack_low and __data_end exports, unwinding may cause memory corruption");
if self.data(store).will_use_asyncify() {
tracing::warn!("Missing both __stack_low and __data_end exports, unwinding may cause memory corruption");
}
0
};

if stack_lower >= stack_base {
tracing::warn!(
"Detected lower end of stack to be above higher end, ignoring stack_lower; \
unwinding may cause memory corruption"
);
if self.data(store).will_use_asyncify() {
tracing::warn!(
"Detected lower end of stack to be above higher end, ignoring stack_lower; \
unwinding may cause memory corruption"
);
}
stack_lower = 0;
}

Expand Down
Loading