diff options
| author | Amlal <amlalelmahrouss@icloud.com> | 2024-05-11 06:43:54 +0000 |
|---|---|---|
| committer | Amlal <amlalelmahrouss@icloud.com> | 2024-05-11 06:43:54 +0000 |
| commit | ca675beb41dba8d7d16c5793b55d1672f38be3b4 (patch) | |
| tree | c995ada42729ac2059a0ed87a4539d1a7e10b14a /Private/NewKit | |
| parent | 2b4a4792abf51487ab4a16106f9376f43acf381a (diff) | |
| parent | bc57a29a24b98b00ba17710ba84ec2188ab73504 (diff) | |
Merged in MHR-23 (pull request #12)
MHR-23: Merge work.
Diffstat (limited to 'Private/NewKit')
27 files changed, 0 insertions, 1499 deletions
diff --git a/Private/NewKit/Application.hxx b/Private/NewKit/Application.hxx deleted file mode 100644 index 15ffd073..00000000 --- a/Private/NewKit/Application.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -/// -/// @brief Application object, given by the OS to the process. interact with the OS. -/// @file Application.hxx -/// @author Amlal EL Mahrouss -/// - -#include <NewKit/Defines.hpp> -#include <CFKit/GUIDWrapper.hpp> - -/// \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); -} Application, *ApplicationRef; - -#define app_cast reinterpret_cast<ApplicationRef> diff --git a/Private/NewKit/Array.hpp b/Private/NewKit/Array.hpp deleted file mode 100644 index 68ca9bfc..00000000 --- a/Private/NewKit/Array.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ -#pragma once - -#include <KernelKit/DebugOutput.hpp> -#include <NewKit/ErrorOr.hpp> -#include <NewKit/Defines.hpp> - -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; - - ErrorOr<T> operator[](Size At) - { - if (At > N) - return {}; - - kcout << "Returning element\r"; - return ErrorOr<T>(fArray[At]); - } - - Boolean Empty() const - { - for (auto Val : fArray) - { - if (Val) - return false; - } - - return true; - } - - SizeT Count() const - { - SizeT cntElems = 0UL; - for (auto Val : fArray) - { - if (Val) - ++cntElems; - } - - return cntElems; - } - - const T *CData() - { - return fArray; - } - - operator bool() - { - return !Empty(); - } - -private: - T fArray[N]; - -}; -} // namespace NewOS diff --git a/Private/NewKit/ArrayList.hpp b/Private/NewKit/ArrayList.hpp deleted file mode 100644 index b7ab50cf..00000000 --- a/Private/NewKit/ArrayList.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> - -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}; - } -} // namespace NewOS diff --git a/Private/NewKit/Atom.hpp b/Private/NewKit/Atom.hpp deleted file mode 100644 index 648302fc..00000000 --- a/Private/NewKit/Atom.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ -#pragma once - -#include <NewKit/Defines.hpp> - -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; -}; -} // namespace NewOS diff --git a/Private/NewKit/Crc32.hpp b/Private/NewKit/Crc32.hpp deleted file mode 100644 index 0dccd4d8..00000000 --- a/Private/NewKit/Crc32.hpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * ======================================================== - * - * NewOS Date Added: 13/02/2023 - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#ifndef __CRC32_H__ -#define __CRC32_H__ - -#include <NewKit/Defines.hpp> - -#define kCrcCnt (256) - -namespace NewOS { -UInt ke_calculate_crc32(const Char* crc, UInt len) noexcept; -} // namespace NewOS - -#endif // !__CRC32_H__ diff --git a/Private/NewKit/CxxAbi.hpp b/Private/NewKit/CxxAbi.hpp deleted file mode 100644 index d210bf18..00000000 --- a/Private/NewKit/CxxAbi.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ -#pragma once - -#include <NewKit/Defines.hpp> - -#ifdef __GNUC__ - -#define kDSOMaxObjects (128) - -struct atexit_func_entry_t -{ - void (*destructor_func)(void *); - void *obj_ptr; - void *dso_handle; -}; - -typedef unsigned uarch_t; - -namespace cxxabiv1 -{ - typedef void *__guard; -} - -#endif // __GNUC__
\ No newline at end of file diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp deleted file mode 100644 index bed02081..00000000 --- a/Private/NewKit/Defines.hpp +++ /dev/null @@ -1,138 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Macros.hpp> - -#define NEWKIT_VERSION "1.01" - -#if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__) -#include <CRT/__mpcc_defines.hxx> -#endif - -#ifdef __has_feature -#if !__has_feature(cxx_nullptr) -#if !__has_nullptr -#error You must at least have nullptr featured on your C++ compiler. -#endif -#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)) - -#define Yes (true) -#define No (false) - -#define VoidStar NewOS::voidPtr - -#ifdef INIT -#undef 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 deleted file mode 100644 index b2cc65d1..00000000 --- a/Private/NewKit/ErrorID.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -/// @brief Internal kernel errors. - -#include <NewKit/ErrorOr.hpp> -#include <NewKit/Defines.hpp> - -#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 diff --git a/Private/NewKit/ErrorOr.hpp b/Private/NewKit/ErrorOr.hpp deleted file mode 100644 index 6d85a943..00000000 --- a/Private/NewKit/ErrorOr.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* ======================================================== -* -* NewOS -* Copyright Mahrouss Logic, all rights reserved. -* -* ======================================================== -*/ - -#pragma once - -#include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> - -namespace NewOS -{ -using ErrorT = UInt; - -template <typename T> class ErrorOr final -{ - public: - ErrorOr() = default; - ~ErrorOr() = default; - - public: - explicit ErrorOr(Int32 err) - : mId(err) - {} - - explicit ErrorOr(nullPtr Null) - {} - - explicit ErrorOr(T Class) - : mRef(Class) - {} - - ErrorOr &operator=(const ErrorOr &) = default; - ErrorOr(const ErrorOr &) = default; - - ErrorOr &operator=(const Ref<T> &refErr) - { - mRef = refErr; - return *this; - } - - Ref<T> Leak() - { - return mRef; - } - - Int32 Error() - { - return mId; - } - - operator bool() - { - return mRef; - } - - private: - Ref<T> mRef; - Int32 mId{0}; -}; - -using ErrorOrAny = ErrorOr<voidPtr>; - -} // namespace NewOS diff --git a/Private/NewKit/Function.hpp b/Private/NewKit/Function.hpp deleted file mode 100644 index 79d33a3b..00000000 --- a/Private/NewKit/Function.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _INC_FUNCTION_HPP__ -#define _INC_FUNCTION_HPP__ - -#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__ diff --git a/Private/NewKit/Json.hpp b/Private/NewKit/Json.hpp deleted file mode 100644 index d4514ef1..00000000 --- a/Private/NewKit/Json.hpp +++ /dev/null @@ -1,92 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -// last-rev: 30/01/24 - -#include <CompilerKit/CompilerKit.hxx> -#include <NewKit/Defines.hpp> -#include <NewKit/Stream.hpp> -#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 diff --git a/Private/NewKit/KernelCheck.hpp b/Private/NewKit/KernelCheck.hpp deleted file mode 100644 index c65390ad..00000000 --- a/Private/NewKit/KernelCheck.hpp +++ /dev/null @@ -1,57 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> - -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)) -#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, -}; - -namespace NewOS { -class DumpManager final { - public: - static void Dump(void) { - // TODO: - } -}; - -void ke_stop(const Int &id); -} // namespace NewOS - -#ifdef TRY -#undef TRY -#endif - -#define TRY(FN) \ - if (!FN()) { \ - MUST_PASS(false); \ - } diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp deleted file mode 100644 index f2094c87..00000000 --- a/Private/NewKit/Macros.hpp +++ /dev/null @@ -1,98 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#ifndef KIB -#define KIB(X) ((X) << 10) -#endif - -#ifndef MIB -#define MIB(X) ((UInt64)KIB(X) << 20) -#endif - -#ifndef GIB -#define GIB(X) ((UInt64)MIB(X) << 30) -#endif - -#ifndef TIB -#define TIB(X) ((UInt64)GIB(X) << 40) -#endif - -#ifndef ARRAY_SIZE -#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 - -#ifndef ATTRIBUTE -#define ATTRIBUTE(X) __attribute__((X)) -#endif // #ifndef ATTRIBUTE - -#ifndef __MAHROUSS__ -#define __MAHROUSS__ (202401) -#endif // !__MAHROUSS__ - -#ifndef EXTERN_C -#define EXTERN_C extern "C" -#endif - -#ifndef MAKE_ENUM -#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 { -#endif - -#ifndef ENUM_STRING -#define ENUM_STRING(NAME, VAL) inline constexpr const char *NAME = VAL -#endif - -#ifndef END_STRING_ENUM -#define END_STRING_ENUM() } -#endif - -#ifndef Alloca -#define Alloca(Sz) __builtin_alloca(Sz) -#endif // #ifndef Alloca - -#ifndef CANT_REACH -#define CANT_REACH() __builtin_unreachable() -#endif - -#define kBadPtr 0xFBFBFBFBFBFBFBFB -#define kMaxAddr 0xFFFFFFFFFFFFFFFF -#define kPathLen 255 - -#define PACKED ATTRIBUTE(packed) -#define NO_EXEC ATTRIBUTE(noexec) - -#define EXTERN extern -#define STATIC static - -#define CONST const - -#ifndef self -#define self this -#endif - -#define STRINGIFY(X) #X -#define NEWOS_UNUSED(X) ((void)X) - -#ifndef RGB -#define RGB(R, G, B) (UInt32)(0x##R##G##B) -#endif // !RGB diff --git a/Private/NewKit/MutableArray.hpp b/Private/NewKit/MutableArray.hpp deleted file mode 100644 index b46f1bc7..00000000 --- a/Private/NewKit/MutableArray.hpp +++ /dev/null @@ -1,222 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ -#pragma once - -#include <CompilerKit/CompilerKit.hxx> -#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; \ - } - - - -// 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>()) {} - - /* - * 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; - - iterationNode->fUsed = true; - - ++fNodeCount; - - 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 {}; - } - - 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; - } - - 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}; -}; -} // namespace NewOS diff --git a/Private/NewKit/New.hpp b/Private/NewKit/New.hpp deleted file mode 100644 index c828b979..00000000 --- a/Private/NewKit/New.hpp +++ /dev/null @@ -1,18 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ -#pragma once - -#include <KernelKit/KernelHeap.hpp> - -typedef __SIZE_TYPE__ size_t; // gcc will complain about that - -void* operator new(size_t ptr); -void* operator new[](size_t ptr); - -void operator delete(void* ptr); -void operator delete(void* ptr, unsigned long); -void operator delete[](void* ptr); diff --git a/Private/NewKit/NewKit.hpp b/Private/NewKit/NewKit.hpp deleted file mode 100644 index 79993091..00000000 --- a/Private/NewKit/NewKit.hpp +++ /dev/null @@ -1,22 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Array.hpp> -#include <NewKit/ArrayList.hpp> -#include <NewKit/ErrorOr.hpp> -#include <NewKit/Json.hpp> -#include <NewKit/KernelCheck.hpp> -#include <KernelKit/LockDelegate.hpp> -#include <NewKit/MutableArray.hpp> -#include <NewKit/New.hpp> -#include <NewKit/OwnPtr.hpp> -#include <NewKit/Ref.hpp> -#include <NewKit/Stream.hpp> -#include <KernelKit/UserHeap.hpp> -#include <NewKit/Utils.hpp> diff --git a/Private/NewKit/OwnPtr.hpp b/Private/NewKit/OwnPtr.hpp deleted file mode 100644 index ff2b59e1..00000000 --- a/Private/NewKit/OwnPtr.hpp +++ /dev/null @@ -1,67 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> -#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 diff --git a/Private/NewKit/PageAllocator.hpp b/Private/NewKit/PageAllocator.hpp deleted file mode 100644 index 0d8377b0..00000000 --- a/Private/NewKit/PageAllocator.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <HALKit/AMD64/HalPageAlloc.hpp> -#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 diff --git a/Private/NewKit/PageManager.hpp b/Private/NewKit/PageManager.hpp deleted file mode 100644 index 05965306..00000000 --- a/Private/NewKit/PageManager.hpp +++ /dev/null @@ -1,79 +0,0 @@ -// a way to create and find our pages. -// I'm thinking about a separate way of getting a paged area. - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> -#include <NewKit/PageAllocator.hpp> -#include <NewKit/Ref.hpp> - -#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 diff --git a/Private/NewKit/Pair.hpp b/Private/NewKit/Pair.hpp deleted file mode 100644 index 1522caf3..00000000 --- a/Private/NewKit/Pair.hpp +++ /dev/null @@ -1,14 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> - -namespace NewOS -{ - -} // namespace NewOS diff --git a/Private/NewKit/Pmm.hpp b/Private/NewKit/Pmm.hpp deleted file mode 100644 index 2ed8b753..00000000 --- a/Private/NewKit/Pmm.hpp +++ /dev/null @@ -1,39 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#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 diff --git a/Private/NewKit/Ref.hpp b/Private/NewKit/Ref.hpp deleted file mode 100644 index 30e65e2f..00000000 --- a/Private/NewKit/Ref.hpp +++ /dev/null @@ -1,63 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#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 diff --git a/Private/NewKit/Stream.hpp b/Private/NewKit/Stream.hpp deleted file mode 100644 index 67288191..00000000 --- a/Private/NewKit/Stream.hpp +++ /dev/null @@ -1,58 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> -#include <NewKit/Ref.hpp> - -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; - - }; -} // namespace NewOS diff --git a/Private/NewKit/String.hpp b/Private/NewKit/String.hpp deleted file mode 100644 index 93dfc584..00000000 --- a/Private/NewKit/String.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#include <NewKit/Defines.hpp> -#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 diff --git a/Private/NewKit/Utils.hpp b/Private/NewKit/Utils.hpp deleted file mode 100644 index c9503479..00000000 --- a/Private/NewKit/Utils.hpp +++ /dev/null @@ -1,28 +0,0 @@ - -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#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 diff --git a/Private/NewKit/Variant.hpp b/Private/NewKit/Variant.hpp deleted file mode 100644 index c0738de2..00000000 --- a/Private/NewKit/Variant.hpp +++ /dev/null @@ -1,39 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#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 diff --git a/Private/NewKit/compile_flags.txt b/Private/NewKit/compile_flags.txt deleted file mode 100644 index 14c5bc51..00000000 --- a/Private/NewKit/compile_flags.txt +++ /dev/null @@ -1,6 +0,0 @@ --nostdlib --ffreestanding --std=c++20 --I./ --I../ --I../../../ |
