mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-28 08:53:23 +00:00
signal的处理(kill命令)以及一些其他的改进 (#100)
* 将entry.S中冗余的ret_from_syscall代码删除,改为jmp Restore_all * new: 增加判断pt_regs是否来自用户态的函数 * new: rust的cli和sti封装 * 将原有的判断pt_regs是否来自用户态的代码,统一改为调用user_mode函数 * ffz函数:获取u64中的第一个值为0的bit * spinlock增加 spinlock irq spin_unlock_irq * 临时解决显示刷新线程迟迟不运行的问题 * 更改ffi_convert的生命周期标签 * new: 测试signal用的app * 解决由于编译器优化导致local_irq_restore无法获取到正确的rflags的值的问题 * new: exec命令增加"&"后台运行选项 * procfs->status增加显示preempt和虚拟运行时间 * 更改引用计数的FFIBind2Rust trait中的生命周期标签 * new: signal处理(kill) * 更正在review中发现的一些细节问题
This commit is contained in:
11
kernel/src/arch/x86_64/asm/bitops.rs
Normal file
11
kernel/src/arch/x86_64/asm/bitops.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use core::arch::x86_64::_popcnt64;
|
||||
|
||||
/// @brief ffz - 寻找u64中的第一个0所在的位(从第0位开始寻找)
|
||||
/// 请注意,如果x中没有0,那么结果将是未定义的。请确保传入的x至少存在1个0
|
||||
///
|
||||
/// @param x 目标u64
|
||||
/// @return i32 bit-number(0..63) of the first (least significant) zero bit.
|
||||
#[inline]
|
||||
pub fn ffz(x: u64) -> i32 {
|
||||
return unsafe { _popcnt64((x & ((!x) - 1)).try_into().unwrap()) };
|
||||
}
|
@ -1,21 +1,15 @@
|
||||
use core::arch::asm;
|
||||
use core::{arch::asm, ptr::read_volatile};
|
||||
|
||||
#[inline]
|
||||
pub fn local_irq_save(flags: &mut u64) {
|
||||
unsafe {
|
||||
asm!(
|
||||
"pushfq",
|
||||
"pop rax",
|
||||
"mov rax, {0}",
|
||||
"cli",
|
||||
out(reg)(*flags),
|
||||
);
|
||||
asm!("pushfq", "pop rax", "mov rax, {0}", "cli", out(reg)(*flags),);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn local_irq_restore(flags: &u64) {
|
||||
let x = *flags;
|
||||
let x = unsafe { read_volatile(flags) };
|
||||
|
||||
unsafe {
|
||||
asm!("push r15",
|
||||
|
@ -1,3 +1,5 @@
|
||||
pub mod irqflags;
|
||||
#[macro_use]
|
||||
pub mod current;
|
||||
pub mod current;
|
||||
pub mod ptrace;
|
||||
pub mod bitops;
|
12
kernel/src/arch/x86_64/asm/ptrace.rs
Normal file
12
kernel/src/arch/x86_64/asm/ptrace.rs
Normal file
@ -0,0 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
use crate::include::bindings::bindings::pt_regs;
|
||||
|
||||
/// @brief 判断给定的栈帧是否来自用户态
|
||||
/// 判断方法为:根据代码段选择子是否具有ring3的访问权限(低2bit均为1)
|
||||
pub fn user_mode(regs: *const pt_regs)->bool{
|
||||
if (unsafe{(*regs).cs} & 0x3) != 0{
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
18
kernel/src/arch/x86_64/interrupt/mod.rs
Normal file
18
kernel/src/arch/x86_64/interrupt/mod.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#![allow(dead_code)]
|
||||
use core::arch::asm;
|
||||
|
||||
/// @brief 关闭中断
|
||||
#[inline]
|
||||
pub fn cli(){
|
||||
unsafe{
|
||||
asm!("cli");
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief 开启中断
|
||||
#[inline]
|
||||
pub fn sti(){
|
||||
unsafe{
|
||||
asm!("sti");
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#[macro_use]
|
||||
pub mod asm;
|
||||
pub mod cpu;
|
||||
pub mod cpu;
|
||||
pub mod interrupt;
|
Reference in New Issue
Block a user