fix(libc): write a 36-byte struct tm as the console does #10409
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10409"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-23T21:59:04Z.
What
The console's
struct tmis nineints, 36 bytes, with notm_gmtoffortm_zone. AnyPS5'sGuestTmwas the 56-byte FreeBSD layout, somktime,timegm,localtime_s,localtime_r,gmtime_sandgmtime_rwrote 20 bytes past a guest'sstruct tm, andstrftimeread the same 20 bytes back as an offset and a zone-name pointer. A guest with itsstruct tmon the stack has its canary overwritten and aborts on return.GuestTmis now 36 bytes:strftimekeepsmain's%zcode from #10129, which reads the guest zone globals:%zis the guesttimezoneoffset, one hour more only whentm_isdstis positive, printed for anytm_isdstincluding -1.%Zprints nothing, as on the console: a PS4 Pro (firmware 10.71) prints nothing for it and exports notzname(probe below), and the PS5 payload #10129 measured printed nothing either.tznameand the UTF-8 names from #10987 stay; they just do not reach the guest throughstruct tmor%Z;gmtime_sstorestm_isdst-1 andgmtimestores 0, as measured on the console (below);gmtime_randtimegmfollowgmtime, as in FreeBSD (not measured).mktimetherefore reads agmtimeresult as standard time, as the console does;tzsetsets 0 on its own UTC copy sotimezonestays the standard offset.guest_mktimegains a guard-byte test: each conversion gets a 64-byte 0xAA buffer and the bytes from 36 on must stay 0xAA. The tests that read the two removed fields now check the hour or the formatted text instead;guest_strftimegains a regression in itsUTC+3zone: agmtime_sresult (tm_isdst-1) formats%z|%Zas-0300|.guest_time_conversion's POSIX-zone check (Windows) derives the offset withtimegminstead oftm_gmtoff.The branch has current
mainmerged in;Time.cppismain's with this PR's struct and conversion changes on top, and the tests use the declarations ofprx/libc/include/Api.hpp.Tested
Windows 11, MinGW-w64 GCC (winlibs), Ninja, on this branch with
main828e44310emerged in, three runs each:guest_mktime,guest_strftime,guest_time_conversion,guest_time_extras,guest_wide_formatting,guest_crt,guest_errand the fourguest_ampr_*tests pass. Earlier, on4168860: withmain'sGuestTime.hpp,Time.cppandTimeExtras.cpp,guest_mktimeaborts with "A calendar conversion wrote past the 36-byte struct tm".public_headers(audit) andpython tools/check_conventions.py --base mainpass. edubox's run of Fatal Frame II (PPSA32802) on Linux, above, shows the__stack_chk_failafterlocaltime_sgone with this change.Measured on a PS4 Pro (firmware 10.71) with a homebrew probe: each call gets a 64-byte buffer filled with 0xAA (the first 36 bytes hold 2026-10-23 12:00:00 for
mktime);touchedis the offset just past the last byte that changed:Bytes 36 to 63 stay 0xAA in all six calls, for the system
libc.sprxand forlibSceLibcInternal.sprx. The firmware 10.71libSceLibcInternal.sprxagrees:mktime(offset 0xc230) reads offsets 0x0 to 0x20 of its argument, and the routine it andgmtime_s(0x1930) store through (0x1ff70) writes only offsets 0x0 to 0x20. Not run with a title.A third probe (
libc_tzname.c, 2026-11-08) callslocaltimeandstrftimefrom the console'slibc.sprx: 1736942400 givestm_isdst0,%Zempty (returns 0) and%z+0100; 1752580800 givestm_isdst1,%Zempty and%z+0200;sceKernelDlsymfinds notzname. The Windows checks #10987 added inguest_time_conversionnow require the same:%Zempty,%zthe zone's offset for that time (derived from the host zone the test runs in) and the zone'stm_isdst. With%Zprintingtznameagain,guest_time_conversionandguest_strftimefail.A second probe on the same console (firmware 10.710.001) calls
gmtimefromlibc.sprx:gmtime(1000000000)returns[40 46 1 9 8 101 0 251 0]andgmtime(951825600)[0 0 12 29 1 100 2 59 0], sotm_isdstis 0 there, andmktimeof either result is one hour earlier than the timestamp (999996400, 951822000): the console's zone is one hour east of UTC in standard time, and both results are read as standard time, the September one included.guest_mktimenow checks both values and that round trip inCET-1CEST; withgmtimestoring -1 again it fails ("gmtime did not store tm_isdst 0").Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T22:53:51Z.
Review: CHANGES_REQUESTED
Blocking compatibility mismatch with the measured console behavior documented in dependency #10129. That PR records that
%zis emitted even whentm_isdst == -1, and%Zselectstzname[tm_isdst > 0](the standard-name slot when the value is -1). This PR makesgmtime_ssettm_isdstto -1, butformatTimecurrently breaks out of%zfor every negative value,guestZoneNamereturns an empty string for%Z, and the updatedunknown dstfixture expects[][]. OnceGuestTmno longer carries zone fields, these paths need to preserve #10129’s measured rule using the guest timezone globals. Please add a regression for a non-UTC guest zone formatted from agmtimeresult and align both conversions with the dependency’s recorded behavior before merging.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T23:29:13Z.
Review: APPROVED
Re-reviewed the updated head. The 36-byte
GuestTmlayout and the%z/%Zhandling now match the console measurements and the behavior recorded in #10129, includingtm_isdst == -1. The added guarded-write and non-UTCgmtimeformatting regressions address my prior finding. No blocking issue remains in this diff.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T08:36:46Z.
Review: COMMENTED
Reviewed — comments
The change addresses the reported
struct tmover-write, but I did not read every reviewed file or run the reported checks, so a formal approval is not justified.What I ran
Reviewed head
42bda7d256cf30779cee7cd93b8ab618d1441d35using the pinnedrepo_read.pyreader. No tests or builds were run.Results
Findings
Blocking
None identified in the portions inspected.
Non-blocking
None.
Not verified
The report says Windows 11 MinGW-w64/Ninja tests and convention checks passed, and describes console probes; these were not run or independently verified. Read the description, commits, manifest, diff,
GuestTime.hpp, portions ofTime.cppandTimeExtras.cpp. The remaining portions ofTime.cpp, and the changed test and documentation files, were not read. All nine changed files are listed as reviewed in the manifest; their full texts were included, but not all were inspected. No files were excluded by the manifest.To get this to a good state
Nothing is required. This is a review comment because the review was incomplete.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T09:38:30Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and tests support the stated 36-byte guest
struct tmlayout and the reported console formatting behavior.What I ran
Reviewed head
28df803867fe7ddaae1a6839ba57985ff06eed3bagainst basemainusing the prepared diff and pinned repository reader. No test commands were run; the Windows and console runs described in the PR body are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read all changed files listed in the manifest and the relevant conversion, formatting, WebKit caller, and test code. I did not run tests or independently verify the console probes, Windows results, title behavior, or CI. The PR description and commit list were read; excluded files: none.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-11-23T23:43:27Z.
Review: CHANGES_REQUESTED
Blocking transitive regression on exact head
28df803867fe7ddaae1a6839ba57985ff06eed3b.The 36-byte
GuestTmchange itself is well supported, but the%Zchange in libc also changes libSceLibcInternal C++time_put<wchar_t>even though this PR only cites console evidence for libc/strftime behavior.libSceLibcInternal/FacetPut.cppforwards its widedo_puttoLibcWideTimePutDoPut_nid_no_patch, and that helper formats throughwcsftime_nid_postfix. Therefore changing libccase 'Z'to emit nothing makes LibcInternaltime_put<wchar_t>::do_put('%Z')emit nothing too.That is exactly inconsistent with the existing non-Windows regression in
GuestLibcInternalFacetPut.cpp:CheckWideTimePutDoPut()sets a 15-letter zone (ABCDEFGHIJKLMNO0) and requires%Zto produceABCDEFGHIJKLMNO; it separately verifies the 16-letter case returns empty only because the first buffer cannot fit it. oneandonlydean has now reproducedguest_libc_internal_facet_putfailing on this exact head and put the PR on hold until a new head passes it.Please do not just delete/weaken that check without evidence. Either:
%Zbehavior by decoupling its formatter from libc's newly measured%Zrule, while keeping the 36-byte struct and libc%Zfix; or%Zis also empty there, then update the LibcInternal implementation/test deliberately to that measured behavior.Note that
libSceLibcInternal/Export.cpphas its own%Zpath (GentimeField(Zone, ...)) that still emits a zone field, so the current PR otherwise leaves LibcInternal time formatting internally inconsistent.Please rerun
guest_libc_internal_facet_puton the new exact head in addition to the existing libc time tests. Hosted checks being green on this head do not cover this isolated failure.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:36:42Z.
Review: COMMENTED
The Linux integration build stops before the time tests run because strptime still accesses a field removed from GuestTm.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.