summaryrefslogtreecommitdiffhomepage
path: root/Public
diff options
context:
space:
mode:
authoramlal <amlal@el-mahrouss-logic.com>2024-03-21 00:38:52 +0100
committeramlal <amlal@el-mahrouss-logic.com>2024-03-21 00:38:52 +0100
commit333fed96b7ccd3ee4f5f097445408dde34d330db (patch)
treea1c9894b26bd81c2e762b5487e04601b357682f2 /Public
parentf48c5b2cda43241919d3ea1b263bef01e014c537 (diff)
Kernel: See below.
- Fix kernel heap, made it better. - Fix System.Core, made it better. Signed-off-by: amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Public')
-rw-r--r--Public/Kits/System.Core/Defs.hxx71
-rw-r--r--Public/Kits/System.Core/File.hxx57
-rw-r--r--Public/Kits/System.Core/Heap.cxx5
-rw-r--r--Public/Kits/System.Core/Heap.hxx20
-rw-r--r--Public/Kits/System.Core/HeapRuntime.cxx (renamed from Public/Kits/System.Core/HeapImpl.cxx)35
-rw-r--r--Public/Kits/System.Core/System.Core.hxx2
6 files changed, 148 insertions, 42 deletions
diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx
index 84bdc7bb..e99abcc4 100644
--- a/Public/Kits/System.Core/Defs.hxx
+++ b/Public/Kits/System.Core/Defs.hxx
@@ -7,7 +7,7 @@
#pragma once
#ifndef __cplusplus
-#error This API is meant to be used with C++
+#error This API is meant to be used with C++.
#endif
#ifdef CA_MUST_PASS
@@ -38,7 +38,7 @@ CA_EXTERN_C void __assert_chk_fail(void);
#define CA_CDECL __attribute__((cdecl))
#define CA_MSCALL __attribute__((ms_abi))
-#define CA_PASCALL CA_STDCALL
+#define CA_PASCAL CA_STDCALL
typedef __UINT8_TYPE__ BYTE;
typedef __UINT16_TYPE__ WORD;
@@ -61,13 +61,16 @@ typedef __INT32_TYPE__ INT32;
typedef __WCHAR_TYPE__ WCHAR;
typedef WCHAR* PWCHAR;
-typedef bool BOOL;
+typedef CHAR BOOL;
-#define TRUE true
-#define FALSE false
+#define TRUE 1
+#define FALSE 0
#define PTR *
+#define FAR __far
+#define NEAR __near
+
#define CA_UNREFERENCED_PARAMETER(e) ((VOID)e)
#ifdef __x86_64__
@@ -123,7 +126,61 @@ class SystemException {
virtual const char *Name() = 0;
virtual const char *Reason() = 0;
+};
+
+/// @brief Object exception
+/// Throws when the object isn't found.
+class ObjectNotFoundException : public SystemException {
+ public:
+ explicit ObjectNotFoundException() = default;
+ virtual ~ObjectNotFoundException() = default;
+
+ public:
+ HCORE_COPY_DEFAULT(ObjectNotFoundException);
+
+ public:
+ const char *Name() override { return "ObjectNotFoundException"; }
+ const char *Reason() override { return mReason; }
+
+ private:
+ const char *mReason{
+ "System.Core: ObjectNotFoundException: Catastrophic failure!"};
+};
+
+/// @brief pointer exception
+/// Throws when the object isn't found.
+class PointerException : public SystemException {
+ public:
+ explicit PointerException() = default;
+ virtual ~PointerException() = default;
+
+ public:
+ HCORE_COPY_DEFAULT(PointerException);
+
+ public:
+ const char *Name() override { return "PointerException"; }
+ const char *Reason() override { return mReason; }
+
private:
const char *mReason{
- "System.Core: SystemException: Catastrophic failure!"};
-}; \ No newline at end of file
+ "System.Core: PointerException: Catastrophic failure!"};
+};
+
+/// @brief pointer exception
+/// Throws when the object isn't found.
+class NullPointerException : public SystemException {
+ public:
+ explicit NullPointerException() = default;
+ virtual ~NullPointerException() = default;
+
+ public:
+ HCORE_COPY_DEFAULT(NullPointerException);
+
+ public:
+ const char *Name() override { return "NullPointerException"; }
+ const char *Reason() override { return mReason; }
+
+ private:
+ const char *mReason{
+ "System.Core: NullPointerException: Catastrophic failure!"};
+};
diff --git a/Public/Kits/System.Core/File.hxx b/Public/Kits/System.Core/File.hxx
index 97377800..7ae70faf 100644
--- a/Public/Kits/System.Core/File.hxx
+++ b/Public/Kits/System.Core/File.hxx
@@ -4,39 +4,68 @@
------------------------------------------- */
-#ifndef _SYSTEM_KIT_HCORE_FILE_HPP
-#define _SYSTEM_KIT_HCORE_FILE_HPP
+#ifndef __FILE_API__
+#define __FILE_API__
#include <CompilerKit/CompilerKit.hxx>
#include <NewKit/Defines.hpp>
-using namespace HCore;
-
/// @brief SOM class, translated to C++
namespace System {
class File final {
public:
- explicit File(const char *path);
- ~File();
+ explicit File(const char *path) {
+ mHandle = kInstanceObject->Invoke(kInstanceObject, kProcessCallOpenHandle,
+ 0, path);
+ }
+
+ ~File() {
+ kInstanceObject->Invoke(kInstanceObject, kProcessCallCloseHandle, 0,
+ mHandle);
+ }
public:
HCORE_COPY_DEFAULT(File);
public:
- voidPtr Read(SizeT off, SizeT sz);
- void Write(VoidPtr buf, SizeT off, SizeT sz);
- void Seek(SizeT off);
- voidPtr Read(SizeT sz);
- void Write(VoidPtr buf, SizeT sz);
- void Rewind();
+ voidPtr Read(UIntPtr off, SizeT sz) { return (VoidPtr)kInstanceObject->Invoke(kInstanceObject, mHandle, 2, off, sz); }
+ voidPtr Read(SizeT sz) { return (VoidPtr)kInstanceObject->Invoke(kInstanceObject, mHandle, 3, sz); }
+
+ void Write(VoidPtr buf, UIntPtr off, SizeT sz) { kInstanceObject->Invoke(kInstanceObject, mHandle, 4, buf, off, sz); }
+ void Write(VoidPtr buf, SizeT sz) { kInstanceObject->Invoke(kInstanceObject, mHandle, 5, buf, sz); }
+
+ void Seek(UIntPtr off) { kInstanceObject->Invoke(kInstanceObject, mHandle, 5); }
+ void Rewind() { kInstanceObject->Invoke(kInstanceObject, mHandle, 6); }
public:
const char *MIME();
void MIME(const char *mime);
+
+ private:
+ IntPtr mHandle;
};
typedef File *FilePtr;
-} // namespace System
-#endif // ifndef _SYSTEM_KIT_HCORE_FILE_HPP
+/// @brief file exception
+/// Throws when the file isn't found or invalid.
+class FileException : public SystemException {
+ public:
+ explicit FileException() = default;
+ virtual ~FileException() = default;
+
+ public:
+ HCORE_COPY_DEFAULT(FileException);
+
+ public:
+ const char *Name() override { return "FileException"; }
+ const char *Reason() override { return mReason; }
+
+ private:
+ const char *mReason{"System.Core: FileException: Catastrophic failure!"};
+};
+
+} // namespace System
+
+#endif // ifndef __FILE_API__
diff --git a/Public/Kits/System.Core/Heap.cxx b/Public/Kits/System.Core/Heap.cxx
index 4dfd34e4..55850b1a 100644
--- a/Public/Kits/System.Core/Heap.cxx
+++ b/Public/Kits/System.Core/Heap.cxx
@@ -21,7 +21,10 @@ Heap* Heap::Shared() noexcept {
return heap;
}
-Heap::Heap() { }
+Heap::Heap() {
+ CA_MUST_PASS(HcProcessHeapExists(kInstanceObject, (VoidPtr)this));
+}
+
Heap::~Heap() { delete this; }
void Heap::Delete(HeapPtr me) noexcept {
diff --git a/Public/Kits/System.Core/Heap.hxx b/Public/Kits/System.Core/Heap.hxx
index 1bfc00de..6bad93e0 100644
--- a/Public/Kits/System.Core/Heap.hxx
+++ b/Public/Kits/System.Core/Heap.hxx
@@ -56,4 +56,24 @@ class Heap final {
SizeT Size(HeapPtr me) noexcept;
HeapPtr New(const SizeT &sz, const Int32 flags = kHeapNoFlags);
};
+
+
+/// @brief heap exception
+/// Throws when the heap pointer isn't found or invalid.
+class HeapException : public SystemException {
+ public:
+ explicit HeapException() = default;
+ virtual ~HeapException() = default;
+
+ public:
+ HCORE_COPY_DEFAULT(HeapException);
+
+ public:
+ const char *Name() override { return "HeapException"; }
+ const char *Reason() override { return mReason; }
+
+ private:
+ const char *mReason{"System.Core: HeapException: Catastrophic failure!"};
+};
+
} // namespace System \ No newline at end of file
diff --git a/Public/Kits/System.Core/HeapImpl.cxx b/Public/Kits/System.Core/HeapRuntime.cxx
index 2980a3de..c2f1f0e9 100644
--- a/Public/Kits/System.Core/HeapImpl.cxx
+++ b/Public/Kits/System.Core/HeapRuntime.cxx
@@ -8,40 +8,37 @@
/// @param refObj Process object.
/// @param sz size of object.
/// @param flags flags.
-/// @return
-CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags)
-{
- CA_MUST_PASS(sz);
- CA_MUST_PASS(flags);
-
- return (PVOID)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags);
+/// @return
+CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz,
+ DWORD flags) {
+ CA_MUST_PASS(sz);
+ CA_MUST_PASS(flags);
+
+ return (PVOID)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags);
}
/// @brief Free pointer from the user's heap.
/// @param refObj Process object.
/// @param ptr the pointer to free.
-CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr)
-{
- CA_MUST_PASS(ptr);
- CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr));
+CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr) {
+ CA_MUST_PASS(ptr);
+ CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr));
}
/// @brief Get pointer size.
/// @param refObj Process object.
/// @param ptr the pointer to find.
/// @return the size.
-CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr)
-{
- CA_MUST_PASS(ptr);
- return refObj->Invoke(refObj, kProcessCallSizePtr, ptr);
+CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr) {
+ CA_MUST_PASS(ptr);
+ return refObj->Invoke(refObj, kProcessCallSizePtr, ptr);
}
/// @brief Check if the pointer exists.
/// @param refObj Process object.
/// @param ptr the pointer to check.
/// @return if it exists
-CA_EXTERN_C BOOL HcProcessHeapExists(ObjectPtr refObj, PVOID ptr)
-{
- CA_MUST_PASS(ptr);
- return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr);
+CA_EXTERN_C BOOL HcProcessHeapExists(ObjectPtr refObj, PVOID ptr) {
+ CA_MUST_PASS(ptr);
+ return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr);
}
diff --git a/Public/Kits/System.Core/System.Core.hxx b/Public/Kits/System.Core/System.Core.hxx
index 07b7199c..96ab45be 100644
--- a/Public/Kits/System.Core/System.Core.hxx
+++ b/Public/Kits/System.Core/System.Core.hxx
@@ -11,4 +11,4 @@
#include <System.Core/File.hxx>
/// Process & Threading API
-#include <System.Core/Threading.hxx> \ No newline at end of file
+#include <System.Core/Threading.hxx>