From 2e1ad6e1a4ef95bd521b5294a7bf7fd6de7bef77 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 21 May 2024 16:02:59 +0800 Subject: [PATCH] remove T:Copy bounds on bzero not quite sure why it is even there, might just be a thing from really old code we never removed. Removing this allows us to specify pointer types to non-copy elements, making Rust do the hard work of figuring out how big of a block we need to zero. --- loader/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/loader/src/main.rs b/loader/src/main.rs index 6dce704e5..88142999a 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -215,15 +215,17 @@ fn boot_sequence(args: KernelArguments, _signature: u32, fs_prehash: [u8; 64]) - let krn_struct_start = cfg.sram_start as usize + cfg.sram_size - cfg.init_size + cfg.swap_offset; #[cfg(feature = "swap")] if SDBG && VDBG { + const CHUNK_SIZE: usize = 2; // activate to debug stack smashes. RPT should be 0's here (or at least valid PIDs) if stack did // not overflow. - for (_i, _r) in - cfg.runtime_page_tracker[cfg.runtime_page_tracker.len() - 1024..].chunks(32).enumerate() + for (_i, _r) in cfg.runtime_page_tracker[cfg.runtime_page_tracker.len() - 512..] + .chunks(CHUNK_SIZE) + .enumerate() { - println!(" rpt {:08x}: {:02x?}", cfg.runtime_page_tracker.len() - 1024 + _i * 32, _r); + println!(" rpt {:08x}: {:02x?}", cfg.runtime_page_tracker.len() - 512 + _i * CHUNK_SIZE, _r); } } - // Add a static check for stack overflow, using a heuristic that the last 64 bytes of the RPT + // Add a static check for stack overflow, using a heuristic that the last 64 entries of the RPT // ought to be a valid PID. A stack smash is likely to write something that does not obey // this heuristic within that range (any stack-stored pointer, for example, will break this). for &check in cfg.runtime_page_tracker[cfg.runtime_page_tracker.len() - 64..].iter() { @@ -518,15 +520,13 @@ fn clear_ram(cfg: &mut BootConfig) { } } -pub unsafe fn bzero(mut sbss: *mut T, ebss: *mut T) -where - T: Copy, -{ +pub unsafe fn bzero(mut sbss: *mut T, ebss: *mut T) { if VDBG { println!("ZERO: {:08x} - {:08x}", sbss as usize, ebss as usize); } while sbss < ebss { // NOTE(volatile) to prevent this from being transformed into `memclr` + // which can create an accidental dependency on libc. ptr::write_volatile(sbss, mem::zeroed()); sbss = sbss.offset(1); }