mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-13 11:06:46 +00:00
替换 local_irq_save 为 IrqFlagsGuard 实现 (#317)
This commit is contained in:
parent
abf3f634bf
commit
9550910ae1
@ -9,9 +9,10 @@ use core::{
|
|||||||
|
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
|
|
||||||
use crate::include::bindings::bindings::process_control_block;
|
use crate::{exception::InterruptArch, include::bindings::bindings::process_control_block};
|
||||||
|
|
||||||
|
use crate::arch::CurrentIrqArch;
|
||||||
|
|
||||||
use super::asm::irqflags::{local_irq_restore, local_irq_save};
|
|
||||||
/// https://www.felixcloutier.com/x86/fxsave#tbl-3-47
|
/// https://www.felixcloutier.com/x86/fxsave#tbl-3-47
|
||||||
#[repr(C, align(16))]
|
#[repr(C, align(16))]
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
@ -79,7 +80,7 @@ impl FpState {
|
|||||||
/// @brief 从用户态进入内核时,保存浮点寄存器,并关闭浮点功能
|
/// @brief 从用户态进入内核时,保存浮点寄存器,并关闭浮点功能
|
||||||
pub fn fp_state_save(pcb: &mut process_control_block) {
|
pub fn fp_state_save(pcb: &mut process_control_block) {
|
||||||
// 该过程中不允许中断
|
// 该过程中不允许中断
|
||||||
let rflags: usize = local_irq_save();
|
let guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
|
||||||
|
|
||||||
let fp: &mut FpState = if pcb.fp_state == null_mut() {
|
let fp: &mut FpState = if pcb.fp_state == null_mut() {
|
||||||
let f = Box::leak(Box::new(FpState::default()));
|
let f = Box::leak(Box::new(FpState::default()));
|
||||||
@ -111,13 +112,13 @@ pub fn fp_state_save(pcb: &mut process_control_block) {
|
|||||||
"mov cr4, rax" */
|
"mov cr4, rax" */
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
local_irq_restore(rflags);
|
drop(guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief 从内核态返回用户态时,恢复浮点寄存器,并开启浮点功能
|
/// @brief 从内核态返回用户态时,恢复浮点寄存器,并开启浮点功能
|
||||||
pub fn fp_state_restore(pcb: &mut process_control_block) {
|
pub fn fp_state_restore(pcb: &mut process_control_block) {
|
||||||
// 该过程中不允许中断
|
// 该过程中不允许中断
|
||||||
let rflags = local_irq_save();
|
let guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
|
||||||
|
|
||||||
if pcb.fp_state == null_mut() {
|
if pcb.fp_state == null_mut() {
|
||||||
panic!("fp_state_restore: fp_state is null. pid={}", pcb.pid);
|
panic!("fp_state_restore: fp_state is null. pid={}", pcb.pid);
|
||||||
@ -141,5 +142,5 @@ pub fn fp_state_restore(pcb: &mut process_control_block) {
|
|||||||
fp.restore();
|
fp.restore();
|
||||||
fp.clear();
|
fp.clear();
|
||||||
|
|
||||||
local_irq_restore(rflags);
|
drop(guard);
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,12 @@ use alloc::{boxed::Box, sync::Arc};
|
|||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
arch::CurrentIrqArch,
|
||||||
arch::{
|
arch::{
|
||||||
asm::{
|
asm::current::current_pcb,
|
||||||
current::current_pcb,
|
|
||||||
irqflags::{local_irq_restore, local_irq_save},
|
|
||||||
},
|
|
||||||
interrupt::{cli, sti},
|
interrupt::{cli, sti},
|
||||||
},
|
},
|
||||||
|
exception::InterruptArch,
|
||||||
include::bindings::bindings::MAX_CPU_NUM,
|
include::bindings::bindings::MAX_CPU_NUM,
|
||||||
kdebug, kinfo,
|
kdebug, kinfo,
|
||||||
libs::rwlock::RwLock,
|
libs::rwlock::RwLock,
|
||||||
@ -226,14 +225,14 @@ impl Softirq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn raise_softirq(&self, softirq_num: SoftirqNumber) {
|
pub fn raise_softirq(&self, softirq_num: SoftirqNumber) {
|
||||||
let flags = local_irq_save();
|
let guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
|
||||||
let processor_id = smp_get_processor_id() as usize;
|
let processor_id = smp_get_processor_id() as usize;
|
||||||
|
|
||||||
cpu_pending(processor_id).insert(VecStatus::from(softirq_num));
|
cpu_pending(processor_id).insert(VecStatus::from(softirq_num));
|
||||||
|
|
||||||
compiler_fence(Ordering::SeqCst);
|
compiler_fence(Ordering::SeqCst);
|
||||||
|
|
||||||
local_irq_restore(flags);
|
drop(guard);
|
||||||
// kdebug!("raise_softirq exited");
|
// kdebug!("raise_softirq exited");
|
||||||
}
|
}
|
||||||
pub unsafe fn clear_softirq_pending(&self, softirq_num: SoftirqNumber) {
|
pub unsafe fn clear_softirq_pending(&self, softirq_num: SoftirqNumber) {
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
use super::{page::PageFlags, PageTableKind, PhysAddr, VirtAddr};
|
use super::{page::PageFlags, PageTableKind, PhysAddr, VirtAddr};
|
||||||
use crate::{
|
use crate::{
|
||||||
arch::{
|
arch::{
|
||||||
asm::irqflags::{local_irq_restore, local_irq_save},
|
|
||||||
mm::{LockedFrameAllocator, PageMapper},
|
mm::{LockedFrameAllocator, PageMapper},
|
||||||
|
CurrentIrqArch,
|
||||||
},
|
},
|
||||||
|
exception::InterruptArch,
|
||||||
libs::align::page_align_up,
|
libs::align::page_align_up,
|
||||||
mm::allocator::page_frame::PageFrameCount,
|
mm::allocator::page_frame::PageFrameCount,
|
||||||
mm::{MMArch, MemoryManagementArch},
|
mm::{MMArch, MemoryManagementArch},
|
||||||
@ -126,12 +127,12 @@ impl KernelMapper {
|
|||||||
impl Drop for KernelMapper {
|
impl Drop for KernelMapper {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// 为了防止fetch_sub和store之间,由于中断,导致store错误清除了owner,导致错误,因此需要关中断。
|
// 为了防止fetch_sub和store之间,由于中断,导致store错误清除了owner,导致错误,因此需要关中断。
|
||||||
let flags = local_irq_save();
|
let guard = unsafe { CurrentIrqArch::save_and_disable_irq() };
|
||||||
let prev_count = KERNEL_MAPPER_LOCK_COUNT.fetch_sub(1, Ordering::Relaxed);
|
let prev_count = KERNEL_MAPPER_LOCK_COUNT.fetch_sub(1, Ordering::Relaxed);
|
||||||
if prev_count == 1 {
|
if prev_count == 1 {
|
||||||
KERNEL_MAPPER_LOCK_OWNER.store(KERNEL_MAPPER_NO_PROCESSOR, Ordering::Release);
|
KERNEL_MAPPER_LOCK_OWNER.store(KERNEL_MAPPER_NO_PROCESSOR, Ordering::Release);
|
||||||
}
|
}
|
||||||
local_irq_restore(flags);
|
drop(guard);
|
||||||
compiler_fence(Ordering::Release);
|
compiler_fence(Ordering::Release);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1118,7 +1118,8 @@ impl VMA {
|
|||||||
// kdebug!("VMA::zeroed: flusher dropped");
|
// kdebug!("VMA::zeroed: flusher dropped");
|
||||||
|
|
||||||
// 清空这些内存
|
// 清空这些内存
|
||||||
let virt_iter: VirtPageFrameIter = VirtPageFrameIter::new(destination, destination.add(page_count));
|
let virt_iter: VirtPageFrameIter =
|
||||||
|
VirtPageFrameIter::new(destination, destination.add(page_count));
|
||||||
for frame in virt_iter {
|
for frame in virt_iter {
|
||||||
let paddr = mapper.translate(frame.virt_address()).unwrap().0;
|
let paddr = mapper.translate(frame.virt_address()).unwrap().0;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user