Fix workspace clippy usage

This commit is contained in:
Zhang Junyang
2024-02-28 00:44:55 +08:00
committed by Tate, Hongliang Tian
parent 7eac2772d0
commit f415585dff
19 changed files with 181 additions and 179 deletions

View File

@ -105,7 +105,7 @@ pub fn legacy32_rust_target_json() -> &'static str {
/// Interestingly, the resulting binary should be the same as the memory
/// dump of the kernel setup header when it's loaded by the bootloader.
fn to_flat_binary(elf_file: &[u8]) -> Vec<u8> {
let elf = xmas_elf::ElfFile::new(&elf_file).unwrap();
let elf = xmas_elf::ElfFile::new(elf_file).unwrap();
let mut bin = Vec::<u8>::new();
for program in elf.program_iter() {

View File

@ -166,6 +166,8 @@ bitflags::bitflags! {
}
// The `flags` field choices in the PE section header.
// We follow the Linux naming, thus ignoring the clippy name warnings.
#[allow(clippy::enum_variant_names)]
#[derive(Serialize, Clone, Copy)]
#[repr(u32)]
enum PeSectionHdrFlagsAlign {
@ -238,10 +240,10 @@ impl ImageSectionAddrInfo {
}
Self {
text: SetupVA::from(text_start.unwrap())..SetupVA::from(text_end.unwrap()),
data: SetupVA::from(data_start.unwrap())..SetupVA::from(data_end.unwrap()),
bss: SetupVA::from(bss_start.unwrap())..SetupVA::from(bss_end.unwrap()),
rodata: SetupVA::from(rodata_start.unwrap())..SetupVA::from(rodata_end.unwrap()),
text: text_start.unwrap()..text_end.unwrap(),
data: data_start.unwrap()..data_end.unwrap(),
bss: bss_start.unwrap()..bss_end.unwrap(),
rodata: rodata_start.unwrap()..rodata_end.unwrap(),
}
}
@ -351,90 +353,90 @@ pub(crate) fn make_pe_coff_header(setup_elf: &[u8], image_size: usize) -> ImageP
let addr_info = ImageSectionAddrInfo::from(&elf);
// PE section headers
let mut sec_hdrs = Vec::<PeSectionHdr>::new();
// .reloc
sec_hdrs.push(PeSectionHdr {
name: [b'.', b'r', b'e', b'l', b'o', b'c', 0, 0],
virtual_size: relocs.len() as u32,
virtual_address: usize::from(SetupVA::from(reloc_offset)) as u32,
raw_data_size: relocs.len() as u32,
data_addr: usize::from(reloc_offset) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_INITIALIZED_DATA
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_DISCARDABLE)
.bits
| PeSectionHdrFlagsAlign::_1Bytes as u32,
});
// .text
sec_hdrs.push(PeSectionHdr {
name: [b'.', b't', b'e', b'x', b't', 0, 0, 0],
virtual_size: addr_info.text_virt_size() as u32,
virtual_address: usize::from(addr_info.text.start) as u32,
raw_data_size: addr_info.text_file_size() as u32,
data_addr: usize::from(SetupFileOffset::from(addr_info.text.start)) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_CODE
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_EXECUTE)
.bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
});
// .data
sec_hdrs.push(PeSectionHdr {
name: [b'.', b'd', b'a', b't', b'a', 0, 0, 0],
virtual_size: addr_info.data_virt_size() as u32,
virtual_address: usize::from(addr_info.data.start) as u32,
raw_data_size: addr_info.data_file_size() as u32,
data_addr: usize::from(SetupFileOffset::from(addr_info.data.start)) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_INITIALIZED_DATA
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_WRITE)
.bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
});
// .bss
sec_hdrs.push(PeSectionHdr {
name: [b'.', b'b', b's', b's', 0, 0, 0, 0],
virtual_size: addr_info.bss_virt_size() as u32,
virtual_address: usize::from(addr_info.bss.start) as u32,
raw_data_size: 0,
data_addr: 0,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_UNINITIALIZED_DATA
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_WRITE)
.bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
});
// .rodata
sec_hdrs.push(PeSectionHdr {
name: [b'.', b'r', b'o', b'd', b'a', b't', b'a', 0],
virtual_size: addr_info.rodata_virt_size() as u32,
virtual_address: usize::from(addr_info.rodata.start) as u32,
raw_data_size: addr_info.rodata_file_size() as u32,
data_addr: usize::from(SetupFileOffset::from(addr_info.rodata.start)) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_INITIALIZED_DATA | PeSectionHdrFlags::MEM_READ).bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
});
let sec_hdrs = [
// .reloc
PeSectionHdr {
name: [b'.', b'r', b'e', b'l', b'o', b'c', 0, 0],
virtual_size: relocs.len() as u32,
virtual_address: usize::from(SetupVA::from(reloc_offset)) as u32,
raw_data_size: relocs.len() as u32,
data_addr: usize::from(reloc_offset) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_INITIALIZED_DATA
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_DISCARDABLE)
.bits
| PeSectionHdrFlagsAlign::_1Bytes as u32,
},
// .text
PeSectionHdr {
name: [b'.', b't', b'e', b'x', b't', 0, 0, 0],
virtual_size: addr_info.text_virt_size() as u32,
virtual_address: usize::from(addr_info.text.start) as u32,
raw_data_size: addr_info.text_file_size() as u32,
data_addr: usize::from(SetupFileOffset::from(addr_info.text.start)) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_CODE
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_EXECUTE)
.bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
},
// .data
PeSectionHdr {
name: [b'.', b'd', b'a', b't', b'a', 0, 0, 0],
virtual_size: addr_info.data_virt_size() as u32,
virtual_address: usize::from(addr_info.data.start) as u32,
raw_data_size: addr_info.data_file_size() as u32,
data_addr: usize::from(SetupFileOffset::from(addr_info.data.start)) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_INITIALIZED_DATA
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_WRITE)
.bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
},
// .bss
PeSectionHdr {
name: [b'.', b'b', b's', b's', 0, 0, 0, 0],
virtual_size: addr_info.bss_virt_size() as u32,
virtual_address: usize::from(addr_info.bss.start) as u32,
raw_data_size: 0,
data_addr: 0,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_UNINITIALIZED_DATA
| PeSectionHdrFlags::MEM_READ
| PeSectionHdrFlags::MEM_WRITE)
.bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
},
// .rodata
PeSectionHdr {
name: [b'.', b'r', b'o', b'd', b'a', b't', b'a', 0],
virtual_size: addr_info.rodata_virt_size() as u32,
virtual_address: usize::from(addr_info.rodata.start) as u32,
raw_data_size: addr_info.rodata_file_size() as u32,
data_addr: usize::from(SetupFileOffset::from(addr_info.rodata.start)) as u32,
relocs: 0,
line_numbers: 0,
num_relocs: 0,
num_lin_numbers: 0,
flags: (PeSectionHdrFlags::CNT_INITIALIZED_DATA | PeSectionHdrFlags::MEM_READ).bits
| PeSectionHdrFlagsAlign::_16Bytes as u32,
},
];
// Write the MS-DOS header
bin.extend_from_slice(&MZ_MAGIC.to_le_bytes());
// Write the MS-DOS stub at 0x3c

View File

@ -19,7 +19,7 @@ pub fn load_elf(file: &[u8]) {
}
fn load_segment(file: &xmas_elf::ElfFile, program: &xmas_elf::program::ProgramHeader64) {
let SegmentData::Undefined(header_data) = program.get_data(&file).unwrap() else {
let SegmentData::Undefined(header_data) = program.get_data(file).unwrap() else {
panic!("[setup] Unexpected segment data type!");
};
// Safety: the physical address from the ELF file is valid

View File

@ -40,5 +40,5 @@ fn get_payload(boot_params: &BootParams) -> &'static [u8] {
let payload_length = hdr.payload_length as usize;
// Safety: the payload_offset and payload_length is valid if we assume that the
// boot_params struct is correct.
unsafe { core::slice::from_raw_parts_mut(payload_offset as *mut u8, payload_length as usize) }
unsafe { core::slice::from_raw_parts_mut(payload_offset as *mut u8, payload_length) }
}

View File

@ -12,6 +12,10 @@ use super::{
relocation::apply_rela_dyn_relocations,
};
// Suppress warnings since using todo!.
#[allow(unreachable_code)]
#[allow(unused_variables)]
#[allow(clippy::diverging_sub_expression)]
#[export_name = "efi_stub_entry"]
extern "sysv64" fn efi_stub_entry(handle: Handle, mut system_table: SystemTable<Boot>) -> ! {
unsafe {
@ -19,13 +23,9 @@ extern "sysv64" fn efi_stub_entry(handle: Handle, mut system_table: SystemTable<
}
uefi_services::init(&mut system_table).unwrap();
// Suppress TODO warning.
#[allow(unreachable_code)]
efi_phase_boot(
handle,
system_table,
todo!("Use EFI boot services to fill boot params"),
);
let boot_params_ptr = todo!("Use EFI boot services to fill boot params");
efi_phase_boot(handle, system_table, boot_params_ptr);
}
#[export_name = "efi_handover_entry"]
@ -65,7 +65,7 @@ fn efi_phase_boot(
let Ok(loaded_image) = boot_services.open_protocol_exclusive::<LoadedImage>(handle) else {
panic!("Failed to open LoadedImage protocol");
};
loaded_image.data_type().clone()
loaded_image.data_type()
};
let (system_table, memory_map) = system_table.exit_boot_services(memory_type);
@ -115,8 +115,8 @@ fn efi_phase_runtime(
break;
}
e820_table[e820_entries] = linux_boot_params::BootE820Entry {
addr: md.phys_start as u64,
size: md.page_count as u64 * 4096,
addr: md.phys_start,
size: md.page_count * 4096,
typ: match md.ty {
uefi::table::boot::MemoryType::CONVENTIONAL => linux_boot_params::E820Type::Ram,
uefi::table::boot::MemoryType::RESERVED => linux_boot_params::E820Type::Reserved,

View File

@ -13,8 +13,8 @@ global_asm!(include_str!("setup.S"));
pub const ASTER_ENTRY_POINT: u32 = 0x8001200;
unsafe fn call_aster_entrypoint(entrypoint: u64, boot_params_ptr: u64) -> ! {
asm!("mov rsi, {}", in(reg) boot_params_ptr as u64);
asm!("mov rax, {}", in(reg) entrypoint as u64);
asm!("mov rsi, {}", in(reg) boot_params_ptr);
asm!("mov rax, {}", in(reg) entrypoint);
asm!("jmp rax");
unreachable!();

View File

@ -30,7 +30,7 @@ fn get_rela_array() -> &'static [Elf64Rela] {
end = in(reg) end,
start = in(reg) start,
);
len / core::mem::size_of::<Elf64Rela>() as usize
len / core::mem::size_of::<Elf64Rela>()
};
#[cfg(feature = "debug_print")]
unsafe {
@ -44,7 +44,7 @@ fn get_rela_array() -> &'static [Elf64Rela] {
print_str("\n");
}
// Safety: the linker will ensure that the symbols are valid.
unsafe { core::slice::from_raw_parts(start as *const Elf64Rela, len) }
unsafe { core::slice::from_raw_parts(start, len) }
}
const R_X86_64_RELATIVE: u32 = 8;

View File

@ -16,6 +16,7 @@ const START_OF_SETUP32_VA: usize = 0x100000;
/// The setup is a position-independent executable. We can get the loaded base
/// address from the symbol.
#[inline]
#[allow(clippy::fn_to_numeric_cast)]
pub fn get_image_loaded_offset() -> isize {
extern "C" {
fn start_of_setup32();