From 1043343b9db89d60dcc911eef97ef796bb87b6d0 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Wed, 26 Aug 2026 19:04:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(mm):=20get=5Fblock=5Fsize=20=E7=A7=BB?= =?UTF-8?q?=E4=BD=8D=E6=94=B9=2064=20=E4=BD=8D=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BC=99=E4=BC=B4=E5=88=9D=E5=A7=8B=E5=8C=96=E6=97=A0=E9=99=90?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 4096<<20 在 i32 下溢出为 0x0 → bs=0x0 → cur_addr/remaining 不变 → 无限循环 ([mm] it=1..6 order=20 bs=0x0 addr 不变)。改 t.CUInt64T 移位。另增关键数值 打印(memmap addr/size/desc/entries),配合描述符转储定位 4GB 伪可用区。 --- VKernel/Kernel/mm/mm.vp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/VKernel/Kernel/mm/mm.vp b/VKernel/Kernel/mm/mm.vp index 02994fe..b46363b 100644 --- a/VKernel/Kernel/mm/mm.vp +++ b/VKernel/Kernel/mm/mm.vp @@ -86,7 +86,9 @@ def get_order(size: t.CUInt64T) -> t.CStatic | t.CInt: # 计算块大小 def get_block_size(order: t.CInt) -> t.CStatic | t.CUInt64T: - return MIN_BLOCK_SIZE << order + # 4096 << 20 = 4GB 超出 i32 范围 → 0x0 → 伙伴初始化无限循环(bs=0x0)。 + # 必须用 64 位移位(4096<<20 = 4294967296)。 + return t.CUInt64T(MIN_BLOCK_SIZE) << t.CUInt64T(order) @t.Object @@ -507,6 +509,11 @@ def init(MemmapAddr: t.CUInt64T, MemmapSize: t.CUInt64T, MemmapDescSize: t.CUInt if MemmapSize > 0: if MemmapDescSize > 0: num_entries: t.CUInt64T = MemmapSize / MemmapDescSize + # [DBG] 关键数值:memmap 缓冲/步长/条目数(用后移除) + _dk1: t.CArray[t.CChar, 100] + viperlib.snprintf(c.Addr(_dk1), 100, "[mm] addr=0x%lx size=%lu desc=%lu entries=%lu\n", + MemmapAddr, MemmapSize, MemmapDescSize, num_entries) + serial.puts(c.Addr(_dk1)) max_memory: t.CUInt64T = 0 best_start: t.CUInt64T = 0 best_avail_size: t.CUInt64T = 0