diff --git a/litebox_shim_linux/src/syscalls/signal/x86.rs b/litebox_shim_linux/src/syscalls/signal/x86.rs index 34c6872dc9..4d5ec9d558 100644 --- a/litebox_shim_linux/src/syscalls/signal/x86.rs +++ b/litebox_shim_linux/src/syscalls/signal/x86.rs @@ -42,7 +42,8 @@ struct SignalFrameRt { impl Task { /// Legacy signal return syscall implementation for x86. pub(crate) fn sys_sigreturn(&self, ctx: &mut PtRegs) -> Result { - let lctx_addr = ctx.esp.wrapping_sub(8); + let sigframe_addr = ctx.esp.wrapping_sub(8); + let lctx_addr = sigframe_addr.wrapping_add(offset_of!(SignalFrame, context)); let lctx_ptr = ConstPtr::::from_usize(lctx_addr); let Some(lctx) = lctx_ptr.read_at_offset(0) else { self.force_signal(Signal::SIGSEGV, false); @@ -73,14 +74,14 @@ pub(super) fn get_signal_frame(sp: usize, action: &SigAction) -> usize { // Space for the signal frame. if action.flags.contains(SaFlags::SIGINFO) { - frame_addr -= core::mem::size_of::(); + frame_addr = frame_addr.wrapping_sub(core::mem::size_of::()); } else { - frame_addr -= core::mem::size_of::(); + frame_addr = frame_addr.wrapping_sub(core::mem::size_of::()); } // Align the frame (offset by 4 bytes for return address). frame_addr &= !15; - frame_addr -= 4; + frame_addr = frame_addr.wrapping_sub(4); frame_addr } diff --git a/litebox_shim_linux/src/syscalls/signal/x86_64.rs b/litebox_shim_linux/src/syscalls/signal/x86_64.rs index 8455010aab..f068df4232 100644 --- a/litebox_shim_linux/src/syscalls/signal/x86_64.rs +++ b/litebox_shim_linux/src/syscalls/signal/x86_64.rs @@ -32,14 +32,14 @@ pub(super) fn get_signal_frame(sp: usize, _action: &SigAction) -> usize { let mut frame_addr = sp; // Skip the redzone. - frame_addr -= 128; + frame_addr = frame_addr.wrapping_sub(128); // Space for the signal frame. - frame_addr -= core::mem::size_of::(); + frame_addr = frame_addr.wrapping_sub(core::mem::size_of::()); // Align the frame (offset by 8 bytes for return address) frame_addr &= !15; - frame_addr -= 8; + frame_addr = frame_addr.wrapping_sub(8); frame_addr }