From 91a0f66af159f1b2dc0350623c626254a4138f15 Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Wed, 1 Jul 2020 00:16:48 +0100 Subject: [PATCH 1/3] Insert the correct address into the allocations map --- src/kernel/vmm.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/kernel/vmm.zig b/src/kernel/vmm.zig index 9a06d249..0e753a38 100644 --- a/src/kernel/vmm.zig +++ b/src/kernel/vmm.zig @@ -253,7 +253,7 @@ pub fn VirtualMemoryManager(comptime Payload: type) type { try phys_list.append(phys); } } - _ = try self.allocations.put(virt, Allocation{ .physical = phys_list }); + _ = try self.allocations.put(virtual.start, Allocation{ .physical = phys_list }); } /// @@ -310,7 +310,7 @@ pub fn VirtualMemoryManager(comptime Payload: type) type { /// Bitmap.BitmapError.OutOfBounds - The address is out of the manager's bounds /// pub fn free(self: *Self, vaddr: usize) (bitmap.Bitmap(u32).BitmapError || VmmError)!void { - const entry = vaddr / BLOCK_SIZE; + const entry = (vaddr - self.start) / BLOCK_SIZE; if (try self.bmp.isSet(entry)) { // There will be an allocation associated with this virtual address const allocation = self.allocations.get(vaddr) orelse unreachable; From 9a408dc6ae5ed7102fd6ff3eb42c62fd9133f2a6 Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Mon, 6 Jul 2020 12:16:01 +0100 Subject: [PATCH 2/3] Add test for correct address --- src/kernel/vmm.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/kernel/vmm.zig b/src/kernel/vmm.zig index 0e753a38..d38bb6c4 100644 --- a/src/kernel/vmm.zig +++ b/src/kernel/vmm.zig @@ -469,6 +469,8 @@ test "set" { const pend = vend + 123; const attrs = Attributes{ .kernel = true, .writable = true, .cachable = true }; try vmm.set(.{ .start = vstart, .end = vend }, mem.Range{ .start = pstart, .end = pend }, attrs); + // Make sure it put the correct address in the map + std.testing.expect(vmm.allocations.get(vstart) != null); var allocations = test_allocations orelse unreachable; // The entries before the virtual start shouldn't be set From febb6c7e23a7fec331f7c71fd483b0ceea069db8 Mon Sep 17 00:00:00 2001 From: Sam Tebbs Date: Mon, 6 Jul 2020 12:21:04 +0100 Subject: [PATCH 3/3] Update for new HashMap.get --- src/kernel/vmm.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kernel/vmm.zig b/src/kernel/vmm.zig index d38bb6c4..c9847afa 100644 --- a/src/kernel/vmm.zig +++ b/src/kernel/vmm.zig @@ -318,7 +318,7 @@ pub fn VirtualMemoryManager(comptime Payload: type) type { defer physical.deinit(); const num_physical_allocations = physical.items.len; for (physical.items) |block, i| { - // Clear the address space entry, unmap the virtual memory and free the physical memory + // Clear the address space entry and free the physical memory try self.bmp.clearEntry(entry + i); pmm.free(block) catch |e| panic(@errorReturnTrace(), "Failed to free PMM reserved memory at 0x{X}: {}\n", .{ block * BLOCK_SIZE, e }); }