summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-18 20:01:38 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-18 20:01:38 +0100
commit98347089c7e4e2b306d25a0db77e00aa2ea50882 (patch)
treea0b3a1130bff9068055aea87f3e3b964dc9fce0a
parent4c714f2c24c5df78bae2f35c42c73107de4c8c71 (diff)
unstable, secret: Very important changes done to the system API, add
threading functions. Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
-rw-r--r--.vscode/c_cpp_properties.json4
-rw-r--r--Private/CompilerKit/Detail.hxx4
-rw-r--r--Private/KernelKit/ThreadLocalStorage.hxx5
-rw-r--r--Private/NetworkKit/NetworkDevice.hpp17
-rw-r--r--Private/NewBoot/Source/makefile2
-rw-r--r--Private/NewKit/Defines.hpp6
-rw-r--r--Private/Source/Network/NetworkDevice.cxx2
-rw-r--r--Private/Source/ThreadLocalStorage.cxx6
-rw-r--r--Private/makefile2
-rw-r--r--Public/Kits/System.Core/Defs.hxx19
-rw-r--r--Public/Kits/System.Core/HCoreHeap.hxx7
-rw-r--r--Public/Kits/System.Core/Heap.cxx5
-rw-r--r--Public/Kits/System.Core/HintBase.hxx18
-rw-r--r--Public/Kits/System.Core/Makefile2
-rw-r--r--Public/Kits/System.Core/New+Delete.cxx50
-rw-r--r--Public/Kits/System.Core/System.hxx2
-rw-r--r--Public/Kits/System.Core/ThreadAPI.hxx36
-rw-r--r--Public/Kits/System.Core/Threading.hxx35
18 files changed, 163 insertions, 59 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 1b98e803..cd9afd5e 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -7,7 +7,7 @@
"${workspaceFolder}/Private/NewBoot/**",
"${workspaceFolder}/Public/Kits/**"
],
- "defines": ["__HCORE__", "Z_PREFIX", "__HAVE_HCORE_APIS__", "__FSKIT_NEWFS__", "kBootKrnlSections"],
+ "defines": ["__HCORE__", "__KERNEL__", "Z_PREFIX", "__HAVE_HCORE_APIS__", "__FSKIT_NEWFS__", "kBootKrnlSections"],
"cStandard": "c17",
"cppStandard": "c++20",
"compilerPath": "/opt/homebrew/bin/x86_64-w64-mingw32-gcc",
@@ -20,7 +20,7 @@
"${workspaceFolder}/Private/NewBoot/**",
"${workspaceFolder}/Public/Kits/**"
],
- "defines": ["__HCORE__", "Z_PREFIX", "__HAVE_HCORE_APIS__", "__FSKIT_NEWFS__", "kBootKrnlSections"],
+ "defines": ["__HCORE__", "__KERNEL__", "Z_PREFIX", "__HAVE_HCORE_APIS__", "__FSKIT_NEWFS__", "kBootKrnlSections"],
"cStandard": "c17",
"cppStandard": "c++20",
"compilerPath": "C:/cygwin64/bin/x86_64-w64-mingw32-gcc.exe",
diff --git a/Private/CompilerKit/Detail.hxx b/Private/CompilerKit/Detail.hxx
index 0c7a7c46..78a08dcf 100644
--- a/Private/CompilerKit/Detail.hxx
+++ b/Private/CompilerKit/Detail.hxx
@@ -6,7 +6,9 @@
#pragma once
-#include <NewKit/Defines.hpp>
+#ifdef __KERNEL__
+# include <NewKit/Defines.hpp>
+#endif // ifdef __KERNEL__
#define HCORE_COPY_DELETE(KLASS) \
KLASS &operator=(const KLASS &) = delete; \
diff --git a/Private/KernelKit/ThreadLocalStorage.hxx b/Private/KernelKit/ThreadLocalStorage.hxx
index 25c9c48f..2fab5026 100644
--- a/Private/KernelKit/ThreadLocalStorage.hxx
+++ b/Private/KernelKit/ThreadLocalStorage.hxx
@@ -38,7 +38,8 @@ struct ThreadInformationBlock final {
HCore::UIntPtr StartData; // Allocation Heap
HCore::UIntPtr StartStack; // Stack Pointer.
HCore::Int32 Arch; // Architecture and/or platform.
- rt_cookie_type Cookie; // Not shown in public header, this is the way we tell
+ HCore::Int32 ID; // Thread execution ID.
+ rt_cookie_type Cookie; // Not shown in public header, location of the cookie header is store here, this is the way we tell
// something went wrong.
};
@@ -46,7 +47,7 @@ struct ThreadInformationBlock final {
EXTERN_C void rt_install_tib(ThreadInformationBlock *pTib, HCore::VoidPtr pPib);
///! @brief Cookie Sanity check.
-HCore::Boolean tls_check(ThreadInformationBlock *ptr);
+HCore::Boolean tls_check_tib(ThreadInformationBlock *ptr);
/// @brief TLS check system call
EXTERN_C HCore::Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept;
diff --git a/Private/NetworkKit/NetworkDevice.hpp b/Private/NetworkKit/NetworkDevice.hpp
index 74b60068..d85cb939 100644
--- a/Private/NetworkKit/NetworkDevice.hpp
+++ b/Private/NetworkKit/NetworkDevice.hpp
@@ -4,8 +4,8 @@
------------------------------------------- */
-#ifndef _INC_NETWORKDEVICE_HPP__
-#define _INC_NETWORKDEVICE_HPP__
+#ifndef __NETWORK_DEVICE__
+#define __NETWORK_DEVICE__
#include <KernelKit/DeviceManager.hpp>
#include <NetworkKit/IP.hpp>
@@ -30,17 +30,18 @@ class NetworkDevice final : public DeviceInterface<NetworkDeviceCommand> {
NetworkDevice(const NetworkDevice &) = default;
public:
- const char *Name() const override { return "NetworkDevice"; }
+ const char *Name() const override;
private:
void (*fCleanup)(void);
};
struct PACKED NetworkDeviceCommand final {
- UInt32 Command;
- UInt32 VLan;
- UInt32 DmaLow;
- UInt32 DmaHigh;
+ UInt32 CommandName;
+ UInt32 CommandType;
+ UInt32 CommandFlags;
+ VoidPtr CommandBuffer;
+ SizeT CommandSizeBuffer;
};
/// @brief TCP device.
@@ -58,4 +59,4 @@ using HPCNetworkDevice = NetworkDevice;
#include <NetworkKit/NetworkDevice.inl>
-#endif // !_INC_NETWORKDEVICE_HPP__
+#endif // !__NETWORK_DEVICE__
diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile
index 801e7699..2eab4a84 100644
--- a/Private/NewBoot/Source/makefile
+++ b/Private/NewBoot/Source/makefile
@@ -23,7 +23,7 @@ REM=rm
REM_FLAG=-f
FLAG_ASM=-f win64
-FLAG_GNU=-fshort-wchar -DkBootKrnlSections=9 -mgeneral-regs-only -mno-red-zone -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -D__BOOTLOADER__ -I./
+FLAG_GNU=-fshort-wchar -DkBootKrnlSections=9 -mgeneral-regs-only -mno-red-zone -D__KERNEL__ -DEFI_FUNCTION_WRAPPER -I../ -I../../ -I./ -c -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -D__HAVE_HCORE_APIS__ -D__HCORE__ -D__BOOTLOADER__ -I./
.PHONY: invalid-recipe
invalid-recipe:
diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp
index bc41633f..563af7d2 100644
--- a/Private/NewKit/Defines.hpp
+++ b/Private/NewKit/Defines.hpp
@@ -8,7 +8,11 @@
#include <NewKit/Macros.hpp>
-#define NEWKIT_VERSION "1.00"
+#ifndef __KERNEL__
+# error You are not compiling the kernel.
+#endif
+
+#define NEWKIT_VERSION "1.01"
#if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__)
#include <CRT/__cxxkit_defines.hxx>
diff --git a/Private/Source/Network/NetworkDevice.cxx b/Private/Source/Network/NetworkDevice.cxx
index eba95a2c..f43ef335 100644
--- a/Private/Source/Network/NetworkDevice.cxx
+++ b/Private/Source/Network/NetworkDevice.cxx
@@ -7,5 +7,5 @@
#include <NetworkKit/NetworkDevice.hpp>
namespace HCore {
-
+const char *NetworkDevice::Name() const { return "NetworkDevice"; }
} // namespace HCore
diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx
index 395b9dc6..8fd61d5e 100644
--- a/Private/Source/ThreadLocalStorage.cxx
+++ b/Private/Source/ThreadLocalStorage.cxx
@@ -25,12 +25,12 @@ using namespace HCore;
* @return if the cookie is enabled.
*/
-Boolean tls_check(VoidPtr ptr) {
+Boolean tls_check_tib(VoidPtr ptr) {
if (!ptr) return false;
const char* _ptr = (const char*)ptr;
- kcout << "HCoreKrnl\\TLS: Checking for cookie...\n";
+ kcout << "HCoreKrnl\\TLS: Checking for a valid cookie...\n";
return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 &&
_ptr[2] == kCookieMag2;
@@ -44,7 +44,7 @@ Boolean tls_check(VoidPtr ptr) {
EXTERN_C Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept {
ThreadInformationBlock* tib = (ThreadInformationBlock*)stackPtr->Gs;
- if (!tls_check(tib->Cookie)) {
+ if (!tls_check_tib(tib->Cookie)) {
kcout << "HCoreKrnl\\TLS: Verification failed, Crashing...\n";
ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
}
diff --git a/Private/makefile b/Private/makefile
index d64889a3..e9528a48 100644
--- a/Private/makefile
+++ b/Private/makefile
@@ -5,7 +5,7 @@
CC = x86_64-w64-mingw32-gcc
LD = x86_64-w64-mingw32-ld
-CCFLAGS = -c -ffreestanding -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./
+CCFLAGS = -c -ffreestanding -mgeneral-regs-only -mno-red-zone -fno-rtti -fno-exceptions -std=c++20 -D__FSKIT_NEWFS__ -D__KERNEL__ -D__HAVE_HCORE_APIS__ -D__HCORE__ -I../ -I./
ASM = nasm
# Add assembler, linker, and object files variables.
diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx
index ad615ef9..d1e5d483 100644
--- a/Public/Kits/System.Core/Defs.hxx
+++ b/Public/Kits/System.Core/Defs.hxx
@@ -45,12 +45,29 @@ typedef __UINT16_TYPE__ WORD;
typedef __UINT32_TYPE__ DWORD;
typedef __UINT64_TYPE__ QWORD;
+typedef char CHAR;
+typedef CHAR* PCHAR;
+
typedef void* PVOID;
typedef void VOID;
+typedef __UINTPTR_TYPE__ UINT_PTR;
+typedef __INTPTR_TYPE__ INT_PTR;
+typedef __UINT64_TYPE__ UINT64;
+typedef __INT64_TYPE__ INT64;
+typedef __UINT32_TYPE__ UINT32;
+typedef __INT32_TYPE__ INT32;
+
typedef __WCHAR_TYPE__ WCHAR;
typedef WCHAR* PWCHAR;
+typedef bool BOOL;
+
+#define TRUE true
+#define FALSE false
+
+#define PTR *
+
#define CA_UNREFERENCED_PARAMETER(e) ((VOID)e)
#ifdef __x86_64__
@@ -90,3 +107,5 @@ enum {
kProcessHeapCallCloseHandle,
kProcessHeapCallsCnt,
};
+
+#include <System.Core/HintBase.hxx>
diff --git a/Public/Kits/System.Core/HCoreHeap.hxx b/Public/Kits/System.Core/HCoreHeap.hxx
index 0c6eb1dc..41143495 100644
--- a/Public/Kits/System.Core/HCoreHeap.hxx
+++ b/Public/Kits/System.Core/HCoreHeap.hxx
@@ -11,3 +11,10 @@ CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags)
CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr);
CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr);
CA_EXTERN_C QWORD HcProcessHeapExists(ObjectPtr refObj, PVOID ptr);
+
+enum HcAllocationKind {
+ kStandardAllocation = 0xC,
+ kArrayAllocation = 0xD,
+};
+
+#define kAllocationTypes 2
diff --git a/Public/Kits/System.Core/Heap.cxx b/Public/Kits/System.Core/Heap.cxx
index 56188e95..aaac37a8 100644
--- a/Public/Kits/System.Core/Heap.cxx
+++ b/Public/Kits/System.Core/Heap.cxx
@@ -20,7 +20,10 @@ Heap* Heap::Shared() noexcept {
return heap;
}
-void Heap::Delete(HeapPtr me) noexcept { HcFreeProcessHeap(kInstanceObject, me); }
+void Heap::Delete(HeapPtr me) noexcept {
+ CA_MUST_PASS(me);
+ HcFreeProcessHeap(kInstanceObject, me);
+}
SizeT Heap::Size(HeapPtr me) noexcept {
CA_MUST_PASS(me);
diff --git a/Public/Kits/System.Core/HintBase.hxx b/Public/Kits/System.Core/HintBase.hxx
new file mode 100644
index 00000000..86faf455
--- /dev/null
+++ b/Public/Kits/System.Core/HintBase.hxx
@@ -0,0 +1,18 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#pragma once
+
+#define _Input
+#define _Output
+
+#define _Optional
+
+#define _StrictCheckInput
+#define _StrictCheckOutput
+
+#define _InOut
+#define _StrictInOut
diff --git a/Public/Kits/System.Core/Makefile b/Public/Kits/System.Core/Makefile
index f358dfa5..286c1120 100644
--- a/Public/Kits/System.Core/Makefile
+++ b/Public/Kits/System.Core/Makefile
@@ -4,7 +4,7 @@
##################################################
CC=x86_64-w64-mingw32-g++
-CCFLAGS=-shared -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -Xlinker --subsystem=17
+CCFLAGS=-shared -ffreestanding -nostdlib -fno-rtti -fno-exceptions -std=c++20 -Xlinker --subsystem=17
OUTPUT=System.Core.dll
.PHONY: build-core
diff --git a/Public/Kits/System.Core/New+Delete.cxx b/Public/Kits/System.Core/New+Delete.cxx
new file mode 100644
index 00000000..cac883f4
--- /dev/null
+++ b/Public/Kits/System.Core/New+Delete.cxx
@@ -0,0 +1,50 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+#include <System.Core/HCoreHeap.hxx>
+
+void* operator new[](size_t sz)
+{
+ if (sz == 0)
+ ++sz;
+
+ return HcAllocateProcessHeap(kInstanceObject, sz, kStandardAllocation);
+}
+
+void* operator new(size_t sz)
+{
+ if (sz == 0)
+ ++sz;
+
+ return HcAllocateProcessHeap(kInstanceObject, sz, kArrayAllocation);
+}
+
+void operator delete[](void* ptr)
+{
+ if (ptr == nullptr)
+ return;
+
+ HcFreeProcessHeap(kInstanceObject, ptr);
+}
+
+void operator delete(void* ptr)
+{
+ if (ptr == nullptr)
+ return;
+
+ HcFreeProcessHeap(kInstanceObject, ptr);
+}
+
+void operator delete(void* ptr, size_t sz)
+{
+ if (ptr == nullptr)
+ return;
+
+ (void)sz;
+
+ HcFreeProcessHeap(kInstanceObject, ptr);
+}
+
diff --git a/Public/Kits/System.Core/System.hxx b/Public/Kits/System.Core/System.hxx
index 37cab4a4..05028d87 100644
--- a/Public/Kits/System.Core/System.hxx
+++ b/Public/Kits/System.Core/System.hxx
@@ -13,6 +13,6 @@
#include <System.Core/Defs.hxx>
#include <System.Core/File.hxx>
#include <System.Core/Heap.hxx>
-#include <System.Core/ThreadAPI.hxx>
+#include <System.Core/Threading.hxx>
using namespace HCore;
diff --git a/Public/Kits/System.Core/ThreadAPI.hxx b/Public/Kits/System.Core/ThreadAPI.hxx
deleted file mode 100644
index ec15a64c..00000000
--- a/Public/Kits/System.Core/ThreadAPI.hxx
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -------------------------------------------
-
- Copyright Mahrouss Logic
-
-------------------------------------------- */
-
-//
-// Created by Amlal on 1/27/24.
-//
-
-#ifndef __THREAD_API__
-#define __THREAD_API__
-
-#include <NewKit/Defines.hpp>
-
-namespace HCore {
-/// @brief Thread Information Block for Local Storage.
-/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64)
-struct ThreadInformationBlock final {
- const Char Name[255]; // Module Name
- const UIntPtr StartAddress; // Start Address
- const UIntPtr StartHeap; // Allocation Heap
- const UIntPtr StartStack; // Stack Pointer.
- const Int32 Arch; // Architecture and/or platform.
-};
-
-enum {
- kPC_IA64,
- kPC_AMD64 = kPC_IA64,
- kPC_ARM,
- kMACS_64x0,
- kMACS_32x0,
-};
-} // namespace HCore
-
-#endif // __THREAD_API__
diff --git a/Public/Kits/System.Core/Threading.hxx b/Public/Kits/System.Core/Threading.hxx
new file mode 100644
index 00000000..5d5ed0a6
--- /dev/null
+++ b/Public/Kits/System.Core/Threading.hxx
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright Mahrouss Logic
+
+------------------------------------------- */
+
+//
+// Created by Amlal on 3/18/24
+//
+
+#ifndef __THREAD_API__
+#define __THREAD_API__
+
+#include <System.Core/Defs.hxx>
+
+/// @brief Thread Information Block variant for scheduling.
+struct ThreadInformationBlock final {
+ const CHAR Name[255]; // Module Name
+ const UINT_PTR StartAddress; // Start Address
+ const UINT_PTR StartHeap; // Allocation Heap
+ const UINT_PTR StartStack; // Stack Pointer.
+ const DWORD Arch; // Architecture and/or platform.
+ const WORD TID; // Execution Thread ID.
+};
+
+ThreadInformationBlock* HcCreateThread(_Input PVOID Start,
+ _Optional _InOut PVOID HeapOpt, _Optional _InOut PVOID StackOpt);
+
+BOOL HcDestroyThread(_Input ThreadInformationBlock* TIB);
+
+BOOL HcStopThread(_Input ThreadInformationBlock* TIB);
+
+BOOL HcResumeThread(_Input ThreadInformationBlock* TIB);
+
+#endif // __THREAD_API__