mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-25 10:03:23 +00:00
refactor(ipc): Refactor the syscalls in ipc (#1183)
* feat(ipc): 完成对ipc的系统调用的重构 * refactor(ipc): 优化结构 Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com> * feat: fmt Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com> --------- Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com> Co-authored-by: Vitus <zhzvitus@gmail.com> Co-authored-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
This commit is contained in:
@ -20,7 +20,7 @@ use crate::{
|
||||
mm::MemoryManagementArch,
|
||||
process::ProcessManager,
|
||||
sched::{schedule, SchedMode},
|
||||
syscall::{user_access::UserBufferWriter, Syscall},
|
||||
syscall::user_access::UserBufferWriter,
|
||||
};
|
||||
|
||||
/// 信号处理的栈的栈指针的最小对齐数量
|
||||
@ -556,8 +556,11 @@ impl SignalArch for X86_64SignalArch {
|
||||
// 如果当前的rsp不来自用户态,则认为产生了错误(或被SROP攻击)
|
||||
if UserBufferWriter::new(frame, size_of::<SigFrame>(), true).is_err() {
|
||||
error!("rsp doesn't from user level");
|
||||
let _r = Syscall::kill_process(ProcessManager::current_pcb().pid(), Signal::SIGSEGV)
|
||||
.map_err(|e| e.to_posix_errno());
|
||||
let _r = crate::ipc::kill::kill_process(
|
||||
ProcessManager::current_pcb().pid(),
|
||||
Signal::SIGSEGV,
|
||||
)
|
||||
.map_err(|e| e.to_posix_errno());
|
||||
return trap_frame.rax;
|
||||
}
|
||||
let mut sigmask: SigSet = unsafe { (*frame).context.oldmask };
|
||||
@ -565,8 +568,11 @@ impl SignalArch for X86_64SignalArch {
|
||||
// 从用户栈恢复sigcontext
|
||||
if !unsafe { &mut (*frame).context }.restore_sigcontext(trap_frame) {
|
||||
error!("unable to restore sigcontext");
|
||||
let _r = Syscall::kill_process(ProcessManager::current_pcb().pid(), Signal::SIGSEGV)
|
||||
.map_err(|e| e.to_posix_errno());
|
||||
let _r = crate::ipc::kill::kill_process(
|
||||
ProcessManager::current_pcb().pid(),
|
||||
Signal::SIGSEGV,
|
||||
)
|
||||
.map_err(|e| e.to_posix_errno());
|
||||
// 如果这里返回 err 值的话会丢失上一个系统调用的返回值
|
||||
}
|
||||
// 由于系统调用的返回值会被系统调用模块被存放在rax寄存器,因此,为了还原原来的那个系统调用的返回值,我们需要在这里返回恢复后的rax的值
|
||||
@ -658,7 +664,7 @@ fn setup_frame(
|
||||
ProcessManager::current_pcb().pid(),
|
||||
sig as i32
|
||||
);
|
||||
let r = Syscall::kill_process(
|
||||
let r = crate::ipc::kill::kill_process(
|
||||
ProcessManager::current_pcb().pid(),
|
||||
Signal::SIGSEGV,
|
||||
);
|
||||
@ -698,7 +704,8 @@ fn setup_frame(
|
||||
if r.is_err() {
|
||||
// 如果地址区域位于内核空间,则直接报错
|
||||
// todo: 生成一个sigsegv
|
||||
let r = Syscall::kill_process(ProcessManager::current_pcb().pid(), Signal::SIGSEGV);
|
||||
let r =
|
||||
crate::ipc::kill::kill_process(ProcessManager::current_pcb().pid(), Signal::SIGSEGV);
|
||||
if r.is_err() {
|
||||
error!("In setup frame: generate SIGSEGV signal failed");
|
||||
}
|
||||
@ -709,7 +716,10 @@ fn setup_frame(
|
||||
// 将siginfo拷贝到用户栈
|
||||
info.copy_siginfo_to_user(unsafe { &mut ((*frame).info) as *mut SigInfo })
|
||||
.map_err(|e| -> SystemError {
|
||||
let r = Syscall::kill_process(ProcessManager::current_pcb().pid(), Signal::SIGSEGV);
|
||||
let r = crate::ipc::kill::kill_process(
|
||||
ProcessManager::current_pcb().pid(),
|
||||
Signal::SIGSEGV,
|
||||
);
|
||||
if r.is_err() {
|
||||
error!("In copy_siginfo_to_user: generate SIGSEGV signal failed");
|
||||
}
|
||||
@ -723,7 +733,10 @@ fn setup_frame(
|
||||
.context
|
||||
.setup_sigcontext(oldset, trap_frame)
|
||||
.map_err(|e: SystemError| -> SystemError {
|
||||
let r = Syscall::kill_process(ProcessManager::current_pcb().pid(), Signal::SIGSEGV);
|
||||
let r = crate::ipc::kill::kill_process(
|
||||
ProcessManager::current_pcb().pid(),
|
||||
Signal::SIGSEGV,
|
||||
);
|
||||
if r.is_err() {
|
||||
error!("In setup_sigcontext: generate SIGSEGV signal failed");
|
||||
}
|
||||
|
Reference in New Issue
Block a user