mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
signal的发送(暂时父子进程之间共享信号及相应的结构体) (#89)
* 解决由于spinlock.h中包含preempt_enable()带来的循环include问题 * new: 初步实现signal的数据结构 * new:signal相关数据结构 * fix: 解决bindings.rs报一堆警告的问题 * new: rust下的kdebug kinfo kwarn kBUG kerror宏 * 移动asm.h和cmpxchg.h * new: signal的发送(暂时只支持父子进程共享信号及处理函数)
This commit is contained in:
3
kernel/src/arch/mod.rs
Normal file
3
kernel/src/arch/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
#[cfg(target_arch="x86_64")]
|
||||
#[macro_use]
|
||||
pub mod x86_64;
|
18
kernel/src/arch/x86_64/asm/current.rs
Normal file
18
kernel/src/arch/x86_64/asm/current.rs
Normal file
@ -0,0 +1,18 @@
|
||||
use crate::include::bindings::bindings::process_control_block;
|
||||
|
||||
use core::{arch::asm, sync::atomic::compiler_fence};
|
||||
|
||||
/// @brief 获取指向当前进程的pcb的可变引用
|
||||
#[inline]
|
||||
pub fn current_pcb() -> &'static mut process_control_block {
|
||||
let ret: Option<&mut process_control_block>;
|
||||
unsafe {
|
||||
let mut tmp: u64 = !(32767u64);
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
asm!("and {0}, rsp", inout(reg)(tmp),);
|
||||
compiler_fence(core::sync::atomic::Ordering::SeqCst);
|
||||
ret = (tmp as *mut process_control_block).as_mut();
|
||||
}
|
||||
|
||||
ret.unwrap()
|
||||
}
|
24
kernel/src/arch/x86_64/asm/irqflags.rs
Normal file
24
kernel/src/arch/x86_64/asm/irqflags.rs
Normal file
@ -0,0 +1,24 @@
|
||||
use core::arch::asm;
|
||||
|
||||
#[inline]
|
||||
pub fn local_irq_save(flags: &mut u64) {
|
||||
unsafe {
|
||||
asm!(
|
||||
"pushfq",
|
||||
"pop rax",
|
||||
"mov rax, {0}",
|
||||
"cli",
|
||||
out(reg)(*flags),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn local_irq_restore(flags: &u64) {
|
||||
let x = *flags;
|
||||
|
||||
unsafe {
|
||||
asm!("push r15",
|
||||
"popfq", in("r15")(x));
|
||||
}
|
||||
}
|
3
kernel/src/arch/x86_64/asm/mod.rs
Normal file
3
kernel/src/arch/x86_64/asm/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub mod irqflags;
|
||||
#[macro_use]
|
||||
pub mod current;
|
16
kernel/src/arch/x86_64/cpu.rs
Normal file
16
kernel/src/arch/x86_64/cpu.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use core::arch::asm;
|
||||
|
||||
/// @brief 获取当前cpu的apic id
|
||||
#[inline]
|
||||
pub fn arch_current_apic_id() -> u8 {
|
||||
let cpuid_res: u32;
|
||||
unsafe {
|
||||
asm!(
|
||||
"mov eax, 1",
|
||||
"cpuid",
|
||||
"mov r15, ebx",
|
||||
lateout("r15") cpuid_res
|
||||
);
|
||||
}
|
||||
return (cpuid_res >> 24) as u8;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <common/compiler.h>
|
||||
#include <arch/x86_64/asm/asm.h>
|
||||
#include <asm/asm.h>
|
||||
|
||||
/**
|
||||
* @brief 通过extern不存在的函数,来让编译器报错。以防止不符合要求的代码的产生。
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <asm/asm.h>
|
||||
// 保存当前rflags的值到变量x内并关闭中断
|
||||
#define local_irq_save(x) __asm__ __volatile__("pushfq ; popq %0 ; cli" \
|
||||
: "=g"(x)::"memory")
|
||||
|
3
kernel/src/arch/x86_64/mod.rs
Normal file
3
kernel/src/arch/x86_64/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
#[macro_use]
|
||||
pub mod asm;
|
||||
pub mod cpu;
|
Reference in New Issue
Block a user