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

fix(lazy-pages-fuzzer): Increase Wasmi's max stack size #4348

Merged
merged 3 commits into from
Nov 22, 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
4 changes: 2 additions & 2 deletions lazy-pages/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct GlobalsAccessWasmRuntime<'a> {
pub instance: &'a mut SandboxInstance,
}

impl<'a> GlobalsAccessor for GlobalsAccessWasmRuntime<'a> {
impl GlobalsAccessor for GlobalsAccessWasmRuntime<'_> {
fn get_i64(&mut self, name: &LimitedStr) -> Result<i64, GlobalsAccessError> {
// SAFETY: this is safe because this method is called only from signal handler context
unsafe {
Expand Down Expand Up @@ -80,7 +80,7 @@ struct GlobalsAccessNativeRuntime<'a, 'b> {
pub inner_access_provider: &'a mut &'b mut dyn GlobalsAccessor,
}

impl<'a, 'b> GlobalsAccessor for GlobalsAccessNativeRuntime<'a, 'b> {
impl GlobalsAccessor for GlobalsAccessNativeRuntime<'_, '_> {
fn get_i64(&mut self, name: &LimitedStr) -> Result<i64, GlobalsAccessError> {
self.inner_access_provider.get_i64(name)
}
Expand Down
4 changes: 2 additions & 2 deletions lazy-pages/src/host_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) struct HostFuncAccessHandler<'a> {
pub gas_charger: GasCharger,
}

impl<'a> AccessHandler for HostFuncAccessHandler<'a> {
impl AccessHandler for HostFuncAccessHandler<'_> {
type Pages = BTreeSet<GearPage>;
type Output = Status;

Expand Down Expand Up @@ -107,7 +107,7 @@ fn accesses_pages(
let last_byte = access
.offset
.checked_add(access.size.saturating_sub(1))
.ok_or_else(|| Error::OutOfWasmMemoryAccess)?;
.ok_or(Error::OutOfWasmMemoryAccess)?;

let start = (access.offset / page_size) * page_size;
let end = (last_byte / page_size) * page_size;
Expand Down
6 changes: 2 additions & 4 deletions lazy-pages/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ unsafe fn user_signal_handler_internal(
info: ExceptionInfo,
) -> Result<(), Error> {
let native_addr = info.fault_addr as usize;
let is_write = info.is_write.ok_or_else(|| Error::ReadOrWriteIsUnknown)?;
let wasm_mem_addr = exec_ctx
.wasm_mem_addr
.ok_or_else(|| Error::WasmMemAddrIsNotSet)?;
let is_write = info.is_write.ok_or(Error::ReadOrWriteIsUnknown)?;
let wasm_mem_addr = exec_ctx.wasm_mem_addr.ok_or(Error::WasmMemAddrIsNotSet)?;

if native_addr < wasm_mem_addr {
return Err(Error::OutOfWasmMemoryAccess);
Expand Down
6 changes: 3 additions & 3 deletions sandbox/host/src/store_refcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub struct StoreRefCell<S> {

trait GenericAsStoreMut {}

impl<'r, 's> GenericAsStoreMut for &'r mut wasmer::StoreMut<'s> {}
impl<'s, T> GenericAsStoreMut for wasmi::StoreContextMut<'s, T> {}
impl GenericAsStoreMut for &mut wasmer::StoreMut<'_> {}
impl<T> GenericAsStoreMut for wasmi::StoreContextMut<'_, T> {}

#[derive(Debug)]
pub struct BorrowScopeError;
Expand Down Expand Up @@ -236,7 +236,7 @@ pub struct RefMut<'b, S> {
state: &'b Cell<BorrowState>,
}

impl<'a, S> Deref for RefMut<'a, S> {
impl<S> Deref for RefMut<'_, S> {
type Target = S;

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions utils/lazy-pages-fuzzer/src/lazy_pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl UserSignalHandler for FuzzerLazyPagesSignalHandler {
log::debug!("Interrupted, exception info = {:?}", info);
FUZZER_LP_CONTEXT.with(|ctx| {
let mut borrow = ctx.borrow_mut();
let ctx = borrow.as_mut().ok_or_else(|| Error::WasmMemAddrIsNotSet)?;
let ctx = borrow.as_mut().ok_or(Error::WasmMemAddrIsNotSet)?;
user_signal_handler_internal(ctx, info)
})
}
Expand All @@ -134,7 +134,7 @@ fn user_signal_handler_internal(
info: ExceptionInfo,
) -> Result<(), Error> {
let native_addr = info.fault_addr as usize;
let is_write = info.is_write.ok_or_else(|| Error::ReadOrWriteIsUnknown)?;
let is_write = info.is_write.ok_or(Error::ReadOrWriteIsUnknown)?;
let wasm_mem_range = &ctx.memory_range;

if !wasm_mem_range.contains(&native_addr) {
Expand Down
6 changes: 3 additions & 3 deletions utils/lazy-pages-fuzzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use std::collections::BTreeMap;

use anyhow::Result;
use anyhow::{Context, Result};
use gear_wasm_instrument::parity_wasm::elements::Module;

mod config;
Expand Down Expand Up @@ -60,8 +60,8 @@ pub fn run(generated_module: GeneratedModule) -> Result<()> {
}
};

let wasmer_res = unwrap_error_chain(WasmerRunner::run(&module));
let wasmi_res = unwrap_error_chain(WasmiRunner::run(&module));
let wasmer_res = unwrap_error_chain(WasmerRunner::run(&module).context("wasmer"));
let wasmi_res = unwrap_error_chain(WasmiRunner::run(&module).context("wasmi"));

RunResult::verify_equality(wasmer_res, wasmi_res);

Expand Down
3 changes: 2 additions & 1 deletion utils/lazy-pages-fuzzer/src/wasmi_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ fn config() -> Config {
let register_len = size_of::<UntypedVal>();

const DEFAULT_MIN_VALUE_STACK_HEIGHT: usize = 1024;
const DEFAULT_MAX_VALUE_STACK_HEIGHT: usize = 1024 * DEFAULT_MIN_VALUE_STACK_HEIGHT;
// Fuzzer requires bigger stack size
const DEFAULT_MAX_VALUE_STACK_HEIGHT: usize = 1024 * DEFAULT_MIN_VALUE_STACK_HEIGHT * 16;
ByteNacked marked this conversation as resolved.
Show resolved Hide resolved
const DEFAULT_MAX_RECURSION_DEPTH: usize = 16384;

let mut config = Config::default();
Expand Down
Loading