Commit Graph

2240 Commits

Author SHA1 Message Date
screamm e99816e8f3 fix(libkernel): give guest sockets ordinary descriptor numbers below FD_SETSIZE
libkernel numbered guest sockets from GuestSockets::FirstDescriptor
(0x10000000), so a title that puts a socket in a 1024-bit fd_set writes
fd / 8 bytes past it. The Epic Online Services SDK does this on its
RtcNetworkThread and three titles stop there (#1794):

Palworld PPSA23126 (queeeef, main a11c8f7f7):
  FATAL: unhandled exception 0xc0000005 on thread 37164 'RtcNetworkThread'
    rip 0x00007ffcdb1ea2be eossdk-ps5-shipping.prx.guest.prx+0xdea2be
    rcx 0000000010000005 rsi 0000000000400000 r12 0000000010000005
The Mound PPSA26223 (xXPBSXx, main 0a8b1d32b):
  FATAL: unhandled exception 0xc0000005 on thread 'RtcNetworkThread',
  rip eossdk-ps5-shipping.prx.guest.prx+0xefc6f4, rcx = 0x10000005,
  rsi = 0x400000
Dying Light 2 PPSA02262 (tv7):
  FATAL: unhandled exception 0xc0000005 on thread 'RtcNetworkThread'
    rcx 0000000010000005 ... rsi 0000000000400000 ... r12 0000000010000005

On FreeBSD 11.4 (8c639945) FD_SETSIZE is 1024 (sys/sys/select.h:58-59)
and sockets take the lowest free entry of the one process descriptor
table that files use (kern_descrip.c:1643-1660 fdalloc,
uipc_syscalls.c kern_socket through falloc).

Every socket number is now a real host descriptor: a zero-access NUL
handle registered with _open_osfhandle on Windows (as directory
descriptors already are) and an F_DUPFD_CLOEXEC duplicate of the host
socket on Linux. The socket table maps that number to the socket, so
"is this a socket" is a table lookup instead of a range check at the 31
former FirstDescriptor comparisons. close releases both the socket entry
and the number, dup and dup2 duplicate the number through the host table
and keep the socket shared, dup2 of a file onto a socket number drops the
socket entry, and sceKernelClose now closes sockets too. sceNetSocket and
sceNetAccept take their ids from the same table instead of a counter from
32, so libkernel and libSceNet numbers never collide.

select polls guest sockets alongside libSceNet sockets, the random device,
stdio and (on Linux) host descriptors; poll throws only for an open
descriptor that is not a guest socket and reports POLLNVAL otherwise.
File calls that used to fail with EBADF on the socket range return
FreeBSD's answer for a socket: lseek ESPIPE (kern_lseek), ftruncate and
getdirentries EINVAL (invfo_truncate, getvnode), flock EOPNOTSUPP;
fstat on a socket throws. pread on a closed descriptor returns EBADF.

title failing on host descriptor numbers; these three titles are that
case, and this change keeps host numbering for files and only moves
sockets into it.

Tests: guest_socket_descriptors (new: socket below 1024, select on a
socket and a file together, close frees the number for a file, dup of a
socket, sceKernelClose), guest_select (socket and pipe together, Linux),
guest_poll, guest_dup, guest_socket_pair, guest_fstatfs,
guest_posix_filesystem and guest_sce_net updated.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 20378375b31eb5db922db6e55f45e44a4dae6445)
2026-10-13 03:22:36 +00:00
Dean c13dc7e6b4
Merge pull request #4558 from MiniRML/fix/kernel-json-number-locale
fix(kernel): parse JSON numbers independently of host locale
2026-10-13 15:37:49 +13:00
Dean 7cad853fc1
Merge pull request #4690 from David-cmrg/fix/libkernel-create-data-dir
fix(libkernel): create /data at start-up
2026-10-13 15:37:26 +13:00
Dean bef5f45bbc
Merge pull request #4729 from zaydzaari/research/rtc-minute-separator-1342
fix(rtc): reject date strings ending at the minutes
2026-10-13 15:37:15 +13:00
Dean b85934913f
Merge pull request #4738 from milescoviello/carry/fdopen-append-windows-4735
fix(libc): append through a descriptor opened by fdopen in an append mode on Windows
2026-10-13 15:37:03 +13:00
Dean b17fb4a4a7
Merge pull request #4792 from marshmll/fix/linux-host-stderr-redirect
fix(libc): keep host diagnostics on stderr when a guest redirects it on Linux
2026-10-13 15:36:51 +13:00
Dean 1419ea91fd
Merge pull request #3958 from MarcZX100/codex/carry-accepted-socket-mode
fix(libkernel): inherit listener mode on accepted sockets
2026-10-13 15:36:27 +13:00
Dean 37a0a3608c
Merge pull request #4480 from milescoviello/carry/fcntl-record-locks-windows-4479
feat(libkernel): implement fcntl record locks on Windows
2026-10-13 15:36:03 +13:00
Dean 495bf91a04
Merge pull request #4880 from David-cmrg/fix/libc-mspace-realloc-usable
fix(libc): keep a moved mspace block's usable bytes in realloc
2026-10-13 15:15:29 +13:00
Dean c27687313c
Merge pull request #4859 from EagleBearerYS/fix/libkernel-flexible-map-flag-8000
fix(libkernel): accept flag 0x8000 in sceKernelMapFlexibleMemory
2026-10-13 14:48:21 +13:00
David-cmrg 00c35c159c fix(libc): keep a moved mspace block's usable bytes in realloc 2026-10-13 03:38:29 +02:00
Dean 22c30bed2b
Merge pull request #4842 from LeandroLP23/fix/agc-ancillary-layer-unwritten
fix(shader): read the ancillary render target index as 0
2026-10-13 14:31:32 +13:00
Dean d1fd9372ba
Merge pull request #3602 from CouchRiv/fix-libc-powf-special-value
fix(libc): powf(1, y) returns 1 for any y
2026-10-13 14:15:52 +13:00
Dean 9ddb59fb87
Merge pull request #3635 from MarcZX100/codex/libc-readdir-r-3556
feat(libc): implement readdir_r
2026-10-13 14:15:32 +13:00
Dean 510a2188cf
Merge pull request #4031 from AlxcBTW/carry/pixel-ancillary-word-v3
feat(shader): give reads the masked-select pass keeps the whole pixel ancillary word
2026-10-13 13:59:10 +13:00
Dean 4430780bdd
Merge pull request #3644 from DariusHQ/fix/libkernel-poll-pipes
fix(libkernel): poll pipe descriptors
2026-10-13 13:52:54 +13:00
Dean 007759a6b6
Merge pull request #4524 from jagrat04/feat/libkernel-segment-info
feat(libkernel): implement sceKernelInternalMemoryGetModuleSegmentInfo
2026-10-13 13:52:34 +13:00
Dean Galvin 64ca6e3329 fix(libkernel): follow pollscan for a pipe whose other end is closed
FreeBSD's pollscan clears POLLOUT whenever POLLHUP is set, so a write end
whose read end is closed reports POLLHUP alone, with POLLIN and POLLRDNORM
when they were asked for; both host paths reported POLLOUT | POLLHUP.

POLLOUT on a read end now throws. FreeBSD opens both ends FREAD | FWRITE
and pipe_poll reports the read end writable, which a one-way host pipe
cannot back.

guest_poll drained 1 KiB from the full pipe before expecting POLLOUT, but
Linux reports it only once a whole 4 KiB page is free, so the test aborted
there. It now drains the pipe, which is writable on every host.
2026-10-13 13:37:28 +13:00
Dean 284a1c3342
Merge pull request #4509 from ErenYeager1836/feat/webbrowser-dialog-predetermined-content
fix(libSceWebBrowserDialog): permit termination from finished state in sceWebBrowserDialogTerminate
2026-10-13 13:34:24 +13:00
Alex a3b8c054f3 fix(libc): powf(1, y) returns 1 for any y
powf(1.0, nan) returned 0x7fc00001; FreeBSD msun (lib/msun/src/e_powf.c)
returns 0x3f800000. That case now follows FreeBSD; other inputs are
unchanged.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-10-12 20:32:48 -04:00
LeandroLP23 3334e41e45 fix(shader): read the ancillary render target index as 0
No pre-rasterization stage writes Layer: vertex layer exports are
ignored, so the first layer is used and the render target index field
of the packed ancillary word is 0. The lowering read the Layer builtin
for it instead. AMD's Windows driver drops the color writes of a
fragment shader that consumes an unwritten Layer, which made
agc_driver_relative_ancillary fail on AMD hardware (#4800); lavapipe
returns 0 there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:23:56 +13:00
Dean Galvin c52321fab5 fix(shader): move the primitive class to request version 19 and compose the ancillary word with render target index 0
main reads target.vertexSubgroups at request version 18 since #4470, so
reading the pixel primitive class at 18 as well read a version 18
request written by main one byte short. The class is now written and
read at version 19. agc_shader_memory loads a version 18 request as
main writes it, and it fails with "truncated data" when the class is
read at 18.

The composed word no longer reads the Layer builtin for bits 16-28.
Draws render to a single layer and guest layer exports are ignored, so
no stage writes Layer, and AMD's Windows driver drops the writes of a
fragment shader that reads it unwritten (#4800). The field is the
constant 0 and pixel_ancillary checks that the composed program has no
Layer read. The debt entry names the bits that have no source and are
assumed zero (2-7, 12-15, 29-31), and says that a change which makes
draws export a layer must restore the read.
2026-10-13 13:18:51 +13:00
AlxcBTW 18d9874a06 feat(shader): give reads the masked-select pass keeps the whole pixel ancillary word
A packed ancillary word that still reaches an export, or any other read
the masked-select pass cannot drop, no longer stops the recompile. After
that pass every remaining use gets the composed word: the primitive class
at bits 0-1, SampleId at bits 8-11 and Layer at bits 16-28, with every
other bit zero. Those lanes do export the ancillary VGPR on the console,
so the word has to be right, not just present.

The primitive class (0 point, 1 line, 2 triangle, 3 rectangle) comes from
the draw. RasterPrimitiveOf maps rect lists to 3, line lists on the vertex
path to 1 and everything else the driver accepts to 2, because its
geometry and tessellation paths only output triangles. It reaches the
shader as pipeline specialization constant 8233, the way dual-source
blending does: a request field that is folded into the specialized
module and is part of the result memo, the draw key and the serialized
request (version 17).

Only shaders that read the class pay for it. ShaderInfo records the read
(disk cache format 28), and only those shaders put the class in their
module key, so a shader that reads just the sample or layer field keeps
one module for every primitive class. The draw sets the class only when
the pixel shader loads the ancillary VGPR, so other draws keep the draw
cache entries they have today.

The VRS rates (bits 2-5) and the eye id (bit 7) are 0 because the driver
supports neither VRS nor multiview. SampleId is 0 because the driver
rejects MSAA and per-sample shading, and Layer is 0 while it ignores
vertex layer exports. TechnicalDebt.md records the layout sources and
these assumptions.

Tests:
- pixel_ancillary builds an export to target 0 whose two channels select
  between a packed value and a phi carrying the word. It checks the word
  for each primitive class, sample and layer, checks that the three
  shapes the masked-select pass keeps now compile with the composed word,
  and that a program whose select the pass drops reads no class.
- agc_driver_pixel_ancillary_word exports the word from a draw and reads
  back 2, 3 and 1 for triangle, rectangle and line. A shader that reads
  only the sample field shares one module across the classes, and the
  whole-word shader gets one per class. It also checks RasterPrimitiveOf.
- agc_shader_memory covers the version 17 round trip, and
  agc_shader_disk_cache the new flag.

Both ancillary tests fail with the old refusal when the composition is
disabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 13:06:21 +13:00
Dean d38d98bc84
Merge pull request #4068 from Kikoarl/feat/sysmodule-acm-module-id
feat(libSceSysmodule): register libSceAcm (0x10B) and libScePsml (0x137) module IDs
2026-10-13 12:28:42 +13:00
Dean 90c683946f
Merge pull request #4819 from oneandonlydean/up4/fix-kqueue-test-flake
fix(libkernel): pair the inotify halves of a rename in a watched directory
2026-10-13 12:03:30 +13:00
jagrat Singh ea03a22c7f feat(libkernel): implement sceKernelInternalMemoryGetModuleSegmentInfo 2026-10-13 04:29:25 +05:30
Dean Galvin 59fcdea9c4 fix(libkernel): pair the inotify halves of a rename in a watched directory
inotify queues IN_MOVED_FROM and IN_MOVED_TO of a rename one after the
other. The watcher thread could read the first before the second was
queued and report a rename inside the directory as a move to another
directory (NOTE_WRITE | NOTE_EXTEND instead of NOTE_WRITE), which made
guest_kqueue abort on loaded runners.

The watcher now reads the queue until it is empty and, when a move half
has no partner, calls getdents64 on the directory before reading again:
that takes the directory lock rename holds until both halves are queued.
2026-10-13 11:53:02 +13:00
Yunus Shaikh 56d35172f5 fix(libkernel): accept flag 0x8000 in sceKernelMapFlexibleMemory
The libc.prx heap that Animal Well (PPSA22520 01.000.011, SDK 9.04)
bundles maps each arena with sceKernelMapFlexibleMemory(&addr, len, 3,
0x8000). It threw "Unsupported memory mapping flags 0x8000" before the
first frame. The flag is ignored as sceKernelMapNamedFlexibleMemoryInternal
already does; other unknown flags still throw.
2026-10-12 15:38:48 -07:00
Dean df5108f90e
Merge pull request #4530 from babyhuey/feat/libkernel-internal-memory-available-size
feat(libkernel): export sceKernelInternalMemoryGetAvailableSize
2026-10-13 11:16:17 +13:00
marshmll 438d410824 fix(libc): keep host diagnostics on stderr when a guest redirects it on Linux
On Linux a guest stderr redirect also moves the host's: guest
descriptors are host descriptors, and the guest stderr stream wraps the
host stderr FILE. After dup2(fd, 2), or freopen(path, mode, stderr) with
full buffering, the libc terminate report, the host fprintf(stderr)
diagnostics and libstdc++'s terminate message go into the title's pipe
or file, and abort() discards what is still buffered. RetroArch
(PPSA99169) reopens stderr onto app0/trace.txt with full buffering, so
its stop on main left no message anywhere.

Before the first guest redirect of descriptor 2 (libkernel dup2, libc
freopen of a stream on descriptor 2), keep a close-on-exec duplicate of
the host descriptor 2 and point the host stderr at an unbuffered stream
on it. The guest stream keeps its own FILE and follows the redirect.
The libc terminate report writes to the kept descriptor with write()
instead of the stderr stream, and libkernel's sceKernelDebugOutText uses
the same kept descriptor.
2026-10-12 19:00:08 -03:00
Adrià 584cc4c571
Merge pull request #4761 from p3n1cillin/claude/agc-driver-validation-debug
feat(libSceAgcDriver): answer validation and shader debugging queries as the retail library does
2026-10-12 23:22:01 +02:00
Adrià 55b2b332c3
Merge pull request #4766 from p3n1cillin/claude/libc-heap-report-for-game
feat(libc): report heap backtraces and heap errors requested by the guest heap
2026-10-12 23:21:56 +02:00
Adrià d7323df946
Merge pull request #4755 from ivica00/feat/libc-nearbyint
feat(libc): implement nearbyint
2026-10-12 23:21:19 +02:00
babyhuey ff56dadc0a feat(libkernel): export sceKernelInternalMemoryGetAvailableSize 2026-10-12 17:18:53 -04:00
Adrià 559979dc67
Merge pull request #4750 from p3n1cillin/claude/session-signaling-connection-status
feat(libSceNpSessionSignaling): answer connection status queries offline
2026-10-12 23:18:08 +02:00
Adrià ceb6927888
Merge pull request #4671 from jagrat04/feat/libkernel-killpg
feat(libkernel): implement killpg
2026-10-12 23:17:33 +02:00
p3nicillin d3ef2b30b7 feat(libc): report heap backtraces and heap errors requested by the guest heap
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 22:15:55 +01:00
Adrià b5b33511f7
Merge pull request #4710 from babyhuey/feat/libkernel-scekernelmmap
feat(libkernel): export sceKernelMmap
2026-10-12 23:15:49 +02:00
Adrià 962aba18f5
Merge pull request #4578 from jagrat04/feat/libkernel-getsid
feat(libkernel): implement getsid for calling process
2026-10-12 23:14:58 +02:00
Adrià e0fad55e56
Merge pull request #4651 from ErenYeager1836/feat/libkernel-event-error
feat(libkernel): implement sceKernelGetEventError
2026-10-12 23:13:34 +02:00
ivica00 5883c25552 feat(libc): implement nearbyint
The float helper is already on main. The double helper rounds with the current mode and does not raise the inexact flag.
2026-10-12 23:11:50 +02:00
Adrià Franch 935e7d6ba1 test(libkernel): drop guest_ioctl_getsid, it pinned the getsid throw 2026-10-12 23:11:21 +02:00
jagrat Singh 3ce13e2b7d feat(libkernel): implement getsid for calling process 2026-10-12 23:11:21 +02:00
jagrat Singh f08dc5e3c3 feat(libkernel): implement killpg 2026-10-12 23:11:01 +02:00
p3nicillin 8e5a1cae23 feat(libSceAgcDriver): answer the validation and shader debugging queries as the retail library does
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 22:10:58 +01:00
Adrià 7940cacd83
Merge pull request #4655 from milescoviello/feat/libc-ceil
feat(libc): implement ceil
2026-10-12 23:10:14 +02:00
Adrià 5efd09afc4
Merge pull request #4653 from Lorkydey/feat/libc-statvfs
feat(libc): query filesystem statistics by guest path
2026-10-12 23:08:17 +02:00
David a0a238c86a feat(libkernel): implement sceKernelGetEventError
Return the event's data when EV_ERROR is set in its flags and 0 otherwise, as KytyPS5 does and as FreeBSD 11 kevent stores the errno of a failed change. A null event throws like the other accessors.
2026-10-12 23:07:39 +02:00
Adrià 5f01c80821
Merge pull request #4595 from jagrat04/feat/libkernel-setregid
feat(libkernel): implement setregid
2026-10-12 23:06:27 +02:00
Adrià 2a9068b159
Merge pull request #4138 from VitzS7/fix/libkernel-signal-waits
feat(libkernel): wait for pending guest signals in the signal waits
2026-10-12 23:06:25 +02:00