Clear DF flag during signal handling to conform to x86-64 calling convention

This commit is contained in:
Ruize Tang
2024-11-25 11:44:46 +08:00
committed by Tate, Hongliang Tian
parent 9e5075dab7
commit 05ff441577
3 changed files with 72 additions and 1 deletions

View File

@ -218,6 +218,15 @@ pub fn handle_user_signal(
} else {
user_ctx.set_arguments(sig_num, 0, 0);
}
// CPU architecture-dependent logic
cfg_if::cfg_if! {
if #[cfg(target_arch = "x86_64")] {
// Clear `DF` flag for C function entry to conform to x86-64 calling convention.
// Bit 10 is the DF flag.
const X86_RFLAGS_DF: usize = 1 << 10;
user_ctx.general_regs_mut().rflags &= !X86_RFLAGS_DF;
}
}
Ok(())
}