summaryrefslogtreecommitdiffhomepage
path: root/dev/sci
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-10-08 19:17:37 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-10-08 19:21:53 +0200
commit2a51866f3f39d4ebf0fd2d132cfad1e2962d1236 (patch)
treea325b523090f1bbc027114314ec946cd2226923a /dev/sci
parentc43a509be4e1098ad73d0449e512d118add7f151 (diff)
IMP: A New set of features and APIs in zka-sci-cxx.dll
- IStr object for a class like string object. - New SCI APIs, Disk management. Loader, I/O and new Mm functions. - Fixed and improved XPCOMReleaseClass. - Using IStr when dealing with XPCOM events. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/sci')
-rw-r--r--dev/sci/sci.json2
-rw-r--r--dev/sci/sci_base.hxx105
-rw-r--r--dev/sci/sci_lpc.hxx2
-rw-r--r--dev/sci/xpcom_core.hxx21
4 files changed, 112 insertions, 18 deletions
diff --git a/dev/sci/sci.json b/dev/sci/sci.json
index 0b7c6bb7..0bc6cdcf 100644
--- a/dev/sci/sci.json
+++ b/dev/sci/sci.json
@@ -13,7 +13,7 @@
"-Wl,--subsystem=17"
],
"cpp_macros": [
- "__SCI_IMPL__",
+ "__XPCOM_IMPL__",
"cSCIVersion=0x0100",
"cSCIVersionHighest=0x0100",
"cSCIVersionLowest=0x0100"
diff --git a/dev/sci/sci_base.hxx b/dev/sci/sci_base.hxx
index e73da45b..70a0f7f4 100644
--- a/dev/sci/sci_base.hxx
+++ b/dev/sci/sci_base.hxx
@@ -2,8 +2,8 @@
Copyright ZKA Technologies.
-File: SCIBase.hxx
-Purpose: sci/M core header file (C++)
+File: sci_base.hxx
+Purpose: SCI core header file (C++ only).
------------------------------------------- */
@@ -39,7 +39,7 @@ typedef char Char;
#include <sci/sci_lpc.hxx>
-#ifdef __SCI_IMPL__
+#ifdef __XPCOM_IMPL__
#include <sci/xpcom_core.hxx>
#else
class IUnknown; // Refrenced from an IDB entry.
@@ -92,25 +92,25 @@ typedef Object SocketObject;
// ------------------------------------------------------------------------------------------ //
// ------------------------------------------------------------------------------------------ //
-/// @note Part of ZKA loader API.
+/// @note Dynamic 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 Object LdrGetDLLProc(_Input const Char* symbol, _Input Object dll_handle);
+IMPORT_C Object LdrGetDLLSymbolFromHandle(_Input const Char* symbol, _Input Object dll_handle);
/// @brief Open DLL handle.
/// @param path
/// @param drv
/// @return
-IMPORT_C Object LdrOpenDLL(_Input const Char* path, _Input const Char* drive_letter);
+IMPORT_C Object LdrOpenDLLHandle(_Input const Char* path, _Input const Char* drive_letter);
/// @brief Close DLL handle
/// @param dll_handle
/// @return
-IMPORT_C Void LdrCloseDLL(_Input Object dll_handle);
+IMPORT_C Void LdrCloseDLLHandle(_Input Object* dll_handle);
// ------------------------------------------------------------------------------------------ //
// File API.
@@ -127,12 +127,27 @@ IMPORT_C Object IoOpenFile(const Char* fs_path, const Char* drive_letter);
/// @return void.
IMPORT_C Void IoCloseFile(_Input Object file_desc);
+/// @brief Write data to a file.
+/// @param file_desc the file descriptor.
+/// @param out_data the data to write.
+/// @param sz_data the size of the data to write.
+/// @return the number of bytes written.
IMPORT_C UInt32 IoWriteFile(_Input Object file_desc, _Output VoidPtr out_data, SizeT sz_data);
+/// @brief Read data from a file.
+/// @param file_desc the file descriptor.
+/// @param out_data the data to read.
+/// @param sz_data the size of the data to read.
IMPORT_C UInt32 IoReadFile(_Input Object file_desc, _Output VoidPtr* out_data, SizeT sz_data);
+/// @brief Rewind the file pointer to the beginning of the file.
+/// @param file_desc the file descriptor.
+/// @return the number of bytes read.
IMPORT_C UInt64 IoRewindFile(_Input Object file_desc);
+/// @brief Tell the current position of the file pointer.
+/// @param file_desc the file descriptor.
+/// @return the current position of the file pointer.
IMPORT_C UInt64 IoTellFile(_Input Object file_desc);
IMPORT_C UInt64 IoSeekFile(_Input Object file_desc, UInt64 file_offset);
@@ -146,7 +161,7 @@ IMPORT_C UInt64 IoSeekFile(_Input Object file_desc, UInt64 file_offset);
/// @return > 0 error ocurred or already present, = 0 success.
IMPORT_C UInt32 RtlTlsInstall(Void);
-#ifndef __SCI_IMPL__
+#ifndef __XPCOM_IMPL__
// ------------------------------------------------------------------------
// XPCOM API.
@@ -176,7 +191,7 @@ IMPORT_C SInt32 XPCOMCreateInstance(_Input UInt32 flags, _Output Object* handle_
/// @param handle_instance the XPCOM handle.
IMPORT_C Void XPCOMDestroyInstance(_Input Object handle_instance);
-#endif // !__SCI_IMPL__
+#endif // !__XPCOM_IMPL__
// ------------------------------------------------------------------------
// Memory Management API.
@@ -196,9 +211,15 @@ IMPORT_C Void 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.
+/// @brief Fill memory region with CRC32.
IMPORT_C UInt32 MmFillCRC32Heap(_Input VoidPtr heap);
+/// @brief Copy memory region.
+IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len);
+
+/// @brief Fill memory region.
+IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value);
+
// ------------------------------------------------------------------------
// Error handling API.
// ------------------------------------------------------------------------
@@ -209,22 +230,86 @@ IMPORT_C SInt32 ErrGetLastError(Void);
// Threading API.
// ------------------------------------------------------------------------
+/// @brief Exit the current thread.
+/// @param exit_code the exit code.
IMPORT_C Void ThrExitCurrentThread(_Input SInt32 exit_code);
+
+/// @brief Exit the main thread.
+/// @param exit_code the exit code.
IMPORT_C Void ThrExitMainThread(_Input SInt32 exit_code);
+/// @brief Exit a thread.
+/// @param thread the thread to exit.
+/// @param exit_code the exit code.
IMPORT_C Void ThrExitThread(_Input ThreadObject thread, _Input SInt32 exit_code);
typedef Void(*GenericThreadFn)(Void);
+/// @brief Create a thread.
+/// @param proc the thread procedure.
+/// @return the thread object.
IMPORT_C ThreadObject ThrCreateThread(GenericThreadFn proc);
+/// @brief Yield the current thread.
+/// @param thread the thread to yield.
IMPORT_C Void ThrExitYieldThread(Void);
+/// @brief Join a thread.
+/// @param thread the thread to join.
IMPORT_C Void ThrExitJoinThread(Void);
+
+/// @brief Detach a thread.
+/// @param thread the thread to detach.
IMPORT_C Void ThrExitDetachThread(Void);
// ------------------------------------------------------------------------
// Drive Management API.
// ------------------------------------------------------------------------
+/// @brief Get the default drive letter.
+/// @param void.
+/// @return the drive letter.
+IMPORT_C Char* DrvGetDefaultDriveLetter(Void);
+
+/// @brief Get the drive letter from a path.
+/// @param path the path.
+/// @return the drive letter.
+IMPORT_C Char* DrvGetDriveLetterFromPath(_Input const Char* path);
+
+/// @brief Get a mounted drive from a letter.
+/// @param letter the letter (A..Z).
+/// @return the drive object.
+IMPORT_C Object DrvGetMountedDrive(_Input const Char letter);
+
+/// @brief Mount a drive.
+/// @param path the path to mount.
+/// @param letter the letter to mount.
+IMPORT_C Void DrvMountDrive(_Input const Char* path, _Input const Char* letter);
+
+/// @brief Unmount a drive.
+/// @param letter the letter to unmount.
+IMPORT_C Void DrvUnmountDrive(_Input const Char letter);
+
+// ------------------------------------------------------------------------
+// Event handling API, use to listen to OS specific events.
+// ------------------------------------------------------------------------
+
+/// @brief Add an event listener.
+/// @param event_name the event name.
+/// @param listener the listener to add.
+/// @return the event listener.
+IMPORT_C Void EvtAddListener(_Input const Char* event_name, _Input Object listener);
+
+/// @brief Remove an event listener.
+/// @param event_name the event name.
+/// @param listener the listener to remove.
+/// @return the event listener.
+IMPORT_C Void EvtRemoveListener(_Input const Char* event_name, _Input Object listener);
+
+/// @brief Dispatch an event.
+/// @param event_name the event name.
+/// @param event_data the event data.
+/// @return the event data.
+IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr event_data);
+
#endif // ifndef __SCI_BASE_HXX__
diff --git a/dev/sci/sci_lpc.hxx b/dev/sci/sci_lpc.hxx
index 6b52050b..c8fb0b55 100644
--- a/dev/sci/sci_lpc.hxx
+++ b/dev/sci/sci_lpc.hxx
@@ -44,4 +44,6 @@ inline constexpr ErrObject kErrorSign = 60;
inline constexpr ErrObject kErrorInvalidCreds = 61;
inline constexpr ErrObject kErrorUnimplemented = 0;
+/// @brief The last error reported by the system to the process.
IMPORT_C ErrObject kLastError;
+
diff --git a/dev/sci/xpcom_core.hxx b/dev/sci/xpcom_core.hxx
index 2b2754e6..ef82733e 100644
--- a/dev/sci/xpcom_core.hxx
+++ b/dev/sci/xpcom_core.hxx
@@ -20,6 +20,7 @@ Purpose: Base code of XPCOM.
protocol IUnknown; // Refrenced from an IDB entry.
protocol ICLSID; // From the IDB, the constructor of the object, e.g: TextUCLSID.
object UUID;
+object IStr;
/// @brief Unknown XPCOM interface
protocol clsid("d7c144b6-0792-44b8-b06b-02b227b547df") IUnknown
@@ -45,6 +46,9 @@ public:
template <typename TCLS, typename UCLSID, typename... Args>
inline TCLS* XPCOMQueryInterface(UCLSID* uclsidOfCls, Args&&... args)
{
+ if (uclsidOfCls == nullptr)
+ return nullptr;
+
uclsidOfCls->AddRef();
return uclsidOfCls->QueryInterfaceWithArgs(args...);
}
@@ -56,17 +60,20 @@ inline TCLS* XPCOMQueryInterface(UCLSID* uclsidOfCls, Args&&... args)
template <typename TCLS>
inline SInt32 XPCOMReleaseClass(TCLS** cls)
{
- if (!cls)
- return -1;
+ if (!*cls)
+ return -kErrorInvalidData;
- cls->RemoveRef();
- cls->Release();
+ (*cls)->RemoveRef();
+ (*cls)->Release();
- cls = nullptr;
+ *cls = nullptr;
- return 0;
+ return kErrorSuccess;
}
+/// @brief Event listener interface.
+/// @tparam FnSign the event listener function type.
+/// @tparam ClsID the event listener class ID.
template <typename FnSign, typename ClsID>
protocol IEventListener : public ClsID
{
@@ -78,7 +85,7 @@ protocol IEventListener : public ClsID
IEventListener& operator=(const IEventListener&) = default;
IEventListener(const IEventListener&) = default;
- virtual IEventListener& operator-=(const Char* event_name)
+ virtual IEventListener& operator-=(const IStr* event_name)
{
this->RemoveEventListener(event_name);
return *this;