From 9fad5e653c839d5d19fb0265cc6023f04a820ec7 Mon Sep 17 00:00:00 2001 From: vasilito Date: Wed, 8 Jul 2026 17:57:54 +0300 Subject: [PATCH] syscall: add FullContextRegs arch types for /proc/{pid}/ctx --- src/arch/aarch64.rs | 31 +++++++++++++++++++++++++++++++ src/arch/riscv64.rs | 31 +++++++++++++++++++++++++++++++ src/arch/x86.rs | 31 +++++++++++++++++++++++++++++++ src/arch/x86_64.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index 7ba23e5c6f..dea4209789 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -95,6 +95,14 @@ pub struct IntRegisters { pub x0: usize, } +#[derive(Clone, Copy, Debug, Default)] +#[repr(C)] +pub struct FullContextRegs { + pub int: IntRegisters, + pub float: FloatRegisters, + pub env: EnvRegisters, +} + impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { @@ -149,6 +157,29 @@ impl DerefMut for FloatRegisters { } } +impl Deref for FullContextRegs { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const FullContextRegs as *const u8, + mem::size_of::(), + ) + } + } +} + +impl DerefMut for FullContextRegs { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut FullContextRegs as *mut u8, + mem::size_of::(), + ) + } + } +} + #[derive(Clone, Copy, Debug, Default)] #[repr(C, packed)] pub struct EnvRegisters { diff --git a/src/arch/riscv64.rs b/src/arch/riscv64.rs index ea4ae694a7..a581cbe824 100644 --- a/src/arch/riscv64.rs +++ b/src/arch/riscv64.rs @@ -96,6 +96,14 @@ pub struct IntRegisters { pub x1: usize, } +#[derive(Clone, Copy, Debug, Default)] +#[repr(C)] +pub struct FullContextRegs { + pub int: IntRegisters, + pub float: FloatRegisters, + pub env: EnvRegisters, +} + impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { @@ -149,6 +157,29 @@ impl DerefMut for FloatRegisters { } } +impl Deref for FullContextRegs { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const FullContextRegs as *const u8, + mem::size_of::(), + ) + } + } +} + +impl DerefMut for FullContextRegs { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut FullContextRegs as *mut u8, + mem::size_of::(), + ) + } + } +} + #[derive(Clone, Copy, Debug, Default)] #[repr(packed)] pub struct EnvRegisters { diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 7c4c01d9ac..10254d54d8 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -164,6 +164,14 @@ pub struct IntRegisters { // pub gs: usize } +#[derive(Clone, Copy, Debug, Default)] +#[repr(C)] +pub struct FullContextRegs { + pub int: IntRegisters, + pub float: FloatRegisters, + pub env: EnvRegisters, +} + impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { @@ -227,6 +235,29 @@ impl DerefMut for FloatRegisters { } } +impl Deref for FullContextRegs { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const FullContextRegs as *const u8, + mem::size_of::(), + ) + } + } +} + +impl DerefMut for FullContextRegs { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut FullContextRegs as *mut u8, + mem::size_of::(), + ) + } + } +} + #[derive(Clone, Copy, Debug, Default)] #[repr(C, packed)] pub struct EnvRegisters { diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 93277e59c7..c73e44374b 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -81,6 +81,14 @@ pub struct IntRegisters { pub ss: usize, } +#[derive(Clone, Copy, Debug, Default)] +#[repr(C)] +pub struct FullContextRegs { + pub int: IntRegisters, + pub float: FloatRegisters, + pub env: EnvRegisters, +} + impl Deref for IntRegisters { type Target = [u8]; fn deref(&self) -> &[u8] { @@ -133,6 +141,29 @@ impl DerefMut for FloatRegisters { } } } + +impl Deref for FullContextRegs { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts( + self as *const FullContextRegs as *const u8, + mem::size_of::(), + ) + } + } +} + +impl DerefMut for FullContextRegs { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut( + self as *mut FullContextRegs as *mut u8, + mem::size_of::(), + ) + } + } +} #[derive(Clone, Copy, Debug, Default)] #[repr(C, packed)] pub struct EnvRegisters {