feat(libSceLibcInternal): read time fields and build time_get/time_put facets #21895

Merged
MarrasFederico merged 2 commits from upstream-pr/21895 into main 2026-11-16 23:56:36 +00:00
MarrasFederico commented 2026-11-16 20:32:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-16T20:32:30Z.


What

16 time_get and time_put exports of libSceLibcInternal threw NotImplemented. They now work. The code is in the new TimeGetFields.cpp. The stubs leave Export.cpp and InventoryExports6.cpp.

  • Fields. do_get_time, do_get_year and do_get_monthname for char and wchar_t.
    • do_get_time reads HH:MM:SS with ranges [0, 23], [0, 59] and [0, 60]. It fails as soon as the state is not good.
    • do_get_year reads up to 4 digits. With 1 or 2 digits, 0 to 68 become 2000 to 2068 and 69 to 99 stay in the 1900s. With more digits the year is literal. This is the rule #17568 reads from the console libc.prx for std::__sce_v2.
    • do_get_monthname matches month names without case, longest prefix first, through the ctype of the global locale. A partial match fails. It does not set eofbit.
  • _Getint (wchar_t). Reads at most as many digits as the upper bound has. Leading spaces count as digits. It takes a sign, keeps one leading zero and converts with _Stolx. On failure the value is left as it was. It sets eofbit at the end of input.
  • get(fmt, fmtend) and _Getfmt (wchar_t). get clears the state, stops once it is not good, skips spaces, matches literals without case and reads the E, O, Q and # modifiers. _Getfmt matches literals with case and sets eofbit at the end. Both call the facet's do_get virtual for each % field.
  • Constructors.
    • time_get<wchar_t>(const char*, size_t) (C1, C2) accepts only "C", through _Locinfo. It fills the first 0x30 bytes: static C-locale names and date order mdy. Its do_get_date, do_get_weekday and do_get slots throw.
    • The time_get D2 destructors free nothing, like the console's single-ret _Tidy.
    • time_put<char> (C1 with _Locinfo, C2) fills its 0xb8 bytes from _Getptimes.
    • time_put<wchar_t> (C1) writes only the 0x10-byte facet header and does not call _Init.
  • Still a stub. time_put<wchar_t>::_Init keeps throwing, now with its real signature: its _Tnames past +0x10 is unverified.
  • Debt. A fragment removes the 16 stub entries and adds two entries. They record the unverified layout past 0x2c and 0x10, the static month table of time_get<char> and the slots that still throw.

Parsing follows Dinkumware's xloctime as kept in microsoft/STL at 770da5aa45. The licence notice is at the top of the file.

Tested

Ubuntu 26.04.1 LTS, GCC 15.2.0, Release, BUILD_TESTING=ON. Branch based on 207fca028a; it merges with main at f2a25e5b42 without conflicts. Not run in a title.

  • New test guest_libc_internal_time_get_fields. It reads from buffered and unbuffered (underflow/uflow) stream buffers. It covers construction, reference counts and untouched bytes past the wchar_t facets, _Getint (width, leading zeros and spaces, sign, range, end of input), the three field readers for both character types, get and _Getfmt with a custom ctype<wchar_t>, and null arguments.
  • ctest -R "^(guest_libc_internal_(time_get|time_get_fields|facet_put|facet_queries|empty_facet_members|locale_objects|wide_ctype|showmanyc|num_get)|guest_locale|guest_strftime|guest_ctype_case)$": 12 of 12 passed. The new test passed 3 runs in a row.
  • Negative control: with case-sensitive month matching, the test fails on do_get_monthname case-insensitive full name.
  • tools/check_conventions.py, test_public_headers.py --audit-only and git diff --check pass.
  • tools/pr_overlap.py --names: no open PR implements these 17 names. --branch: no open PR shares an export or a new file. #19434, #19602, #19609, #20059 and #20834 touch nearby lines: the end of CMakeLists.txt and libSceLibcInternal.hpp, and the stubs next to do_date_order in Export.cpp. #13778, #14834, #17300 and #18135 could not be compared automatically; by hand, none of them changes these 17 functions.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5344603370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21895). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-11-16T20:32:30Z. --- ### What 16 `time_get` and `time_put` exports of `libSceLibcInternal` threw `NotImplemented`. They now work. The code is in the new `TimeGetFields.cpp`. The stubs leave `Export.cpp` and `InventoryExports6.cpp`. - **Fields.** `do_get_time`, `do_get_year` and `do_get_monthname` for `char` and `wchar_t`. - `do_get_time` reads `HH:MM:SS` with ranges `[0, 23]`, `[0, 59]` and `[0, 60]`. It fails as soon as the state is not good. - `do_get_year` reads up to 4 digits. With 1 or 2 digits, 0 to 68 become 2000 to 2068 and 69 to 99 stay in the 1900s. With more digits the year is literal. This is the rule #17568 reads from the console `libc.prx` for `std::__sce_v2`. - `do_get_monthname` matches month names without case, longest prefix first, through the `ctype` of the global locale. A partial match fails. It does not set `eofbit`. - **`_Getint` (`wchar_t`).** Reads at most as many digits as the upper bound has. Leading spaces count as digits. It takes a sign, keeps one leading zero and converts with `_Stolx`. On failure the value is left as it was. It sets `eofbit` at the end of input. - **`get(fmt, fmtend)` and `_Getfmt` (`wchar_t`).** `get` clears the state, stops once it is not good, skips spaces, matches literals without case and reads the `E`, `O`, `Q` and `#` modifiers. `_Getfmt` matches literals with case and sets `eofbit` at the end. Both call the facet's `do_get` virtual for each `%` field. - **Constructors.** - `time_get<wchar_t>(const char*, size_t)` (C1, C2) accepts only `"C"`, through `_Locinfo`. It fills the first `0x30` bytes: static C-locale names and date order `mdy`. Its `do_get_date`, `do_get_weekday` and `do_get` slots throw. - The `time_get` D2 destructors free nothing, like the console's single-`ret` `_Tidy`. - `time_put<char>` (C1 with `_Locinfo`, C2) fills its `0xb8` bytes from `_Getptimes`. - `time_put<wchar_t>` (C1) writes only the `0x10`-byte facet header and does not call `_Init`. - **Still a stub.** `time_put<wchar_t>::_Init` keeps throwing, now with its real signature: its `_Tnames` past `+0x10` is unverified. - **Debt.** A fragment removes the 16 stub entries and adds two entries. They record the unverified layout past `0x2c` and `0x10`, the static month table of `time_get<char>` and the slots that still throw. Parsing follows Dinkumware's `xloctime` as kept in microsoft/STL at `770da5aa45`. The licence notice is at the top of the file. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04.1 LTS, GCC 15.2.0, Release, `BUILD_TESTING=ON`. Branch based on `207fca028a`; it merges with `main` at `f2a25e5b42` without conflicts. Not run in a title. - New test `guest_libc_internal_time_get_fields`. It reads from buffered and unbuffered (`underflow`/`uflow`) stream buffers. It covers construction, reference counts and untouched bytes past the `wchar_t` facets, `_Getint` (width, leading zeros and spaces, sign, range, end of input), the three field readers for both character types, `get` and `_Getfmt` with a custom `ctype<wchar_t>`, and null arguments. - `ctest -R "^(guest_libc_internal_(time_get|time_get_fields|facet_put|facet_queries|empty_facet_members|locale_objects|wide_ctype|showmanyc|num_get)|guest_locale|guest_strftime|guest_ctype_case)$"`: 12 of 12 passed. The new test passed 3 runs in a row. - Negative control: with case-sensitive month matching, the test fails on `do_get_monthname case-insensitive full name`. - `tools/check_conventions.py`, `test_public_headers.py --audit-only` and `git diff --check` pass. - `tools/pr_overlap.py --names`: no open PR implements these 17 names. `--branch`: no open PR shares an export or a new file. #19434, #19602, #19609, #20059 and #20834 touch nearby lines: the end of `CMakeLists.txt` and `libSceLibcInternal.hpp`, and the stubs next to `do_date_order` in `Export.cpp`. #13778, #14834, #17300 and #18135 could not be compared automatically; by hand, none of them changes these 17 functions. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-16 21:35:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T21:35:00Z.

Review: COMMENTED


Reviewed — comments

This implementation has focused host-side tests, but the review is incomplete because not every changed line and changed file was inspected.

What I ran

Reviewed head 6dcaff9ed730247f78ec7ea659ee8dd6387b5b16. No commands or tests were run by this reviewer; the description reports Ubuntu 26.04.1, GCC 15.2.0 tests and checks, which I did not independently run.

Results

Check Result Note
Reported test suite not run Author-reported only
Reviewer checks not run No command execution available
Source review not run Several changed files and added lines remain unread

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Not verified

The full added test source, changed export and inventory files, and portions of the manifest and diff were not inspected. In particular, the tests do not independently verify iterator behavior against production stream buffers, and no console behavior was confirmed. Files read: description.md, commits.md, README.md, manifest.json (partial), diff.patch (partial), TimeGetFields.cpp, TimeGetFields.hpp, libSceLibcInternal.hpp, CMakeLists.txt (partial), and the debt change record. The changed files reported by the manifest are CMakeLists.txt, Export.cpp, InventoryExports6.cpp, TimeGetFields.cpp, InventoryExports6.hpp, PendingExports.hpp, TimeGetFields.hpp, libSceLibcInternal.hpp, GuestLibcInternalTimeGetFields.cpp, and feat-libcinternal-time-get-fields.md; not all were fully reviewed.

To get this to a good state

Nothing is required. The author may share the console verification status when available.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5928140837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21895#pullrequestreview-5928140837). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T21:35:00Z. **Review:** COMMENTED --- # Reviewed — comments This implementation has focused host-side tests, but the review is incomplete because not every changed line and changed file was inspected. ## What I ran Reviewed head `6dcaff9ed730247f78ec7ea659ee8dd6387b5b16`. No commands or tests were run by this reviewer; the description reports Ubuntu 26.04.1, GCC 15.2.0 tests and checks, which I did not independently run. ## Results | Check | Result | Note | |---|---|---| | Reported test suite | not run | Author-reported only | | Reviewer checks | not run | No command execution available | | Source review | not run | Several changed files and added lines remain unread | ## Findings ### Blocking None verified in the inspected code. ### Non-blocking None. ## Not verified The full added test source, changed export and inventory files, and portions of the manifest and diff were not inspected. In particular, the tests do not independently verify iterator behavior against production stream buffers, and no console behavior was confirmed. Files read: `description.md`, `commits.md`, `README.md`, `manifest.json` (partial), `diff.patch` (partial), `TimeGetFields.cpp`, `TimeGetFields.hpp`, `libSceLibcInternal.hpp`, `CMakeLists.txt` (partial), and the debt change record. The changed files reported by the manifest are `CMakeLists.txt`, `Export.cpp`, `InventoryExports6.cpp`, `TimeGetFields.cpp`, `InventoryExports6.hpp`, `PendingExports.hpp`, `TimeGetFields.hpp`, `libSceLibcInternal.hpp`, `GuestLibcInternalTimeGetFields.cpp`, and `feat-libcinternal-time-get-fields.md`; not all were fully reviewed. ## To get this to a good state Nothing is required. The author may share the console verification status when available.
PrivacyOnion commented 2026-11-16 22:28:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T22:28:27Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 819d98b3e9:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_time_get_fields_tests built cleanly.
  • CTest (guest_libc_internal_time_get_fields):
    1/1 Test #4144: guest_libc_internal_time_get_fields ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Export.cpp, core/libs/prx/libSceLibcInternal/InventoryExports6.cpp, core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp, core/libs/prx/libSceLibcInternal/include/PendingExports.hpp, core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp, core/libs/prx/libSceLibcInternal/TimeGetFields.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4144: guest_libc_internal_time_get_fields ...Subprocess aborted***Exception:   0.36 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified null and bounds checks in TimeGetFields.cpp across all exports (e.g. RequireArgument guards for self, state, time, iterators, and format strings).
    • Verified streambuf virtual dispatch and iterator management in Peek, Inc, and Equal in TimeGetFields.cpp.
    • Verified GetIntV2 digit counting, sign handling, prefix zeroes, and range validation against lo and hi using _Stolx_nid_postfix.
    • Verified DoGetTimeImpl, DoGetYearImpl, and DoGetMonthnameImpl against Microsoft STL xloctime/xlocale behavior and console libc specifications.
    • Verified wide character facet table definitions, vtables, refcounting atomics, and locinfo scoped destruction in TimeGetFields.cpp.
    • Verified AGENTS.md compliance, conventional commits, debt fragment format, and export replacements from Export.cpp and InventoryExports6.cpp.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5928955682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21895#pullrequestreview-5928955682). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T22:28:27Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `819d98b3e9`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_time_get_fields_tests` built cleanly. - **CTest** (`guest_libc_internal_time_get_fields`): ``` 1/1 Test #4144: guest_libc_internal_time_get_fields ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/Export.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports6.cpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp`, `core/libs/prx/libSceLibcInternal/include/PendingExports.hpp`, `core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp`, `core/libs/prx/libSceLibcInternal/TimeGetFields.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4144: guest_libc_internal_time_get_fields ...Subprocess aborted***Exception: 0.36 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified null and bounds checks in TimeGetFields.cpp across all exports (e.g. RequireArgument guards for self, state, time, iterators, and format strings). - Verified streambuf virtual dispatch and iterator management in Peek, Inc, and Equal in TimeGetFields.cpp. - Verified GetIntV2 digit counting, sign handling, prefix zeroes, and range validation against lo and hi using _Stolx_nid_postfix. - Verified DoGetTimeImpl, DoGetYearImpl, and DoGetMonthnameImpl against Microsoft STL xloctime/xlocale behavior and console libc specifications. - Verified wide character facet table definitions, vtables, refcounting atomics, and locinfo scoped destruction in TimeGetFields.cpp. - Verified AGENTS.md compliance, conventional commits, debt fragment format, and export replacements from Export.cpp and InventoryExports6.cpp. 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!21895
No description provided.