summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/CodeManager.cxx2
-rw-r--r--Private/Source/Crc32.cxx109
-rw-r--r--Private/Source/CxxAbi.cxx121
-rw-r--r--Private/Source/CxxKitRT.cxx49
-rw-r--r--Private/Source/Defines.cxx1
-rw-r--r--Private/Source/DriveManager.cxx60
-rw-r--r--Private/Source/ErrorOr.cxx2
-rw-r--r--Private/Source/FileManager.cxx57
-rw-r--r--Private/Source/Framebuffer.cxx39
-rw-r--r--Private/Source/GUIDWizard.cxx65
-rw-r--r--Private/Source/GUIDWrapper.cxx5
-rw-r--r--Private/Source/Heap.cxx208
-rw-r--r--Private/Source/IndexableProperty.cxx18
-rw-r--r--Private/Source/KHeap.cxx126
-rw-r--r--Private/Source/KernelHeap.cxx109
-rw-r--r--Private/Source/LockDelegate.cxx2
-rw-r--r--Private/Source/Network/IP.cpp158
-rw-r--r--Private/Source/Network/NetworkDevice.cpp26
-rw-r--r--Private/Source/New+Delete.cxx2
-rw-r--r--Private/Source/NewFS-Journal.cxx90
-rw-r--r--Private/Source/NewFS.cxx70
-rw-r--r--Private/Source/OSErr.cxx1
-rw-r--r--Private/Source/OwnPtr.cxx2
-rw-r--r--Private/Source/PRDT.cxx50
-rw-r--r--Private/Source/PageAllocator.cxx78
-rw-r--r--Private/Source/PageManager.cxx245
-rw-r--r--Private/Source/Panic.cxx57
-rw-r--r--Private/Source/PermissionSelector.cxx31
-rw-r--r--Private/Source/Pmm.cxx103
-rw-r--r--Private/Source/ProcessManager.cxx2
-rw-r--r--Private/Source/Property.cxx17
-rw-r--r--Private/Source/RuntimeMain.cxx25
-rw-r--r--Private/Source/SMPManager.cxx203
-rw-r--r--Private/Source/Semaphore.cxx53
-rw-r--r--Private/Source/SharedObject.cxx45
-rw-r--r--Private/Source/Storage/ATA.cxx114
-rw-r--r--Private/Source/Storage/NVME.cxx10
-rw-r--r--Private/Source/Storage/Storage.cxx3
-rw-r--r--Private/Source/String.cxx309
-rw-r--r--Private/Source/ThreadLocalStorage.cxx27
-rw-r--r--Private/Source/Timer.cxx13
-rw-r--r--Private/Source/URL.cxx138
-rw-r--r--Private/Source/UserHeap.cxx188
-rw-r--r--Private/Source/Utils.cxx289
-rw-r--r--Private/Source/Variant.cxx34
45 files changed, 1502 insertions, 1854 deletions
diff --git a/Private/Source/CodeManager.cxx b/Private/Source/CodeManager.cxx
index f1c6840e..ced403cc 100644
--- a/Private/Source/CodeManager.cxx
+++ b/Private/Source/CodeManager.cxx
@@ -14,7 +14,7 @@
#include <KernelKit/FileManager.hpp>
#include <KernelKit/ProcessManager.hpp>
#include <NewKit/ErrorID.hpp>
-#include <NewKit/KHeap.hpp>
+#include <NewKit/KernelHeap.hpp>
#include <NewKit/OwnPtr.hpp>
#include <NewKit/String.hpp>
diff --git a/Private/Source/Crc32.cxx b/Private/Source/Crc32.cxx
index 72b4da55..37663b8d 100644
--- a/Private/Source/Crc32.cxx
+++ b/Private/Source/Crc32.cxx
@@ -12,56 +12,67 @@
// @file CRC32.cpp
// @brief Checksum implementation.
-namespace hCore
-{
- UInt kCrcTbl[kCrcCnt] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832,
- 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
- 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a,
- 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
- 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
- 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab,
- 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4,
- 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074,
- 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525,
- 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
- 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
- 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76,
- 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
- 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6,
- 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7,
- 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
- 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7,
- 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
- 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
- 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330,
- 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
- };
+namespace hCore {
+UInt kCrcTbl[kCrcCnt] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
- static Int crc_byte(Int crc, UChar byte)
- {
- crc = (crc >> 8) ^ kCrcTbl[(byte) ^ (crc & 0x000000FF)]; // shift 8 bytes to the right
-
- // XOR polynomial XOR the crc
- // without the 2 highest bytes
- return crc;
- }
+static Int crc_byte(Int crc, UChar byte) {
+ crc = (crc >> 8) ^
+ kCrcTbl[(byte) ^ (crc & 0x000000FF)]; // shift 8 bytes to the right
- Int crc32(const Char *byte, Int len)
- {
- Int checksum = 0;
+ // XOR polynomial XOR the crc
+ // without the 2 highest bytes
+ return crc;
+}
- for (UChar index = 1; index < len; ++index)
- checksum = crc_byte(checksum, byte[index]);
+Int crc32(const Char *byte, Int len) {
+ Int checksum = 0;
- return checksum;
- }
-} // namespace hCore
+ for (UChar index = 1; index < len; ++index)
+ checksum = crc_byte(checksum, byte[index]);
+
+ return checksum;
+}
+} // namespace hCore
diff --git a/Private/Source/CxxAbi.cxx b/Private/Source/CxxAbi.cxx
index 4984c81a..49b5834a 100644
--- a/Private/Source/CxxAbi.cxx
+++ b/Private/Source/CxxAbi.cxx
@@ -18,98 +18,75 @@ void *__dso_handle;
atexit_func_entry_t __atexit_funcs[DSO_MAX_OBJECTS];
uarch_t __atexit_func_count;
-extern "C" void __cxa_pure_virtual()
-{
- hCore::kcout << "[__cxa_pure_virtual] Placeholder\n";
+extern "C" void __cxa_pure_virtual() {
+ hCore::kcout << "[__cxa_pure_virtual] Placeholder\n";
}
-extern "C" void __stack_chk_fail()
-{
- hCore::kcout << "[__stack_chk_fail] Buffer overflow detected\n";
- hCore::panic(RUNTIME_CHECK_POINTER);
+extern "C" void __stack_chk_fail() {
+ hCore::kcout << "[__stack_chk_fail] Buffer overflow detected\n";
+ hCore::panic(RUNTIME_CHECK_POINTER);
}
-extern "C" int __cxa_atexit(void (*f)(void *), void *arg, void *dso)
-{
- if (__atexit_func_count >= DSO_MAX_OBJECTS)
- return -1;
+extern "C" int __cxa_atexit(void (*f)(void *), void *arg, void *dso) {
+ if (__atexit_func_count >= DSO_MAX_OBJECTS) return -1;
- __atexit_funcs[__atexit_func_count].destructor_func = f;
- __atexit_funcs[__atexit_func_count].obj_ptr = arg;
- __atexit_funcs[__atexit_func_count].dso_handle = dso;
+ __atexit_funcs[__atexit_func_count].destructor_func = f;
+ __atexit_funcs[__atexit_func_count].obj_ptr = arg;
+ __atexit_funcs[__atexit_func_count].dso_handle = dso;
- __atexit_func_count++;
+ __atexit_func_count++;
- return 0;
+ return 0;
}
-extern "C" void __cxa_finalize(void *f)
-{
- uarch_t i = __atexit_func_count;
- if (!f)
- {
- while (i--)
- {
- if (__atexit_funcs[i].destructor_func)
- {
- (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
- };
- }
-
- return;
+extern "C" void __cxa_finalize(void *f) {
+ uarch_t i = __atexit_func_count;
+ if (!f) {
+ while (i--) {
+ if (__atexit_funcs[i].destructor_func) {
+ (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
+ };
}
- while (i--)
- {
- if (__atexit_funcs[i].destructor_func)
- {
- (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
- __atexit_funcs[i].destructor_func = 0;
- };
- }
+ return;
+ }
+
+ while (i--) {
+ if (__atexit_funcs[i].destructor_func) {
+ (*__atexit_funcs[i].destructor_func)(__atexit_funcs[i].obj_ptr);
+ __atexit_funcs[i].destructor_func = 0;
+ };
+ }
}
-namespace cxxabiv1
-{
- extern "C" int __cxa_guard_acquire(__guard *g)
- {
- (void) g;
- return 0;
- }
+namespace cxxabiv1 {
+extern "C" int __cxa_guard_acquire(__guard *g) {
+ (void)g;
+ return 0;
+}
- extern "C" int __cxa_guard_release(__guard *g)
- {
- *(char *) g = 1;
- return 0;
- }
+extern "C" int __cxa_guard_release(__guard *g) {
+ *(char *)g = 1;
+ return 0;
+}
- extern "C" void __cxa_guard_abort(__guard *g)
- {
- (void) g;
- }
-} // namespace cxxabiv1
+extern "C" void __cxa_guard_abort(__guard *g) { (void)g; }
+} // namespace cxxabiv1
#else
-namespace cxxkit
-{
- extern "C" void __unwind(void(**finis)(void), int cnt)
- {
- for (int i = 0; i < cnt; ++i)
- (finis[i])();
- }
+namespace cxxkit {
+extern "C" void __unwind(void (**finis)(void), int cnt) {
+ for (int i = 0; i < cnt; ++i) (finis[i])();
+}
- extern "C" void __init_local(void(**init)(void), int cnt)
- {
- for (int i = 0; i < cnt; ++i)
- (init[i])();
- }
+extern "C" void __init_local(void (**init)(void), int cnt) {
+ for (int i = 0; i < cnt; ++i) (init[i])();
+}
- extern "C" void __fini_local(void(**finis)(void), int cnt)
- {
- for (int i = 0; i < cnt; ++i)
- (finis[i])();
- }
+extern "C" void __fini_local(void (**finis)(void), int cnt) {
+ for (int i = 0; i < cnt; ++i) (finis[i])();
}
+} // namespace cxxkit
#endif
diff --git a/Private/Source/CxxKitRT.cxx b/Private/Source/CxxKitRT.cxx
index 21ebb342..e608ab3c 100644
--- a/Private/Source/CxxKitRT.cxx
+++ b/Private/Source/CxxKitRT.cxx
@@ -14,35 +14,30 @@
using namespace hCore;
// unimplemented _HintTell
-void _HintTell(_HintMessage* ppMsg, _HintId* pId)
-{
- switch (*pId)
- {
- case kErrorExecutable:
- {
- const char* msg = "CodeManager doesn't recognize this executable.";
- rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
- break;
+void _HintTell(_HintMessage* ppMsg, _HintId* pId) {
+ switch (*pId) {
+ case kErrorExecutable: {
+ const char* msg = "CodeManager doesn't recognize this executable.";
+ rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
+ break;
}
- case kErrorExecutableLib:
- {
- const char* msg = "CodeManager doesn't recognize this library.";
- rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
- break;
+ case kErrorExecutableLib: {
+ const char* msg = "CodeManager doesn't recognize this library.";
+ rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
+ break;
}
- case kErrorFileNotFound:
- {
- const char* msg = "FileManager doesn't find this file.";
- rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
- break;
+ case kErrorFileNotFound: {
+ const char* msg = "FileManager doesn't find this file.";
+ rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
+ break;
}
- case kErrorNoNetwork:
- {
- const char* msg = "NetworkManager doesn't detect any WiFi/Ethernet connection.";
- rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
- break;
+ case kErrorNoNetwork: {
+ const char* msg =
+ "NetworkManager doesn't detect any WiFi/Ethernet connection.";
+ rt_copy_memory((const voidPtr)msg, *ppMsg, string_length(msg));
+ break;
}
default:
- break;
- }
-} \ No newline at end of file
+ break;
+ }
+}
diff --git a/Private/Source/Defines.cxx b/Private/Source/Defines.cxx
index 5b78388f..3e0bd946 100644
--- a/Private/Source/Defines.cxx
+++ b/Private/Source/Defines.cxx
@@ -8,4 +8,3 @@
*/
#include <NewKit/Defines.hpp>
-
diff --git a/Private/Source/DriveManager.cxx b/Private/Source/DriveManager.cxx
index be35e275..ee279ed1 100644
--- a/Private/Source/DriveManager.cxx
+++ b/Private/Source/DriveManager.cxx
@@ -10,53 +10,43 @@
#include <KernelKit/DebugOutput.hpp>
#include <KernelKit/DriveManager.hpp>
-namespace hCore
-{
-DriveSelector::DriveSelector() : fDrive(nullptr)
-{
-}
+namespace hCore {
+DriveSelector::DriveSelector() : fDrive(nullptr) {}
-DriveSelector::~DriveSelector()
-{
- if (fDrive)
- {
- this->Unmount();
- }
+DriveSelector::~DriveSelector() {
+ if (fDrive) {
+ this->Unmount();
+ }
}
-DriveTraits &DriveSelector::GetMounted()
-{
- MUST_PASS(fDrive != nullptr);
- return *fDrive;
+DriveTraits &DriveSelector::GetMounted() {
+ MUST_PASS(fDrive != nullptr);
+ return *fDrive;
}
-bool DriveSelector::Mount(DriveTraits *drive)
-{
- if (drive && drive->fReady() && fDrive == nullptr)
- {
- fDrive = drive;
- fDrive->fMount();
+bool DriveSelector::Mount(DriveTraits *drive) {
+ if (drive && drive->fReady() && fDrive == nullptr) {
+ fDrive = drive;
+ fDrive->fMount();
- kcout << "[Mount] drive: " << fDrive->fName << "\n";
+ kcout << "[Mount] drive: " << fDrive->fName << "\n";
- return true;
- }
+ return true;
+ }
- return false;
+ return false;
}
-DriveTraits *DriveSelector::Unmount()
-{
- if (!fDrive)
- return nullptr;
+DriveTraits *DriveSelector::Unmount() {
+ if (!fDrive) return nullptr;
- auto drivePointer = fDrive;
+ auto drivePointer = fDrive;
- fDrive->fUnmount();
- fDrive = nullptr;
+ fDrive->fUnmount();
+ fDrive = nullptr;
- kcout << "[Unmount] drive: " << drivePointer->fName << "\n";
+ kcout << "[Unmount] drive: " << drivePointer->fName << "\n";
- return drivePointer;
+ return drivePointer;
}
-} // namespace hCore
+} // namespace hCore
diff --git a/Private/Source/ErrorOr.cxx b/Private/Source/ErrorOr.cxx
index cf6f2317..4137c243 100644
--- a/Private/Source/ErrorOr.cxx
+++ b/Private/Source/ErrorOr.cxx
@@ -9,4 +9,4 @@
#include <NewKit/ErrorOr.hpp>
-/* BUILDME needs that file */ \ No newline at end of file
+/* BUILDME needs that file */
diff --git a/Private/Source/FileManager.cxx b/Private/Source/FileManager.cxx
index 2a6648ce..9bf26c29 100644
--- a/Private/Source/FileManager.cxx
+++ b/Private/Source/FileManager.cxx
@@ -13,35 +13,30 @@
//! @brief File manager for hCore.
-namespace hCore
-{
- static IFilesystemManager* kMounted = nullptr;
-
- /// @brief FilesystemManager getter.
- /// @return The mounted filesystem.
- IFilesystemManager* IFilesystemManager::GetMounted() { return kMounted; }
-
- IFilesystemManager* IFilesystemManager::Unmount()
- {
- if (kMounted)
- {
- auto mount = kMounted;
- kMounted = nullptr;
-
- return mount;
- }
-
- return nullptr;
- }
-
- bool IFilesystemManager::Mount(IFilesystemManager* pMount)
- {
- if (pMount)
- {
- kMounted = pMount;
- return true;
- }
-
- return false;
- }
+namespace hCore {
+static IFilesystemManager* kMounted = nullptr;
+
+/// @brief FilesystemManager getter.
+/// @return The mounted filesystem.
+IFilesystemManager* IFilesystemManager::GetMounted() { return kMounted; }
+
+IFilesystemManager* IFilesystemManager::Unmount() {
+ if (kMounted) {
+ auto mount = kMounted;
+ kMounted = nullptr;
+
+ return mount;
+ }
+
+ return nullptr;
+}
+
+bool IFilesystemManager::Mount(IFilesystemManager* pMount) {
+ if (pMount) {
+ kMounted = pMount;
+ return true;
+ }
+
+ return false;
}
+} // namespace hCore
diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx
index 208e90e9..1a73e449 100644
--- a/Private/Source/Framebuffer.cxx
+++ b/Private/Source/Framebuffer.cxx
@@ -9,31 +9,28 @@
#include <KernelKit/Framebuffer.hpp>
-namespace hCore
-{
- Framebuffer::Framebuffer(hCore::Ref<FramebufferContext*> &addr)
- : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32)
- {}
+namespace hCore {
+Framebuffer::Framebuffer(hCore::Ref<FramebufferContext*>& addr)
+ : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32) {}
- Framebuffer::~Framebuffer() = default;
+Framebuffer::~Framebuffer() = default;
- volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height)
- {
- if (m_FrameBufferAddr)
- return reinterpret_cast<volatile hCore::UIntPtr*>(m_FrameBufferAddr->m_Base + width_and_height);
+volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height) {
+ if (m_FrameBufferAddr)
+ return reinterpret_cast<volatile hCore::UIntPtr*>(
+ m_FrameBufferAddr->m_Base + width_and_height);
- return nullptr;
- }
+ return nullptr;
+}
- Ref<FramebufferContext*>& Framebuffer::Leak() { return m_FrameBufferAddr; }
+Ref<FramebufferContext*>& Framebuffer::Leak() { return m_FrameBufferAddr; }
- Framebuffer::operator bool() { return m_FrameBufferAddr; }
+Framebuffer::operator bool() { return m_FrameBufferAddr; }
- const FramebufferColorKind& Framebuffer::Color(const FramebufferColorKind& colour)
- {
- if (colour != FramebufferColorKind::INVALID)
- m_Colour = colour;
+const FramebufferColorKind& Framebuffer::Color(
+ const FramebufferColorKind& colour) {
+ if (colour != FramebufferColorKind::INVALID) m_Colour = colour;
- return m_Colour;
- }
-} // namespace hCore
+ return m_Colour;
+}
+} // namespace hCore
diff --git a/Private/Source/GUIDWizard.cxx b/Private/Source/GUIDWizard.cxx
index 25875671..d3b11b0a 100644
--- a/Private/Source/GUIDWizard.cxx
+++ b/Private/Source/GUIDWizard.cxx
@@ -16,49 +16,42 @@
// @brief Size of UUID.
#define kUUIDSize 32
-namespace hCore::XRN::Version1
-{
- auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*>
- {
- GUIDSequence *seq = new GUIDSequence();
- MUST_PASS(seq);
+namespace hCore::XRN::Version1 {
+auto make_sequence(const ArrayList<UShort>& uuidSeq) -> Ref<GUIDSequence*> {
+ GUIDSequence* seq = new GUIDSequence();
+ MUST_PASS(seq);
- Ref<GUIDSequence*> sequenceReference{seq, true};
+ Ref<GUIDSequence*> sequenceReference{seq, true};
- sequenceReference->m_Ms1 |= uuidSeq[0];
- sequenceReference->m_Ms2 |= uuidSeq[1];
- sequenceReference->m_Ms3 |= uuidSeq[2];
- sequenceReference->m_Ms3 |= uuidSeq[3];
+ sequenceReference->m_Ms1 |= uuidSeq[0];
+ sequenceReference->m_Ms2 |= uuidSeq[1];
+ sequenceReference->m_Ms3 |= uuidSeq[2];
+ sequenceReference->m_Ms3 |= uuidSeq[3];
- return sequenceReference;
- }
+ return sequenceReference;
+}
- // @brief Tries to make a guid out of a string.
- // This function is not complete for now
- auto try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr <Ref<StringView>>
- {
- Char buf[kUUIDSize];
+// @brief Tries to make a guid out of a string.
+// This function is not complete for now
+auto try_guid_to_string(Ref<GUIDSequence*>& seq) -> ErrorOr<Ref<StringView>> {
+ Char buf[kUUIDSize];
- for (SizeT index = 0; index < 16; ++index)
- {
- buf[index] = seq->u8[index] + kAsciiBegin;
- }
+ for (SizeT index = 0; index < 16; ++index) {
+ buf[index] = seq->u8[index] + kAsciiBegin;
+ }
- for (SizeT index = 16; index < 24; ++index)
- {
- buf[index] = seq->u16[index] + kAsciiBegin;
- }
+ for (SizeT index = 16; index < 24; ++index) {
+ buf[index] = seq->u16[index] + kAsciiBegin;
+ }
- for (SizeT index = 24; index < 28; ++index)
- {
- buf[index] = seq->u32[index] + kAsciiBegin;
- }
+ for (SizeT index = 24; index < 28; ++index) {
+ buf[index] = seq->u32[index] + kAsciiBegin;
+ }
- auto view = StringBuilder::Construct(buf);
+ auto view = StringBuilder::Construct(buf);
- if (view)
- return ErrorOr<Ref<StringView>>{ view.Leak() };
+ if (view) return ErrorOr<Ref<StringView>>{view.Leak()};
- return ErrorOr<Ref<StringView>>{-1};
- }
-} // namespace hCore::XRN::Version1
+ return ErrorOr<Ref<StringView>>{-1};
+}
+} // namespace hCore::XRN::Version1
diff --git a/Private/Source/GUIDWrapper.cxx b/Private/Source/GUIDWrapper.cxx
index 3ae42eeb..fa9a52a6 100644
--- a/Private/Source/GUIDWrapper.cxx
+++ b/Private/Source/GUIDWrapper.cxx
@@ -9,7 +9,4 @@
#include <CFKit/GUIDWrapper.hpp>
-namespace hCore::XRN
-{
-
-}
+namespace hCore::XRN {}
diff --git a/Private/Source/Heap.cxx b/Private/Source/Heap.cxx
deleted file mode 100644
index ea667a5c..00000000
--- a/Private/Source/Heap.cxx
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * ========================================================
- *
- * hCore
- * Copyright 2024 Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
-
-#include <NewKit/Heap.hpp>
-#include <NewKit/PageManager.hpp>
-
-/// @file Heap.cxx
-/// @brief hCore Process Heap Manager
-/// @note if you want to look at kernel allocs, please look for KHeap.cxx
-/// bugs: 0
-
-namespace hCore
-{
- class HeapManager final
- {
- public:
- static SizeT& GetCount() { return s_NumPools; }
- static Ref<Pmm>& GetPmm() { return s_Pmm; }
- static Boolean& IsEnabled() { return s_PoolsAreEnabled; }
- static Array<Ref<PTEWrapper*>, kPoolMaxSz>& The() { return s_Pool; }
-
- private:
- static Size s_NumPools;
- static Ref<Pmm> s_Pmm;
-
- private:
- static Boolean s_PoolsAreEnabled;
- static Array<Ref<PTEWrapper*>, kPoolMaxSz> s_Pool;
-
- };
-
- //! declare fields
-
- SizeT HeapManager::s_NumPools = 0UL;
- Ref<Pmm> HeapManager::s_Pmm;
- Boolean HeapManager::s_PoolsAreEnabled = true;
- Array<Ref<PTEWrapper*>, kPoolMaxSz> HeapManager::s_Pool;
-
- static voidPtr rt_find_unused_heap(Int flags);
- static void rt_free_heap_internal(voidPtr vaddr);
- static voidPtr rt_make_heap(voidPtr vaddr, Int flags);
- static bool rt_check_and_free_heap(const SizeT &index, voidPtr ptr);
-
- static voidPtr rt_find_unused_heap(Int flags)
- {
- for (SizeT index = 0; index < kPoolMaxSz; ++index)
- {
- if (HeapManager::The()[index] &&
- !HeapManager::The()[index].Leak().Leak().Leak()->Present())
- {
- HeapManager::GetPmm().Leak().TogglePresent(HeapManager::The()[index].Leak().Leak(), true);
- kcout << "[rt_find_unused_heap] Done, trying now to make a pool\r\n";
-
- return rt_make_heap((voidPtr)HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress(), flags);
- }
- }
-
- return nullptr;
- }
-
- static voidPtr rt_make_heap(voidPtr virtualAddress, Int flags)
- {
- if (virtualAddress)
- {
- HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(virtualAddress);
-
- if (!pool_hdr->Free)
- {
- kcout << "[rt_make_heap] pool_hdr->Free, Pool already exists\n";
- return nullptr;
- }
-
- pool_hdr->Flags = flags;
- pool_hdr->Magic = kPoolMag;
- pool_hdr->Free = false;
-
- kcout << "[rt_make_heap] New allocation has been done.\n";
- return reinterpret_cast<voidPtr>((reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(HeapHeader)));
- }
-
- kcout << "[rt_make_heap] Address is invalid";
- return nullptr;
- }
-
- static void rt_free_heap_internal(voidPtr virtualAddress)
- {
- HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader));
-
- if (pool_hdr->Magic == kPoolMag)
- {
- pool_hdr->Free = false;
- pool_hdr->Flags = 0;
-
- kcout << "[rt_free_heap_internal] Successfully marked header as free!\r\n";
- }
- }
-
- static bool rt_check_and_free_heap(const SizeT& index, voidPtr ptr)
- {
- if (HeapManager::The()[index])
- {
- // ErrorOr<>::operator bool
- if (!HeapManager::The()[index].Leak().Leak().IsStrong())
- {
- // we want them to be weak
- // because we allocated it.
- if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() == (UIntPtr) ptr)
- {
- HeapManager::GetPmm().Leak().FreePage(HeapManager::The()[index].Leak().Leak());
- --HeapManager::GetCount();
-
- rt_free_heap_internal(ptr);
- ptr = nullptr;
-
- return true;
- }
- }
- }
-
- return false;
- }
-
- /// @brief Creates a new pool pointer.
- /// @param flags the flags attached to it.
- /// @return a pool pointer with selected permissions.
- voidPtr pool_new_ptr(Int32 flags)
- {
- if (!HeapManager::IsEnabled())
- return nullptr;
-
- if (HeapManager::GetCount() > kPoolMaxSz)
- return nullptr;
-
- if (voidPtr ret = rt_find_unused_heap(flags))
- return ret;
-
- // this wasn't set to true
- auto ref_page = HeapManager::GetPmm().Leak().RequestPage(((flags & kPoolUser)),
- (flags & kPoolRw));
- if (ref_page)
- {
- ///! reserve page.
- HeapManager::The()[HeapManager::GetCount()].Leak() = ref_page;
- auto& ref = HeapManager::GetCount();
- ++ref; // increment the number of addresses we have now.
-
- kcout << "[pool_new_ptr] New Address found!\r\n";
-
- // finally make the pool address.
- return rt_make_heap(reinterpret_cast<voidPtr>(ref_page.Leak()->VirtualAddress()), flags);
- }
-
- return nullptr;
- }
-
- /// @brief free a pool pointer.
- /// @param ptr The pool pointer to free.
- /// @return status code
- Int32 pool_free_ptr(voidPtr ptr)
- {
- if (!HeapManager::IsEnabled())
- return -1;
-
- if (ptr)
- {
- SizeT base = HeapManager::GetCount();
-
- if (rt_check_and_free_heap(base, ptr))
- return 0;
-
- for (SizeT index = 0; index < kPoolMaxSz; ++index)
- {
- if (rt_check_and_free_heap(index, ptr))
- return 0;
-
- --base;
- }
- }
-
- return -1;
- }
-
- /// @brief Checks if pointer is valid.
- /// @param thePool the pool pointer.
- /// @param thePtr the pointer.
- /// @param theLimit the last address of the pool.
- /// @return if it is valid.
- Boolean pool_ptr_exists(UIntPtr thePool, UIntPtr thePtr, SizeT theLimit)
- {
- if (HeapManager::GetCount() < 1)
- return false;
-
- if (thePool == 0 ||
- thePtr == 0 ||
- theLimit == 0)
- {
- return false;
- }
-
- return ((thePool) < (thePtr) < (theLimit));
- }
-} // namespace hCore
diff --git a/Private/Source/IndexableProperty.cxx b/Private/Source/IndexableProperty.cxx
index 5b49d6c1..2dac5a09 100644
--- a/Private/Source/IndexableProperty.cxx
+++ b/Private/Source/IndexableProperty.cxx
@@ -9,20 +9,18 @@
//! @brief hCore NewFS Indexer.
-#include <FSKit/IndexableProperty.hxx>
#include <CompilerKit/Compiler.hpp>
+#include <FSKit/IndexableProperty.hxx>
#include <NewKit/MutableArray.hpp>
#include <NewKit/Utils.hpp>
#define kMaxLenIndexer 256
-namespace hCore
-{
- namespace Indexer
- {
- IndexProperty& IndexableProperty::LeakProperty() noexcept { return fIndex; }
+namespace hCore {
+namespace Indexer {
+IndexProperty& IndexableProperty::LeakProperty() noexcept { return fIndex; }
- void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; }
- void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; }
- }
-}
+void IndexableProperty::AddFlag(Int16 flag) { fFlags |= flag; }
+void IndexableProperty::RemoveFlag(Int16 flag) { fFlags &= flag; }
+} // namespace Indexer
+} // namespace hCore
diff --git a/Private/Source/KHeap.cxx b/Private/Source/KHeap.cxx
deleted file mode 100644
index c36c6ad7..00000000
--- a/Private/Source/KHeap.cxx
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * ========================================================
- *
- * hCore
- * Copyright 2024 Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
-
-#include <NewKit/KHeap.hpp>
-
-//! @file KHeap.cpp
-//! @brief this allocator is used by kernel to allocate pages.
-
-#define kMaxWrappers (4096 * 8)
-
-namespace hCore
-{
-static Ref<PTEWrapper *> kWrapperList[kMaxWrappers];
-static SizeT kWrapperCount = 0UL;
-static Ref<PTEWrapper *> kLastWrapper;
-static Pmm kPmm;
-
-namespace Detail
-{
-static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user)
-{
- for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper)
- {
- if (!kWrapperList[indexWrapper]->Present())
- {
- kWrapperList[indexWrapper]->Reclaim(); /* very straight-forward as you can see. */
- return reinterpret_cast<voidPtr>(kWrapperList[indexWrapper]->VirtualAddress());
- }
- }
-
- return nullptr;
-}
-} // namespace Detail
-
-/// @brief manual allocation
-/// @param sz size of pointer
-/// @param rw read write (true to enable it)
-/// @param user is it accesible by user processes?
-/// @return the pointer
-VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user)
-{
- if (kWrapperCount < sz)
- return nullptr;
-
- if (auto ptr = Detail::find_ptr(sz, rw, user); ptr)
- return ptr;
-
- Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw);
-
- if (wrapper)
- {
- kLastWrapper = wrapper;
-
- kWrapperList[kWrapperCount] = wrapper;
- ++kWrapperCount;
-
- return reinterpret_cast<voidPtr>(wrapper->VirtualAddress());
- }
-
- return nullptr;
-}
-
-/// @brief Declare pointer as free.
-/// @param ptr the pointer.
-/// @return
-Int32 kernel_delete_ptr(voidPtr ptr)
-{
- if (ptr)
- {
- const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
-
- if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress())
- {
- return kPmm.FreePage(kLastWrapper);
- }
-
- Ref<PTEWrapper *> wrapper;
-
- for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper)
- {
- if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress)
- {
- wrapper = kWrapperList[indexWrapper];
- return kPmm.FreePage(wrapper);
- }
- }
- }
-
- return -1;
-}
-
-/// @brief find pointer in kernel heap
-/// @param ptr the pointer
-/// @return if it exists.
-Boolean kernel_valid_ptr(voidPtr ptr)
-{
- if (ptr)
- {
- const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
-
- if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress())
- {
- return true;
- }
-
- Ref<PTEWrapper *> wrapper;
-
- for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper)
- {
- if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress)
- {
- wrapper = kWrapperList[indexWrapper];
- return true;
- }
- }
- }
-
- return false;
-}
-} // namespace hCore
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
new file mode 100644
index 00000000..02688a2f
--- /dev/null
+++ b/Private/Source/KernelHeap.cxx
@@ -0,0 +1,109 @@
+/*
+ * ========================================================
+ *
+ * hCore
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <NewKit/KernelHeap.hpp>
+
+//! @file KernelHeap.cpp
+//! @brief Kernel allocator.
+
+#define kMaxWrappers (4096 * 8)
+
+namespace hCore {
+static Ref<PTEWrapper *> kWrapperList[kMaxWrappers];
+static SizeT kWrapperCount = 0UL;
+static Ref<PTEWrapper *> kLastWrapper;
+static Pmm kPmm;
+
+namespace Detail {
+static voidPtr find_ptr(const SizeT &sz, const bool rw, const bool user) {
+ for (SizeT indexWrapper = 0; indexWrapper < kMaxWrappers; ++indexWrapper) {
+ if (!kWrapperList[indexWrapper]->Present()) {
+ kWrapperList[indexWrapper]
+ ->Reclaim(); /* very straight-forward as you can see. */
+ return reinterpret_cast<voidPtr>(
+ kWrapperList[indexWrapper]->VirtualAddress());
+ }
+ }
+
+ return nullptr;
+}
+} // namespace Detail
+
+/// @brief manual allocation
+/// @param sz size of pointer
+/// @param rw read write (true to enable it)
+/// @param user is it accesible by user processes?
+/// @return the pointer
+VoidPtr kernel_new_ptr(const SizeT &sz, const bool rw, const bool user) {
+ if (kWrapperCount < sz) return nullptr;
+
+ if (auto ptr = Detail::find_ptr(sz, rw, user); ptr) return ptr;
+
+ Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw);
+
+ if (wrapper) {
+ kLastWrapper = wrapper;
+
+ kWrapperList[kWrapperCount] = wrapper;
+ ++kWrapperCount;
+
+ return reinterpret_cast<voidPtr>(wrapper->VirtualAddress());
+ }
+
+ return nullptr;
+}
+
+/// @brief Declare pointer as free.
+/// @param ptr the pointer.
+/// @return
+Int32 kernel_delete_ptr(voidPtr ptr) {
+ if (ptr) {
+ const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
+
+ if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
+ return kPmm.FreePage(kLastWrapper);
+ }
+
+ Ref<PTEWrapper *> wrapper;
+
+ for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) {
+ if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) {
+ wrapper = kWrapperList[indexWrapper];
+ return kPmm.FreePage(wrapper);
+ }
+ }
+ }
+
+ return -1;
+}
+
+/// @brief find pointer in kernel heap
+/// @param ptr the pointer
+/// @return if it exists.
+Boolean kernel_valid_ptr(voidPtr ptr) {
+ if (ptr) {
+ const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
+
+ if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
+ return true;
+ }
+
+ Ref<PTEWrapper *> wrapper;
+
+ for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) {
+ if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) {
+ wrapper = kWrapperList[indexWrapper];
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+} // namespace hCore
diff --git a/Private/Source/LockDelegate.cxx b/Private/Source/LockDelegate.cxx
index 7bc742ec..d6608e60 100644
--- a/Private/Source/LockDelegate.cxx
+++ b/Private/Source/LockDelegate.cxx
@@ -7,4 +7,4 @@
* ========================================================
*/
-#include <NewKit/LockDelegate.hpp> \ No newline at end of file
+#include <NewKit/LockDelegate.hpp>
diff --git a/Private/Source/Network/IP.cpp b/Private/Source/Network/IP.cpp
index ba6fd71f..4e8f602a 100644
--- a/Private/Source/Network/IP.cpp
+++ b/Private/Source/Network/IP.cpp
@@ -10,118 +10,86 @@
#include <NetworkKit/IP.hpp>
#include <NewKit/Utils.hpp>
-namespace hCore
-{
- char* RawIPAddress::Address()
- {
- return m_Addr;
- }
+namespace hCore {
+char* RawIPAddress::Address() { return m_Addr; }
- RawIPAddress::RawIPAddress(char bytes[4])
- {
- rt_copy_memory(bytes, m_Addr, 4);
- }
+RawIPAddress::RawIPAddress(char bytes[4]) { rt_copy_memory(bytes, m_Addr, 4); }
- bool RawIPAddress::operator==(const RawIPAddress& ipv4)
- {
- for (Size index = 0; index < 4; ++index)
- {
- if (ipv4.m_Addr[index] != m_Addr[index])
- return false;
- }
+bool RawIPAddress::operator==(const RawIPAddress& ipv4) {
+ for (Size index = 0; index < 4; ++index) {
+ if (ipv4.m_Addr[index] != m_Addr[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- bool RawIPAddress::operator!=(const RawIPAddress& ipv4)
- {
- for (Size index = 0; index < 4; ++index)
- {
- if (ipv4.m_Addr[index] == m_Addr[index])
- return false;
- }
+bool RawIPAddress::operator!=(const RawIPAddress& ipv4) {
+ for (Size index = 0; index < 4; ++index) {
+ if (ipv4.m_Addr[index] == m_Addr[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- char& RawIPAddress::operator[](const Size& index)
- {
- kcout << "[RawIPAddress::operator[]] Fetching Index...\r\n";
+char& RawIPAddress::operator[](const Size& index) {
+ kcout << "[RawIPAddress::operator[]] Fetching Index...\r\n";
- if (index > 4)
- panic(RUNTIME_CHECK_EXPRESSION);
+ if (index > 4) panic(RUNTIME_CHECK_EXPRESSION);
- return m_Addr[index];
- }
+ return m_Addr[index];
+}
- RawIPAddress6::RawIPAddress6(char bytes[8])
- {
- rt_copy_memory(bytes, m_Addr, 8);
- }
+RawIPAddress6::RawIPAddress6(char bytes[8]) {
+ rt_copy_memory(bytes, m_Addr, 8);
+}
- char &RawIPAddress6::operator[](const Size &index)
- {
- kcout << "[RawIPAddress6::operator[]] Fetching Index...\r\n";
+char& RawIPAddress6::operator[](const Size& index) {
+ kcout << "[RawIPAddress6::operator[]] Fetching Index...\r\n";
- if (index > 8)
- panic(RUNTIME_CHECK_EXPRESSION);
+ if (index > 8) panic(RUNTIME_CHECK_EXPRESSION);
- return m_Addr[index];
- }
+ return m_Addr[index];
+}
- bool RawIPAddress6::operator==(const RawIPAddress6& ipv6)
- {
- for (SizeT index = 0; index < 8; ++index)
- {
- if (ipv6.m_Addr[index] != m_Addr[index])
- return false;
- }
+bool RawIPAddress6::operator==(const RawIPAddress6& ipv6) {
+ for (SizeT index = 0; index < 8; ++index) {
+ if (ipv6.m_Addr[index] != m_Addr[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6)
- {
- for (SizeT index = 0; index < 8; ++index)
- {
- if (ipv6.m_Addr[index] == m_Addr[index])
- return false;
- }
+bool RawIPAddress6::operator!=(const RawIPAddress6& ipv6) {
+ for (SizeT index = 0; index < 8; ++index) {
+ if (ipv6.m_Addr[index] == m_Addr[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6> ipv6)
- {
- auto str = StringBuilder::Construct(ipv6.Leak().Address());
- return str;
- }
+ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress6> ipv6) {
+ auto str = StringBuilder::Construct(ipv6.Leak().Address());
+ return str;
+}
- ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4)
- {
- auto str = StringBuilder::Construct(ipv4.Leak().Address());
- return str;
- }
+ErrorOr<StringView> IPFactory::ToStringView(Ref<RawIPAddress> ipv4) {
+ auto str = StringBuilder::Construct(ipv4.Leak().Address());
+ return str;
+}
- bool IPFactory::IpCheckVersion4(const char *ip)
- {
- int cnter = 0;
-
- for (Size base = 0; base < string_length(ip); ++base)
- {
- if (ip[base] == '.')
- {
- cnter = 0;
- }
- else
- {
- if (cnter == 3)
- return false;
-
- ++cnter;
- }
- }
-
- return true;
+bool IPFactory::IpCheckVersion4(const char* ip) {
+ int cnter = 0;
+
+ for (Size base = 0; base < string_length(ip); ++base) {
+ if (ip[base] == '.') {
+ cnter = 0;
+ } else {
+ if (cnter == 3) return false;
+
+ ++cnter;
}
-} // namespace NewKit
+ }
+
+ return true;
+}
+} // namespace hCore
diff --git a/Private/Source/Network/NetworkDevice.cpp b/Private/Source/Network/NetworkDevice.cpp
index 766e1f2e..bd75d7ed 100644
--- a/Private/Source/Network/NetworkDevice.cpp
+++ b/Private/Source/Network/NetworkDevice.cpp
@@ -12,23 +12,21 @@
// network devices implementation.
// PPPNetworkService, TCPNetworkDevice, UDPNetworkService
-namespace hCore
-{
- NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand), void (*in)(NetworkDeviceCommand), void(*on_cleanup)(void))
- : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup)
- {
+namespace hCore {
+NetworkDevice::NetworkDevice(void (*out)(NetworkDeviceCommand),
+ void (*in)(NetworkDeviceCommand),
+ void (*on_cleanup)(void))
+ : DeviceInterface<NetworkDeviceCommand>(out, in), fCleanup(on_cleanup) {
#ifdef __DEBUG__
- kcout << "NetworkDevice init.\r\n";
+ kcout << "NetworkDevice init.\r\n";
#endif
- }
+}
- NetworkDevice::~NetworkDevice()
- {
+NetworkDevice::~NetworkDevice() {
#ifdef __DEBUG__
- kcout << "NetworkDevice cleanup.\r\n";
+ kcout << "NetworkDevice cleanup.\r\n";
#endif
- if (fCleanup)
- fCleanup();
- }
-} // namespace NewKit
+ if (fCleanup) fCleanup();
+}
+} // namespace hCore
diff --git a/Private/Source/New+Delete.cxx b/Private/Source/New+Delete.cxx
index ff2bf8bb..0e247e0c 100644
--- a/Private/Source/New+Delete.cxx
+++ b/Private/Source/New+Delete.cxx
@@ -7,7 +7,7 @@
* ========================================================
*/
-#include <NewKit/KHeap.hpp>
+#include <NewKit/KernelHeap.hpp>
#include <NewKit/New.hpp>
void* operator new[](size_t sz)
diff --git a/Private/Source/NewFS-Journal.cxx b/Private/Source/NewFS-Journal.cxx
index 9c96928d..14ba417f 100644
--- a/Private/Source/NewFS-Journal.cxx
+++ b/Private/Source/NewFS-Journal.cxx
@@ -14,54 +14,46 @@
#define kOpCache (4)
-namespace hCore
-{
- typedef Boolean(*NewFSRunner)(VoidPtr delegate);
-
- class NewFSJournalRunner final
- {
- public:
- NewFSRunner fLoadRoutine{ nullptr };
- NewFSRunner fCacheRoutine{ nullptr };
- NewFSRunner fUnloadRoutine{ nullptr };
-
- explicit NewFSJournalRunner(NewFSRunner load_runner)
- : fLoadRoutine(load_runner)
- {
- MUST_PASS(fLoadRoutine);
-
- fLoadRoutine(this);
- }
-
- ~NewFSJournalRunner() noexcept
- {
- MUST_PASS(fUnloadRoutine);
-
- fUnloadRoutine(this);
- }
-
- HCORE_COPY_DEFAULT(NewFSJournalRunner);
-
- public:
- Boolean Run(const Int32& operation, VoidPtr class_ptr)
- {
- switch (operation)
- {
- case kOpCache:
- {
- if (!class_ptr)
- {
- kcout << "Miss for class_ptr at NewFSJournalManager::Run(class_ptr) " << __FILE__ << "\n";
- return false;
- }
+namespace hCore {
+typedef Boolean (*NewFSRunner)(VoidPtr delegate);
- MUST_PASS(fCacheRoutine);
- return fCacheRoutine(class_ptr);
- }
- };
-
- return false;
- }
-
+class NewFSJournalRunner final {
+ public:
+ NewFSRunner fLoadRoutine{nullptr};
+ NewFSRunner fCacheRoutine{nullptr};
+ NewFSRunner fUnloadRoutine{nullptr};
+
+ explicit NewFSJournalRunner(NewFSRunner load_runner)
+ : fLoadRoutine(load_runner) {
+ MUST_PASS(fLoadRoutine);
+
+ fLoadRoutine(this);
+ }
+
+ ~NewFSJournalRunner() noexcept {
+ MUST_PASS(fUnloadRoutine);
+
+ fUnloadRoutine(this);
+ }
+
+ HCORE_COPY_DEFAULT(NewFSJournalRunner);
+
+ public:
+ Boolean Run(const Int32& operation, VoidPtr class_ptr) {
+ switch (operation) {
+ case kOpCache: {
+ if (!class_ptr) {
+ kcout << "Miss for class_ptr at NewFSJournalManager::Run(class_ptr) "
+ << __FILE__ << "\n";
+ return false;
+ }
+
+ MUST_PASS(fCacheRoutine);
+ return fCacheRoutine(class_ptr);
+ }
};
-} // namespace hCore
+
+ return false;
+ }
+};
+} // namespace hCore
diff --git a/Private/Source/NewFS.cxx b/Private/Source/NewFS.cxx
index cd787e9b..2283e779 100644
--- a/Private/Source/NewFS.cxx
+++ b/Private/Source/NewFS.cxx
@@ -10,42 +10,34 @@
#include <FSKit/NewFS.hxx>
#include <KernelKit/FileManager.hpp>
-namespace hCore
-{
- NewFilesystemManager::NewFilesystemManager() = default;
-
- NewFilesystemManager::~NewFilesystemManager() = default;
-
- /**
- * Unallocates a file from disk.
- * @param node_name it's path.
- * @return operation status boolean.
- */
- bool NewFilesystemManager::Remove(const char* node_name)
- {
- if (node_name == nullptr ||
- *node_name == 0)
- return false;
-
- if (auto catalog = fIO->GetCatalog(node_name);
- catalog)
- return fIO->RemoveCatalog(*catalog);
-
- return false;
- }
-
- NodePtr NewFilesystemManager::Create(const char* path)
- {
- return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindFile));
- }
-
- NodePtr NewFilesystemManager::CreateDirectory(const char *path)
- {
- return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindDir));
- }
-
- NodePtr NewFilesystemManager::CreateAlias(const char *path)
- {
- return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindAlias));
- }
-} // namespace hCore
+namespace hCore {
+NewFilesystemManager::NewFilesystemManager() = default;
+
+NewFilesystemManager::~NewFilesystemManager() = default;
+
+/**
+ * Unallocates a file from disk.
+ * @param node_name it's path.
+ * @return operation status boolean.
+ */
+bool NewFilesystemManager::Remove(const char* node_name) {
+ if (node_name == nullptr || *node_name == 0) return false;
+
+ if (auto catalog = fIO->GetCatalog(node_name); catalog)
+ return fIO->RemoveCatalog(*catalog);
+
+ return false;
+}
+
+NodePtr NewFilesystemManager::Create(const char* path) {
+ return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindFile));
+}
+
+NodePtr NewFilesystemManager::CreateDirectory(const char* path) {
+ return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindDir));
+}
+
+NodePtr NewFilesystemManager::CreateAlias(const char* path) {
+ return node_cast(fIO->CreateCatalog(path, 0, kCatalogKindAlias));
+}
+} // namespace hCore
diff --git a/Private/Source/OSErr.cxx b/Private/Source/OSErr.cxx
index 810b77b7..6c37c40d 100644
--- a/Private/Source/OSErr.cxx
+++ b/Private/Source/OSErr.cxx
@@ -8,4 +8,3 @@
*/
#include <KernelKit/OSErr.hpp>
-
diff --git a/Private/Source/OwnPtr.cxx b/Private/Source/OwnPtr.cxx
index 79a9a368..f7f9d31f 100644
--- a/Private/Source/OwnPtr.cxx
+++ b/Private/Source/OwnPtr.cxx
@@ -7,4 +7,4 @@
* ========================================================
*/
-#include <NewKit/OwnPtr.hpp> \ No newline at end of file
+#include <NewKit/OwnPtr.hpp>
diff --git a/Private/Source/PRDT.cxx b/Private/Source/PRDT.cxx
index 7e74c200..8ea2ee70 100644
--- a/Private/Source/PRDT.cxx
+++ b/Private/Source/PRDT.cxx
@@ -8,42 +8,28 @@
*/
#include <KernelKit/DebugOutput.hpp>
-#include <StorageKit/PRDT.hpp>
#include <NewKit/String.hpp>
+#include <StorageKit/PRDT.hpp>
-namespace hCore
-{
- PRDT::PRDT(const UIntPtr &physAddr)
- : m_PrdtAddr(physAddr)
- {
- MUST_PASS(physAddr);
- kcout << "PRDT::PRDT() {}\r\n";
- }
+namespace hCore {
+PRDT::PRDT(const UIntPtr& physAddr) : m_PrdtAddr(physAddr) {
+ MUST_PASS(physAddr);
+ kcout << "PRDT::PRDT() {}\r\n";
+}
- PRDT::~PRDT()
- {
- kcout << "PRDT::~PRDT() {}\r\n";
- m_PrdtAddr = 0;
- }
+PRDT::~PRDT() {
+ kcout << "PRDT::~PRDT() {}\r\n";
+ m_PrdtAddr = 0;
+}
- const UInt& PRDT::Low()
- {
- return m_Low;
- }
+const UInt& PRDT::Low() { return m_Low; }
- const UShort& PRDT::High()
- {
- return m_High;
- }
+const UShort& PRDT::High() { return m_High; }
- const UIntPtr& PRDT::PhysicalAddress()
- {
- return m_PrdtAddr;
- }
+const UIntPtr& PRDT::PhysicalAddress() { return m_PrdtAddr; }
- PRDT& PRDT::operator=(const UIntPtr& prdtAddress)
- {
- m_PrdtAddr = prdtAddress;
- return *this;
- }
-} // namespace hCore
+PRDT& PRDT::operator=(const UIntPtr& prdtAddress) {
+ m_PrdtAddr = prdtAddress;
+ return *this;
+}
+} // namespace hCore
diff --git a/Private/Source/PageAllocator.cxx b/Private/Source/PageAllocator.cxx
index e29710dd..59ad6b28 100644
--- a/Private/Source/PageAllocator.cxx
+++ b/Private/Source/PageAllocator.cxx
@@ -12,45 +12,39 @@
#include <NewKit/PageAllocator.hpp>
// empty for now.
-namespace hCore::Detail
-{
- UIntPtr create_page_wrapper(Boolean rw, Boolean user)
- {
- auto addr = HAL::hal_create_page(rw, user);
-
- if (addr == kBadAddress)
- {
- kcout << "[create_page_wrapper] kBadAddress returned\n";
- panic(RUNTIME_CHECK_POINTER);
- }
-
- return addr;
- }
-
- void exec_disable(UIntPtr VirtualAddr)
- {
- PTE *VirtualAddrTable = reinterpret_cast<PTE*>(VirtualAddr);
- MUST_PASS(!VirtualAddrTable->Accessed);
- VirtualAddrTable->ExecDisable = true;
-
- flush_tlb(VirtualAddr);
- }
-
- bool page_disable(UIntPtr VirtualAddr)
- {
- if (VirtualAddr) {
- auto VirtualAddrTable = (PTE * )(VirtualAddr);
- MUST_PASS(!VirtualAddrTable->Accessed);
-
- if (VirtualAddrTable->Accessed)
- return false;
- VirtualAddrTable->Present = false;
-
- flush_tlb(VirtualAddr);
-
- return true;
- }
-
- return false;
- }
-} // namespace hCore::Detail
+namespace hCore::Detail {
+UIntPtr create_page_wrapper(Boolean rw, Boolean user) {
+ auto addr = HAL::hal_create_page(rw, user);
+
+ if (addr == kBadAddress) {
+ kcout << "[create_page_wrapper] kBadAddress returned\n";
+ panic(RUNTIME_CHECK_POINTER);
+ }
+
+ return addr;
+}
+
+void exec_disable(UIntPtr VirtualAddr) {
+ PTE *VirtualAddrTable = reinterpret_cast<PTE *>(VirtualAddr);
+ MUST_PASS(!VirtualAddrTable->Accessed);
+ VirtualAddrTable->ExecDisable = true;
+
+ flush_tlb(VirtualAddr);
+}
+
+bool page_disable(UIntPtr VirtualAddr) {
+ if (VirtualAddr) {
+ auto VirtualAddrTable = (PTE *)(VirtualAddr);
+ MUST_PASS(!VirtualAddrTable->Accessed);
+
+ if (VirtualAddrTable->Accessed) return false;
+ VirtualAddrTable->Present = false;
+
+ flush_tlb(VirtualAddr);
+
+ return true;
+ }
+
+ return false;
+}
+} // namespace hCore::Detail
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index fc6b8e80..32c1f22a 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -10,137 +10,114 @@
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/PageManager.hpp>
-namespace hCore
-{
- PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable, UIntPtr VirtAddr)
- : m_Rw(Rw),
- m_User(User),
- m_ExecDisable(ExecDisable),
- m_VirtAddr(VirtAddr),
- m_Cache(false),
- m_Shareable(false),
- m_Wt(false),
- m_Present(true),
- m_Accessed(false)
- {
- // special case for the null region.
- if (VirtAddr == 0)
- {
- m_Wt = false;
- m_Rw = false;
- m_Cache = false;
- m_Shareable = false;
- }
- }
-
- PTEWrapper::~PTEWrapper()
- {
- PTE* raw = reinterpret_cast<PTE*>(m_VirtAddr);
-
- MUST_PASS(raw);
- MUST_PASS(!raw->Accessed);
-
- if (raw->Present)
- raw->Present = false;
- }
-
- void PTEWrapper::FlushTLB(Ref<PageManager> &pm)
- {
- pm.Leak().FlushTLB(this->m_VirtAddr);
- }
-
- void PageManager::FlushTLB(UIntPtr VirtAddr)
- {
- if (VirtAddr == kBadAddress)
- return;
-
- flush_tlb(VirtAddr);
- }
-
- bool PTEWrapper::Reclaim()
- {
- if (!this->m_Present)
- {
- this->m_Present = true;
- return true;
- }
-
- return false;
- }
-
- PTEWrapper *PageManager::Request(Boolean Rw, Boolean User, Boolean ExecDisable)
- {
- PTEWrapper *PageTableEntry =
- reinterpret_cast<PTEWrapper*>(hCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User));
-
- if (PageTableEntry == nullptr) {
- kcout << "PTEWrapper : Page table is nullptr!, kernel_new_ptr failed!";
- return nullptr;
- }
-
- *PageTableEntry = PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)};
- return PageTableEntry;
- }
-
- bool PageManager::Free(Ref<PTEWrapper*> &wrapper)
- {
- if (wrapper) {
- if (!Detail::page_disable(wrapper->VirtualAddress()))
- return false;
-
- this->FlushTLB(wrapper->VirtualAddress());
- return true;
- }
-
- return false;
- }
-
- const UIntPtr &PTEWrapper::VirtualAddress()
- {
- return m_VirtAddr;
- }
-
- bool PTEWrapper::Shareable()
- {
- auto raw = reinterpret_cast<PTE*>(m_VirtAddr);
-
- if (raw->Present)
- {
- m_Shareable = raw->Shared;
- return m_Shareable;
- }
- else
- {
- kcout << "[PTEWrapper::Shareable] page is not present!";
- return false;
- }
- }
-
- bool PTEWrapper::Present()
- {
- auto raw = reinterpret_cast<PTE*>(m_VirtAddr);
-
- if (raw->Present)
- {
- m_Present = raw->Present;
- return m_Present;
- }
- else
- {
- kcout << "[PTEWrapper::Present] page is not present!";
- return false;
- }
- }
-
- bool PTEWrapper::Access()
- {
- auto raw = reinterpret_cast<PTE*>(m_VirtAddr);
-
- if (raw->Present)
- {
- m_Accessed = raw->Accessed;
- }
-
- return m_Accessed;
- }
-} // namespace hCore
+namespace hCore {
+PTEWrapper::PTEWrapper(Boolean Rw, Boolean User, Boolean ExecDisable,
+ UIntPtr VirtAddr)
+ : m_Rw(Rw),
+ m_User(User),
+ m_ExecDisable(ExecDisable),
+ m_VirtAddr(VirtAddr),
+ m_Cache(false),
+ m_Shareable(false),
+ m_Wt(false),
+ m_Present(true),
+ m_Accessed(false) {
+ // special case for the null region.
+ if (VirtAddr == 0) {
+ m_Wt = false;
+ m_Rw = false;
+ m_Cache = false;
+ m_Shareable = false;
+ }
+}
+
+PTEWrapper::~PTEWrapper() {
+ PTE *raw = reinterpret_cast<PTE *>(m_VirtAddr);
+
+ MUST_PASS(raw);
+ MUST_PASS(!raw->Accessed);
+
+ if (raw->Present) raw->Present = false;
+}
+
+void PTEWrapper::FlushTLB(Ref<PageManager> &pm) {
+ pm.Leak().FlushTLB(this->m_VirtAddr);
+}
+
+void PageManager::FlushTLB(UIntPtr VirtAddr) {
+ if (VirtAddr == kBadAddress) return;
+
+ flush_tlb(VirtAddr);
+}
+
+bool PTEWrapper::Reclaim() {
+ if (!this->m_Present) {
+ this->m_Present = true;
+ return true;
+ }
+
+ return false;
+}
+
+PTEWrapper *PageManager::Request(Boolean Rw, Boolean User,
+ Boolean ExecDisable) {
+ PTEWrapper *PageTableEntry = reinterpret_cast<PTEWrapper *>(
+ hCore::HAL::hal_alloc_page(sizeof(PTEWrapper), Rw, User));
+
+ if (PageTableEntry == nullptr) {
+ kcout << "PTEWrapper : Page table is nullptr!, kernel_new_ptr failed!";
+ return nullptr;
+ }
+
+ *PageTableEntry =
+ PTEWrapper{Rw, User, ExecDisable, Detail::create_page_wrapper(Rw, User)};
+ return PageTableEntry;
+}
+
+bool PageManager::Free(Ref<PTEWrapper *> &wrapper) {
+ if (wrapper) {
+ if (!Detail::page_disable(wrapper->VirtualAddress())) return false;
+
+ this->FlushTLB(wrapper->VirtualAddress());
+ return true;
+ }
+
+ return false;
+}
+
+const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; }
+
+bool PTEWrapper::Shareable() {
+ auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
+
+ if (raw->Present) {
+ m_Shareable = raw->Shared;
+ return m_Shareable;
+ } else {
+ kcout << "[PTEWrapper::Shareable] page is not present!";
+ return false;
+ }
+}
+
+bool PTEWrapper::Present() {
+ auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
+
+ if (raw->Present) {
+ m_Present = raw->Present;
+ return m_Present;
+ } else {
+ kcout << "[PTEWrapper::Present] page is not present!";
+ return false;
+ }
+}
+
+bool PTEWrapper::Access() {
+ auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
+
+ if (raw->Present) {
+ m_Accessed = raw->Accessed;
+ }
+
+ return m_Accessed;
+}
+} // namespace hCore
diff --git a/Private/Source/Panic.cxx b/Private/Source/Panic.cxx
index 46e184d3..9e3dddfb 100644
--- a/Private/Source/Panic.cxx
+++ b/Private/Source/Panic.cxx
@@ -7,50 +7,43 @@
* ========================================================
*/
-#include <NewKit/Panic.hpp>
#include <ArchKit/Arch.hpp>
-#include <NewKit/String.hpp>
-
#include <KernelKit/DebugOutput.hpp>
+#include <NewKit/Panic.hpp>
+#include <NewKit/String.hpp>
-extern "C" [[noreturn]] void wait_for_debugger()
-{
- while (true)
- {
- hCore::HAL::rt_cli();
- hCore::HAL::rt_halt();
- }
+extern "C" [[noreturn]] void wait_for_debugger() {
+ while (true) {
+ hCore::HAL::rt_cli();
+ hCore::HAL::rt_halt();
+ }
}
/* Each error code is attributed with an ID, which will prompt a string onto the
* screen. Wait for debugger... */
-namespace hCore
-{
- void panic(const hCore::Int& id)
- {
+namespace hCore {
+void panic(const hCore::Int &id) {
#ifdef __DEBUG__
- kcout << "hCore: Kernel Panic! \r\n";
- kcout << StringBuilder::FromInt("kError : %\n", id);
+ kcout << "hCore: Kernel Panic! \r\n";
+ kcout << StringBuilder::FromInt("kError : %\n", id);
- DumpManager::Dump();
-#endif // __DEBUG__
+ DumpManager::Dump();
+#endif // __DEBUG__
- wait_for_debugger();
- }
+ wait_for_debugger();
+}
- void runtime_check(bool expr, const char *file, const char *line)
- {
- if (!expr)
- {
+void runtime_check(bool expr, const char *file, const char *line) {
+ if (!expr) {
#ifdef __DEBUG__
- kcout << "[KERNEL] Check Failed!\n";
- kcout << "[KERNEL] File: " << file << "\n";
- kcout << "[KERNEL] Where: " << line << "\n";
+ kcout << "[KERNEL] Check Failed!\n";
+ kcout << "[KERNEL] File: " << file << "\n";
+ kcout << "[KERNEL] Where: " << line << "\n";
-#endif // __DEBUG__
+#endif // __DEBUG__
- hCore::panic(RUNTIME_CHECK_FAILED); // Runtime Check failed
- }
- }
-} // namespace hCore
+ hCore::panic(RUNTIME_CHECK_FAILED); // Runtime Check failed
+ }
+}
+} // namespace hCore
diff --git a/Private/Source/PermissionSelector.cxx b/Private/Source/PermissionSelector.cxx
index 04245502..69bb949b 100644
--- a/Private/Source/PermissionSelector.cxx
+++ b/Private/Source/PermissionSelector.cxx
@@ -13,31 +13,24 @@
#include <KernelKit/PermissionSelector.hxx>
#include <NewKit/Panic.hpp>
-namespace hCore
-{
-PermissionSelector::PermissionSelector(const Int32 &sel) : fRing((RingKind)sel)
-{
- MUST_PASS(sel > 0);
+namespace hCore {
+PermissionSelector::PermissionSelector(const Int32 &sel)
+ : fRing((RingKind)sel) {
+ MUST_PASS(sel > 0);
}
-PermissionSelector::PermissionSelector(const RingKind &ringKind) : fRing(ringKind)
-{
-}
+PermissionSelector::PermissionSelector(const RingKind &ringKind)
+ : fRing(ringKind) {}
PermissionSelector::~PermissionSelector() = default;
-bool PermissionSelector::operator==(const PermissionSelector &lhs)
-{
- return lhs.fRing == this->fRing;
+bool PermissionSelector::operator==(const PermissionSelector &lhs) {
+ return lhs.fRing == this->fRing;
}
-bool PermissionSelector::operator!=(const PermissionSelector &lhs)
-{
- return lhs.fRing != this->fRing;
+bool PermissionSelector::operator!=(const PermissionSelector &lhs) {
+ return lhs.fRing != this->fRing;
}
-const RingKind &PermissionSelector::Ring() noexcept
-{
- return this->fRing;
-}
-} // namespace hCore
+const RingKind &PermissionSelector::Ring() noexcept { return this->fRing; }
+} // namespace hCore
diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx
index 5d4ce965..b87e450b 100644
--- a/Private/Source/Pmm.cxx
+++ b/Private/Source/Pmm.cxx
@@ -10,84 +10,69 @@
#include <KernelKit/DebugOutput.hpp>
#include <NewKit/Pmm.hpp>
-namespace hCore
-{
- Pmm::Pmm() = default;
+namespace hCore {
+Pmm::Pmm() = default;
- Pmm::Pmm(Ref<PageManager*> &pm) : m_PageManager(pm)
- {
- MUST_PASS(pm.Leak());
- kcout << "[PMM] New PhysicalMemoryManager\r\n";
- }
+Pmm::Pmm(Ref<PageManager *> &pm) : m_PageManager(pm) {
+ MUST_PASS(pm.Leak());
+ kcout << "[PMM] New PhysicalMemoryManager\r\n";
+}
- Pmm::~Pmm() = default;
+Pmm::~Pmm() = default;
- /* If this returns Null pointer, enter emergency mode */
- Ref<PTEWrapper*> Pmm::RequestPage(Boolean user, Boolean readWrite)
- {
- if (m_PageManager)
- {
- PTEWrapper *pt = m_PageManager.Leak()->Request(user, readWrite, true);
+/* If this returns Null pointer, enter emergency mode */
+Ref<PTEWrapper *> Pmm::RequestPage(Boolean user, Boolean readWrite) {
+ if (m_PageManager) {
+ PTEWrapper *pt = m_PageManager.Leak()->Request(user, readWrite, true);
- if (pt)
- return Ref<PTEWrapper*>(pt);
+ if (pt) return Ref<PTEWrapper *>(pt);
- return {};
- }
+ return {};
+ }
- kcout << "[Pmm::RequestPage] Ref<PTEWrapper*> could not be created! "
- "m_PageManager is nullptr!\r\n";
+ kcout << "[Pmm::RequestPage] Ref<PTEWrapper*> could not be created! "
+ "m_PageManager is nullptr!\r\n";
- return {};
- }
+ return {};
+}
- Boolean Pmm::FreePage(Ref<PTEWrapper*> PageRef)
- {
- if (!PageRef)
- return false;
+Boolean Pmm::FreePage(Ref<PTEWrapper *> PageRef) {
+ if (!PageRef) return false;
- PageRef->m_Present = false;
+ PageRef->m_Present = false;
- return true;
- }
+ return true;
+}
- Boolean Pmm::TogglePresent(Ref<PTEWrapper*> PageRef, Boolean Enable)
- {
- if (!PageRef)
- return false;
+Boolean Pmm::TogglePresent(Ref<PTEWrapper *> PageRef, Boolean Enable) {
+ if (!PageRef) return false;
- PageRef->m_Present = Enable;
+ PageRef->m_Present = Enable;
- return true;
- }
+ return true;
+}
- Boolean Pmm::ToggleUser(Ref<PTEWrapper*> PageRef, Boolean Enable)
- {
- if (!PageRef)
- return false;
+Boolean Pmm::ToggleUser(Ref<PTEWrapper *> PageRef, Boolean Enable) {
+ if (!PageRef) return false;
- PageRef->m_Rw = Enable;
+ PageRef->m_Rw = Enable;
- return true;
- }
+ return true;
+}
- Boolean Pmm::ToggleRw(Ref<PTEWrapper*> PageRef, Boolean Enable)
- {
- if (!PageRef)
- return false;
+Boolean Pmm::ToggleRw(Ref<PTEWrapper *> PageRef, Boolean Enable) {
+ if (!PageRef) return false;
- PageRef->m_Rw = Enable;
+ PageRef->m_Rw = Enable;
- return true;
- }
+ return true;
+}
- Boolean Pmm::ToggleShare(Ref<PTEWrapper*> PageRef, Boolean Enable)
- {
- if (!PageRef)
- return false;
+Boolean Pmm::ToggleShare(Ref<PTEWrapper *> PageRef, Boolean Enable) {
+ if (!PageRef) return false;
- PageRef->m_Shareable = Enable;
+ PageRef->m_Shareable = Enable;
- return true;
- }
-} // namespace hCore
+ return true;
+}
+} // namespace hCore
diff --git a/Private/Source/ProcessManager.cxx b/Private/Source/ProcessManager.cxx
index 664a1c7c..987b8093 100644
--- a/Private/Source/ProcessManager.cxx
+++ b/Private/Source/ProcessManager.cxx
@@ -10,7 +10,7 @@
#include "NewKit/Panic.hpp"
#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/SMPManager.hpp>
-#include <NewKit/KHeap.hpp>
+#include <NewKit/KernelHeap.hpp>
#include <NewKit/String.hpp>
#define kPoolAlign (4)
diff --git a/Private/Source/Property.cxx b/Private/Source/Property.cxx
index ebb87fb9..f3633598 100644
--- a/Private/Source/Property.cxx
+++ b/Private/Source/Property.cxx
@@ -9,15 +9,10 @@
#include <CFKit/Property.hpp>
-namespace hCore
-{
- bool Property::StringEquals(StringView &name)
- {
- return m_sName && this->m_sName == name;
- }
+namespace hCore {
+bool Property::StringEquals(StringView& name) {
+ return m_sName && this->m_sName == name;
+}
- const PropertyId& Property::GetPropertyById()
- {
- return m_Action;
- }
-} // namespace hCore
+const PropertyId& Property::GetPropertyById() { return m_Action; }
+} // namespace hCore
diff --git a/Private/Source/RuntimeMain.cxx b/Private/Source/RuntimeMain.cxx
index 210a5c43..a2b777d8 100644
--- a/Private/Source/RuntimeMain.cxx
+++ b/Private/Source/RuntimeMain.cxx
@@ -7,7 +7,6 @@
* ========================================================
*/
-#include "NewKit/Defines.hpp"
#include <ArchKit/Arch.hpp>
#include <KernelKit/CodeManager.hpp>
#include <KernelKit/FileManager.hpp>
@@ -17,20 +16,18 @@
extern "C" void (*__SYSTEM_FINI)();
extern "C" void (**__SYSTEM_INIT)();
-extern "C" void RuntimeMain()
-{
- for (hCore::SizeT index_init = 0UL; __SYSTEM_INIT[index_init] != __SYSTEM_FINI; ++index_init)
- {
- __SYSTEM_INIT[index_init]();
- }
+extern "C" void RuntimeMain() {
+ for (hCore::SizeT index_init = 0UL;
+ __SYSTEM_INIT[index_init] != __SYSTEM_FINI; ++index_init) {
+ __SYSTEM_INIT[index_init]();
+ }
- MUST_PASS(hCore::init_hal());
+ MUST_PASS(hCore::init_hal());
- hCore::IFilesystemManager::Mount(new hCore::NewFilesystemManager());
- hCore::PEFLoader img("/System/Seeker.cm");
+ hCore::IFilesystemManager::Mount(new hCore::NewFilesystemManager());
+ hCore::PEFLoader img("/System/Seeker.cm");
- if (!hCore::Utils::execute_from_image(img))
- {
- hCore::panic(RUNTIME_CHECK_BOOTSTRAP);
- }
+ if (!hCore::Utils::execute_from_image(img)) {
+ hCore::panic(RUNTIME_CHECK_BOOTSTRAP);
+ }
}
diff --git a/Private/Source/SMPManager.cxx b/Private/Source/SMPManager.cxx
index 4897165b..05e47ea8 100644
--- a/Private/Source/SMPManager.cxx
+++ b/Private/Source/SMPManager.cxx
@@ -7,144 +7,137 @@
* ========================================================
*/
-#include <KernelKit/SMPManager.hpp>
-#include <KernelKit/ProcessManager.hpp>
#include <ArchKit/Arch.hpp>
+#include <KernelKit/ProcessManager.hpp>
+#include <KernelKit/SMPManager.hpp>
/// BUGS: 0
//! This file handles multi processing in hCore.
//! Multi processing is needed for File I/O, networking and scheduling.
-namespace hCore
-{
- // A ProcessorCore class takes care of it's owned hardware thread.
- // It has a stack for it's core.
+namespace hCore {
+// A ProcessorCore class takes care of it's owned hardware thread.
+// It has a stack for it's core.
+
+// @brief constructor
+ProcessorCore::ProcessorCore() = default;
+
+// @brief destructor
+ProcessorCore::~ProcessorCore() = default;
+
+//! @brief returns the id
- // @brief constructor
- ProcessorCore::ProcessorCore() = default;
+const ThreadID& ProcessorCore::ID() noexcept { return m_ID; }
- // @brief destructor
- ProcessorCore::~ProcessorCore() = default;
-
- //! @brief returns the id
+//! @brief returns the kind
- const ThreadID& ProcessorCore::ID() noexcept { return m_ID; }
-
- //! @brief returns the kind
+const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; }
- const ThreadKind& ProcessorCore::Kind() noexcept { return m_Kind; }
+//! @brief is the core busy?
- //! @brief is the core busy?
+bool ProcessorCore::IsBusy() noexcept { return m_Busy; }
- bool ProcessorCore::IsBusy() noexcept { return m_Busy; }
+/// @brief Get processor stack frame.
- /// @brief Get processor stack frame.
+HAL::StackFrame* ProcessorCore::StackFrame() noexcept {
+ MUST_PASS(m_Stack);
+ return m_Stack;
+}
- HAL::StackFrame* ProcessorCore::StackFrame() noexcept
- {
- MUST_PASS(m_Stack);
- return m_Stack;
- }
+void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; }
- void ProcessorCore::Busy(const bool busy) noexcept { m_Busy = busy; }
+ProcessorCore::operator bool() { return m_Stack; }
- ProcessorCore::operator bool() { return m_Stack; }
+/// @brief Wakeup the processor.
- /// @brief Wakeup the processor.
+void ProcessorCore::Wake(const bool wakeup) noexcept {
+ m_Wakeup = wakeup;
- void ProcessorCore::Wake(const bool wakeup) noexcept
- {
- m_Wakeup = wakeup;
+ if (!m_Wakeup)
+ rt_hang_thread(m_Stack);
+ else
+ rt_wakeup_thread(m_Stack);
+}
- if (!m_Wakeup)
- rt_hang_thread(m_Stack);
- else
- rt_wakeup_thread(m_Stack);
- }
+bool ProcessorCore::Switch(HAL::StackFrame* stack) {
+ if (stack == nullptr) return false;
- bool ProcessorCore::Switch(HAL::StackFrame* stack)
- {
- if (stack == nullptr)
- return false;
+ return rt_do_context_switch(m_Stack, stack) == 0;
+}
- return rt_do_context_switch(m_Stack, stack) == 0;
- }
+///! @brief Tells if processor is waked up.
+bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; }
- ///! @brief Tells if processor is waked up.
- bool ProcessorCore::IsWakeup() noexcept { return m_Wakeup; }
+//! @brief Constructor and destructor
- //! @brief Constructor and destructor
+///! @brief Default constructor.
+SMPManager::SMPManager() = default;
- ///! @brief Default constructor.
- SMPManager::SMPManager() = default;
+///! @brief Default destructor.
+SMPManager::~SMPManager() = default;
- ///! @brief Default destructor.
- SMPManager::~SMPManager() = default;
+/// @brief Shared singleton function
+Ref<SMPManager> SMPManager::Shared() {
+ static SMPManager manager;
+ return {manager};
+}
- /// @brief Shared singleton function
- Ref<SMPManager> SMPManager::Shared()
- {
- static SMPManager manager;
- return { manager };
- }
+/// @brief Get Stack Frame of Core
+HAL::StackFramePtr SMPManager::GetStackFrame() noexcept {
+ if (m_ThreadList[m_CurrentThread].Leak() &&
+ ProcessHelper::GetCurrentPID() ==
+ m_ThreadList[m_CurrentThread].Leak().Leak().m_PID)
+ return m_ThreadList[m_CurrentThread].Leak().Leak().m_Stack;
- /// @brief Get Stack Frame of Core
- HAL::StackFramePtr SMPManager::GetStackFrame() noexcept
- {
- if (m_ThreadList[m_CurrentThread].Leak() &&
- ProcessHelper::GetCurrentPID() == m_ThreadList[m_CurrentThread].Leak().Leak().m_PID)
- return m_ThreadList[m_CurrentThread].Leak().Leak().m_Stack;
+ return nullptr;
+}
- return nullptr;
- }
+/// @brief Finds and switch to a free core.
+bool SMPManager::Switch(HAL::StackFrame* stack) {
+ if (stack == nullptr) return false;
- /// @brief Finds and switch to a free core.
- bool SMPManager::Switch(HAL::StackFrame* stack)
- {
- if (stack == nullptr)
- return false;
+ for (SizeT idx = 0; idx < kMaxHarts; ++idx) {
+ // stack != nullptr -> if core is used, then continue.
+ if (!m_ThreadList[idx].Leak() ||
+ !m_ThreadList[idx].Leak().Leak().IsWakeup() ||
+ m_ThreadList[idx].Leak().Leak().IsBusy())
+ continue;
- for (SizeT idx = 0; idx < kMaxHarts; ++idx)
- {
- // stack != nullptr -> if core is used, then continue.
- if (!m_ThreadList[idx].Leak() ||
- !m_ThreadList[idx].Leak().Leak().IsWakeup() ||
- m_ThreadList[idx].Leak().Leak().IsBusy())
- continue;
+ m_ThreadList[idx].Leak().Leak().m_ID = idx;
+ m_ThreadList[idx].Leak().Leak().m_Stack = stack;
+ m_ThreadList[idx].Leak().Leak().m_PID = ProcessHelper::GetCurrentPID();
- m_ThreadList[idx].Leak().Leak().m_ID = idx;
- m_ThreadList[idx].Leak().Leak().m_Stack = stack;
- m_ThreadList[idx].Leak().Leak().m_PID = ProcessHelper::GetCurrentPID();
-
- m_ThreadList[idx].Leak().Leak().Busy(true);
+ m_ThreadList[idx].Leak().Leak().Busy(true);
- Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0);
-
- m_ThreadList[idx].Leak().Leak().Busy(false);
+ Boolean ret = (rt_do_context_switch(rt_get_current_context(), stack) == 0);
- return ret;
- }
+ m_ThreadList[idx].Leak().Leak().Busy(false);
- return false;
- }
+ return ret;
+ }
- /**
- * Index hart
- * @param idx
- * @return
- */
- Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) { return m_ThreadList[idx].Leak(); }
-
- /**
- * Check if thread pool isn't empty.
- * @return
- */
- SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); }
-
- /**
- * Reverse operator bool
- * @return
- */
- bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); }
-} // namespace hCore
+ return false;
+}
+
+/**
+ * Index hart
+ * @param idx
+ * @return
+ */
+Ref<ProcessorCore> SMPManager::operator[](const SizeT& idx) {
+ return m_ThreadList[idx].Leak();
+}
+
+/**
+ * Check if thread pool isn't empty.
+ * @return
+ */
+SMPManager::operator bool() noexcept { return !m_ThreadList.Empty(); }
+
+/**
+ * Reverse operator bool
+ * @return
+ */
+bool SMPManager::operator!() noexcept { return m_ThreadList.Empty(); }
+} // namespace hCore
diff --git a/Private/Source/Semaphore.cxx b/Private/Source/Semaphore.cxx
index 0c530274..5702b9fb 100644
--- a/Private/Source/Semaphore.cxx
+++ b/Private/Source/Semaphore.cxx
@@ -7,47 +7,38 @@
* ========================================================
*/
+#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/Semaphore.hpp>
-
#include <KernelKit/Timer.hpp>
-#include <KernelKit/ProcessManager.hpp>
-namespace hCore
-{
- bool Semaphore::Unlock() noexcept
- {
- if (fLockingProcess)
- fLockingProcess = nullptr;
+namespace hCore {
+bool Semaphore::Unlock() noexcept {
+ if (fLockingProcess) fLockingProcess = nullptr;
- return fLockingProcess == nullptr;
- }
+ return fLockingProcess == nullptr;
+}
- bool Semaphore::Lock(Process* process)
- {
- if (!process ||
- fLockingProcess)
- return false;
+bool Semaphore::Lock(Process* process) {
+ if (!process || fLockingProcess) return false;
- fLockingProcess = process;
+ fLockingProcess = process;
- return true;
- }
+ return true;
+}
- bool Semaphore::IsLocked() const { return fLockingProcess; }
+bool Semaphore::IsLocked() const { return fLockingProcess; }
- bool Semaphore::LockOrWait(Process* process, const Int64& seconds)
- {
- if (process == nullptr)
- return false;
+bool Semaphore::LockOrWait(Process* process, const Int64& seconds) {
+ if (process == nullptr) return false;
- HardwareTimer timer(Seconds(seconds));
- timer.Wait();
+ HardwareTimer timer(Seconds(seconds));
+ timer.Wait();
- return this->Lock(process);
- }
+ return this->Lock(process);
+}
- void Semaphore::Sync() noexcept
- {
- while (fLockingProcess) {}
- }
+void Semaphore::Sync() noexcept {
+ while (fLockingProcess) {
+ }
}
+} // namespace hCore
diff --git a/Private/Source/SharedObject.cxx b/Private/Source/SharedObject.cxx
index a6ccc224..0e824b27 100644
--- a/Private/Source/SharedObject.cxx
+++ b/Private/Source/SharedObject.cxx
@@ -18,38 +18,37 @@ using namespace hCore;
/***********************************************************************************/
-extern "C" SharedObject *__LibMain(VoidPtr image)
-{
- /***********************************************************************************/
- /* Allocate new library to be added to the lookup table. */
- /***********************************************************************************/
+extern "C" SharedObject *__LibMain(VoidPtr image) {
+ /***********************************************************************************/
+ /* Allocate new library to be added to the lookup table.
+ */
+ /***********************************************************************************/
- SharedObject *library = hcore_tls_new_class<SharedObject>();
+ SharedObject *library = hcore_tls_new_class<SharedObject>();
- if (!library)
- {
- kcout << "__LibMain: Out of Memory!\n";
- ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+ if (!library) {
+ kcout << "__LibMain: Out of Memory!\n";
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
- return nullptr;
- }
+ return nullptr;
+ }
- library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>());
+ library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>());
- if (!library->Get())
- {
- kcout << "__LibMain: Out of Memory!\n";
- ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+ if (!library->Get()) {
+ kcout << "__LibMain: Out of Memory!\n";
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
- return nullptr;
- }
+ return nullptr;
+ }
- library->Get()->fImageObject = ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
- library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart);
+ library->Get()->fImageObject =
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Image;
+ library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart);
- kcout << "__LibMain: Done allocating Shared Library...\n";
+ kcout << "__LibMain: Done allocating Shared Library...\n";
- return library;
+ return library;
}
/***********************************************************************************/
diff --git a/Private/Source/Storage/ATA.cxx b/Private/Source/Storage/ATA.cxx
index 08fa43b3..f960907b 100644
--- a/Private/Source/Storage/ATA.cxx
+++ b/Private/Source/Storage/ATA.cxx
@@ -7,93 +7,85 @@
* ========================================================
*/
-#include <StorageKit/ATA.hpp>
#include <ArchKit/Arch.hpp>
+#include <StorageKit/ATA.hpp>
//! @brief Driver for ATA, listens to a specific address for data to come.
//! mapped by NewFirmware.
#define kATAError 2
-namespace hCore
-{
- Ref<PRDT*> kPrdt = nullptr;
+namespace hCore {
+Ref<PRDT*> kPrdt = nullptr;
- bool set_prdt_struct(Ref<PRDT*>& refCtrl)
- {
- if (!kPrdt)
- {
- kPrdt = refCtrl;
- kcout << "[set_prdt_struct] PRDT is set.";
+bool set_prdt_struct(Ref<PRDT*>& refCtrl) {
+ if (!kPrdt) {
+ kPrdt = refCtrl;
+ kcout << "[set_prdt_struct] PRDT is set.";
- return true;
- }
+ return true;
+ }
- kcout << "[set_prdt_struct] [WARNING] Tried to change PRDT.\n";
- return false;
- }
+ kcout << "[set_prdt_struct] [WARNING] Tried to change PRDT.\n";
+ return false;
+}
- enum
- {
- k28BitRead = 0xC8,
- k48BitRead = 0x25,
- k28BitWrite = 0xCA,
- k48BitWrite = 0x35,
- };
+enum {
+ k28BitRead = 0xC8,
+ k48BitRead = 0x25,
+ k28BitWrite = 0xCA,
+ k48BitWrite = 0x35,
+};
- const char* ata_read_28(ULong lba)
- {
- static char buffer[512];
+const char* ata_read_28(ULong lba) {
+ static char buffer[512];
- UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
+ UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
- packet[0] = k28BitRead;
- packet[1] = (UIntPtr)&buffer;
- packet[2] = lba;
+ packet[0] = k28BitRead;
+ packet[1] = (UIntPtr)&buffer;
+ packet[2] = lba;
- rt_wait_for_io();
+ rt_wait_for_io();
- return buffer;
- }
+ return buffer;
+}
- const char* ata_read_48(ULong lba)
- {
- static char buffer[512];
+const char* ata_read_48(ULong lba) {
+ static char buffer[512];
- UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
+ UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
- packet[0] = k48BitRead;
- packet[1] = (UIntPtr)&buffer;
- packet[4] = lba;
+ packet[0] = k48BitRead;
+ packet[1] = (UIntPtr)&buffer;
+ packet[4] = lba;
- rt_wait_for_io();
+ rt_wait_for_io();
- return buffer;
- }
+ return buffer;
+}
- Int32 ata_write_48(ULong lba, const char *text)
- {
- UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
+Int32 ata_write_48(ULong lba, const char* text) {
+ UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
- packet[0] = k48BitWrite;
- packet[1] = (UIntPtr)&text;
- packet[2] = lba;
+ packet[0] = k48BitWrite;
+ packet[1] = (UIntPtr)&text;
+ packet[2] = lba;
- rt_wait_for_io();
+ rt_wait_for_io();
- return packet[1] == 2 ? kATAError : 0;
- }
+ return packet[1] == 2 ? kATAError : 0;
+}
- Int32 ata_write_28(ULong lba, const char *text)
- {
- UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
+Int32 ata_write_28(ULong lba, const char* text) {
+ UIntPtr* packet = (UIntPtr*)kPrdt.Leak()->PhysicalAddress();
- packet[0] = k28BitWrite;
- packet[1] = (UIntPtr)&text;
- packet[2] = lba;
+ packet[0] = k28BitWrite;
+ packet[1] = (UIntPtr)&text;
+ packet[2] = lba;
- rt_wait_for_io();
+ rt_wait_for_io();
- return packet[1] == 2 ? kATAError : 0;
- }
-} // namespace hCore
+ return packet[1] == 2 ? kATAError : 0;
+}
+} // namespace hCore
diff --git a/Private/Source/Storage/NVME.cxx b/Private/Source/Storage/NVME.cxx
index aa1d8ecc..9501b8fa 100644
--- a/Private/Source/Storage/NVME.cxx
+++ b/Private/Source/Storage/NVME.cxx
@@ -9,10 +9,6 @@
#include <StorageKit/NVME.hpp>
-namespace hCore
-{
- const char *NVMEDevice::Name() const
- {
- return ("NVMEDevice");
- }
-} // namespace hCore
+namespace hCore {
+const char *NVMEDevice::Name() const { return ("NVMEDevice"); }
+} // namespace hCore
diff --git a/Private/Source/Storage/Storage.cxx b/Private/Source/Storage/Storage.cxx
index 6384479a..2340763a 100644
--- a/Private/Source/Storage/Storage.cxx
+++ b/Private/Source/Storage/Storage.cxx
@@ -9,4 +9,5 @@
#include <StorageKit/Storage.hpp>
-const OSScsiPacket kCDRomPacketTemplate = { 0x43, 0, 1, 0, 0, 0, 0, 12, 0x40, 0, 0 };
+const OSScsiPacket kCDRomPacketTemplate = {0x43, 0, 1, 0, 0, 0,
+ 0, 12, 0x40, 0, 0};
diff --git a/Private/Source/String.cxx b/Private/Source/String.cxx
index 3ad2a0cd..b4f95f6c 100644
--- a/Private/Source/String.cxx
+++ b/Private/Source/String.cxx
@@ -10,230 +10,185 @@
#include <NewKit/String.hpp>
#include <NewKit/Utils.hpp>
-namespace hCore
-{
- Char* StringView::Data() { return m_Data; }
+namespace hCore {
+Char *StringView::Data() { return m_Data; }
- const Char* StringView::CData() { return m_Data; }
+const Char *StringView::CData() { return m_Data; }
- Size StringView::Length() const { return string_length(m_Data); }
+Size StringView::Length() const { return string_length(m_Data); }
- bool StringView::operator==(const StringView &rhs) const
- {
- if (rhs.Length() != this->Length())
- return false;
+bool StringView::operator==(const StringView &rhs) const {
+ if (rhs.Length() != this->Length()) return false;
- for (Size index = 0; index < this->Length(); ++index)
- {
- if (rhs.m_Data[index] != m_Data[index])
- return false;
- }
+ for (Size index = 0; index < this->Length(); ++index) {
+ if (rhs.m_Data[index] != m_Data[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- bool StringView::operator==(const Char *rhs) const
- {
- if (string_length(rhs) != this->Length())
- return false;
+bool StringView::operator==(const Char *rhs) const {
+ if (string_length(rhs) != this->Length()) return false;
- for (Size index = 0; index < string_length(rhs); ++index)
- {
- if (rhs[index] != m_Data[index])
- return false;
- }
+ for (Size index = 0; index < string_length(rhs); ++index) {
+ if (rhs[index] != m_Data[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- bool StringView::operator!=(const StringView &rhs) const
- {
- if (rhs.Length() != this->Length())
- return false;
+bool StringView::operator!=(const StringView &rhs) const {
+ if (rhs.Length() != this->Length()) return false;
- for (Size index = 0; index < rhs.Length(); ++index)
- {
- if (rhs.m_Data[index] == m_Data[index])
- return false;
- }
+ for (Size index = 0; index < rhs.Length(); ++index) {
+ if (rhs.m_Data[index] == m_Data[index]) return false;
+ }
- return true;
- }
+ return true;
+}
- bool StringView::operator!=(const Char *rhs) const
- {
- if (string_length(rhs) != this->Length())
- return false;
+bool StringView::operator!=(const Char *rhs) const {
+ if (string_length(rhs) != this->Length()) return false;
- for (Size index = 0; index < string_length(rhs); ++index)
- {
- if (rhs[index] == m_Data[index])
- return false;
- }
-
- return true;
- }
+ for (Size index = 0; index < string_length(rhs); ++index) {
+ if (rhs[index] == m_Data[index]) return false;
+ }
- ErrorOr<StringView> StringBuilder::Construct(const Char *data)
- {
- if (!data ||
- *data == 0)
- return {};
+ return true;
+}
- StringView view(string_length(data));
-
- rt_copy_memory(reinterpret_cast<voidPtr>(const_cast<Char*>(data)), reinterpret_cast<voidPtr>(view.Data()),
- view.Length());
+ErrorOr<StringView> StringBuilder::Construct(const Char *data) {
+ if (!data || *data == 0) return {};
- return ErrorOr<StringView>(view);
- }
+ StringView view(string_length(data));
- const char* StringBuilder::FromInt(const char *fmt, int i)
- {
- if (!fmt)
- return ("-1");
+ rt_copy_memory(reinterpret_cast<voidPtr>(const_cast<Char *>(data)),
+ reinterpret_cast<voidPtr>(view.Data()), view.Length());
- char* ret = (char*)__alloca(sizeof(char) * 8 + string_length(fmt));
+ return ErrorOr<StringView>(view);
+}
- if (!ret)
- return ("-1");
+const char *StringBuilder::FromInt(const char *fmt, int i) {
+ if (!fmt) return ("-1");
- Char result[8];
+ char *ret = (char *)__alloca(sizeof(char) * 8 + string_length(fmt));
- if (!to_str(result, sizeof(int), i))
- {
- return ("-1");
- }
+ if (!ret) return ("-1");
- const auto fmt_len = string_length(fmt);
- const auto res_len = string_length(result);
+ Char result[8];
- for (Size idx = 0; idx < fmt_len; ++idx)
- {
- if (fmt[idx] == '%') {
- SizeT result_cnt = idx;
+ if (!to_str(result, sizeof(int), i)) {
+ return ("-1");
+ }
- for (auto y_idx = idx; y_idx < res_len; ++y_idx) {
- ret[result_cnt] = result[y_idx];
- ++result_cnt;
- }
+ const auto fmt_len = string_length(fmt);
+ const auto res_len = string_length(result);
- break;
- }
+ for (Size idx = 0; idx < fmt_len; ++idx) {
+ if (fmt[idx] == '%') {
+ SizeT result_cnt = idx;
- ret[idx] = fmt[idx];
- }
+ for (auto y_idx = idx; y_idx < res_len; ++y_idx) {
+ ret[result_cnt] = result[y_idx];
+ ++result_cnt;
+ }
- return ret; /* Copy that ret into a buffer, Alloca allocates to the stack */
+ break;
}
- const char *StringBuilder::FromBool(const char *fmt, bool i)
- {
- if (!fmt)
- return ("?");
+ ret[idx] = fmt[idx];
+ }
- const char* boolean_expr = i ? "true" : "false";
- char* ret = (char*)__alloca((sizeof(char) * i) ? 4 : 5 + string_length(fmt));
+ return ret; /* Copy that ret into a buffer, Alloca allocates to the stack */
+}
- if (!ret)
- return ("?");
+const char *StringBuilder::FromBool(const char *fmt, bool i) {
+ if (!fmt) return ("?");
- const auto fmt_len = string_length(fmt);
- const auto res_len = string_length(boolean_expr);
+ const char *boolean_expr = i ? "true" : "false";
+ char *ret = (char *)__alloca((sizeof(char) * i) ? 4 : 5 + string_length(fmt));
- for (Size idx = 0; idx < fmt_len; ++idx)
- {
- if (fmt[idx] == '%') {
- SizeT result_cnt = idx;
+ if (!ret) return ("?");
- for (auto y_idx = idx; y_idx < res_len; ++y_idx)
- {
- ret[result_cnt] = boolean_expr[y_idx];
- ++result_cnt;
- }
+ const auto fmt_len = string_length(fmt);
+ const auto res_len = string_length(boolean_expr);
- break;
- }
+ for (Size idx = 0; idx < fmt_len; ++idx) {
+ if (fmt[idx] == '%') {
+ SizeT result_cnt = idx;
- ret[idx] = fmt[idx];
- }
+ for (auto y_idx = idx; y_idx < res_len; ++y_idx) {
+ ret[result_cnt] = boolean_expr[y_idx];
+ ++result_cnt;
+ }
- return ret;
+ break;
}
- bool StringBuilder::Equals(const char *lhs, const char *rhs)
- {
- if (string_length(rhs) != string_length(lhs))
- return false;
+ ret[idx] = fmt[idx];
+ }
- for (Size index = 0; index < string_length(rhs); ++index)
- {
- if (rhs[index] != lhs[index])
- return false;
- }
+ return ret;
+}
- return true;
- }
+bool StringBuilder::Equals(const char *lhs, const char *rhs) {
+ if (string_length(rhs) != string_length(lhs)) return false;
- const char *StringBuilder::Format(const char *fmt, const char *fmt2)
- {
- if (!fmt || !fmt2)
- return ("?");
-
- char* ret = (char*)alloca(sizeof(char) * string_length(fmt2) + string_length(fmt2));
-
- if (!ret)
- return ("?");
-
- for (Size idx = 0; idx < string_length(fmt); ++idx)
- {
- if (fmt[idx] == '%') {
- Size result_cnt = idx;
- for (Size y_idx = 0; y_idx < string_length(fmt2); ++y_idx)
- {
- ret[result_cnt] = fmt2[y_idx];
- ++result_cnt;
- }
-
- break;
- }
-
- ret[idx] = fmt[idx];
- }
-
- return ret;
- }
+ for (Size index = 0; index < string_length(rhs); ++index) {
+ if (rhs[index] != lhs[index]) return false;
+ }
- static void string_append(char *lhs, char *rhs, int cur)
- {
- if (lhs && rhs &&
- cur < string_length(lhs))
- {
- SizeT sz_rhs = string_length(rhs);
+ return true;
+}
- rt_copy_memory(rhs, lhs + cur, sz_rhs);
- }
- }
+const char *StringBuilder::Format(const char *fmt, const char *fmt2) {
+ if (!fmt || !fmt2) return ("?");
+
+ char *ret =
+ (char *)alloca(sizeof(char) * string_length(fmt2) + string_length(fmt2));
- StringView& StringView::operator+=(const Char *rhs)
- {
- if (string_length(rhs) > string_length(this->m_Data))
- return *this;
+ if (!ret) return ("?");
- string_append(this->m_Data, const_cast<char*>(rhs), this->m_Cur);
- this->m_Cur += string_length(rhs);
-
- return *this;
+ for (Size idx = 0; idx < string_length(fmt); ++idx) {
+ if (fmt[idx] == '%') {
+ Size result_cnt = idx;
+ for (Size y_idx = 0; y_idx < string_length(fmt2); ++y_idx) {
+ ret[result_cnt] = fmt2[y_idx];
+ ++result_cnt;
+ }
+
+ break;
}
- StringView& StringView::operator+=(const StringView &rhs)
- {
- if (string_length(rhs.m_Data) > string_length(this->m_Data))
- return *this;
+ ret[idx] = fmt[idx];
+ }
- string_append(this->m_Data, const_cast<char*>(rhs.m_Data), this->m_Cur);
- this->m_Cur += string_length(const_cast<char*>(rhs.m_Data));
+ return ret;
+}
- return *this;
- }
-} // namespace hCore
+static void string_append(char *lhs, char *rhs, int cur) {
+ if (lhs && rhs && cur < string_length(lhs)) {
+ SizeT sz_rhs = string_length(rhs);
+
+ rt_copy_memory(rhs, lhs + cur, sz_rhs);
+ }
+}
+
+StringView &StringView::operator+=(const Char *rhs) {
+ if (string_length(rhs) > string_length(this->m_Data)) return *this;
+
+ string_append(this->m_Data, const_cast<char *>(rhs), this->m_Cur);
+ this->m_Cur += string_length(rhs);
+
+ return *this;
+}
+
+StringView &StringView::operator+=(const StringView &rhs) {
+ if (string_length(rhs.m_Data) > string_length(this->m_Data)) return *this;
+
+ string_append(this->m_Data, const_cast<char *>(rhs.m_Data), this->m_Cur);
+ this->m_Cur += string_length(const_cast<char *>(rhs.m_Data));
+
+ return *this;
+}
+} // namespace hCore
diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx
index bcafdd10..66ec69d6 100644
--- a/Private/Source/ThreadLocalStorage.cxx
+++ b/Private/Source/ThreadLocalStorage.cxx
@@ -17,16 +17,15 @@ using namespace hCore;
* @param ptr
* @return if the cookie is enabled.
*/
-Boolean hcore_tls_check(VoidPtr ptr)
-{
- if (!ptr)
- return false;
+Boolean hcore_tls_check(VoidPtr ptr) {
+ if (!ptr) return false;
- const char* _ptr = (const char*)ptr;
+ const char* _ptr = (const char*)ptr;
- kcout << "TLS: Check for cookie...\n";
+ kcout << "TLS: Checking for cookie...\n";
- return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 && _ptr[2] == kCookieMag2;
+ return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 &&
+ _ptr[2] == kCookieMag2;
}
/**
@@ -34,11 +33,11 @@ Boolean hcore_tls_check(VoidPtr ptr)
* @param ptr
* @return
*/
-Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept
-{
- if (!hcore_tls_check(ptr.Cookie))
- {
- kcout << "TLS: Verification failure, crashing...\n";
- ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
- }
+Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept {
+ if (!hcore_tls_check(ptr.Cookie)) {
+ kcout << "TLS: Verification failure, crashing...\n";
+ ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
+ }
+
+ kcout << "TLS: Verification succeeded! Keeping on...\n";
}
diff --git a/Private/Source/Timer.cxx b/Private/Source/Timer.cxx
index 73343fad..137a5545 100644
--- a/Private/Source/Timer.cxx
+++ b/Private/Source/Timer.cxx
@@ -18,12 +18,11 @@ Int32 HardwareTimerInterface::Wait() noexcept { return H_UNIMPLEMENTED; }
HardwareTimer::HardwareTimer(Int64 seconds) : fWaitFor(seconds) {}
HardwareTimer::~HardwareTimer() { fWaitFor = 0; }
-Int32 HardwareTimer::Wait() noexcept
-{
- if (fWaitFor < 1)
- return -1;
+Int32 HardwareTimer::Wait() noexcept {
+ if (fWaitFor < 1) return -1;
- while (*fDigitalTimer < (*fDigitalTimer + fWaitFor)) {}
+ while (*fDigitalTimer < (*fDigitalTimer + fWaitFor)) {
+ }
- return 0;
-} \ No newline at end of file
+ return 0;
+}
diff --git a/Private/Source/URL.cxx b/Private/Source/URL.cxx
index 0aa75ab9..02a3ec77 100644
--- a/Private/Source/URL.cxx
+++ b/Private/Source/URL.cxx
@@ -8,92 +8,80 @@
*/
#include <CFKit/URL.hpp>
-#include <NewKit/Utils.hpp>
-
#include <KernelKit/DebugOutput.hpp>
+#include <NewKit/Utils.hpp>
// Bugs = 0
-namespace hCore
-{
- Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {}
-
- Url::~Url() = default;
-
- constexpr const char *kProtos[] = {
- "https", // http with the secure.
- "http", // http without the secure
- "file", // filesystem protocol
- "ftp", // file transfer protocol
- "params", // system settings
- "rsh", // remote shell (gui)
- };
-
- constexpr const int kUrlOutSz = 3; //! ://
- constexpr const int kProtosCount = 8;
- constexpr const int kRangeSz = 4096;
-
- static ErrorOr<StringView> url_extract_location(const char *url)
- {
- if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz)
- return ErrorOr<StringView>{-1};
-
- StringView view(string_length(url));
-
- SizeT i = 0;
- bool scheme_found = false;
-
- for (; i < string_length(url); ++i)
- {
- if (!scheme_found)
- {
- for (int y = 0; kProtosCount; ++y)
- {
- if (string_in_string(view.CData(), kProtos[y]))
- {
- i += string_length(kProtos[y]) + kUrlOutSz;
- scheme_found = true;
-
- break;
- }
- }
- }
-
- view.Data()[i] = url[i];
- }
+namespace hCore {
+Url::Url(StringView &strUrl) : m_urlView(strUrl, false) {}
- return ErrorOr<StringView>(view);
- }
+Url::~Url() = default;
- static ErrorOr<StringView> url_extract_protocol(const char *url)
- {
- if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz)
- return ErrorOr<StringView>{-1};
+constexpr const char *kProtos[] = {
+ "https", // http with the secure.
+ "http", // http without the secure
+ "file", // filesystem protocol
+ "ftp", // file transfer protocol
+ "params", // system settings
+ "rsh", // remote shell (gui)
+};
- ErrorOr<StringView> view{ -1 };
-
- return view;
- }
+constexpr const int kUrlOutSz = 3; //! ://
+constexpr const int kProtosCount = 8;
+constexpr const int kRangeSz = 4096;
+
+static ErrorOr<StringView> url_extract_location(const char *url) {
+ if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz)
+ return ErrorOr<StringView>{-1};
- Ref<ErrorOr<StringView>> Url::Location() noexcept
- {
- const char *src = m_urlView.Leak().CData();
- auto loc = url_extract_location(src);
+ StringView view(string_length(url));
- if (!loc)
- return {};
+ SizeT i = 0;
+ bool scheme_found = false;
- return Ref<ErrorOr<StringView>>(loc);
+ for (; i < string_length(url); ++i) {
+ if (!scheme_found) {
+ for (int y = 0; kProtosCount; ++y) {
+ if (string_in_string(view.CData(), kProtos[y])) {
+ i += string_length(kProtos[y]) + kUrlOutSz;
+ scheme_found = true;
+
+ break;
+ }
+ }
}
- Ref<ErrorOr<StringView>> Url::Protocol() noexcept
- {
- const char *src = m_urlView.Leak().CData();
- auto loc = url_extract_protocol(src);
+ view.Data()[i] = url[i];
+ }
- if (!loc)
- return {};
+ return ErrorOr<StringView>(view);
+}
- return Ref<ErrorOr<StringView>>(loc);
- }
-} // namespace hCore
+static ErrorOr<StringView> url_extract_protocol(const char *url) {
+ if (!url || *url == 0 || string_length(url, kRangeSz) > kRangeSz)
+ return ErrorOr<StringView>{-1};
+
+ ErrorOr<StringView> view{-1};
+
+ return view;
+}
+
+Ref<ErrorOr<StringView>> Url::Location() noexcept {
+ const char *src = m_urlView.Leak().CData();
+ auto loc = url_extract_location(src);
+
+ if (!loc) return {};
+
+ return Ref<ErrorOr<StringView>>(loc);
+}
+
+Ref<ErrorOr<StringView>> Url::Protocol() noexcept {
+ const char *src = m_urlView.Leak().CData();
+ auto loc = url_extract_protocol(src);
+
+ if (!loc) return {};
+
+ return Ref<ErrorOr<StringView>>(loc);
+}
+} // namespace hCore
diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx
new file mode 100644
index 00000000..e748e315
--- /dev/null
+++ b/Private/Source/UserHeap.cxx
@@ -0,0 +1,188 @@
+/*
+ * ========================================================
+ *
+ * hCore
+ * Copyright 2024 Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <NewKit/PageManager.hpp>
+#include <NewKit/UserHeap.hpp>
+
+/// @file Heap.cxx
+/// @brief Heap Manager, user mode allocator.
+/// @note if you want to look at kernel allocs, please look for KHeap.cxx
+/// bugs: 0
+
+namespace hCore {
+class HeapManager final {
+ public:
+ static SizeT& GetCount() { return s_NumPools; }
+ static Ref<Pmm>& GetPmm() { return s_Pmm; }
+ static Boolean& IsEnabled() { return s_PoolsAreEnabled; }
+ static Array<Ref<PTEWrapper*>, kPoolMaxSz>& The() { return s_Pool; }
+
+ private:
+ static Size s_NumPools;
+ static Ref<Pmm> s_Pmm;
+
+ private:
+ static Boolean s_PoolsAreEnabled;
+ static Array<Ref<PTEWrapper*>, kPoolMaxSz> s_Pool;
+};
+
+//! declare fields
+
+SizeT HeapManager::s_NumPools = 0UL;
+Ref<Pmm> HeapManager::s_Pmm;
+Boolean HeapManager::s_PoolsAreEnabled = true;
+Array<Ref<PTEWrapper*>, kPoolMaxSz> HeapManager::s_Pool;
+
+static voidPtr ke_find_unused_heap(Int flags);
+static void ke_free_heap_internal(voidPtr vaddr);
+static voidPtr ke_make_heap(voidPtr vaddr, Int flags);
+static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr);
+
+static voidPtr ke_find_unused_heap(Int flags) {
+ for (SizeT index = 0; index < kPoolMaxSz; ++index) {
+ if (HeapManager::The()[index] &&
+ !HeapManager::The()[index].Leak().Leak().Leak()->Present()) {
+ HeapManager::GetPmm().Leak().TogglePresent(
+ HeapManager::The()[index].Leak().Leak(), true);
+ kcout << "[ke_find_unused_heap] Done, trying now to make a pool\r\n";
+
+ return ke_make_heap((voidPtr)HeapManager::The()[index]
+ .Leak()
+ .Leak()
+ .Leak()
+ ->VirtualAddress(),
+ flags);
+ }
+ }
+
+ return nullptr;
+}
+
+static voidPtr ke_make_heap(voidPtr virtualAddress, Int flags) {
+ if (virtualAddress) {
+ HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(virtualAddress);
+
+ if (!pool_hdr->Free) {
+ kcout << "[ke_make_heap] pool_hdr->Free, Pool already exists\n";
+ return nullptr;
+ }
+
+ pool_hdr->Flags = flags;
+ pool_hdr->Magic = kPoolMag;
+ pool_hdr->Free = false;
+
+ kcout << "[ke_make_heap] New allocation has been done.\n";
+ return reinterpret_cast<voidPtr>(
+ (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(HeapHeader)));
+ }
+
+ kcout << "[ke_make_heap] Address is invalid";
+ return nullptr;
+}
+
+static void ke_free_heap_internal(voidPtr virtualAddress) {
+ HeapHeader* pool_hdr = reinterpret_cast<HeapHeader*>(
+ reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(HeapHeader));
+
+ if (pool_hdr->Magic == kPoolMag) {
+ pool_hdr->Free = false;
+ pool_hdr->Flags = 0;
+
+ kcout << "[ke_free_heap_internal] Successfully marked header as free!\r\n";
+ }
+}
+
+static bool ke_check_and_free_heap(const SizeT& index, voidPtr ptr) {
+ if (HeapManager::The()[index]) {
+ // ErrorOr<>::operator bool
+ if (!HeapManager::The()[index].Leak().Leak().IsStrong()) {
+ // we want them to be weak
+ // because we allocated it.
+ if (HeapManager::The()[index].Leak().Leak().Leak()->VirtualAddress() ==
+ (UIntPtr)ptr) {
+ HeapManager::GetPmm().Leak().FreePage(
+ HeapManager::The()[index].Leak().Leak());
+ --HeapManager::GetCount();
+
+ ke_free_heap_internal(ptr);
+ ptr = nullptr;
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+/// @brief Creates a new pool pointer.
+/// @param flags the flags attached to it.
+/// @return a pool pointer with selected permissions.
+voidPtr pool_new_ptr(Int32 flags) {
+ if (!HeapManager::IsEnabled()) return nullptr;
+
+ if (HeapManager::GetCount() > kPoolMaxSz) return nullptr;
+
+ if (voidPtr ret = ke_find_unused_heap(flags)) return ret;
+
+ // this wasn't set to true
+ auto ref_page = HeapManager::GetPmm().Leak().RequestPage(
+ ((flags & kPoolUser)), (flags & kPoolRw));
+ if (ref_page) {
+ ///! reserve page.
+ HeapManager::The()[HeapManager::GetCount()].Leak() = ref_page;
+ auto& ref = HeapManager::GetCount();
+ ++ref; // increment the number of addresses we have now.
+
+ kcout << "[pool_new_ptr] New Address found!\r\n";
+
+ // finally make the pool address.
+ return ke_make_heap(
+ reinterpret_cast<voidPtr>(ref_page.Leak()->VirtualAddress()), flags);
+ }
+
+ return nullptr;
+}
+
+/// @brief free a pool pointer.
+/// @param ptr The pool pointer to free.
+/// @return status code
+Int32 pool_free_ptr(voidPtr ptr) {
+ if (!HeapManager::IsEnabled()) return -1;
+
+ if (ptr) {
+ SizeT base = HeapManager::GetCount();
+
+ if (ke_check_and_free_heap(base, ptr)) return 0;
+
+ for (SizeT index = 0; index < kPoolMaxSz; ++index) {
+ if (ke_check_and_free_heap(index, ptr)) return 0;
+
+ --base;
+ }
+ }
+
+ return -1;
+}
+
+/// @brief Checks if pointer is valid.
+/// @param thePool the pool pointer.
+/// @param thePtr the pointer.
+/// @param theLimit the last address of the pool.
+/// @return if it is valid.
+Boolean pool_ptr_exists(UIntPtr thePool, UIntPtr thePtr, SizeT theLimit) {
+ if (HeapManager::GetCount() < 1) return false;
+
+ if (thePool == 0 || thePtr == 0 || theLimit == 0) {
+ return false;
+ }
+
+ return ((thePool) < (thePtr) < (theLimit));
+}
+} // namespace hCore
diff --git a/Private/Source/Utils.cxx b/Private/Source/Utils.cxx
index 9f767d72..6569258b 100644
--- a/Private/Source/Utils.cxx
+++ b/Private/Source/Utils.cxx
@@ -9,211 +9,166 @@
#include <NewKit/Utils.hpp>
-namespace hCore
-{
- Int string_compare(const Char *src, const Char *cmp, Size size)
- {
- Int32 counter = 0;
-
- for (Size index = 0; index < size; ++index)
- {
- if (src[index] != cmp[index])
- ++counter;
- }
-
- return counter;
- }
+namespace hCore {
+Int string_compare(const Char *src, const Char *cmp, Size size) {
+ Int32 counter = 0;
- void rt_zero_memory(voidPtr pointer, Size len)
- {
- rt_set_memory((voidPtr) pointer, 0, len);
- }
+ for (Size index = 0; index < size; ++index) {
+ if (src[index] != cmp[index]) ++counter;
+ }
- Size string_length(const Char *str, SizeT _len)
- {
- if (*str == '\0')
- return 0;
+ return counter;
+}
- Size len{0};
- while (str[len] != '\0')
- {
- if (len > _len)
- {
- break;
- }
+void rt_zero_memory(voidPtr pointer, Size len) {
+ rt_set_memory((voidPtr)pointer, 0, len);
+}
- ++len;
- }
+Size string_length(const Char *str, SizeT _len) {
+ if (*str == '\0') return 0;
- return len;
+ Size len{0};
+ while (str[len] != '\0') {
+ if (len > _len) {
+ break;
}
- Size string_length(const Char *str)
- {
- if (*str == '\0')
- return 0;
+ ++len;
+ }
- Size len{0};
- while (str[len] != '\0')
- ++len;
+ return len;
+}
- return len;
- }
+Size string_length(const Char *str) {
+ if (*str == '\0') return 0;
- voidPtr rt_set_memory(voidPtr src, char value, Size len)
- {
- if (!src || len < 1)
- return nullptr;
- char *start = reinterpret_cast<Char*>(src);
+ Size len{0};
+ while (str[len] != '\0') ++len;
- while (len)
- {
- *start = value;
- ++start;
- --len;
- }
+ return len;
+}
- return (voidPtr) start;
- }
+voidPtr rt_set_memory(voidPtr src, char value, Size len) {
+ if (!src || len < 1) return nullptr;
+ char *start = reinterpret_cast<Char *>(src);
- Int rt_move_memory(const voidPtr src, voidPtr dst, Size len)
- {
- if (len < 1)
- return -2;
- if (!src || !dst)
- return -1;
+ while (len) {
+ *start = value;
+ ++start;
+ --len;
+ }
- char *srcChr = reinterpret_cast<Char*>(src);
- char *dstChar = reinterpret_cast<Char*>(dst);
- Size index = 0;
+ return (voidPtr)start;
+}
- while (index < len)
- {
- dstChar[index] = srcChr[index];
- srcChr[index] = 0;
+Int rt_move_memory(const voidPtr src, voidPtr dst, Size len) {
+ if (len < 1) return -2;
+ if (!src || !dst) return -1;
- index++;
- }
+ char *srcChr = reinterpret_cast<Char *>(src);
+ char *dstChar = reinterpret_cast<Char *>(dst);
+ Size index = 0;
- return 0;
- }
+ while (index < len) {
+ dstChar[index] = srcChr[index];
+ srcChr[index] = 0;
- Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len)
- {
- if (len < 1)
- return -2;
- if (!src || !dst)
- return -1;
+ index++;
+ }
- char *srcChr = reinterpret_cast<char*>(src);
- char *dstChar = reinterpret_cast<char*>(dst);
- Size index = 0;
+ return 0;
+}
- while (index < len)
- {
- dstChar[index] = srcChr[index];
- index++;
- }
+Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len) {
+ if (len < 1) return -2;
+ if (!src || !dst) return -1;
- return 0;
- }
+ char *srcChr = reinterpret_cast<char *>(src);
+ char *dstChar = reinterpret_cast<char *>(dst);
+ Size index = 0;
- const Char *alloc_string(const Char *text)
- {
- if (!text)
- return nullptr;
+ while (index < len) {
+ dstChar[index] = srcChr[index];
+ index++;
+ }
- const Char *string = new Char[string_length(text)];
- if (!string)
- return nullptr;
+ return 0;
+}
- voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char*>(text));
- voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char*>(string));
- rt_copy_memory(vText, vStr, string_length(text));
- return string;
- }
+const Char *alloc_string(const Char *text) {
+ if (!text) return nullptr;
- Int to_uppercase(Int character)
- {
- if (character >= 'a' && character <= 'z')
- return character - 0x20;
+ const Char *string = new Char[string_length(text)];
+ if (!string) return nullptr;
- return character;
- }
+ voidPtr vText = reinterpret_cast<voidPtr>(const_cast<char *>(text));
+ voidPtr vStr = reinterpret_cast<voidPtr>(const_cast<char *>(string));
+ rt_copy_memory(vText, vStr, string_length(text));
+ return string;
+}
- Int to_lower(Int character)
- {
- if (character >= 'A' && character <= 'Z')
- return character + 0x20;
+Int to_uppercase(Int character) {
+ if (character >= 'a' && character <= 'z') return character - 0x20;
- return character;
- }
+ return character;
+}
- bool to_str(Char *str, Int limit, Int base)
- {
- if (limit == 0)
- return false;
+Int to_lower(Int character) {
+ if (character >= 'A' && character <= 'Z') return character + 0x20;
- Int copy_limit = limit;
- Int cnt = 0;
- Int ret = base;
+ return character;
+}
- while (limit != 1) {
- ret = ret % 10;
- str[cnt] = ret;
+bool to_str(Char *str, Int limit, Int base) {
+ if (limit == 0) return false;
- ++cnt;
- --limit;
- --ret;
- }
+ Int copy_limit = limit;
+ Int cnt = 0;
+ Int ret = base;
- str[copy_limit] = '\0';
- return true;
- }
+ while (limit != 1) {
+ ret = ret % 10;
+ str[cnt] = ret;
- Boolean is_space(Char chr)
- {
- return chr == ' ';
- }
+ ++cnt;
+ --limit;
+ --ret;
+ }
- Boolean is_newln(Char chr)
- {
- return chr == '\n';
- }
+ str[copy_limit] = '\0';
+ return true;
+}
- voidPtr string_in_string(const char *in, const char *needle)
- {
- for (size_t i = 0; i < string_length(in); ++i)
- {
- if (string_compare(in + i, needle, string_length(needle)) == 0)
- return reinterpret_cast<voidPtr>(const_cast<char*>(in + i));
- }
+Boolean is_space(Char chr) { return chr == ' '; }
- return nullptr;
- }
+Boolean is_newln(Char chr) { return chr == '\n'; }
- // @brief Checks for a string start at the character.
-
- char* string_from_char(char* str, const char chr)
- {
- while (*str != chr)
- {
- ++str;
-
- if (*str == 0)
- return nullptr;
- }
-
- return str;
- }
-} // namespace hCore
+voidPtr string_in_string(const char *in, const char *needle) {
+ for (size_t i = 0; i < string_length(in); ++i) {
+ if (string_compare(in + i, needle, string_length(needle)) == 0)
+ return reinterpret_cast<voidPtr>(const_cast<char *>(in + i));
+ }
-extern "C" void memset(void* dst, char src, size_t len)
-{
- hCore::rt_set_memory(dst, src, len);
+ return nullptr;
}
-extern "C" void memcpy(void* dst, void* src, size_t len)
-{
- hCore::rt_copy_memory(src, dst, len);
-} \ No newline at end of file
+// @brief Checks for a string start at the character.
+
+char *string_from_char(char *str, const char chr) {
+ while (*str != chr) {
+ ++str;
+
+ if (*str == 0) return nullptr;
+ }
+
+ return str;
+}
+} // namespace hCore
+
+extern "C" void memset(void *dst, char src, size_t len) {
+ hCore::rt_set_memory(dst, src, len);
+}
+
+extern "C" void memcpy(void *dst, void *src, size_t len) {
+ hCore::rt_copy_memory(src, dst, len);
+}
diff --git a/Private/Source/Variant.cxx b/Private/Source/Variant.cxx
index 3881a07d..cb1a9a01 100644
--- a/Private/Source/Variant.cxx
+++ b/Private/Source/Variant.cxx
@@ -9,24 +9,20 @@
#include <NewKit/Variant.hpp>
-namespace hCore
-{
- const Char* Variant::ToString()
- {
- if (m_Ptr == nullptr)
- {
- return ("Memory:{Nullptr}");
- }
+namespace hCore {
+const Char* Variant::ToString() {
+ if (m_Ptr == nullptr) {
+ return ("Memory:{Nullptr}");
+ }
- switch (m_Kind)
- {
- case VariantKind::kString:
- return ("Class:{String}");
- case VariantKind::kPointer:
- return ("Memory:{Pointer}");
- default:
- return ("Class:{Undefined}");
- }
- }
+ switch (m_Kind) {
+ case VariantKind::kString:
+ return ("Class:{String}");
+ case VariantKind::kPointer:
+ return ("Memory:{Pointer}");
+ default:
+ return ("Class:{Undefined}");
+ }
+}
-} // namespace hCore
+} // namespace hCore