This repository was archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathptr_t.cpp
108 lines (84 loc) · 2.38 KB
/
ptr_t.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
This file is part of Fennix Kernel.
Fennix Kernel is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix Kernel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
*/
#ifdef DEBUG
#include <types.h>
#include <debug.h>
#include <assert.h>
class __ptr_t_demo
{
public:
ptr_t<void *> Address;
__ptr_t_demo(ptr_t<void *> Address, ptr_t<void *> Address2 = nullptr)
{
this->Address = Address;
}
~__ptr_t_demo() {}
void *test1()
{
return Address + 0xdeadbeef;
}
uintptr_t test2()
{
return Address + 0xdeadbeef;
}
void *Map(ptr_t<void *> VirtualAddress, ptr_t<void *> &PhysicalAddress, size_t Length)
{
ptr_t<void *> Final;
for (size_t i = 0; i < Length; i++)
Final = VirtualAddress + (i * 0x1000);
PhysicalAddress = 0;
return Final;
}
};
__constructor void TestPtr_T()
{
__ptr_t_demo demo(nullptr);
assert(demo.test1() == (void *)0xdeadbeef);
assert(demo.test2() == 0xdeadbeef);
ptr_t<void *> VirtualAddress = 0x1000;
ptr_t<void *> PhysicalAddress = 0x2000;
size_t Length = 4;
void *ret = demo.Map(VirtualAddress, PhysicalAddress, Length);
assert(ret == (void *)0x4000);
VirtualAddress -= 0x1000;
assert(PhysicalAddress == 0);
VirtualAddress = 0x1;
assert(VirtualAddress > PhysicalAddress);
assert(VirtualAddress > 0);
PhysicalAddress = 0x2;
assert(VirtualAddress < PhysicalAddress);
PhysicalAddress = 0;
assert(!(PhysicalAddress < 0));
PhysicalAddress = 0x1;
assert(VirtualAddress >= PhysicalAddress);
assert(VirtualAddress >= 0);
VirtualAddress = 0;
PhysicalAddress = 0;
assert(VirtualAddress <= PhysicalAddress);
assert(PhysicalAddress <= 0);
VirtualAddress = 0x1000;
assert(VirtualAddress == 0x1000);
assert(VirtualAddress != 0x2000);
PhysicalAddress = 0x1000;
assert(PhysicalAddress == 0x1000);
assert(PhysicalAddress != 0x2000);
ptr_t<void *> v;
v += 1;
assert(v == 1);
v -= 1;
assert(v == 0);
v -= 1;
assert(v == (void *)-1);
}
#endif // DEBUG