Skip to content

Commit

Permalink
修复由于升级工具链导致的x86下的warning
Browse files Browse the repository at this point in the history
  • Loading branch information
fslongjin committed Dec 6, 2023
1 parent 193adc2 commit ad7d365
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 58 deletions.
9 changes: 3 additions & 6 deletions kernel/src/arch/x86_64/driver/hpet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Hpet {
let tm_num = hpet.timers_num();
kinfo!("HPET has {} timers", tm_num);
hpet_info.hpet_number = tm_num as u8;
drop(hpet);

drop(mmio);
if tm_num == 0 {
return Err(SystemError::ENODEV);
Expand Down Expand Up @@ -118,7 +118,6 @@ impl Hpet {

unsafe { regs.write_main_counter_value(0) };

drop(regs);
drop(inner_guard);

let (inner_guard, timer_reg) = unsafe { self.timer_mut(0).ok_or(SystemError::ENODEV) }?;
Expand All @@ -130,7 +129,6 @@ impl Hpet {
volwrite!(timer_reg, config, 0x004c);
volwrite!(timer_reg, comparator_value, ticks);
}
drop(timer_reg);
drop(inner_guard);

// todo!("register irq in C");
Expand All @@ -142,7 +140,6 @@ impl Hpet {
// 置位旧设备中断路由兼容标志位、定时器组使能标志位
unsafe { regs.write_general_config(3) };

drop(regs);
drop(inner_guard);

kinfo!("HPET enabled");
Expand Down Expand Up @@ -208,7 +205,7 @@ impl Hpet {
pub fn main_counter_value(&self) -> u64 {
let (inner_guard, regs) = unsafe { self.hpet_regs() };
let value = regs.main_counter_value();
drop(regs);

drop(inner_guard);
return value;
}
Expand All @@ -217,7 +214,7 @@ impl Hpet {
let (inner_guard, regs) = unsafe { self.hpet_regs() };
let period = regs.counter_clock_period();
kdebug!("HPET period: {}", period);
drop(regs);

drop(inner_guard);
return period;
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/driver/base/kset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl KSet {
#[allow(dead_code)]
pub fn cleanup_weak(&self) {
let mut kobjects = self.kobjects.write();
kobjects.extract_if(|x| x.upgrade().is_none());
kobjects.retain(|x| x.upgrade().is_some());
}

pub fn as_kobject(&self) -> Arc<dyn KObject> {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/driver/tty/serial/serial8250/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl Driver for Serial8250ISADriver {
fn delete_device(&self, device: &Arc<dyn Device>) {
let mut inner = self.inner.write();

inner.devices.extract_if(|d| Arc::ptr_eq(d, device));
inner.devices.retain(|d| !Arc::ptr_eq(d, device));
}

fn bus(&self) -> Option<Arc<dyn Bus>> {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/exception/softirq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Softirq {
/// @param irq_num 中断向量号码
pub fn unregister_softirq(&self, softirq_num: SoftirqNumber) {
// kdebug!("unregister_softirq softirq_num = {:?}", softirq_num as u64);
let table_guard = &mut self.table.write();
let mut table_guard = self.table.write();
// 将软中断向量清空
table_guard[softirq_num as usize] = None;
drop(table_guard);
Expand Down
1 change: 0 additions & 1 deletion kernel/src/filesystem/fat/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ impl FATDir {
// todo: 设置创建、访问时间
dot_entry.flush(&fs, fs.cluster_bytes_offset(first_cluster) + offset)?;

drop(dot_entry);
// 偏移量加上一个目录项的长度
offset += FATRawDirEntry::DIR_ENTRY_LEN;

Expand Down
15 changes: 5 additions & 10 deletions kernel/src/filesystem/procfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ impl ProcFSInode {
/// @brief 去除Vec中所有的\0,并在结尾添加\0
#[inline]
fn trim_string(&self, data: &mut Vec<u8>) {
data.extract_if(|x: &mut u8| *x == 0);
data.retain(|x| *x != 0);

data.push(0);
}
// todo:其他数据获取函数实现
Expand Down Expand Up @@ -420,15 +421,9 @@ impl IndexNode for LockedProcFSInode {
if let FileType::Dir = guard.metadata.file_type {
return Ok(());
}
// 获取数据信息
let private_data = match data {
FilePrivateData::Procfs(p) => p,
_ => {
panic!("ProcFS: FilePrivateData mismatch!");
}
};
// 释放资源
drop(private_data);
// 释放data
*data = FilePrivateData::Procfs(ProcfsFilePrivateData::new());

return Ok(());
}

Expand Down
13 changes: 2 additions & 11 deletions kernel/src/ipc/signal_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,17 +423,8 @@ impl SigPending {
/// @brief 从sigpending中删除mask中被置位的信号。也就是说,比如mask的第1位被置为1,那么就从sigqueue中删除所有signum为2的信号的信息。
pub fn flush_by_mask(&mut self, mask: &SigSet) {
// 定义过滤器,从sigqueue中删除mask中被置位的信号
let filter = |x: &mut SigInfo| {
if mask.contains(SigSet::from_bits_truncate(x.sig_no as u64)) {
return true;
}
return false;
};
let filter_result: Vec<SigInfo> = self.queue.q.extract_if(filter).collect();
// 回收这些siginfo
for x in filter_result {
drop(x)
}
let filter = |x: &SigInfo| !mask.contains(SigSet::from_bits_truncate(x.sig_no as u64));
self.queue.q.retain(filter);
}
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/ipc/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Syscall {
) -> Result<usize, SystemError> {
// 请注意:用户态传进来的user_sigaction结构体类型,请注意,这个结构体与内核实际的不一样
let act: *mut UserSigaction = new_act as *mut UserSigaction;
let mut old_act = old_act as *mut UserSigaction;
let old_act = old_act as *mut UserSigaction;
let mut new_ka: Sigaction = Default::default();
let mut old_sigaction: Sigaction = Default::default();
// 如果传入的,新的sigaction不为空
Expand Down
2 changes: 0 additions & 2 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
#![feature(const_trait_impl)]
#![feature(const_refs_to_cell)]
#![feature(core_intrinsics)]
#![feature(cstr_from_bytes_until_nul)]
#![feature(c_void_variant)]
#![feature(extract_if)]
#![feature(inline_const)]
#![feature(is_some_and)]
#![feature(naked_functions)]
#![feature(panic_info_message)]
#![feature(ptr_internals)]
Expand Down
4 changes: 0 additions & 4 deletions kernel/src/libs/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,6 @@ impl BinaryLoader for ElfLoader {
return Err(ExecError::InvalidParemeter);
}

drop(p_vaddr);

// end vaddr of this segment(code+data+bss)
let seg_end_vaddr_f = self.elf_page_align_up(VirtAddr::new(
(seg_to_load.p_vaddr + seg_to_load.p_filesz) as usize,
Expand All @@ -683,8 +681,6 @@ impl BinaryLoader for ElfLoader {
end_data = Some(seg_end_vaddr_f);
}

drop(seg_end_vaddr_f);

let seg_end_vaddr = VirtAddr::new((seg_to_load.p_vaddr + seg_to_load.p_memsz) as usize);

if seg_end_vaddr > elf_brk {
Expand Down
7 changes: 3 additions & 4 deletions kernel/src/libs/futex/futex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ impl FutexHashBucket {

/// 将FutexObj从bucket中删除
pub fn remove(&mut self, futex: Arc<FutexObj>) {
self.chain.extract_if(|x| Arc::ptr_eq(x, &futex));
self.chain
.extract_if(|x| Arc::ptr_eq(x, &futex))
.for_each(drop);
}
}

Expand Down Expand Up @@ -284,7 +286,6 @@ impl Futex {
kwarn!("error:{e:?}");
e
})?;
drop(bucket_mut);
drop(futex_map_guard);
drop(irq_guard);
sched();
Expand Down Expand Up @@ -368,7 +369,6 @@ impl Futex {
// 从队列中唤醒
let count = bucket_mut.wake_up(key.clone(), Some(bitset), nr_wake)?;

drop(bucket_mut);
drop(binding);

FutexData::try_remove(&key);
Expand Down Expand Up @@ -427,7 +427,6 @@ impl Futex {
// 唤醒nr_wake个进程
let bucket_1_mut = futex_data_guard.get_mut(&key1).ok_or(SystemError::EINVAL)?;
let ret = bucket_1_mut.wake_up(key1.clone(), None, nr_wake as u32)?;
drop(bucket_1_mut);
// 将bucket1中最多nr_requeue个任务转移到bucket2
for _ in 0..nr_requeue {
let bucket_1_mut = futex_data_guard.get_mut(&key1).ok_or(SystemError::EINVAL)?;
Expand Down
13 changes: 0 additions & 13 deletions kernel/src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ impl Socket for RawSocket {
}
}
}
drop(socket);
drop(socket_set_guard);
SOCKET_WAITQUEUE.sleep();
}
Expand Down Expand Up @@ -371,8 +370,6 @@ impl Socket for RawSocket {
// 发送数据包
socket.send_slice(&buffer).unwrap();

drop(socket);

iface.poll(&mut socket_set_guard).ok();

drop(socket_set_guard);
Expand Down Expand Up @@ -489,7 +486,6 @@ impl Socket for UdpSocket {

if socket.can_recv() {
if let Ok((size, remote_endpoint)) = socket.recv_slice(buf) {
drop(socket);
drop(socket_set_guard);
poll_ifaces();
return (Ok(size), Endpoint::Ip(Some(remote_endpoint)));
Expand All @@ -498,7 +494,6 @@ impl Socket for UdpSocket {
// 如果socket没有连接,则忙等
// return (Err(SystemError::ENOTCONN), Endpoint::Ip(None));
}
drop(socket);
drop(socket_set_guard);
SOCKET_WAITQUEUE.sleep();
}
Expand Down Expand Up @@ -545,7 +540,6 @@ impl Socket for UdpSocket {
match socket.send_slice(&buf, *remote_endpoint) {
Ok(()) => {
// kdebug!("udp write: send ok");
drop(socket);
drop(socket_set_guard);
poll_ifaces();
return Ok(buf.len());
Expand Down Expand Up @@ -731,7 +725,6 @@ impl Socket for TcpSocket {
return (Err(SystemError::ENOTCONN), Endpoint::Ip(None));
};

drop(socket);
drop(socket_set_guard);
poll_ifaces();
return (Ok(size), Endpoint::Ip(Some(endpoint)));
Expand All @@ -751,7 +744,6 @@ impl Socket for TcpSocket {
} else {
return (Err(SystemError::ENOTCONN), Endpoint::Ip(None));
}
drop(socket);
drop(socket_set_guard);
SOCKET_WAITQUEUE.sleep();
}
Expand All @@ -765,7 +757,6 @@ impl Socket for TcpSocket {
if socket.can_send() {
match socket.send_slice(buf) {
Ok(size) => {
drop(socket);
drop(socket_set_guard);
poll_ifaces();
return Ok(size);
Expand Down Expand Up @@ -825,7 +816,6 @@ impl Socket for TcpSocket {
// avoid deadlock
drop(inner_iface);
drop(iface);
drop(socket);
drop(sockets);
loop {
poll_ifaces();
Expand All @@ -837,7 +827,6 @@ impl Socket for TcpSocket {
return Ok(());
}
tcp::State::SynSent => {
drop(socket);
drop(sockets);
SOCKET_WAITQUEUE.sleep();
}
Expand Down Expand Up @@ -916,7 +905,6 @@ impl Socket for TcpSocket {
if socket.is_active() {
// kdebug!("tcp accept: socket.is_active()");
let remote_ep = socket.remote_endpoint().ok_or(SystemError::ENOTCONN)?;
drop(socket);

let new_socket = {
// Initialize the TCP socket's buffers.
Expand Down Expand Up @@ -965,7 +953,6 @@ impl Socket for TcpSocket {

return Ok((new_socket, Endpoint::Ip(Some(remote_ep))));
}
drop(socket);
drop(sockets);
SOCKET_WAITQUEUE.sleep();
}
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ impl Drop for ProcessControlBlock {
.unwrap_or_else(|e| panic!("procfs_unregister_pid failed: error: {e:?}"));

if let Some(ppcb) = self.parent_pcb.read().upgrade() {
ppcb.children.write().extract_if(|pid| *pid == self.pid());
ppcb.children.write().retain(|pid| *pid != self.pid());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/time/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Timer {
/// @brief 将定时器插入到定时器链表中
pub fn activate(&self) {
let inner_guard = self.0.lock();
let timer_list = &mut TIMER_LIST.lock();
let mut timer_list = TIMER_LIST.lock();

// 链表为空,则直接插入
if timer_list.is_empty() {
Expand Down Expand Up @@ -133,7 +133,8 @@ impl Timer {
pub fn cancel(&self) -> bool {
TIMER_LIST
.lock()
.extract_if(|x| Arc::<Timer>::as_ptr(&x) == self as *const Timer);
.extract_if(|x| Arc::<Timer>::as_ptr(&x) == self as *const Timer)
.for_each(|p| drop(p));
true
}
}
Expand Down

0 comments on commit ad7d365

Please sign in to comment.