Commit Graph

26 Commits

Author SHA1 Message Date
David 7126090654 fix(libc): convert local times before 1970 and after 3000 on Windows 2026-10-13 01:47:03 +00:00
Dean 0ef9dc9282
Merge pull request #4277 from BharatYadav007/bharat/libc-mktime-negative-one
fix(libc): normalize valid mktime minus-one results
2026-10-13 01:30:26 +13:00
Dean e50326224c
Merge pull request #4103 from yunusshaikh7/fix/libc-difftime-negative-times-windows
fix(libc): subtract negative times in difftime on Windows
2026-10-13 01:29:12 +13:00
Dean 256cc9f976
Merge pull request #4099 from yunusshaikh7/fix/libc-asctime-years-before-1900-windows
fix(libc): format years before 1900 in asctime on Windows
2026-10-13 01:28:18 +13:00
BharatYadav007 f0e852ae27 fix(libc): normalize valid mktime minus-one results 2026-10-12 10:18:20 +05:30
Yunus Shaikh 1b009e1879 fix(libc): subtract negative times in difftime on Windows
difftime and libc_difftime passed their arguments to the host CRT.
UCRT's _difftime64 returns 0 and sets errno to EINVAL when either
argument is negative (common_difftime in ucrt/time/difftime.cpp), so
on Windows difftime(0, -1) returned 0 instead of 1 and every
difference involving a time before 1970 was 0. C17 7.27.2.2 defines
the result as time1 - time0, and FreeBSD 11's difftime
(contrib/tzcode/stdtime/difftime.c) and glibc on the Linux build
compute it for any arguments.

Subtract the smaller time from the larger as uint64_t, which cannot
overflow, convert the difference to double and negate it when time1
is the smaller one, as FreeBSD and glibc's fallback path do. The
result is time1 - time0 rounded once to double on both hosts.
difftime now forwards to libc_difftime like the other aliases in the
file.
2026-10-11 16:12:25 -07:00
Yunus Shaikh 7cc5698094 fix(libc): format years before 1900 in asctime on Windows
asctime passed the guest tm to the host CRT. UCRT's asctime returns
null and sets errno to EINVAL when tm_year is negative or tm_mday is
past the end of the month (common_asctime_s in ucrt/time/asctime.cpp),
so on Windows asctime of any time in the years 1000 to 1899, which
gmtime converts, or of February 29 in a common year returned null.
C17 7.27.3.1 defines the text for every year from 1000 to 9999 when
each member is in its normal range (tm_mday 1 to 31), and glibc on
the Linux build and FreeBSD 11's asctime
(contrib/tzcode/stdtime/asctime.c) print it.

Format the text with the C17 algorithm's format into a thread-local
buffer that fits any member values. As in glibc and FreeBSD, a
weekday or month outside its range is printed as ???, and the year is
computed in 64 bits.
2026-10-11 16:08:53 -07:00
QRMOE 1b9179501f
fix(libc): preserve strftime literal conversions
Normalize FreeBSD 11.4 literal conversions before host formatting.

AI-assisted: yes
2026-10-11 16:51:42 +02:00
Adrià 08e0079e4d
Merge pull request #3451 from LeandroLP23/fix/libc-time-strftime-freebsd-conversions
fix(libc): format %k, %l, %s, %v and %+ in strftime
2026-10-11 13:46:24 +02:00
Hussein Kadhim 84926887e9 fix(libc): keep the literal percent after E and O in strftime
A format such as %E%k is a modified percent sign followed by a literal k, so the second percent must not start a new conversion.
2026-10-11 12:05:00 +02:00
Hussein Kadhim c5bc118f4b fix(libc): accept E and O before new strftime conversions and take %+ zone from tm 2026-10-11 12:05:00 +02:00
Hussein Kadhim 7e3a409022 fix(libc): format %k, %l, %s, %v and %+ in strftime 2026-10-11 12:05:00 +02:00
Pouare514 5290f92876 fix(libs): share Sony CRT semantics between libc and libSceAmpr with tests 2026-10-11 11:42:31 +02:00
Adrià Franch ef2d56eb9c feat(libc): implement ctime
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-11 02:58:30 +02:00
Hannah Lyons 502dae1ef3 feat(libc): implement tzset 2026-10-10 18:37:10 -04:00
Adrià 2337e0d5d6
Merge pull request #2031 from Aryansh1520/fix/libc-tz-once
perf(libc): set TZ once on Linux
2026-10-10 08:08:28 +02:00
Mohd Faour 0aae158635 fix(libc): convert times into the guest's 56-byte tm on Windows
gmtime, localtime, mktime, strftime and asctime took and returned the
host std::tm. The guest's FreeBSD tm has tm_gmtoff and tm_zone after the
nine calendar fields, so on Windows, where std::tm is 36 bytes, a title
reading those fields read past the thread-local result, and gmtime_s left
them unwritten. Windows gmtime_s also accepts only 1969-12-31 12:00 to
3001-01-19 21:59 UTC, where the guest libc converts any time.

Convert through a GuestTm with the guest layout on both hosts. Compute
the UTC fields from the day count, so every time whose year fits an int
converts, and on Windows take the local offset and zone name from the
CRT. gmtime reports the zone as UTC like the guest libc. localtime and
mktime keep the CRT's range on Windows; recorded in TechnicalDebt.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-10 02:13:17 +02:00
Aryan Sharma 631654b649 perf(libc): limit the TZ initializer to Linux 2026-10-09 11:16:57 +05:30
Aryan Sharma 11b32af522 perf(libc): set TZ once on Linux
Without TZ, glibc's localtime and mktime run tzset on every call and
re-check /etc/localtime each time. PPSA28997 calls them every frame
during its intro, which then spent most of its time there. TZ is set
to :/etc/localtime when unset, so the zone is read once.
2026-10-09 10:59:48 +05:30
Sanjaysrinivas 69901c9ac8 fix(libc): avoid time conversion races 2026-10-07 21:40:31 +02:00
Adrià Franch 3f2e5150c2 feat(libc): implement _Xtime_get_ticks
Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-05 20:16:11 +02:00
Dean Galvin a599eca727 feat(libc): operator new/delete, bounds-checked functions, char locale facets and runtime helpers
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
2026-09-28 14:22:48 +13:00
devilismyfriend f3ac61000d feat(runtime): guest arena, kernel thread/sync/file APIs, crash hooks
- libc: reserve guest memory in one arena below the PS5 map limit with
  MEM_WRITE_WATCH (GuestArena) and a caching guest heap; the allocation
  registry gains a generation counter, an invalidator callback for the
  driver's page cache and a pin waiter for leased ranges. This replaces
  the fault-based GuestMemoryTracking/GuestMemoryBacking layer, whose
  files are removed.
- libkernel: mmap/mprotect/munmap on the arena, flexible memory budget,
  real sceKernelVirtualQuery; POSIX pthread layer, rwlocks, timed locks,
  TSD, event flags; 0.5 ms scheduler tick and high-resolution sleeps;
  TSC/clock/time functions; file APIs return SCE errno codes; the APR
  file-streaming API.
- libc: vectored crash reporter with backtraces for fatal exceptions,
  SIGABRT, UCRT invalid parameters and process exit; SSE4a EXTRQ/INSERTQ
  emulation for Intel hosts; %ls/%lc/%S/%C with the guest's 16-bit
  wchar_t; hand-written setjmp/longjmp for the guest jmp_buf; a path
  alias table for short save-data mount points; more string, stdio and
  math exports.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0177gthrWEBBfBu5xJDXgBfo
2026-09-25 16:27:49 -07:00
boykopovar 67b778055a refactor(libs): use local cmakelists in libc 2026-09-11 12:22:19 +03:00
boykopovar abc72da741 feat(libs): define vabi macros + add to declarations 2026-09-10 08:07:03 +03:00
boykopovar 5a1d7525f9 feat(libs): libc impl (wip) 2026-08-22 16:00:29 +03:00