diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-09-28 14:18:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-28 14:18:55 +0200 |
| commit | 643fd1890646442e97f61c323bb1342ccae8c46b (patch) | |
| tree | 1dccc97ea6d52012d682f664995959fe7db9ddd1 /dev/libSystem/SystemKit | |
| parent | dfad97487744840f26ea8046d1a011688bd9edd0 (diff) | |
| parent | 2d673e164b98db5eb08d4c41c6225fbe73ee82d7 (diff) | |
Merge pull request #66 from 0xf00sec/patch-2
feat: `T.Value` (ErrorOr.h)
Diffstat (limited to 'dev/libSystem/SystemKit')
| -rw-r--r-- | dev/libSystem/SystemKit/Syscall.h | 18 | ||||
| -rw-r--r-- | dev/libSystem/SystemKit/Verify.h | 40 |
2 files changed, 42 insertions, 16 deletions
diff --git a/dev/libSystem/SystemKit/Syscall.h b/dev/libSystem/SystemKit/Syscall.h index a1505b46..35bfc6f8 100644 --- a/dev/libSystem/SystemKit/Syscall.h +++ b/dev/libSystem/SystemKit/Syscall.h @@ -14,22 +14,8 @@ 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) { - if (!path || *path == 0) return 0; - - 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; -} +IMPORT_C UInt64 libsys_hash_64(const Char* path); #ifndef SYSCALL_HASH #define SYSCALL_HASH(str) libsys_hash_64(str) -#endif // !SYSCALL_HASH
\ No newline at end of file +#endif // !SYSCALL_HASH diff --git a/dev/libSystem/SystemKit/Verify.h b/dev/libSystem/SystemKit/Verify.h new file mode 100644 index 00000000..cbf85830 --- /dev/null +++ b/dev/libSystem/SystemKit/Verify.h @@ -0,0 +1,40 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + + File: Verify.h + Purpose: System Call Interface Verification Layer. + + ------------------------------------------- */ + +#pragma once + +#include <libSystem/SystemKit/System.h> + +namespace LibSystem::Detail { +/// @author 0xf00sec, and Amlal El Mahrouss +/// @brief safe cast operator. +template <typename T, typename R = VoidPtr> +inline R sys_safe_cast(const T* ptr) { + _rtl_assert(ptr, "safe cast failed!"); + return static_cast<R>(const_cast<T*>(ptr)); +} + +template <typename T, typename U> +struct must_cast_traits { + constexpr static BOOL value = false; +}; + +template <typename T> +struct must_cast_traits<T, T> { + constexpr static BOOL value = true; +}; + +/// @author Amlal El Mahrouss +/// @brief Safe constexpr cast. +template <typename T, typename R> +inline constexpr R* sys_constexpr_cast(T* ptr) { + static_assert(must_cast_traits<T, R>::value, "constexpr cast failed! types are a mismatch!"); + return static_cast<R*>(ptr); +} +} // namespace LibSystem::Detail |
