summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-01 18:25:14 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-01 18:25:14 +0200
commit86e291120d124dec7244202b1766901a59dfb2e6 (patch)
tree1aa92d3b8a05216941986cf2724ff20ad01b3884
parentf9579f444b1791d2b73d4d841569728fb203cb29 (diff)
[IMP] newoskrnl: Add symbol for cred_construct_token, reworked
ProcessHeap, new SCI.hxx for SCI and SCM. [IMP] newosldr: Loads the kernel correctly and can launch it, improved erorr handling. [META] newoskrnl, newosldr: Improved code and refactors. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Boot/Sources/HEL/AMD64/BootJump.S6
-rw-r--r--Boot/Sources/HEL/AMD64/BootMain.cxx11
-rw-r--r--Boot/Sources/ProgramLoader.cxx48
-rw-r--r--Kernel/HALKit/AMD64/HalBoot.asm20
-rw-r--r--Kernel/HALKit/AMD64/HalKernelMain.cxx24
-rw-r--r--Kernel/HALKit/ARM64/HalKernelMain.cxx11
-rw-r--r--Kernel/KernelKit/PE.hxx5
-rw-r--r--Kernel/KernelKit/ProcessHeap.hxx1
-rw-r--r--Kernel/KernelKit/ThreadLocalStorage.hxx24
-rw-r--r--Kernel/Sources/ProcessHeap.cxx26
-rw-r--r--Kernel/Sources/ThreadLocalStorage.cxx23
-rw-r--r--Kernel/Sources/User.cxx17
-rw-r--r--Kernel/Sources/Utils.cxx4
-rw-r--r--Kernel/amd64-efi.make5
-rw-r--r--SCIKit/ErrorTypes.hxx2
-rw-r--r--SCIKit/SCI.hxx (renamed from SCIKit/Types.hxx)66
16 files changed, 181 insertions, 112 deletions
diff --git a/Boot/Sources/HEL/AMD64/BootJump.S b/Boot/Sources/HEL/AMD64/BootJump.S
index fc7b3c68..7c2fcbc4 100644
--- a/Boot/Sources/HEL/AMD64/BootJump.S
+++ b/Boot/Sources/HEL/AMD64/BootJump.S
@@ -8,11 +8,13 @@
@brief this function setups a stack and then jumps to
a function */
rt_jump_to_address:
- mov r8, rsp
+ mov rsp, r8
push rax
push rdx
- jmp rcx
+ mov rbx, rcx
+ mov rcx, rdx
+ jmp rbx
pop rdx
pop rax
diff --git a/Boot/Sources/HEL/AMD64/BootMain.cxx b/Boot/Sources/HEL/AMD64/BootMain.cxx
index 5e0c8b05..56ef0457 100644
--- a/Boot/Sources/HEL/AMD64/BootMain.cxx
+++ b/Boot/Sources/HEL/AMD64/BootMain.cxx
@@ -243,16 +243,7 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle,
loader->SetName("\"newoskrnl.exe\" (64-bit MP)");
}
- if (!loader->IsValid())
- {
- writer.Write("newosldr: Invalid kernel image!\r");
-
- EFI::Stop();
-
- CANT_REACH();
- }
-
- writer.Write("newosldr: ").Write(loader->GetName()).Write("\r");
+ writer.Write("newosldr: Running: ").Write(loader->GetName()).Write("\r");
CopyMem(handoverHdrPtr->f_CommandLine[0], "/SMP", StrLen("/SMP"));
diff --git a/Boot/Sources/ProgramLoader.cxx b/Boot/Sources/ProgramLoader.cxx
index 90e4b624..2103414a 100644
--- a/Boot/Sources/ProgramLoader.cxx
+++ b/Boot/Sources/ProgramLoader.cxx
@@ -18,6 +18,8 @@ EXTERN_C
#include <string.h>
}
+extern EfiBootServices* BS;
+
namespace Boot
{
EXTERN_C Int32 rt_jump_to_address(HEL::HandoverProc baseCode, HEL::HandoverInformationHeader* handover, Char* stackPointer);
@@ -63,14 +65,22 @@ namespace Boot
{
ExecSectionHeaderPtr sect = &sectPtr[sectIndex];
- // if this is a code header.
- if (sect->mCharacteristics & 0x00000020)
+ EfiPhysicalAddress address_to_alloc = sect->mVirtualAddress;
+
+ // if this is a code header, then we can look for the entrypoint.
+ if (sect->mCharacteristics & eUserSection)
{
- fStartAddress = (VoidPtr)(optHdr->mAddressOfEntryPoint + sect->mPointerToRawData +
- sect->mVirtualAddress);
- writer.Write("newosldr: Start Address: ").Write((UIntPtr)fStartAddress).Write("\r");
+ BS->AllocatePages(EfiAllocateType::AllocateAddress, EfiMemoryType::EfiLoaderCode, 1, &address_to_alloc);
- break;
+ if (!fStartAddress)
+ {
+ fStartAddress = (VoidPtr)((UIntPtr)firstBytes + optHdr->mAddressOfEntryPoint);
+ writer.Write("newosldr: Start Address set: ").Write((UIntPtr)fStartAddress).Write("\r");
+ }
+ }
+ else
+ {
+ BS->AllocatePages(EfiAllocateType::AllocateAddress, EfiMemoryType::EfiLoaderData, 1, &address_to_alloc);
}
}
}
@@ -97,32 +107,28 @@ namespace Boot
{
BTextWriter writer;
- if (!handover ||
- ((Char*)fStartAddress)[0] == 0x0)
+ if (!handover)
{
writer.Write("newosldr: Exec format error.\r");
return;
}
- writer.Write("newosldr: Trying to run: ").Write(fBlobName).Write("\r");
+ HEL::HandoverProc err_fn = [](HEL::HandoverInformationHeader* rcx) -> void {
+ BTextWriter writer;
+ writer.Write("newosldr: Exec format error, Thread has been aborted.\r");
+
+ EFI::ThrowError(L"Exec-Format-Error", L"Format doesn't match (Thread aborted.)");
+ };
if (!fStartAddress)
{
- HEL::HandoverProc fn = [](HEL::HandoverInformationHeader* rcx) -> void {
- BTextWriter writer;
- writer.Write("newosldr: Exec format error, Thread has been aborted.\r");
-
- EFI::ThrowError(L"Exec-Format-Error", L"Format doesn't match (Thread aborted.)");
- };
-
- rt_jump_to_address(fn, handover, fStackPtr);
-
- return;
+ err_fn(handover);
}
- HEL::HandoverProc start = reinterpret_cast<HEL::HandoverProc>((UIntPtr)fStartAddress);
+ volatile HEL::HandoverProc start = reinterpret_cast<HEL::HandoverProc>((UIntPtr)fStartAddress);
- rt_jump_to_address(start, handover, fStackPtr);
+ start(handover);
+ err_fn(handover);
}
const Char* ProgramLoader::GetName()
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.
diff --git a/SCIKit/ErrorTypes.hxx b/SCIKit/ErrorTypes.hxx
index 4473722a..35af4d64 100644
--- a/SCIKit/ErrorTypes.hxx
+++ b/SCIKit/ErrorTypes.hxx
@@ -6,7 +6,7 @@
#pragma once
-#include <SCIKit/Types.hxx>
+#include <SCIKit/SCI.hxx>
#define ErrLocalIsOk() (kLastError == kErrorSuccess)
#define ErrLocalFailed() (kLastError != kErrorSuccess)
diff --git a/SCIKit/Types.hxx b/SCIKit/SCI.hxx
index 2c7e204e..5f819ba1 100644
--- a/SCIKit/Types.hxx
+++ b/SCIKit/SCI.hxx
@@ -12,8 +12,8 @@ Purpose: System Call types.
#define IMPORT_CXX extern "C++"
#define IMPORT_C extern "C"
-typedef bool Bool;
-typedef void UInt0;
+typedef bool Bool;
+typedef void UInt0;
typedef __UINT64_TYPE__ UInt64;
typedef __UINT32_TYPE__ UInt32;
@@ -27,7 +27,11 @@ typedef __INT32_TYPE__ SInt32;
typedef __INT16_TYPE__ SInt16;
typedef __INT8_TYPE__ SInt8;
-typedef char UTFChar;
+typedef void* VoidPtr;
+typedef __UINTPTR_TYPE__ UIntPtr;
+typedef char Char;
+
+typedef Char UTFChar;
// Interfaces are divided between classes.
// So that they aren't too big.
@@ -56,18 +60,58 @@ public:
#else
/// @brief Allocate new SCM class.
-/// @tparam TCLS
-/// @tparam UCLSID
-/// @param uclsidOfCls
-/// @return
+/// @tparam TCLS
+/// @tparam UCLSID
+/// @param uclsidOfCls
+/// @return
template <typename TCLS, typename UCLSID, typename... Args>
inline TCLS* RtlGetClassFromCLSID(UCLSID uclsidOfCls, Args... args);
/// @brief Release SCM class.
-/// @tparam TCLS
-/// @param cls
-/// @return
+/// @tparam TCLS
+/// @param cls
+/// @return
template <typename TCLS>
inline SInt32 RtlReleaseClass(TCLS* cls);
-#endif \ No newline at end of file
+#endif
+
+/* ================================================ */
+/* SCI structures */
+/* ================================================ */
+
+struct HEAP_ALLOC_INFO final
+{
+ VoidPtr fThe;
+ SizeT fTheSz;
+};
+
+struct THREAD_INFORMATION_BLOCK final
+{
+ Char f_Cookie[3]; // Process cookie.
+ UIntPtr f_Code; // Start Address
+ UIntPtr f_Data; // Allocation Heap
+ UIntPtr f_BSS; // Stack Pointer.
+ SInt32 f_ID; // Thread execution ID.
+};
+
+struct PROCESS_BLOCK_INFO final
+{
+ THREAD_INFORMATION_BLOCK* fTIB;
+ THREAD_INFORMATION_BLOCK* fGIB;
+};
+
+struct PROCESS_EXIT_INFO final
+{
+ static constexpr auto cReasonLen = 512;
+
+ SInt64 fCode;
+ Char fReason[cReasonLen];
+};
+
+/// @brief Raise system call.
+/// @param id the system call id could be 0x10 for example.
+/// @param data the data associated with it.
+/// @param data_sz the size of the data associated with it.
+/// @return status code.
+IMPORT_C SInt32 RtlRaiseSystemCall(const SInt32 id, VoidPtr data, SizeT data_sz); \ No newline at end of file