summaryrefslogtreecommitdiffhomepage
path: root/Private/NewKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-05 21:10:18 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-05 21:10:18 +0200
commitf95d8bf159d10b5a9521dcaa0bc37aa0e9dfc02b (patch)
treebf8186f1a0521a64983bb0bca4f7b54883542195 /Private/NewKit
parent5a903c1d8f80ca8d7bc5fbea0aea710ce0133f9d (diff)
MHR-23: Add run_format.sh, kernel patches.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/NewKit')
-rw-r--r--Private/NewKit/Application.hxx17
-rw-r--r--Private/NewKit/Array.hpp91
-rw-r--r--Private/NewKit/ArrayList.hpp89
-rw-r--r--Private/NewKit/Atom.hpp67
-rw-r--r--Private/NewKit/Crc32.hpp9
-rw-r--r--Private/NewKit/CxxAbi.hpp8
-rw-r--r--Private/NewKit/Defines.hpp221
-rw-r--r--Private/NewKit/ErrorID.hpp10
-rw-r--r--Private/NewKit/ErrorOr.hpp82
-rw-r--r--Private/NewKit/Function.hpp82
-rw-r--r--Private/NewKit/Json.hpp176
-rw-r--r--Private/NewKit/KernelCheck.hpp72
-rw-r--r--Private/NewKit/Macros.hpp34
-rw-r--r--Private/NewKit/MutableArray.hpp384
-rw-r--r--Private/NewKit/OwnPtr.hpp135
-rw-r--r--Private/NewKit/PageAllocator.hpp16
-rw-r--r--Private/NewKit/PageManager.hpp126
-rw-r--r--Private/NewKit/Pair.hpp2
-rw-r--r--Private/NewKit/Pmm.hpp59
-rw-r--r--Private/NewKit/Ref.hpp128
-rw-r--r--Private/NewKit/Stream.hpp86
-rw-r--r--Private/NewKit/String.hpp115
-rw-r--r--Private/NewKit/Utils.hpp35
-rw-r--r--Private/NewKit/Variant.hpp71
24 files changed, 1142 insertions, 973 deletions
diff --git a/Private/NewKit/Application.hxx b/Private/NewKit/Application.hxx
index 15ffd073..78ae20cd 100644
--- a/Private/NewKit/Application.hxx
+++ b/Private/NewKit/Application.hxx
@@ -17,14 +17,15 @@
/// \brief Application Interface.
/// \author Amlal El Mahrouss
-typedef struct _Application final {
- /// @brief Releases the object exit the process on main object.
- NewOS::Void(*Release)(struct _Application* Self, NewOS::Int32 ExitCode);
- /// @brief Invoke a function from the application object.
- NewOS::IntPtr(*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...);
- /// @brief Query a new application object from a GUID.
- /// @note this doesn't query a process, it query a registered object withtin that app.
- NewOS::Void(*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf);
+typedef struct _Application final
+{
+ /// @brief Releases the object exit the process on main object.
+ NewOS::Void (*Release)(struct _Application* Self, NewOS::Int32 ExitCode);
+ /// @brief Invoke a function from the application object.
+ NewOS::IntPtr (*Invoke)(struct _Application* Self, NewOS::Int32 Sel, ...);
+ /// @brief Query a new application object from a GUID.
+ /// @note this doesn't query a process, it query a registered object withtin that app.
+ NewOS::Void (*Query)(struct _Application* Self, NewOS::VoidPtr* Dst, NewOS::SizeT SzDst, NewOS::XRN::GUIDSequence GuidOf);
} Application, *ApplicationRef;
#define app_cast reinterpret_cast<ApplicationRef>
diff --git a/Private/NewKit/Array.hpp b/Private/NewKit/Array.hpp
index 68ca9bfc..1799e025 100644
--- a/Private/NewKit/Array.hpp
+++ b/Private/NewKit/Array.hpp
@@ -11,60 +11,59 @@
namespace NewOS
{
-template <typename T, Size N>
-class Array final
-{
-public:
- explicit Array() = default;
- ~Array() = default;
-
- Array &operator=(const Array &) = default;
- Array(const Array &) = default;
+ template <typename T, Size N>
+ class Array final
+ {
+ public:
+ explicit Array() = default;
+ ~Array() = default;
- ErrorOr<T> operator[](Size At)
- {
- if (At > N)
- return {};
+ Array& operator=(const Array&) = default;
+ Array(const Array&) = default;
- kcout << "Returning element\r";
- return ErrorOr<T>(fArray[At]);
- }
+ ErrorOr<T> operator[](Size At)
+ {
+ if (At > N)
+ return {};
- Boolean Empty() const
- {
- for (auto Val : fArray)
- {
- if (Val)
- return false;
- }
+ kcout << "Returning element\r";
+ return ErrorOr<T>(fArray[At]);
+ }
- return true;
- }
+ Boolean Empty() const
+ {
+ for (auto Val : fArray)
+ {
+ if (Val)
+ return false;
+ }
- SizeT Count() const
- {
- SizeT cntElems = 0UL;
- for (auto Val : fArray)
- {
- if (Val)
- ++cntElems;
- }
+ return true;
+ }
- return cntElems;
- }
+ SizeT Count() const
+ {
+ SizeT cntElems = 0UL;
+ for (auto Val : fArray)
+ {
+ if (Val)
+ ++cntElems;
+ }
- const T *CData()
- {
- return fArray;
- }
+ return cntElems;
+ }
- operator bool()
- {
- return !Empty();
- }
+ const T* CData()
+ {
+ return fArray;
+ }
-private:
- T fArray[N];
+ operator bool()
+ {
+ return !Empty();
+ }
-};
+ private:
+ T fArray[N];
+ };
} // namespace NewOS
diff --git a/Private/NewKit/ArrayList.hpp b/Private/NewKit/ArrayList.hpp
index b7ab50cf..31646472 100644
--- a/Private/NewKit/ArrayList.hpp
+++ b/Private/NewKit/ArrayList.hpp
@@ -10,48 +10,49 @@
namespace NewOS
{
- template <typename T>
- class ArrayList final
- {
- public:
- explicit ArrayList(T *list)
- : fList(reinterpret_cast<T>(list))
- {}
-
- ~ArrayList() = default;
-
- ArrayList &operator=(const ArrayList &) = default;
- ArrayList(const ArrayList &) = default;
-
- T *Data()
- {
- return fList;
- }
-
- const T *CData()
- {
- return fList;
- }
-
- T &operator[](int index) const
- {
- return fList[index];
- }
-
- operator bool()
- {
- return fList;
- }
-
- private:
- T *fList;
-
- friend class InitHelpers;
-
- };
-
- template <typename ValueType> ArrayList<ValueType> make_list(ValueType val)
- {
- return ArrayList<ValueType>{val};
- }
+ template <typename T>
+ class ArrayList final
+ {
+ public:
+ explicit ArrayList(T* list)
+ : fList(reinterpret_cast<T>(list))
+ {
+ }
+
+ ~ArrayList() = default;
+
+ ArrayList& operator=(const ArrayList&) = default;
+ ArrayList(const ArrayList&) = default;
+
+ T* Data()
+ {
+ return fList;
+ }
+
+ const T* CData()
+ {
+ return fList;
+ }
+
+ T& operator[](int index) const
+ {
+ return fList[index];
+ }
+
+ operator bool()
+ {
+ return fList;
+ }
+
+ private:
+ T* fList;
+
+ friend class InitHelpers;
+ };
+
+ template <typename ValueType>
+ ArrayList<ValueType> make_list(ValueType val)
+ {
+ return ArrayList<ValueType>{val};
+ }
} // namespace NewOS
diff --git a/Private/NewKit/Atom.hpp b/Private/NewKit/Atom.hpp
index 648302fc..812e1819 100644
--- a/Private/NewKit/Atom.hpp
+++ b/Private/NewKit/Atom.hpp
@@ -9,37 +9,38 @@
namespace NewOS
{
-template <typename T> class Atom final
-{
- public:
- explicit Atom() = default;
- ~Atom() = default;
-
- public:
- Atom &operator=(const Atom &) = delete;
- Atom(const Atom &) = delete;
-
- public:
- T operator[](Size sz)
- {
- return (fArrayOfAtoms & sz);
- }
- void operator|(Size sz)
- {
- fArrayOfAtoms |= sz;
- }
-
- friend Boolean operator==(Atom<T> &atomic, const T &idx)
- {
- return atomic[idx] == idx;
- }
-
- friend Boolean operator!=(Atom<T> &atomic, const T &idx)
- {
- return atomic[idx] == idx;
- }
-
- private:
- T fArrayOfAtoms;
-};
+ template <typename T>
+ class Atom final
+ {
+ public:
+ explicit Atom() = default;
+ ~Atom() = default;
+
+ public:
+ Atom& operator=(const Atom&) = delete;
+ Atom(const Atom&) = delete;
+
+ public:
+ T operator[](Size sz)
+ {
+ return (fArrayOfAtoms & sz);
+ }
+ void operator|(Size sz)
+ {
+ fArrayOfAtoms |= sz;
+ }
+
+ friend Boolean operator==(Atom<T>& atomic, const T& idx)
+ {
+ return atomic[idx] == idx;
+ }
+
+ friend Boolean operator!=(Atom<T>& atomic, const T& idx)
+ {
+ return atomic[idx] == idx;
+ }
+
+ private:
+ T fArrayOfAtoms;
+ };
} // namespace NewOS
diff --git a/Private/NewKit/Crc32.hpp b/Private/NewKit/Crc32.hpp
index 0dccd4d8..c0feaa7f 100644
--- a/Private/NewKit/Crc32.hpp
+++ b/Private/NewKit/Crc32.hpp
@@ -14,8 +14,9 @@
#define kCrcCnt (256)
-namespace NewOS {
-UInt ke_calculate_crc32(const Char* crc, UInt len) noexcept;
-} // namespace NewOS
+namespace NewOS
+{
+ UInt ke_calculate_crc32(const Char* crc, UInt len) noexcept;
+} // namespace NewOS
-#endif // !__CRC32_H__
+#endif // !__CRC32_H__
diff --git a/Private/NewKit/CxxAbi.hpp b/Private/NewKit/CxxAbi.hpp
index d210bf18..9bba2beb 100644
--- a/Private/NewKit/CxxAbi.hpp
+++ b/Private/NewKit/CxxAbi.hpp
@@ -13,16 +13,16 @@
struct atexit_func_entry_t
{
- void (*destructor_func)(void *);
- void *obj_ptr;
- void *dso_handle;
+ void (*destructor_func)(void*);
+ void* obj_ptr;
+ void* dso_handle;
};
typedef unsigned uarch_t;
namespace cxxabiv1
{
- typedef void *__guard;
+ typedef void* __guard;
}
#endif // __GNUC__ \ No newline at end of file
diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp
index bed02081..fb7d84bb 100644
--- a/Private/NewKit/Defines.hpp
+++ b/Private/NewKit/Defines.hpp
@@ -22,117 +22,128 @@
#endif
#endif
-namespace NewOS {
-using voidPtr = void *;
-using VoidPtr = void *;
-using nullPtr = decltype(nullptr);
-using NullPtr = decltype(nullptr);
-
-using Int = int;
-using Int32 = int;
-using UShort = unsigned short;
-using UInt16 = unsigned short;
-using Short = short;
-using Int16 = short;
-using UInt = unsigned int;
-using UInt32 = unsigned int;
-using Long = __INT64_TYPE__;
-using Int64 = __INT64_TYPE__;
-using ULong = __UINT64_TYPE__;
-using UInt64 = __UINT64_TYPE__;
-using Boolean = bool;
-using Bool = bool;
-using Char = char;
-using UChar = unsigned char;
-using UInt8 = unsigned char;
-
-using SSize = Int64;
-using SSizeT = Int64;
-using Size = __SIZE_TYPE__;
-using SizeT = __SIZE_TYPE__;
-using IntPtr = __INTPTR_TYPE__;
-using UIntPtr = __UINTPTR_TYPE__;
-using IntFast = __INT_FAST32_TYPE__;
-using IntFast64 = __INT_FAST64_TYPE__;
-using PtrDiff = __PTRDIFF_TYPE__;
-
-typedef UIntPtr *Ptr64;
-typedef UInt32 *Ptr32;
-
-using Utf8Char = char8_t;
-using Utf16Char = char16_t;
-using WideChar = wchar_t;
-using Utf32Char = char32_t;
-
-using Void = void;
-
-using Lba = UInt64;
-
-enum class Endian : UChar { kEndianLittle, kEndianBig, kEndianMixed, kCount };
-
-/// @brief Forward object.
-/// @tparam Args the object type.
-/// @param arg the object.
-/// @return object's rvalue
-template <typename Args>
-inline Args &&forward(Args &arg) {
- return static_cast<Args &&>(arg);
-}
-
-/// @brief Move object.
-/// @tparam Args the object type.
-/// @param arg the object.
-/// @return object's rvalue
-template <typename Args>
-inline Args &&move(Args &&arg) {
- return static_cast<Args &&>(arg);
-}
-
-/// @brief Encoder class
-/// Used to cast A to B or B to A.
-class Encoder final {
-public:
- explicit Encoder() = default;
- ~Encoder() = default;
-
- Encoder &operator=(const Encoder &) = default;
- Encoder(const Encoder &) = default;
-
-public:
- /// @brief Convert type to bytes.
- /// @tparam T the type.
- /// @param type (a1) the data.
- /// @return a1 as Char*
- template <typename T>
- Char* AsBytes(T type) noexcept {
- return reinterpret_cast<Char*>(type);
- }
-
- /// @brief Convert T class to Y class.
- /// @tparam T the class type of type.
- /// @tparam Y the result class.
- /// @param type the class to cast.
- /// @return the class as Y.
- template <typename T, typename Y>
- Y As(T type) noexcept {
- return type.template As<Y>();
- }
-
-};
-} // namespace NewOS
-
-#define DEDUCE_ENDIAN(address, value) \
- (((reinterpret_cast<NewOS::Char *>(address)[0]) == (value)) \
- ? (NewOS::Endian::kEndianBig) \
- : (NewOS::Endian::kEndianLittle))
+namespace NewOS
+{
+ using voidPtr = void*;
+ using VoidPtr = void*;
+ using nullPtr = decltype(nullptr);
+ using NullPtr = decltype(nullptr);
+
+ using Int = int;
+ using Int32 = int;
+ using UShort = unsigned short;
+ using UInt16 = unsigned short;
+ using Short = short;
+ using Int16 = short;
+ using UInt = unsigned int;
+ using UInt32 = unsigned int;
+ using Long = __INT64_TYPE__;
+ using Int64 = __INT64_TYPE__;
+ using ULong = __UINT64_TYPE__;
+ using UInt64 = __UINT64_TYPE__;
+ using Boolean = bool;
+ using Bool = bool;
+ using Char = char;
+ using UChar = unsigned char;
+ using UInt8 = unsigned char;
+
+ using SSize = Int64;
+ using SSizeT = Int64;
+ using Size = __SIZE_TYPE__;
+ using SizeT = __SIZE_TYPE__;
+ using IntPtr = __INTPTR_TYPE__;
+ using UIntPtr = __UINTPTR_TYPE__;
+ using IntFast = __INT_FAST32_TYPE__;
+ using IntFast64 = __INT_FAST64_TYPE__;
+ using PtrDiff = __PTRDIFF_TYPE__;
+
+ typedef UIntPtr* Ptr64;
+ typedef UInt32* Ptr32;
+
+ using Utf8Char = char8_t;
+ using Utf16Char = char16_t;
+ using WideChar = wchar_t;
+ using Utf32Char = char32_t;
+
+ using Void = void;
+
+ using Lba = UInt64;
+
+ enum class Endian : UChar
+ {
+ kEndianLittle,
+ kEndianBig,
+ kEndianMixed,
+ kCount
+ };
+
+ /// @brief Forward object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& forward(Args& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Move object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& move(Args&& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Encoder class
+ /// Used to cast A to B or B to A.
+ class Encoder final
+ {
+ public:
+ explicit Encoder() = default;
+ ~Encoder() = default;
+
+ Encoder& operator=(const Encoder&) = default;
+ Encoder(const Encoder&) = default;
+
+ public:
+ /// @brief Convert type to bytes.
+ /// @tparam T the type.
+ /// @param type (a1) the data.
+ /// @return a1 as Char*
+ template <typename T>
+ Char* AsBytes(T type) noexcept
+ {
+ return reinterpret_cast<Char*>(type);
+ }
+
+ /// @brief Convert T class to Y class.
+ /// @tparam T the class type of type.
+ /// @tparam Y the result class.
+ /// @param type the class to cast.
+ /// @return the class as Y.
+ template <typename T, typename Y>
+ Y As(T type) noexcept
+ {
+ return type.template As<Y>();
+ }
+ };
+} // namespace NewOS
+
+#define DEDUCE_ENDIAN(address, value) \
+ (((reinterpret_cast<NewOS::Char*>(address)[0]) == (value)) \
+ ? (NewOS::Endian::kEndianBig) \
+ : (NewOS::Endian::kEndianLittle))
#define Yes (true)
-#define No (false)
+#define No (false)
#define VoidStar NewOS::voidPtr
#ifdef INIT
#undef INIT
-#endif // ifdef INIT
+#endif // ifdef INIT
#define INIT(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__)
diff --git a/Private/NewKit/ErrorID.hpp b/Private/NewKit/ErrorID.hpp
index b2cc65d1..fcd574e2 100644
--- a/Private/NewKit/ErrorID.hpp
+++ b/Private/NewKit/ErrorID.hpp
@@ -11,9 +11,9 @@
#include <NewKit/ErrorOr.hpp>
#include <NewKit/Defines.hpp>
-#define H_EXEC_ERROR 33
+#define H_EXEC_ERROR 33
#define H_FILE_NOT_FOUND 35
-#define H_DIR_NOT_FOUND 36
-#define H_FILE_EXISTS 46
-#define H_UNIMPLEMENTED 0
-#define H_INVALID_DATA 1
+#define H_DIR_NOT_FOUND 36
+#define H_FILE_EXISTS 46
+#define H_UNIMPLEMENTED 0
+#define H_INVALID_DATA 1
diff --git a/Private/NewKit/ErrorOr.hpp b/Private/NewKit/ErrorOr.hpp
index 6d85a943..a2b5da62 100644
--- a/Private/NewKit/ErrorOr.hpp
+++ b/Private/NewKit/ErrorOr.hpp
@@ -14,55 +14,59 @@
namespace NewOS
{
-using ErrorT = UInt;
+ using ErrorT = UInt;
-template <typename T> class ErrorOr final
-{
- public:
- ErrorOr() = default;
- ~ErrorOr() = default;
+ template <typename T>
+ class ErrorOr final
+ {
+ public:
+ ErrorOr() = default;
+ ~ErrorOr() = default;
- public:
- explicit ErrorOr(Int32 err)
- : mId(err)
- {}
+ public:
+ explicit ErrorOr(Int32 err)
+ : mId(err)
+ {
+ }
- explicit ErrorOr(nullPtr Null)
- {}
+ explicit ErrorOr(nullPtr Null)
+ {
+ }
- explicit ErrorOr(T Class)
- : mRef(Class)
- {}
+ explicit ErrorOr(T Class)
+ : mRef(Class)
+ {
+ }
- ErrorOr &operator=(const ErrorOr &) = default;
- ErrorOr(const ErrorOr &) = default;
+ ErrorOr& operator=(const ErrorOr&) = default;
+ ErrorOr(const ErrorOr&) = default;
- ErrorOr &operator=(const Ref<T> &refErr)
- {
- mRef = refErr;
- return *this;
- }
+ ErrorOr& operator=(const Ref<T>& refErr)
+ {
+ mRef = refErr;
+ return *this;
+ }
- Ref<T> Leak()
- {
- return mRef;
- }
+ Ref<T> Leak()
+ {
+ return mRef;
+ }
- Int32 Error()
- {
- return mId;
- }
+ Int32 Error()
+ {
+ return mId;
+ }
- operator bool()
- {
- return mRef;
- }
+ operator bool()
+ {
+ return mRef;
+ }
- private:
- Ref<T> mRef;
- Int32 mId{0};
-};
+ private:
+ Ref<T> mRef;
+ Int32 mId{0};
+ };
-using ErrorOrAny = ErrorOr<voidPtr>;
+ using ErrorOrAny = ErrorOr<voidPtr>;
} // namespace NewOS
diff --git a/Private/NewKit/Function.hpp b/Private/NewKit/Function.hpp
index 79d33a3b..12ae03f3 100644
--- a/Private/NewKit/Function.hpp
+++ b/Private/NewKit/Function.hpp
@@ -3,37 +3,51 @@
#include <NewKit/Defines.hpp>
-namespace NewOS {
-template <typename T, typename... Args>
-class Function final {
- public:
- Function() = default;
-
- public:
- explicit Function(T (*Fn)(Args... args)) : fFn(Fn) {}
-
- ~Function() = default;
-
- Function &operator=(const Function &) = default;
- Function(const Function &) = default;
-
- template <typename... XArgs>
- T operator()(Args... args) {
- return fFn(args...);
- }
-
- template <typename... XArgs>
- T Call(Args... args) {
- return fFn(args...);
- }
-
- operator bool() { return fFn; }
-
- bool operator!() { return !fFn; }
-
- private:
- T (*fFn)(Args... args);
-};
-} // namespace NewOS
-
-#endif // !_INC_FUNCTION_HPP__
+namespace NewOS
+{
+ template <typename T, typename... Args>
+ class Function final
+ {
+ public:
+ Function() = default;
+
+ public:
+ explicit Function(T (*Fn)(Args... args))
+ : fFn(Fn)
+ {
+ }
+
+ ~Function() = default;
+
+ Function& operator=(const Function&) = default;
+ Function(const Function&) = default;
+
+ template <typename... XArgs>
+ T operator()(Args... args)
+ {
+ return fFn(args...);
+ }
+
+ template <typename... XArgs>
+ T Call(Args... args)
+ {
+ return fFn(args...);
+ }
+
+ operator bool()
+ {
+ return fFn;
+ }
+
+ bool operator!()
+ {
+ return !fFn;
+ }
+
+ private:
+ T(*fFn)
+ (Args... args);
+ };
+} // namespace NewOS
+
+#endif // !_INC_FUNCTION_HPP__
diff --git a/Private/NewKit/Json.hpp b/Private/NewKit/Json.hpp
index d4514ef1..8f7c2765 100644
--- a/Private/NewKit/Json.hpp
+++ b/Private/NewKit/Json.hpp
@@ -15,78 +15,104 @@
#include <NewKit/String.hpp>
#include <NewKit/Utils.hpp>
-namespace NewOS {
-/// @brief Json value class
-class JsonType final {
- public:
- explicit JsonType() : NewOS::JsonType(1, 1) {}
-
- explicit JsonType(SizeT lhsLen, SizeT rhsLen)
- : fKey(lhsLen), fValue(rhsLen) {}
-
- ~JsonType() = default;
-
- NEWOS_COPY_DEFAULT(JsonType);
-
- private:
- StringView fKey;
- StringView fValue;
-
- public:
- /// @brief returns the key of the json
- /// @return the key as string view.
- StringView &AsKey() { return fKey; }
-
- /// @brief returns the value of the json.
- /// @return the key as string view.
- StringView &AsValue() { return fValue; }
-
- static JsonType kUndefined;
-};
-
-/// @brief Json stream helper class.
-struct JsonStreamTrait final {
- JsonType In(const char *full_array) {
- SizeT len = rt_string_len(full_array);
-
- if (full_array[0] == '\"' && full_array[len - 1] == ',' ||
- full_array[len - 1] == '\"') {
- Boolean probe_key = true;
-
- SizeT key_len = 0;
- SizeT value_len = 0;
-
- for (SizeT i = 1; i < len; i++) {
- if (full_array[i] == ' ') continue;
-
- JsonType type(kPathLen, kPathLen);
-
- if (probe_key) {
- type.AsKey().Data()[key_len] = full_array[i];
- ++key_len;
-
- if (full_array[i] == '\"') {
- probe_key = false;
- type.AsKey().Data()[key_len] = 0;
-
- ++i;
- }
- } else {
- type.AsValue().Data()[value_len] = full_array[i];
- ++value_len;
-
- if (full_array[i] == '\"') {
- type.AsValue().Data()[value_len] = 0;
- }
- }
- }
- }
-
- return JsonType::kUndefined;
- }
-
- JsonType Out(JsonType &out) { return out; }
-};
-
-using JsonStream = Stream<JsonStreamTrait, JsonType>;
-} // namespace NewOS
+namespace NewOS
+{
+ /// @brief Json value class
+ class JsonType final
+ {
+ public:
+ explicit JsonType()
+ : NewOS::JsonType(1, 1)
+ {
+ }
+
+ explicit JsonType(SizeT lhsLen, SizeT rhsLen)
+ : fKey(lhsLen), fValue(rhsLen)
+ {
+ }
+
+ ~JsonType() = default;
+
+ NEWOS_COPY_DEFAULT(JsonType);
+
+ private:
+ StringView fKey;
+ StringView fValue;
+
+ public:
+ /// @brief returns the key of the json
+ /// @return the key as string view.
+ StringView& AsKey()
+ {
+ return fKey;
+ }
+
+ /// @brief returns the value of the json.
+ /// @return the key as string view.
+ StringView& AsValue()
+ {
+ return fValue;
+ }
+
+ static JsonType kUndefined;
+ };
+
+ /// @brief Json stream helper class.
+ struct JsonStreamTrait final
+ {
+ JsonType In(const char* full_array)
+ {
+ SizeT len = rt_string_len(full_array);
+
+ if (full_array[0] == '\"' && full_array[len - 1] == ',' ||
+ full_array[len - 1] == '\"')
+ {
+ Boolean probe_key = true;
+
+ SizeT key_len = 0;
+ SizeT value_len = 0;
+
+ for (SizeT i = 1; i < len; i++)
+ {
+ if (full_array[i] == ' ')
+ continue;
+
+ JsonType type(kPathLen, kPathLen);
+
+ if (probe_key)
+ {
+ type.AsKey().Data()[key_len] = full_array[i];
+ ++key_len;
+
+ if (full_array[i] == '\"')
+ {
+ probe_key = false;
+ type.AsKey().Data()[key_len] = 0;
+
+ ++i;
+ }
+ }
+ else
+ {
+ type.AsValue().Data()[value_len] = full_array[i];
+ ++value_len;
+
+ if (full_array[i] == '\"')
+ {
+ type.AsValue().Data()[value_len] = 0;
+ }
+ }
+ }
+ }
+
+ return JsonType::kUndefined;
+ }
+
+ JsonType Out(JsonType& out)
+ {
+ return out;
+ }
+ };
+
+ using JsonStream = Stream<JsonStreamTrait, JsonType>;
+} // namespace NewOS
diff --git a/Private/NewKit/KernelCheck.hpp b/Private/NewKit/KernelCheck.hpp
index c65390ad..3416846e 100644
--- a/Private/NewKit/KernelCheck.hpp
+++ b/Private/NewKit/KernelCheck.hpp
@@ -9,49 +9,55 @@
#include <NewKit/Defines.hpp>
-namespace NewOS {
-void ke_runtime_check(bool bExpression, const char *file, const char *line);
+namespace NewOS
+{
+ void ke_runtime_check(bool bExpression, const char* file, const char* line);
}
#define MUST_PASS_COMPILER(EXPR, MSG) static_assert(EXPR, MSG)
#define __MUST_PASS(EXPR, FILE, LINE) \
- NewOS::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE))
+ NewOS::ke_runtime_check(EXPR, FILE, STRINGIFY(LINE))
#define MUST_PASS(EXPR) __MUST_PASS(EXPR, __FILE__, __LINE__)
-#define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION)
-
-enum RUNTIME_CHECK {
- RUNTIME_CHECK_FAILED = -1,
- RUNTIME_CHECK_POINTER = 0,
- RUNTIME_CHECK_EXPRESSION,
- RUNTIME_CHECK_FILE,
- RUNTIME_CHECK_IPC,
- RUNTIME_CHECK_TLS,
- RUNTIME_CHECK_HANDSHAKE,
- RUNTIME_CHECK_ACPI,
- RUNTIME_CHECK_INVALID_PRIVILEGE,
- RUNTIME_CHECK_PROCESS,
- RUNTIME_CHECK_BAD_BEHAVIOR,
- RUNTIME_CHECK_BOOTSTRAP,
- RUNTIME_CHECK_UNEXCPECTED,
- RUNTIME_CHECK_COUNT,
+#define assert(EXPR) MUST_PASS(EXPR, RUNTIME_CHECK_EXPRESSION)
+
+enum RUNTIME_CHECK
+{
+ RUNTIME_CHECK_FAILED = -1,
+ RUNTIME_CHECK_POINTER = 0,
+ RUNTIME_CHECK_EXPRESSION,
+ RUNTIME_CHECK_FILE,
+ RUNTIME_CHECK_IPC,
+ RUNTIME_CHECK_TLS,
+ RUNTIME_CHECK_HANDSHAKE,
+ RUNTIME_CHECK_ACPI,
+ RUNTIME_CHECK_INVALID_PRIVILEGE,
+ RUNTIME_CHECK_PROCESS,
+ RUNTIME_CHECK_BAD_BEHAVIOR,
+ RUNTIME_CHECK_BOOTSTRAP,
+ RUNTIME_CHECK_UNEXCPECTED,
+ RUNTIME_CHECK_COUNT,
};
-namespace NewOS {
-class DumpManager final {
- public:
- static void Dump(void) {
- // TODO:
- }
-};
+namespace NewOS
+{
+ class DumpManager final
+ {
+ public:
+ static void Dump(void)
+ {
+ // TODO:
+ }
+ };
-void ke_stop(const Int &id);
-} // namespace NewOS
+ void ke_stop(const Int& id);
+} // namespace NewOS
#ifdef TRY
#undef TRY
#endif
-#define TRY(FN) \
- if (!FN()) { \
- MUST_PASS(false); \
- }
+#define TRY(FN) \
+ if (!FN()) \
+ { \
+ MUST_PASS(false); \
+ }
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index 6fe25fdf..86060a02 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -23,43 +23,47 @@
#endif
#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(a) \
- (((sizeof(a) / sizeof(*(a))) / \
- (static_cast<NewOS::Size>(!(sizeof(a) % sizeof(*(a)))))))
+#define ARRAY_SIZE(a) \
+ (((sizeof(a) / sizeof(*(a))) / \
+ (static_cast<NewOS::Size>(!(sizeof(a) % sizeof(*(a)))))))
#endif
#ifndef ALIGN
#define ALIGN(X) __attribute__((aligned(X)))
-#endif // #ifndef ALIGN
+#endif // #ifndef ALIGN
#ifndef ATTRIBUTE
#define ATTRIBUTE(X) __attribute__((X))
-#endif // #ifndef ATTRIBUTE
+#endif // #ifndef ATTRIBUTE
#ifndef __MAHROUSS__
#define __MAHROUSS__ (202401)
-#endif // !__MAHROUSS__
+#endif // !__MAHROUSS__
#ifndef EXTERN_C
#define EXTERN_C extern "C"
#endif
#ifndef MAKE_ENUM
-#define MAKE_ENUM(NAME) enum NAME {
+#define MAKE_ENUM(NAME) \
+ enum NAME \
+ {
#endif
#ifndef END_ENUM
#define END_ENUM() \
- } \
- ;
+ } \
+ ;
#endif
#ifndef MAKE_STRING_ENUM
-#define MAKE_STRING_ENUM(NAME) namespace NAME {
+#define MAKE_STRING_ENUM(NAME) \
+ namespace NAME \
+ {
#endif
#ifndef ENUM_STRING
-#define ENUM_STRING(NAME, VAL) inline constexpr const char *NAME = VAL
+#define ENUM_STRING(NAME, VAL) inline constexpr const char* NAME = VAL
#endif
#ifndef END_STRING_ENUM
@@ -68,17 +72,17 @@
#ifndef Alloca
#define Alloca(Sz) __builtin_alloca(Sz)
-#endif // #ifndef Alloca
+#endif // #ifndef Alloca
#ifndef CANT_REACH
#define CANT_REACH() __builtin_unreachable()
#endif
-#define kBadPtr 0xFBFBFBFBFBFBFBFB
+#define kBadPtr 0xFBFBFBFBFBFBFBFB
#define kMaxAddr 0xFFFFFFFFFFFFFFFF
#define kPathLen 255
-#define PACKED ATTRIBUTE(packed)
+#define PACKED ATTRIBUTE(packed)
#define NO_EXEC ATTRIBUTE(noexec)
#define EXTERN extern
@@ -90,7 +94,7 @@
#define self this
#endif
-#define STRINGIFY(X) #X
+#define STRINGIFY(X) #X
#define NEWOS_UNUSED(X) ((void)X)
#ifndef RGB
diff --git a/Private/NewKit/MutableArray.hpp b/Private/NewKit/MutableArray.hpp
index b46f1bc7..5eca9087 100644
--- a/Private/NewKit/MutableArray.hpp
+++ b/Private/NewKit/MutableArray.hpp
@@ -9,214 +9,224 @@
#include <NewKit/Array.hpp>
#include <NewKit/Defines.hpp>
-#define TRY_FIND_NODE(NAME, NODE) \
- auto *NAME = NODE; \
- while (NAME) \
- { \
- if (NAME->fIndex == Index) \
- return NAME->fVal; \
- NAME = NAME->fNext; \
- }
-
-
-
-#define TRY_FIND_NODE2(NAME, NODE) \
- auto *NAME = NODE; \
- while (NAME) \
- { \
- if (NAME->fIndex == Index) \
- return Ref<T>{NAME->fVal}; \
- NAME = NAME->fNext; \
- }
-
-
-
-#define TRY_REMOVE_NODE(NODE) \
- if (NODE && NODE->fIndex == Index) \
- { \
- NODE->fUsed = false; \
- NODE->fIndex = 0; \
- \
- return true; \
- }
-
-
+#define TRY_FIND_NODE(NAME, NODE) \
+ auto* NAME = NODE; \
+ while (NAME) \
+ { \
+ if (NAME->fIndex == Index) \
+ return NAME->fVal; \
+ NAME = NAME->fNext; \
+ }
+
+#define TRY_FIND_NODE2(NAME, NODE) \
+ auto* NAME = NODE; \
+ while (NAME) \
+ { \
+ if (NAME->fIndex == Index) \
+ return Ref<T>{NAME->fVal}; \
+ NAME = NAME->fNext; \
+ }
+
+#define TRY_REMOVE_NODE(NODE) \
+ if (NODE && NODE->fIndex == Index) \
+ { \
+ NODE->fUsed = false; \
+ NODE->fIndex = 0; \
+ \
+ return true; \
+ }
// FIXME: this is a shitty algorithm, which is consumer hungry.
// Remove and occurences of that, and remove that class.
namespace NewOS
{
-template <typename T> class MutableArray;
-
-template <typename T, T _PlaceHolderValue> class NullableMutableArray;
-
-template <typename T> class MutableLinkedList
-{
- public:
- T fVal;
- SizeT fIndex{0};
- Boolean fUsed{false};
-
- MutableLinkedList *fPrev{nullptr};
- MutableLinkedList *fNext{nullptr};
-};
-
-template <typename T, T _PlaceHolderValue> class NullableMutableArray
-{
- public:
- // explicit this.
- explicit NullableMutableArray() : fFirstNode(new MutableLinkedList<T>()) {}
-
- /*
+ template <typename T>
+ class MutableArray;
+
+ template <typename T, T _PlaceHolderValue>
+ class NullableMutableArray;
+
+ template <typename T>
+ class MutableLinkedList
+ {
+ public:
+ T fVal;
+ SizeT fIndex{0};
+ Boolean fUsed{false};
+
+ MutableLinkedList* fPrev{nullptr};
+ MutableLinkedList* fNext{nullptr};
+ };
+
+ template <typename T, T _PlaceHolderValue>
+ class NullableMutableArray
+ {
+ public:
+ // explicit this.
+ explicit NullableMutableArray()
+ : fFirstNode(new MutableLinkedList<T>())
+ {
+ }
+
+ /*
* We free all the nodes allocated by the array
* and store the next one inside "NextIt"
*/
- virtual ~NullableMutableArray()
- {
- auto *It = fFirstNode;
- MutableLinkedList<T> *NextIt = nullptr;
-
- while (It)
- {
- NextIt = It->fNext;
- delete It;
-
- It = NextIt;
- }
- }
-
- NullableMutableArray &operator=(const NullableMutableArray &) = default;
- NullableMutableArray(const NullableMutableArray &) = default;
-
- operator bool() { return Count() > 1; }
-
- public:
- T operator[](const SizeT &Index) const
- {
- TRY_FIND_NODE(first, fFirstNode);
- TRY_FIND_NODE(last, fLastNode);
-
- return _PlaceHolderValue;
- }
-
- SizeT Count() const { return fNodeCount; }
-
- public:
- Boolean Remove(const SizeT &Index)
- {
- TRY_REMOVE_NODE(fFirstNode);
- TRY_REMOVE_NODE(fLastNode);
-
- return false;
- }
-
- Boolean Add(const T val)
- {
- auto *iterationNode = fFirstNode;
- MUST_PASS(iterationNode);
-
- while (iterationNode)
- {
- if (!iterationNode->fUsed)
- {
- iterationNode->fVal = val;
- iterationNode->fIndex = 0;
-
- iterationNode->fUsed = true;
-
- ++fNodeCount;
-
- return true;
- }
-
- iterationNode = iterationNode->fNext;
- }
-
- return false;
- }
-
- private:
- /* Avoid useless lookups */
- MutableLinkedList<T> *fLastNode{nullptr};
- MutableLinkedList<T> *fFirstNode{nullptr};
-
- /* Number of nodes inside of this dynamic array. */
- NewOS::SizeT fNodeCount{0};
-
- private:
- // don't remove that
- friend MutableArray<T>;
-};
-
-template <typename T>
-class MutableArray : public NullableMutableArray<voidPtr, nullptr>
-{
- public:
- // explicit this.
- explicit MutableArray() = default;
- virtual ~MutableArray() = default;
-
- NEWOS_COPY_DEFAULT(MutableArray)
-
- public:
- Boolean Add(const T val)
- {
- auto *iterationNode = fFirstNode;
- MUST_PASS(iterationNode);
-
- while (iterationNode)
- {
- if (!iterationNode->fUsed)
- {
- iterationNode->fVal = val;
- iterationNode->fIndex = 0;
+ virtual ~NullableMutableArray()
+ {
+ auto* It = fFirstNode;
+ MutableLinkedList<T>* NextIt = nullptr;
+
+ while (It)
+ {
+ NextIt = It->fNext;
+ delete It;
- iterationNode->fUsed = true;
+ It = NextIt;
+ }
+ }
- ++fNodeCount;
+ NullableMutableArray& operator=(const NullableMutableArray&) = default;
+ NullableMutableArray(const NullableMutableArray&) = default;
- return true;
- }
+ operator bool()
+ {
+ return Count() > 1;
+ }
- iterationNode = iterationNode->fNext;
- }
+ public:
+ T operator[](const SizeT& Index) const
+ {
+ TRY_FIND_NODE(first, fFirstNode);
+ TRY_FIND_NODE(last, fLastNode);
- return false;
- }
+ return _PlaceHolderValue;
+ }
+
+ SizeT Count() const
+ {
+ return fNodeCount;
+ }
+
+ public:
+ Boolean Remove(const SizeT& Index)
+ {
+ TRY_REMOVE_NODE(fFirstNode);
+ TRY_REMOVE_NODE(fLastNode);
- public:
- Ref<T> operator[](const SizeT &Index) const
- {
- TRY_FIND_NODE2(first, fFirstNode);
- TRY_FIND_NODE2(last, fLastNode);
+ return false;
+ }
- return {};
- }
+ Boolean Add(const T val)
+ {
+ auto* iterationNode = fFirstNode;
+ MUST_PASS(iterationNode);
- SizeT Count() const { return fNodeCount; }
+ while (iterationNode)
+ {
+ if (!iterationNode->fUsed)
+ {
+ iterationNode->fVal = val;
+ iterationNode->fIndex = 0;
+
+ iterationNode->fUsed = true;
+
+ ++fNodeCount;
+
+ return true;
+ }
+
+ iterationNode = iterationNode->fNext;
+ }
+
+ return false;
+ }
+
+ private:
+ /* Avoid useless lookups */
+ MutableLinkedList<T>* fLastNode{nullptr};
+ MutableLinkedList<T>* fFirstNode{nullptr};
+
+ /* Number of nodes inside of this dynamic array. */
+ NewOS::SizeT fNodeCount{0};
+
+ private:
+ // don't remove that
+ friend MutableArray<T>;
+ };
+
+ template <typename T>
+ class MutableArray : public NullableMutableArray<voidPtr, nullptr>
+ {
+ public:
+ // explicit this.
+ explicit MutableArray() = default;
+ virtual ~MutableArray() = default;
+
+ NEWOS_COPY_DEFAULT(MutableArray)
+
+ public:
+ Boolean Add(const T val)
+ {
+ auto* iterationNode = fFirstNode;
+ MUST_PASS(iterationNode);
+
+ while (iterationNode)
+ {
+ if (!iterationNode->fUsed)
+ {
+ iterationNode->fVal = val;
+ iterationNode->fIndex = 0;
+
+ iterationNode->fUsed = true;
+
+ ++fNodeCount;
- bool Contains(T &value) noexcept
- {
- MutableLinkedList<T> *first = fFirstNode;
+ return true;
+ }
+
+ iterationNode = iterationNode->fNext;
+ }
+
+ return false;
+ }
+
+ public:
+ Ref<T> operator[](const SizeT& Index) const
+ {
+ TRY_FIND_NODE2(first, fFirstNode);
+ TRY_FIND_NODE2(last, fLastNode);
+
+ return {};
+ }
- while (first)
- {
- if (first->fVal == value && first->fUsed)
- return true;
+ SizeT Count() const
+ {
+ return fNodeCount;
+ }
+
+ bool Contains(T& value) noexcept
+ {
+ MutableLinkedList<T>* first = fFirstNode;
+
+ while (first)
+ {
+ if (first->fVal == value && first->fUsed)
+ return true;
- first = first->fNext;
- }
+ first = first->fNext;
+ }
- return false;
- }
+ return false;
+ }
- private:
- /* Avoid useless lookups */
- MutableLinkedList<T> *fLastNode{nullptr};
- MutableLinkedList<T> *fFirstNode{nullptr};
+ private:
+ /* Avoid useless lookups */
+ MutableLinkedList<T>* fLastNode{nullptr};
+ MutableLinkedList<T>* fFirstNode{nullptr};
- /* Number of nodes inside of this dynamic array. */
- NewOS::SizeT fNodeCount{0};
-};
+ /* Number of nodes inside of this dynamic array. */
+ NewOS::SizeT fNodeCount{0};
+ };
} // namespace NewOS
diff --git a/Private/NewKit/OwnPtr.hpp b/Private/NewKit/OwnPtr.hpp
index ff2b59e1..742295da 100644
--- a/Private/NewKit/OwnPtr.hpp
+++ b/Private/NewKit/OwnPtr.hpp
@@ -11,57 +11,84 @@
#include <NewKit/KernelCheck.hpp>
#include <NewKit/Ref.hpp>
-namespace NewOS {
-template <typename T>
-class OwnPtr;
-
-template <typename T>
-class NonNullRefPtr;
-
-template <typename T>
-class OwnPtr final {
- public:
- OwnPtr() {}
- ~OwnPtr() { this->Delete(); }
-
- OwnPtr &operator=(const OwnPtr &) = default;
- OwnPtr(const OwnPtr &) = default;
-
- public:
- template <typename... Args>
- bool New(Args &&...arg) {
- if (fCls) {
- return false;
- }
-
- fCls = new T(arg...);
- return fCls;
- }
-
- void Delete() {
- if (fCls) delete fCls;
-
- fCls = nullptr;
- }
-
- T *operator->() const { return fCls; };
- T *Raw() { return fCls; }
-
- Ref<T> AsRef() { return Ref<T>(fCls); }
-
- operator bool() { return fCls; }
- bool operator!() { return !fCls; }
-
- private:
- T *fCls;
-};
-
-template <typename T, typename... Args>
-OwnPtr<T> make_ptr(Args... args) {
- OwnPtr<T> ret;
- ret.template New<Args...>(forward(args)...);
- MUST_PASS(ret);
-
- return ret;
-}
-} // namespace NewOS
+namespace NewOS
+{
+ template <typename T>
+ class OwnPtr;
+
+ template <typename T>
+ class NonNullRefPtr;
+
+ template <typename T>
+ class OwnPtr final
+ {
+ public:
+ OwnPtr()
+ {
+ }
+ ~OwnPtr()
+ {
+ this->Delete();
+ }
+
+ OwnPtr& operator=(const OwnPtr&) = default;
+ OwnPtr(const OwnPtr&) = default;
+
+ public:
+ template <typename... Args>
+ bool New(Args&&... arg)
+ {
+ if (fCls)
+ {
+ return false;
+ }
+
+ fCls = new T(arg...);
+ return fCls;
+ }
+
+ void Delete()
+ {
+ if (fCls)
+ delete fCls;
+
+ fCls = nullptr;
+ }
+
+ T* operator->() const
+ {
+ return fCls;
+ };
+ T* Raw()
+ {
+ return fCls;
+ }
+
+ Ref<T> AsRef()
+ {
+ return Ref<T>(fCls);
+ }
+
+ operator bool()
+ {
+ return fCls;
+ }
+ bool operator!()
+ {
+ return !fCls;
+ }
+
+ private:
+ T* fCls;
+ };
+
+ template <typename T, typename... Args>
+ OwnPtr<T> make_ptr(Args... args)
+ {
+ OwnPtr<T> ret;
+ ret.template New<Args...>(forward(args)...);
+ MUST_PASS(ret);
+
+ return ret;
+ }
+} // namespace NewOS
diff --git a/Private/NewKit/PageAllocator.hpp b/Private/NewKit/PageAllocator.hpp
index 0d8377b0..0ed543f3 100644
--- a/Private/NewKit/PageAllocator.hpp
+++ b/Private/NewKit/PageAllocator.hpp
@@ -10,10 +10,12 @@
#include <NewKit/Defines.hpp>
#include <NewKit/PageManager.hpp>
-namespace NewOS {
-namespace Detail {
-VoidPtr create_page_wrapper(Boolean rw, Boolean user, SizeT pageSz);
-void exec_disable(UIntPtr addr);
-bool page_disable(UIntPtr addr);
-} // namespace Detail
-} // namespace NewOS
+namespace NewOS
+{
+ namespace Detail
+ {
+ VoidPtr create_page_wrapper(Boolean rw, Boolean user, SizeT pageSz);
+ void exec_disable(UIntPtr addr);
+ bool page_disable(UIntPtr addr);
+ } // namespace Detail
+} // namespace NewOS
diff --git a/Private/NewKit/PageManager.hpp b/Private/NewKit/PageManager.hpp
index 05965306..0203a600 100644
--- a/Private/NewKit/PageManager.hpp
+++ b/Private/NewKit/PageManager.hpp
@@ -15,65 +15,67 @@
#ifndef kBadAddress
#define kBadAddress (0)
-#endif // #ifndef kBadAddress
-
-namespace NewOS {
-class PageManager;
-
-class PTEWrapper final {
- public:
- explicit PTEWrapper(Boolean Rw = false, Boolean User = false,
- Boolean ExecDisable = false, UIntPtr Address = 0);
-
- ~PTEWrapper();
-
- PTEWrapper &operator=(const PTEWrapper &) = default;
- PTEWrapper(const PTEWrapper &) = default;
-
- public:
- const UIntPtr VirtualAddress();
-
- void NoExecute(const bool enable = false);
- const bool &NoExecute();
-
- bool Reclaim();
- bool Shareable();
- bool Present();
- bool Access();
-
- private:
- Boolean fRw;
- Boolean fUser;
- Boolean fExecDisable;
- UIntPtr fVirtAddr;
- Boolean fCache;
- Boolean fShareable;
- Boolean fWt;
- Boolean fPresent;
- Boolean fAccessed;
-
- private:
- friend class PageManager;
- friend class Pmm;
-};
-
-struct PageManager final {
- public:
- PageManager() = default;
- ~PageManager() = default;
-
- PageManager &operator=(const PageManager &) = default;
- PageManager(const PageManager &) = default;
-
- public:
- PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz);
- bool Free(Ref<PTEWrapper *> &wrapper);
-
- private:
- void FlushTLB(UIntPtr VirtAddr);
-
- private:
- friend PTEWrapper;
- friend class Pmm;
-};
-} // namespace NewOS
+#endif // #ifndef kBadAddress
+
+namespace NewOS
+{
+ class PageManager;
+
+ class PTEWrapper final
+ {
+ public:
+ explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0);
+
+ ~PTEWrapper();
+
+ PTEWrapper& operator=(const PTEWrapper&) = default;
+ PTEWrapper(const PTEWrapper&) = default;
+
+ public:
+ const UIntPtr VirtualAddress();
+
+ void NoExecute(const bool enable = false);
+ const bool& NoExecute();
+
+ bool Reclaim();
+ bool Shareable();
+ bool Present();
+ bool Access();
+
+ private:
+ Boolean fRw;
+ Boolean fUser;
+ Boolean fExecDisable;
+ UIntPtr fVirtAddr;
+ Boolean fCache;
+ Boolean fShareable;
+ Boolean fWt;
+ Boolean fPresent;
+ Boolean fAccessed;
+
+ private:
+ friend class PageManager;
+ friend class Pmm;
+ };
+
+ struct PageManager final
+ {
+ public:
+ PageManager() = default;
+ ~PageManager() = default;
+
+ PageManager& operator=(const PageManager&) = default;
+ PageManager(const PageManager&) = default;
+
+ public:
+ PTEWrapper Request(Boolean Rw, Boolean User, Boolean ExecDisable, SizeT Sz);
+ bool Free(Ref<PTEWrapper*>& wrapper);
+
+ private:
+ void FlushTLB(UIntPtr VirtAddr);
+
+ private:
+ friend PTEWrapper;
+ friend class Pmm;
+ };
+} // namespace NewOS
diff --git a/Private/NewKit/Pair.hpp b/Private/NewKit/Pair.hpp
index 1522caf3..659a7ed9 100644
--- a/Private/NewKit/Pair.hpp
+++ b/Private/NewKit/Pair.hpp
@@ -10,5 +10,5 @@
namespace NewOS
{
-
+
} // namespace NewOS
diff --git a/Private/NewKit/Pmm.hpp b/Private/NewKit/Pmm.hpp
index 2ed8b753..07c5e399 100644
--- a/Private/NewKit/Pmm.hpp
+++ b/Private/NewKit/Pmm.hpp
@@ -10,30 +10,35 @@
#include <NewKit/PageManager.hpp>
#include <NewKit/Ref.hpp>
-namespace NewOS {
-class Pmm;
-class PTEWrapper;
-
-class Pmm final {
- public:
- explicit Pmm();
- ~Pmm();
-
- Pmm &operator=(const Pmm &) = delete;
- Pmm(const Pmm &) = default;
-
- Ref<PTEWrapper> RequestPage(Boolean user = false, Boolean readWrite = false);
- Boolean FreePage(Ref<PTEWrapper> refPage);
-
- Boolean ToggleRw(Ref<PTEWrapper> refPage, Boolean enable = true);
- Boolean TogglePresent(Ref<PTEWrapper> refPage, Boolean enable = true);
- Boolean ToggleUser(Ref<PTEWrapper> refPage, Boolean enable = true);
- Boolean ToggleShare(Ref<PTEWrapper> refPage, Boolean enable = true);
-
- /// @brief Get the page manager of this.
- Ref<PageManager> &Leak() { return fPageManager; }
-
- private:
- Ref<PageManager> fPageManager;
-};
-} // namespace NewOS
+namespace NewOS
+{
+ class Pmm;
+ class PTEWrapper;
+
+ class Pmm final
+ {
+ public:
+ explicit Pmm();
+ ~Pmm();
+
+ Pmm& operator=(const Pmm&) = delete;
+ Pmm(const Pmm&) = default;
+
+ Ref<PTEWrapper> RequestPage(Boolean user = false, Boolean readWrite = false);
+ Boolean FreePage(Ref<PTEWrapper> refPage);
+
+ Boolean ToggleRw(Ref<PTEWrapper> refPage, Boolean enable = true);
+ Boolean TogglePresent(Ref<PTEWrapper> refPage, Boolean enable = true);
+ Boolean ToggleUser(Ref<PTEWrapper> refPage, Boolean enable = true);
+ Boolean ToggleShare(Ref<PTEWrapper> refPage, Boolean enable = true);
+
+ /// @brief Get the page manager of this.
+ Ref<PageManager>& Leak()
+ {
+ return fPageManager;
+ }
+
+ private:
+ Ref<PageManager> fPageManager;
+ };
+} // namespace NewOS
diff --git a/Private/NewKit/Ref.hpp b/Private/NewKit/Ref.hpp
index 30e65e2f..b062cf09 100644
--- a/Private/NewKit/Ref.hpp
+++ b/Private/NewKit/Ref.hpp
@@ -10,54 +10,80 @@
#include <NewKit/Defines.hpp>
#include <NewKit/KernelCheck.hpp>
-namespace NewOS {
-template <typename T>
-class Ref final {
- public:
- Ref() = default;
- ~Ref() = default;
-
- public:
- Ref(T cls, const bool &strong = false) : fClass(cls), fStrong(strong) {}
-
- Ref &operator=(T ref) {
- fClass = ref;
- return *this;
- }
-
- public:
- T operator->() const { return fClass; }
-
- T &Leak() { return fClass; }
-
- T operator*() { return fClass; }
-
- bool IsStrong() const { return fStrong; }
-
- operator bool() { return fStrong; }
-
- private:
- T fClass;
- bool fStrong{false};
-};
-
-template <typename T>
-class NonNullRef final {
- public:
- NonNullRef() = delete;
- NonNullRef(nullPtr) = delete;
-
- NonNullRef(T *ref) : fRef(ref, true) {}
-
- Ref<T> &operator->() {
- MUST_PASS(fRef);
- return fRef;
- }
-
- NonNullRef &operator=(const NonNullRef<T> &ref) = delete;
- NonNullRef(const NonNullRef<T> &ref) = default;
-
- private:
- Ref<T> fRef{nullptr};
-};
-} // namespace NewOS
+namespace NewOS
+{
+ template <typename T>
+ class Ref final
+ {
+ public:
+ Ref() = default;
+ ~Ref() = default;
+
+ public:
+ Ref(T cls, const bool& strong = false)
+ : fClass(cls), fStrong(strong)
+ {
+ }
+
+ Ref& operator=(T ref)
+ {
+ fClass = ref;
+ return *this;
+ }
+
+ public:
+ T operator->() const
+ {
+ return fClass;
+ }
+
+ T& Leak()
+ {
+ return fClass;
+ }
+
+ T operator*()
+ {
+ return fClass;
+ }
+
+ bool IsStrong() const
+ {
+ return fStrong;
+ }
+
+ operator bool()
+ {
+ return fStrong;
+ }
+
+ private:
+ T fClass;
+ bool fStrong{false};
+ };
+
+ template <typename T>
+ class NonNullRef final
+ {
+ public:
+ NonNullRef() = delete;
+ NonNullRef(nullPtr) = delete;
+
+ NonNullRef(T* ref)
+ : fRef(ref, true)
+ {
+ }
+
+ Ref<T>& operator->()
+ {
+ MUST_PASS(fRef);
+ return fRef;
+ }
+
+ NonNullRef& operator=(const NonNullRef<T>& ref) = delete;
+ NonNullRef(const NonNullRef<T>& ref) = default;
+
+ private:
+ Ref<T> fRef{nullptr};
+ };
+} // namespace NewOS
diff --git a/Private/NewKit/Stream.hpp b/Private/NewKit/Stream.hpp
index 67288191..9f737b2d 100644
--- a/Private/NewKit/Stream.hpp
+++ b/Private/NewKit/Stream.hpp
@@ -12,47 +12,47 @@
namespace NewOS
{
- template <typename StreamTrait, typename Kind>
- class Stream final
- {
- public:
- explicit Stream(Ref<Stream> ref)
- : fStream(ref)
- {}
-
- ~Stream() = default;
-
- Stream &operator=(const Stream &) = default;
- Stream(const Stream &) = default;
-
- template <typename Data>
- friend Stream<StreamTrait, Kind> &operator>>(Stream<StreamTrait, Kind> &Ks, Ref<Data>& Buf)
- {
- Ks.fKind = Ks.fStream->In(Buf);
- return *Ks;
- }
-
- template <typename Data>
- friend Stream<StreamTrait, Kind> &operator<<(Stream<StreamTrait, Kind> &Ks, Ref<Data>& Buf)
- {
- Ks.fKind = Buf;
- Ks.fStream->Out(Buf.Leak());
- return *Ks;
- }
-
- Ref<StreamTrait> &AsStreamTrait()
- {
- return fStream;
- }
-
- Ref<Kind>& AsType()
- {
- return fKind;
- }
-
- private:
- Ref<StreamTrait> fStream;
- Ref<Kind> fKind;
-
- };
+ template <typename StreamTrait, typename Kind>
+ class Stream final
+ {
+ public:
+ explicit Stream(Ref<Stream> ref)
+ : fStream(ref)
+ {
+ }
+
+ ~Stream() = default;
+
+ Stream& operator=(const Stream&) = default;
+ Stream(const Stream&) = default;
+
+ template <typename Data>
+ friend Stream<StreamTrait, Kind>& operator>>(Stream<StreamTrait, Kind>& Ks, Ref<Data>& Buf)
+ {
+ Ks.fKind = Ks.fStream->In(Buf);
+ return *Ks;
+ }
+
+ template <typename Data>
+ friend Stream<StreamTrait, Kind>& operator<<(Stream<StreamTrait, Kind>& Ks, Ref<Data>& Buf)
+ {
+ Ks.fKind = Buf;
+ Ks.fStream->Out(Buf.Leak());
+ return *Ks;
+ }
+
+ Ref<StreamTrait>& AsStreamTrait()
+ {
+ return fStream;
+ }
+
+ Ref<Kind>& AsType()
+ {
+ return fKind;
+ }
+
+ private:
+ Ref<StreamTrait> fStream;
+ Ref<Kind> fKind;
+ };
} // namespace NewOS
diff --git a/Private/NewKit/String.hpp b/Private/NewKit/String.hpp
index 93dfc584..7346c5e9 100644
--- a/Private/NewKit/String.hpp
+++ b/Private/NewKit/String.hpp
@@ -10,54 +10,67 @@
#include <NewKit/ErrorOr.hpp>
#include <NewKit/KernelCheck.hpp>
-namespace NewOS {
-class StringView final {
- public:
- explicit StringView() = default;
-
- explicit StringView(Size Sz) : fSz(Sz) {
- MUST_PASS(Sz > 1);
- fData = new Char[Sz];
- MUST_PASS(fData);
- }
-
- ~StringView() {
- if (fData) delete[] fData;
- }
-
- StringView &operator=(const StringView &) = default;
- StringView(const StringView &) = default;
-
- Char *Data();
- const Char *CData();
- Size Length() const;
-
- bool operator==(const Char *rhs) const;
- bool operator!=(const Char *rhs) const;
-
- bool operator==(const StringView &rhs) const;
- bool operator!=(const StringView &rhs) const;
-
- StringView &operator+=(const Char *rhs);
- StringView &operator+=(const StringView &rhs);
-
- operator bool() { return fData; }
-
- bool operator!() { return fData; }
-
- private:
- Char *fData{nullptr};
- Size fSz{0};
- Size fCur{0};
-
- friend class StringBuilder;
-};
-
-struct StringBuilder final {
- static ErrorOr<StringView> Construct(const Char *data);
- static const char *FromInt(const char *fmt, int n);
- static const char *FromBool(const char *fmt, bool n);
- static const char *Format(const char *fmt, const char *from);
- static bool Equals(const char *lhs, const char *rhs);
-};
-} // namespace NewOS
+namespace NewOS
+{
+ class StringView final
+ {
+ public:
+ explicit StringView() = default;
+
+ explicit StringView(Size Sz)
+ : fSz(Sz)
+ {
+ MUST_PASS(Sz > 1);
+ fData = new Char[Sz];
+ MUST_PASS(fData);
+ }
+
+ ~StringView()
+ {
+ if (fData)
+ delete[] fData;
+ }
+
+ StringView& operator=(const StringView&) = default;
+ StringView(const StringView&) = default;
+
+ Char* Data();
+ const Char* CData();
+ Size Length() const;
+
+ bool operator==(const Char* rhs) const;
+ bool operator!=(const Char* rhs) const;
+
+ bool operator==(const StringView& rhs) const;
+ bool operator!=(const StringView& rhs) const;
+
+ StringView& operator+=(const Char* rhs);
+ StringView& operator+=(const StringView& rhs);
+
+ operator bool()
+ {
+ return fData;
+ }
+
+ bool operator!()
+ {
+ return fData;
+ }
+
+ private:
+ Char* fData{nullptr};
+ Size fSz{0};
+ Size fCur{0};
+
+ friend class StringBuilder;
+ };
+
+ struct StringBuilder final
+ {
+ static ErrorOr<StringView> Construct(const Char* data);
+ static const char* FromInt(const char* fmt, int n);
+ static const char* FromBool(const char* fmt, bool n);
+ static const char* Format(const char* fmt, const char* from);
+ static bool Equals(const char* lhs, const char* rhs);
+ };
+} // namespace NewOS
diff --git a/Private/NewKit/Utils.hpp b/Private/NewKit/Utils.hpp
index c9503479..c18a606f 100644
--- a/Private/NewKit/Utils.hpp
+++ b/Private/NewKit/Utils.hpp
@@ -9,20 +9,21 @@
#include <NewKit/Defines.hpp>
-namespace NewOS {
-Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len);
-Int rt_move_memory(const voidPtr src, voidPtr dst, Size len);
-voidPtr rt_set_memory(voidPtr dst, Char val, Size len);
-void rt_zero_memory(voidPtr pointer, Size len);
-Int rt_string_cmp(const Char *src, const Char *cmp, Size len);
-const Char *alloc_string(const Char *text);
-Size rt_string_len(const Char *str);
-Size rt_string_len(const Char *str, SizeT _len);
-Boolean rt_to_string(Char *buf, Int limit, Int base);
-Boolean is_newln(Char chr);
-Boolean is_space(Char chr);
-Int rt_to_uppercase(Int c);
-Int rt_to_lower(Int c);
-voidPtr rt_string_in_string(const char *in, const char *needle);
-char *rt_string_has_char(char *str, const char chr);
-} // namespace NewOS
+namespace NewOS
+{
+ Int rt_copy_memory(const voidPtr src, voidPtr dst, Size len);
+ Int rt_move_memory(const voidPtr src, voidPtr dst, Size len);
+ voidPtr rt_set_memory(voidPtr dst, Char val, Size len);
+ void rt_zero_memory(voidPtr pointer, Size len);
+ Int rt_string_cmp(const Char* src, const Char* cmp, Size len);
+ const Char* alloc_string(const Char* text);
+ Size rt_string_len(const Char* str);
+ Size rt_string_len(const Char* str, SizeT _len);
+ Boolean rt_to_string(Char* buf, Int limit, Int base);
+ Boolean is_newln(Char chr);
+ Boolean is_space(Char chr);
+ Int rt_to_uppercase(Int c);
+ Int rt_to_lower(Int c);
+ voidPtr rt_string_in_string(const char* in, const char* needle);
+ char* rt_string_has_char(char* str, const char chr);
+} // namespace NewOS
diff --git a/Private/NewKit/Variant.hpp b/Private/NewKit/Variant.hpp
index c0738de2..f26a2406 100644
--- a/Private/NewKit/Variant.hpp
+++ b/Private/NewKit/Variant.hpp
@@ -9,31 +9,46 @@
#include <NewKit/Defines.hpp>
#include <NewKit/String.hpp>
-namespace NewOS {
-class Variant final {
- public:
- enum class VariantKind { kString, kPointer, kUndefined };
-
- public:
- explicit Variant() = delete;
-
- public:
- Variant &operator=(const Variant &) = default;
- Variant(const Variant &) = default;
-
- ~Variant() = default;
-
- public:
- explicit Variant(StringView *stringView)
- : fPtr((voidPtr)stringView), fKind(VariantKind::kString) {}
- explicit Variant(nullPtr) : fPtr(nullptr), fKind(VariantKind::kUndefined) {}
- explicit Variant(voidPtr ptr) : fPtr(ptr), fKind(VariantKind::kPointer) {}
-
- public:
- const Char *ToString();
-
- private:
- voidPtr fPtr{nullptr};
- VariantKind fKind{VariantKind::kUndefined};
-};
-} // namespace NewOS
+namespace NewOS
+{
+ class Variant final
+ {
+ public:
+ enum class VariantKind
+ {
+ kString,
+ kPointer,
+ kUndefined
+ };
+
+ public:
+ explicit Variant() = delete;
+
+ public:
+ Variant& operator=(const Variant&) = default;
+ Variant(const Variant&) = default;
+
+ ~Variant() = default;
+
+ public:
+ explicit Variant(StringView* stringView)
+ : fPtr((voidPtr)stringView), fKind(VariantKind::kString)
+ {
+ }
+ explicit Variant(nullPtr)
+ : fPtr(nullptr), fKind(VariantKind::kUndefined)
+ {
+ }
+ explicit Variant(voidPtr ptr)
+ : fPtr(ptr), fKind(VariantKind::kPointer)
+ {
+ }
+
+ public:
+ const Char* ToString();
+
+ private:
+ voidPtr fPtr{nullptr};
+ VariantKind fKind{VariantKind::kUndefined};
+ };
+} // namespace NewOS