diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-06-22 21:41:15 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-06-22 21:41:15 +0200 |
| commit | 41703b62f9e7e83fa856fbf53101edc889502c45 (patch) | |
| tree | 96079f607134642cae1b6c79b1da70135c1bf5d6 | |
| parent | 7c63269be0c40d8b6169d3cacf487ab370206f60 (diff) | |
feat: use FNV in libSystem's syscall routing.
fix: Add legacy string.h functions back, for GCC.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
| -rw-r--r-- | dev/boot/src/BootSupport.cc | 58 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/Syscall.h | 22 | ||||
| -rw-r--r-- | dev/libSystem/src/SystemCalls.cc (renamed from dev/libSystem/src/SystemAPI.cc) | 10 |
3 files changed, 77 insertions, 13 deletions
diff --git a/dev/boot/src/BootSupport.cc b/dev/boot/src/BootSupport.cc index 7cf7af95..96c6594e 100644 --- a/dev/boot/src/BootSupport.cc +++ b/dev/boot/src/BootSupport.cc @@ -18,7 +18,7 @@ /// @param dst destination pointer. /// @param byte value to fill in. /// @param len length of of src. -EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len, long long unsigned int dst_size) { +EXTERN_C VoidPtr memnset(void* dst, int byte, long long unsigned int len, long long unsigned int dst_size) { if (!dst || len > dst_size) { // For now, we return nullptr or an error status. return nullptr; @@ -35,7 +35,7 @@ EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len, long lo /// @param dst destination pointer. /// @param src source pointer. /// @param len length of of src. -EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len, long long unsigned int dst_size) { +EXTERN_C VoidPtr memncpy(void* dst, const void* src, long long unsigned int len, long long unsigned int dst_size) { if (!dst || !src || len > dst_size) { // Similar to memset, this is a critical failure. return nullptr; @@ -49,7 +49,7 @@ EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len, } /// @brief strlen definition in C++. -EXTERN_C size_t strlen(const char* whatToCheck, size_t max_len) { +EXTERN_C size_t strnlen(const char* whatToCheck, size_t max_len) { size_t len = 0; while (len < max_len && whatToCheck[len] != '\0') { ++len; @@ -58,7 +58,7 @@ EXTERN_C size_t strlen(const char* whatToCheck, size_t max_len) { } /// @brief strcmp definition in C++. -EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight, size_t max_len) { +EXTERN_C int strncmp(const char* whatToCheck, const char* whatToCheckRight, size_t max_len) { size_t i = 0; while (i < max_len && whatToCheck[i] == whatToCheckRight[i]) { if (whatToCheck[i] == '\0') return 0; @@ -73,4 +73,54 @@ EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight, size_ /// @brief something specific to the Microsoft's ABI, When the stack grows too big. EXTERN_C void ___chkstk_ms(void) {} +/// @note GCC expects them to be here. + +/// @brief memset definition in C++. +/// @param dst destination pointer. +/// @param byte value to fill in. +/// @param len length of of src. +EXTERN_C VoidPtr memset(void* dst, int byte, long long unsigned int len) { + for (size_t i = 0UL; i < len; ++i) { + ((int*) dst)[i] = byte; + } + + return dst; +} + +/// @brief memcpy definition in C++. +/// @param dst destination pointer. +/// @param src source pointer. +/// @param len length of of src. +EXTERN_C VoidPtr memcpy(void* dst, const void* src, long long unsigned int len) { + for (size_t i = 0UL; i < len; ++i) { + ((int*) dst)[i] = ((int*) src)[i]; + } + + return dst; +} + +/// @brief strlen definition in C++. +EXTERN_C size_t strlen(const char* whatToCheck) { + SizeT len = 0; + + while (whatToCheck[len] != 0) { + ++len; + } + + return len; +} + +/// @brief strcmp definition in C++. +EXTERN_C int strcmp(const char* whatToCheck, const char* whatToCheckRight) { + SizeT len = 0; + + while (whatToCheck[len] == whatToCheckRight[len]) { + if (whatToCheck[len] == 0) return 0; + + ++len; + } + + return len; +} + #endif diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index 436665ae..5a840df1 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -9,11 +9,25 @@ #include <libSystem/SystemKit/System.h> #include <cstdarg> -#ifndef SYSCALL_HASH -#define SYSCALL_HASH(str) (UInt64) str -#endif // !SYSCALL_HASH - IMPORT_C VoidPtr libsys_syscall_arg_1(SizeT id); IMPORT_C VoidPtr libsys_syscall_arg_2(SizeT id, VoidPtr arg1); IMPORT_C VoidPtr libsys_syscall_arg_3(SizeT id, VoidPtr arg1, VoidPtr arg3); IMPORT_C VoidPtr libsys_syscall_arg_4(SizeT id, VoidPtr arg1, VoidPtr arg3, VoidPtr arg4); + +inline UInt64 libsys_hash_64(const Char* path) { + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; + const UInt64 FNV_PRIME = 0x100000001b3ULL; + + UInt64 hash = FNV_OFFSET_BASIS; + + while (*path) { + hash ^= (Char) (*path++); + hash *= FNV_PRIME; + } + + return hash; +} + +#ifndef SYSCALL_HASH +#define SYSCALL_HASH(str) libsys_hash_64(str) +#endif // !SYSCALL_HASH
\ No newline at end of file diff --git a/dev/libSystem/src/SystemAPI.cc b/dev/libSystem/src/SystemCalls.cc index d0682830..6344cdac 100644 --- a/dev/libSystem/src/SystemAPI.cc +++ b/dev/libSystem/src/SystemCalls.cc @@ -47,7 +47,7 @@ IMPORT_C VoidPtr MmFillMemory(_Input VoidPtr dest, _Input SizeT len, _Input UInt }
IMPORT_C Ref IoOpenFile(_Input const Char* path, _Input const Char* drv_letter) {
- return (Ref) libsys_syscall_arg_3(SYSCALL_HASH('IoOpenFile'),
+ return (Ref) libsys_syscall_arg_3(SYSCALL_HASH("IoOpenFile"),
reinterpret_cast<VoidPtr>(const_cast<Char*>(path)),
reinterpret_cast<VoidPtr>(const_cast<Char*>(drv_letter)));
}
@@ -58,14 +58,14 @@ IMPORT_C Void IoCloseFile(_Input Ref desc) { IMPORT_C UInt64 IoSeekFile(_Input Ref desc, _Input UInt64 off) {
auto ret = (volatile UInt64*) libsys_syscall_arg_3(
- SYSCALL_HASH('IoSeekFile'), reinterpret_cast<VoidPtr>(desc), reinterpret_cast<VoidPtr>(&off));
+ SYSCALL_HASH("IoSeekFile"), reinterpret_cast<VoidPtr>(desc), reinterpret_cast<VoidPtr>(&off));
MUST_PASS((*ret) != ~0UL);
return *ret;
}
IMPORT_C UInt64 IoTellFile(_Input Ref desc) {
- auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH('IoTellFile'),
+ auto ret = (volatile UInt64*) libsys_syscall_arg_2(SYSCALL_HASH("IoTellFile"),
reinterpret_cast<VoidPtr>(desc));
return *ret;
}
@@ -76,7 +76,7 @@ IMPORT_C SInt32 PrintOut(_Input IORef desc, const char* fmt, ...) { va_start(args, fmt);
auto ret = (volatile UInt64*) libsys_syscall_arg_4(
- SYSCALL_HASH('PrintOut'), reinterpret_cast<VoidPtr>(desc),
+ SYSCALL_HASH("PrintOut"), reinterpret_cast<VoidPtr>(desc),
reinterpret_cast<VoidPtr>(const_cast<Char*>(fmt)), args);
va_end(args);
@@ -89,6 +89,6 @@ IMPORT_C Void _rtl_assert(Bool expr, const Char* origin) { PrintOut(nullptr, "Assertion failed: %s\r", origin);
PrintOut(nullptr, "Origin: %s\r", origin);
- libsys_syscall_arg_1(SYSCALL_HASH('_rtl_debug_break'));
+ libsys_syscall_arg_1(SYSCALL_HASH("_rtl_debug_break"));
}
}
|
