pluto/test/mock/kernel/vmm_mock.zig

54 lines
1.6 KiB
Zig
Raw Normal View History

2020-01-09 17:16:51 +01:00
const mem = @import("mem_mock.zig");
2020-01-09 14:27:49 +01:00
const bitmap = @import("../../../src/kernel/bitmap.zig");
2020-08-23 20:48:10 +02:00
const vmm = @import("../../../src/kernel/vmm.zig");
2020-01-09 17:16:51 +01:00
const arch = @import("arch_mock.zig");
const std = @import("std");
2020-01-09 14:27:49 +01:00
pub const VmmError = error{
/// A memory region expected to be allocated wasn't
NotAllocated,
};
2020-08-23 20:48:10 +02:00
pub const Attributes = vmm.Attributes;
2020-01-09 14:27:49 +01:00
pub const BLOCK_SIZE: u32 = 1024;
2020-08-23 20:48:10 +02:00
pub const Mapper = vmm.Mapper;
pub const MapperError = error{
InvalidVirtualAddress,
InvalidPhysicalAddress,
AddressMismatch,
MisalignedVirtualAddress,
MisalignedPhysicalAddress,
NotMapped,
};
pub var kernel_vmm: VirtualMemoryManager(arch.VmmPayload) = undefined;
2020-01-09 17:16:51 +01:00
pub fn VirtualMemoryManager(comptime Payload: type) type {
2020-01-09 14:27:49 +01:00
return struct {
const Self = @This();
2020-08-23 20:48:10 +02:00
pub fn init(start: usize, end: usize, allocator: *std.mem.Allocator, mapper: Mapper(Payload), payload: Payload) std.mem.Allocator.Error!Self {
return Self{};
}
pub fn virtToPhys(self: *const Self, virt: usize) VmmError!usize {
return 0;
}
2020-01-09 14:27:49 +01:00
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;
}
};
2020-01-09 17:16:51 +01:00
}
pub fn init(mem_profile: *const mem.MemProfile, allocator: *std.mem.Allocator) std.mem.Allocator.Error!VirtualMemoryManager(arch.VmmPayload) {
2020-01-09 17:16:51 +01:00
return std.mem.Allocator.Error.OutOfMemory;
}