Skip to content

Commit

Permalink
Remove return value from wmemcheck libcalls (#9676)
Browse files Browse the repository at this point in the history
This isn't used in the compiled code so don't bake it in.
  • Loading branch information
alexcrichton authored Nov 25, 2024
1 parent 6c97d5e commit 91d3219
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
8 changes: 4 additions & 4 deletions crates/environ/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ macro_rules! foreach_builtin_function {
new_epoch(vmctx: vmctx) -> i64;
// Invoked before malloc returns.
#[cfg(feature = "wmemcheck")]
check_malloc(vmctx: vmctx, addr: i32, len: i32) -> i32;
check_malloc(vmctx: vmctx, addr: i32, len: i32);
// Invoked before the free returns.
#[cfg(feature = "wmemcheck")]
check_free(vmctx: vmctx, addr: i32) -> i32;
check_free(vmctx: vmctx, addr: i32);
// Invoked before a load is executed.
#[cfg(feature = "wmemcheck")]
check_load(vmctx: vmctx, num_bytes: i32, addr: i32, offset: i32) -> i32;
check_load(vmctx: vmctx, num_bytes: i32, addr: i32, offset: i32);
// Invoked before a store is executed.
#[cfg(feature = "wmemcheck")]
check_store(vmctx: vmctx, num_bytes: i32, addr: i32, offset: i32) -> i32;
check_store(vmctx: vmctx, num_bytes: i32, addr: i32, offset: i32);
// Invoked after malloc is called.
#[cfg(feature = "wmemcheck")]
malloc_start(vmctx: vmctx);
Expand Down
32 changes: 12 additions & 20 deletions crates/wasmtime/src/runtime/vm/libcalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,14 +1110,12 @@ unsafe fn check_malloc(
instance: &mut Instance,
addr: u32,
len: u32,
) -> Result<u32> {
) -> Result<()> {
if let Some(wmemcheck_state) = &mut instance.wmemcheck_state {
let result = wmemcheck_state.malloc(addr as usize, len as usize);
wmemcheck_state.memcheck_on();
match result {
Ok(()) => {
return Ok(0);
}
Ok(()) => {}
Err(DoubleMalloc { addr, len }) => {
bail!("Double malloc at addr {:#x} of size {}", addr, len)
}
Expand All @@ -1129,19 +1127,17 @@ unsafe fn check_malloc(
}
}
}
Ok(0)
Ok(())
}

// Hook for validating free using wmemcheck_state.
#[cfg(feature = "wmemcheck")]
unsafe fn check_free(_store: &mut dyn VMStore, instance: &mut Instance, addr: u32) -> Result<u32> {
unsafe fn check_free(_store: &mut dyn VMStore, instance: &mut Instance, addr: u32) -> Result<()> {
if let Some(wmemcheck_state) = &mut instance.wmemcheck_state {
let result = wmemcheck_state.free(addr as usize);
wmemcheck_state.memcheck_on();
match result {
Ok(()) => {
return Ok(0);
}
Ok(()) => {}
Err(InvalidFree { addr }) => {
bail!("Invalid free at addr {:#x}", addr)
}
Expand All @@ -1150,7 +1146,7 @@ unsafe fn check_free(_store: &mut dyn VMStore, instance: &mut Instance, addr: u3
}
}
}
Ok(0)
Ok(())
}

// Hook for validating load using wmemcheck_state.
Expand All @@ -1161,13 +1157,11 @@ fn check_load(
num_bytes: u32,
addr: u32,
offset: u32,
) -> Result<u32> {
) -> Result<()> {
if let Some(wmemcheck_state) = &mut instance.wmemcheck_state {
let result = wmemcheck_state.read(addr as usize + offset as usize, num_bytes as usize);
match result {
Ok(()) => {
return Ok(0);
}
Ok(()) => {}
Err(InvalidRead { addr, len }) => {
bail!("Invalid load at addr {:#x} of size {}", addr, len);
}
Expand All @@ -1179,7 +1173,7 @@ fn check_load(
}
}
}
Ok(0)
Ok(())
}

// Hook for validating store using wmemcheck_state.
Expand All @@ -1190,13 +1184,11 @@ fn check_store(
num_bytes: u32,
addr: u32,
offset: u32,
) -> Result<u32> {
) -> Result<()> {
if let Some(wmemcheck_state) = &mut instance.wmemcheck_state {
let result = wmemcheck_state.write(addr as usize + offset as usize, num_bytes as usize);
match result {
Ok(()) => {
return Ok(0);
}
Ok(()) => {}
Err(InvalidWrite { addr, len }) => {
bail!("Invalid store at addr {:#x} of size {}", addr, len)
}
Expand All @@ -1208,7 +1200,7 @@ fn check_store(
}
}
}
Ok(0)
Ok(())
}

// Hook for turning wmemcheck load/store validation off when entering a malloc function.
Expand Down

0 comments on commit 91d3219

Please sign in to comment.