This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathMemory.h
More file actions
70 lines (59 loc) · 2.26 KB
/
Copy pathMemory.h
File metadata and controls
70 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright © 2016-2022 Byteduck */
#pragma once
#include "../kstd/kstddef.h"
#include "../api/page_size.h"
#include "../kstd/kstdlib.h"
#define PAGING_4KiB 0
#define PAGING_4MiB 1
#define PAGE_SIZE_FLAG PAGING_4KiB
#define HIGHER_HALF 0xC0000000
#define KERNEL_TEXT ((size_t)&_KERNEL_TEXT)
#define KERNEL_TEXT_END ((size_t)&_KERNEL_TEXT_END)
#define KERNEL_DATA ((size_t)&_KERNEL_DATA)
#define KERNEL_DATA_END ((size_t)&_KERNEL_DATA_END)
#define KERNEL_END ((size_t)&_KERNEL_END)
#define PAGETABLES_START ((size_t)&_PAGETABLES_START)
#define PAGETABLES_END ((size_t)&_PAGETABLES_END)
#define KERNEL_TEXT_SIZE (KERNEL_TEXT_END - KERNEL_TEXT)
#define KERNEL_DATA_SIZE (KERNEL_DATA_END - KERNEL_DATA)
#define KERNEL_END_VIRTADDR (HIGHER_HALF + KERNEL_SIZE_PAGES * PAGE_SIZE)
#define KERNEL_VIRTUAL_HEAP_BEGIN 0xE0000000
#define KERNEL_QUICKMAP_PAGE_A (KERNEL_VIRTUAL_HEAP_BEGIN - PAGE_SIZE)
#define KERNEL_QUICKMAP_PAGE_B (KERNEL_VIRTUAL_HEAP_BEGIN - (PAGE_SIZE * 2))
// For disambiguating parameter meanings.
typedef size_t PageIndex;
typedef size_t PhysicalAddress;
typedef size_t VirtualAddress;
struct VirtualRange {
public:
VirtualRange(VirtualAddress start, size_t size):
start(start),
size(size) {}
const static VirtualRange null;
VirtualAddress start;
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 {
public:
VirtualAddress address;
VirtualAddress instruction_pointer;
enum class Type {
Read, Write, Execute, Unknown
} type;
};