Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions kernel/memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "../kstd/kstddef.h"
#include "../api/page_size.h"
#include "../kstd/kstdlib.h"

#define PAGING_4KiB 0
#define PAGING_4MiB 1
Expand Down Expand Up @@ -41,6 +42,22 @@ struct VirtualRange {
size_t size;
[[nodiscard]] VirtualAddress end() const { return start + size; }
[[nodiscard]] bool contains(VirtualAddress address) const { return address >= start && address < end(); }
[[nodiscard]] bool overlaps(VirtualRange range) const { return max(start, range.start) < min(end(), range.end()); }
};

/** A struct to be used for the keys in memory maps. **/
struct ComparableVirtualRange: public VirtualRange {
ComparableVirtualRange(VirtualAddress start, size_t size): VirtualRange(start, size) {}
ComparableVirtualRange(VirtualAddress start): VirtualRange(start, 1) {}
ComparableVirtualRange(VirtualRange range): VirtualRange(range.start, range.size) {}

bool operator<(ComparableVirtualRange other) const {
return start < other.start;
}

bool operator==(ComparableVirtualRange other) const {
return overlaps(other);
}
};

struct PageFault {
Expand Down
Loading