-
Notifications
You must be signed in to change notification settings - Fork 3
Arch refactor #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arch refactor #255
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -293,3 +293,79 @@ impl crate::kernel::syscall::syscall_frame::SyscallFrame for TrapFrame { | |||||||||||||||||||||||||||||||||||||||||||||||||
| self.regs[4] = val; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| impl crate::arch::HwTrapFrame for TrapFrame { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn zero_init() -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::zero_init() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_kernel_trap_frame(&mut self, entry: usize, terminal: usize, kernel_sp: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_kernel_trap_frame(self, entry, terminal, kernel_sp) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_exec_trap_frame_from_layout( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| &mut self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| entry: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kernel_sp: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| layout: &crate::arch::task::ExecStackLayout, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_exec_trap_frame_from_layout(self, entry, kernel_sp, layout) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe fn set_clone_trap_frame( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| &mut self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| parent_frame: &Self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kernel_sp: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| user_sp: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe { TrapFrame::set_clone_trap_frame(self, parent_frame, kernel_sp, user_sp) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe fn set_fork_trap_frame(&mut self, parent_frame: &Self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe { TrapFrame::set_fork_trap_frame(self, parent_frame) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+315
to
+326
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement the safe version of
Suggested change
References
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn get_sp(&self) -> usize { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::get_sp(self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_sp(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_sp(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_a0(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_a0(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_a1(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_a1(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_a2(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_a2(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_ra(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_ra(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_sepc(&mut self, pc: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_sepc(self, pc) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn get_sepc(&self) -> usize { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::get_sepc(self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_tls(&mut self, tls: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_tls(self, tls) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn to_mcontext(&self) -> MContextT { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::to_mcontext(self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn restore_from_mcontext(&mut self, mcontext: &MContextT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::restore_from_mcontext(self, mcontext) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -225,6 +225,82 @@ impl crate::kernel::syscall::syscall_frame::SyscallFrame for TrapFrame { | |||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| impl crate::arch::HwTrapFrame for TrapFrame { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn zero_init() -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::zero_init() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_kernel_trap_frame(&mut self, entry: usize, terminal: usize, kernel_sp: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_kernel_trap_frame(self, entry, terminal, kernel_sp) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_exec_trap_frame_from_layout( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| &mut self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| entry: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kernel_sp: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| layout: &crate::arch::task::ExecStackLayout, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_exec_trap_frame_from_layout(self, entry, kernel_sp, layout) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe fn set_clone_trap_frame( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| &mut self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| parent_frame: &Self, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| kernel_sp: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| user_sp: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe { TrapFrame::set_clone_trap_frame(self, parent_frame, kernel_sp, user_sp) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe fn set_fork_trap_frame(&mut self, parent_frame: &Self) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe { TrapFrame::set_fork_trap_frame(self, parent_frame) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+246
to
+257
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement the safe version of
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn get_sp(&self) -> usize { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::get_sp(self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_sp(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_sp(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_a0(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_a0(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_a1(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_a1(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_a2(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_a2(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_ra(&mut self, val: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_ra(self, val) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_sepc(&mut self, pc: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_sepc(self, pc) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn get_sepc(&self) -> usize { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::get_sepc(self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn set_tls(&mut self, tls: usize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::set_tls(self, tls) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn to_mcontext(&self) -> MContextT { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::to_mcontext(self) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| fn restore_from_mcontext(&mut self, mcontext: &MContextT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TrapFrame::restore_from_mcontext(self, mcontext) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| pub struct SumGuard; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| impl SumGuard { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn new() -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
HwTrapFramerequiresCopy(as specified bypub trait HwTrapFrame: Copy + ...), any implementing type is guaranteed to beCopy. Therefore, copying the trap frame can be done safely using simple struct assignment (e.g.,*self = *parent_frame;) instead ofcore::ptr::copy_nonoverlapping. This allows us to remove theunsafekeyword from these trait methods entirely, improving safety and maintainability.