Skip to content

Commit 8665c59

Browse files
committed
Resolve remaining clippy warnings
1 parent 2c8a630 commit 8665c59

File tree

13 files changed

+47
-18
lines changed

13 files changed

+47
-18
lines changed

bios/boot_sector/src/main.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#![no_main]
33
#![warn(unsafe_op_in_unsafe_fn)]
44

5-
use core::{arch::global_asm, slice};
5+
use core::{
6+
arch::{asm, global_asm},
7+
slice,
8+
};
69
use fail::{print_char, UnwrapOrFail};
710

811
global_asm!(include_str!("boot.s"));
@@ -73,5 +76,7 @@ pub extern "C" fn first_stage(disk_number: u16) {
7376
print_char(b'R');
7477
}
7578

76-
loop {}
79+
loop {
80+
unsafe { asm!("hlt") }
81+
}
7782
}

bios/common/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ pub struct E820MemoryRegion {
6262
pub region_type: u32,
6363
pub acpi_extended_attributes: u32,
6464
}
65+
66+
pub fn hlt() {
67+
unsafe { core::arch::asm!("hlt") };
68+
}

bios/common/src/racy_cell.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ impl<T> RacyCell<T> {
77
Self(UnsafeCell::new(v))
88
}
99

10+
/// Gets a mutable pointer to the wrapped value.
11+
///
12+
/// ## Safety
13+
/// Ensure that the access is unique (no active references, mutable or not).
14+
#[allow(clippy::mut_from_ref)]
1015
pub unsafe fn get_mut(&self) -> &mut T {
1116
unsafe { &mut *self.0.get() }
1217
}

bios/stage-2/src/fat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Bpb {
2828
fat_size_16: u16,
2929
total_sectors_32: u32,
3030
fat_size_32: u32,
31-
root_cluster: u32,
31+
_root_cluster: u32,
3232
}
3333

3434
impl Bpb {
@@ -71,7 +71,7 @@ impl Bpb {
7171
fat_size_16,
7272
total_sectors_32,
7373
fat_size_32,
74-
root_cluster,
74+
_root_cluster: root_cluster,
7575
}
7676
}
7777

@@ -209,7 +209,7 @@ impl<D: Read + Seek> FileSystem<D> {
209209
) -> impl Iterator<Item = Result<RawDirectoryEntry, ()>> + 'a {
210210
match self.bpb.fat_type() {
211211
FatType::Fat32 => {
212-
self.bpb.root_cluster;
212+
// self.bpb.root_cluster;
213213
unimplemented!();
214214
}
215215
FatType::Fat12 | FatType::Fat16 => {

bios/stage-2/src/main.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
copy_to_protected_mode, enter_protected_mode_and_jump_to_stage_3, enter_unreal_mode,
88
},
99
};
10-
use bootloader_x86_64_bios_common::{BiosFramebufferInfo, BiosInfo, Region};
10+
use bootloader_x86_64_bios_common::{hlt, BiosFramebufferInfo, BiosInfo, Region};
1111
use byteorder::{ByteOrder, LittleEndian};
1212
use core::{fmt::Write as _, slice};
1313
use disk::AlignedArrayBuffer;
@@ -50,12 +50,12 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
5050

5151
let mut entries = [PartitionTableEntry::empty(); MAX_ENTRIES];
5252
let raw = unsafe { slice::from_raw_parts(partition_table_start, ENTRY_SIZE * MAX_ENTRIES) };
53-
for idx in 0..MAX_ENTRIES {
53+
for (idx, entry) in entries.iter_mut().enumerate() {
5454
let offset = idx * ENTRY_SIZE;
5555
let partition_type = PartitionType::from_mbr_tag_byte(raw[offset + 4]);
5656
let lba = LittleEndian::read_u32(&raw[offset + 8..]);
5757
let len = LittleEndian::read_u32(&raw[offset + 12..]);
58-
entries[idx] = PartitionTableEntry::new(partition_type, lba, len);
58+
*entry = PartitionTableEntry::new(partition_type, lba, len);
5959
}
6060
entries
6161
};
@@ -146,7 +146,9 @@ fn start(disk_number: u16, partition_table_start: *const u8) -> ! {
146146

147147
enter_protected_mode_and_jump_to_stage_3(STAGE_3_DST, &mut info);
148148

149-
loop {}
149+
loop {
150+
hlt();
151+
}
150152
}
151153

152154
fn load_file(

bios/stage-3/src/main.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![deny(unsafe_op_in_unsafe_fn)]
44

55
use crate::screen::Writer;
6-
use bootloader_x86_64_bios_common::BiosInfo;
6+
use bootloader_x86_64_bios_common::{hlt, BiosInfo};
77
use core::{arch::asm, fmt::Write as _};
88

99
mod gdt;
@@ -24,7 +24,9 @@ pub extern "C" fn _start(info: &mut BiosInfo) {
2424
gdt::LONG_MODE_GDT.load();
2525
enter_long_mode_and_jump_to_stage_4(info);
2626

27-
loop {}
27+
loop {
28+
hlt();
29+
}
2830
}
2931

3032
#[no_mangle]

bios/stage-4/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn detect_rsdp() -> Option<PhysAddr> {
227227
}
228228
}
229229

230-
#[cfg(all(not(test), target_os = "none"))]
230+
#[cfg(target_os = "none")]
231231
#[panic_handler]
232232
fn panic(info: &core::panic::PanicInfo) -> ! {
233233
unsafe {

common/src/legacy_memory_region.rs

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub trait LegacyMemoryRegion: Copy + core::fmt::Debug {
1111
fn start(&self) -> PhysAddr;
1212
/// Returns the size of the region in bytes.
1313
fn len(&self) -> u64;
14+
/// Returns whether this region is empty.
15+
fn is_empty(&self) -> bool {
16+
self.len() == 0
17+
}
1418
/// Returns the type of the region, e.g. whether it is usable or reserved.
1519
fn kind(&self) -> MemoryRegionKind;
1620

@@ -81,6 +85,11 @@ where
8185
self.original.len()
8286
}
8387

88+
/// Returns whether this memory map is empty.
89+
pub fn is_empty(&self) -> bool {
90+
self.len() == 0
91+
}
92+
8493
/// Returns the largest detected physical memory address.
8594
///
8695
/// Useful for creating a mapping for all physical memory.

common/src/logger.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn get_char_raster(c: char) -> RasterizedChar {
5151
font_constants::CHAR_RASTER_HEIGHT,
5252
)
5353
}
54-
get(c).unwrap_or(get(BACKUP_CHAR).expect("Should get raster of backup char."))
54+
get(c).unwrap_or_else(|| get(BACKUP_CHAR).expect("Should get raster of backup char."))
5555
}
5656

5757
impl LockedLogger {
@@ -62,6 +62,7 @@ impl LockedLogger {
6262

6363
/// Force-unlocks the logger to prevent a deadlock.
6464
///
65+
/// ## Safety
6566
/// This method is not memory safe and should be only used when absolutely necessary.
6667
pub unsafe fn force_unlock(&self) {
6768
unsafe { self.0.force_unlock() };

tests/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bootloader_test_runner::run_test_kernel;
55
#[test]
66
fn basic_boot() {
77
// build test kernel manually to force-enable link-time optimization
8-
let mut cmd = Command::new(std::env::var("CARGO").unwrap_or("cargo".into()));
8+
let mut cmd = Command::new(std::env::var("CARGO").unwrap_or_else(|_| "cargo".into()));
99
cmd.arg("build");
1010
cmd.arg("-p").arg("test_kernel_lto");
1111
cmd.arg("--target").arg("x86_64-unknown-none");

uefi/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn main_inner(image: Handle, mut st: SystemTable<Boot>) -> Status {
7474
)
7575
.unwrap();
7676

77-
let kernel = load_kernel(image, &mut st);
77+
let kernel = load_kernel(image, &st);
7878

7979
let framebuffer = init_logger(&st, kernel.config);
8080

@@ -428,7 +428,7 @@ fn init_logger(st: &SystemTable<Boot>, config: BootloaderConfig) -> Option<RawFr
428428
})
429429
}
430430

431-
#[cfg(all(not(test), target_os = "uefi"))]
431+
#[cfg(target_os = "uefi")]
432432
#[panic_handler]
433433
fn panic(info: &core::panic::PanicInfo) -> ! {
434434
use core::arch::asm;

uefi/src/memory_descriptor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub struct UefiMemoryDescriptor(pub MemoryDescriptor);
88

99
const PAGE_SIZE: u64 = 4096;
1010

11-
impl<'a> LegacyMemoryRegion for UefiMemoryDescriptor {
11+
impl LegacyMemoryRegion for UefiMemoryDescriptor {
1212
fn start(&self) -> PhysAddr {
1313
PhysAddr::new(self.0.phys_start)
1414
}

x86_64-stage-4.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
},
1818
"static-position-independent-executables": true,
1919
"target-pointer-width": "64",
20-
"relocation-model": "static"
20+
"relocation-model": "static",
21+
"os": "none"
2122
}

0 commit comments

Comments
 (0)