TrapFrame

Struct TrapFrame 

Source
#[repr(C)]
pub struct TrapFrame {
Show 34 fields pub sepc: usize, pub x1_ra: usize, pub x2_sp: usize, pub x3_gp: usize, pub x4_tp: usize, pub x5_t0: usize, pub x6_t1: usize, pub x7_t2: usize, pub x8_s0: usize, pub x9_s1: usize, pub x10_a0: usize, pub x11_a1: usize, pub x12_a2: usize, pub x13_a3: usize, pub x14_a4: usize, pub x15_a5: usize, pub x16_a6: usize, pub x17_a7: usize, pub x18_s2: usize, pub x19_s3: usize, pub x20_s4: usize, pub x21_s5: usize, pub x22_s6: usize, pub x23_s7: usize, pub x24_s8: usize, pub x25_s9: usize, pub x26_s10: usize, pub x27_s11: usize, pub x28_t3: usize, pub x29_t4: usize, pub x30_t5: usize, pub x31_t6: usize, pub sstatus: usize, pub kernel_sp: usize,
}
Expand description

陷阱帧结构体,保存寄存器状态

Fields§

§sepc: usize

程序计数器 在发生陷阱时,sepc 寄存器的值应保存到这里

§x1_ra: usize§x2_sp: usize§x3_gp: usize§x4_tp: usize§x5_t0: usize§x6_t1: usize§x7_t2: usize§x8_s0: usize§x9_s1: usize§x10_a0: usize§x11_a1: usize§x12_a2: usize§x13_a3: usize§x14_a4: usize§x15_a5: usize§x16_a6: usize§x17_a7: usize§x18_s2: usize§x19_s3: usize§x20_s4: usize§x21_s5: usize§x22_s6: usize§x23_s7: usize§x24_s8: usize§x25_s9: usize§x26_s10: usize§x27_s11: usize§x28_t3: usize§x29_t4: usize§x30_t5: usize§x31_t6: usize§sstatus: usize§kernel_sp: usize

Implementations§

Source§

impl TrapFrame

Source

pub fn zero_init() -> Self

创建一个全零初始化的陷阱帧

Source

pub fn get_sp(&self) -> usize

获取栈指针

Source

pub fn set_sp(&mut self, val: usize)

设置栈指针

Source

pub fn get_a0(&self) -> usize

获取第一个参数寄存器 (a0)

Source

pub fn set_a0(&mut self, val: usize)

设置第一个参数寄存器 (a0)

Source

pub fn set_sepc(&mut self, pc: usize)

设置程序计数器

Source

pub fn get_sepc(&self) -> usize

获取程序计数器

Source

pub fn set_kernel_trap_frame( &mut self, entry: usize, terminal: usize, kernel_sp: usize, )

设置内核线程的初始陷阱帧 参数:

  • entry: 线程入口地址
  • terminal: 线程结束时跳转地址
  • kernel_sp: 内核栈顶地址
Source

pub unsafe fn set_clone_trap_frame( &mut self, parent_frame: &TrapFrame, kernel_sp: usize, user_sp: usize, )

设置克隆线程的 TrapFrame 参数:

  • parent_frame: 父线程的 TrapFrame 引用
  • entry: 线程入口地址
  • args: 传递给线程函数的参数
  • kernel_sp: 内核栈顶地址
  • user_sp: 用户栈顶地址
§安全性
  • parent_frame 必须指向一个完全初始化的、有效的 TrapFrame
  • parent_frame 必须在整个复制期间保持有效
  • self 必须指向一个可写的内存区域,大小至少为 size_of::<TrapFrame>()
  • selfparent_frame 不能内存重叠
  • 调用后 self 将包含 parent_frame 的精确副本(除了修改的字段)
Source

pub fn set_exec_trap_frame( &mut self, entry: usize, user_sp: usize, kernel_sp: usize, argc: usize, argv: usize, envp: usize, )

设置用户态的 TrapFrame 用于execve新程序 参数:

  • entry: 用户程序入口地址
  • user_sp: 用户栈顶地址
  • kernel_sp: 内核栈顶地址
  • argc: 命令行参数个数
  • argv: 命令行参数指针数组地址
  • envp: 环境变量指针数组地址
Source

pub unsafe fn set_fork_trap_frame(&mut self, parent_frame: &TrapFrame)

设置 fork 后子进程的 TrapFrame

§参数:
  • tpr: 父进程的 TrapFrame 引用
§安全性
  • parent_frame 必须指向一个完全初始化的、有效的 TrapFrame
  • parent_frame 必须在整个复制期间保持有效
  • self 必须指向一个可写的内存区域,大小至少为 size_of::<TrapFrame>()
  • selfparent_frame 不能内存重叠
  • 调用后 self 将包含 parent_frame 的精确副本(除了修改的字段)
Source

pub fn to_mcontext(&self) -> MContextT

将 TrapFrame 转换为 MContextT 结构体

Source

pub fn restore_from_mcontext(&mut self, mcontext: &MContextT)

从 MContextT 恢复 TrapFrame

Trait Implementations§

Source§

impl Clone for TrapFrame

Source§

fn clone(&self) -> TrapFrame

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TrapFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for TrapFrame

Auto Trait Implementations§

§

impl Freeze for TrapFrame

§

impl RefUnwindSafe for TrapFrame

§

impl Send for TrapFrame

§

impl Sync for TrapFrame

§

impl Unpin for TrapFrame

§

impl UnwindSafe for TrapFrame

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.