diff options
| author | 😄 Amlal El Mahrouss <amlal@nekernel.org> | 2026-03-24 12:37:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-24 12:37:20 +0100 |
| commit | 48a0084c66f43eb2206fdfd757fb026bbd90d1eb (patch) | |
| tree | 7ded7e3fddec1a79e134451e4be5bce0b3244897 /src | |
| parent | 5b5081e679a0481356d1e026310546ac632b1c87 (diff) | |
| parent | 6cf854b950e3884d6b5a08eb6059d1780f4d19db (diff) | |
Merge pull request #144 from ne-foss-org/user-system-utf8
[FEAT] Kernel: UTF-8 usage in UserMgr.
Diffstat (limited to 'src')
| -rw-r--r-- | src/kernel/KernelKit/Semaphore.h | 7 | ||||
| -rw-r--r-- | src/kernel/KernelKit/User.h | 13 | ||||
| -rw-r--r-- | src/kernel/src/Property.cpp | 2 | ||||
| -rw-r--r-- | src/kernel/src/RT/.keep | 0 | ||||
| -rw-r--r-- | src/kernel/src/RT/README.txt | 4 | ||||
| -rw-r--r-- | src/kernel/src/User.cpp | 15 | ||||
| -rw-r--r-- | src/libSystem/SystemKit/System.h | 6 |
7 files changed, 36 insertions, 11 deletions
diff --git a/src/kernel/KernelKit/Semaphore.h b/src/kernel/KernelKit/Semaphore.h index bb6b9ba9..4dc9a454 100644 --- a/src/kernel/KernelKit/Semaphore.h +++ b/src/kernel/KernelKit/Semaphore.h @@ -29,6 +29,7 @@ using SemaphoreArr = UInt64[kSemaphoreCount]; /// @brief Checks if the semaphore is valid. inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) { + if (!sem) return false; return sem[kSemaphoreOwnerIndex] == owner && sem[kSemaphoreCountIndex] > 0; } @@ -36,6 +37,8 @@ inline bool rtl_sem_is_valid(const SemaphoreArr& sem, const UInt64& owner = 0) { /// @param sem /// @return inline bool rtl_sem_release(SemaphoreArr& sem) { + if (!sem) return false; + sem[kSemaphoreOwnerIndex] = 0; sem[kSemaphoreCountIndex] = 0; @@ -47,6 +50,8 @@ inline bool rtl_sem_release(SemaphoreArr& sem) { /// @param owner the owner to set, could be anything identifitable. /// @return inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) { + if (!sem) return false; + if (!owner) { err_global_get() = kErrorInvalidData; return false; // Invalid owner, return false and set KPC. @@ -65,6 +70,8 @@ inline bool rtl_sem_acquire(SemaphoreArr& sem, const UInt64& owner) { /// @return inline bool rtl_sem_wait(SemaphoreArr& sem, const UInt64& owner, const UInt64& timeout, bool& condition) { + if (!sem) return false; + if (!rtl_sem_is_valid(sem, owner)) { return false; } diff --git a/src/kernel/KernelKit/User.h b/src/kernel/KernelKit/User.h index bae51180..cc64bd1c 100644 --- a/src/kernel/KernelKit/User.h +++ b/src/kernel/KernelKit/User.h @@ -42,16 +42,16 @@ enum struct UserRingKind : Int32 { kRingCount = 3, }; -using UserPublicKey = Char*; -using UserPublicKeyType = Char; +using UserPublicKey = Char8*; +using UserPublicKeyType = Char8; /// @brief System User class. class User final { public: User() = delete; - User(const Int32& sel, const Char* username); - User(const UserRingKind& kind, const Char* username); + User(const Int32& sel, const UserPublicKeyType* username); + User(const UserRingKind& kind, const UserPublicKeyType* username); ~User(); @@ -82,10 +82,15 @@ class User final { /// @param password the password to check. Bool Login(const UserPublicKey password); + /// @brief Returns whether the user is an adult or not. + Bool IsAdult(); + private: UserRingKind mUserRing{UserRingKind::kRingStdUser}; Char mUserName[kMaxUserNameLen] = {0}; UInt64 mUserFNV{0UL}; + Bool mUserIsAdult{NO}; + }; /// \brief Alias for user ptr. diff --git a/src/kernel/src/Property.cpp b/src/kernel/src/Property.cpp index 6db475e8..6da6ae70 100644 --- a/src/kernel/src/Property.cpp +++ b/src/kernel/src/Property.cpp @@ -6,6 +6,7 @@ #include <CFKit/Property.h> namespace Kernel::CF { + /***********************************************************************************/ /// @brief Destructor. /***********************************************************************************/ @@ -37,4 +38,5 @@ KBasicString<>& Property::GetKey() { PropertyId& Property::GetValue() { return fValue; } + } // namespace Kernel::CF diff --git a/src/kernel/src/RT/.keep b/src/kernel/src/RT/.keep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/kernel/src/RT/.keep diff --git a/src/kernel/src/RT/README.txt b/src/kernel/src/RT/README.txt new file mode 100644 index 00000000..d85b9570 --- /dev/null +++ b/src/kernel/src/RT/README.txt @@ -0,0 +1,4 @@ +NeKernel Real-Time Patches +========================== + +This patchset transforms NeKernel into a real-time OS, although designed for backend/server purposes.
\ No newline at end of file diff --git a/src/kernel/src/User.cpp b/src/kernel/src/User.cpp index 3f5bb66a..6fd2e7b3 100644 --- a/src/kernel/src/User.cpp +++ b/src/kernel/src/User.cpp @@ -23,7 +23,7 @@ namespace Detail { /// \param password password to hash. /// \return the hashed password //////////////////////////////////////////////////////////// - STATIC UInt64 user_fnv_generator(const Char* password, User* user) { + STATIC UInt64 user_fnv_generator(const UserPublicKeyType* password, User* user) { kout << "user_fnv_generator: Try hashing user password...\r"; if (!password || !user) return 0; @@ -48,18 +48,17 @@ namespace Detail { //////////////////////////////////////////////////////////// /// @brief User ring constructor. //////////////////////////////////////////////////////////// -User::User(const Int32& sel, const Char* user_name) : mUserRing((UserRingKind) sel) { +User::User(const Int32& sel, const UserPublicKeyType* user_name) : mUserRing((UserRingKind) sel) { MUST_PASS(sel >= 0); - rt_copy_memory_safe((VoidPtr) user_name, this->mUserName, rt_string_len(user_name), - kMaxUserNameLen); + urt_copy_memory((VoidPtr) user_name, this->mUserName, urt_string_len(user_name)); } //////////////////////////////////////////////////////////// /// @brief User ring constructor. //////////////////////////////////////////////////////////// -User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(ring_kind) { - rt_copy_memory_safe((VoidPtr) user_name, this->mUserName, rt_string_len(user_name), - kMaxUserNameLen); +User::User(const UserRingKind& ring_kind, const UserPublicKeyType* user_name) + : mUserRing(ring_kind) { + urt_copy_memory((VoidPtr) user_name, this->mUserName, urt_string_len(user_name)); } //////////////////////////////////////////////////////////// @@ -67,6 +66,8 @@ User::User(const UserRingKind& ring_kind, const Char* user_name) : mUserRing(rin //////////////////////////////////////////////////////////// User::~User() = default; +Bool User::IsAdult() { return mUserIsAdult; } + Bool User::Save(const UserPublicKey password) { if (!password || *password == 0) return No; diff --git a/src/libSystem/SystemKit/System.h b/src/libSystem/SystemKit/System.h index 324aae5c..7e4a9ae6 100644 --- a/src/libSystem/SystemKit/System.h +++ b/src/libSystem/SystemKit/System.h @@ -408,4 +408,10 @@ IMPORT_C SInt32 SemWait(_Input SemaphoreRef sem); /// @brief Close a semaphore. IMPORT_C SInt32 SemClose(_Input SemaphoreRef sem); +// ------------------------------------------------------------------------------------------ // +// @brief User AgeAuth API. +// ------------------------------------------------------------------------------------------ // + +IMPORT_C SInt32 UserIsAdult(_Input SInt32 uid); + #endif // ifndef SYSTEMKIT_SYSTEM_H |
