From 41703b62f9e7e83fa856fbf53101edc889502c45 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 22 Jun 2025 21:41:15 +0200 Subject: feat: use FNV in libSystem's syscall routing. fix: Add legacy string.h functions back, for GCC. Signed-off-by: Amlal El Mahrouss --- dev/libSystem/SystemKit/Syscall.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'dev/libSystem/SystemKit/Syscall.h') 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 #include -#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 -- cgit v1.2.3 From 34ff4ddd4ddeb4a8262dc86cdddc3677e5bfbc72 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 10 Jul 2025 02:11:33 +0200 Subject: feat: Fix FNV's pointer check. why: - It doesn't have any pointer check. - We could save cycles by also checking for `*path == 0` Signed-off-by: Amlal El Mahrouss --- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 2 ++ dev/libSystem/SystemKit/Syscall.h | 2 ++ 2 files changed, 4 insertions(+) (limited to 'dev/libSystem/SystemKit/Syscall.h') diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 8092f53b..344369d5 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -89,6 +89,8 @@ namespace Detail { /// @param path the directory path. /// @return The hashed path. STATIC UInt64 hefsi_hash_64(const Utf8Char* path) { + if (!path || *path == 0) return 0; + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; const UInt64 FNV_PRIME = 0x100000001b3ULL; diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index 5a840df1..a1505b46 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -15,6 +15,8 @@ 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) { + if (!path || *path == 0) return 0; + const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; const UInt64 FNV_PRIME = 0x100000001b3ULL; -- cgit v1.2.3