### UserContext::get_syscall_args Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Get syscall args. ```APIDOC ## get_syscall_args ### Description Get syscall args. ### Method Rust method ### Signature `pub fn get_syscall_args(&self) -> [usize; 6]` ### Parameters - `self` (`&UserContext`) - Required - The user context to read from. ### Returns - `[usize; 6]` - An array of six syscall arguments. ``` -------------------------------- ### Replace syscall instruction Source: https://docs.rs/trapframe/latest/trapframe/fn.syscall_fn_entry.html Example showing the replacement of a syscall instruction with a call to syscall_fn_entry. ```asm syscall call syscall_fn_entry ``` -------------------------------- ### UserContext::get_syscall_ret Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Get return value of syscall. ```APIDOC ## get_syscall_ret ### Description Get return value of syscall. ### Method Rust method ### Signature `pub fn get_syscall_ret(&self) -> usize` ### Parameters - `self` (`&UserContext`) - Required - The user context to read from. ### Returns - `usize` - The syscall return value. ``` -------------------------------- ### Common assembly for syscall_fn_entry trap frame setup Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Assembly for the syscall_fn_entry symbol that saves the stack pointer, switches to the kernel stack, and pushes the trap frame (struct GeneralRegs) including gs_base, user fsbase, rflags, rip, and r15. ```assembly global_asm!( r#" syscall_fn_entry: # save rsp lea r11, [rsp + 8] # save rsp to r11 (clobber) SWITCH_TO_KERNEL_STACK pop rsp lea rsp, [rsp + 20*8] # rsp = top of trap frame # push trap frame (struct GeneralRegs) push 0 # ignore gs_base PUSH_USER_FSBASE pushfq # push rflags push [r11 - 8] # push rip push r15 "# ); ``` -------------------------------- ### UserContext methods for syscall and register manipulation Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Provides methods to get and set syscall number, return value, and arguments, as well as set and get instruction pointer, stack pointer, and TLS pointer. These methods operate on the general registers within UserContext. ```rust impl UserContext { /// Get number of syscall pub fn get_syscall_num(&self) -> usize { self.general.rax } /// Get return value of syscall pub fn get_syscall_ret(&self) -> usize { self.general.rax } /// Set return value of syscall pub fn set_syscall_ret(&mut self, ret: usize) { self.general.rax = ret; } /// Get syscall args pub fn get_syscall_args(&self) -> [usize; 6] { [ self.general.rdi, self.general.rsi, self.general.rdx, self.general.r10, self.general.r8, self.general.r9, ] } /// Set instruction pointer pub fn set_ip(&mut self, ip: usize) { self.general.rip = ip; } /// Set stack pointer pub fn set_sp(&mut self, sp: usize) { self.general.rsp = sp; } /// Get stack pointer pub fn get_sp(&self) -> usize { self.general.rsp } /// Set tls pointer pub fn set_tls(&mut self, tls: usize) { self.general.fsbase = tls; } } ``` -------------------------------- ### UserContext::get_syscall_num Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Get number of syscall. ```APIDOC ## get_syscall_num ### Description Get number of syscall. ### Method Rust method ### Signature `pub fn get_syscall_num(&self) -> usize` ### Parameters - `self` (`&UserContext`) - Required - The user context to read from. ### Returns - `usize` - The syscall number. ``` -------------------------------- ### UserContext::get_syscall_args Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Returns the syscall arguments from the user context as an array of six usize values, extracted from the general-purpose registers. ```APIDOC ## UserContext::get_syscall_args ### Description Returns the syscall arguments from the user context as an array of six usize values, extracted from the general-purpose registers. ### Signature ```rust pub fn get_syscall_args(&self) -> [usize; 6] ``` ### Parameters - `&self` - The user context. ### Return Value - `[usize; 6]` - The syscall arguments in order: rdi, rsi, rdx, r10, r8, r9. ``` -------------------------------- ### init Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Initializes interrupt handling on x86_64 by disabling interrupts, setting up a new GDT, TSS, IDT, and enabling the syscall instruction. This function is unsafe and should only be called once during system initialization. ```APIDOC ## init ### Description Initializes interrupt handling on x86_64. This function will disable interrupts, switch to a new GDT, TSS, and IDT, and enable the syscall instruction. ### Safety This function is unsafe because it modifies critical system state (GDT, IDT, TSS, and MSRs) and must only be called once during early initialization. ### Signature ```rust pub unsafe fn init() ``` ### Parameters None ### Return Value None ### Notes - Available on target_os = "none" or "uefi". ``` -------------------------------- ### UserContext::run_fncall Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Go to user context by function return, within the same privilege level. User program should call syscall_fn_entry() to return back. Trap reason and error code will always be set to 0x100 and 0. ```APIDOC ## run_fncall ### Description Go to user context by function return, within the same privilege level. User program should call `syscall_fn_entry()` to return back. Trap reason and error code will always be set to 0x100 and 0. ### Method Rust method ### Signature `pub fn run_fncall(&mut self)` ### Parameters - `self` (`&mut UserContext`) - Required - The user context to operate on. ### Returns None ``` -------------------------------- ### UserContext::set_ip Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Set instruction pointer. ```APIDOC ## set_ip ### Description Set instruction pointer. ### Method Rust method ### Signature `pub fn set_ip(&mut self, ip: usize)` ### Parameters - `self` (`&mut UserContext`) - Required - The user context to modify. - `ip` (`usize`) - Required - The instruction pointer value to set. ### Returns None ``` -------------------------------- ### Architecture-specific module loading in lib.rs Source: https://docs.rs/trapframe/latest/src/trapframe/lib.rs.html This snippet demonstrates how the crate uses conditional compilation attributes to select the correct architecture module for the target platform. ```rust 1#![no_std] 2#![deny(warnings)] 3 4extern crate alloc; 5 6#[cfg(target_arch = "x86_64")] 7#[path = "arch/x86_64/mod.rs"] 8mod arch; 9 10#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] 11#[path = "arch/riscv/mod.rs"] 12mod arch; 13 14#[cfg(target_arch = "mips")] 15#[path = "arch/mipsel/mod.rs"] 16pub mod arch; 17 18#[cfg(target_arch = "aarch64")] 19#[path = "arch/aarch64/mod.rs"] 20pub mod arch; 21 22pub use arch::*; ``` -------------------------------- ### Linux assembly for syscall_fn_entry and syscall_fn_return Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Assembly for Linux (target_os = "linux") defining macros to switch to kernel stack, save kernel stack, push/pop user FS base, and the global symbols syscall_fn_entry and syscall_fn_return. Uses SYS_arch_prctl with SET_FS to switch FS base. ```assembly // User: (musl) // - fs:0 (pthread.self) = user fsbase // - fs:48 (pthread.canary2) = kernel fsbase // // Kernel: (glibc) // - fs:0 (pthread.self) = kernel fsbase // - fs:64 (pthread.???) = kernel stack // - fs:72 (pthread.???) = init user fsbase // #[cfg(target_os = "linux")] global_asm!( r#" .macro SWITCH_TO_KERNEL_STACK mov rsp, fs:48 # rsp = kernel fsbase mov rsp, [rsp + 64] # rsp = kernel stack .endm .macro SAVE_KERNEL_STACK mov fs:64, rsp .endm .macro PUSH_USER_FSBASE push fs:0 .endm .macro SWITCH_TO_KERNEL_FSBASE mov eax, 158 # SYS_arch_prctl mov edi, 0x1002 # SET_FS mov rsi, fs:48 # rsi = kernel fsbase syscall .endm .macro POP_USER_FSBASE mov rsi, [rsp + 18 * 8] # rsi = user fsbase mov rdx, fs:0 # rdx = kernel fsbase test rsi, rsi jnz 1f # if not 0, goto set 0: lea rsi, [rdx + 72] # rsi = init user fsbase mov [rsi], rsi # user_fs:0 = user fsbase 1: mov eax, 158 # SYS_arch_prctl mov edi, 0x1002 # SET_FS syscall # set fsbase mov fs:48, rdx # user_fs:48 = kernel fsbase .endm .global syscall_fn_entry .global syscall_fn_return "# ); ``` -------------------------------- ### macOS assembly for syscall_fn_entry and syscall_fn_return Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Assembly for macOS (target_os = "macos") defining macros to switch to kernel stack, save kernel stack, push/pop user GS base, and the global symbols _syscall_fn_entry, syscall_fn_entry, _syscall_fn_return, syscall_fn_return. Uses syscall 0x3000003 to set GS base. ```assembly // User: (musl) // - gs:0 (pthread.self) = user gsbase // - gs:48 (pthread.canary2) = kernel gsbase // // Kernel: (darwin) // - gs:0 (pthread.tsd[self]) = kernel gsbase - 224 // - gs:48 (pthread.tsd[6]) = kernel stack // - gs:240 (pthread.tsd[30]) = init user fsbase // // Ref: // - Set gsbase: // - https://gist.github.com/aras-p/5389747 // - Get gsbase: // - https://github.com/DynamoRIO/dynamorio/issues/1568#issuecomment-239819506 // - https://github.com/apple/darwin-libpthread/blob/03c4628c8940cca6fd6a82957f683af804f62e7f/src/internal.h#L241 #[cfg(target_os = "macos")] global_asm!( r#" .macro SWITCH_TO_KERNEL_STACK mov rsp, gs:48 # rsp = kernel gsbase mov rsp, [rsp + 48] # rsp = kernel stack .endm .macro SAVE_KERNEL_STACK mov gs:48, rsp .endm .macro PUSH_USER_FSBASE push gs:0 .endm .macro SWITCH_TO_KERNEL_FSBASE mov rdi, gs:48 # rdi = kernel gsbase mov eax, 0x3000003 syscall # set gsbase .endm .macro POP_USER_FSBASE mov rdi, [rsp + 18 * 8] # rdi = user gsbase mov rsi, gs:0 add rsi, 224 # rsi = kernel gsbase test rdi, rdi jnz 1f # if not 0, goto set 0: lea rdi, [rsi + 30*8] # rdi = init user gsbase # = pthread.tsd[30] (kernel gsbase + 30 * 8) mov [rdi], rdi # user_gs:0 = user gsbase 1: mov eax, 0x3000003 syscall # set gsbase mov gs:48, rsi # user_gs:48 = kernel gsbase .endm .global _syscall_fn_entry .global syscall_fn_entry .global _syscall_fn_return .set _syscall_fn_entry, syscall_fn_entry .set _syscall_fn_return, syscall_fn_return "# ); ``` -------------------------------- ### UserContext::set_syscall_ret Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Set return value of syscall. ```APIDOC ## set_syscall_ret ### Description Set return value of syscall. ### Method Rust method ### Signature `pub fn set_syscall_ret(&mut self, ret: usize)` ### Parameters - `self` (`&mut UserContext`) - Required - The user context to modify. - `ret` (`usize`) - Required - The return value to set. ### Returns None ``` -------------------------------- ### UserContext::get_sp Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Returns the current stack pointer (RSP) from the user context. ```APIDOC ## UserContext::get_sp ### Description Returns the current stack pointer (RSP) from the user context. ### Signature ```rust pub fn get_sp(&self) -> usize ``` ### Parameters - `&self` - The user context. ### Return Value - `usize` - The current stack pointer value. ``` -------------------------------- ### x86_64 Assembly Register Management Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Assembly routines for pushing registers, switching stacks, and returning to Rust, including the syscall_fn_return entry point. ```asm 160 push r14 161 push r13 162 push r12 163 push r11 164 push r10 165 push r9 166 push r8 167 push r11 # push rsp 168 push rbp 169 push rdi 170 push rsi 171 push rdx 172 push rcx 173 push rbx 174 push rax 175 176 # restore callee-saved registers 177 SWITCH_TO_KERNEL_STACK 178 pop rbx 179 pop rbx 180 pop rbp 181 pop r12 182 pop r13 183 pop r14 184 pop r15 185 186 SWITCH_TO_KERNEL_FSBASE 187 188 # go back to Rust 189 ret 190 191 # extern "sysv64" fn syscall_fn_return(&mut UserContext) 192syscall_fn_return: 193 # save callee-saved registers 194 push r15 195 push r14 196 push r13 197 push r12 198 push rbp 199 push rbx 200 201 push rdi 202 SAVE_KERNEL_STACK 203 mov rsp, rdi 204 205 POP_USER_FSBASE 206 207 # pop trap frame (struct GeneralRegs) 208 pop rax 209 pop rbx 210 pop rcx 211 pop rdx 212 pop rsi 213 pop rdi 214 pop rbp 215 pop r8 # skip rsp 216 pop r8 217 pop r9 218 pop r10 219 pop r11 220 pop r12 221 pop r13 222 pop r14 223 pop r15 224 pop r11 # r11 = rip. FIXME: don't overwrite r11! 225 popfq # pop rflags 226 mov rsp, [rsp - 8*11] # restore rsp 227 jmp r11 # restore rip ``` -------------------------------- ### UserContext and GeneralRegs structures for user space context Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Defines UserContext with general registers, trap number, and error code, and GeneralRegs with all x86_64 general-purpose registers plus rip, rflags, fsbase, and gsbase. Both are repr(C) and derive common traits. ```rust /// User space context #[derive(Debug, Default, Clone, Copy, Eq, PartialEq)] #[repr(C)] pub struct UserContext { pub general: GeneralRegs, pub trap_num: usize, pub error_code: usize, } /// General registers #[derive(Debug, Default, Clone, Copy, Eq, PartialEq)] #[repr(C)] pub struct GeneralRegs { pub rax: usize, pub rbx: usize, pub rcx: usize, pub rdx: usize, pub rsi: usize, pub rdi: usize, pub rbp: usize, pub rsp: usize, pub r8: usize, pub r9: usize, pub r10: usize, pub r11: usize, pub r12: usize, pub r13: usize, pub r14: usize, pub r15: usize, pub rip: usize, pub rflags: usize, pub fsbase: usize, pub gsbase: usize, } ``` -------------------------------- ### Rust implementation of run_fncall and syscall_fn_entry Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Defines the syscall_fn_entry and syscall_fn_return extern functions, and the run_fncall method that calls syscall_fn_return and sets trap_num to 0x100 and error_code to 0. The user program should call syscall_fn_entry() to return back. ```rust //! Switch context by function call within the same privilege level. //! //! # Assumption //! //! This module suppose you are running kernel on Linux or macOS with glibc, //! and your user program is based on musl libc. //! //! Because we will store values in their pthread structure. use super::UserContext; use core::arch::global_asm; extern "sysv64" { /// The syscall entry of function call. /// /// # Usage /// /// Replace `syscall` instruction by a `call` instruction. /// /// ```asm /// syscall /// call syscall_fn_entry /// ``` pub fn syscall_fn_entry(); fn syscall_fn_return(regs: &mut UserContext); } impl UserContext { /// Go to user context by function return, within the same privilege level. /// /// User program should call `syscall_fn_entry()` to return back. /// Trap reason and error code will always be set to 0x100 and 0. pub fn run_fncall(&mut self) { unsafe { syscall_fn_return(self); } self.trap_num = 0x100; self.error_code = 0; } } ``` -------------------------------- ### UserContext::set_ip Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Sets the instruction pointer (RIP) in the user context. ```APIDOC ## UserContext::set_ip ### Description Sets the instruction pointer (RIP) in the user context. ### Signature ```rust pub fn set_ip(&mut self, ip: usize) ``` ### Parameters - `ip` (usize) - The new instruction pointer value. ### Return Value None ``` -------------------------------- ### UserContext::set_tls Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html Set tls pointer. ```APIDOC ## set_tls ### Description Set tls pointer. ### Method Rust method ### Signature `pub fn set_tls(&mut self, tls: usize)` ### Parameters - `self` (`&mut UserContext`) - Required - The user context to modify. - `tls` (`usize`) - Required - The TLS pointer value to set. ### Returns None ``` -------------------------------- ### Function Call Test Suite Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Rust test case that initializes a UserContext and verifies register state restoration after executing a function call. ```rust #[test] fn run_fncall() { extern "sysv64" { fn dump_registers(); } let mut stack = [0u8; 0x1000]; let mut cx = UserContext { general: GeneralRegs { rax: 0, rbx: 1, rcx: 2, rdx: 3, rsi: 4, rdi: 5, rbp: 6, rsp: stack.as_mut_ptr() as usize + 0x1000, r8: 8, r9: 9, r10: 10, r11: 11, r12: 12, r13: 13, r14: 14, r15: 15, rip: dump_registers as *const () as usize, rflags: 0, fsbase: 0, // don't set to non-zero garbage value gsbase: 0, }, trap_num: 0, error_code: 0, }; cx.run_fncall(); // check restored registers let general = unsafe { *(cx.general.rsp as *const GeneralRegs) }; assert_eq!( general, GeneralRegs { rax: 0, rbx: 1, rcx: 2, rdx: 3, rsi: 4, rdi: 5, rbp: 6, // skip rsp r8: 8, r9: 9, r10: 10, // skip r11 r12: 12, r13: 13, r14: 14, r15: 15, ..general } ); // check saved registers assert_eq!( cx.general, GeneralRegs { rax: 10, rbx: 11, rcx: 12, rdx: 13, rsi: 14, rdi: 15, rbp: 16, // skip rsp r8: 18, r9: 19, r10: 20, // skip r11 r12: 22, r13: 23, r14: 24, r15: 25, ..cx.general } ); assert_eq!(cx.trap_num, 0x100); assert_eq!(cx.error_code, 0); } ``` -------------------------------- ### UserContext::set_sp Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Sets the stack pointer (RSP) in the user context. ```APIDOC ## UserContext::set_sp ### Description Sets the stack pointer (RSP) in the user context. ### Signature ```rust pub fn set_sp(&mut self, sp: usize) ``` ### Parameters - `sp` (usize) - The new stack pointer value. ### Return Value None ``` -------------------------------- ### UserContext::get_syscall_ret Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Returns the return value of the syscall from the user context, which is stored in the RAX register. ```APIDOC ## UserContext::get_syscall_ret ### Description Returns the return value of the syscall from the user context, which is stored in the RAX register. ### Signature ```rust pub fn get_syscall_ret(&self) -> usize ``` ### Parameters - `&self` - The user context. ### Return Value - `usize` - The syscall return value (value of RAX). ``` -------------------------------- ### syscall_fn_entry function signature Source: https://docs.rs/trapframe/latest/trapframe/fn.syscall_fn_entry.html The function signature for syscall_fn_entry. ```rust pub unsafe extern "sysv64" fn syscall_fn_entry() ``` -------------------------------- ### syscall_fn_entry Source: https://docs.rs/trapframe/latest/trapframe A function that serves as the syscall entry point for function calls. It is marked as unsafe (⚠) and is part of the public API. ```APIDOC ## Function: syscall_fn_entry ### Description The syscall entry of function call. This function is marked as unsafe (⚠). ### Safety This function is unsafe and must be called with appropriate precautions. ### Parameters No parameters are documented in the source. ### Returns No return value is documented in the source. ``` -------------------------------- ### UserContext Source: https://docs.rs/trapframe/latest/trapframe A struct representing user space context. It is part of the public API for managing user context during context switches or syscalls. ```APIDOC ## Struct: UserContext ### Description Represents user space context. ### Fields No fields are documented in the source. ### Usage This struct is part of the trapframe crate's public API and can be used to manage user space context. ``` -------------------------------- ### UserContext::get_syscall_num Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Returns the syscall number from the user context, which is stored in the RAX register. ```APIDOC ## UserContext::get_syscall_num ### Description Returns the syscall number from the user context, which is stored in the RAX register. ### Signature ```rust pub fn get_syscall_num(&self) -> usize ``` ### Parameters - `&self` - The user context. ### Return Value - `usize` - The syscall number (value of RAX). ``` -------------------------------- ### Unsafe init function for interrupt handling on x86_64 Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Initializes interrupt handling by disabling interrupts, then initializing GDT, IDT, and syscall. This function is unsafe and only available for none or uefi targets. It switches to new GDT, TSS, and IDT, and enables the syscall instruction. ```rust #[cfg(any(target_os = "none", target_os = "uefi"))] pub unsafe fn init() { x86_64::instructions::interrupts::disable(); gdt::init(); idt::init(); syscall::init(); } ``` -------------------------------- ### UserContext::set_syscall_ret Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Sets the return value of the syscall in the user context by writing to the RAX register. ```APIDOC ## UserContext::set_syscall_ret ### Description Sets the return value of the syscall in the user context by writing to the RAX register. ### Signature ```rust pub fn set_syscall_ret(&mut self, ret: usize) ``` ### Parameters - `ret` (usize) - The return value to set. ### Return Value None ``` -------------------------------- ### Module declarations and conditional compilation for x86_64 Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Declares submodules with conditional compilation attributes based on target OS and feature flags. Includes fncall for Linux/macOS, and gdt, idt, ioport, syscall, trap for none/uefi targets. Re-exports syscall_fn_entry and TrapFrame conditionally. ```rust #[cfg(any(target_os = "linux", target_os = "macos"))] mod fncall; #[cfg(any(target_os = "none", target_os = "uefi"))] mod gdt; #[cfg(any(target_os = "none", target_os = "uefi"))] mod idt; #[cfg(feature = "ioport_bitmap")] #[cfg(any(target_os = "none", target_os = "uefi"))] pub mod ioport; #[cfg(any(target_os = "none", target_os = "uefi"))] mod syscall; #[cfg(any(target_os = "none", target_os = "uefi"))] mod trap; #[cfg(any(target_os = "linux", target_os = "macos"))] pub use fncall::syscall_fn_entry; #[cfg(any(target_os = "none", target_os = "uefi"))] pub use trap::TrapFrame; ``` -------------------------------- ### UserContext::set_tls Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/mod.rs.html Sets the thread-local storage (TLS) pointer by writing to the FS base register. ```APIDOC ## UserContext::set_tls ### Description Sets the thread-local storage (TLS) pointer by writing to the FS base register. ### Signature ```rust pub fn set_tls(&mut self, tls: usize) ``` ### Parameters - `tls` (usize) - The new TLS pointer value. ### Return Value None ``` -------------------------------- ### Mock Register Dump Assembly Source: https://docs.rs/trapframe/latest/src/trapframe/arch/x86_64/fncall.rs.html Assembly code used in tests to simulate a user program dumping registers onto the stack before calling the syscall entry. ```asm dump_registers: push r15 push r14 push r13 push r12 push r11 push r10 push r9 push r8 push rsp push rbp push rdi push rsi push rdx push rcx push rbx push rax add rax, 10 add rbx, 10 add rcx, 10 add rdx, 10 add rsi, 10 add rdi, 10 add rbp, 10 add r8, 10 add r9, 10 add r10, 10 add r11, 10 add r12, 10 add r13, 10 add r14, 10 add r15, 10 call syscall_fn_entry ``` -------------------------------- ### UserContext Struct Definition Source: https://docs.rs/trapframe/latest/trapframe/struct.UserContext.html The definition of the UserContext struct, which is marked with #[repr(C)] for binary compatibility. ```rust #[repr(C)] pub struct UserContext { pub general: GeneralRegs, pub trap_num: usize, pub error_code: usize, } ``` -------------------------------- ### GeneralRegs Source: https://docs.rs/trapframe/latest/trapframe A struct representing general registers. It is part of the public API for accessing and manipulating general-purpose registers. ```APIDOC ## Struct: GeneralRegs ### Description Represents general registers. ### Fields No fields are documented in the source. ### Usage This struct is part of the trapframe crate's public API and can be used to access general register state. ``` -------------------------------- ### GeneralRegs struct definition Source: https://docs.rs/trapframe/latest/trapframe/struct.GeneralRegs.html Defines the GeneralRegs struct with 20 fields representing general-purpose registers (rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8-r15, rip, rflags, fsbase, gsbase). All fields are of type usize. The struct is marked with #[repr(C)] for C-compatible layout. ```rust #[repr(C)] pub struct GeneralRegs {Show 20 fields pub rax: usize, pub rbx: usize, pub rcx: usize, pub rdx: usize, pub rsi: usize, pub rdi: usize, pub rbp: usize, pub rsp: usize, pub r8: usize, pub r9: usize, pub r10: usize, pub r11: usize, pub r12: usize, pub r13: usize, pub r14: usize, pub r15: usize, pub rip: usize, pub rflags: usize, pub fsbase: usize, pub gsbase: usize, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.