summaryrefslogtreecommitdiffhomepage
path: root/dev/user
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
commitfb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch)
tree4cec7d1b321307b1d5935577631dae116a658a37 /dev/user
parent63a2d92c5dfe976175cda024ec01905d11b43738 (diff)
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/user')
-rw-r--r--dev/user/Macros.h57
-rw-r--r--dev/user/Opts.h2
-rw-r--r--dev/user/ProcessCodes.h72
-rw-r--r--dev/user/SystemCalls.h23
-rw-r--r--dev/user/src/SystemCalls.cc127
5 files changed, 131 insertions, 150 deletions
diff --git a/dev/user/Macros.h b/dev/user/Macros.h
index a0dfcb00..0bb98a59 100644
--- a/dev/user/Macros.h
+++ b/dev/user/Macros.h
@@ -19,7 +19,7 @@ Purpose: libsci Macros header.
#define ATTRIBUTE(X) __attribute__((X))
#define IMPORT_CXX extern "C++"
-#define IMPORT_C extern "C"
+#define IMPORT_C extern "C"
#define DEPRECATED ATTRIBUTE(deprecated)
@@ -42,12 +42,12 @@ typedef void Void;
#endif
#define YES true
-#define NO false
+#define NO false
typedef __UINT64_TYPE__ UInt64;
typedef __UINT32_TYPE__ UInt32;
typedef __UINT16_TYPE__ UInt16;
-typedef __UINT8_TYPE__ UInt8;
+typedef __UINT8_TYPE__ UInt8;
typedef __SIZE_TYPE__ SizeT;
@@ -56,29 +56,29 @@ typedef __INT32_TYPE__ SInt32;
typedef __INT16_TYPE__ SInt16;
typedef __INT8_TYPE__ SInt8;
-typedef void* VoidPtr;
+typedef void* VoidPtr;
typedef __UINTPTR_TYPE__ UIntPtr;
-typedef char Char;
+typedef char Char;
#ifdef __cplusplus
typedef decltype(nullptr) nullPtr;
-typedef nullPtr NullPtr;
+typedef nullPtr NullPtr;
-#define SCI_COPY_DELETE(KLASS) \
- KLASS& operator=(const KLASS&) = delete; \
- KLASS(const KLASS&) = delete;
+#define SCI_COPY_DELETE(KLASS) \
+ KLASS& operator=(const KLASS&) = delete; \
+ KLASS(const KLASS&) = delete;
-#define SCI_COPY_DEFAULT(KLASS) \
- KLASS& operator=(const KLASS&) = default; \
- KLASS(const KLASS&) = default;
+#define SCI_COPY_DEFAULT(KLASS) \
+ KLASS& operator=(const KLASS&) = default; \
+ KLASS(const KLASS&) = default;
-#define SCI_MOVE_DELETE(KLASS) \
- KLASS& operator=(KLASS&&) = delete; \
- KLASS(KLASS&&) = delete;
+#define SCI_MOVE_DELETE(KLASS) \
+ KLASS& operator=(KLASS&&) = delete; \
+ KLASS(KLASS&&) = delete;
-#define SCI_MOVE_DEFAULT(KLASS) \
- KLASS& operator=(KLASS&&) = default; \
- KLASS(KLASS&&) = default;
+#define SCI_MOVE_DEFAULT(KLASS) \
+ KLASS& operator=(KLASS&&) = default; \
+ KLASS(KLASS&&) = default;
#endif
@@ -87,9 +87,8 @@ IMPORT_C void _rtl_assert(Bool expr, const Char* origin);
#define MUST_PASS(X) _rtl_assert(X, __FILE__)
#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(X) \
- (((sizeof(X) / sizeof(*(X))) / \
- (static_cast<SizeT>(!(sizeof(X) % sizeof(*(X)))))))
+#define ARRAY_SIZE(X) \
+ (((sizeof(X) / sizeof(*(X))) / (static_cast<SizeT>(!(sizeof(X) % sizeof(*(X)))))))
#endif
#ifndef KIB
@@ -97,31 +96,31 @@ IMPORT_C void _rtl_assert(Bool expr, const Char* origin);
#endif
#ifndef kib_cast
-#define kib_cast(X) (UInt64)((X)*1024)
+#define kib_cast(X) (UInt64)((X) * 1024)
#endif
#ifndef MIB
-#define MIB(X) (UInt64)((UInt64)KIB(X) / 1024)
+#define MIB(X) (UInt64)((UInt64) KIB(X) / 1024)
#endif
#ifndef mib_cast
-#define mib_cast(X) (UInt64)((UInt64)kib_cast(X) * 1024)
+#define mib_cast(X) (UInt64)((UInt64) kib_cast(X) * 1024)
#endif
#ifndef GIB
-#define GIB(X) (UInt64)((UInt64)MIB(X) / 1024)
+#define GIB(X) (UInt64)((UInt64) MIB(X) / 1024)
#endif
#ifndef gib_cast
-#define gib_cast(X) (UInt64)((UInt64)mib_cast(X) * 1024)
+#define gib_cast(X) (UInt64)((UInt64) mib_cast(X) * 1024)
#endif
#ifndef TIB
-#define TIB(X) (UInt64)((UInt64)GIB(X) / 1024)
+#define TIB(X) (UInt64)((UInt64) GIB(X) / 1024)
#endif
#ifndef tib_cast
-#define tib_cast(X) ((UInt64)gib_cast(X) * 1024)
+#define tib_cast(X) ((UInt64) gib_cast(X) * 1024)
#endif
-#define SCI_UNUSED(X) ((void)X)
+#define SCI_UNUSED(X) ((void) X)
diff --git a/dev/user/Opts.h b/dev/user/Opts.h
index 09a77570..474fe1b7 100644
--- a/dev/user/Opts.h
+++ b/dev/user/Opts.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
diff --git a/dev/user/ProcessCodes.h b/dev/user/ProcessCodes.h
index 1b1b955b..74b50c68 100644
--- a/dev/user/ProcessCodes.h
+++ b/dev/user/ProcessCodes.h
@@ -1,6 +1,6 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
@@ -12,46 +12,46 @@
/// @brief Process Codes type and values.
/// @author Amlal El Mahrouss (amlal@nekernel.org)
-#define err_local_ok() (kLastError == kErrorSuccess)
+#define err_local_ok() (kLastError == kErrorSuccess)
#define err_local_fail() (kLastError != kErrorSuccess)
-#define err_local_get() (kLastError)
+#define err_local_get() (kLastError)
typedef SInt32 ErrRef;
-inline constexpr ErrRef kErrorSuccess = 0;
-inline constexpr ErrRef kErrorExecutable = 33;
-inline constexpr ErrRef kErrorExecutableLib = 34;
-inline constexpr ErrRef kErrorFileNotFound = 35;
-inline constexpr ErrRef kErrorDirectoryNotFound = 36;
-inline constexpr ErrRef kErrorDiskReadOnly = 37;
-inline constexpr ErrRef kErrorDiskIsFull = 38;
-inline constexpr ErrRef kErrorProcessFault = 39;
-inline constexpr ErrRef kErrorSocketHangUp = 40;
+inline constexpr ErrRef kErrorSuccess = 0;
+inline constexpr ErrRef kErrorExecutable = 33;
+inline constexpr ErrRef kErrorExecutableLib = 34;
+inline constexpr ErrRef kErrorFileNotFound = 35;
+inline constexpr ErrRef kErrorDirectoryNotFound = 36;
+inline constexpr ErrRef kErrorDiskReadOnly = 37;
+inline constexpr ErrRef kErrorDiskIsFull = 38;
+inline constexpr ErrRef kErrorProcessFault = 39;
+inline constexpr ErrRef kErrorSocketHangUp = 40;
inline constexpr ErrRef kErrorThreadLocalStorage = 41;
-inline constexpr ErrRef kErrorMath = 42;
-inline constexpr ErrRef kErrorNoNetwork = 43;
-inline constexpr ErrRef kErrorHeapOutOfMemory = 44;
-inline constexpr ErrRef kErrorNoSuchDisk = 45;
-inline constexpr ErrRef kErrorFileExists = 46;
-inline constexpr ErrRef kErrorFormatFailed = 47;
-inline constexpr ErrRef kErrorNetworkTimeout = 48;
-inline constexpr ErrRef kErrorInternal = 49;
-inline constexpr ErrRef kErrorForkAlreadyExists = 50;
-inline constexpr ErrRef kErrorOutOfTeamSlot = 51;
-inline constexpr ErrRef kErrorHeapNotPresent = 52;
-inline constexpr ErrRef kErrorNoEntrypoint = 53;
-inline constexpr ErrRef kErrorDiskIsCorrupted = 54;
-inline constexpr ErrRef kErrorDisk = 55;
-inline constexpr ErrRef kErrorInvalidData = 56;
-inline constexpr ErrRef kErrorAsync = 57;
-inline constexpr ErrRef kErrorNonBlocking = 58;
-inline constexpr ErrRef kErrorIPC = 59;
-inline constexpr ErrRef kErrorSign = 60;
-inline constexpr ErrRef kErrorInvalidCreds = 61;
-inline constexpr ErrRef kErrorCDTrayBroken = 62;
-inline constexpr ErrRef kErrorUnrecoverableDisk = 63;
-inline constexpr ErrRef kErrorFileLocked = 64;
-inline constexpr ErrRef kErrorUnimplemented = -1;
+inline constexpr ErrRef kErrorMath = 42;
+inline constexpr ErrRef kErrorNoNetwork = 43;
+inline constexpr ErrRef kErrorHeapOutOfMemory = 44;
+inline constexpr ErrRef kErrorNoSuchDisk = 45;
+inline constexpr ErrRef kErrorFileExists = 46;
+inline constexpr ErrRef kErrorFormatFailed = 47;
+inline constexpr ErrRef kErrorNetworkTimeout = 48;
+inline constexpr ErrRef kErrorInternal = 49;
+inline constexpr ErrRef kErrorForkAlreadyExists = 50;
+inline constexpr ErrRef kErrorOutOfTeamSlot = 51;
+inline constexpr ErrRef kErrorHeapNotPresent = 52;
+inline constexpr ErrRef kErrorNoEntrypoint = 53;
+inline constexpr ErrRef kErrorDiskIsCorrupted = 54;
+inline constexpr ErrRef kErrorDisk = 55;
+inline constexpr ErrRef kErrorInvalidData = 56;
+inline constexpr ErrRef kErrorAsync = 57;
+inline constexpr ErrRef kErrorNonBlocking = 58;
+inline constexpr ErrRef kErrorIPC = 59;
+inline constexpr ErrRef kErrorSign = 60;
+inline constexpr ErrRef kErrorInvalidCreds = 61;
+inline constexpr ErrRef kErrorCDTrayBroken = 62;
+inline constexpr ErrRef kErrorUnrecoverableDisk = 63;
+inline constexpr ErrRef kErrorFileLocked = 64;
+inline constexpr ErrRef kErrorUnimplemented = -1;
/// @brief The last error reported by the system to the process.
IMPORT_C ErrRef kLastError;
diff --git a/dev/user/SystemCalls.h b/dev/user/SystemCalls.h
index cfbd99a8..1e391d8a 100644
--- a/dev/user/SystemCalls.h
+++ b/dev/user/SystemCalls.h
@@ -94,7 +94,8 @@ IMPORT_C UInt64 IoSeekFile(_Input Ref file_desc, UInt64 file_offset);
// Process API.
// ------------------------------------------------------------------------
-/// @brief Spawns a Thread Information Block and Global Information Block inside the current process.
+/// @brief Spawns a Thread Information Block and Global Information Block inside the current
+/// process.
/// @param process_id Target Process ID, must be valid.
/// @return > 0 error ocurred or already present, = 0 success.
IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id);
@@ -102,7 +103,8 @@ IMPORT_C UInt32 RtlSpawnIB(UIntPtr process_id);
/// @brief Spawns a process with a unique pid (stored as UIntPtr).
/// @param process_path process filesystem path.
/// @return > 0 process was created.
-IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** argv, Char** envp, SizeT envp_len);
+IMPORT_C UIntPtr RtlSpawnProcess(const Char* process_path, SizeT argc, Char** argv, Char** envp,
+ SizeT envp_len);
/// @brief Exits a process with an exit_code.
/// @return if it has succeeded true, otherwise false.
@@ -269,14 +271,13 @@ IMPORT_C VoidPtr EvtDispatchEvent(_Input const Char* event_name, _Input VoidPtr
// Power API.
// ------------------------------------------------------------------------------------------ //
-enum
-{
- kPowerCodeInvalid,
- kPowerCodeShutdown,
- kPowerCodeReboot,
- kPowerCodeSleep,
- kPowerCodeWake,
- kPowerCodeCount,
+enum {
+ kPowerCodeInvalid,
+ kPowerCodeShutdown,
+ kPowerCodeReboot,
+ kPowerCodeSleep,
+ kPowerCodeWake,
+ kPowerCodeCount,
};
IMPORT_C SInt32 PwrReadCode(_Output SInt32& code);
@@ -346,4 +347,4 @@ IMPORT_C Char* StrFmt(const Char* fmt, ...);
IMPORT_C UInt64 StrMathToNumber(const Char* in, const Char** endp, const SInt16 base);
-#endif // ifndef SCI_SCI_H
+#endif // ifndef SCI_SCI_H
diff --git a/dev/user/src/SystemCalls.cc b/dev/user/src/SystemCalls.cc
index 6b32bd70..d8366d42 100644
--- a/dev/user/src/SystemCalls.cc
+++ b/dev/user/src/SystemCalls.cc
@@ -1,114 +1,95 @@
/* -------------------------------------------
- Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
+ Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.
------------------------------------------- */
-#include <user/SystemCalls.h>
#include <user/Opts.h>
+#include <user/SystemCalls.h>
/// @file SystemCalls.cc
/// @brief Source file for the memory functions of the user.sys.
/// @brief Copy memory region.
-IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len)
-{
- if (!len ||
- !dest ||
- !src)
- {
- return nullptr;
- }
-
- for (SizeT i = 0; i < len; i++)
- {
- ((Char*)dest)[i] = ((Char*)src)[i];
- }
-
- return dest;
+IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input SizeT len) {
+ if (!len || !dest || !src) {
+ return nullptr;
+ }
+
+ for (SizeT i = 0; i < len; i++) {
+ ((Char*) dest)[i] = ((Char*) src)[i];
+ }
+
+ return dest;
}
/// @brief Get string length.
-IMPORT_C SInt64 MmStrLen(const Char* in)
-{
- if (!in)
- return 0;
+IMPORT_C SInt64 MmStrLen(const Char* in) {
+ if (!in) return 0;
- SizeT len{0};
+ SizeT len{0};
- do
- {
- ++len;
- } while (in[len] != '\0');
+ do {
+ ++len;
+ } while (in[len] != '\0');
- return len;
+ return len;
}
/// @brief Fill memory region **dest** with **value**.
-IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value)
-{
- if (!len ||
- !dest)
- {
- return nullptr;
- }
-
- for (SizeT i = 0; i < len; i++)
- {
- ((Char*)dest)[i] = value;
- }
-
- return dest;
+IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt8 value) {
+ if (!len || !dest) {
+ return nullptr;
+ }
+
+ for (SizeT i = 0; i < len; i++) {
+ ((Char*) dest)[i] = value;
+ }
+
+ return dest;
}
-IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter)
-{
- return sci_syscall_arg_3(1, reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
- reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
+IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) {
+ return sci_syscall_arg_3(1, reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
}
-IMPORT_C Void IoCloseFile(_Input Ref desc)
-{
- sci_syscall_arg_2(2, desc);
+IMPORT_C Void IoCloseFile(_Input Ref desc) {
+ sci_syscall_arg_2(2, desc);
}
-IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off)
-{
- auto ret = (UInt64*)sci_syscall_arg_3(3, reinterpret_cast<VoidPtr>(desc),
- reinterpret_cast<VoidPtr>(&off));
+IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) {
+ auto ret = (UInt64*) sci_syscall_arg_3(3, reinterpret_cast<VoidPtr>(desc),
+ reinterpret_cast<VoidPtr>(&off));
- MUST_PASS((*ret) != ~0UL);
- return *ret;
+ MUST_PASS((*ret) != ~0UL);
+ return *ret;
}
-IMPORT_C UInt64 IoTellFile(_Input Ref desc)
-{
- auto ret = (UInt64*)sci_syscall_arg_2(4, reinterpret_cast<VoidPtr>(desc));
- return *ret;
+IMPORT_C UInt64 IoTellFile(_Input Ref desc) {
+ auto ret = (UInt64*) sci_syscall_arg_2(4, reinterpret_cast<VoidPtr>(desc));
+ return *ret;
}
/// @brief Print to the file descriptor.
/// @param desc the file descriptor.
-IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...)
-{
- va_list args;
+IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) {
+ va_list args;
- va_start(args, fmt);
+ va_start(args, fmt);
- auto ret = (UInt64*)sci_syscall_arg_4(5, reinterpret_cast<VoidPtr>(desc),
- reinterpret_cast<VoidPtr>(const_cast<Char*>(fmt)), args);
+ auto ret = (UInt64*) sci_syscall_arg_4(5, reinterpret_cast<VoidPtr>(desc),
+ reinterpret_cast<VoidPtr>(const_cast<Char*>(fmt)), args);
- va_end(args);
+ va_end(args);
- return *ret;
+ return *ret;
}
/// @internal
-IMPORT_C Void _rtl_assert(Bool expr, const Char* origin)
-{
- if (!expr)
- {
- PrintOut(nullptr, "Assertion failed: %s\r", origin);
- PrintOut(nullptr, "Origin: %s\r", origin);
- }
+IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) {
+ if (!expr) {
+ PrintOut(nullptr, "Assertion failed: %s\r", origin);
+ PrintOut(nullptr, "Origin: %s\r", origin);
+ }
} \ No newline at end of file