From 8719b4570a2d10dd49a0d3a47e24f5c55bdda85e Mon Sep 17 00:00:00 2001 From: Amlal Date: Sun, 22 Sep 2024 17:46:11 +0200 Subject: :boom: A big refactor on the filesystem structure. Signed-off-by: Amlal --- dev/sci/ReadMe.md | 5 + dev/sci/makefile | 12 +++ dev/sci/sci.json | 21 +++++ dev/sci/sci_base.hxx | 233 ++++++++++++++++++++++++++++++++++++++++++++++ dev/sci/sci_err.hxx | 47 ++++++++++ dev/sci/sci_hint.hxx | 23 +++++ dev/sci/scm-design.drawio | 28 ++++++ dev/sci/source_deploy.xml | 9 ++ dev/sci/src/sci_base.cxx | 7 ++ dev/sci/xpcom_core.hxx | 85 +++++++++++++++++ dev/sci/xpcom_sms.idl | 34 +++++++ 11 files changed, 504 insertions(+) create mode 100644 dev/sci/ReadMe.md create mode 100644 dev/sci/makefile create mode 100644 dev/sci/sci.json create mode 100644 dev/sci/sci_base.hxx create mode 100644 dev/sci/sci_err.hxx create mode 100644 dev/sci/sci_hint.hxx create mode 100644 dev/sci/scm-design.drawio create mode 100644 dev/sci/source_deploy.xml create mode 100644 dev/sci/src/sci_base.cxx create mode 100644 dev/sci/xpcom_core.hxx create mode 100644 dev/sci/xpcom_sms.idl (limited to 'dev/sci') diff --git a/dev/sci/ReadMe.md b/dev/sci/ReadMe.md new file mode 100644 index 00000000..9978e56e --- /dev/null +++ b/dev/sci/ReadMe.md @@ -0,0 +1,5 @@ +# ZKA's SCI. + +System Call and Component Interface, used maninly to communicate with Kernel and registered objects. + +###### (c) ZKA Technologies, all rights reserved. diff --git a/dev/sci/makefile b/dev/sci/makefile new file mode 100644 index 00000000..05593216 --- /dev/null +++ b/dev/sci/makefile @@ -0,0 +1,12 @@ +###################### +# (C) ZKA +# XPCOM/SCI kit makefile. +###################### + +CC=g++ +FLAGS=-I../ -shared -fPIC -D__ZKA_SYMS__ +OUTPUT=sci.dll + +.PHONY: build-sci +build-sci: + $(CC) $(wildcard *.cxx) $(FLAGS) -o $(OUTPUT) diff --git a/dev/sci/sci.json b/dev/sci/sci.json new file mode 100644 index 00000000..32a9238b --- /dev/null +++ b/dev/sci/sci.json @@ -0,0 +1,21 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++", + "compiler_std": "c++20", + "headers_path": ["../"], + "sources_path": ["src/*.cxx"], + "output_name": "sci.dll", + "compiler_flags": [ + "-fPIC", + "-ffreestanding", + "-shared", + "-fno-rtti", + "-fno-exceptions", + "-Wl,--subsystem=17" + ], + "cpp_macros": [ + "__SCI_IMPL__", + "cSCIVersion=0x0100", + "cSCIVersionHighest=0x0100", + "cSCIVersionLowest=0x0100" + ] +} diff --git a/dev/sci/sci_base.hxx b/dev/sci/sci_base.hxx new file mode 100644 index 00000000..0bdbb2eb --- /dev/null +++ b/dev/sci/sci_base.hxx @@ -0,0 +1,233 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies. + +File: SCIBase.hxx +Purpose: sci/M core header file (C++) + +------------------------------------------- */ + +#ifndef __SCI_BASE_HXX__ +#define __SCI_BASE_HXX__ + +#include + +#define IMPORT_CXX extern "C++" +#define IMPORT_C extern "C" + +typedef bool Bool; +typedef void UInt0; + +typedef __UINT64_TYPE__ UInt64; +typedef __UINT32_TYPE__ UInt32; +typedef __UINT16_TYPE__ UInt16; +typedef __UINT8_TYPE__ UInt8; + +typedef __SIZE_TYPE__ SizeT; + +typedef __INT64_TYPE__ SInt64; +typedef __INT32_TYPE__ SInt32; +typedef __INT16_TYPE__ SInt16; +typedef __INT8_TYPE__ SInt8; + +typedef void* VoidPtr; +typedef __UINTPTR_TYPE__ UIntPtr; +typedef char Char; + +#include + +#ifdef __SCI_IMPL__ +#include +#else +class IUnknown; // Refrenced from an IDB entry. +class UnknownUCLSID; // From the IDB, the constructor of the object, e.g: WordUCLSID. +class UUID; + +/// @brief Allocate new XPCOM class. +/// @tparam TCLS +/// @tparam UCLSID +/// @param uclsidOfCls +/// @return +template +TCLS* XPCOMQueryInterface(UCLSID uclsidOfCls, Args... args); + +template +SInt32 XPCOMReleaseClass(TCLS** cls); + +/// @brief Release XPCOM class. +/// @tparam TCLS +/// @param cls +/// @return +template +SInt32 RtlReleaseClass(TCLS* cls); + +class __attribute__((uuid("d7c144b6-0792-44b8-b06b-02b227b547df"))) IUnknown +{ +public: + explicit IUnknown() = default; + virtual ~IUnknown() = default; + + IUnknown& operator=(const IUnknown&) = default; + IUnknown(const IUnknown&) = default; + + virtual SInt32 Release() = 0; + virtual void RemoveRef() = 0; + virtual IUnknown* AddRef() = 0; + virtual VoidPtr QueryInterface(UUID* p_uuid) = 0; +}; + +template +class IEventListener : public ClsID +{ +public: + explicit IEventListener() = default; + virtual ~IEventListener() = default; + + IEventListener& operator=(const IEventListener&) = default; + IEventListener(const IEventListener&) = default; + + virtual IEventListener& operator+=(FnSign arg) = 0; +}; +#endif + +// ------------------------------------------------------------------------------------------ // +/// @note Handle types. +// ------------------------------------------------------------------------------------------ // + +typedef VoidPtr ZKAObject; + +typedef ZKAObject ZKADLLObject; +typedef ZKAObject ZKAIOObject; +typedef ZKAObject ZKASCMObject; +typedef ZKAObject ZKAThreadObject; +typedef ZKAObject ZKASocketObject; + +// ------------------------------------------------------------------------------------------ // + +// ------------------------------------------------------------------------------------------ // +/// @note Part of ZKA loader API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Get function which is part of the DLL. +/// @param symbol the symbol to look for +/// @param dll_handle the DLL handle. +/// @return the proc pointer. +IMPORT_C ZKAObject LdrGetDLLProc(_Input const Char* symbol, _Input ZKAObject dll_handle); + +/// @brief Open DLL handle. +/// @param path +/// @param drv +/// @return +IMPORT_C ZKAObject LdrOpenDLL(_Input const Char* path, _Input const Char* drive_letter); + +/// @brief Close DLL handle +/// @param dll_handle +/// @return +IMPORT_C UInt0 LdrCloseDLL(_Input ZKAObject dll_handle); + +// ------------------------------------------------------------------------------------------ // +// File API. +// ------------------------------------------------------------------------------------------ // + +/// @brief Opens a file from a drive. +/// @param fs_path the filesystem path. +/// @param drive_letter drive name, use NULL to use default one. +/// @return the file descriptor of the file. +IMPORT_C ZKAObject IoOpenFile(const Char* fs_path, const Char* drive_letter); + +/// @brief Closes a file and flushes its content. +/// @param file_desc the file descriptor. +/// @return void. +IMPORT_C UInt0 IoCloseFile(_Input ZKAObject file_desc); + +IMPORT_C UInt32 IoWriteFile(_Input ZKAObject file_desc, _Output VoidPtr out_data, SizeT sz_data); + +IMPORT_C UInt32 IoReadFile(_Input ZKAObject file_desc, _Output VoidPtr* out_data, SizeT sz_data); + +IMPORT_C UInt64 IoRewindFile(_Input ZKAObject file_desc); + +IMPORT_C UInt64 IoTellFile(_Input ZKAObject file_desc); + +IMPORT_C UInt64 IoSeekFile(_Input ZKAObject file_desc, UInt64 file_offset); + +// ------------------------------------------------------------------------ +// TLS API. +// ------------------------------------------------------------------------ + +/// @brief Installs the Thread Information Block and Global Information Block inside the current process. +/// @param void. +/// @return > 0 error ocurred or already present, = 0 success. +IMPORT_C UInt32 TlsInstall(UInt0); + +// ------------------------------------------------------------------------ +// XPCOM API. +// ------------------------------------------------------------------------ + +/// @brief Allocate new XPCOM object. +/// @tparam TCLS the class type. +/// @tparam UCLSID UCLS factory class type. +/// @param uclsidOfCls UCLS factory class +/// @return TCLS interface +template +TCLS* XPCOMQueryInterface(_Input UCLSID* uclsidOfCls, _Input Args&&... args); + +/// @brief Release XPCOM object. +/// @tparam TCLS the class type. +/// @param cls the class to release. +/// @return status code. +template +SInt32 XPCOMReleaseClass(_Input TCLS* cls); + +/// @brief Creates an XPCOM instance in the process. +/// @param handle_instance the XPCOM handle. +/// @param flags the XPCOM flags. +IMPORT_C SInt32 XPCOMCreateInstance(_Input UInt32 flags, _Output ZKAObject* handle_instance); + +/// @brief Destroys an XPCOM instance of the process. +/// @param handle_instance the XPCOM handle. +IMPORT_C UInt0 XPCOMDestroyInstance(_Input ZKAObject handle_instance); + +// ------------------------------------------------------------------------ +// Memory Management API. +// ------------------------------------------------------------------------ + +/// @brief Creates a new heap from the process's address space. +/// @param len the length of it. +/// @param flags the flags of it. +/// @return heap pointer. +IMPORT_C VoidPtr MmCreateHeap(_Input SizeT len, _Input UInt32 flags); + +/// @brief Destroys the pointer +/// @param heap the heap itself. +/// @return void. +IMPORT_C UInt0 MmDestroyHeap(_Input VoidPtr heap); + +/// @brief Change protection flags of memory region. +IMPORT_C UInt32 MmChangeHeapFlags(_Input VoidPtr heap, _Input UInt32 flags); + +/// @brief Fill memory region with CRC32. +IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap); + +// ------------------------------------------------------------------------ +// Error handling API. +// ------------------------------------------------------------------------ + +IMPORT_C SInt32 ErrGetLastError(UInt0); + +// ------------------------------------------------------------------------ +// Threading API. +// ------------------------------------------------------------------------ + +IMPORT_C UInt0 ThrExitCurrentThread(_Input SInt32 exit_code); +IMPORT_C UInt0 ThrExitMainThread(_Input SInt32 exit_code); + +IMPORT_C UInt0 ThrExitYieldThread(UInt0); + +IMPORT_C UInt0 ThrExitJoinThread(UInt0); +IMPORT_C UInt0 ThrExitDetachThread(UInt0); + +// ------------------------------------------------------------------------ +// Drive Management API. +// ------------------------------------------------------------------------ + +#endif // ifndef __SCI_BASE_HXX__ diff --git a/dev/sci/sci_err.hxx b/dev/sci/sci_err.hxx new file mode 100644 index 00000000..a1e56dfd --- /dev/null +++ b/dev/sci/sci_err.hxx @@ -0,0 +1,47 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#define ErrLocalIsOk() (kLastError == kErrorSuccess) +#define ErrLocalFailed() (kLastError != kErrorSuccess) +#define ErrLocal() (kLastError) + +typedef SInt32 ZKAErr; + +inline constexpr ZKAErr kErrorSuccess = 0; +inline constexpr ZKAErr kErrorExecutable = 33; +inline constexpr ZKAErr kErrorExecutableLib = 34; +inline constexpr ZKAErr kErrorFileNotFound = 35; +inline constexpr ZKAErr kErrorDirectoryNotFound = 36; +inline constexpr ZKAErr kErrorDiskReadOnly = 37; +inline constexpr ZKAErr kErrorDiskIsFull = 38; +inline constexpr ZKAErr kErrorProcessFault = 39; +inline constexpr ZKAErr kErrorSocketHangUp = 40; +inline constexpr ZKAErr kErrorThreadLocalStorage = 41; +inline constexpr ZKAErr kErrorMath = 42; +inline constexpr ZKAErr kErrorNoNetwork = 43; +inline constexpr ZKAErr kErrorHeapOutOfMemory = 44; +inline constexpr ZKAErr kErrorNoSuchDisk = 45; +inline constexpr ZKAErr kErrorFileExists = 46; +inline constexpr ZKAErr kErrorFormatFailed = 47; +inline constexpr ZKAErr kErrorNetworkTimeout = 48; +inline constexpr ZKAErr kErrorInternal = 49; +inline constexpr ZKAErr kErrorForkAlreadyExists = 50; +inline constexpr ZKAErr kErrorOutOfTeamSlot = 51; +inline constexpr ZKAErr kErrorHeapNotPresent = 52; +inline constexpr ZKAErr kErrorNoEntrypoint = 53; +inline constexpr ZKAErr kErrorDiskIsCorrupted = 54; +inline constexpr ZKAErr kErrorDisk = 55; +inline constexpr ZKAErr kErrorInvalidData = 56; +inline constexpr ZKAErr kErrorAsync = 57; +inline constexpr ZKAErr kErrorNonBlocking = 58; +inline constexpr ZKAErr kErrorIPC = 59; +inline constexpr ZKAErr kErrorSign = 60; +inline constexpr ZKAErr kErrorInvalidCreds = 61; +inline constexpr ZKAErr kErrorUnimplemented = 0; + +IMPORT_C ZKAErr kLastError; diff --git a/dev/sci/sci_hint.hxx b/dev/sci/sci_hint.hxx new file mode 100644 index 00000000..c785f953 --- /dev/null +++ b/dev/sci/sci_hint.hxx @@ -0,0 +1,23 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __SCI_HINT_HXX__ +#define __SCI_HINT_HXX__ + +#pragma compiler(hint_manifest) + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut + +#endif // ifndef __SCI_HINT_HXX__ diff --git a/dev/sci/scm-design.drawio b/dev/sci/scm-design.drawio new file mode 100644 index 00000000..22bcace6 --- /dev/null +++ b/dev/sci/scm-design.drawio @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/sci/source_deploy.xml b/dev/sci/source_deploy.xml new file mode 100644 index 00000000..a392015c --- /dev/null +++ b/dev/sci/source_deploy.xml @@ -0,0 +1,9 @@ + + + src/*.cxx + *.drawio + *.hxx + *.inl + *.idl + + diff --git a/dev/sci/src/sci_base.cxx b/dev/sci/src/sci_base.cxx new file mode 100644 index 00000000..d2897cb3 --- /dev/null +++ b/dev/sci/src/sci_base.cxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include diff --git a/dev/sci/xpcom_core.hxx b/dev/sci/xpcom_core.hxx new file mode 100644 index 00000000..63bcf403 --- /dev/null +++ b/dev/sci/xpcom_core.hxx @@ -0,0 +1,85 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies. + +File: rt.internal.inl +Purpose: Base code of XPCOM. + +------------------------------------------- */ + +/// @internal + +#ifndef __NDK__ +#define object class +#define protocol class +#define clsid(X) + +#warning ! You may be using the clang version of the ZKAKit, please be cautious that some features mayn't be present. ! +#endif // !__NDK__ + +protocol IUnknown; // Refrenced from an IDB entry. +protocol UnknownUCLSID; // From the IDB, the constructor of the object, e.g: TextUCLSID. +object UUID; + +/// @brief Unknown XPCOM interface +protocol clsid("d7c144b6-0792-44b8-b06b-02b227b547df") IUnknown +{ +public: + explicit IUnknown() = default; + virtual ~IUnknown() = default; + + IUnknown& operator=(const IUnknown&) = default; + IUnknown(const IUnknown&) = default; + + virtual SInt32 Release() = 0; + virtual void RemoveRef() = 0; + virtual IUnknown* AddRef() = 0; + virtual VoidPtr QueryInterface(UUID * p_uuid) = 0; +}; + +/// @brief Allocate new XPCOM object. +/// @tparam TCLS the class type. +/// @tparam UCLSID UCLS factory class type. +/// @param uclsidOfCls UCLS factory class +/// @return TCLS interface +template +inline TCLS* XPCOMQueryInterface(UCLSID* uclsidOfCls, Args&&... args) +{ + uclsidOfCls->AddRef(); + return uclsidOfCls->QueryInterfaceWithArgs(args...); +} + +/// @brief Release XPCOM object. +/// @tparam TCLS the class type. +/// @param cls the class to release. +/// @return status code. +template +inline SInt32 XPCOMReleaseClass(TCLS** cls) +{ + if (!cls) + return -1; + + cls->RemoveRef(); + cls->Release(); + + cls = nullptr; + + return 0; +} + +template +protocol IEventListener : public ClsID +{ +public: + explicit IEventListener() = default; + virtual ~IEventListener() = default; + + IEventListener& operator=(const IEventListener&) = default; + IEventListener(const IEventListener&) = default; + + virtual IEventListener& operator+=(FnSign arg) + { + this->AddEventListener(arg); + return *this; + } +}; diff --git a/dev/sci/xpcom_sms.idl b/dev/sci/xpcom_sms.idl new file mode 100644 index 00000000..ae37d285 --- /dev/null +++ b/dev/sci/xpcom_sms.idl @@ -0,0 +1,34 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies. + +File: rt.internal.inl +Purpose: Base code of XPCOM. + +------------------------------------------- */ + +/// @internal + +#ifndef __NDK__ +#define object class +#define protocol class +#define interface private +#define interface_method +#define CONST const +#define CHAR char +#define INT32 __INT32_TYPE__ +#define SIZE_T __SIZE_TYPE__ +#define _Output +#define _Input +#define clsid(X) + +#warning ! You may be using the clang version of the ZKAKit, please be cautious that some features mayn't be present. ! +#endif // !__NDK__ + +clsid("0943A614-0201-4107-8F8D-E909DF7F53C9") +protocol ISMS +{ +interface: + interface_method INT32 SendMessage(_Input CONST CHAR* bytes, _Input SIZE_T bytes_size); + interface_method INT32 RecvMessage(_Output CONST CHAR** bytes_in, _Input SIZE_T bytes_size); +}; -- cgit v1.2.3