diff options
Diffstat (limited to 'Kernel')
| -rw-r--r-- | Kernel/HALKit/AMD64/HalBoot.asm | 20 | ||||
| -rw-r--r-- | Kernel/HALKit/AMD64/HalKernelMain.cxx | 24 | ||||
| -rw-r--r-- | Kernel/HALKit/ARM64/HalKernelMain.cxx | 11 | ||||
| -rw-r--r-- | Kernel/KernelKit/PE.hxx | 5 | ||||
| -rw-r--r-- | Kernel/KernelKit/ProcessHeap.hxx | 1 | ||||
| -rw-r--r-- | Kernel/KernelKit/ThreadLocalStorage.hxx | 24 | ||||
| -rw-r--r-- | Kernel/Sources/ProcessHeap.cxx | 26 | ||||
| -rw-r--r-- | Kernel/Sources/ThreadLocalStorage.cxx | 23 | ||||
| -rw-r--r-- | Kernel/Sources/User.cxx | 17 | ||||
| -rw-r--r-- | Kernel/Sources/Utils.cxx | 4 | ||||
| -rw-r--r-- | Kernel/amd64-efi.make | 5 |
11 files changed, 93 insertions, 67 deletions
diff --git a/Kernel/HALKit/AMD64/HalBoot.asm b/Kernel/HALKit/AMD64/HalBoot.asm index ad1c1987..8cb55a20 100644 --- a/Kernel/HALKit/AMD64/HalBoot.asm +++ b/Kernel/HALKit/AMD64/HalBoot.asm @@ -10,8 +10,7 @@ [bits 64] ;; Global symbol of this unit -[global MainLong] -[global MainUnsupported] +[extern hal_init_platform] %define kTypeKernel 100 %define kArchAmd64 122 @@ -23,19 +22,4 @@ HandoverMagic: dq kHandoverMagic HandoverType: dw kTypeKernel HandoverArch: dw kArchAmd64 ;; This NewBootStart points to Main. -HandoverStart: dq __ImageStart - -section .text - -global __ImageStart -global __NewBootJumpProc - -extern hal_init_platform - -;; Just a simple setup, we'd also need to tell some before -__NewBootJumpProc: -__ImageStart: - push rcx - call hal_init_platform - pop rcx - ret +HandoverStart: dq hal_init_platform diff --git a/Kernel/HALKit/AMD64/HalKernelMain.cxx b/Kernel/HALKit/AMD64/HalKernelMain.cxx index d21d2f9c..6e923555 100644 --- a/Kernel/HALKit/AMD64/HalKernelMain.cxx +++ b/Kernel/HALKit/AMD64/HalKernelMain.cxx @@ -32,19 +32,19 @@ EXTERN_C void KeMain(); EXTERN_C Kernel::VoidPtr kInterruptVectorTable[]; -struct PACKED HEAP_ALLOC_INFO final +struct HEAP_ALLOC_INFO final { Kernel::VoidPtr fThe; Kernel::Size fTheSz; }; -struct PACKED PROCESS_BLOCK_INFO final +struct PROCESS_BLOCK_INFO final { - ThreadInformationBlock* fTIB; - ThreadInformationBlock* fPIB; + THREAD_INFORMATION_BLOCK* fTIB; + THREAD_INFORMATION_BLOCK* fGIB; }; -struct PACKED PROCESS_EXIT_INFO final +struct PROCESS_EXIT_INFO final { STATIC constexpr auto cReasonLen = 512; @@ -131,11 +131,14 @@ EXTERN_C void hal_init_platform( kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { const char* msg = (const char*)rdx; - Kernel::kcout << "Native Log: " << msg << "\r"; + Kernel::kcout << "Kernel: " << msg << "\r"; }; kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { - tls_check_syscall_impl(rdx); + if (tls_check_syscall_impl(rdx) == false) + { + Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + } }; kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { @@ -170,8 +173,8 @@ EXTERN_C void hal_init_platform( if (!rdxPb) return; - // install the fTIB and fPIB. - rt_install_tib(rdxPb->fTIB, rdxPb->fPIB); + // install the fTIB and fGIB. + rt_install_tib(rdxPb->fTIB, rdxPb->fGIB); }; kSyscalls[cExitInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { @@ -224,8 +227,7 @@ EXTERN_C void hal_init_platform( Kernel::StringView strAutoMount(cMaxPropLen); strAutoMount += "\\Properties\\AutoMountFS?"; - cAutoFormatDisk.GetKey() = strAutoMount; - + cAutoFormatDisk.GetKey() = strAutoMount; for (size_t i = 0; i < cMaxCmdLine; i++) { diff --git a/Kernel/HALKit/ARM64/HalKernelMain.cxx b/Kernel/HALKit/ARM64/HalKernelMain.cxx index 0d6a8ca5..64e38fcb 100644 --- a/Kernel/HALKit/ARM64/HalKernelMain.cxx +++ b/Kernel/HALKit/ARM64/HalKernelMain.cxx @@ -36,8 +36,8 @@ struct PACKED HeapAllocInfo final struct PACKED ProcessBlockInfo final { - ThreadInformationBlock* fTIB; - ThreadInformationBlock* fPIB; + THREAD_INFORMATION_BLOCK* fTIB; + THREAD_INFORMATION_BLOCK* fPIB; }; struct PACKED ProcessExitInfo final @@ -91,11 +91,14 @@ EXTERN_C void hal_init_platform( kSyscalls[cSerialAlertInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { const char* msg = (const char*)rdx; - Kernel::kcout << "serial: " << msg << "\r"; + Kernel::kcout << "Kernel: " << msg << "\r"; }; kSyscalls[cTlsInterrupt].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { - tls_check_syscall_impl(rdx); + if (tls_check_syscall_impl(rdx) == false) + { + Kernel::ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + } }; kSyscalls[cLPCSanitizeMsg].Leak().Leak()->fProc = [](Kernel::VoidPtr rdx) -> void { diff --git a/Kernel/KernelKit/PE.hxx b/Kernel/KernelKit/PE.hxx index 0788cd2d..13b002d7 100644 --- a/Kernel/KernelKit/PE.hxx +++ b/Kernel/KernelKit/PE.hxx @@ -129,4 +129,9 @@ typedef struct ExecImageHeader { ExecOptionalHeader mOptHdr; } ExecImageHeader, *ExecImageHeaderPtr; +enum +{ + eUserSection = 0x00000020, +}; + #endif /* ifndef __KERNELKIT_INC_PE_HXX__ */ diff --git a/Kernel/KernelKit/ProcessHeap.hxx b/Kernel/KernelKit/ProcessHeap.hxx index 377e6009..c7522da5 100644 --- a/Kernel/KernelKit/ProcessHeap.hxx +++ b/Kernel/KernelKit/ProcessHeap.hxx @@ -17,7 +17,6 @@ /// @file ProcessHeap.hxx /// @brief Process heap allocator. -#define kUserHeapMaxSz (4096) #define kUserHeapMag (0xFAF0FEF0) namespace Kernel diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx index 4a0d7528..9332a47b 100644 --- a/Kernel/KernelKit/ThreadLocalStorage.hxx +++ b/Kernel/KernelKit/ThreadLocalStorage.hxx @@ -17,21 +17,21 @@ #define kTLSCookieLen (3U) -/// @brief Thread Information Block for Local Storage. +struct THREAD_INFORMATION_BLOCK; + +/// @brief Thread Information Block. /// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64) -struct PACKED ThreadInformationBlock final +struct PACKED THREAD_INFORMATION_BLOCK final { - Kernel::Char Cookie[kTLSCookieLen]; // Process cookie. - Kernel::UIntPtr StartCode; // Start Address - Kernel::UIntPtr StartData; // Allocation Heap - Kernel::UIntPtr StartStack; // Stack Pointer. - Kernel::Int32 ThreadID; // Thread execution ID. + Kernel::Char f_Cookie[kTLSCookieLen]; // Process cookie. + Kernel::UIntPtr f_Code; // Start Address + Kernel::UIntPtr f_Data; // Allocation Heap + Kernel::UIntPtr f_BSS; // Stack Pointer. + Kernel::Int32 f_ID; // Thread execution ID. }; -typedef struct ThreadInformationBlock ProcessInformationBlock; - ///! @brief Cookie Sanity check. -Kernel::Boolean tls_check_tib(ThreadInformationBlock* Ptr); +Kernel::Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib); ///! @brief new ptr syscall. template <typename T> @@ -45,10 +45,10 @@ template <typename T, typename... Args> T* tls_new_class(Args&&... args); /// @brief TLS install TIB and PIB. (syscall) -EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, ThreadInformationBlock* PIB); +EXTERN_C void rt_install_tib(THREAD_INFORMATION_BLOCK* TIB, THREAD_INFORMATION_BLOCK* PIB); /// @brief TLS check (syscall) -EXTERN_C Kernel::Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept; +EXTERN_C Kernel::Bool tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept; #include <KernelKit/ThreadLocalStorage.inl> diff --git a/Kernel/Sources/ProcessHeap.cxx b/Kernel/Sources/ProcessHeap.cxx index 414cd934..fe54be4b 100644 --- a/Kernel/Sources/ProcessHeap.cxx +++ b/Kernel/Sources/ProcessHeap.cxx @@ -92,19 +92,35 @@ namespace Kernel /// @return VoidPtr the heap pointer. STATIC VoidPtr ke_find_unused_heap(Int32 flags) { - for (SizeT index = 0; index < kUserHeapMaxSz; ++index) + SizeT index = 0UL; + + while (true) { + /* ************************************ */ + /* allocate if it doesnt exist. */ + /* ************************************ */ + if (!ProcessHeapHelper::The()[index]) + { + ProcessHeapHelper::The().Add(Kernel::Ref<Kernel::PTEWrapper>()); + } + if (ProcessHeapHelper::The()[index] && !ProcessHeapHelper::The()[index].Leak().Leak().Present()) { ProcessHeapHelper::Leak().Leak().TogglePresent( ProcessHeapHelper::The()[index].Leak().Leak(), true); + + ProcessHeapHelper::Leak().Leak().ToggleUser( + ProcessHeapHelper::The()[index].Leak().Leak(), true); + kcout << "[ke_find_unused_heap] Done, trying to make a pool now...\r"; return ke_make_heap_internal( (VoidPtr)ProcessHeapHelper::The()[index].Leak().Leak().VirtualAddress(), flags); } + + ++index; } return nullptr; @@ -131,7 +147,8 @@ namespace Kernel poolHdr->fMagic = kUserHeapMag; poolHdr->fFree = false; - kcout << "[ke_make_heap_internal] New allocation has been done.\n"; + kcout << "[ke_make_heap_internal] New allocation has been done, returning new chunk.\n"; + return reinterpret_cast<VoidPtr>( (reinterpret_cast<UIntPtr>(virtualAddress) + sizeof(PROCESS_HEAP_HEADER))); } @@ -204,9 +221,6 @@ namespace Kernel if (!ProcessHeapHelper::IsEnabled()) return nullptr; - if (ProcessHeapHelper::Count() > kUserHeapMaxSz) - return nullptr; - if (VoidPtr ret = ke_find_unused_heap(flags)) return ret; @@ -245,7 +259,7 @@ namespace Kernel if (ke_check_and_free_heap(base, ptr)) return 0; - for (SizeT index = 0; index < kUserHeapMaxSz; ++index) + for (SizeT index = 0; index < ProcessHeapHelper::The().Count(); ++index) { if (ke_check_and_free_heap(index, ptr)) return 0; diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index 245ffa1c..aac6f9ce 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -24,20 +24,20 @@ using namespace Kernel; Kernel::Property cTLSEnforceCheck; /** - * @brief Check for cookie inside TIB. + * @brief Checks for cookie inside the TIB. * @param tib the TIB to check. * @return if the cookie is enabled. */ -Boolean tls_check_tib(ThreadInformationBlock* tib) +Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib) { - if (!tib) + if (!the_tib) return false; Encoder encoder; - const char* tibAsBytes = encoder.AsBytes(tib); + const char* tibAsBytes = encoder.AsBytes(the_tib); - kcout << "newoskrnl: checking for a valid cookie...\r"; + kcout << "newoskrnl: checking for a valid cookie inside the TIB...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -48,28 +48,29 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) * @param stackPtr The call frame. * @return */ -EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept +EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { if (!tib_ptr) { if (cTLSEnforceCheck.GetValue() == No) { - return; + return true; } else { - kcout << "newoskrnl: crashing because of an invalid TIB...\r"; - ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + kcout << "newoskrnl: failing because of an invalid TIB...\r"; + return false; } } - ThreadInformationBlock* tib_struct = (ThreadInformationBlock*)tib_ptr; + THREAD_INFORMATION_BLOCK* tib_struct = (THREAD_INFORMATION_BLOCK*)tib_ptr; if (!tls_check_tib(tib_struct)) { kcout << "newoskrnl: crashing because of an invalid TIB...\r"; - ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + return false; } kcout << "newoskrnl: Verification succeeded! staying alive...\r"; + return true; } diff --git a/Kernel/Sources/User.cxx b/Kernel/Sources/User.cxx index e546dd81..40723f27 100644 --- a/Kernel/Sources/User.cxx +++ b/Kernel/Sources/User.cxx @@ -17,10 +17,21 @@ #include <KernelKit/Heap.hxx> -/// bugs 0 +/// BUGS: 0 namespace Kernel { + namespace Detail + { + /// \brief Constructs a token by hashing the password. + /// \param password password to hash. + /// \return the hashed password + const Char* cred_construct_token(const Char* password) + { + return nullptr; + } + } + User::User(const Int32& sel, const Char* userName) : fRing((RingKind)sel) { @@ -108,7 +119,9 @@ namespace Kernel } else { - if (rt_string_cmp((Char*)token, const_cast<Char*>(password), rt_string_len(password))) + auto tok = Detail::cred_construct_token(password); + + if (rt_string_cmp((Char*)token, tok, rt_string_len(tok))) { kcout << "newoskrnl: Incorrect credentials.\r"; diff --git a/Kernel/Sources/Utils.cxx b/Kernel/Sources/Utils.cxx index 152f28fa..2132e80d 100644 --- a/Kernel/Sources/Utils.cxx +++ b/Kernel/Sources/Utils.cxx @@ -11,6 +11,10 @@ namespace Kernel { Int rt_string_cmp(const Char* src, const Char* cmp, Size size) { + if (!cmp || + !src) + return 1; + Int32 counter = 0; for (Size index = 0; index < size; ++index) diff --git a/Kernel/amd64-efi.make b/Kernel/amd64-efi.make index 934481af..22e958b7 100644 --- a/Kernel/amd64-efi.make +++ b/Kernel/amd64-efi.make @@ -6,7 +6,8 @@ CC = x86_64-w64-mingw32-g++ LD = x86_64-w64-mingw32-ld CCFLAGS = -fshort-wchar -c -fPIC -ffreestanding -D__NEWOS_AMD64__ -mno-red-zone -fno-rtti -fno-exceptions \ - -std=c++20 -D__NEWOS_SUPPORT_NX__ -I../Vendor -D__FSKIT_USE_NEWFS__ -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I./ + -std=c++20 -D__NEWOS_SUPPORT_NX__ -I../Vendor -D__FSKIT_USE_NEWFS__ \ + -D__KERNEL__ -D__HAVE_MAHROUSS_APIS__ -D__MAHROUSS__ -I./ ASM = nasm @@ -34,7 +35,7 @@ COPY = cp ASMFLAGS = -f win64 # Kernel subsystem is 17 and entrypoint is __ImageStart -LDFLAGS = -e __ImageStart --subsystem=17 +LDFLAGS = -e hal_init_platform --subsystem=17 LDOBJ = Objects/*.obj # This file is the kernel, responsible of task management and memory. |
