Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align allocator's base address and length to BLOCK_SIZE #51

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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