4
1
mirror of https://github.com/DragonOS-Community/DragonOS.git synced 2025-06-20 05:56:32 +00:00

修复内核的clippy检查报错 (#637)

修复内核的clippy检查报错
---------

Co-authored-by: Samuel Dai <947309196@qq.com>
Co-authored-by: Donkey Kane <109840258+xiaolin2004@users.noreply.github.com>
Co-authored-by: themildwind <107623059+themildwind@users.noreply.github.com>
Co-authored-by: GnoCiYeH <heyicong@dragonos.org>
Co-authored-by: MemoryShore <105195940+MemoryShore@users.noreply.github.com>
Co-authored-by: 曾俊 <110876916+ZZJJWarth@users.noreply.github.com>
Co-authored-by: sun5etop <146408999+sun5etop@users.noreply.github.com>
Co-authored-by: hmt <114841534+1037827920@users.noreply.github.com>
Co-authored-by: laokengwt <143977175+laokengwt@users.noreply.github.com>
Co-authored-by: TTaq <103996388+TTaq@users.noreply.github.com>
Co-authored-by: Jomo <2512364506@qq.com>
Co-authored-by: Samuel Dai <samuka007@qq.com>
Co-authored-by: sspphh <112558065+sspphh@users.noreply.github.com>
This commit is contained in:
LoGin
2024-03-22 23:26:39 +08:00
committed by GitHub
parent 4695947e1b
commit b5b571e026
175 changed files with 1820 additions and 2155 deletions
kernel
crates
bitmap
unified-init
macros
src
arch
driver
exception
filesystem
include
bindings
init
ipc
lib.rs
libs
mm
net
process
sched
smp
syscall

@ -117,6 +117,10 @@ impl<T: Clone + SafeForZero, const ALIGN: usize> Clone for AlignedBox<T, ALIGN>
/// 一个用于表明某个类型是安全的用于零初始化的 trait
///
/// 该 trait 用于表明某个类型是安全的用于零初始化的,即该类型的所有位都可以被初始化为 0 而不会出现未定义行为。
///
/// # Safety
///
/// 该 trait 是 unsafe 的,因为它要求实现者保证该类型的所有位都可以被初始化为 0 而不会出现未定义行为。
pub unsafe trait SafeForZero {}
unsafe impl<const NUM: usize> SafeForZero for [u8; NUM] {}

@ -194,6 +194,7 @@ impl ElfLoader {
/// ## 返回值
///
/// - `Ok((VirtAddr, bool))`如果成功加载则bool值为true否则为false. VirtAddr为加载的地址
#[allow(clippy::too_many_arguments)]
fn load_elf_segment(
&self,
user_vm_guard: &mut RwLockWriteGuard<'_, InnerAddressSpace>,
@ -501,7 +502,7 @@ impl ElfLoader {
}
impl BinaryLoader for ElfLoader {
fn probe(self: &'static Self, param: &ExecParam, buf: &[u8]) -> Result<(), ExecError> {
fn probe(&'static self, param: &ExecParam, buf: &[u8]) -> Result<(), ExecError> {
// let elf_bytes =
// ElfBytes::<AnyEndian>::minimal_parse(buf).map_err(|_| ExecError::NotExecutable)?;
@ -518,7 +519,7 @@ impl BinaryLoader for ElfLoader {
}
fn load(
self: &'static Self,
&'static self,
param: &mut ExecParam,
head_buf: &[u8],
) -> Result<BinaryLoaderResult, ExecError> {
@ -546,7 +547,7 @@ impl BinaryLoader for ElfLoader {
let interpreter: Option<File> = None;
for seg in phdr_table {
if seg.p_type == PT_GNU_PROPERTY {
_gnu_property_data = Some(seg.clone());
_gnu_property_data = Some(seg);
continue;
}
if seg.p_type != PT_INTERP {
@ -659,6 +660,7 @@ impl BinaryLoader for ElfLoader {
let vaddr = VirtAddr::new(seg_to_load.p_vaddr.try_into().unwrap());
#[allow(clippy::if_same_then_else)]
if !first_pt_load {
elf_map_flags.insert(MapFlags::MAP_FIXED_NOREPLACE);
} else if elf_type == ElfType::Executable {
@ -743,10 +745,10 @@ impl BinaryLoader for ElfLoader {
}
let p_vaddr = VirtAddr::new(seg_to_load.p_vaddr as usize);
if (seg_to_load.p_flags & elf::abi::PF_X) != 0 {
if start_code.is_none() || start_code.as_ref().unwrap() > &p_vaddr {
start_code = Some(p_vaddr);
}
if (seg_to_load.p_flags & elf::abi::PF_X) != 0
&& (start_code.is_none() || start_code.as_ref().unwrap() > &p_vaddr)
{
start_code = Some(p_vaddr);
}
if start_data.is_none()
@ -796,11 +798,7 @@ impl BinaryLoader for ElfLoader {
}
// kdebug!("elf load: phdr_vaddr={phdr_vaddr:?}");
let program_entrypoint = VirtAddr::new(ehdr.e_entry as usize + load_bias);
let phdr_vaddr = if phdr_vaddr.is_some() {
Some(phdr_vaddr.unwrap() + load_bias)
} else {
None
};
let phdr_vaddr = phdr_vaddr.map(|phdr_vaddr| phdr_vaddr + load_bias);
elf_bss += load_bias;
elf_brk += load_bias;

@ -69,7 +69,7 @@ impl FutexHashBucket {
/// 进入该函数前,需要关中断
#[inline(always)]
pub fn sleep_no_sched(&mut self, futex_q: Arc<FutexObj>) -> Result<(), SystemError> {
assert!(CurrentIrqArch::is_irq_enabled() == false);
assert!(!CurrentIrqArch::is_irq_enabled());
self.chain.push_back(futex_q);
ProcessManager::mark_sleep(true)?;
@ -193,7 +193,7 @@ impl PartialEq for PrivateKey {
.address_space
.as_ref()
.unwrap_or(&Weak::default())
.ptr_eq(&other.address_space.as_ref().unwrap_or(&Weak::default()))
.ptr_eq(other.address_space.as_ref().unwrap_or(&Weak::default()))
&& self.address == other.address;
}
}
@ -261,9 +261,7 @@ impl Futex {
let pcb = ProcessManager::current_pcb();
// 创建超时计时器任务
let mut timer = None;
if !abs_time.is_none() {
let time = abs_time.unwrap();
if let Some(time) = abs_time {
let wakeup_helper = WakeUpHelper::new(pcb.clone());
let sec = time.tv_sec;
@ -299,8 +297,8 @@ impl Futex {
Some(bucket_mut) => {
if !bucket_mut.contains(&futex_q) {
// 取消定时器任务
if timer.is_some() {
timer.unwrap().cancel();
if let Some(timer) = timer {
timer.cancel();
}
return Ok(0);
}
@ -309,20 +307,18 @@ impl Futex {
}
None => {
// 取消定时器任务
if timer.is_some() {
timer.unwrap().cancel();
if let Some(timer) = timer {
timer.cancel();
}
return Ok(0);
}
};
// 如果是超时唤醒,则返回错误
if timer.is_some() {
if timer.clone().unwrap().timeout() {
bucket_mut.remove(futex_q);
if timer.is_some() && timer.clone().unwrap().timeout() {
bucket_mut.remove(futex_q);
return Err(SystemError::ETIMEDOUT);
}
return Err(SystemError::ETIMEDOUT);
}
// TODO: 如果没有挂起的信号则重新判断是否满足wait要求重新进入wait
@ -334,12 +330,12 @@ impl Futex {
// 需要处理信号然后重启futex系统调用
// 取消定时器任务
if timer.is_some() {
let timer = timer.unwrap();
if let Some(timer) = timer {
if !timer.timeout() {
timer.cancel();
}
}
Ok(0)
}
@ -412,7 +408,7 @@ impl Futex {
return Err(SystemError::EINVAL);
}
if likely(!cmpval.is_none()) {
if likely(cmpval.is_some()) {
let uval_reader =
UserBufferReader::new(uaddr1.as_ptr::<u32>(), core::mem::size_of::<u32>(), true)?;
let curval = uval_reader.read_one_from_user::<u32>(0)?;
@ -505,7 +501,7 @@ impl Futex {
// 计算相对页的偏移量
let offset = address & (MMArch::PAGE_SIZE - 1);
// 判断内存对齐
if !(uaddr.data() & (core::mem::size_of::<u32>() - 1) == 0) {
if uaddr.data() & (core::mem::size_of::<u32>() - 1) != 0 {
return Err(SystemError::EINVAL);
}
@ -555,16 +551,14 @@ impl Futex {
let mut oparg = sign_extend32((encoded_op & 0x00fff000) >> 12, 11);
let cmparg = sign_extend32(encoded_op & 0x00000fff, 11);
if encoded_op & (FutexOP::FUTEX_OP_OPARG_SHIFT.bits() << 28) != 0 {
if oparg > 31 {
kwarn!(
"futex_wake_op: pid:{} tries to shift op by {}; fix this program",
ProcessManager::current_pcb().pid().data(),
oparg
);
if (encoded_op & (FutexOP::FUTEX_OP_OPARG_SHIFT.bits() << 28) != 0) && oparg > 31 {
kwarn!(
"futex_wake_op: pid:{} tries to shift op by {}; fix this program",
ProcessManager::current_pcb().pid().data(),
oparg
);
oparg &= 31;
}
oparg &= 31;
}
// TODO: 这个汇编似乎是有问题的,目前不好测试

@ -1,3 +1,4 @@
pub mod constant;
#[allow(clippy::module_inception)]
pub mod futex;
pub mod syscall;

@ -13,11 +13,11 @@ pub const TYPE1_KEYCODE_FLAG_BREAK: u8 = 0x80; // 用于判断按键是否被按
#[derive(Debug, PartialEq, Eq)]
#[allow(dead_code)]
pub enum KeyFlag {
NoneFlag = 0 as u8,
PauseBreak = 1 as u8,
PrintScreenPress = 2 as u8,
PrintScreenRelease = 4 as u8,
OtherKey = 8 as u8, // 除了上面两个按键以外的功能按键(不包括下面的第三类按键)
NoneFlag = 0_u8,
PauseBreak = 1_u8,
PrintScreenPress = 2_u8,
PrintScreenRelease = 4_u8,
OtherKey = 8_u8, // 除了上面两个按键以外的功能按键(不包括下面的第三类按键)
}
/// @brief A FSM to parse type one keyboard scan code
@ -117,13 +117,11 @@ impl TypeOneFSMState {
};
if scancode != PAUSE_BREAK_SCAN_CODE[i as usize] {
return self.handle_type3(scancode, scancode_status);
} else if i == 5 {
// 所有Pause Break扫描码都被清除
return TypeOneFSMState::Start;
} else {
if i == 5 {
// 所有Pause Break扫描码都被清除
return TypeOneFSMState::Start;
} else {
return TypeOneFSMState::PauseBreak(i + 1);
}
return TypeOneFSMState::PauseBreak(i + 1);
}
}
@ -244,7 +242,7 @@ impl TypeOneFSMState {
// 数字小键盘的 / 符号
scancode_status.kp_forward_slash = true;
let ch = '/' as u8;
let ch = b'/';
Self::emit(ch);
}
0xb5 => {
@ -252,7 +250,7 @@ impl TypeOneFSMState {
}
0x1c => {
scancode_status.kp_enter = true;
Self::emit('\n' as u8);
Self::emit(b'\n');
}
0x9c => {
scancode_status.kp_enter = false;
@ -266,7 +264,7 @@ impl TypeOneFSMState {
fn handle_type3(&self, scancode: u8, scancode_status: &mut ScanCodeStatus) -> TypeOneFSMState {
// 判断按键是被按下还是抬起
let flag_make = if (scancode & (TYPE1_KEYCODE_FLAG_BREAK as u8)) > 0 {
let flag_make = if (scancode & (TYPE1_KEYCODE_FLAG_BREAK)) > 0 {
false //up
} else {
true //down
@ -307,7 +305,7 @@ impl TypeOneFSMState {
key = KeyFlag::NoneFlag;
}
_ => {
if flag_make == false {
if !flag_make {
// kdebug!("in type3 ch is {:#x}\n",ch);
key = KeyFlag::NoneFlag;
}
@ -319,14 +317,12 @@ impl TypeOneFSMState {
col = true;
}
if scancode_status.caps_lock {
if index >= 0x10 && index <= 0x19 {
col = !col;
} else if index >= 0x1e && index <= 0x26 {
col = !col;
} else if index >= 0x2c && index <= 0x32 {
col = !col;
}
if scancode_status.caps_lock
&& ((0x10..=0x19).contains(&index)
|| (0x1e..=0x26).contains(&index)
|| (0x2c..=0x32).contains(&index))
{
col = !col;
}
let mut ch = TYPE1_KEY_CODE_MAPTABLE[col as usize + 2 * index as usize];
@ -373,14 +369,12 @@ impl TypeOneFSMState {
}
if scancode != PRTSC_SCAN_CODE[i as usize] {
return self.handle_type3(scancode, scancode_status);
} else if i == 3 {
// 成功解析出PrtscPress
return TypeOneFSMState::Start;
} else {
if i == 3 {
// 成功解析出PrtscPress
return TypeOneFSMState::Start;
} else {
// 继续解析
return TypeOneFSMState::PrtscPress(i + 1);
}
// 继续解析
return TypeOneFSMState::PrtscPress(i + 1);
}
}
@ -400,14 +394,12 @@ impl TypeOneFSMState {
}
if scancode != PRTSC_SCAN_CODE[i as usize] {
return self.handle_type3(scancode, scancode_status);
} else if i == 3 {
// 成功解析出PrtscRelease
return TypeOneFSMState::Start;
} else {
if i == 3 {
// 成功解析出PrtscRelease
return TypeOneFSMState::Start;
} else {
// 继续解析
return TypeOneFSMState::PrtscRelease(i + 1);
}
// 继续解析
return TypeOneFSMState::PrtscRelease(i + 1);
}
}
}
@ -479,51 +471,44 @@ impl ScanCodeStatus {
const TYPE1_KEY_CODE_MAPTABLE: [u8; 256] = [
/*0x00*/ 0, 0, /*0x01*/ 0, 0, // ESC
/*0x02*/ '1' as u8, '!' as u8, /*0x03*/ '2' as u8, '@' as u8,
/*0x04*/ '3' as u8, '#' as u8, /*0x05*/ '4' as u8, '$' as u8,
/*0x06*/ '5' as u8, '%' as u8, /*0x07*/ '6' as u8, '^' as u8,
/*0x08*/ '7' as u8, '&' as u8, /*0x09*/ '8' as u8, '*' as u8,
/*0x0a*/ '9' as u8, '(' as u8, /*0x0b*/ '0' as u8, ')' as u8,
/*0x0c*/ '-' as u8, '_' as u8, /*0x0d*/ '=' as u8, '+' as u8,
/*0x0e \b */ 8 as u8, 8 as u8, // BACKSPACE
/*0x0f*/ '\t' as u8, '\t' as u8, // TAB
/*0x02*/ b'1', b'!', /*0x03*/ b'2', b'@', /*0x04*/ b'3', b'#',
/*0x05*/ b'4', b'$', /*0x06*/ b'5', b'%', /*0x07*/ b'6', b'^',
/*0x08*/ b'7', b'&', /*0x09*/ b'8', b'*', /*0x0a*/ b'9', b'(',
/*0x0b*/ b'0', b')', /*0x0c*/ b'-', b'_', /*0x0d*/ b'=', b'+',
/*0x0e \b */ 8, 8, // BACKSPACE
/*0x0f*/ b'\t', b'\t', // TAB
////////////////////////character///////////////////////////
/*0x10*/ 'q' as u8,
'Q' as u8, /*0x11*/ 'w' as u8, 'W' as u8, /*0x12*/ 'e' as u8, 'E' as u8,
/*0x13*/ 'r' as u8, 'R' as u8, /*0x14*/ 't' as u8, 'T' as u8,
/*0x15*/ 'y' as u8, 'Y' as u8, /*0x16*/ 'u' as u8, 'U' as u8,
/*0x17*/ 'i' as u8, 'I' as u8, /*0x18*/ 'o' as u8, 'O' as u8,
/*0x19*/ 'p' as u8, 'P' as u8,
/*0x10*/ b'q', b'Q',
/*0x11*/ b'w', b'W', /*0x12*/ b'e', b'E', /*0x13*/ b'r', b'R',
/*0x14*/ b't', b'T', /*0x15*/ b'y', b'Y', /*0x16*/ b'u', b'U',
/*0x17*/ b'i', b'I', /*0x18*/ b'o', b'O', /*0x19*/ b'p', b'P',
////////////////////////character///////////////////////////
/*0x1a*/ '[' as u8,
'{' as u8, /*0x1b*/ ']' as u8, '}' as u8, /*0x1c*/ '\n' as u8,
'\n' as u8, // ENTER
/*0x1a*/ b'[', b'{',
/*0x1b*/ b']', b'}', /*0x1c*/ b'\n', b'\n', // ENTER
/*0x1d*/ 0x1d, 0x1d, // CTRL Left
////////////////////////character///////////////////////////
/*0x1e*/ 'a' as u8,
'A' as u8, /*0x1f*/ 's' as u8, 'S' as u8, /*0x20*/ 'd' as u8, 'D' as u8,
/*0x21*/ 'f' as u8, 'F' as u8, /*0x22*/ 'g' as u8, 'G' as u8,
/*0x23*/ 'h' as u8, 'H' as u8, /*0x24*/ 'j' as u8, 'J' as u8,
/*0x25*/ 'k' as u8, 'K' as u8, /*0x26*/ 'l' as u8, 'L' as u8,
/*0x1e*/ b'a', b'A',
/*0x1f*/ b's', b'S', /*0x20*/ b'd', b'D', /*0x21*/ b'f', b'F',
/*0x22*/ b'g', b'G', /*0x23*/ b'h', b'H', /*0x24*/ b'j', b'J',
/*0x25*/ b'k', b'K', /*0x26*/ b'l', b'L',
////////////////////////character///////////////////////////
/*0x27*/ ';' as u8,
':' as u8, /*0x28*/ '\'' as u8, '"' as u8, /*0x29*/ '`' as u8, '~' as u8,
/*0x2a*/ 0x2a, 0x2a, // SHIFT Left
/*0x2b*/ '\\' as u8, '|' as u8,
/*0x27*/ b';', b':',
/*0x28*/ b'\'', b'"', /*0x29*/ b'`', b'~', /*0x2a*/ 0x2a,
0x2a, // SHIFT Left
/*0x2b*/ b'\\', b'|',
////////////////////////character///////////////////////////
/*0x2c*/ 'z' as u8,
'Z' as u8, /*0x2d*/ 'x' as u8, 'X' as u8, /*0x2e*/ 'c' as u8, 'C' as u8,
/*0x2f*/ 'v' as u8, 'V' as u8, /*0x30*/ 'b' as u8, 'B' as u8,
/*0x31*/ 'n' as u8, 'N' as u8, /*0x32*/ 'm' as u8, 'M' as u8,
/*0x2c*/ b'z', b'Z',
/*0x2d*/ b'x', b'X', /*0x2e*/ b'c', b'C', /*0x2f*/ b'v', b'V',
/*0x30*/ b'b', b'B', /*0x31*/ b'n', b'N', /*0x32*/ b'm', b'M',
////////////////////////character///////////////////////////
/*0x33*/ ',' as u8,
'<' as u8, /*0x34*/ '.' as u8, '>' as u8, /*0x35*/ '/' as u8, '?' as u8,
/*0x36*/ 0x36, 0x36, // SHIFT Right
/*0x37*/ '*' as u8, '*' as u8, /*0x38*/ 0x38, 0x38, // ALT Left
/*0x39*/ ' ' as u8, ' ' as u8, /*0x3a*/ 0, 0, // CAPS LOCK
/*0x33*/ b',', b'<',
/*0x34*/ b'.', b'>', /*0x35*/ b'/', b'?', /*0x36*/ 0x36,
0x36, // SHIFT Right
/*0x37*/ b'*', b'*', /*0x38*/ 0x38, 0x38, // ALT Left
/*0x39*/ b' ', b' ', /*0x3a*/ 0, 0, // CAPS LOCK
/*0x3b*/ 0, 0, // F1
/*0x3c*/ 0, 0, // F2
/*0x3d*/ 0, 0, // F3
@ -536,19 +521,19 @@ const TYPE1_KEY_CODE_MAPTABLE: [u8; 256] = [
/*0x44*/ 0, 0, // F10
/*0x45*/ 0, 0, // NUM LOCK
/*0x46*/ 0, 0, // SCROLL LOCK
/*0x47*/ '7' as u8, 0, /*PAD HONE*/
/*0x48*/ '8' as u8, 0, /*PAD UP*/
/*0x49*/ '9' as u8, 0, /*PAD PAGEUP*/
/*0x4a*/ '-' as u8, 0, /*PAD MINUS*/
/*0x4b*/ '4' as u8, 0, /*PAD LEFT*/
/*0x4c*/ '5' as u8, 0, /*PAD MID*/
/*0x4d*/ '6' as u8, 0, /*PAD RIGHT*/
/*0x4e*/ '+' as u8, 0, /*PAD PLUS*/
/*0x4f*/ '1' as u8, 0, /*PAD END*/
/*0x50*/ '2' as u8, 0, /*PAD DOWN*/
/*0x51*/ '3' as u8, 0, /*PAD PAGEDOWN*/
/*0x52*/ '0' as u8, 0, /*PAD INS*/
/*0x53*/ '.' as u8, 0, /*PAD DOT*/
/*0x47*/ b'7', 0, /*PAD HONE*/
/*0x48*/ b'8', 0, /*PAD UP*/
/*0x49*/ b'9', 0, /*PAD PAGEUP*/
/*0x4a*/ b'-', 0, /*PAD MINUS*/
/*0x4b*/ b'4', 0, /*PAD LEFT*/
/*0x4c*/ b'5', 0, /*PAD MID*/
/*0x4d*/ b'6', 0, /*PAD RIGHT*/
/*0x4e*/ b'+', 0, /*PAD PLUS*/
/*0x4f*/ b'1', 0, /*PAD END*/
/*0x50*/ b'2', 0, /*PAD DOWN*/
/*0x51*/ b'3', 0, /*PAD PAGEDOWN*/
/*0x52*/ b'0', 0, /*PAD INS*/
/*0x53*/ b'.', 0, /*PAD DOT*/
/*0x54*/ 0, 0, /*0x55*/ 0, 0, /*0x56*/ 0, 0, /*0x57*/ 0, 0, // F11
/*0x58*/ 0, 0, // F12
/*0x59*/ 0, 0, /*0x5a*/ 0, 0, /*0x5b*/ 0, 0, /*0x5c*/ 0, 0,

@ -72,7 +72,7 @@ impl ScmBufferInfo {
///
/// - `Result<Self, SystemError>` 创建成功返回新的帧缓冲区结构体,创建失败返回错误码
pub fn new(mut buf_type: ScmBufferFlag) -> Result<Self, SystemError> {
if unlikely(SCM_DOUBLE_BUFFER_ENABLED.load(Ordering::SeqCst) == false) {
if unlikely(!SCM_DOUBLE_BUFFER_ENABLED.load(Ordering::SeqCst)) {
let mut device_buffer = video_refresh_manager().device_buffer().clone();
buf_type.remove(ScmBufferFlag::SCM_BF_DB);
buf_type.insert(ScmBufferFlag::SCM_BF_FB);
@ -143,16 +143,10 @@ impl ScmBufferInfo {
}
pub fn is_double_buffer(&self) -> bool {
match &self.buf {
ScmBuffer::DoubleBuffer(_) => true,
_ => false,
}
matches!(&self.buf, ScmBuffer::DoubleBuffer(_))
}
pub fn is_device_buffer(&self) -> bool {
match &self.buf {
ScmBuffer::DeviceBuffer(_) => true,
_ => false,
}
matches!(&self.buf, ScmBuffer::DeviceBuffer(_))
}
pub fn copy_from_nonoverlapping(&mut self, src: &ScmBufferInfo) {
@ -301,7 +295,7 @@ pub fn scm_framework_enable(framework: Arc<dyn ScmUiFramework>) -> Result<i32, S
// }
let mut current_framework = CURRENT_FRAMEWORK.write();
if SCM_DOUBLE_BUFFER_ENABLED.load(Ordering::SeqCst) == true {
if SCM_DOUBLE_BUFFER_ENABLED.load(Ordering::SeqCst) {
video_refresh_manager().set_refresh_target(&metadata.buf_info)?;
}
@ -393,7 +387,7 @@ pub fn scm_disable_put_to_window() {
// mm之前要停止往窗口打印信息时因为没有动态内存分配(rwlock与otion依然能用但是textui并没有往scm注册)且使用的是textui,要直接修改textui里面的值
if CURRENT_FRAMEWORK.read().is_none() {
textui_disable_put_to_window();
assert!(textui_is_enable_put_to_window() == false);
assert!(!textui_is_enable_put_to_window());
} else {
let r = CURRENT_FRAMEWORK
.write()

@ -158,20 +158,19 @@ impl Sub<i32> for LineId {
LineId::new(self.0 - rhs)
}
}
impl Into<i32> for LineId {
fn into(self) -> i32 {
self.0.clone()
impl From<LineId> for i32 {
fn from(value: LineId) -> Self {
value.0
}
}
impl Into<u32> for LineId {
fn into(self) -> u32 {
self.0.clone() as u32
impl From<LineId> for u32 {
fn from(value: LineId) -> Self {
value.0 as u32
}
}
impl Into<usize> for LineId {
fn into(self) -> usize {
self.0.clone() as usize
impl From<LineId> for usize {
fn from(value: LineId) -> Self {
value.0 as usize
}
}
impl Sub<LineId> for LineId {
@ -220,19 +219,19 @@ impl Sub<i32> for LineIndex {
}
}
impl Into<i32> for LineIndex {
fn into(self) -> i32 {
self.0.clone()
impl From<LineIndex> for i32 {
fn from(val: LineIndex) -> Self {
val.0
}
}
impl Into<u32> for LineIndex {
fn into(self) -> u32 {
self.0.clone() as u32
impl From<LineIndex> for u32 {
fn from(value: LineIndex) -> Self {
value.0 as u32
}
}
impl Into<usize> for LineIndex {
fn into(self) -> usize {
self.0.clone() as usize
impl From<LineIndex> for usize {
fn from(value: LineIndex) -> Self {
value.0 as usize
}
}
#[derive(Copy, Clone, Debug)]
@ -260,24 +259,24 @@ impl From<u32> for FontColor {
return Self(value & 0x00ffffff);
}
}
impl Into<usize> for FontColor {
fn into(self) -> usize {
self.0.clone() as usize
impl From<FontColor> for usize {
fn from(value: FontColor) -> Self {
value.0 as usize
}
}
impl Into<u32> for FontColor {
fn into(self) -> u32 {
self.0.clone()
impl From<FontColor> for u32 {
fn from(value: FontColor) -> Self {
value.0
}
}
impl Into<u16> for FontColor {
fn into(self) -> u16 {
self.0.clone() as u16
impl From<FontColor> for u16 {
fn from(value: FontColor) -> Self {
value.0 as u16
}
}
impl Into<u64> for FontColor {
fn into(self) -> u64 {
self.0.clone() as u64
impl From<FontColor> for u64 {
fn from(value: FontColor) -> Self {
value.0 as u64
}
}
@ -463,7 +462,7 @@ impl TextuiCharChromatic {
}
unsafe {
addr = (addr.offset(1)) as *mut u32;
addr = addr.offset(1);
}
}
}
@ -776,14 +775,14 @@ impl TextuiWindow {
if character == '\n' {
// 换行时还需要输出\r
send_to_default_serial8250_port(&[b'\r']);
if is_enable_window == true {
if is_enable_window {
self.textui_new_line()?;
}
return Ok(());
}
// 输出制表符
else if character == '\t' {
if is_enable_window == true {
if is_enable_window {
if let TextuiVline::Chromatic(vline) =
&self.vlines[<LineId as Into<usize>>::into(self.vline_operating)]
{
@ -798,7 +797,7 @@ impl TextuiWindow {
}
// 字符 '\x08' 代表 ASCII 码中的退格字符。它在输出中的作用是将光标向左移动一个位置,并在该位置上输出后续的字符,从而实现字符的删除或替换。
else if character == '\x08' {
if is_enable_window == true {
if is_enable_window {
let mut tmp = LineIndex(0);
if let TextuiVline::Chromatic(vline) =
&mut self.vlines[<LineId as Into<usize>>::into(self.vline_operating)]
@ -853,17 +852,15 @@ impl TextuiWindow {
self.textui_refresh_vlines(self.top_vline, actual_line_sum)?;
}
}
} else {
if is_enable_window == true {
if let TextuiVline::Chromatic(vline) =
&self.vlines[<LineId as Into<usize>>::into(self.vline_operating)]
{
if !vline.index.check(self.chars_per_line) {
self.textui_new_line()?;
}
return self.true_textui_putchar_window(character, frcolor, bkcolor);
} else if is_enable_window {
if let TextuiVline::Chromatic(vline) =
&self.vlines[<LineId as Into<usize>>::into(self.vline_operating)]
{
if !vline.index.check(self.chars_per_line) {
self.textui_new_line()?;
}
return self.true_textui_putchar_window(character, frcolor, bkcolor);
}
}
@ -902,7 +899,7 @@ impl TextUiFramework {
default_window: Arc<SpinLock<TextuiWindow>>,
) -> Self {
let actual_line =
AtomicI32::new((&metadata.buf_info().height() / TEXTUI_CHAR_HEIGHT) as i32);
AtomicI32::new((metadata.buf_info().height() / TEXTUI_CHAR_HEIGHT) as i32);
let inner = TextUiFramework {
metadata: RwLock::new(metadata),
window_list,
@ -1001,8 +998,7 @@ pub extern "C" fn rs_textui_putchar(character: u8, fr_color: u32, bk_color: u32)
);
let port = TTY_PORTS[current_vcnum as usize].clone();
let tty = port.port_data().tty();
if tty.is_some() {
let tty = tty.unwrap();
if let Some(tty) = tty {
send_to_default_serial8250_port(&[character]);
return tty
.write_without_serial(buf.as_bytes(), buf.len())

@ -49,7 +49,7 @@ pub fn no_init_textui_putchar_window(
if unlikely(character == '\n') {
// 换行时还需要输出\r
send_to_default_serial8250_port(&[b'\r']);
if is_put_to_window == true {
if is_put_to_window {
NO_ALLOC_OPERATIONS_LINE.fetch_add(1, Ordering::SeqCst);
NO_ALLOC_OPERATIONS_INDEX.store(0, Ordering::SeqCst);
}
@ -57,7 +57,7 @@ pub fn no_init_textui_putchar_window(
}
// 输出制表符
else if character == '\t' {
if is_put_to_window == true {
if is_put_to_window {
let char = TextuiCharChromatic::new(Some(' '), frcolor, bkcolor);
//打印的空格数注意将每行分成一个个表格每个表格为8个字符
@ -75,7 +75,7 @@ pub fn no_init_textui_putchar_window(
}
// 字符 '\x08' 代表 ASCII 码中的退格字符。它在输出中的作用是将光标向左移动一个位置,并在该位置上输出后续的字符,从而实现字符的删除或替换。
else if character == '\x08' {
if is_put_to_window == true {
if is_put_to_window {
NO_ALLOC_OPERATIONS_INDEX.fetch_sub(1, Ordering::SeqCst);
let op_char = NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst);
if op_char >= 0 {
@ -98,24 +98,21 @@ pub fn no_init_textui_putchar_window(
}
}
}
} else {
if is_put_to_window == true {
// 输出其他字符
let char = TextuiCharChromatic::new(Some(character), frcolor, bkcolor);
} else if is_put_to_window {
// 输出其他字符
let char = TextuiCharChromatic::new(Some(character), frcolor, bkcolor);
if NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst)
== CHAR_PER_LINE.load(Ordering::SeqCst)
{
NO_ALLOC_OPERATIONS_INDEX.store(0, Ordering::SeqCst);
NO_ALLOC_OPERATIONS_LINE.fetch_add(1, Ordering::SeqCst);
}
char.no_init_textui_render_chromatic(
LineId::new(NO_ALLOC_OPERATIONS_LINE.load(Ordering::SeqCst)),
LineIndex::new(NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst)),
);
NO_ALLOC_OPERATIONS_INDEX.fetch_add(1, Ordering::SeqCst);
if NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst) == CHAR_PER_LINE.load(Ordering::SeqCst)
{
NO_ALLOC_OPERATIONS_INDEX.store(0, Ordering::SeqCst);
NO_ALLOC_OPERATIONS_LINE.fetch_add(1, Ordering::SeqCst);
}
char.no_init_textui_render_chromatic(
LineId::new(NO_ALLOC_OPERATIONS_LINE.load(Ordering::SeqCst)),
LineIndex::new(NO_ALLOC_OPERATIONS_INDEX.load(Ordering::SeqCst)),
);
NO_ALLOC_OPERATIONS_INDEX.fetch_add(1, Ordering::SeqCst);
}
return Ok(());

@ -19,6 +19,7 @@ impl<T> LockFreeFlags<T> {
}
}
#[allow(clippy::mut_from_ref)]
pub fn get_mut(&self) -> &mut T {
unsafe {
(self.inner.get().as_ref().unwrap() as *const T as *mut T)

@ -64,8 +64,7 @@ impl<T> Mutex<T> {
// 当前mutex已经上锁
if inner.is_locked {
// 检查当前进程是否处于等待队列中,如果不在,就加到等待队列内
if self.check_pid_in_wait_list(&inner, ProcessManager::current_pcb().pid()) == false
{
if !self.check_pid_in_wait_list(&inner, ProcessManager::current_pcb().pid()) {
inner.wait_list.push_back(ProcessManager::current_pcb());
}

@ -38,7 +38,7 @@ impl<V: Clone + Copy, T> NotifierChain<V, T> {
// 在 notifier chain中寻找第一个优先级比要插入块低的块
for b in self.0.iter() {
// 判断之前是否已经注册过该节点
if Arc::as_ptr(&block) == Arc::as_ptr(b) {
if Arc::ptr_eq(&block, b) {
kwarn!(
"notifier callback {:?} already registered",
Arc::as_ptr(&block)
@ -65,7 +65,7 @@ impl<V: Clone + Copy, T> NotifierChain<V, T> {
/// @brief 在通知链中取消注册节点
pub fn unregister(&mut self, block: Arc<dyn NotifierBlock<V, T>>) -> Result<(), SystemError> {
let remove = self.0.extract_if(|b| Arc::as_ptr(&block) == Arc::as_ptr(b));
let remove = self.0.extract_if(|b| Arc::ptr_eq(&block, b));
match remove.count() {
0 => return Err(SystemError::ENOENT),
_ => return Ok(()),
@ -107,6 +107,12 @@ impl<V: Clone + Copy, T> NotifierChain<V, T> {
#[derive(Debug)]
pub struct AtomicNotifierChain<V: Clone + Copy, T>(SpinLock<NotifierChain<V, T>>);
impl<V: Clone + Copy, T> Default for AtomicNotifierChain<V, T> {
fn default() -> Self {
Self::new()
}
}
impl<V: Clone + Copy, T> AtomicNotifierChain<V, T> {
pub fn new() -> Self {
Self(SpinLock::new(NotifierChain::<V, T>::new()))

@ -91,8 +91,7 @@ impl PrintkWriter {
// tty已经初始化了之后才输出到屏幕
let port = TTY_PORTS[current_vcnum as usize].clone();
let tty = port.port_data().tty();
if tty.is_some() {
let tty = tty.unwrap();
if let Some(tty) = tty {
let _ = tty.write(tty.core(), s.as_bytes(), s.len());
} else {
let _ = textui_putstr(s, FontColor::WHITE, FontColor::BLACK);
@ -122,7 +121,7 @@ impl Logger {
pub fn log(&self, log_level: usize, message: fmt::Arguments) {
if unsafe { KMSG.is_some() } {
let timestamp: TimeSpec = TimeSpec::now();
let log_level = LogLevel::from(log_level.clone());
let log_level = LogLevel::from(log_level);
let log_message = LogMessage::new(timestamp, log_level, message.to_string());

@ -17,6 +17,7 @@ use core::fmt::{self, Debug};
use core::iter::{FromIterator, IntoIterator};
use core::marker;
use core::mem;
use core::mem::swap;
use core::ops::Index;
use core::ptr;
@ -63,7 +64,7 @@ struct NodePtr<K: Ord, V>(*mut RBTreeNode<K, V>);
impl<K: Ord, V> Clone for NodePtr<K, V> {
fn clone(&self) -> NodePtr<K, V> {
NodePtr(self.0)
*self
}
}
@ -77,7 +78,7 @@ impl<K: Ord, V> Ord for NodePtr<K, V> {
impl<K: Ord, V> PartialOrd for NodePtr<K, V> {
fn partial_cmp(&self, other: &NodePtr<K, V>) -> Option<Ordering> {
unsafe { Some((*self.0).key.cmp(&(*other.0).key)) }
Some(self.cmp(other))
}
}
@ -158,7 +159,7 @@ impl<K: Ord, V> NodePtr<K, V> {
#[inline]
fn min_node(self) -> NodePtr<K, V> {
let mut temp = self.clone();
let mut temp = self;
while !temp.left().is_null() {
temp = temp.left();
}
@ -167,7 +168,7 @@ impl<K: Ord, V> NodePtr<K, V> {
#[inline]
fn max_node(self) -> NodePtr<K, V> {
let mut temp = self.clone();
let mut temp = self;
while !temp.right().is_null() {
temp = temp.right();
}
@ -239,7 +240,7 @@ impl<K: Ord, V> NodePtr<K, V> {
if self.is_null() {
return NodePtr::null();
}
unsafe { (*self.0).parent.clone() }
unsafe { (*self.0).parent }
}
#[inline]
@ -247,7 +248,7 @@ impl<K: Ord, V> NodePtr<K, V> {
if self.is_null() {
return NodePtr::null();
}
unsafe { (*self.0).left.clone() }
unsafe { (*self.0).left }
}
#[inline]
@ -255,7 +256,7 @@ impl<K: Ord, V> NodePtr<K, V> {
if self.is_null() {
return NodePtr::null();
}
unsafe { (*self.0).right.clone() }
unsafe { (*self.0).right }
}
#[inline]
@ -378,6 +379,7 @@ where
/// This is a method to help us to get inner struct.
impl<K: Ord + Debug, V: Debug> RBTree<K, V> {
#[allow(clippy::only_used_in_recursion)]
fn tree_print(&self, node: NodePtr<K, V>, direction: i32) {
if node.is_null() {
return;
@ -882,20 +884,20 @@ impl<K: Ord, V> RBTree<K, V> {
node.set_right(temp.left());
if !temp.left().is_null() {
temp.left().set_parent(node.clone());
temp.left().set_parent(node);
}
temp.set_parent(node.parent());
if node == self.root {
self.root = temp.clone();
self.root = temp;
} else if node == node.parent().left() {
node.parent().set_left(temp.clone());
node.parent().set_left(temp);
} else {
node.parent().set_right(temp.clone());
node.parent().set_right(temp);
}
temp.set_left(node.clone());
node.set_parent(temp.clone());
temp.set_left(node);
node.set_parent(temp);
}
/*
@ -917,20 +919,20 @@ impl<K: Ord, V> RBTree<K, V> {
node.set_left(temp.right());
if !temp.right().is_null() {
temp.right().set_parent(node.clone());
temp.right().set_parent(node);
}
temp.set_parent(node.parent());
if node == self.root {
self.root = temp.clone();
self.root = temp;
} else if node == node.parent().right() {
node.parent().set_right(temp.clone());
node.parent().set_right(temp);
} else {
node.parent().set_left(temp.clone());
node.parent().set_left(temp);
}
temp.set_right(node.clone());
node.set_parent(temp.clone());
temp.set_right(node);
node.set_parent(temp);
}
/// replace value if key exist, if not exist insert it.
@ -983,9 +985,7 @@ impl<K: Ord, V> RBTree<K, V> {
// Case 2条件叔叔是黑色且当前节点是右孩子
if parent.right() == node {
self.left_rotate(parent);
let temp = parent;
parent = node;
node = temp;
swap(&mut parent, &mut node);
}
// Case 3条件叔叔是黑色且当前节点是左孩子。
@ -1006,9 +1006,7 @@ impl<K: Ord, V> RBTree<K, V> {
// Case 2条件叔叔是黑色且当前节点是右孩子
if parent.left() == node {
self.right_rotate(parent);
let temp = parent;
parent = node;
node = temp;
swap(&mut parent, &mut node);
}
// Case 3条件叔叔是黑色且当前节点是左孩子。
@ -1029,7 +1027,7 @@ impl<K: Ord, V> RBTree<K, V> {
while !x.is_null() {
y = x;
match node.cmp(&&mut x) {
match node.cmp(&x) {
Ordering::Less => {
x = x.left();
}
@ -1043,7 +1041,7 @@ impl<K: Ord, V> RBTree<K, V> {
if y.is_null() {
self.root = node;
} else {
match node.cmp(&&mut y) {
match node.cmp(&y) {
Ordering::Less => {
y.set_left(node);
}
@ -1190,6 +1188,7 @@ impl<K: Ord, V> RBTree<K, V> {
true
}
#[allow(clippy::only_used_in_recursion)]
#[inline]
fn clear_recurse(&mut self, current: NodePtr<K, V>) {
if !current.is_null() {
@ -1309,12 +1308,10 @@ impl<K: Ord, V> RBTree<K, V> {
let mut replace = node.right().min_node();
if node == self.root {
self.root = replace;
} else if node.parent().left() == node {
node.parent().set_left(replace);
} else {
if node.parent().left() == node {
node.parent().set_left(replace);
} else {
node.parent().set_right(replace);
}
node.parent().set_right(replace);
}
// child是"取代节点"的右孩子,也是需要"调整的节点"。
@ -1360,12 +1357,10 @@ impl<K: Ord, V> RBTree<K, V> {
if self.root == node {
self.root = child
} else if parent.left() == node {
parent.set_left(child);
} else {
if parent.left() == node {
parent.set_left(child);
} else {
parent.set_right(child);
}
parent.set_right(child);
}
if color == Color::Black {

@ -130,13 +130,12 @@ impl<T> RwLock<T> {
fn inner_try_read(&self) -> Option<RwLockReadGuard<T>> {
let reader_value = self.current_reader();
//得到自增后的reader_value, 包括了尝试获得READER守卫的进程
let value;
if reader_value.is_err() {
return None; //获取失败
let value = if let Ok(rv) = reader_value {
rv
} else {
value = reader_value.unwrap();
}
return None;
};
//判断有没有writer和upgrader
//注意, 若upgrader存在,已经存在的读者继续占有锁,但新读者不允许获得锁

@ -24,7 +24,7 @@ impl Semaphore {
if counter > 0 {
Ok(Self {
counter: AtomicI32::new(counter),
wait_queue: WaitQueue::INIT,
wait_queue: WaitQueue::default(),
})
} else {
return Err(SystemError::EOVERFLOW);

@ -71,8 +71,8 @@ impl<T> SpinLock<T> {
pub fn lock(&self) -> SpinLockGuard<T> {
loop {
let res = self.try_lock();
if res.is_ok() {
return res.unwrap();
if let Ok(res) = res {
return res;
}
spin_loop();
}

@ -1,6 +1,6 @@
#![allow(dead_code)]
use core::mem::size_of;
use core::mem::{size_of, size_of_val};
use alloc::vec::Vec;
use system_error::SystemError;
@ -19,7 +19,7 @@ pub struct VecCursor {
impl VecCursor {
/// @brief 新建一个游标
pub fn new(data: Vec<u8>) -> Self {
return Self { data: data, pos: 0 };
return Self { data, pos: 0 };
}
/// @brief 创建一个全0的cursor
@ -112,12 +112,12 @@ impl VecCursor {
///
/// @param buf 目标u16数组
pub fn read_u16_into(&mut self, buf: &mut [u16]) -> Result<(), SystemError> {
if self.pos + buf.len() * size_of::<u16>() > self.data.len() * size_of::<u16>() {
if self.pos + size_of_val(buf) > self.data.len() * size_of::<u16>() {
return Err(SystemError::E2BIG);
}
for i in 0..buf.len() {
buf[i] = self.read_u16()?;
for item in buf.iter_mut() {
*item = self.read_u16()?;
}
return Ok(());
@ -130,22 +130,15 @@ impl VecCursor {
/// @return Ok(新的游标位置) 调整成功,返回新的游标位置
/// @return Err(SystemError::EOVERFLOW) 调整失败,游标超出正确的范围。(失败时游标位置不变)
pub fn seek(&mut self, origin: SeekFrom) -> Result<usize, SystemError> {
let pos: i64;
match origin {
SeekFrom::SeekSet(offset) => {
pos = offset;
}
SeekFrom::SeekCurrent(offset) => {
pos = self.pos as i64 + offset;
}
SeekFrom::SeekEnd(offset) => {
// 请注意此处的offset应小于等于0否则肯定是不合法的
pos = self.data.len() as i64 + offset;
}
let pos = match origin {
SeekFrom::SeekSet(offset) => offset,
SeekFrom::SeekCurrent(offset) => self.pos as i64 + offset,
// 请注意此处的offset应小于等于0否则肯定是不合法的
SeekFrom::SeekEnd(offset) => self.data.len() as i64 + offset,
SeekFrom::Invalid => {
return Err(SystemError::EINVAL);
}
}
};
if pos < 0 || pos > self.data.len() as i64 {
return Err(SystemError::EOVERFLOW);
@ -219,7 +212,7 @@ impl VecCursor {
return Err(SystemError::E2BIG);
}
self.data[self.pos..self.pos + buf.len()].copy_from_slice(&buf[..]);
self.data[self.pos..self.pos + buf.len()].copy_from_slice(buf);
self.pos += buf.len();
return Ok(());

@ -27,7 +27,9 @@ pub struct WaitQueue(SpinLock<InnerWaitQueue>);
#[allow(dead_code)]
impl WaitQueue {
pub const INIT: WaitQueue = WaitQueue(SpinLock::new(InnerWaitQueue::INIT));
pub const fn default() -> Self {
WaitQueue(SpinLock::new(InnerWaitQueue::INIT))
}
/// @brief 让当前进程在等待队列上进行等待,并且,允许被信号打断
pub fn sleep(&self) {
@ -77,7 +79,7 @@ impl WaitQueue {
pub unsafe fn sleep_without_schedule(&self) {
before_sleep_check(1);
// 安全检查:确保当前处于中断禁止状态
assert!(CurrentIrqArch::is_irq_enabled() == false);
assert!(!CurrentIrqArch::is_irq_enabled());
let mut guard: SpinLockGuard<InnerWaitQueue> = self.0.lock();
ProcessManager::mark_sleep(true).unwrap_or_else(|e| {
panic!("sleep error: {:?}", e);
@ -89,7 +91,7 @@ impl WaitQueue {
pub unsafe fn sleep_without_schedule_uninterruptible(&self) {
before_sleep_check(1);
// 安全检查:确保当前处于中断禁止状态
assert!(CurrentIrqArch::is_irq_enabled() == false);
assert!(!CurrentIrqArch::is_irq_enabled());
let mut guard: SpinLockGuard<InnerWaitQueue> = self.0.lock();
ProcessManager::mark_sleep(false).unwrap_or_else(|e| {
panic!("sleep error: {:?}", e);