aboutsummaryrefslogtreecommitdiff
path: root/src/lib/paging.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/paging.zig')
-rw-r--r--src/lib/paging.zig18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/lib/paging.zig b/src/lib/paging.zig
index 0775940..dd1feeb 100644
--- a/src/lib/paging.zig
+++ b/src/lib/paging.zig
@@ -36,19 +36,13 @@ pub var next_mmio_vaddr: usize = 0xff000000;
pub var kmem: *Table = undefined;
-pub const AllocError = error{
+pub const Error = error{
ZeroSize,
OutOfMemory,
- OutOfRange,
- DoubleFree,
AlreadyTaken,
NotALeaf,
};
-pub const TableError = error{
- NotALeaf,
-};
-
pub const Mode = enum(u4) {
bare,
sv39 = 8,
@@ -85,7 +79,7 @@ pub const Page = struct {
// Fails if the page is already taken.
// Returns whether the operation was successful.
pub fn take(self: *Page, last: bool) !void {
- if (@bitCast(self.flags.active)) return AllocError.AlreadyTaken;
+ if (@bitCast(self.flags.active)) return Error.AlreadyTaken;
self.flags.active = 1;
if (last) self.flags.last = 1;
@@ -303,7 +297,7 @@ pub const Table = struct {
// This function internally uses zeroedAlloc to allocate memory for the required page tables,
// but assumes that the physical address to map to has already been allocated by the caller.
pub fn map(root: *Table, vaddr: usize, paddr: usize, flags: EntryFlags, level: usize) !void {
- if (!flags.isLeaf()) return TableError.NotALeaf;
+ if (!flags.isLeaf()) return Error.NotALeaf;
const vpn = virtualPageNumbers(vaddr);
@@ -499,7 +493,7 @@ pub fn init() !void {
// Allocate memory pages. Passing n <= 0 results in an error.
pub fn alloc(n: usize) ![]align(page_size) u8 {
- if (n <= 0) return AllocError.ZeroSize;
+ if (n <= 0) return Error.ZeroSize;
const num_pages = heapSize() / page_size;
// Start allocating beyond page descriptors.
@@ -541,7 +535,7 @@ pub fn alloc(n: usize) ![]align(page_size) u8 {
}
}
- return AllocError.OutOfMemory;
+ return Error.OutOfMemory;
}
// Free (contiguous) memory page(s).
@@ -576,7 +570,7 @@ pub fn free(memory: anytype) void {
// Allocate memory pages and overwrite their contents with zeroes for added security.
// Passing n <= 0 results in an error.
-pub fn zeroedAlloc(n: usize) AllocError![]align(page_size) u8 {
+pub fn zeroedAlloc(n: usize) Error![]align(page_size) u8 {
const ret = try alloc(n);
const satp = riscv.satp.read();