diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs new file mode 100644 index 00000000..9f8bfed0 --- /dev/null +++ b/src/arch/aarch64.rs @@ -0,0 +1,9 @@ +#[allow(missing_docs)] +#[derive(Clone, Debug)] +#[repr(C)] +pub struct SavedFrame { + pub gp_regs: [u64; 32], + pub spsr_el1: u64, + pub elr_el1: u64, + pub sp_el0: u64, +} diff --git a/src/arch/mod.rs b/src/arch/mod.rs new file mode 100644 index 00000000..57a6ad25 --- /dev/null +++ b/src/arch/mod.rs @@ -0,0 +1,13 @@ +//! Architecture-specific ABI implementation details + +#[cfg(target_arch = "aarch64")] +pub(crate) mod aarch64; +#[cfg(target_arch = "aarch64")] +use aarch64 as arch_impl; + +#[cfg(target_arch = "x86_64")] +pub(crate) mod x86_64; +#[cfg(target_arch = "x86_64")] +use x86_64 as arch_impl; + +pub use arch_impl::SavedFrame; diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs new file mode 100644 index 00000000..40a9b039 --- /dev/null +++ b/src/arch/x86_64.rs @@ -0,0 +1,26 @@ +#![allow(missing_docs)] + +#[derive(Clone, Debug)] +#[repr(C)] +pub struct SavedFrame { + pub rax: u64, + pub rcx: u64, + pub rdx: u64, + pub rbx: u64, + pub rsi: u64, + pub rdi: u64, + pub rbp: u64, + + pub r8: u64, + pub r9: u64, + pub r10: u64, + pub r11: u64, + pub r12: u64, + pub r13: u64, + pub r14: u64, + pub r15: u64, + + pub user_ip: u64, + pub user_sp: u64, + pub rflags: u64, +} diff --git a/src/error.rs b/src/error.rs index 96e3b49a..1f17c785 100644 --- a/src/error.rs +++ b/src/error.rs @@ -28,6 +28,8 @@ primitive_enum!( DirectoryNotEmpty = 11, #[doc = "Operation was interrupted"] Interrupted = 12, + #[doc = "Operation has not completed yet"] + WouldBlock = 13, } ); diff --git a/src/lib.rs b/src/lib.rs index d52970dc..984e5b3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,7 @@ pub(crate) mod macros; +pub mod arch; pub mod error; pub mod io; pub mod path; diff --git a/src/macros.rs b/src/macros.rs index 75521902..5006cc81 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,15 +1,15 @@ /// Helper macro to define primitive enums with integer reprs, as well as their conversion methods #[macro_export] macro_rules! primitive_enum { - ($(#[doc = $enum_doc:expr])? $vis:vis enum $name:ident: $repr:ty { - $( $(#[doc = $doc:expr])? $variant:ident = $discriminant:literal, )+ + ($(#[$struct_meta:meta])* $vis:vis enum $name:ident: $repr:ty { + $( $(#[$variant_meta:meta])* $variant:ident = $discriminant:literal, )+ }) => { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[repr($repr)] - $(#[doc = $enum_doc])? + $(#[$struct_meta])* $vis enum $name { $( - $(#[doc = $doc])? + $(#[$variant_meta])? $variant = $discriminant ),+ } diff --git a/src/process.rs b/src/process.rs index 6d9623d9..503eb1c3 100644 --- a/src/process.rs +++ b/src/process.rs @@ -2,7 +2,7 @@ use core::num::NonZeroI32; -use crate::{io::RawFd, primitive_enum}; +use crate::{arch::SavedFrame, io::RawFd, primitive_enum}; /// Code signalled by a process when it finishes or is terminated by a signal #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -40,21 +40,6 @@ primitive_enum! { } } -/// Platform-specific "snapshot" of a program's context, used to restore it later when returning -/// from a signal handler -#[derive(Clone, Debug)] -#[repr(C)] -pub struct SavedFrame { - /// General-purpose registers - pub gp_regs: [u64; 32], - /// SPSR_EL1 - pub spsr_el1: u64, - /// ELR_EL1 (return address) - pub elr_el1: u64, - /// SP_EL0 (return stack) - pub sp_el0: u64, -} - /// Data provided by the kernel to signal entry function #[derive(Clone, Debug)] #[repr(C)]