From 3b3b36dcc6542e203475fe1d50ed89799e3f3fc6 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 25 Mar 2024 20:17:53 +0100 Subject: Kernel: implement some tickets, improved stuff. Signed-off-by: Amlal El Mahrouss --- .../System.Core/Headers/Containers/ODF.hxx | 41 ++++ .../System.Core/Headers/Containers/XIFF.hxx | 57 +++++ Public/Developer/System.Core/Headers/Defines.hxx | 250 +++++++++++++++++++++ Public/Developer/System.Core/Headers/File.hxx | 105 +++++++++ Public/Developer/System.Core/Headers/Heap.hxx | 64 ++++++ Public/Developer/System.Core/Headers/Hint.hxx | 18 ++ Public/Developer/System.Core/Headers/Thread.hxx | 23 ++ .../System.Core/Headers/Window/Dialog.hxx | 9 + .../Developer/System.Core/Headers/Window/Image.hxx | 8 + .../Developer/System.Core/Headers/Window/Menu.hxx | 8 + .../Developer/System.Core/Headers/Window/Rsrc.hxx | 8 + .../System.Core/Headers/Window/TrueType.hxx | 7 + .../System.Core/Headers/Window/Window.hxx | 38 ++++ 13 files changed, 636 insertions(+) create mode 100644 Public/Developer/System.Core/Headers/Containers/ODF.hxx create mode 100644 Public/Developer/System.Core/Headers/Containers/XIFF.hxx create mode 100644 Public/Developer/System.Core/Headers/Defines.hxx create mode 100644 Public/Developer/System.Core/Headers/File.hxx create mode 100644 Public/Developer/System.Core/Headers/Heap.hxx create mode 100644 Public/Developer/System.Core/Headers/Hint.hxx create mode 100644 Public/Developer/System.Core/Headers/Thread.hxx create mode 100644 Public/Developer/System.Core/Headers/Window/Dialog.hxx create mode 100644 Public/Developer/System.Core/Headers/Window/Image.hxx create mode 100644 Public/Developer/System.Core/Headers/Window/Menu.hxx create mode 100644 Public/Developer/System.Core/Headers/Window/Rsrc.hxx create mode 100644 Public/Developer/System.Core/Headers/Window/TrueType.hxx create mode 100644 Public/Developer/System.Core/Headers/Window/Window.hxx (limited to 'Public/Developer/System.Core/Headers') diff --git a/Public/Developer/System.Core/Headers/Containers/ODF.hxx b/Public/Developer/System.Core/Headers/Containers/ODF.hxx new file mode 100644 index 00000000..266726bf --- /dev/null +++ b/Public/Developer/System.Core/Headers/Containers/ODF.hxx @@ -0,0 +1,41 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#ifndef __ODF__ +#define __ODF__ + +#include + +/** + * @brief Open Document Format + * @file ODF.hxx + */ + +/// @brief four-character code for ODF. +#define kFourCCLength_ODF 4 + +/// @brief Document file header. +typedef struct ODFFileHeader { + CharacterTypeUTF8 f_Ident[kFourCCLength_ODF]; + + Int32Type f_DocumentKind; + Int32Type f_DocumentSize; + + Int64Type f_MetaForkOffset; + Int64Type f_DocumentForkOffset; + + CharacterTypeUTF8 f_Padding[4]; +} PACKED ODFFileHeader; + +/// @brief ODF Fork header +typedef struct ODFForkHeader { + CharacterTypeUTF8 f_MetadataName[255]; + + Int32Type f_MetadataKind; + Int32Type f_MetadataSize; + + CharacterTypeUTF8 f_Padding; +} PACKED ODFForkHeader; + +#endif // !__ODF__ \ No newline at end of file diff --git a/Public/Developer/System.Core/Headers/Containers/XIFF.hxx b/Public/Developer/System.Core/Headers/Containers/XIFF.hxx new file mode 100644 index 00000000..11d286e9 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Containers/XIFF.hxx @@ -0,0 +1,57 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#ifndef __XIFF__ +#define __XIFF__ + +/** --------------------------------------------------- + + * THIS FILE CONTAINS CODE FOR THE eXtended Information File Format. + * XIFF is used to make setup programs/audio/video files. + +------------------------------------------------------- */ + +#include + +/// @brief four-character code for XIFF. +#define kFourCCLength_XIFF 4 +#define kXIFFNameLength 255 + +#define kXIFFContainerVideo "XVFF" +#define kXIFFContainerAudio "XAFF" +#define kXIFFContainerInstaller "XNFF" +#define kXIFFContainerGeneric "XIFF" +#define kXIFFContainerBinary "XBFF" + +/*** + * @brief Generic XIFF header + * Used by XIFF based containers. + */ + +struct PACKED XiffHeader final { + ByteType f_Magic[kFourCCLength_XIFF]; // XIFF string (includes \0) + DWordType f_Size; // overall size of header (XiffHeader) in bytes + DWordType f_FormatType; // format type. generic + ByteType f_SpecificMag[kFourCCLength_XIFF]; // The sub header magic + DWordType f_SpecificSize; // length of the format data + DWordType f_SpecificFormatType; // format type. generic +}; + +typedef struct XiffHeader XiffHeader; + +/// @brief XIFF metadata header, either located in forks or in file directly. +/// @author Amlal EL Mahrouss +struct ML_PACKED XiffMetadataHeader final { + ByteType f_Name[kXIFFNameLength]; + DWordType f_Flags; + DWordType f_Type; + QWordType f_Offset; + SizeType f_Size; +}; + +#define kXIFFStringMetadata4CC "strp" +#define kXIFFFontMetadata4CC "font" +#define kXIFFResourceMetadata4CC "resx" + +#endif // ifndef __XIFF__ diff --git a/Public/Developer/System.Core/Headers/Defines.hxx b/Public/Developer/System.Core/Headers/Defines.hxx new file mode 100644 index 00000000..867dac76 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Defines.hxx @@ -0,0 +1,250 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#ifndef __cplusplus +#error This API is meant to be used with C++. +#endif + +#ifdef CA_MUST_PASS +#undef CA_MUST_PASS +#endif + +#ifdef _DEBUG +#define CA_MUST_PASS(e) { if (!e) { __assert_chk_fail() } } +#else +#define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) +#endif + +#ifdef __cplusplus + +#define CA_EXTERN_C extern "C" + +#else + +#define CA_EXTERN_C extern + +#endif + +CA_EXTERN_C void __assert_chk_fail(void); + +#define CA_STDCALL __attribute__((stdcall)) +#define CA_CDECL __attribute__((cdecl)) +#define CA_MSCALL __attribute__((ms_abi)) + +#define PACKED __attribute__((packed)) + +#define CA_PASCAL CA_STDCALL + +typedef __UINT8_TYPE__ ByteType; +typedef __UINT16_TYPE__ WordType; +typedef __UINT32_TYPE__ DWordType; +typedef __UINT64_TYPE__ QWordType; +typedef __SIZE_TYPE__ SizeType; + +typedef char CharacterTypeUTF8; +typedef CharacterTypeUTF8* PtrCharacterType; + +typedef void* PtrVoidType; +typedef void VoidType; + +typedef __UINTPTR_TYPE__ UIntPtrType; +typedef __INTPTR_TYPE__ IntPtrType; +typedef __UINT64_TYPE__ UInt64Type; +typedef __INT64_TYPE__ Int64Type; +typedef __UINT32_TYPE__ UInt32Type; +typedef __INT32_TYPE__ Int32Type; + +typedef CharacterTypeUTF8 BooleanType; + +#define CA_COPY_DELETE(KLASS) \ + KLASS &operator=(const KLASS &) = delete; \ + KLASS(const KLASS &) = delete; + + +#define CA_COPY_DEFAULT(KLASS) \ + KLASS &operator=(const KLASS &) = default; \ + KLASS(const KLASS &) = default; + + +#define CA_MOVE_DELETE(KLASS) \ + KLASS &operator=(KLASS &&) = delete; \ + KLASS(KLASS &&) = delete; + + +#define CA_MOVE_DEFAULT(KLASS) \ + KLASS &operator=(KLASS &&) = default; \ + KLASS(KLASS &&) = default; + + +#define Yes 1 +#define No 0 + +#define CA_PTR * + +#define CA_FAR __far +#define CA_NEAR __near + +#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)e) + +#ifdef __x86_64__ +# define _M_AMD64 2 +#endif + +#ifdef __aarch64__ +# define _M_AARCH64 3 +#endif + +#ifdef __powerpc64__ +# define _M_PPC64 4 +#endif + +#ifdef __64x0__ +# define _M_64000 5 +#endif + +#ifdef __riscv__ +# define _M_RISCV 6 +#endif + +#define CA_STATIC static +#define CA_INLINE inline +#define CA_CONST const + +#ifdef __cplusplus +#define CA_CONSTEXPR constexpr +#else +#define CA_CONSTEXPR +#endif // __cplusplus + +enum HcProcessCall { + kProcessCallAllocPtr = 1, + kProcessCallFreePtr, + kProcessCallSizePtr, + kProcessCallCheckPtr, + kProcessCallAllocStack, + /// @brief Open a specific handle (can be used as sel to call methods related to it.) + kProcessCallOpenHandle, + kProcessCallCloseHandle, + /// @brief Number of process calls. + kProcessCallsCount = 7, +}; + +#include + +class SystemException { + public: + explicit SystemException() = default; + virtual ~SystemException() = default; + + public: + CA_COPY_DEFAULT(SystemException); + + public: + 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: + CA_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: + CA_COPY_DEFAULT(PointerException); + + public: + const char *Name() override { return "PointerException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{ + "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: + CA_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!"}; +}; + +#define kObjectGlobalNamespaceSystem "HCORE_ROOT\\" +#define kObjectGlobalNamespaceUser "HCORE_USER_ROOT\\" + +enum { + kObjectTypeProcess, + kObjectTypeFile, + kObjectTypeDevice, + kObjectTypeNetwork, + kObjectTypeInvalid, + KObjectTypeUserDefined = 0xCF, + kObjectTypeCount = 5, +}; + +/** + * @brief GUID type, something you can also find in CFKit. + * @author AMlal El Mahrouss + */ +typedef struct GUID final { + DWordType Data1; + WordType Data2; + WordType Data3; + ByteType Data4[8]; +} GUIDType, *PtrGUIDType; + +/// \brief Object handle. +/// \author Amlal El Mahrouss +typedef struct Object final { + CharacterTypeUTF8 ObjectName[255]; + DWordType ObjectType; + CharacterTypeUTF8 ObjectNamespace[255]; + + VoidType(*Release)(struct Object* Self); + IntPtrType(*Invoke)(struct Object* Self, DWordType Sel, ...); + VoidType(*Query)(struct Object* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); +} Object, *ObjectPtr; + +#define object_cast reinterpret_cast + +CA_EXTERN_C ObjectPtr HcGetInstanceObject(void); + +CA_INLINE ObjectPtr kApplicationObject; diff --git a/Public/Developer/System.Core/Headers/File.hxx b/Public/Developer/System.Core/Headers/File.hxx new file mode 100644 index 00000000..06c2a22e --- /dev/null +++ b/Public/Developer/System.Core/Headers/File.hxx @@ -0,0 +1,105 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifndef __FILE_API__ +#define __FILE_API__ + +#include + +namespace System { +class FileInterface; +class DirectoryInterface; + +typedef IntPtrType SymlinkType; +typedef IntPtrType FileType; +typedef IntPtrType DirectoryType; +typedef IntPtrType FSRef; + +enum { + kErrorNoSuchPath = -44, + kErrorNotAFile = -45, + kErrorNotADirectory = -46, + kErrorDirectory = -47, + kErrorBrokenSymlink = -48, +}; + +/// @brief System file interface + +class FileInterface final { + public: + explicit FileInterface(const char *path) { + mHandle = kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, + 0, path); + } + + ~FileInterface() { + kApplicationObject->Invoke(kApplicationObject, kProcessCallCloseHandle, 0, + mHandle); + } + + public: + CA_COPY_DEFAULT(FileInterface); + + public: + PtrVoidType Read(UIntPtrType off, SizeType sz) { + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 2, + off, sz); + } + PtrVoidType Read(SizeType sz) { + return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, 3, + sz); + } + + void Write(PtrVoidType buf, UIntPtrType off, SizeType sz) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 4, buf, off, sz); + } + void Write(PtrVoidType buf, SizeType sz) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 5, buf, sz); + } + + void Seek(UIntPtrType off) { + kApplicationObject->Invoke(kApplicationObject, mHandle, 5); + } + void Rewind() { kApplicationObject->Invoke(kApplicationObject, mHandle, 6); } + + public: + const char *MIME(); + void MIME(const char *mime); + + private: + FileType mHandle; +}; + +typedef FileInterface *FilePtr; + +/// @brief file exception +/// Throws when the file isn't found or invalid. +class FileException : public SystemException { + public: + explicit FileException() = default; + virtual ~FileException() = default; + + public: + CA_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!"}; +}; + +inline IntPtrType MakeSymlink(const char *from, const char *outputWhere) { + CA_MUST_PASS(from); + CA_MUST_PASS(outputWhere); + + return kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, 1, + from); +} +} // namespace System + +#endif // ifndef __FILE_API__ diff --git a/Public/Developer/System.Core/Headers/Heap.hxx b/Public/Developer/System.Core/Headers/Heap.hxx new file mode 100644 index 00000000..c134ca4e --- /dev/null +++ b/Public/Developer/System.Core/Headers/Heap.hxx @@ -0,0 +1,64 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +namespace System { +class HeapException; +class HeapInterface; + +typedef PtrVoidType PtrHeapType; + +enum { + kHeapExpandable = 2, + kHeapNoExecute = 4, + kHeapShared = 6, + kHeapReadOnly = 8, + kHeapNoFlags = 0 +}; + +class HeapInterface final { + private: + explicit HeapInterface(); + + public: + ~HeapInterface(); + + public: + CA_COPY_DEFAULT(HeapInterface); + + public: + static HeapInterface *Shared() noexcept; + + public: + void Delete(PtrHeapType me) noexcept; + SizeType Size(PtrHeapType me) noexcept; + PtrHeapType New(const SizeType &sz, + const DWordType 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: + CA_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 diff --git a/Public/Developer/System.Core/Headers/Hint.hxx b/Public/Developer/System.Core/Headers/Hint.hxx new file mode 100644 index 00000000..86faf455 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Hint.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/Developer/System.Core/Headers/Thread.hxx b/Public/Developer/System.Core/Headers/Thread.hxx new file mode 100644 index 00000000..df803860 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Thread.hxx @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD_API__ +#define __THREAD_API__ + +#include + +/// @brief Thread Information Block, which holds information about the running +/// thread. +typedef QWordType ThreadRef; + +/// @brief Main application thread. +CA_EXTERN_C ThreadRef kMainThread; + +#endif // __THREAD_API__ diff --git a/Public/Developer/System.Core/Headers/Window/Dialog.hxx b/Public/Developer/System.Core/Headers/Window/Dialog.hxx new file mode 100644 index 00000000..3e445532 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window/Dialog.hxx @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include diff --git a/Public/Developer/System.Core/Headers/Window/Image.hxx b/Public/Developer/System.Core/Headers/Window/Image.hxx new file mode 100644 index 00000000..2a02b434 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window/Image.hxx @@ -0,0 +1,8 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + diff --git a/Public/Developer/System.Core/Headers/Window/Menu.hxx b/Public/Developer/System.Core/Headers/Window/Menu.hxx new file mode 100644 index 00000000..2a02b434 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window/Menu.hxx @@ -0,0 +1,8 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + diff --git a/Public/Developer/System.Core/Headers/Window/Rsrc.hxx b/Public/Developer/System.Core/Headers/Window/Rsrc.hxx new file mode 100644 index 00000000..2a02b434 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window/Rsrc.hxx @@ -0,0 +1,8 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + diff --git a/Public/Developer/System.Core/Headers/Window/TrueType.hxx b/Public/Developer/System.Core/Headers/Window/TrueType.hxx new file mode 100644 index 00000000..62ed1255 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window/TrueType.hxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once diff --git a/Public/Developer/System.Core/Headers/Window/Window.hxx b/Public/Developer/System.Core/Headers/Window/Window.hxx new file mode 100644 index 00000000..1a8c6cf6 --- /dev/null +++ b/Public/Developer/System.Core/Headers/Window/Window.hxx @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include + +/// @file Window.hxx +/// @brief Tracker window manager. +/// @author Amlal El Mahrouss. + +typedef float PositionType; + +/// @brief A point, can represent the size, position of a window. +typedef struct _Point { + PositionType X, Y; +} Point; + +/// @brief Tracker Graphics port. +typedef struct _GraphicsPort { + WordType windowPort; + WordType windowKind; + BooleanType windowVisible; + BooleanType windowMaximized; + BooleanType windowMinimized; + BooleanType windowMoving; + BooleanType windowDisableClose; + BooleanType windowDisableMinimize; + Point windowPosition; + Point windowSize; + BooleanType windowInvalidate; + DWordType windowClearColor; + WordType menuPort; + WordType parentPort; +} GraphicsPort; -- cgit v1.2.3