Skip to content

Commit

Permalink
Merge pull request #51 from naoki9911/fix-allocator-init
Browse files Browse the repository at this point in the history
align allocator's base address and length to BLOCK_SIZE
  • Loading branch information
saza-ku authored Feb 23, 2024
2 parents 3f1d28e + 12b4771 commit 1c0ea8a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/mem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}

Expand Down

0 comments on commit 1c0ea8a

Please sign in to comment.