From 6bb44fdb31b8927e8e66e24ea187b2d2b79f591d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 22 Feb 2026 06:22:04 +0100 Subject: chore: modules conversion from .cc to .cpp. Signed-off-by: Amlal El Mahrouss --- src/libMsg/libMsg.json | 2 +- src/libMsg/src/Server.cc | 5 - src/libMsg/src/Server.cpp | 5 + src/libSystem/libSystem.json | 2 +- src/libSystem/src/JailCalls.cc | 15 --- src/libSystem/src/JailCalls.cpp | 15 +++ src/libSystem/src/SystemCalls.cc | 224 -------------------------------------- src/libSystem/src/SystemCalls.cpp | 224 ++++++++++++++++++++++++++++++++++++++ src/libSystem/src/Utilities.cpp | 27 +++++ src/libSystem/src/Utils.cc | 27 ----- src/libSystem/src/VerifyCalls.cc | 16 --- src/libSystem/src/VerifyCalls.cpp | 16 +++ 12 files changed, 289 insertions(+), 289 deletions(-) delete mode 100644 src/libMsg/src/Server.cc create mode 100644 src/libMsg/src/Server.cpp delete mode 100644 src/libSystem/src/JailCalls.cc create mode 100644 src/libSystem/src/JailCalls.cpp delete mode 100644 src/libSystem/src/SystemCalls.cc create mode 100644 src/libSystem/src/SystemCalls.cpp create mode 100644 src/libSystem/src/Utilities.cpp delete mode 100644 src/libSystem/src/Utils.cc delete mode 100644 src/libSystem/src/VerifyCalls.cc create mode 100644 src/libSystem/src/VerifyCalls.cpp (limited to 'src') diff --git a/src/libMsg/libMsg.json b/src/libMsg/libMsg.json index 858c427b..4b22534f 100644 --- a/src/libMsg/libMsg.json +++ b/src/libMsg/libMsg.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "../../public/frameworks", "./"], - "sources_path": ["src/*.cc"], + "sources_path": ["src/*.cpp"], "output_name": "libMsg.dll", "compiler_flags": [ "-ffreestanding", diff --git a/src/libMsg/src/Server.cc b/src/libMsg/src/Server.cc deleted file mode 100644 index aeb5ed4f..00000000 --- a/src/libMsg/src/Server.cc +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include diff --git a/src/libMsg/src/Server.cpp b/src/libMsg/src/Server.cpp new file mode 100644 index 00000000..aeb5ed4f --- /dev/null +++ b/src/libMsg/src/Server.cpp @@ -0,0 +1,5 @@ +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include diff --git a/src/libSystem/libSystem.json b/src/libSystem/libSystem.json index 6faaa695..16557645 100644 --- a/src/libSystem/libSystem.json +++ b/src/libSystem/libSystem.json @@ -2,7 +2,7 @@ "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", "headers_path": ["../", "./"], - "sources_path": ["src/*.cc", "src/*.stub.obj"], + "sources_path": ["src/*.cpp", "src/*.stub.obj"], "output_name": "libSystem.dll", "compiler_flags": [ "-ffreestanding", diff --git a/src/libSystem/src/JailCalls.cc b/src/libSystem/src/JailCalls.cc deleted file mode 100644 index 7a3218bf..00000000 --- a/src/libSystem/src/JailCalls.cc +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include -#include -#include - -using namespace LibSystem; - -IMPORT_C struct JAIL* JailGetCurrent(Void) { - return (struct JAIL*) libsys_syscall_arg_1(SYSCALL_HASH("JailGetCurrent")); -} \ No newline at end of file diff --git a/src/libSystem/src/JailCalls.cpp b/src/libSystem/src/JailCalls.cpp new file mode 100644 index 00000000..7a3218bf --- /dev/null +++ b/src/libSystem/src/JailCalls.cpp @@ -0,0 +1,15 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include +#include +#include + +using namespace LibSystem; + +IMPORT_C struct JAIL* JailGetCurrent(Void) { + return (struct JAIL*) libsys_syscall_arg_1(SYSCALL_HASH("JailGetCurrent")); +} \ No newline at end of file diff --git a/src/libSystem/src/SystemCalls.cc b/src/libSystem/src/SystemCalls.cc deleted file mode 100644 index 07f5241b..00000000 --- a/src/libSystem/src/SystemCalls.cc +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include -#include - -using namespace LibSystem; - -IMPORT_C Char* StrFmt(const Char* fmt, ...) { - if (!fmt || *fmt == 0) return const_cast("(null)"); - - return const_cast(""); -} - -// memmove-style copy -IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input UInt64 len) { - // handles overlap, prefers 64-bit word copies when aligned - if (!len || !dest || !src) return nullptr; - - auto s = static_cast(src); - auto d = static_cast(dest); - - if (d == s) return dest; - - // decide direction - if (d > s && d < s + len) { - const UInt8* rs = s + len; - UInt8* rd = d + len; - - // try 64-bit aligned backward copy - if (len >= sizeof(UInt64) && (reinterpret_cast(rs) % sizeof(UInt64) == 0) && - (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { - auto rsw = reinterpret_cast(rs); - auto rdw = reinterpret_cast(rd); - - SizeT words = len / sizeof(UInt64); - - for (SizeT i = 0; i < words; ++i) { - rdw[-1 - static_cast(i)] = rsw[-1 - static_cast(i)]; - } - - SizeT rem = len % sizeof(UInt64); - for (SizeT i = 0; i < rem; ++i) { - rd[-1 - i] = rs[-1 - i]; - } - } else { - // byte-wise backward - for (SizeT i = 0; i < len; ++i) { - rd[-1 - i] = rs[-1 - i]; - } - } - } else { - // try 64-bit aligned forward copy - if (len >= sizeof(UInt64) && (reinterpret_cast(s) % sizeof(UInt64) == 0) && - (reinterpret_cast(d) % sizeof(UInt64) == 0)) { - auto sw = reinterpret_cast(s); - auto dw = reinterpret_cast(d); - SizeT words = len / sizeof(UInt64); - - for (SizeT i = 0; i < words; ++i) { - dw[i] = sw[i]; - } - - SizeT rem = len % sizeof(UInt64); - const SizeT offset = words * sizeof(UInt64); - for (SizeT i = 0; i < rem; ++i) { - d[offset + i] = s[offset + i]; - } - } else { - for (SizeT i = 0; i < len; ++i) { - d[i] = s[i]; - } - } - } - - return dest; -} - -IMPORT_C SInt64 MmStrLen(const Char* in) { - // strlen via pointer walk - if (!in) return -kErrorInvalidData; - - const Char* p = in; - while (*p) ++p; - - return static_cast(p - in); -} - -IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input UInt64 len, _Input UInt8 value) { - if (!len || !dest) return nullptr; - - auto d = static_cast(dest); - - if (len >= sizeof(UInt64) && (reinterpret_cast(d) % sizeof(UInt64)) == 0) { - UInt64 pattern = static_cast(value); - pattern |= (pattern << 8); - pattern |= (pattern << 16); - pattern |= (pattern << 32); - - auto dw = reinterpret_cast(d); - SizeT words = len / sizeof(UInt64); - - for (SizeT i = 0; i < words; ++i) { - dw[i] = pattern; - } - - SizeT rem = len % sizeof(UInt64); - const SizeT offset = words * sizeof(UInt64); - for (SizeT i = 0; i < rem; ++i) { - d[offset + i] = value; - } - } else { - for (SizeT i = 0; i < len; ++i) d[i] = value; - } - - return dest; -} - -IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { - return static_cast(libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"), - Verify::sys_safe_cast(path), - Verify::sys_safe_cast(drv_letter))); -} - -IMPORT_C Void IoCloseFile(_Input Ref desc) { - libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast(desc)); -} - -IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { - auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("IoSeekFile"), static_cast(desc), - reinterpret_cast(&off)); - - if (!ret_ptr) return ~0UL; - - auto ret = static_cast(ret_ptr); - UInt64 result = *ret; - MUST_PASS(result != ~0UL); - return result; -} - -IMPORT_C UInt64 IoTellFile(_Input Ref desc) { - auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), static_cast(desc)); - if (!ret_ptr) return ~0UL; - auto ret = static_cast(ret_ptr); - return *ret; -} - -IMPORT_C SInt32 PrintRelease(_Input IORef buf) { - SInt32* ret = static_cast( - libsys_syscall_arg_2(SYSCALL_HASH("PrintRelease"), static_cast(buf))); - if (!ret) return -kErrorInvalidData; - - return static_cast(*ret); -} - -IMPORT_C IORef PrintCreate(Void) { - return static_cast(libsys_syscall_arg_1(SYSCALL_HASH("PrintCreate"))); -} - -IMPORT_C VoidPtr MmCreateHeap(UInt64 initial_size, UInt32 max_size) { - return static_cast(libsys_syscall_arg_3(SYSCALL_HASH("MmCreateHeap"), - reinterpret_cast(&initial_size), - reinterpret_cast(&max_size))); -} - -IMPORT_C SInt32 MmDestroyHeap(VoidPtr heap) { - auto ret = libsys_syscall_arg_2(SYSCALL_HASH("MmDestroyHeap"), static_cast(heap)); - return *static_cast(ret); -} - -IMPORT_C SInt32 PrintIn(_Input IORef desc, const Char* fmt, ...) { - va_list args; - va_start(args, fmt); - - auto buf = StrFmt(fmt, args); - - va_end(args); - - // if truncated, `needed` >= kBufferSz; we still send truncated buffer - auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintIn"), static_cast(desc), - Verify::sys_safe_cast(buf)); - - if (!ret_ptr) return -kErrorInvalidData; - - auto ret = static_cast(ret_ptr); - - return *ret; -} - -IMPORT_C IORef PrintGet(const Char* path) { - return static_cast( - libsys_syscall_arg_2(SYSCALL_HASH("PrintGet"), Verify::sys_safe_cast(path))); -} - -IMPORT_C ErrRef ErrGetLastError(Void) { - return *static_cast(libsys_syscall_arg_1(SYSCALL_HASH("ErrGetLastError"))); -} - -IMPORT_C SInt32 PrintOut(_Input IORef desc, const Char* fmt, ...) { - va_list args; - va_start(args, fmt); - - auto buf = StrFmt(fmt, args); - - va_end(args); - - // if truncated, `needed` >= kBufferSz; we still send truncated buffer - auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintOut"), static_cast(desc), - Verify::sys_safe_cast(buf)); - - if (!ret_ptr) return -kErrorInvalidData; - - auto ret = static_cast(ret_ptr); - - return *ret; -} - -IMPORT_C UInt64 PrintSize(IORef ref) { - MUST_PASS(ref); - return *static_cast(libsys_syscall_arg_2(SYSCALL_HASH("PrintSize"), ref)); -} \ No newline at end of file diff --git a/src/libSystem/src/SystemCalls.cpp b/src/libSystem/src/SystemCalls.cpp new file mode 100644 index 00000000..07f5241b --- /dev/null +++ b/src/libSystem/src/SystemCalls.cpp @@ -0,0 +1,224 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include +#include + +using namespace LibSystem; + +IMPORT_C Char* StrFmt(const Char* fmt, ...) { + if (!fmt || *fmt == 0) return const_cast("(null)"); + + return const_cast(""); +} + +// memmove-style copy +IMPORT_C VoidPtr MmCopyMemory(_Input VoidPtr dest, _Input VoidPtr src, _Input UInt64 len) { + // handles overlap, prefers 64-bit word copies when aligned + if (!len || !dest || !src) return nullptr; + + auto s = static_cast(src); + auto d = static_cast(dest); + + if (d == s) return dest; + + // decide direction + if (d > s && d < s + len) { + const UInt8* rs = s + len; + UInt8* rd = d + len; + + // try 64-bit aligned backward copy + if (len >= sizeof(UInt64) && (reinterpret_cast(rs) % sizeof(UInt64) == 0) && + (reinterpret_cast(rd) % sizeof(UInt64) == 0)) { + auto rsw = reinterpret_cast(rs); + auto rdw = reinterpret_cast(rd); + + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + rdw[-1 - static_cast(i)] = rsw[-1 - static_cast(i)]; + } + + SizeT rem = len % sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + rd[-1 - i] = rs[-1 - i]; + } + } else { + // byte-wise backward + for (SizeT i = 0; i < len; ++i) { + rd[-1 - i] = rs[-1 - i]; + } + } + } else { + // try 64-bit aligned forward copy + if (len >= sizeof(UInt64) && (reinterpret_cast(s) % sizeof(UInt64) == 0) && + (reinterpret_cast(d) % sizeof(UInt64) == 0)) { + auto sw = reinterpret_cast(s); + auto dw = reinterpret_cast(d); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + dw[i] = sw[i]; + } + + SizeT rem = len % sizeof(UInt64); + const SizeT offset = words * sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + d[offset + i] = s[offset + i]; + } + } else { + for (SizeT i = 0; i < len; ++i) { + d[i] = s[i]; + } + } + } + + return dest; +} + +IMPORT_C SInt64 MmStrLen(const Char* in) { + // strlen via pointer walk + if (!in) return -kErrorInvalidData; + + const Char* p = in; + while (*p) ++p; + + return static_cast(p - in); +} + +IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input UInt64 len, _Input UInt8 value) { + if (!len || !dest) return nullptr; + + auto d = static_cast(dest); + + if (len >= sizeof(UInt64) && (reinterpret_cast(d) % sizeof(UInt64)) == 0) { + UInt64 pattern = static_cast(value); + pattern |= (pattern << 8); + pattern |= (pattern << 16); + pattern |= (pattern << 32); + + auto dw = reinterpret_cast(d); + SizeT words = len / sizeof(UInt64); + + for (SizeT i = 0; i < words; ++i) { + dw[i] = pattern; + } + + SizeT rem = len % sizeof(UInt64); + const SizeT offset = words * sizeof(UInt64); + for (SizeT i = 0; i < rem; ++i) { + d[offset + i] = value; + } + } else { + for (SizeT i = 0; i < len; ++i) d[i] = value; + } + + return dest; +} + +IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) { + return static_cast(libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"), + Verify::sys_safe_cast(path), + Verify::sys_safe_cast(drv_letter))); +} + +IMPORT_C Void IoCloseFile(_Input Ref desc) { + libsys_syscall_arg_2(SYSCALL_HASH("IoCloseFile"), static_cast(desc)); +} + +IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) { + auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("IoSeekFile"), static_cast(desc), + reinterpret_cast(&off)); + + if (!ret_ptr) return ~0UL; + + auto ret = static_cast(ret_ptr); + UInt64 result = *ret; + MUST_PASS(result != ~0UL); + return result; +} + +IMPORT_C UInt64 IoTellFile(_Input Ref desc) { + auto ret_ptr = libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"), static_cast(desc)); + if (!ret_ptr) return ~0UL; + auto ret = static_cast(ret_ptr); + return *ret; +} + +IMPORT_C SInt32 PrintRelease(_Input IORef buf) { + SInt32* ret = static_cast( + libsys_syscall_arg_2(SYSCALL_HASH("PrintRelease"), static_cast(buf))); + if (!ret) return -kErrorInvalidData; + + return static_cast(*ret); +} + +IMPORT_C IORef PrintCreate(Void) { + return static_cast(libsys_syscall_arg_1(SYSCALL_HASH("PrintCreate"))); +} + +IMPORT_C VoidPtr MmCreateHeap(UInt64 initial_size, UInt32 max_size) { + return static_cast(libsys_syscall_arg_3(SYSCALL_HASH("MmCreateHeap"), + reinterpret_cast(&initial_size), + reinterpret_cast(&max_size))); +} + +IMPORT_C SInt32 MmDestroyHeap(VoidPtr heap) { + auto ret = libsys_syscall_arg_2(SYSCALL_HASH("MmDestroyHeap"), static_cast(heap)); + return *static_cast(ret); +} + +IMPORT_C SInt32 PrintIn(_Input IORef desc, const Char* fmt, ...) { + va_list args; + va_start(args, fmt); + + auto buf = StrFmt(fmt, args); + + va_end(args); + + // if truncated, `needed` >= kBufferSz; we still send truncated buffer + auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintIn"), static_cast(desc), + Verify::sys_safe_cast(buf)); + + if (!ret_ptr) return -kErrorInvalidData; + + auto ret = static_cast(ret_ptr); + + return *ret; +} + +IMPORT_C IORef PrintGet(const Char* path) { + return static_cast( + libsys_syscall_arg_2(SYSCALL_HASH("PrintGet"), Verify::sys_safe_cast(path))); +} + +IMPORT_C ErrRef ErrGetLastError(Void) { + return *static_cast(libsys_syscall_arg_1(SYSCALL_HASH("ErrGetLastError"))); +} + +IMPORT_C SInt32 PrintOut(_Input IORef desc, const Char* fmt, ...) { + va_list args; + va_start(args, fmt); + + auto buf = StrFmt(fmt, args); + + va_end(args); + + // if truncated, `needed` >= kBufferSz; we still send truncated buffer + auto ret_ptr = libsys_syscall_arg_3(SYSCALL_HASH("PrintOut"), static_cast(desc), + Verify::sys_safe_cast(buf)); + + if (!ret_ptr) return -kErrorInvalidData; + + auto ret = static_cast(ret_ptr); + + return *ret; +} + +IMPORT_C UInt64 PrintSize(IORef ref) { + MUST_PASS(ref); + return *static_cast(libsys_syscall_arg_2(SYSCALL_HASH("PrintSize"), ref)); +} \ No newline at end of file diff --git a/src/libSystem/src/Utilities.cpp b/src/libSystem/src/Utilities.cpp new file mode 100644 index 00000000..3ccfafa2 --- /dev/null +++ b/src/libSystem/src/Utilities.cpp @@ -0,0 +1,27 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include +#include + +using namespace LibSystem; + +/// @note This uses the FNV 64-bit variant. +IMPORT_C UInt64 libsys_hash_64(const Char* path) { + if (!path || *path == 0) return 0; + + const UInt64 kFNVSeed = 0xcbf29ce484222325ULL; + const UInt64 kFNVPrime = 0x100000001b3ULL; + + UInt64 hash = kFNVSeed; + + while (*path) { + hash ^= (Char) (*path++); + hash *= kFNVPrime; + } + + return hash; +} diff --git a/src/libSystem/src/Utils.cc b/src/libSystem/src/Utils.cc deleted file mode 100644 index 3ccfafa2..00000000 --- a/src/libSystem/src/Utils.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include -#include - -using namespace LibSystem; - -/// @note This uses the FNV 64-bit variant. -IMPORT_C UInt64 libsys_hash_64(const Char* path) { - if (!path || *path == 0) return 0; - - const UInt64 kFNVSeed = 0xcbf29ce484222325ULL; - const UInt64 kFNVPrime = 0x100000001b3ULL; - - UInt64 hash = kFNVSeed; - - while (*path) { - hash ^= (Char) (*path++); - hash *= kFNVPrime; - } - - return hash; -} diff --git a/src/libSystem/src/VerifyCalls.cc b/src/libSystem/src/VerifyCalls.cc deleted file mode 100644 index f23417e9..00000000 --- a/src/libSystem/src/VerifyCalls.cc +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include - -using namespace LibSystem; - -IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { - if (!expr) { - PrintOut(nullptr, "Assertion failed: %s\r", origin); - libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break")); - } -} \ No newline at end of file diff --git a/src/libSystem/src/VerifyCalls.cpp b/src/libSystem/src/VerifyCalls.cpp new file mode 100644 index 00000000..f23417e9 --- /dev/null +++ b/src/libSystem/src/VerifyCalls.cpp @@ -0,0 +1,16 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include + +using namespace LibSystem; + +IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { + if (!expr) { + PrintOut(nullptr, "Assertion failed: %s\r", origin); + libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break")); + } +} \ No newline at end of file -- cgit v1.2.3