mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 12:16:31 +00:00
chore: update toolchain version to 2024-11-05 (#1031)
* chore: update toolchain version to 2024-11-05 * update dragon reach to e945c217b3 * update dog to 6f2c0c8f12 --------- Co-authored-by: longjin <longjin@DragonOS.org>
This commit is contained in:
@ -40,7 +40,7 @@ kernel_subdirs := debug
|
||||
|
||||
|
||||
kernel_rust:
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 $(CARGO_ZBUILD) build --release --target $(TARGET_JSON)
|
||||
RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-11-05 $(CARGO_ZBUILD) build --release --target $(TARGET_JSON)
|
||||
|
||||
|
||||
all: kernel
|
||||
|
@ -4,7 +4,6 @@ use crate::arch::{
|
||||
interrupt::TrapFrame,
|
||||
};
|
||||
use asm_macros::{restore_from_x6_to_x31, save_from_x6_to_x31};
|
||||
use core::arch::asm;
|
||||
use kdepends::memoffset::offset_of;
|
||||
|
||||
/// Riscv64中断处理入口
|
||||
@ -12,7 +11,7 @@ use kdepends::memoffset::offset_of;
|
||||
#[no_mangle]
|
||||
#[repr(align(4))]
|
||||
pub unsafe extern "C" fn handle_exception() -> ! {
|
||||
asm!(
|
||||
core::arch::naked_asm!(
|
||||
concat!("
|
||||
/*
|
||||
* If coming from userspace, preserve the user thread pointer and load
|
||||
@ -27,15 +26,14 @@ pub unsafe extern "C" fn handle_exception() -> ! {
|
||||
j {_restore_kernel_tpsp}
|
||||
"),
|
||||
csr_scratch = const CSR_SSCRATCH,
|
||||
_restore_kernel_tpsp = sym _restore_kernel_tpsp,
|
||||
options(noreturn),
|
||||
_restore_kernel_tpsp = sym _restore_kernel_tpsp
|
||||
)
|
||||
}
|
||||
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn _restore_kernel_tpsp() -> ! {
|
||||
asm!(
|
||||
core::arch::naked_asm!(
|
||||
concat!("
|
||||
// 这次是从内核态进入中断
|
||||
// 从sscratch寄存器加载当前cpu的上下文
|
||||
@ -48,16 +46,14 @@ unsafe extern "C" fn _restore_kernel_tpsp() -> ! {
|
||||
"),
|
||||
csr_scratch = const CSR_SSCRATCH,
|
||||
lc_off_kernel_sp = const offset_of!(LocalContext, kernel_sp),
|
||||
_save_context = sym _save_context,
|
||||
|
||||
options(noreturn),
|
||||
_save_context = sym _save_context
|
||||
)
|
||||
}
|
||||
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn _save_context() -> ! {
|
||||
asm!(
|
||||
core::arch::naked_asm!(
|
||||
concat!("
|
||||
|
||||
|
||||
@ -164,15 +160,14 @@ unsafe extern "C" fn _save_context() -> ! {
|
||||
csr_epc = const CSR_SEPC,
|
||||
csr_tval = const CSR_STVAL,
|
||||
csr_cause = const CSR_SCAUSE,
|
||||
csr_scratch = const CSR_SSCRATCH,
|
||||
options(noreturn),
|
||||
csr_scratch = const CSR_SSCRATCH
|
||||
)
|
||||
}
|
||||
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn ret_from_exception() -> ! {
|
||||
asm!(
|
||||
core::arch::naked_asm!(
|
||||
concat!("
|
||||
ld s0, {off_status}(sp)
|
||||
andi s0, s0, {sr_spp}
|
||||
@ -249,8 +244,6 @@ pub unsafe extern "C" fn ret_from_exception() -> ! {
|
||||
off_t6 = const offset_of!(TrapFrame, t6),
|
||||
off_sp = const offset_of!(TrapFrame, sp),
|
||||
off_tp = const offset_of!(TrapFrame, tp),
|
||||
off_epc = const offset_of!(TrapFrame, epc),
|
||||
|
||||
options(noreturn),
|
||||
off_epc = const offset_of!(TrapFrame, epc)
|
||||
)
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ impl KernelThreadMechanism {
|
||||
pub(super) unsafe extern "C" fn kernel_thread_bootstrap_stage1() {
|
||||
// 这个函数要是naked的,只是因为现在还没有实现,而naked func不能打`unimplemented!()`
|
||||
// 所以先写成了普通函数
|
||||
asm!(concat!(
|
||||
core::arch::naked_asm!(concat!(
|
||||
"
|
||||
ld x3, {off_gp}(sp)
|
||||
ld x5, {off_t0}(sp)
|
||||
@ -111,8 +111,7 @@ pub(super) unsafe extern "C" fn kernel_thread_bootstrap_stage1() {
|
||||
off_t4 = const offset_of!(TrapFrame, t4),
|
||||
off_t5 = const offset_of!(TrapFrame, t5),
|
||||
off_t6 = const offset_of!(TrapFrame, t6),
|
||||
stage2_func = sym jump_to_stage2,
|
||||
options(noreturn),
|
||||
stage2_func = sym jump_to_stage2
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -78,9 +78,8 @@ pub unsafe fn arch_switch_to_user(trap_frame: TrapFrame) -> ! {
|
||||
|
||||
#[naked]
|
||||
unsafe extern "C" fn ready_to_switch_to_user(trap_frame: usize, new_pc: usize) -> ! {
|
||||
asm!(
|
||||
concat!(
|
||||
"
|
||||
core::arch::naked_asm!(concat!(
|
||||
"
|
||||
// 设置trap frame
|
||||
mv sp, a0
|
||||
// 设置返回地址
|
||||
@ -88,9 +87,7 @@ unsafe extern "C" fn ready_to_switch_to_user(trap_frame: usize, new_pc: usize) -
|
||||
jr a1
|
||||
|
||||
"
|
||||
),
|
||||
options(noreturn)
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
impl ProcessManager {
|
||||
@ -227,7 +224,7 @@ impl ProcessManager {
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.6.21/arch/riscv/kernel/entry.S#233
|
||||
#[naked]
|
||||
unsafe extern "C" fn switch_to_inner(prev: *mut ArchPCBInfo, next: *mut ArchPCBInfo) {
|
||||
core::arch::asm!(concat!(
|
||||
core::arch::naked_asm!(concat!(
|
||||
"
|
||||
sd ra, {off_ra}(a0)
|
||||
sd sp, {off_sp}(a0)
|
||||
@ -304,8 +301,7 @@ unsafe extern "C" fn switch_to_inner(prev: *mut ArchPCBInfo, next: *mut ArchPCBI
|
||||
off_s9 = const(offset_of!(ArchPCBInfo, s9)),
|
||||
off_s10 = const(offset_of!(ArchPCBInfo, s10)),
|
||||
off_s11 = const(offset_of!(ArchPCBInfo, s11)),
|
||||
before_switch_finish_hook = sym before_switch_finish_hook,
|
||||
options(noreturn));
|
||||
before_switch_finish_hook = sym before_switch_finish_hook);
|
||||
}
|
||||
|
||||
/// 在切换上下文完成后的钩子函数(必须在这里加一个跳转函数,否则会出现relocation truncated to fit: R_RISCV_JAL错误)
|
||||
|
@ -45,7 +45,7 @@ macro_rules! interrupt_handler {
|
||||
#[naked]
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn [<irq_handler $name>]() {
|
||||
core::arch::asm!(
|
||||
core::arch::naked_asm!(
|
||||
concat!(
|
||||
"
|
||||
push 0x0
|
||||
@ -60,8 +60,7 @@ macro_rules! interrupt_handler {
|
||||
jmp x86_64_do_irq
|
||||
"
|
||||
),
|
||||
irqnum = const($name),
|
||||
options(noreturn)
|
||||
irqnum = const($name)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ unsafe fn allocator_init() {
|
||||
for i in 0..total_num {
|
||||
let area = mem_block_manager().get_initial_memory_region(i).unwrap();
|
||||
// debug!("area: base={:?}, size={:#x}, end={:?}", area.base, area.size, area.base + area.size);
|
||||
for i in 0..((area.size + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE) {
|
||||
for i in 0..area.size.div_ceil(MMArch::PAGE_SIZE) {
|
||||
let paddr = area.base.add(i * MMArch::PAGE_SIZE);
|
||||
let vaddr = unsafe { MMArch::phys_2_virt(paddr) }.unwrap();
|
||||
let flags = kernel_page_flags::<MMArch>(vaddr);
|
||||
|
@ -1,5 +1,3 @@
|
||||
use core::arch::asm;
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use system_error::SystemError;
|
||||
|
||||
@ -61,7 +59,7 @@ impl KernelThreadMechanism {
|
||||
/// 跳转之后,指向Box<KernelThreadClosure>的指针将传入到stage2的函数
|
||||
#[naked]
|
||||
pub(super) unsafe extern "sysv64" fn kernel_thread_bootstrap_stage1() {
|
||||
asm!(
|
||||
core::arch::naked_asm!(
|
||||
concat!(
|
||||
"
|
||||
|
||||
@ -92,6 +90,5 @@ pub(super) unsafe extern "sysv64" fn kernel_thread_bootstrap_stage1() {
|
||||
"
|
||||
),
|
||||
stage2_func = sym kernel_thread_bootstrap_stage2,
|
||||
options(noreturn)
|
||||
)
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ impl ProcessManager {
|
||||
/// 保存上下文,然后切换进程,接着jmp到`switch_finish_hook`钩子函数
|
||||
#[naked]
|
||||
unsafe extern "sysv64" fn switch_to_inner(prev: *mut ArchPCBInfo, next: *mut ArchPCBInfo) {
|
||||
asm!(
|
||||
core::arch::naked_asm!(
|
||||
// As a quick reminder for those who are unfamiliar with the System V ABI (extern "C"):
|
||||
//
|
||||
// - the current parameters are passed in the registers `rdi`, `rsi`,
|
||||
@ -498,13 +498,12 @@ unsafe extern "sysv64" fn switch_to_inner(prev: *mut ArchPCBInfo, next: *mut Arc
|
||||
off_gs = const(offset_of!(ArchPCBInfo, gs)),
|
||||
|
||||
switch_hook = sym crate::process::switch_finish_hook,
|
||||
options(noreturn),
|
||||
);
|
||||
}
|
||||
|
||||
#[naked]
|
||||
unsafe extern "sysv64" fn switch_back() -> ! {
|
||||
asm!("ret", options(noreturn));
|
||||
core::arch::naked_asm!("ret");
|
||||
}
|
||||
|
||||
pub unsafe fn arch_switch_to_user(trap_frame: TrapFrame) -> ! {
|
||||
|
@ -1,5 +1,4 @@
|
||||
use core::{
|
||||
arch::asm,
|
||||
hint::spin_loop,
|
||||
sync::atomic::{compiler_fence, fence, AtomicBool, Ordering},
|
||||
};
|
||||
@ -65,14 +64,13 @@ unsafe extern "C" fn smp_ap_start() -> ! {
|
||||
|
||||
#[naked]
|
||||
unsafe extern "sysv64" fn smp_init_switch_stack(st: &ApStartStackInfo) -> ! {
|
||||
asm!(concat!("
|
||||
core::arch::naked_asm!(concat!("
|
||||
mov rsp, [rdi + {off_rsp}]
|
||||
mov rbp, [rdi + {off_rsp}]
|
||||
jmp {stage1}
|
||||
"),
|
||||
off_rsp = const(offset_of!(ApStartStackInfo, vaddr)),
|
||||
stage1 = sym smp_ap_start_stage1,
|
||||
options(noreturn));
|
||||
stage1 = sym smp_ap_start_stage1);
|
||||
}
|
||||
|
||||
unsafe extern "C" fn smp_ap_start_stage1() -> ! {
|
||||
|
@ -20,8 +20,8 @@ use system_error::SystemError;
|
||||
|
||||
use super::{disk_info::Partition, gendisk::GenDisk, manager::BlockDevMeta};
|
||||
|
||||
/// 该文件定义了 Device 和 BlockDevice 的接口
|
||||
/// Notice 设备错误码使用 Posix 规定的 int32_t 的错误码表示,而不是自己定义错误enum
|
||||
// 该文件定义了 Device 和 BlockDevice 的接口
|
||||
// Notice 设备错误码使用 Posix 规定的 int32_t 的错误码表示,而不是自己定义错误enum
|
||||
|
||||
// 使用方法:
|
||||
// 假设 blk_dev 是块设备
|
||||
|
@ -161,6 +161,7 @@ impl GenDiskMap {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[allow(dead_code)]
|
||||
pub fn max_idx(&self) -> u32 {
|
||||
self.max_idx.load(Ordering::SeqCst)
|
||||
}
|
||||
|
@ -134,6 +134,7 @@ impl BlockDevManager {
|
||||
}
|
||||
|
||||
/// 卸载磁盘设备
|
||||
#[allow(dead_code)]
|
||||
pub fn unregister(&self, dev: &Arc<dyn BlockDevice>) {
|
||||
let mut inner = self.inner();
|
||||
inner.disks.remove(dev.dev_name());
|
||||
|
@ -18,7 +18,7 @@ use super::{
|
||||
pub trait CharDevice: Device {
|
||||
/// Notice buffer对应设备按字节划分,使用u8类型
|
||||
/// Notice offset应该从0开始计数
|
||||
|
||||
///
|
||||
/// @brief: 从设备的第offset个字节开始,读取len个byte,存放到buf中
|
||||
/// @parameter offset: 起始字节偏移量
|
||||
/// @parameter len: 读取字节的数量
|
||||
|
@ -137,6 +137,7 @@ impl VirtIOBlkManager {
|
||||
BlockDevName::new(format!("vd{}", x), id)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn free_id(&self, id: usize) {
|
||||
if id >= Self::MAX_DEVICES {
|
||||
return;
|
||||
|
@ -1,153 +0,0 @@
|
||||
use crate::driver::base::block::block_device::BlockDevice;
|
||||
use crate::driver::base::device::device_number::{DeviceNumber, Major};
|
||||
use crate::filesystem::devfs::{DevFS, DeviceINode};
|
||||
use crate::filesystem::vfs::file::FileMode;
|
||||
use crate::filesystem::vfs::syscall::ModeType;
|
||||
use crate::filesystem::vfs::{
|
||||
core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata,
|
||||
};
|
||||
use crate::libs::spinlock::SpinLockGuard;
|
||||
use crate::{libs::spinlock::SpinLock, time::PosixTimeSpec};
|
||||
use alloc::{
|
||||
string::String,
|
||||
sync::{Arc, Weak},
|
||||
vec::Vec,
|
||||
};
|
||||
use system_error::SystemError;
|
||||
|
||||
use super::ahcidisk::LockedAhciDisk;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AhciInode {
|
||||
/// uuid 暂时不知道有什么用(x
|
||||
// uuid: Uuid,
|
||||
/// 指向自身的弱引用
|
||||
self_ref: Weak<LockedAhciInode>,
|
||||
/// 指向inode所在的文件系统对象的指针
|
||||
fs: Weak<DevFS>,
|
||||
/// INode 元数据
|
||||
metadata: Metadata,
|
||||
/// INode 对应的磁盘
|
||||
disk: Arc<LockedAhciDisk>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LockedAhciInode(pub SpinLock<AhciInode>);
|
||||
|
||||
impl LockedAhciInode {
|
||||
pub fn new(disk: Arc<LockedAhciDisk>) -> Arc<Self> {
|
||||
let inode = AhciInode {
|
||||
// uuid: Uuid::new_v5(),
|
||||
self_ref: Weak::default(),
|
||||
fs: Weak::default(),
|
||||
disk,
|
||||
metadata: Metadata {
|
||||
dev_id: 1,
|
||||
inode_id: generate_inode_id(),
|
||||
size: 0,
|
||||
blk_size: 0,
|
||||
blocks: 0,
|
||||
atime: PosixTimeSpec::default(),
|
||||
mtime: PosixTimeSpec::default(),
|
||||
ctime: PosixTimeSpec::default(),
|
||||
file_type: FileType::BlockDevice, // 文件夹,block设备,char设备
|
||||
mode: ModeType::from_bits_truncate(0o666),
|
||||
nlinks: 1,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
raw_dev: DeviceNumber::new(Major::HD_MAJOR, 0),
|
||||
},
|
||||
};
|
||||
|
||||
let result = Arc::new(LockedAhciInode(SpinLock::new(inode)));
|
||||
result.0.lock().self_ref = Arc::downgrade(&result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
impl DeviceINode for LockedAhciInode {
|
||||
fn set_fs(&self, fs: Weak<DevFS>) {
|
||||
self.0.lock().fs = fs;
|
||||
}
|
||||
}
|
||||
|
||||
impl IndexNode for LockedAhciInode {
|
||||
fn as_any_ref(&self) -> &dyn core::any::Any {
|
||||
self
|
||||
}
|
||||
|
||||
fn open(
|
||||
&self,
|
||||
_data: SpinLockGuard<FilePrivateData>,
|
||||
_mode: &FileMode,
|
||||
) -> Result<(), SystemError> {
|
||||
Err(SystemError::ENOSYS)
|
||||
}
|
||||
|
||||
fn close(&self, _data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
|
||||
Err(SystemError::ENOSYS)
|
||||
}
|
||||
|
||||
fn metadata(&self) -> Result<Metadata, SystemError> {
|
||||
return Ok(self.0.lock().metadata.clone());
|
||||
}
|
||||
|
||||
fn fs(&self) -> Arc<dyn FileSystem> {
|
||||
return self.0.lock().fs.upgrade().unwrap();
|
||||
}
|
||||
|
||||
fn list(&self) -> Result<Vec<String>, SystemError> {
|
||||
Err(SystemError::ENOSYS)
|
||||
}
|
||||
|
||||
fn set_metadata(&self, metadata: &Metadata) -> Result<(), SystemError> {
|
||||
let mut inode = self.0.lock();
|
||||
inode.metadata.atime = metadata.atime;
|
||||
inode.metadata.mtime = metadata.mtime;
|
||||
inode.metadata.ctime = metadata.ctime;
|
||||
inode.metadata.mode = metadata.mode;
|
||||
inode.metadata.uid = metadata.uid;
|
||||
inode.metadata.gid = metadata.gid;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
/// 读设备 - 应该调用设备的函数读写,而不是通过文件系统读写
|
||||
fn read_at(
|
||||
&self,
|
||||
offset: usize, // lba地址
|
||||
len: usize,
|
||||
buf: &mut [u8],
|
||||
data: SpinLockGuard<FilePrivateData>,
|
||||
) -> Result<usize, SystemError> {
|
||||
if buf.len() < len {
|
||||
return Err(SystemError::EINVAL);
|
||||
}
|
||||
|
||||
if let FilePrivateData::Unused = *data {
|
||||
return self.0.lock().disk.read_at_bytes(offset, len, buf);
|
||||
}
|
||||
|
||||
return Err(SystemError::EINVAL);
|
||||
}
|
||||
|
||||
/// 写设备 - 应该调用设备的函数读写,而不是通过文件系统读写
|
||||
fn write_at(
|
||||
&self,
|
||||
offset: usize, // lba地址
|
||||
len: usize,
|
||||
buf: &[u8],
|
||||
data: SpinLockGuard<FilePrivateData>,
|
||||
) -> Result<usize, SystemError> {
|
||||
if buf.len() < len {
|
||||
return Err(SystemError::EINVAL);
|
||||
}
|
||||
|
||||
if let FilePrivateData::Unused = *data {
|
||||
return self.0.lock().disk.write_at_bytes(offset, len, buf);
|
||||
}
|
||||
|
||||
return Err(SystemError::EINVAL);
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
//! 文件说明: 实现了 AHCI 中的控制器 HBA 的相关行为
|
||||
use core::{intrinsics::size_of, ptr};
|
||||
|
||||
use core::sync::atomic::compiler_fence;
|
||||
@ -5,8 +6,6 @@ use core::sync::atomic::compiler_fence;
|
||||
use crate::arch::MMArch;
|
||||
use crate::mm::{MemoryManagementArch, PhysAddr};
|
||||
|
||||
/// 文件说明: 实现了 AHCI 中的控制器 HBA 的相关行为
|
||||
|
||||
/// 根据 AHCI 写出 HBA 的 Command
|
||||
pub const ATA_CMD_READ_DMA_EXT: u8 = 0x25; // 读操作,并且退出
|
||||
pub const ATA_CMD_WRITE_DMA_EXT: u8 = 0x35; // 写操作,并且退出
|
||||
|
@ -1,5 +1,4 @@
|
||||
// 导出 ahci 相关的 module
|
||||
pub mod ahci_inode;
|
||||
pub mod ahcidisk;
|
||||
pub mod hba;
|
||||
use crate::arch::MMArch;
|
||||
|
@ -67,7 +67,7 @@ impl<'a> EFIMemoryDescIter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for EFIMemoryDescIter<'a> {
|
||||
impl Iterator for EFIMemoryDescIter<'_> {
|
||||
type Item = MemoryDescriptor;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -74,8 +74,7 @@ impl EFIManager {
|
||||
warn!("report systable header: failed to map systable header, err: {fw_ptr:?}");
|
||||
}
|
||||
|
||||
let s = CStr::from_bytes_with_nul(&tmp_buf)
|
||||
.unwrap_or_else(|_| CStr::from_bytes_with_nul(b"Unknown\0").unwrap());
|
||||
let s = CStr::from_bytes_with_nul(&tmp_buf).unwrap_or(c"Unknown");
|
||||
info!("EFI version: {:?}, vendor: {:?}", header.revision, s);
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,7 @@ pub trait SerioDriver: Driver {
|
||||
fn cleanup(&self, device: &Arc<dyn SerioDevice>) -> Result<(), SystemError>;
|
||||
}
|
||||
|
||||
///todo: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c#810
|
||||
|
||||
/// todo: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/input/serio/serio.c#810
|
||||
#[allow(dead_code)]
|
||||
#[inline(always)]
|
||||
pub fn serio_driver_manager() -> &'static SerioDriverManager {
|
||||
|
@ -17,7 +17,9 @@ const PAGE_SIZE: usize = 4096;
|
||||
/// @return PhysAddr 获得的内存页的初始物理地址
|
||||
pub fn dma_alloc(pages: usize) -> (usize, NonNull<u8>) {
|
||||
let page_num = PageFrameCount::new(
|
||||
((pages * PAGE_SIZE + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE).next_power_of_two(),
|
||||
(pages * PAGE_SIZE)
|
||||
.div_ceil(MMArch::PAGE_SIZE)
|
||||
.next_power_of_two(),
|
||||
);
|
||||
unsafe {
|
||||
let (paddr, count) = allocate_page_frames(page_num).expect("e1000e: alloc page failed");
|
||||
@ -44,7 +46,9 @@ pub fn dma_alloc(pages: usize) -> (usize, NonNull<u8>) {
|
||||
/// @return i32 0表示成功
|
||||
pub unsafe fn dma_dealloc(paddr: usize, vaddr: NonNull<u8>, pages: usize) -> i32 {
|
||||
let page_count = PageFrameCount::new(
|
||||
((pages * PAGE_SIZE + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE).next_power_of_two(),
|
||||
(pages * PAGE_SIZE)
|
||||
.div_ceil(MMArch::PAGE_SIZE)
|
||||
.next_power_of_two(),
|
||||
);
|
||||
|
||||
// 恢复页面属性
|
||||
|
@ -186,8 +186,14 @@ impl Clone for LoopbackDriver {
|
||||
}
|
||||
|
||||
impl phy::Device for LoopbackDriver {
|
||||
type RxToken<'a> = LoopbackRxToken where Self: 'a;
|
||||
type TxToken<'a> = LoopbackTxToken where Self: 'a;
|
||||
type RxToken<'a>
|
||||
= LoopbackRxToken
|
||||
where
|
||||
Self: 'a;
|
||||
type TxToken<'a>
|
||||
= LoopbackTxToken
|
||||
where
|
||||
Self: 'a;
|
||||
/// ## 返回设备的物理层特性。
|
||||
/// lo设备的最大传输单元为65535,最大突发大小为1,传输介质默认为Ethernet
|
||||
fn capabilities(&self) -> phy::DeviceCapabilities {
|
||||
|
@ -539,8 +539,14 @@ impl VirtioNetToken {
|
||||
}
|
||||
|
||||
impl phy::Device for VirtIONicDeviceInner {
|
||||
type RxToken<'a> = VirtioNetToken where Self: 'a;
|
||||
type TxToken<'a> = VirtioNetToken where Self: 'a;
|
||||
type RxToken<'a>
|
||||
= VirtioNetToken
|
||||
where
|
||||
Self: 'a;
|
||||
type TxToken<'a>
|
||||
= VirtioNetToken
|
||||
where
|
||||
Self: 'a;
|
||||
|
||||
fn receive(
|
||||
&mut self,
|
||||
|
@ -71,6 +71,7 @@ impl OpenFirmwareFdtDriver {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub unsafe fn set_fdt_map_guard(&self, guard: Option<MMIOSpaceGuard>) {
|
||||
self.inner.write().fdt_map_guard = guard;
|
||||
}
|
||||
@ -293,6 +294,7 @@ impl OpenFirmwareFdtDriver {
|
||||
/// 在UEFI初始化后,扫描FDT中的`/reserved-memory`节点,设置保留的内存
|
||||
///
|
||||
/// 参考: https://code.dragonos.org.cn/xref/linux-6.1.9/drivers/of/fdt.c#634
|
||||
#[allow(dead_code)]
|
||||
pub fn early_init_fdt_scan_reserved_mem(&self) {
|
||||
let vaddr = boot_params().read().fdt();
|
||||
if vaddr.is_none() {
|
||||
@ -323,7 +325,6 @@ impl OpenFirmwareFdtDriver {
|
||||
}
|
||||
|
||||
/// 保留fdt自身的内存空间
|
||||
|
||||
fn early_reserve_fdt_itself(&self, fdt: &Fdt) {
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
{
|
||||
|
@ -1474,7 +1474,7 @@ pub struct ExternalCapabilityIterator<'a> {
|
||||
pub bus_device_function: BusDeviceFunction,
|
||||
pub next_capability_offset: Option<u16>,
|
||||
}
|
||||
impl<'a> Iterator for ExternalCapabilityIterator<'a> {
|
||||
impl Iterator for ExternalCapabilityIterator<'_> {
|
||||
type Item = ExternalCapabilityInfo;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let offset = self.next_capability_offset?;
|
||||
|
@ -317,7 +317,7 @@ pub struct PciRootIterator<'a> {
|
||||
index: usize,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for PciRootIterator<'a> {
|
||||
impl Iterator for PciRootIterator<'_> {
|
||||
type Item = Arc<PciRoot>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -64,6 +64,7 @@ impl ScsiManager {
|
||||
BlockDevName::new(format!("sd{}", x), id)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn free_id(&self, id: usize) {
|
||||
if id >= Self::MAX_DEVICES {
|
||||
return;
|
||||
|
@ -181,6 +181,7 @@ impl FrameBufferManager {
|
||||
}
|
||||
|
||||
/// 根据id查找帧缓冲区
|
||||
#[allow(dead_code)]
|
||||
pub fn find_fb_by_id(&self, id: FbId) -> Result<Option<Arc<dyn FrameBuffer>>, SystemError> {
|
||||
if unlikely(!id.is_valid()) {
|
||||
return Err(SystemError::EINVAL);
|
||||
|
@ -77,7 +77,6 @@ impl VirtIOIrqManager {
|
||||
/// # 返回
|
||||
/// - 如果找到了设备,返回一个包含设备的`Option<Arc<dyn VirtIODevice>>`。
|
||||
/// - 如果没有找到设备,返回`None`。
|
||||
|
||||
pub fn lookup_device(&self, dev_id: &Arc<DeviceId>) -> Option<Arc<dyn VirtIODevice>> {
|
||||
let map = self.map.read_irqsave();
|
||||
map.get(dev_id).cloned()
|
||||
|
@ -23,7 +23,9 @@ unsafe impl Hal for HalImpl {
|
||||
_direction: BufferDirection,
|
||||
) -> (virtio_drivers::PhysAddr, NonNull<u8>) {
|
||||
let page_num = PageFrameCount::new(
|
||||
((pages * PAGE_SIZE + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE).next_power_of_two(),
|
||||
(pages * PAGE_SIZE)
|
||||
.div_ceil(MMArch::PAGE_SIZE)
|
||||
.next_power_of_two(),
|
||||
);
|
||||
unsafe {
|
||||
let (paddr, count) =
|
||||
@ -55,7 +57,9 @@ unsafe impl Hal for HalImpl {
|
||||
pages: usize,
|
||||
) -> i32 {
|
||||
let page_count = PageFrameCount::new(
|
||||
((pages * PAGE_SIZE + MMArch::PAGE_SIZE - 1) / MMArch::PAGE_SIZE).next_power_of_two(),
|
||||
(pages * PAGE_SIZE)
|
||||
.div_ceil(MMArch::PAGE_SIZE)
|
||||
.next_power_of_two(),
|
||||
);
|
||||
|
||||
// 恢复页面属性
|
||||
|
@ -306,6 +306,7 @@ impl IrqCommonData {
|
||||
self.inner.lock_irqsave().affinity = affinity;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_effective_affinity(&self, affinity: CpuMask) {
|
||||
self.inner.lock_irqsave().effective_affinity = affinity;
|
||||
}
|
||||
@ -346,6 +347,7 @@ impl InnerIrqCommonData {
|
||||
self.handler_data.clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn effective_affinity(&self) -> &CpuMask {
|
||||
&self.effective_affinity
|
||||
}
|
||||
|
@ -286,10 +286,12 @@ impl IrqDesc {
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_probe(&self) {
|
||||
self.modify_status(IrqLineStatus::IRQ_NOPROBE, IrqLineStatus::empty());
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_noprobe(&self) {
|
||||
self.modify_status(IrqLineStatus::empty(), IrqLineStatus::IRQ_NOPROBE);
|
||||
}
|
||||
@ -416,6 +418,7 @@ impl InnerIrqDesc {
|
||||
self.line_status.insert(IrqLineStatus::IRQ_NOTHREAD);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn clear_nothread(&mut self) {
|
||||
self.line_status.remove(IrqLineStatus::IRQ_NOTHREAD);
|
||||
}
|
||||
@ -451,6 +454,7 @@ impl InnerIrqDesc {
|
||||
!self.line_status.contains(IrqLineStatus::IRQ_NOAUTOEN)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn can_thread(&self) -> bool {
|
||||
!self.line_status.contains(IrqLineStatus::IRQ_NOTHREAD)
|
||||
}
|
||||
@ -486,6 +490,7 @@ impl InnerIrqDesc {
|
||||
self.actions.clear();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn remove_action(&mut self, action: &Arc<IrqAction>) {
|
||||
self.actions.retain(|a| !Arc::ptr_eq(a, action));
|
||||
}
|
||||
@ -506,14 +511,17 @@ impl InnerIrqDesc {
|
||||
&self.common_data
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn depth(&self) -> u32 {
|
||||
self.depth
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn wake_depth(&self) -> u32 {
|
||||
self.wake_depth
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_depth(&mut self, depth: u32) {
|
||||
self.depth = depth;
|
||||
}
|
||||
@ -540,6 +548,7 @@ impl InnerIrqDesc {
|
||||
&mut self.percpu_enabled
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn percpu_affinity(&self) -> &Option<CpuMask> {
|
||||
&self.percpu_affinity
|
||||
}
|
||||
@ -969,6 +978,7 @@ impl IrqDescManager {
|
||||
}
|
||||
|
||||
/// 设置指定irq的可用cpu为所有cpu
|
||||
#[allow(dead_code)]
|
||||
pub fn set_percpu_devid_all(&self, irq: IrqNumber) -> Result<(), SystemError> {
|
||||
self.set_percpu_devid(irq, None)
|
||||
}
|
||||
|
@ -319,6 +319,7 @@ impl IrqDomainManager {
|
||||
/// - `handler_data`: 中断流处理程序数据
|
||||
/// - `handler_name`: 中断处理程序名称
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[allow(dead_code)]
|
||||
pub fn domain_set_info(
|
||||
&self,
|
||||
domain: &Arc<IrqDomain>,
|
||||
@ -557,14 +558,17 @@ impl IrqDomain {
|
||||
}
|
||||
|
||||
/// The number of mapped interrupts
|
||||
#[allow(dead_code)]
|
||||
pub fn map_count(&self) -> u32 {
|
||||
self.revmap_read_irqsave().map.len() as u32
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn host_data(&self) -> Option<Arc<dyn IrqChipData>> {
|
||||
self.inner.lock_irqsave().host_data.clone()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn set_host_data(&self, host_data: Option<Arc<dyn IrqChipData>>) {
|
||||
self.inner.lock_irqsave().host_data = host_data;
|
||||
}
|
||||
|
@ -785,6 +785,7 @@ impl IrqManager {
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn irq_set_affinity(
|
||||
&self,
|
||||
irq_data: &Arc<IrqData>,
|
||||
|
@ -275,13 +275,13 @@ struct RunningCountGuard<'a> {
|
||||
}
|
||||
|
||||
impl<'a> RunningCountGuard<'a> {
|
||||
fn new(cpu_running_count: &'a PerCpuVar<AtomicI16>) -> RunningCountGuard {
|
||||
fn new(cpu_running_count: &'a PerCpuVar<AtomicI16>) -> RunningCountGuard<'a> {
|
||||
cpu_running_count.get().fetch_add(1, Ordering::SeqCst);
|
||||
return RunningCountGuard { cpu_running_count };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for RunningCountGuard<'a> {
|
||||
impl Drop for RunningCountGuard<'_> {
|
||||
fn drop(&mut self) {
|
||||
self.cpu_running_count.get().fetch_sub(1, Ordering::SeqCst);
|
||||
}
|
||||
|
@ -266,8 +266,7 @@ impl BiosParameterBlock {
|
||||
bpb.trail_sig = cursor.read_u16()?;
|
||||
|
||||
// 计算根目录项占用的空间(单位:字节)
|
||||
let root_sectors = ((bpb.root_entries_cnt as u32 * 32) + (bpb.bytes_per_sector as u32 - 1))
|
||||
/ (bpb.bytes_per_sector as u32);
|
||||
let root_sectors = (bpb.root_entries_cnt as u32 * 32).div_ceil(bpb.bytes_per_sector as u32);
|
||||
|
||||
// 每FAT扇区数
|
||||
let fat_size = if bpb.fat_size_16 != 0 {
|
||||
@ -347,9 +346,8 @@ impl BiosParameterBlock {
|
||||
}
|
||||
};
|
||||
|
||||
let root_sectors = ((self.root_entries_cnt as u32 * 32)
|
||||
+ (self.bytes_per_sector as u32 - 1))
|
||||
/ (self.bytes_per_sector as u32);
|
||||
let root_sectors =
|
||||
(self.root_entries_cnt as u32 * 32).div_ceil(self.bytes_per_sector as u32);
|
||||
|
||||
// 当前分区总扇区数
|
||||
let total_sectors = if self.total_sectors_16 != 0 {
|
||||
|
@ -256,8 +256,7 @@ impl FATFile {
|
||||
// 如果还需要更多的簇
|
||||
if bytes_remain_in_cluster < extra_bytes {
|
||||
let clusters_to_allocate =
|
||||
(extra_bytes - bytes_remain_in_cluster + fs.bytes_per_cluster() - 1)
|
||||
/ fs.bytes_per_cluster();
|
||||
(extra_bytes - bytes_remain_in_cluster).div_ceil(fs.bytes_per_cluster());
|
||||
let last_cluster = if let Some(c) = fs.get_last_cluster(self.first_cluster) {
|
||||
c
|
||||
} else {
|
||||
@ -338,7 +337,7 @@ impl FATFile {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let new_last_cluster = (new_size + fs.bytes_per_cluster() - 1) / fs.bytes_per_cluster();
|
||||
let new_last_cluster = new_size.div_ceil(fs.bytes_per_cluster());
|
||||
if let Some(begin_delete) =
|
||||
fs.get_cluster_by_relative(self.first_cluster, new_last_cluster as usize)
|
||||
{
|
||||
@ -463,8 +462,7 @@ impl FATDir {
|
||||
|
||||
// 计算需要申请多少个簇
|
||||
let clusters_required =
|
||||
(remain_entries * FATRawDirEntry::DIR_ENTRY_LEN + fs.bytes_per_cluster() - 1)
|
||||
/ fs.bytes_per_cluster();
|
||||
(remain_entries * FATRawDirEntry::DIR_ENTRY_LEN).div_ceil(fs.bytes_per_cluster());
|
||||
let mut first_cluster = Cluster::default();
|
||||
let mut prev_cluster = current_cluster;
|
||||
// debug!(
|
||||
|
@ -326,9 +326,8 @@ impl FATFileSystem {
|
||||
};
|
||||
|
||||
// 根目录项占用的扇区数(向上取整)
|
||||
let root_dir_sectors: u64 = ((bpb.root_entries_cnt as u64 * 32)
|
||||
+ (bpb.bytes_per_sector as u64 - 1))
|
||||
/ (bpb.bytes_per_sector as u64);
|
||||
let root_dir_sectors: u64 =
|
||||
(bpb.root_entries_cnt as u64 * 32).div_ceil(bpb.bytes_per_sector as u64);
|
||||
|
||||
// FAT表大小(单位:扇区)
|
||||
let fat_size = if bpb.fat_size_16 != 0 {
|
||||
@ -843,6 +842,7 @@ impl FATFileSystem {
|
||||
/// @return Ok(true) 正常
|
||||
/// @return Ok(false) 不正常
|
||||
/// @return Err(SystemError) 在判断时发生错误
|
||||
#[allow(dead_code)]
|
||||
pub fn is_hard_error_bit_ok(&mut self) -> Result<bool, SystemError> {
|
||||
match self.bpb.fat_type {
|
||||
FATType::FAT32(_) => {
|
||||
@ -935,10 +935,8 @@ impl FATFileSystem {
|
||||
|
||||
_ => {
|
||||
// FAT12 / FAT16
|
||||
let root_dir_sectors: u64 = (((self.bpb.root_entries_cnt as u64) * 32)
|
||||
+ self.bpb.bytes_per_sector as u64
|
||||
- 1)
|
||||
/ self.bpb.bytes_per_sector as u64;
|
||||
let root_dir_sectors: u64 = ((self.bpb.root_entries_cnt as u64) * 32)
|
||||
.div_ceil(self.bpb.bytes_per_sector as u64);
|
||||
// 数据区扇区数
|
||||
let data_sec: u64 = self.bpb.total_sectors_16 as u64
|
||||
- (self.bpb.rsvd_sec_cnt as u64
|
||||
@ -1283,6 +1281,7 @@ impl FATFsInfo {
|
||||
/// @brief 根据fsinfo的信息,计算当前总的空闲簇数量
|
||||
///
|
||||
/// @param 当前文件系统的最大簇号
|
||||
#[allow(dead_code)]
|
||||
pub fn count_free_cluster(&self, max_cluster: Cluster) -> Option<u64> {
|
||||
let count_clusters = max_cluster.cluster_num - RESERVED_CLUSTERS as u64 + 1;
|
||||
// 信息不合理,当前的FsInfo中存储的free count大于计算出来的值
|
||||
@ -1301,6 +1300,7 @@ impl FATFsInfo {
|
||||
/// @brief 更新FsInfo中的“空闲簇统计信息“为new_count
|
||||
///
|
||||
/// 请注意,除非手动调用`flush()`,否则本函数不会将数据刷入磁盘
|
||||
#[allow(dead_code)]
|
||||
pub fn update_free_count_abs(&mut self, new_count: u32) {
|
||||
self.free_count = new_count;
|
||||
}
|
||||
@ -1308,6 +1308,7 @@ impl FATFsInfo {
|
||||
/// @brief 更新FsInfo中的“空闲簇统计信息“,把它加上delta.
|
||||
///
|
||||
/// 请注意,除非手动调用`flush()`,否则本函数不会将数据刷入磁盘
|
||||
#[allow(dead_code)]
|
||||
pub fn update_free_count_delta(&mut self, delta: i32) {
|
||||
self.free_count = (self.free_count as i32 + delta) as u32;
|
||||
}
|
||||
@ -1360,6 +1361,7 @@ impl FATFsInfo {
|
||||
/// @brief 读取磁盘上的Fs Info扇区,将里面的内容更新到结构体中
|
||||
///
|
||||
/// @param partition fs info所在的分区
|
||||
#[allow(dead_code)]
|
||||
pub fn update(&mut self, partition: Arc<Partition>) -> Result<(), SystemError> {
|
||||
if let Some(off) = self.offset {
|
||||
let in_block_offset = off % LBA_SIZE as u64;
|
||||
@ -1888,7 +1890,7 @@ struct ClusterIter<'a> {
|
||||
fs: &'a FATFileSystem,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for ClusterIter<'a> {
|
||||
impl Iterator for ClusterIter<'_> {
|
||||
type Item = Cluster;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -169,7 +169,7 @@ impl<'a> MbrPartitionIter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for MbrPartitionIter<'a> {
|
||||
impl Iterator for MbrPartitionIter<'_> {
|
||||
type Item = Partition;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -14,6 +14,7 @@ use alloc::sync::Arc;
|
||||
use alloc::sync::Weak;
|
||||
use alloc::vec::Vec;
|
||||
use entry::{OvlEntry, OvlLayer};
|
||||
use linkme::distributed_slice;
|
||||
use system_error::SystemError;
|
||||
|
||||
const WHITEOUT_MODE: u64 = 0o020000 | 0o600; // whiteout字符设备文件模式与权限
|
||||
@ -89,7 +90,7 @@ struct OverlayFS {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct OvlInode {
|
||||
pub struct OvlInode {
|
||||
redirect: String, // 重定向路径
|
||||
file_type: FileType,
|
||||
flags: SpinLock<u64>,
|
||||
|
@ -51,7 +51,6 @@ impl Syscall {
|
||||
/// - 成功,Ok(usize)
|
||||
/// - 失败,Err(SystemError) 操作失败,返回posix错误码
|
||||
///
|
||||
|
||||
pub fn do_syslog(
|
||||
syslog_action_type: usize,
|
||||
buf: &mut [u8],
|
||||
|
@ -800,7 +800,7 @@ impl<'a> FileDescriptorIterator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for FileDescriptorIterator<'a> {
|
||||
impl Iterator for FileDescriptorIterator<'_> {
|
||||
type Item = (i32, Arc<File>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -49,6 +49,7 @@ impl BootParams {
|
||||
core::str::from_utf8(&self.boot_cmdline()[..self.boot_cmdline_len()]).unwrap()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn bootloader_name(&self) -> Option<&str> {
|
||||
self.bootloader_name.as_deref()
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ pub struct KernelCmdlineParamBuilder {
|
||||
inv: bool,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl KernelCmdlineParamBuilder {
|
||||
pub const fn new(name: &'static str, ty: KCmdlineParamType) -> Self {
|
||||
Self {
|
||||
@ -110,6 +111,7 @@ pub enum KernelCmdlineParameter {
|
||||
EarlyKV(&'static KernelCmdlineEarlyKV),
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl KernelCmdlineParameter {
|
||||
pub fn name(&self) -> &str {
|
||||
match self {
|
||||
@ -195,6 +197,7 @@ pub struct KernelCmdlineEarlyKV {
|
||||
default: &'static str,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl KernelCmdlineEarlyKV {
|
||||
pub const VALUE_MAX_LEN: usize = 256;
|
||||
|
||||
|
@ -297,7 +297,6 @@ pub struct UserSigaction {
|
||||
* siginfo中,根据signal的来源不同,该info中对应了不同的数据./=
|
||||
* 请注意,该info最大占用16字节
|
||||
*/
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SigInfo {
|
||||
|
@ -2,20 +2,15 @@
|
||||
#![feature(alloc_error_handler)]
|
||||
#![feature(allocator_api)]
|
||||
#![feature(arbitrary_self_types)]
|
||||
#![feature(asm_const)]
|
||||
#![feature(concat_idents)]
|
||||
#![feature(const_for)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_option)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_refs_to_cell)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(c_void_variant)]
|
||||
#![feature(extract_if)]
|
||||
#![feature(fn_align)]
|
||||
#![feature(linked_list_retain)]
|
||||
#![feature(naked_functions)]
|
||||
#![feature(new_uninit)]
|
||||
#![feature(ptr_internals)]
|
||||
#![feature(trait_upcasting)]
|
||||
#![feature(slice_ptr_get)]
|
||||
@ -23,16 +18,19 @@
|
||||
#![feature(vec_into_raw_parts)]
|
||||
#![feature(c_variadic)]
|
||||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![allow(internal_features)]
|
||||
#![allow(static_mut_refs, non_local_definitions, internal_features)]
|
||||
// clippy的配置
|
||||
#![deny(clippy::all)]
|
||||
#![allow(clippy::bad_bit_mask)]
|
||||
// DragonOS允许在函数中使用return语句(尤其是长函数时,我们推荐这么做)
|
||||
#![allow(clippy::let_and_return)]
|
||||
#![allow(clippy::needless_pass_by_ref_mut)]
|
||||
#![allow(clippy::needless_return)]
|
||||
#![allow(clippy::single_char_pattern)]
|
||||
#![allow(clippy::upper_case_acronyms)]
|
||||
#![allow(
|
||||
clippy::macro_metavars_in_unsafe,
|
||||
clippy::upper_case_acronyms,
|
||||
clippy::single_char_pattern,
|
||||
clippy::needless_return,
|
||||
clippy::needless_pass_by_ref_mut,
|
||||
clippy::let_and_return,
|
||||
clippy::bad_bit_mask
|
||||
)]
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
|
@ -47,7 +47,6 @@ use alloc::sync::Arc;
|
||||
///
|
||||
/// fn test() {
|
||||
/// let a = A { name: "a".to_string() };
|
||||
|
||||
/// let a_arc: Arc<dyn Base> = Arc::new(a) as Arc<dyn Base>;
|
||||
/// let a_arc2: Option<Arc<A>> = a_arc.downcast_arc::<A>();
|
||||
/// assert!(a_arc2.is_some());
|
||||
|
@ -129,7 +129,7 @@ pub struct CpuMaskIter<'a> {
|
||||
begin: bool,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for CpuMaskIter<'a> {
|
||||
impl Iterator for CpuMaskIter<'_> {
|
||||
type Item = ProcessorId;
|
||||
|
||||
fn next(&mut self) -> Option<ProcessorId> {
|
||||
|
@ -844,7 +844,7 @@ impl<'a> FutexIterator<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for FutexIterator<'a> {
|
||||
impl Iterator for FutexIterator<'_> {
|
||||
type Item = VirtAddr;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -298,7 +298,6 @@ pub fn scm_init(enable_put_to_window: bool) {
|
||||
/// ## 参数
|
||||
///
|
||||
/// - framework 要启动的ui框架
|
||||
|
||||
pub fn scm_framework_enable(framework: Arc<dyn ScmUiFramework>) -> Result<i32, SystemError> {
|
||||
// 获取信息
|
||||
let metadata = framework.metadata()?;
|
||||
@ -321,7 +320,6 @@ pub fn scm_framework_enable(framework: Arc<dyn ScmUiFramework>) -> Result<i32, S
|
||||
///
|
||||
/// ## 参数
|
||||
/// - framework 框架结构体
|
||||
|
||||
pub fn scm_register(framework: Arc<dyn ScmUiFramework>) -> Result<i32, SystemError> {
|
||||
// 把ui框架加入链表
|
||||
|
||||
|
@ -595,7 +595,6 @@ impl TextuiWindow {
|
||||
/// -flags 标志位
|
||||
/// -vlines_num 虚拟行的总数
|
||||
/// -chars_num 每行最大的字符数
|
||||
|
||||
pub fn new(flags: WindowFlag, vlines_num: i32, chars_num: i32) -> Self {
|
||||
let mut initial_vlines = Vec::new();
|
||||
|
||||
@ -667,10 +666,8 @@ impl TextuiWindow {
|
||||
|
||||
/// 重新渲染某个窗口的某个虚拟行
|
||||
/// ## 参数
|
||||
|
||||
/// - window 窗口结构体
|
||||
/// - vline_id 虚拟行号
|
||||
|
||||
fn textui_refresh_vline(&mut self, vline_id: LineId) -> Result<(), SystemError> {
|
||||
if self.flags.contains(WindowFlag::TEXTUI_CHROMATIC) {
|
||||
return self.textui_refresh_characters(
|
||||
@ -788,12 +785,10 @@ impl TextuiWindow {
|
||||
}
|
||||
/// 根据输入的一个字符在窗口上输出
|
||||
/// ## 参数
|
||||
|
||||
/// - window 窗口
|
||||
/// - character 字符
|
||||
/// - FRcolor 前景色(RGB)
|
||||
/// - BKcolor 背景色(RGB)
|
||||
|
||||
fn textui_putchar_window(
|
||||
&mut self,
|
||||
character: char,
|
||||
@ -1027,7 +1022,6 @@ where
|
||||
/// - character 字符
|
||||
/// - FRcolor 前景色(RGB)
|
||||
/// - BKcolor 背景色(RGB)
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rs_textui_putchar(character: u8, fr_color: u32, bk_color: u32) -> i32 {
|
||||
if let Some(current_vc) = vc_manager().current_vc() {
|
||||
|
@ -286,7 +286,6 @@ impl<K: Ord + Clone + Debug, V: Clone + Debug> NodePtr<K, V> {
|
||||
|
||||
/// A red black tree implemented with Rust
|
||||
/// It is required that the keys implement the [`Ord`] traits.
|
||||
|
||||
/// # Examples
|
||||
/// ```rust
|
||||
/// use rbtree::RBTree;
|
||||
@ -431,7 +430,7 @@ where
|
||||
|
||||
impl<K: Eq + Ord + Debug, V: Eq + Debug> Eq for RBTree<K, V> {}
|
||||
|
||||
impl<'a, K: Ord + Debug, V: Debug> Index<&'a K> for RBTree<K, V> {
|
||||
impl<K: Ord + Debug, V: Debug> Index<&K> for RBTree<K, V> {
|
||||
type Output = V;
|
||||
|
||||
#[inline]
|
||||
@ -482,7 +481,7 @@ impl<'a, K: Ord + Debug, V: Debug> Clone for Keys<'a, K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K: Ord + Debug, V: Debug> fmt::Debug for Keys<'a, K, V> {
|
||||
impl<K: Ord + Debug, V: Debug> fmt::Debug for Keys<'_, K, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
}
|
||||
@ -527,7 +526,7 @@ impl<'a, K: Ord + Debug, V: Debug> Clone for Values<'a, K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K: Ord + Debug, V: Debug> fmt::Debug for Values<'a, K, V> {
|
||||
impl<K: Ord + Debug, V: Debug> fmt::Debug for Values<'_, K, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
}
|
||||
@ -575,7 +574,7 @@ impl<'a, K: Ord + Debug, V: Debug> Clone for ValuesMut<'a, K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, K: Ord + Debug, V: Debug> fmt::Debug for ValuesMut<'a, K, V> {
|
||||
impl<K: Ord + Debug, V: Debug> fmt::Debug for ValuesMut<'_, K, V> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.debug_list().entries(self.clone()).finish()
|
||||
}
|
||||
@ -1651,7 +1650,7 @@ mod tests {
|
||||
let vec = vec![(1, 1), (2, 2), (3, 3)];
|
||||
let mut map: RBTree<_, _> = vec.into_iter().collect();
|
||||
for value in map.values_mut() {
|
||||
*value = (*value) * 2
|
||||
*value *= 2
|
||||
}
|
||||
let values: Vec<_> = map.values().cloned().collect();
|
||||
assert_eq!(values.len(), 3);
|
||||
@ -1808,7 +1807,7 @@ mod tests {
|
||||
b.insert(2, "two");
|
||||
b.insert(3, "three");
|
||||
|
||||
a.extend(b.into_iter());
|
||||
a.extend(b);
|
||||
|
||||
assert_eq!(a.len(), 3);
|
||||
assert_eq!(a[&1], "one");
|
||||
@ -1818,6 +1817,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_rev_iter() {
|
||||
use crate::libs::rbtree::RBTree;
|
||||
let mut a = RBTree::new();
|
||||
a.insert(1, 1);
|
||||
a.insert(2, 2);
|
||||
@ -1826,7 +1826,7 @@ mod tests {
|
||||
assert_eq!(a.len(), 3);
|
||||
let mut cache = vec![];
|
||||
for e in a.iter().rev() {
|
||||
cache.push(e.0.clone());
|
||||
cache.push(*e.0);
|
||||
}
|
||||
assert_eq!(&cache, &vec![3, 2, 1]);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ use crate::{
|
||||
};
|
||||
|
||||
///RwLock读写锁
|
||||
|
||||
/// @brief READER位占据从右往左数第三个比特位
|
||||
const READER: u32 = 1 << 2;
|
||||
|
||||
@ -548,7 +547,7 @@ impl<'rwlock, T> RwLockWriteGuard<'rwlock, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> Deref for RwLockReadGuard<'rwlock, T> {
|
||||
impl<T> Deref for RwLockReadGuard<'_, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -556,7 +555,7 @@ impl<'rwlock, T> Deref for RwLockReadGuard<'rwlock, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> Deref for RwLockUpgradableGuard<'rwlock, T> {
|
||||
impl<T> Deref for RwLockUpgradableGuard<'_, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -564,7 +563,7 @@ impl<'rwlock, T> Deref for RwLockUpgradableGuard<'rwlock, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> Deref for RwLockWriteGuard<'rwlock, T> {
|
||||
impl<T> Deref for RwLockWriteGuard<'_, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@ -572,13 +571,13 @@ impl<'rwlock, T> Deref for RwLockWriteGuard<'rwlock, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> DerefMut for RwLockWriteGuard<'rwlock, T> {
|
||||
impl<T> DerefMut for RwLockWriteGuard<'_, T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
return unsafe { &mut *self.data };
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> Drop for RwLockReadGuard<'rwlock, T> {
|
||||
impl<T> Drop for RwLockReadGuard<'_, T> {
|
||||
fn drop(&mut self) {
|
||||
debug_assert!(self.lock.load(Ordering::Relaxed) & !(WRITER | UPGRADED) > 0);
|
||||
self.lock.fetch_sub(READER, Ordering::Release);
|
||||
@ -586,7 +585,7 @@ impl<'rwlock, T> Drop for RwLockReadGuard<'rwlock, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> Drop for RwLockUpgradableGuard<'rwlock, T> {
|
||||
impl<T> Drop for RwLockUpgradableGuard<'_, T> {
|
||||
fn drop(&mut self) {
|
||||
debug_assert_eq!(
|
||||
self.inner.lock.load(Ordering::Relaxed) & (WRITER | UPGRADED),
|
||||
@ -598,7 +597,7 @@ impl<'rwlock, T> Drop for RwLockUpgradableGuard<'rwlock, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'rwlock, T> Drop for RwLockWriteGuard<'rwlock, T> {
|
||||
impl<T> Drop for RwLockWriteGuard<'_, T> {
|
||||
fn drop(&mut self) {
|
||||
debug_assert_eq!(self.inner.lock.load(Ordering::Relaxed) & WRITER, WRITER);
|
||||
self.inner
|
||||
|
@ -64,7 +64,6 @@ macro_rules! volatile_write_bit {
|
||||
/// volwrite!(self.common_cfg, queue_enable, 0);
|
||||
///
|
||||
/// 这样做不仅使代码的可读性提高了,也避免了对只读寄存器进行写入的误操作
|
||||
|
||||
/// 只读寄存器
|
||||
#[derive(Default)]
|
||||
#[repr(transparent)]
|
||||
|
@ -473,7 +473,7 @@ pub struct MemBlockIter<'a> {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl<'a> MemBlockIter<'a> {
|
||||
impl MemBlockIter<'_> {
|
||||
/// 获取内存区域数量
|
||||
pub fn total_num(&self) -> usize {
|
||||
self.inner.initial_memory_regions_num
|
||||
@ -490,7 +490,7 @@ impl<'a> MemBlockIter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for MemBlockIter<'a> {
|
||||
impl Iterator for MemBlockIter<'_> {
|
||||
type Item = PhysMemoryArea;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -208,6 +208,8 @@ impl RingPage {
|
||||
let data_head = unsafe { &(*(self.ptr as *mut perf_event_mmap_page)).data_head };
|
||||
data_tail != data_head
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
unsafe { core::slice::from_raw_parts(self.ptr as *const u8, self.size) }
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ pub struct PerfSample<'a> {
|
||||
pub value: &'a [u8],
|
||||
}
|
||||
|
||||
impl<'a> PerfSample<'a> {
|
||||
impl PerfSample<'_> {
|
||||
pub fn calculate_size(value_size: usize) -> usize {
|
||||
size_of::<SampleHeader>() + value_size
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub struct WaitIdInfo {
|
||||
pub cause: i32,
|
||||
}
|
||||
|
||||
impl<'a> KernelWaitOption<'a> {
|
||||
impl KernelWaitOption<'_> {
|
||||
pub fn new(pid_type: PidType, pid: Pid, options: WaitOption) -> Self {
|
||||
Self {
|
||||
pid_type,
|
||||
|
@ -212,7 +212,7 @@ impl Syscall {
|
||||
return Ok(target_proc.basic().pgid());
|
||||
}
|
||||
/// @brief 获取当前进程的父进程id
|
||||
|
||||
///
|
||||
/// 若为initproc则ppid设置为0
|
||||
pub fn getppid() -> Result<Pid, SystemError> {
|
||||
let current_pcb = ProcessManager::current_pcb();
|
||||
|
@ -10,12 +10,11 @@ use system_error::SystemError;
|
||||
|
||||
use super::{user_access::UserBufferWriter, Syscall};
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
/// 系统信息
|
||||
///
|
||||
/// 参考 https://code.dragonos.org.cn/xref/linux-6.1.9/include/uapi/linux/sysinfo.h#8
|
||||
#[derive(Debug, Default, Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct SysInfo {
|
||||
uptime: u64,
|
||||
loads: [u64; 3],
|
||||
|
@ -160,7 +160,7 @@ pub struct UserBufferReader<'a> {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl<'a> UserBufferReader<'a> {
|
||||
impl UserBufferReader<'_> {
|
||||
/// 构造一个指向用户空间位置的BufferReader,为了兼容类似传入 *const u8 的情况,使用单独的泛型来进行初始化
|
||||
///
|
||||
/// @param addr 用户空间指针
|
||||
@ -321,7 +321,7 @@ impl<'a> UserBufferWriter<'a> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn buffer<T>(&'a mut self, offset: usize) -> Result<&mut [T], SystemError> {
|
||||
pub fn buffer<T>(&'a mut self, offset: usize) -> Result<&'a mut [T], SystemError> {
|
||||
Self::convert_with_offset::<T>(self.buffer, offset).map_err(|_| SystemError::EINVAL)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user