diff --git a/cykusz-rs/src/arch/x86_64/acpi/rsdp.rs b/cykusz-rs/src/arch/x86_64/acpi/rsdp.rs index 692a5c95..2dfd8102 100644 --- a/cykusz-rs/src/arch/x86_64/acpi/rsdp.rs +++ b/cykusz-rs/src/arch/x86_64/acpi/rsdp.rs @@ -12,6 +12,7 @@ pub enum Address { trait Header { fn signature(&'static self) -> &'static [u8; 8]; fn rsdt_address(&'static self) -> MappedAddr; + #[allow(dead_code)] fn revision(&'static self) -> u8; } diff --git a/cykusz-rs/src/arch/x86_64/gdt.rs b/cykusz-rs/src/arch/x86_64/gdt.rs index 013c5501..a86fe4da 100644 --- a/cykusz-rs/src/arch/x86_64/gdt.rs +++ b/cykusz-rs/src/arch/x86_64/gdt.rs @@ -1,3 +1,4 @@ +use core::ptr::addr_of; use crate::arch::raw::descriptor as dsc; use crate::arch::raw::gdt; use crate::arch::raw::segmentation as sgm; @@ -61,7 +62,7 @@ pub const fn ring3_ds() -> sgm::SegmentSelector { pub fn early_init() { unsafe { INIT_GDTR.init(&INIT_GDT[..]); - dsc::lgdt(&INIT_GDTR); + dsc::lgdt(addr_of!(INIT_GDTR)); sgm::set_cs(ring0_cs()); sgm::load_ds(ring0_ds()); @@ -87,19 +88,19 @@ fn init_tss(stack_top: VirtAddr, fs_base: u64) { let gdt_low = &mut GDT[5]; //logln!("here {:p}", gdt_low as *mut _); - gdt_low.set_offset(&TSS as *const _ as u32); + gdt_low.set_offset(addr_of!(TSS) as u32); gdt_low.set_limit(::core::mem::size_of::() as u32); } { let gdt_high = &mut GDT[6]; - gdt_high.set_raw((&TSS as *const _ as u64) >> 32); + gdt_high.set_raw((addr_of!(TSS) as u64) >> 32); } dsc::load_tr(&sgm::SegmentSelector::from_raw(5 << 3)); use crate::arch::raw::msr; - msr::wrmsr(msr::IA32_KERNEL_GS_BASE, &TSS as *const _ as u64); + msr::wrmsr(msr::IA32_KERNEL_GS_BASE, addr_of!(TSS) as u64); } } @@ -107,7 +108,7 @@ fn init_tss(stack_top: VirtAddr, fs_base: u64) { pub fn init(stack_top: VirtAddr, fs_base: u64) { unsafe { GDTR.init(&GDT[..]); - dsc::lgdt(&GDTR); + dsc::lgdt(addr_of!(GDTR)); sgm::set_cs(ring0_cs()); sgm::load_ds(ring0_ds()); diff --git a/cykusz-rs/src/arch/x86_64/mm/virt/table.rs b/cykusz-rs/src/arch/x86_64/mm/virt/table.rs index c4ca559a..86b7195b 100644 --- a/cykusz-rs/src/arch/x86_64/mm/virt/table.rs +++ b/cykusz-rs/src/arch/x86_64/mm/virt/table.rs @@ -2,8 +2,6 @@ use core::marker::PhantomData; use crate::arch::mm::virt::entry::Entry; use crate::arch::x86_64::mm::phys::PhysPage; -use crate::kernel::mm::virt; -use crate::kernel::mm::Frame; use crate::kernel::mm::*; use crate::kernel::sync::SpinGuard; diff --git a/cykusz-rs/src/arch/x86_64/output/mod.rs b/cykusz-rs/src/arch/x86_64/output/mod.rs index eb23d060..d3838d82 100644 --- a/cykusz-rs/src/arch/x86_64/output/mod.rs +++ b/cykusz-rs/src/arch/x86_64/output/mod.rs @@ -238,7 +238,7 @@ macro_rules! logln { #[allow(unused)] macro_rules! log { ($($arg:tt)*) => ({ - crate::arch::output::log_fmt_disabled(format_args!($($arg)*)).unwrap(); + crate::arch::output::log_fmt(format_args!($($arg)*)).unwrap(); }); } #[macro_export] diff --git a/cykusz-rs/src/arch/x86_64/raw/descriptor.rs b/cykusz-rs/src/arch/x86_64/raw/descriptor.rs index 0a1008fc..4b927efc 100644 --- a/cykusz-rs/src/arch/x86_64/raw/descriptor.rs +++ b/cykusz-rs/src/arch/x86_64/raw/descriptor.rs @@ -102,7 +102,7 @@ pub unsafe fn lidt(idt: &DescriptorTablePointer) { asm!("lidt [{0}]", in(reg) idt); } -pub unsafe fn lgdt(gdt: &DescriptorTablePointer) { +pub unsafe fn lgdt(gdt: *const DescriptorTablePointer) { asm!("lgdt [{0}]", in(reg) gdt); } diff --git a/cykusz-rs/src/drivers/multiboot2/mod.rs b/cykusz-rs/src/drivers/multiboot2/mod.rs index 44720d5d..899c15aa 100644 --- a/cykusz-rs/src/drivers/multiboot2/mod.rs +++ b/cykusz-rs/src/drivers/multiboot2/mod.rs @@ -1,3 +1,5 @@ +use core::ptr::addr_of; +use crate::drivers::multiboot2::framebuffer_info::FramebufferInfo; use crate::kernel::mm::{MappedAddr, PhysAddr, VirtAddr}; pub use self::tags::*; @@ -76,7 +78,7 @@ impl Info { pub fn framebuffer_info_tag(&self) -> Option<&'static tags::framebuffer_info::FramebufferInfo> { self.tags().find(|t| t.typ == 8).map(|t| unsafe { - &*(t as *const tags::Tag as *const tags::framebuffer_info::FramebufferInfo) + VirtAddr(addr_of!(*t) as usize).read_ref::() }) } diff --git a/cykusz-rs/src/drivers/multiboot2/tags/framebuffer_info.rs b/cykusz-rs/src/drivers/multiboot2/tags/framebuffer_info.rs index f3e63ae0..97370425 100644 --- a/cykusz-rs/src/drivers/multiboot2/tags/framebuffer_info.rs +++ b/cykusz-rs/src/drivers/multiboot2/tags/framebuffer_info.rs @@ -1,4 +1,6 @@ +use core::ptr::addr_of; use crate::drivers::multiboot2::Tag; +use crate::kernel::mm::VirtAddr; #[repr(C)] #[derive(Debug)] @@ -84,6 +86,6 @@ impl FramebufferInfo { } pub fn framebuffer_type(&self) -> &'static FramebufferType { - unsafe { &*(&self.color_info as *const u8 as *const FramebufferType) } + unsafe { VirtAddr(addr_of!(self.color_info) as usize).read_ref::() } } } diff --git a/cykusz-rs/src/drivers/net/e1000/device.rs b/cykusz-rs/src/drivers/net/e1000/device.rs index 008aa063..ae6ce55c 100644 --- a/cykusz-rs/src/drivers/net/e1000/device.rs +++ b/cykusz-rs/src/drivers/net/e1000/device.rs @@ -1,12 +1,9 @@ -use alloc::vec::Vec; use bit_field::BitField; -use crate::drivers::net::e1000::addr::Addr; -use crate::drivers::net::e1000::regs::Regs; -use crate::drivers::pci::{PciData, PciHeader, PciHeader0}; +use crate::drivers::pci::{PciData, PciHeader0}; use crate::kernel::mm::allocate_order; use crate::kernel::mm::heap::{allocate_align, deallocate_align}; -use crate::kernel::mm::{MappedAddr, PhysAddr, VirtAddr}; +use crate::kernel::mm::{PhysAddr, VirtAddr}; use crate::kernel::net::PacketBaseTrait; use crate::kernel::timer::busy_sleep; diff --git a/cykusz-rs/src/drivers/random.rs b/cykusz-rs/src/drivers/random.rs index 155f2de7..c71ded6e 100644 --- a/cykusz-rs/src/drivers/random.rs +++ b/cykusz-rs/src/drivers/random.rs @@ -5,7 +5,6 @@ use alloc::sync::{Arc, Weak}; use crate::kernel::sync::Spin; use crate::kernel::timer::current_ns; -use rand; use rand::{RngCore, SeedableRng}; struct Random { diff --git a/cykusz-rs/src/kernel/mm/heap.rs b/cykusz-rs/src/kernel/mm/heap.rs index d005cdea..bf969071 100644 --- a/cykusz-rs/src/kernel/mm/heap.rs +++ b/cykusz-rs/src/kernel/mm/heap.rs @@ -7,8 +7,6 @@ use linked_list_allocator::Heap; use spin::Once; use crate::arch::mm::heap::{HEAP_END, HEAP_SIZE, HEAP_START}; -use crate::kernel::mm::map; -use crate::kernel::mm::PAGE_SIZE; use crate::kernel::mm::*; use crate::kernel::sync::Spin; use crate::kernel::utils::types::Align; diff --git a/cykusz-rs/src/kernel/syscall/sys.rs b/cykusz-rs/src/kernel/syscall/sys.rs index 1a5c03eb..a02fe11e 100644 --- a/cykusz-rs/src/kernel/syscall/sys.rs +++ b/cykusz-rs/src/kernel/syscall/sys.rs @@ -591,7 +591,7 @@ pub fn sys_link( ) }; - if Weak::as_ptr(&inode.fs().unwrap()) != Weak::as_ptr(&target_entry.inode().fs().unwrap()) { + if !Weak::ptr_eq(&inode.fs().unwrap(), &target_entry.inode().fs().unwrap()) { return Err(SyscallError::EINVAL); } @@ -677,7 +677,7 @@ pub fn sys_rename( ) }; - if new.inode().fs().unwrap().as_ptr() != old.inode().fs().unwrap().as_ptr() { + if !Weak::ptr_eq(&new.inode().fs().unwrap(), &old.inode().fs().unwrap()) { return Err(SyscallError::EACCES); } diff --git a/cykusz-rs/src/lib.rs b/cykusz-rs/src/lib.rs index e0f3c3d5..13076bf6 100644 --- a/cykusz-rs/src/lib.rs +++ b/cykusz-rs/src/lib.rs @@ -1,7 +1,6 @@ #![no_std] #![allow(internal_features)] #![feature(alloc_error_handler)] -#![feature(array_methods)] #![feature(asm_const)] #![feature(auto_traits)] #![feature(c_variadic)] diff --git a/syscall-defs/src/lib.rs b/syscall-defs/src/lib.rs index 26cc4f75..59625d9d 100644 --- a/syscall-defs/src/lib.rs +++ b/syscall-defs/src/lib.rs @@ -6,9 +6,6 @@ extern crate alloc; #[macro_use] extern crate bitflags; - -use core::convert::TryFrom; - pub mod events; pub mod exec; pub mod ioctl; diff --git a/syscall-defs/src/resource.rs b/syscall-defs/src/resource.rs index 22efe2de..6f82ea4c 100644 --- a/syscall-defs/src/resource.rs +++ b/syscall-defs/src/resource.rs @@ -1,6 +1,4 @@ use crate::SyscallError; -use core::convert::TryFrom; - pub enum RLimitKind { Core = 1, Cpu = 2, diff --git a/user-alloc/src/types.rs b/user-alloc/src/types.rs index 63938a36..f4af7c23 100644 --- a/user-alloc/src/types.rs +++ b/user-alloc/src/types.rs @@ -5,6 +5,7 @@ pub trait Align { } pub trait CeilDiv { + #[allow(dead_code)] fn ceil_div(self, d: Self) -> Self; } diff --git a/userspace/src/bin/shell/main.rs b/userspace/src/bin/shell/main.rs index cc0edd0c..416acf05 100644 --- a/userspace/src/bin/shell/main.rs +++ b/userspace/src/bin/shell/main.rs @@ -10,6 +10,7 @@ extern crate syscall_user as syscall; use alloc::string::String; use alloc::vec::Vec; +use core::ptr::{addr_of, addr_of_mut}; use chrono::{Datelike, Timelike}; use syscall::bochs; @@ -45,7 +46,7 @@ fn ls(path: &str) { let struct_len = core::mem::size_of::(); loop { - let dentry = unsafe { &*(buf.as_ptr().offset(offset) as *const SysDirEntry) }; + let dentry = unsafe { &*(addr_of!(buf).offset(offset) as *const SysDirEntry) }; let namebytes = unsafe { core::slice::from_raw_parts( dentry.name.as_ptr(), @@ -736,12 +737,12 @@ static mut READY: bool = false; fn set_ready(r: bool) { unsafe { - (&mut READY as *mut bool).write_volatile(r); + addr_of_mut!(READY).write_volatile(r); } } fn ready() -> bool { - unsafe { (&READY as *const bool).read_volatile() } + unsafe { addr_of!(READY).read_volatile() } } fn signal_test() { @@ -836,7 +837,9 @@ fn main_old() -> ! { print!("[root {}]# ", make_str(&pwd[0..pwd_r])); // Read some data from stdin - let r = syscall::read(1, &mut buf).unwrap(); + let r = syscall::read(1, &mut unsafe { + *addr_of_mut!(buf) + }).unwrap(); { // Write data from stdin into the file diff --git a/userspace/src/bin/shell/nc.rs b/userspace/src/bin/shell/nc.rs index 86a011a5..dea19a9f 100644 --- a/userspace/src/bin/shell/nc.rs +++ b/userspace/src/bin/shell/nc.rs @@ -1,3 +1,4 @@ +use core::ptr::addr_of_mut; use syscall_defs::net::{SockAddr, SockAddrIn, SockDomain, SockType, SockTypeFlags}; use syscall_defs::poll::FdSet; @@ -23,7 +24,7 @@ static mut RECV_BUF: [u8; 2 * 4096] = [0u8; 2 * 4096]; static mut SENT: usize = 0; fn recv(fd: usize) -> bool { - let res = unsafe { syscall::read(fd, &mut RECV_BUF) }; + let res = unsafe { syscall::read(fd, &mut *addr_of_mut!(RECV_BUF)) }; match res { Ok(len) if len > 1 => {