summaryrefslogtreecommitdiffhomepage
path: root/dev/sci
diff options
context:
space:
mode:
Diffstat (limited to 'dev/sci')
-rw-r--r--dev/sci/ReadMe.md5
-rw-r--r--dev/sci/makefile12
-rw-r--r--dev/sci/sci.json21
-rw-r--r--dev/sci/sci_base.hxx233
-rw-r--r--dev/sci/sci_err.hxx47
-rw-r--r--dev/sci/sci_hint.hxx23
-rw-r--r--dev/sci/scm-design.drawio28
-rw-r--r--dev/sci/source_deploy.xml9
-rw-r--r--dev/sci/src/sci_base.cxx7
-rw-r--r--dev/sci/xpcom_core.hxx85
-rw-r--r--dev/sci/xpcom_sms.idl34
11 files changed, 504 insertions, 0 deletions
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 <sci/sci_hint.hxx>
+
+#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 <sci/sci_err.hxx>
+
+#ifdef __SCI_IMPL__
+#include <sci/xpcom_core.hxx>
+#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 <typename TCLS, typename UCLSID, typename... Args>
+TCLS* XPCOMQueryInterface(UCLSID uclsidOfCls, Args... args);
+
+template <typename TCLS>
+SInt32 XPCOMReleaseClass(TCLS** cls);
+
+/// @brief Release XPCOM class.
+/// @tparam TCLS
+/// @param cls
+/// @return
+template <typename TCLS>
+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 <typename FnSign, typename ClsID>
+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 <typename TCLS, typename UCLSID, typename... Args>
+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 <typename TCLS>
+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 @@
+<mxfile host="65bd71144e">
+ <diagram name="Page-1" id="_vc7fxBdNKI2W8YhI8VA">
+ <mxGraphModel dx="774" dy="581" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
+ <root>
+ <mxCell id="0"/>
+ <mxCell id="1" parent="0"/>
+ <mxCell id="eRehIIeIVOPW1y23kRkx-9" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="eRehIIeIVOPW1y23kRkx-2" target="eRehIIeIVOPW1y23kRkx-8" edge="1">
+ <mxGeometry relative="1" as="geometry"/>
+ </mxCell>
+ <mxCell id="eRehIIeIVOPW1y23kRkx-2" value="User level interfaces and events." style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
+ <mxGeometry x="200" y="450" width="226" height="60" as="geometry"/>
+ </mxCell>
+ <mxCell id="eRehIIeIVOPW1y23kRkx-4" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;" parent="1" source="eRehIIeIVOPW1y23kRkx-3" target="eRehIIeIVOPW1y23kRkx-2" edge="1">
+ <mxGeometry relative="1" as="geometry"/>
+ </mxCell>
+ <mxCell id="eRehIIeIVOPW1y23kRkx-3" value="IDB" style="shape=cylinder3;whiteSpace=wrap;html=1;boundedLbl=1;backgroundOutline=1;size=15;" parent="1" vertex="1">
+ <mxGeometry x="283" y="290" width="60" height="80" as="geometry"/>
+ </mxCell>
+ <mxCell id="eRehIIeIVOPW1y23kRkx-8" value="Program #2&lt;div&gt;Is a web browser, it uses an HTML parser component.&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
+ <mxGeometry x="253" y="570" width="120" height="60" as="geometry"/>
+ </mxCell>
+ <mxCell id="eRehIIeIVOPW1y23kRkx-10" value="&lt;h1 style=&quot;margin-top: 0px;&quot;&gt;System Component/Call Model/Interface&lt;/h1&gt;&lt;p&gt;XPCOM is a standardized way of sharing code within DLLs in NewOS.&lt;/p&gt;&lt;p&gt;All classes are based upon&amp;nbsp;&lt;span style=&quot;color: rgb(78, 201, 176); background-color: rgb(31, 31, 31); font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px;&quot;&gt;IUnknown&lt;/span&gt;&lt;/p&gt;&lt;p&gt;It is also used to register and call code using&amp;nbsp;&lt;span style=&quot;color: rgb(78, 201, 176); background-color: rgb(31, 31, 31); font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px;&quot;&gt;IEventListener&lt;/span&gt;&lt;/p&gt;" style="text;html=1;whiteSpace=wrap;overflow=hidden;rounded=0;" parent="1" vertex="1">
+ <mxGeometry x="450" y="240" width="320" height="240" as="geometry"/>
+ </mxCell>
+ </root>
+ </mxGraphModel>
+ </diagram>
+</mxfile>
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 @@
+<SourceDeploy>
+<HiddenFiles>
+ <SourceFile>src/*.cxx</SourceFile>
+ <SourceFile>*.drawio</SourceFile>
+ <SourceFile>*.hxx</SourceFile>
+ <SourceFile>*.inl</SourceFile>
+ <SourceFile>*.idl</SourceFile>
+</HiddenFiles>
+</SourceDeploy>
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 <sci/sci_base.hxx>
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 <typename TCLS, typename UCLSID, typename... Args>
+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 <typename TCLS>
+inline SInt32 XPCOMReleaseClass(TCLS** cls)
+{
+ if (!cls)
+ return -1;
+
+ cls->RemoveRef();
+ cls->Release();
+
+ cls = nullptr;
+
+ return 0;
+}
+
+template <typename FnSign, typename ClsID>
+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);
+};