From 66a5243f18a8572e9c27005824716148e8255c4a Mon Sep 17 00:00:00 2001 From: vasilito Date: Sun, 12 Jul 2026 05:17:55 +0300 Subject: [PATCH] diag: remove all diagnostic serial canary chars and info! debug logging Removes serial canary characters (R,S,1-7) from start.rs, per-syscall logging from syscall/fs.rs (sys_write/openat), per-fd-operation logging from context/context.rs (FdTbl/Context::remove_file), bootstrap step logging from syscall/process.rs (usermode_bootstrap), AwaitingFiletableChange FD dump and AS:MMAP logging from scheme/proc.rs, and context switch logging from startup/mod.rs. Only 'RedBear OS starting...' boot message retained. --- src/arch/x86_shared/start.rs | 37 --------------------------------- src/context/context.rs | 7 ------- src/scheme/proc.rs | 35 +------------------------------ src/startup/mod.rs | 13 ------------ src/syscall/fs.rs | 40 +++--------------------------------- src/syscall/process.rs | 15 ++------------ 6 files changed, 6 insertions(+), 141 deletions(-) diff --git a/src/arch/x86_shared/start.rs b/src/arch/x86_shared/start.rs index b408420054..133ef4c845 100644 --- a/src/arch/x86_shared/start.rs +++ b/src/arch/x86_shared/start.rs @@ -84,15 +84,6 @@ extern "C" fn kstart() { /// The entry to Rust, all things must be initialized unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { unsafe { - // EARLY CANARY: write 'R' to COM1 before any kernel init. - // This proves the serial hardware works and the kernel reached Rust entry. - // If this character appears but "Redox OS starting..." does not, - // the hang is in args_ptr.read(), serial::init(), or graphical_debug::init(). - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { - core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'R', options(nostack, preserves_flags)); - } - let bootstrap = { let args = args_ptr.read(); @@ -102,31 +93,15 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { // Set up graphical debug graphical_debug::init(args.env()); - // SECOND CANARY: write 'S' to COM1 after serial init. - // If 'R' appears but 'S' does not, the hang is in serial::init() or graphical_debug::init(). - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { - core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'S', options(nostack, preserves_flags)); - } - info!("RedBear OS starting..."); args.print(); - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'1', options(nostack, preserves_flags)); } - // Set up GDT gdt::init_bsp(stack_end); - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'2', options(nostack, preserves_flags)); } - // Set up IDT idt::init_bsp(); - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'3', options(nostack, preserves_flags)); } - // Initialize RMM #[cfg(target_arch = "x86")] let mut bump_allocator = @@ -134,9 +109,6 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { #[cfg(target_arch = "x86_64")] let mut bump_allocator = crate::startup::memory::init(&args, Some(0x100000), None); - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'4', options(nostack, preserves_flags)); } - // Initialize paging paging::init(); @@ -145,14 +117,11 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { } numa::init(&mut bump_allocator); - info!("NUMA init done, calling init_mm"); crate::memory::init_mm(bump_allocator); - info!("init_mm done"); #[cfg(target_arch = "x86_64")] crate::arch::alternative::early_init(true); - info!("alternatives done"); // Set up syscall instruction interrupt::syscall::init(); @@ -163,9 +132,6 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { // Activate memory logging crate::log::init(); - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'6', options(nostack, preserves_flags)); } - // Initialize miscellaneous processor features #[cfg(target_arch = "x86_64")] crate::arch::misc::init(LogicalCpuId::BSP); @@ -173,9 +139,6 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! { // Initialize devices device::init(); - #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - { core::arch::asm!("out dx, al", in("dx") 0x3F8u16, in("al") b'7', options(nostack, preserves_flags)); } - // Read ACPI tables, starts APs if cfg!(feature = "acpi") { crate::acpi::init_after_mem(args.acpi_rsdp()); diff --git a/src/context/context.rs b/src/context/context.rs index 4ee0e56302..573a4460ee 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -433,11 +433,7 @@ impl Context { i: FileHandle, lock_token: &mut LockToken, ) -> Option { - let is_upper = i.get() & syscall::UPPER_FDTBL_TAG != 0; let result = self.files.write(lock_token.token()).remove_file(i); - if is_upper && result.is_some() { - crate::info!("Context::remove_file ctx={} upper_idx={}", self.name, i.get()); - } result } @@ -969,9 +965,6 @@ impl FdTbl { let removed_file_opt = fdtbl.get_mut(real_index).and_then(|opt| opt.take()); if removed_file_opt.is_some() { self.active_count -= 1; - if index & syscall::UPPER_FDTBL_TAG != 0 { - crate::info!("FdTbl::remove_file upper idx={} active={}", real_index, self.active_count); - } } removed_file_opt diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index 189cf538ab..7e22f29338 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -765,31 +765,6 @@ impl KernelScheme for ProcScheme { kind: ContextHandle::AwaitingFiletableChange { new_ft }, context, } => { - let (posix_count, upper_count, upper_list, posix_list) = { - let ft = new_ft.read(token.token()); - let pc = ft.posix_fdtbl.iter().filter(|f| f.is_some()).count(); - let uc = ft.upper_fdtbl.iter().filter(|f| f.is_some()).count(); - let mut ul = String::new(); - for (i, f) in ft.upper_fdtbl.iter().enumerate() { - if f.is_some() { - ul.push_str(&format!(" {:x}", i)); - } - } - let mut pl = String::new(); - for (i, f) in ft.posix_fdtbl.iter().enumerate() { - if f.is_some() { - pl.push_str(&format!(" {}", i)); - } - } - (pc, uc, ul, pl) - }; - let ctx_name = context.read(token.token()).name; - info!( - "AwaitingFiletableChange applied: ctx='{}' posix_fds={} upper_fds={}", - ctx_name, posix_count, upper_count - ); - info!("upper FDs present:{}", upper_list); - info!("posix FDs present:{}", posix_list); context.write(token.token()).files = new_ft; } _ => (), @@ -1369,14 +1344,10 @@ impl ContextHandle { let addr_raw = next()??; let size_raw = next()??; let flags_raw = next()??; - info!("AS:MMAP fd={} off={} addr={:#x} size={:#x} flags={:#x}", fd, offset, addr_raw, size_raw, flags_raw); let page_span = crate::syscall::validate_region(addr_raw, size_raw)?; let flags = match MapFlags::from_bits(flags_raw) { Some(f) => f, - None => { - info!("AS:MMAP MapFlags::from_bits FAILED"); - return Err(Error::new(EINVAL)); - } + None => return Err(Error::new(EINVAL)), }; if fd == !0 { @@ -1395,10 +1366,6 @@ impl ContextHandle { false, token, ); - match res { - Ok(a) => { info!("AS:MMAP fmap_anonymous ok addr={:#x}", a); } - Err(ref e) => { info!("AS:MMAP fmap_anonymous ERR errno={}", e.errno); } - }; return res; } else { let (scheme, number) = extract_scheme_number(fd, token)?; diff --git a/src/startup/mod.rs b/src/startup/mod.rs index 4596adf7fd..42cd38760e 100644 --- a/src/startup/mod.rs +++ b/src/startup/mod.rs @@ -137,10 +137,8 @@ pub(crate) fn init_env() -> &'static [u8] { } extern "C" fn userspace_init() { - info!("userspace_init: entered bootstrap context"); let mut token = unsafe { CleanLockToken::new() }; let bootstrap = BOOTSTRAP.get().expect("BOOTSTRAP was not set"); - info!("userspace_init: calling usermode_bootstrap"); unsafe { crate::syscall::process::usermode_bootstrap(bootstrap, &mut token) } } @@ -191,7 +189,6 @@ pub(crate) fn kmain(bootstrap: Bootstrap) -> ! { } numa::dump_info(); - info!("kmain: dump_info done, calling run_userspace"); run_userspace(&mut token) } @@ -228,24 +225,14 @@ pub(crate) fn kmain_ap(cpu_id: crate::cpu_set::LogicalCpuId) -> ! { } fn run_userspace(token: &mut CleanLockToken) -> ! { - let mut switch_count = 0u64; loop { unsafe { interrupt::disable(); match context::switch(token) { SwitchResult::Switched => { - switch_count += 1; - if switch_count <= 5 || switch_count % 10000 == 0 { - info!("run_userspace: switch {} completed", switch_count); - } interrupt::enable_and_nop(); } SwitchResult::AllContextsIdle => { - if switch_count == 0 { - info!("run_userspace: AllContextsIdle on first switch — no runnable contexts"); - } - switch_count += 1; - // Enable interrupts, then halt CPU (to save power) until the next interrupt is actually fired. interrupt::enable_and_halt(); } } diff --git a/src/syscall/fs.rs b/src/syscall/fs.rs index e8a85611cf..f1a9767e57 100644 --- a/src/syscall/fs.rs +++ b/src/syscall/fs.rs @@ -77,35 +77,9 @@ pub fn openat( let current_lock = context::current(); let mut current = current_lock.read(token.token()); let (context, mut token) = current.token_split(); - let name = context.name; - let pipe = context.get_file(fh, &mut token).ok_or_else(|| { - let ft = context.files.read(token.token()); - let raw = fh.get(); - let stripped = raw & !syscall::UPPER_FDTBL_TAG; - let is_upper = raw & syscall::UPPER_FDTBL_TAG != 0; - let upper_len = ft.upper_fdtbl.len(); - let upper_at_idx = if is_upper && stripped < ft.upper_fdtbl.len() { - ft.upper_fdtbl[stripped].is_some() - } else { - false - }; - let upper_present: String = ft.upper_fdtbl.iter().enumerate() - .filter(|(_, f)| f.is_some()) - .map(|(i, _)| i.to_string()) - .collect::>().join(","); - let posix_present: String = ft.posix_fdtbl.iter().enumerate() - .filter(|(_, f)| f.is_some()) - .map(|(i, _)| i.to_string()) - .collect::>().join(","); - info!( - "openat: EBADF fh={:#x} ctx='{}' is_upper={} idx={} upper_len={} upper_at_idx={} upper_present=[{}] posix_present=[{}]", - raw, name, is_upper, stripped, upper_len, upper_at_idx, upper_present, posix_present - ); - Error::new(EBADF) - })?; - let desc = pipe.description.read(token.token()); - info!("openat: fh={:#x} scheme_id={} number={} path='{}' ctx='{}'", fh.get(), desc.scheme.get(), desc.number, path_buf, name); - (desc.scheme, desc.number) + let pipe = context.get_file(fh, &mut token).ok_or(Error::new(EBADF))?; + let desc = pipe.description.read(token.token()); + (desc.scheme, desc.number) }; let caller_ctx = context::current() @@ -866,10 +840,6 @@ pub fn sys_read(fd: FileHandle, buf: UserSliceWo, token: &mut CleanLockToken) -> Ok(bytes_read) } pub fn sys_write(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) -> Result { - if fd.get() <= 5 || fd.get() > 0x4000000000000000 { - let name = context::current().read(token.token()).name; - info!("sys_write ENTER fd={} buf_len={} ctx='{}'", fd.get(), buf.len(), name); - } let result = (|| { let (bytes_written, desc_arc, desc) = file_op_generic_ext(fd, token, |scheme, desc_arc, desc, token| { @@ -896,9 +866,5 @@ pub fn sys_write(fd: FileHandle, buf: UserSliceRo, token: &mut CleanLockToken) - guard.io_write_bytes = guard.io_write_bytes.saturating_add(bytes_written as u64); Ok(bytes_written) })(); - if result.is_err() && fd.get() <= 10 { - let name = context::current().read(token.token()).name; - info!("sys_write fd={} ctx='{}' err={:?}", fd.get(), name, result.as_ref().err()); - } result } diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 5f5209ba21..6e773c5d90 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -148,9 +148,7 @@ const KERNEL_METADATA_PAGE_COUNT: usize = syscall::KERNEL_METADATA_SIZE / PAGE_S }; pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockToken) { - info!("usermode_bootstrap: ENTER, page_count={}", bootstrap.page_count); assert_ne!(bootstrap.page_count, 0); - info!("usermode_bootstrap: page_count ok, getting addr_space"); { let addr_space = Arc::clone( @@ -159,7 +157,6 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok .addr_space() .expect("expected bootstrap context to have an address space"), ); - info!("usermode_bootstrap: got addr_space, calling mmap for {} pages", bootstrap.page_count); let base = Page::containing_address(VirtualAddress::new(PAGE_SIZE)); let flags = MapFlags::MAP_FIXED_NOREPLACE @@ -173,7 +170,6 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok let _base_page = { let mut lock_token = token.token(); let mut addr_space_lock = addr_space.acquire_write(lock_token.downgrade()); - info!("usermode_bootstrap: acquired write lock, calling mmap"); addr_space_lock .mmap( &addr_space, @@ -194,7 +190,6 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok ) .expect("Failed to allocate bootstrap pages") }; - info!("usermode_bootstrap: mmap done"); // Insert kernel schemes root capabilities. let mut kernel_schemes_infos = @@ -206,10 +201,7 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok inner.fd = { let cap_fd = match scheme.as_scheme().scheme_root(token) { Ok(fd) => fd, - Err(e) => { - info!("scheme_root failed for {:?}: {}", i, e); - usize::MAX - } + Err(_) => usize::MAX }; let inserted = insert_fd( scheme.scheme_id(), @@ -217,7 +209,6 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok matches!(scheme, GlobalSchemes::Proc), token, ); - info!("inserted fd {:#x} for scheme_id {} cap_fd {}", inserted, scheme.scheme_id().get(), cap_fd); inserted }; } @@ -300,7 +291,6 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok .expect("failed to copy memory to bootstrap"); let bootstrap_entry = u64::from_le_bytes(bootstrap_slice[0x1a..0x22].try_into().unwrap()); - info!("Bootstrap entry point: {:#x}, pages: {}, stack at {:#x}", bootstrap_entry, bootstrap.page_count, PAGE_SIZE + bootstrap.page_count * PAGE_SIZE + 8 * PAGE_SIZE); assert_ne!(bootstrap_entry, 0); // Map a minimal user stack for the bootstrap process. Without this, @@ -363,8 +353,7 @@ pub unsafe fn usermode_bootstrap(bootstrap: &Bootstrap, token: &mut CleanLockTok regs.set_instr_pointer(bootstrap_entry.try_into().unwrap()); regs.set_stack_pointer(stack_top_vaddr); } - info!("usermode_bootstrap: EXIT, entry={:#x}, sp={:#x}", bootstrap_entry, stack_top_vaddr); -} + } unsafe fn bootstrap_mem(bootstrap: &crate::startup::Bootstrap) -> &'static [u8] { unsafe {