From da70596895d8135e08f8caac6978117697b4c021 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 18 Aug 2024 21:39:29 +0200 Subject: [REFACTOR] Improved project structure. Signed-off-by: Amlal El Mahrouss --- dev/SCI/Hint.hxx | 23 ++++++ dev/SCI/ReadMe.md | 3 + dev/SCI/SCIBase.cxx | 7 ++ dev/SCI/SCIBase.hxx | 185 ++++++++++++++++++++++++++++++++++++++++++++++ dev/SCI/SCIErr.cxx | 9 +++ dev/SCI/SCIErr.hxx | 49 ++++++++++++ dev/SCI/SCM.drawio | 28 +++++++ dev/SCI/build.json | 10 +++ dev/SCI/compile_flags.txt | 4 + dev/SCI/makefile | 12 +++ dev/SCI/scm.idlparser.inl | 21 ++++++ dev/SCI/scm.internal.inl | 84 +++++++++++++++++++++ dev/SCI/source_deploy.xml | 7 ++ 13 files changed, 442 insertions(+) create mode 100644 dev/SCI/Hint.hxx create mode 100644 dev/SCI/ReadMe.md create mode 100644 dev/SCI/SCIBase.cxx create mode 100644 dev/SCI/SCIBase.hxx create mode 100644 dev/SCI/SCIErr.cxx create mode 100644 dev/SCI/SCIErr.hxx create mode 100644 dev/SCI/SCM.drawio create mode 100644 dev/SCI/build.json create mode 100644 dev/SCI/compile_flags.txt create mode 100644 dev/SCI/makefile create mode 100644 dev/SCI/scm.idlparser.inl create mode 100644 dev/SCI/scm.internal.inl create mode 100644 dev/SCI/source_deploy.xml (limited to 'dev/SCI') diff --git a/dev/SCI/Hint.hxx b/dev/SCI/Hint.hxx new file mode 100644 index 00000000..c785f953 --- /dev/null +++ b/dev/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/ReadMe.md b/dev/SCI/ReadMe.md new file mode 100644 index 00000000..b5f76a9f --- /dev/null +++ b/dev/SCI/ReadMe.md @@ -0,0 +1,3 @@ +# Official SCM implementation for New OS + +Read the specs for + information... \ No newline at end of file diff --git a/dev/SCI/SCIBase.cxx b/dev/SCI/SCIBase.cxx new file mode 100644 index 00000000..628bfd67 --- /dev/null +++ b/dev/SCI/SCIBase.cxx @@ -0,0 +1,7 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include \ No newline at end of file diff --git a/dev/SCI/SCIBase.hxx b/dev/SCI/SCIBase.hxx new file mode 100644 index 00000000..b902b5fa --- /dev/null +++ b/dev/SCI/SCIBase.hxx @@ -0,0 +1,185 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies. + +File: SCIBase.hxx +Purpose: SCI/M core header file (C++) + +------------------------------------------- */ + +#ifndef __SCI_BASE_HXX__ +#define __SCI_BASE_HXX__ + +#ifdef __cplusplus + +#include + +#define IMPORT_CXX extern "C++" +#define IMPORT_C extern "C" + +#define OBJECT_PATH "::\\" + +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; + +#ifdef __SCI_IMPL__ +#include +#else +class UnknownInterface; // Refrenced from an IDB entry. +class UnknownUCLSID; // From the IDB, the constructor of the object, e.g: WordUCLSID. +class UUID; + +/// @brief Allocate new SCM class. +/// @tparam TCLS +/// @tparam UCLSID +/// @param uclsidOfCls +/// @return +template +TCLS* RtlQueryInterface(UCLSID uclsidOfCls, Args... args); + +/// @brief Release SCM class. +/// @tparam TCLS +/// @param cls +/// @return +template +SInt32 RtlReleaseClass(TCLS* cls); + +class __attribute__((uuid("d7c144b6-0792-44b8-b06b-02b227b547df"))) UnknownInterface +{ +public: + explicit UnknownInterface() = default; + virtual ~UnknownInterface() = default; + + UnknownInterface& operator=(const UnknownInterface&) = default; + UnknownInterface(const UnknownInterface&) = default; + + virtual SInt32 Release() = 0; + virtual void RemoveRef() = 0; + virtual UnknownInterface* AddRef() = 0; + virtual VoidPtr QueryInterface(UUID* p_uuid) = 0; +}; + +template +class EventListenerInterface final : public ClsID +{ +public: + explicit EventListenerInterface() = default; + virtual ~EventListenerInterface() = default; + + EventListenerInterface& operator=(const EventListenerInterface&) = default; + EventListenerInterface(const EventListenerInterface&) = default; + + virtual EventListenerInterface& operator +=(FnSign arg) = 0; +}; +#endif + +// ------------------------------------------------------------------------------------------ // +/// @note Handle types. +// ------------------------------------------------------------------------------------------ // + +typedef VoidPtr NEW_OBJECT; + +typedef NEW_OBJECT DLL_OBJECT; +typedef NEW_OBJECT IO_OBJECT; +typedef NEW_OBJECT COMP_OBJECT; + +// ------------------------------------------------------------------------------------------ // + +// ------------------------------------------------------------------------------------------ // +/// @note Part of NK 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 VoidPtr RtlGetDLLProc(_Input const Char* symbol, _Input NEW_OBJECT dll_handle); + +/// @brief Open DLL handle. +/// @param path +/// @param drv +/// @return +IMPORT_C NEW_OBJECT RtlOpenDLL(_Input const Char* path, _Input const Char* drive_letter); + +/// @brief Close DLL handle +/// @param dll_handle +/// @return +IMPORT_C UInt0 RtlCloseDLL(_Input NEW_OBJECT dll_handle); + +/// @note Part of NK 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 NEW_OBJECT RtlOpenFile(const Char* fs_path, const Char* drive_letter); + +/// @brief Closes a file and flushes its content. +/// @param file_desc the file descriptor. +/// @return +IMPORT_C UInt0 RtlCloseFile(_Input NEW_OBJECT file_desc); + +/// @brief Installs the TIB and GIB inside the current process. +/// @param none +/// @return > 0 error ocurred or already present, = 0 success. +IMPORT_C UInt32 RtlInstallInfoBlocks(UInt0); + +/// @brief Allocate new SCM object. +/// @tparam TCLS the class type. +/// @tparam UCLSID UCLS factory class type. +/// @param uclsidOfCls UCLS factory class +/// @return TCLS interface +template +TCLS* ScmQueryInterface(_Input UCLSID* uclsidOfCls, _Input Args&&... args); + +/// @brief Release SCM object. +/// @tparam TCLS the class type. +/// @param cls the class to release. +/// @return status code. +template +SInt32 ScmReleaseClass(_Input TCLS* cls); + +/// @brief Creates an SCM instance in the process. +/// @param handle_instance the SCM handle. +/// @param flags the SCM flags. +SInt32 ScmCreateInstance(_Input UInt32 flags, _Output VoidPtr* handle_instance); + +/// @brief Destroys an SCM instance of the process. +/// @param handle_instance the SCM handle. +UInt0 ScmDestroyInstance(_Input VoidPtr handle_instance); + +/// @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. +VoidPtr RtlCreateHeap(_Input SizeT len, _Input UInt32 flags); + +/// @brief Destroys the pointer +/// @param heap the heap itself. +/// @return void. +UInt0 RtlDestroyHeap(_Input VoidPtr heap); + +#else + +#include + +#endif // ifdef __cplusplus + +#endif // ifndef __SCI_BASE_HXX__ \ No newline at end of file diff --git a/dev/SCI/SCIErr.cxx b/dev/SCI/SCIErr.cxx new file mode 100644 index 00000000..b0766944 --- /dev/null +++ b/dev/SCI/SCIErr.cxx @@ -0,0 +1,9 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include + +NEW_ERROR_TYPE kLastError = 0; \ No newline at end of file diff --git a/dev/SCI/SCIErr.hxx b/dev/SCI/SCIErr.hxx new file mode 100644 index 00000000..aa3e72e4 --- /dev/null +++ b/dev/SCI/SCIErr.hxx @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include + +#define ErrLocalIsOk() (kLastError == kErrorSuccess) +#define ErrLocalFailed() (kLastError != kErrorSuccess) +#define ErrLocal() (kLastError) + +typedef SInt32 NEW_ERROR_TYPE; + +inline constexpr NEW_ERROR_TYPE kErrorSuccess = 0; +inline constexpr NEW_ERROR_TYPE kErrorExecutable = 33; +inline constexpr NEW_ERROR_TYPE kErrorExecutableLib = 34; +inline constexpr NEW_ERROR_TYPE kErrorFileNotFound = 35; +inline constexpr NEW_ERROR_TYPE kErrorDirectoryNotFound = 36; +inline constexpr NEW_ERROR_TYPE kErrorDiskReadOnly = 37; +inline constexpr NEW_ERROR_TYPE kErrorDiskIsFull = 38; +inline constexpr NEW_ERROR_TYPE kErrorProcessFault = 39; +inline constexpr NEW_ERROR_TYPE kErrorSocketHangUp = 40; +inline constexpr NEW_ERROR_TYPE kErrorThreadLocalStorage = 41; +inline constexpr NEW_ERROR_TYPE kErrorMath = 42; +inline constexpr NEW_ERROR_TYPE kErrorNoNetwork = 43; +inline constexpr NEW_ERROR_TYPE kErrorHeapOutOfMemory = 44; +inline constexpr NEW_ERROR_TYPE kErrorNoSuchDisk = 45; +inline constexpr NEW_ERROR_TYPE kErrorFileExists = 46; +inline constexpr NEW_ERROR_TYPE kErrorFormatFailed = 47; +inline constexpr NEW_ERROR_TYPE kErrorNetworkTimeout = 48; +inline constexpr NEW_ERROR_TYPE kErrorInternal = 49; +inline constexpr NEW_ERROR_TYPE kErrorForkAlreadyExists = 50; +inline constexpr NEW_ERROR_TYPE kErrorOutOfTeamSlot = 51; +inline constexpr NEW_ERROR_TYPE kErrorHeapNotPresent = 52; +inline constexpr NEW_ERROR_TYPE kErrorNoEntrypoint = 53; +inline constexpr NEW_ERROR_TYPE kErrorDiskIsCorrupted = 54; +inline constexpr NEW_ERROR_TYPE kErrorDisk = 55; +inline constexpr NEW_ERROR_TYPE kErrorInvalidData = 56; +inline constexpr NEW_ERROR_TYPE kErrorAsync = 57; +inline constexpr NEW_ERROR_TYPE kErrorNonBlocking = 58; +inline constexpr NEW_ERROR_TYPE kErrorIPC = 59; +inline constexpr NEW_ERROR_TYPE kErrorSign = 60; +inline constexpr NEW_ERROR_TYPE kErrorInvalidCreds = 61; +inline constexpr NEW_ERROR_TYPE kErrorUnimplemented = 0; + +IMPORT_C NEW_ERROR_TYPE kLastError; diff --git a/dev/SCI/SCM.drawio b/dev/SCI/SCM.drawio new file mode 100644 index 00000000..403d6642 --- /dev/null +++ b/dev/SCI/SCM.drawio @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/dev/SCI/build.json b/dev/SCI/build.json new file mode 100644 index 00000000..9bc72bfa --- /dev/null +++ b/dev/SCI/build.json @@ -0,0 +1,10 @@ +{ + "compiler_path": "x86_64-w64-mingw32-g++.exe", + "compiler_std": "c++20", + "headers_path": ["../"], + "sources_path": ["*.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"] + } + \ No newline at end of file diff --git a/dev/SCI/compile_flags.txt b/dev/SCI/compile_flags.txt new file mode 100644 index 00000000..509e3eed --- /dev/null +++ b/dev/SCI/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../Kernel +-I../ +-std=c++20 diff --git a/dev/SCI/makefile b/dev/SCI/makefile new file mode 100644 index 00000000..63753422 --- /dev/null +++ b/dev/SCI/makefile @@ -0,0 +1,12 @@ +###################### +# (C) ZKA +# SCM/SCI kit makefile. +###################### + +CC=g++ +FLAGS=-I../ -shared -fPIC -D__NEWOS_SYMS__ +OUTPUT=sci.dll + +.PHONY: build-sci +build-sci: + $(CC) $(wildcard *.cxx) $(FLAGS) -o $(OUTPUT) \ No newline at end of file diff --git a/dev/SCI/scm.idlparser.inl b/dev/SCI/scm.idlparser.inl new file mode 100644 index 00000000..6189eab6 --- /dev/null +++ b/dev/SCI/scm.idlparser.inl @@ -0,0 +1,21 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies. + +File: rt.internal.inl +Purpose: Base code of SCM. + +------------------------------------------- */ + +/// @internal + +#ifndef __NDK__ +#define object class +#define protocol class +#define clsid(X) __attribute__((uuid(X))) + +#warning ! you may be using the clang version of the newos kit, please be cautious that some thing mayn't be present. ! +#endif // !__NDK__ + +protocol IDLParserInterface; +protocol IDLInterface; \ No newline at end of file diff --git a/dev/SCI/scm.internal.inl b/dev/SCI/scm.internal.inl new file mode 100644 index 00000000..8a5a85fa --- /dev/null +++ b/dev/SCI/scm.internal.inl @@ -0,0 +1,84 @@ +/* ------------------------------------------- + +Copyright ZKA Technologies. + +File: rt.internal.inl +Purpose: Base code of SCM. + +------------------------------------------- */ + +/// @internal + +#ifndef __NDK__ +#define object class +#define protocol class +#define clsid(X) __attribute__((uuid(X))) + +#warning ! you may be using the clang version of the newos kit, please be cautious that some thing mayn't be present. ! +#endif // !__NDK__ + +// Interfaces are divided between classes. +// So that they aren't too big. + +protocol UnknownInterface; // Refrenced from an IDB entry. +class UnknownUCLSID; // From the IDB, the constructor of the object, e.g: TextUCLSID. +object UUID; + +protocol clsid("d7c144b6-0792-44b8-b06b-02b227b547df") UnknownInterface +{ +public: + explicit UnknownInterface() = default; + virtual ~UnknownInterface() = default; + + UnknownInterface& operator=(const UnknownInterface&) = default; + UnknownInterface(const UnknownInterface&) = default; + + virtual SInt32 Release() = 0; + virtual void RemoveRef() = 0; + virtual UnknownInterface* AddRef() = 0; + virtual VoidPtr QueryInterface(UUID* p_uuid) = 0; +}; + +/// @brief Allocate new SCM object. +/// @tparam TCLS the class type. +/// @tparam UCLSID UCLS factory class type. +/// @param uclsidOfCls UCLS factory class +/// @return TCLS interface +template +inline TCLS* ScmQueryInterface(UCLSID* uclsidOfCls, Args&&... args) +{ + return uclsidOfCls->QueryInterfaceWithArgs(args...); +} + +/// @brief Release SCM object. +/// @tparam TCLS the class type. +/// @param cls the class to release. +/// @return status code. +template +inline SInt32 ScmReleaseClass(TCLS* cls) +{ + if (!cls) + return -1; + + cls->DecrementRef(); + cls->Release(); + + return 0; +} + +template +protocol EventListenerInterface final : public ClsID +{ +public: + explicit EventListenerInterface() = default; + virtual ~EventListenerInterface() = default; + + EventListenerInterface& operator=(const EventListenerInterface&) = default; + EventListenerInterface(const EventListenerInterface&) = default; + + virtual EventListenerInterface& operator +=(FnSign arg) + { + this->AddEventListener(arg); + return *this; + } +}; diff --git a/dev/SCI/source_deploy.xml b/dev/SCI/source_deploy.xml new file mode 100644 index 00000000..7873c49f --- /dev/null +++ b/dev/SCI/source_deploy.xml @@ -0,0 +1,7 @@ + + + *.cxx + *.drawio + *.internal.inl + + -- cgit v1.2.3