feat(libSceLibcInternal): implement spin lock, time and zone helpers #22431

Merged
heditrigui merged 1 commit from upstream-pr/22431 into main 2026-11-18 09:42:06 +00:00
heditrigui commented 2026-11-17 15:21:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by heditrigui on 2026-11-17T15:21:47Z.


What

Implements _Lock_spin_lock, _Unlock_spin_lock, _Getzone, _Tzoff, and _Gettime in libSceLibcInternal per Dinkumware libc specifications and firmware 13.42 disassembly:

  • _Lock_spin_lock and _Unlock_spin_lock: Dinkumware atomic 1-byte spinlock synchronization using __atomic_exchange_n with acquire semantics and pause instruction spinning, and __atomic_store_n with release semantics.
  • _Getzone: returns the standard timezone separator string ":".
  • _Tzoff: returns 0 for standard UTC offset.
  • _Gettime: parses separator-delimited time string tokens, extracting field pointers and token lengths.

Tested

  • Added host-only unit test suite guest_libc_internal_time_lock_tests in core/libs/tests/GuestLibcInternalTimeLock.cpp testing single-threaded acquire/release, 4-worker concurrent stress test with 10,000 iterations to verify mutex mutual exclusion and avoid race conditions, null pointer safety, zone string validation, tzoff return value, and token extraction across boundary conditions (multi-field strings, negative indices, out-of-bounds indices, empty and null strings).
  • Verified tools/check_conventions.py --base upstream/main passes with 0 findings.
  • Verified line endings with git diff --check.

Checklist

  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5359653013 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22431). Originally posted by [heditrigui](https://github.com/heditrigui) on 2026-11-17T15:21:47Z. --- ### What Implements `_Lock_spin_lock`, `_Unlock_spin_lock`, `_Getzone`, `_Tzoff`, and `_Gettime` in `libSceLibcInternal` per Dinkumware libc specifications and firmware 13.42 disassembly: - `_Lock_spin_lock` and `_Unlock_spin_lock`: Dinkumware atomic 1-byte spinlock synchronization using `__atomic_exchange_n` with acquire semantics and pause instruction spinning, and `__atomic_store_n` with release semantics. - `_Getzone`: returns the standard timezone separator string `":"`. - `_Tzoff`: returns 0 for standard UTC offset. - `_Gettime`: parses separator-delimited time string tokens, extracting field pointers and token lengths. ### Tested - Added host-only unit test suite `guest_libc_internal_time_lock_tests` in `core/libs/tests/GuestLibcInternalTimeLock.cpp` testing single-threaded acquire/release, 4-worker concurrent stress test with 10,000 iterations to verify mutex mutual exclusion and avoid race conditions, null pointer safety, zone string validation, tzoff return value, and token extraction across boundary conditions (multi-field strings, negative indices, out-of-bounds indices, empty and null strings). - Verified `tools/check_conventions.py --base upstream/main` passes with 0 findings. - Verified line endings with `git diff --check`. ### Checklist - [x] Depends on: none - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-17 15:24:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T15:24:08Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 71308fce31:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_time_lock_tests built cleanly.
  • CTest (guest_libc_internal_time_lock):
    1/1 Test #4149: guest_libc_internal_time_lock ....   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Export.cpp, core/libs/prx/libSceLibcInternal/InventoryExports2.cpp, core/libs/prx/libSceLibcInternal/include/InventoryExports2.hpp, core/libs/prx/libSceLibcInternal/include/RuntimeInternals.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified _Lock_spin_lock_nid_postfix and _Unlock_spin_lock_nid_postfix handle nullptr lock safely and perform atomic exchange/store with acquire/release memory orderings and pause spin on x86/x64
    • Verified _Getzone_nid_postfix returns static literal ":" matching Dinkumware timezone delimiter format
    • Verified _Tzoff_nid_postfix returns 0 for standard UTC offset as documented and implemented in libc debt fragment
    • Verified _Gettime_nid_postfix null check on 's' and length out-pointer handling for all branches (empty string, out-of-bounds index, negative index, null len pointer)
    • Verified docs/dev/debt/changes fragment feat-libc-internal-time-lock-helpers.md format, header declarations in RuntimeInternals.hpp/InventoryExports2.hpp, and CTest integration in CMakeLists.txt

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5941288289 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22431#pullrequestreview-5941288289). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T15:24:08Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `71308fce31`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_time_lock_tests` built cleanly. - **CTest** (`guest_libc_internal_time_lock`): ``` 1/1 Test #4149: guest_libc_internal_time_lock .... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/Export.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports2.cpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports2.hpp`, `core/libs/prx/libSceLibcInternal/include/RuntimeInternals.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified _Lock_spin_lock_nid_postfix and _Unlock_spin_lock_nid_postfix handle nullptr lock safely and perform atomic exchange/store with acquire/release memory orderings and pause spin on x86/x64 - Verified _Getzone_nid_postfix returns static literal \":\" matching Dinkumware timezone delimiter format - Verified _Tzoff_nid_postfix returns 0 for standard UTC offset as documented and implemented in libc debt fragment - Verified _Gettime_nid_postfix null check on 's' and length out-pointer handling for all branches (empty string, out-of-bounds index, negative index, null len pointer) - Verified docs/dev/debt/changes fragment feat-libc-internal-time-lock-helpers.md format, header declarations in RuntimeInternals.hpp/InventoryExports2.hpp, and CTest integration in CMakeLists.txt Looks Good To Me
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!22431
No description provided.