From 12b47712366c388e04d2d862c2e7361baa8652cd Mon Sep 17 00:00:00 2001 From: Naoki MATSUMOTO Date: Mon, 19 Feb 2024 03:43:43 +0900 Subject: [PATCH] align allocator's base address and length to BLOCK_SIZE Base address and length must be aligned to BLOCK_SIZE, but currently aligned to PAGE_SIZE. This causes General Protection Exception in some cases. This patch fixes wrong alignment. Signed-off-by: Naoki MATSUMOTO --- src/mem.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mem.zig b/src/mem.zig index 8812de1..47b52f5 100644 --- a/src/mem.zig +++ b/src/mem.zig @@ -192,8 +192,8 @@ pub fn init(info: *multiboot.BootInfo) void { log.info.printf("available memory: {x} - {x}\n", .{ base, end }); // align the range to BLOCK_SIZE - const aligned_base = util.roundUp(usize, base, PAGE_SIZE); - const aligned_end = util.roundDown(usize, end, PAGE_SIZE); + const aligned_base = util.roundUp(usize, base, BLOCK_SIZE); + const aligned_end = util.roundDown(usize, end, BLOCK_SIZE); const length = aligned_end - aligned_base; if (length >= MIN_BOOTTIME_ALLOCATOR_SIZE) { @@ -213,8 +213,8 @@ pub fn init(info: *multiboot.BootInfo) void { pub fn init2() void { const base = @intFromPtr(boottime_fba.?.buffer.ptr) + boottime_fba.?.end_index; const length = boottime_fba.?.buffer.len - boottime_fba.?.end_index; - const aligned_base = util.roundUp(usize, base, PAGE_SIZE); - const aligned_length = util.roundDown(usize, length, PAGE_SIZE); + const aligned_base = util.roundUp(usize, base, BLOCK_SIZE); + const aligned_length = util.roundDown(usize, length, BLOCK_SIZE); initRange(aligned_base, aligned_length); boottime_allocator = null; @@ -280,10 +280,10 @@ fn initRange(base: usize, length: usize) void { return; } - if (base % PAGE_SIZE != 0) { + if (base % BLOCK_SIZE != 0) { @panic("freeRange: base is not aligned"); } - if (length % PAGE_SIZE != 0) { + if (length % BLOCK_SIZE != 0) { @panic("freeRange: length is not aligned"); }