From 2857a52472a84bed9080c9eb24f68cea4805e266 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Apr 2026 11:54:33 +0000 Subject: [PATCH] Fix fmap BSS zeroing: allocate full len pages not just file portion Agent-Logs-Url: https://github.com/Pryancito/eclipse/sessions/6fc1a83f-eccd-4ebf-88cf-cd3e9be86467 Co-authored-by: Pryancito <4010159+Pryancito@users.noreply.github.com> --- eclipse_kernel/src/filesystem.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/eclipse_kernel/src/filesystem.rs b/eclipse_kernel/src/filesystem.rs index a78d69b79..226a6bdf2 100644 --- a/eclipse_kernel/src/filesystem.rs +++ b/eclipse_kernel/src/filesystem.rs @@ -2501,9 +2501,14 @@ impl Scheme for FileSystemScheme { if offset >= file_size { return Err(scheme_error::EINVAL); } + // `want` is how many bytes actually exist in the file for this mapping. + // `len` may be larger (memsz > filesz) when the segment has a BSS extension. + // We must allocate pages for the full `len` so that the BSS region is backed + // by zeroed physical memory rather than whatever happened to follow the + // file-data allocation in the physical frame pool. let max_len = file_size - offset; let want = core::cmp::min(len, max_len); - let aligned_len = (want + 0xFFF) & !0xFFF; + let aligned_len = (len + 0xFFF) & !0xFFF; if aligned_len == 0 { return Err(scheme_error::EINVAL); } @@ -2518,7 +2523,8 @@ impl Scheme for FileSystemScheme { crate::memory::frame_info::set_refcount(start_phys + i * 4096, 1); } - // Zero the whole region and read file bytes into it. + // Zero the whole region (covers both file data and BSS extension), then + // copy only the file portion (`want` bytes) into the start of the buffer. let kptr = (crate::memory::PHYS_MEM_OFFSET + start_phys) as *mut u8; unsafe { core::ptr::write_bytes(kptr, 0, aligned_len); } let dst = unsafe { core::slice::from_raw_parts_mut(kptr, want) };