Add heap allocator

This commit is contained in:
Sam Tebbs 2020-01-09 13:27:49 +00:00
parent dac57fc87b
commit f5a22fdd4b
4 changed files with 483 additions and 2 deletions

View file

@ -1,14 +1,37 @@
const mem = @import("mem_mock.zig");
const multiboot = @import("../../../src/kernel/multiboot.zig");
const bitmap = @import("../../../src/kernel/bitmap.zig");
const arch = @import("arch_mock.zig");
const std = @import("std");
pub const VmmError = error{
/// A memory region expected to be allocated wasn't
NotAllocated,
};
pub const Attributes = struct {
kernel: bool,
writable: bool,
cachable: bool,
};
pub const BLOCK_SIZE: u32 = 1024;
pub fn Mapper(comptime Payload: type) type {
return struct {};
}
pub fn VirtualMemoryManager(comptime Payload: type) type {
return struct {};
return struct {
const Self = @This();
pub fn alloc(self: *Self, num: u32, attrs: Attributes) std.mem.Allocator.Error!?usize {
return std.mem.Allocator.Error.OutOfMemory;
}
pub fn free(self: *Self, vaddr: usize) (bitmap.Bitmap(u32).BitmapError || VmmError)!void {
return VmmError.NotAllocated;
}
};
}
pub fn init(mem_profile: *const mem.MemProfile, mb_info: *multiboot.multiboot_info_t, allocator: *std.mem.Allocator) std.mem.Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {

View file

@ -64,6 +64,8 @@ def get_post_archinit_cases():
TestCase("TTY tests", [r"TTY: Tested globals", r"TTY: Tested printing"]),
TestCase("TTY done", [r"Done tty"]),
TestCase("Heap", [r"Init heap", r"Done heap"]),
TestCase("Init finishes", [r"Init done"]),
TestCase("Panic tests", [r"Kernel panic: integer overflow", r"c[a-z\d]+: panic", r"c[a-z\d]+: panic.runtimeTests", r"c[a-z\d]+: kmain", r"c[a-z\d]+: start_higher_half"], r"\[ERROR\] ")