fix(libkernel): build the file, module and rtld calls on macOS hosts #10552
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10552"
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 krishalivaibhav on 2026-10-24T09:43:15Z.
What
Builds
libkernelon macOS hosts. Six files used Linux-only APIs and did not compile there; each now has a macOS path behind__APPLE__, and the Linux and Windows paths are unchanged:File/src/NativeStat.cpp:st_atimespec/st_mtimespec/st_ctimespec, and afstatatwalk for guest paths that no longer fitPATH_MAXonce the host root is prepended.File/src/SharedMemory.cpp: an unlinked temp file instead ofmemfd_create; descriptors are recognised throughF_GETPATH.File/src/Stdio.cpp:statfsfromsys/mount.hinstead ofsys/vfs.h, plus the directory-read and vector-IO differences of Darwin.Module/src/DynamicLoader.cpp,Module/src/ModuleInfo.cpp,System/src/Rtld.cpp:dlopen/dladdrhandles and Mach-O segment walks instead oflink.h/dl_iterate_phdr.A second commit makes
File/src/DirectoryDescriptor.cppresolve a descriptor's path throughfcntl(F_GETPATH)on macOS, where/proc/self/fddoes not exist (fdopendirreturned ENOTDIR).A third commit (rebased
f023a5e691) givesguest_module_infoa macOS expectation:eh_framemust match the image's__eh_framesection fromgetsectiondata, andeh_frame_hdris 0 for the fixture, which is not a relinked image.Extracted from iamthehimansh's
feat/macos-port(#8658); Co-authored-by on both commits. The 22 explanatory//comments of the branch version were dropped to follow the no-comments rule.Further commits:
ee34c291e1(was997f6cfd4, iamthehimansh): long-path stat prefixes are opened withO_SEARCHon macOS, so a directory without read permission can still be walked.559568f8d8(was458b30a05):sceKernelGetdirentriesandHostWriteguard their guest outputs on macOS, with theS_ISDIRcheck the Linux path has.74cfbed70d:Rtld.cppimageContainingreturnsnullptron macOS for an address outside every image, as main does on Linux and Windows after #10243, instead of throwing.5200c2edd2: namedshm_openand namedshm_unlinkcallNotImplemented_nid_no_patchon macOS, asdocs/dev/debt/libkernel.mdsays. The host name/anyps5-shm-plus 40 hex digits is 52 bytes against macOSPSHMNAMLEN31, and/dev/shmdoes not exist there. Anonymous shared memory is unchanged.a6d91c88dd: a debt entry for the macOS module info fields left at 0 (tls_*,init_proc_addr,fini_proc_addr,eh_frame_hdr_*) and for the non-empty Mach-O__eh_framecase theguest_module_infofixture does not cover.e95186ba55: the macOSNativeIsPipematches only FIFOs whosefstatfsfails, aspipe()descriptors do, andNativeFstatfsuses it, so a named FIFO is no longer a pipe.fa9d3c8088: a zero-lengthreadv,writev,preadvorpwritevon macOS checks the descriptor, then its access mode, then (for the positioned calls) that it is seekable, before returning 0. This is the FreeBSD 11.4 order; Linux checks seekability first, so a write-only pipe end givesESPIPEthere andEBADFhere.787e08bb5c: an unlinkedanyps5-shm-file counts as shared memory only in the temporary directoryCreateAnonymousFileuses; the not-implemented traces nameshm_openandshm_unlink.1490561626: debt entries for the macOSsceKernelGetdirentries(full re-read, O(n²) paging, index offsets) and for macOS opening every module withRTLD_GLOBAL.f82257e8f9:dlcloseon macOS unregisters a relinked image under the__APS5DATA,__metaload bias thatdl_iterate_phdrreports andmprotectregisters it under, not under its Mach-O header. The header and the load bias are found once when the module is opened, soImageBaseand its throw are gone.f374a777a2: the macOSsceKernelGetdirentriesreads an archived app directory throughFile::ReadDirectoryDescriptor, as the Linux copy does since0a64d23bd; theHostWritechecks now come beforefstat, as there.f58b1c4523: the shared-memory check resolves the temporary directory once.ce09c08f44: on macOS a lookup on the main program's handle (sceKernelDlsymwith handle 0) goes through the default-scope path, becausedlopen(NULL)there is equivalent toRTLD_DEFAULT; a module loaded without 0x100 is no longer found through it.DefaultScopeSymbolreturns null for a hit in such a module, and the main program never counts as one.5afd6df8cc:sceKernelGetModuleInfoFromAddron macOS reportseh_frame_hdrfor a relinked image from thePT_GNU_EH_FRAMEheader in__APS5DATA,__meta, the sourcesceKernelGetModuleInfoForUnwinduses.FindImagerequires the same 0x60-byte__metaminimum asdl_iterate_phdr.32d288095f: after a long-path split, leading slashes of the rest are dropped, so a//at the split point is not resolved from the host root.3dffebe9ec: removes the duplicateftruncateandreadventries the rebase added, describes the handle-0 lookup in the module scope entry, adds the entries skipped or repeated when a directory changes betweengetdirentriescalls to the macOS directory entry, and theeh_frame_hdrsource to the module info entry.Tested
Rebased onto
main809c7fa2df(one conflict, in the include block ofDynamicLoader.cppafter #10627; resolved by keeping main'sHostThreadLocal.hppinclude), macOS x86_64 Release on Apple Silicon M2:DirectoryDescriptor,NativeStat,SharedMemory,Stdio,DynamicLoader,ModuleInfo,Rtld) compile with 0 errors;Stdio.cpp,SharedMemory.cppandDynamicLoader.cppcompile with 0 errors atea0213b6ac, and all seven again at this head, with no warnings from their lines; a standalone x86_64 program with the new empty-vector, shared-memory-directory and pipe checks gives the expected result in 12 cases (EBADF,ESPIPE, 0; temporary directory matches, another directory does not;pipe()is a pipe, a named FIFO is not);Rtld.cppandSharedMemory.cppobjects (other symbols stubbed) checks that_sceKernelRtldThreadAtexitIncrementreturns -1 andDecrementreturns 0 for&localandnullptr, and that namedshm_openandshm_unlinkon a valid name reachNotImplemented_nid_no_patch. It printsok.Not run on the rebased head: the
guest_*test programs. #10366 is merged, but on currentmainlibkernel still does not build on macOS without #7631, #7804 and #4630 (Thread.cpp,Exception.cpp,DirectMemory.cpp), soguest_module_info,guest_filesystem,guest_dynamic_loaderand the other tests below were not re-run.Earlier results on the pre-rebase head (macOS: local integration of
main(e7e3e9c19) + #10419 + #10366 + #10369 + #7631 + #7804 + #4630 + this PR + #10853):guest_module_info,guest_module_args,guest_libc_threads,guest_statvfs,guest_file_timestamps,guest_pthread_stack,guest_raise_exception,guest_fdopendir,guest_kernel_sys,guest_filesystempassed;guest_aioneeds #10543 andguest_dynamic_loaderneeds #10627.Linux: Ubuntu 24.04, g++ 13.3.0, x86-64 Release, on
main60465afd3+ the first commit: libkernel builds with no warnings from the six files. The later commits are__APPLE__-only.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 repositoryStdio.cpphunks; the rest of libkernel on macOS needs #7631, #7804 and #4630🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T10:36:43Z.
Review: CHANGES_REQUESTED
The macOS
AppendingWritevfallback has a correctness hole and overlaps directly with the helper in open PR #10543. Here it treats any descriptor withO_APPENDas an appendable regular file and callswriteveven when the savedlseekposition is negative. For example, anO_APPENDpipe/non-regular descriptor can be written successfully here althoughpwritevshould fail withESPIPE; if saving the offset fails, the code also performs the write without being able to restore the shared descriptor position. #10543’sWritevAtEndchecksfstat/S_ISREG, refuses the fallback when the offset cannot be saved, and covers the same pwrite/pwritev behavior. Please coordinate this shared path with #10543 (or make this PR depend on/reuse its helper) and preserve the native failure behavior for non-regular or non-seekable descriptors. A regression for anO_APPENDpipe and a regular-file offset-preservation case would cover the boundary.Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-24T16:16:17Z.
Review: COMMENTED
Tested head
972a2c6525on Apple M4 Pro, macOS 27.0.1, Apple clang, x86-64 Release under Rosetta 2. Two points for the rebase.Conflict in
ModuleInfo.cpp. Onmain3fcb5e4d76,NativeStat.cpp,SharedMemory.cpp,Stdio.cpp,DynamicLoader.cppandRtld.cppcompile with this PR, butModuleInfo.cppconflicts. #10230 rewrotesceKernelGetModuleInfoFromAddr:st_size0;GuestImageon every host for theflags == 2SystemImagecheck.The macOS branch needs the same. Locally I used this, taking the image header from
dladdr, which is what the AppleSystemImagereads:Test results. With that and the other open macOS build PRs (the same stack as in my review of #7631),
guest_dynamic_loader,guest_module_args,guest_libc_threads,guest_statvfsandguest_file_timestampspass.guest_module_infoaborts atGuestModuleInfo.cpp:68(info.eh_frame_addr != 0). Apple ld gives the fixture only compact unwind information:otool -l libguest_module_fixture.dyliblists__textand__unwind_info, with no__eh_frame. So the Mach-O branch ofFillleaves theeh_framefields 0. Theeh_frame_hdrcheck on the next lines can't hold for Mach-O either.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T19:51:50Z.
Review: DISMISSED
Re-reviewed exact head
e60d9dfa3a911ebdc0847f229eebae1878e4e487. The earlier O_APPEND fallback concern is resolved by removing that path, and theF_GETPATHaddition matches the macOS descriptor-path need. I cannot approve this head yet for two concrete reasons:DIRTYagainstmain; please rebase and rerun checks.guest_module_infotest still requires nonzeroeh_frameandeh_frame_hdrfor every non-Windows host. The reported macOS fixture has only__unwind_info, and the new Mach-OFillpath leaves both fields zero. The author’s own test note identifies this mismatch. Please add an explicit macOS expectation/fixture for these fields (or otherwise make the test pass with documented semantics) and runguest_module_infoon macOS.The hosted product jobs are skipped by path policy, so they do not cover this macOS behavior.
Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-26T06:51:58Z.
Review: CHANGES_REQUESTED
Re-review of
458b30a05. The two new commits look right and pass here, but I am requesting changes for two defects. The first appears once this head is merged with currentmain. The second is in the namedshm_openpath that this PR makes reachable on macOS. My 25 Oct report at3206fbd27said the second one was a problem in the series' test. That was wrong: it comes from this PR, as item 2 explains.Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
Applied at
458b30a05to mugurc's macOS series (27e968974) merged withmainat2742004ed2, with other open macOS fixes, then toggled only this PR. As in my last report,git applyconflicts with the series' own macOS versions of these files. "With" therefore means the seven source files andGuestModuleInfo.cppreplaced by this head's versions. The series turnsguest_module_infooff on Apple, so I turned it back on for both states. Both states build with 0 errors, and the touched files give no warnings with this PR.I ran 44 tests three times in each state, sequentially, and got the same result every run. The set is the one from my last report, plus
guest_directory_entries,guest_underscore_entries,guest_path_name_length,guest_usb_storage,guest_kernel_app_archive_*andwrite_watch_*, which exercise the getdirentries andHostWritechanges:guest_filesystemguest_kernel_sys_module_internalguest_module_infoguest_shm_open(the series' copy)GuestFilesystem.cpp:1245last time: getdents on a plain file must return EINVAL):19last time)module info check failed at line 34GuestShmOpen.cpp:72, located with lldb: it expects a namedshm_opento throw on macOS, and it no longer does. See item 2The other 40 tests give the same result in both states. 34 pass both ways: the other
guest_kernel_sys*tests,guest_libc_threads,guest_statvfs,guest_fdopendir,guest_file_timestamps,guest_pthread_stack,guest_raise_exception,guest_module_args,guest_dynamic_loader_variant_names,guest_directory_entries,guest_underscore_entries,guest_path_name_length,guest_usb_storage,guest_kernel_app_archive_archive/_plainand allwrite_watch_*. 6 fail both ways at the same point:guest_aio(:437, needs #10543),guest_dynamic_loader(:57, needs #10627),guest_append_writes(:79),guest_host_standard_error,guest_kernel_app_archive_mmap(mmap on a file read from app0.zar ... not implemented) andguest_refused_connect.New commits: a standalone x86_64 check on this Mac agrees with
997f6cfd4. On a mode-0100 directory,openat(O_RDONLY | O_DIRECTORY)fails with EACCES, whileopenat(O_SEARCH)succeeds andfstatatthrough that descriptor works.O_SEARCHon a regular file fails with ENOTDIR. The guard block added in458b30a05matches the LinuxsceKernelGetdirentriesline for line.Findings
core/libs/prx/libkernel/System/src/Rtld.cpp:50: the macOS branch throws, butmainnow returns -1 or 0. #10243 (0ce4b82c2d, merged after this PR's basee7e3e9c19) madeimageContainingreturnnullptron Linux and Windows for an address outside every image. With that,_sceKernelRtldThreadAtexitIncrementreturns -1 andDecrementreturns 0, and main'sGuestDynamicLoader.cpp:274-277requires both for&localandnullptr. Git merges this head into currentmainwithout a conflict (git merge-tree), and the mergedimageContainingkeeps the__APPLE__throw. On this Macdladdr(&local)anddladdr(nullptr)both return 0, so after the merge both calls throwstd::runtime_errorout of anextern "C"export on macOS. Fix: rebase on currentmainand replace the throw in the__APPLE__branch withreturn nullptr;. (I could not run this check end to end, becauseguest_dynamic_loaderstops at:57first without #10627.)core/libs/prx/libkernel/File/src/SharedMemory.cpp:612and:1026: a valid namedshm_openreturns a made-up ENAMETOOLONG on macOS instead of throwing. Named objects now go through the shared non-Windows path. That path calls host::shm_open("/anyps5-shm-" + 40 hex digits), a 52-byte name, and macOS limits POSIX shm names toPSHMNAMLEN(31). Checked here:shm_openwith that name fails with errno 63, "File name too long", so every valid guest name gets error 63.HostShmLockis Linux-only, so macOS has no namespace lock.shm_unlinkchecks/dev/shm/...withfaccessat, which does not exist on macOS, so it always returns ENOENT. Even with a short name, the AppleIsHostSharedMemoryDescriptor(:125-132) would not recognise a native POSIX shm descriptor.docs/dev/debt/libkernel.md:264says "Namedshm_openobjects still throw on macOS". The series'GuestShmOpen.cpp:72asserts that throw, and with this PR the assertion fails. main'sGuestShmOpen.cpptests only invalid names, so it does not catch this. Fix: under__APPLE__, callNotImplemented_nid_no_patchinOpenNamedFileand in the namedshm_unlink, as the debt entry describes.core/libs/tests/GuestModuleInfo.cpp:63-64: on this fixture the new macOS expectation checks nothing.otool -l libguest_module_fixture.dylibhere lists only__textand__unwind_info.getsectiondatatherefore returnsnullptrand 0, and the check reduces to0 == 0 && 0 == 0. A regression that stops reporting__eh_framewould still pass. Either check an image that has an__eh_framesection and requireframes != nullptr, or record in the debt file that the Mach-O fields are not covered. A debt entry is also needed for the other macOSFillfields this PR leaves at 0 (tls_*,init_proc_addr,fini_proc_addr,eh_frame_hdr_*), asdocs/dev/debt/libkernel.mddoes for Windows.PR body:
WhatandTesteddescribe the three earlier commits. Please add997f6cfd4(O_SEARCH) and458b30a05(HostWriteguards and theS_ISDIRcheck), and the run that covers them.Not checked here: Linux, Windows, and this PR together with #10543 or #10627.
AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).
Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-26T08:52:23Z.
Review: CHANGES_REQUESTED
Re-review of
8d601f9ec. All four items from my review of458b30a05are fixed, and the A/B below shows no new failures. I am still requesting changes. A closer read of the__APPLE__paths found three inputs that get a made-up result where Linux reports an error or throws, and one known gap with no debt entry (items 1 to 4). None of them comes from the three new commits. They were already there at458b30a05, and I should have raised them then.Earlier items
Rtld.cppmacOSimageContaining: fixed (49c24af9a). On the "with" build here, lldb calls of_sceKernelRtldThreadAtexitIncrement_nid_postfixandDecrementreturn -1 and 0 fornullptrand for a stack address, as main'sGuestDynamicLoader.cpp:274-277requires.shm_openandshm_unlink: fixed (105e043a7). They throw after the name check, asdocs/dev/debt/libkernel.md:272says. The series'GuestShmOpen.cpp:72assertion passes again.GuestModuleInfo.cppon a fixture without__eh_frame: recorded in the debt file (8d601f9ec), together with the other macOS fields left at 0.Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
Applied at
8d601f9ecto mugurc's macOS series (27e968974) merged withmainat2742004ed2, with other open macOS fixes, then toggled only this PR. This head does notgit applythere, because the series has its own macOS versions of these files. "With" therefore replaces the seven source files andGuestModuleInfo.cppwith2742004ed2plus this PR's changes (git merge-file, no conflicts). The exception isRtld.cpp, which is this head's file and so includes #10243. The series turnsguest_module_infooff on Apple, so I turned it back on in both states. Both states build with 0 errors. The PR's lines add no warnings.DirectoryDescriptor.cpp:249gives a-Wextern-c-compatwarning whenever that file is rebuilt, but the warning is on main's code (struct PathTag {}inside anextern "C"function).I ran the same 44 tests as last time, three times in each state, sequentially:
guest_filesystemguest_kernel_sys_module_internalguest_module_infoguest_shm_open(the series' copy)module info check failed at line 34The other five failures stop at the same point in both states:
guest_aioat:437(needs #10543)guest_dynamic_loaderat:57(needs #10627)guest_append_writesat:79guest_host_standard_errorguest_kernel_app_archive_mmap(mmap on a file read from app0.zar ... not implemented)guest_refused_connectis flaky on this tree in both states. It passed 4 of 13 runs without this PR and 0 of 13 with it. lldb puts the failures without the PR atGuestRefusedConnect.cpp:81and:88, and the failure with the PR at:81. Those lines are the libSceNet backlog-drain checks, which no file in this PR touches. It also failed in all 6 runs at the last head. The logs contain noValidation Errorlines in either state.Findings
core/libs/prx/libkernel/File/src/Stdio.cpp:1602,:1621,:1638,:1655: a zero-lengthreadv,writev,preadvorpwritevreturns 0 without checking the descriptor.readv/writevwithiovcnt0 always fail withEINVAL, even for fd -1, so the PR returns 0 instead.sceKernelReadv(-1, iov, 0)returns 0, and so doessceKernelWritevon a read-only descriptor. On Linux the same calls reach hostreadv/writevand fail withEBADF.fcntl(d, F_GETFL). Forpreadv/pwritev, also check that it is seekable (lseek(d, 0, SEEK_CUR)), and maperrnothroughSceErrorFromErrno.core/libs/prx/libkernel/File/src/SharedMemory.cpp:125-132: any unlinked file whose name starts withanyps5-shm-, in any directory, counts as shared memory.F_GETPATHstill returns the path afterunlink. Checked here: for an open, unlinked fileanyps5-shm-probein the temporary directory,F_GETPATHreturned its full path whilest_nlinkwas 0./download0/anyps5-shm-x, opens it and unlinks it gets the shared-memory paths forftruncate,writev,pwritevandfchflags(EINVAL)./dev/shm/anyps5-shm-and the memfd name.CreateAnonymousFileuses (std::filesystem::temp_directory_path(), compared afterrealpath, becauseF_GETPATHreturns the path with symbolic links resolved).core/libs/prx/libkernel/File/src/Stdio.cpp:576-579vs:592-596: on macOSNativeIsPipeis true for any FIFO, whileNativeFstatfstreats only a FIFO whosefstatfsfails as a pipe.fstatfsfails (EINVAL) on apipe()descriptor and succeeds on a named FIFO.fchflagson a named FIFO (:763) returnsEINVALon macOS. Linux'sNativeIsPipeonly matches pipefs, so the same call throws there.NativeIsPipeS_ISFIFO && fstatfs(...) != 0, and haveNativeFstatfscall it, as the Linux branch does.core/libs/prx/libkernel/File/src/Stdio.cpp:1250-1310: the macOSsceKernelGetdirentrieshas no debt entry.__getdirentries64(declared at:372).*basepare entry indexes, not the host's directory cookies. A hostreaddirorlseekon the same descriptor therefore puts it at the wrong entry.docs/dev/debt/libkernel.mdline that states this, like the Windows directory descriptor entry at:158.Smaller points:
SharedMemory.cpp:617:NotImplemented_nid_no_patch(__func__)reportsOpenNamedFile, notshm_open. Passing"shm_open"makes the trace name the export.Module/src/DynamicLoader.cpp:329always loads withRTLD_GLOBALand hides local modules afterwards inDefaultScopeSymbol. IfRTLD_LOCALcannot work on macOS, a debt line saying so would help the next reader. I have not tested this.Not checked here: Linux, Windows, and this PR together with #10543 or #10627.
AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).
Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-26T21:01:08Z.
Review: CHANGES_REQUESTED
Re-review of
6a689187b. The new commits fix all four items and both smaller points from my review of8d601f9ec, and the A/B below shows no new failures. I am still requesting changes for three defects, items 1 to 3 below. None of them comes from the new commits. Items 1 and 2 were already there at8d601f9ec, and item 3 comes from the rebase ontomain.I tested
ea0213b6a, and you rebased while my runs were going. Between the two heads only theF_GETPATHcommit changed: it is now theHostDescriptorTargethelper, which covers both of main's/proc/self/fdreads. Every other file this PR changes is the same on this tree at both heads (git merge-fileof each head onto the tree'smaingives identical files). I did not rebuild at6a689187b, because the newDirectoryDescriptor.cppneeds main's archived-directory changes, which this tree does not have yet.Earlier items
readv/writev/preadv/pwritev: fixed (f0bb0ae73). I called them through lldb on the "with" build:writevon a read-only descriptor andreadvon a write-only one returnEBADF(0x80020009).preadvandpwritevon a pipe returnESPIPE(0x8002001d).anyps5-shm-outside the temporary directory: fixed (88b344f1c). The check uses the sametemp_directory_path()asCreateAnonymousFile, andcanonicalresolves symbolic links the same wayF_GETPATHdoes.f8bd9c3ae).NativeFstatfsbehaves as before. The change a title can see isfchflagson a named FIFO, which now throws, as on Linux.sceKernelGetdirentriesdebt entry: added (6a689187b), with theRTLD_GLOBALquestion and both trace names.Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
Applied at
ea0213b6ato mugurc's macOS series (27e968974) merged withmainat2742004ed2, with other open macOS fixes, then toggled only this PR. As before, the head does notgit applythere, so "with" is the file set from my last round plusgit diff 8d601f9ec ea0213b6a. The series turnsguest_module_infooff on Apple, so I turned it back on in both states. Both states build with 0 errors, and the PR's lines add no warnings.I ran the same 44 tests as last time, three times in each state, one run after another:
guest_filesystemguest_kernel_sys_module_internalguest_module_infoguest_shm_open(the series' copy)module info check failed at line 34The other five failures stop at the same point in both states:
guest_aioat:437(needs #10543)guest_dynamic_loaderat:57(needs #10627)guest_append_writesat:79guest_host_standard_errorguest_kernel_app_archive_mmap(mmap on a file read from app0.zar ... not implemented)guest_refused_connectpassed all six runs this time. No log has aValidation Errorline.Findings
core/libs/prx/libkernel/Module/src/DynamicLoader.cpp:423:dlcloseunregisters a relinked image under its Mach-O header, butmprotectregistered it under its guest load bias.mprotectregisters the image undersearch.base = image->dlpi_addr(DirectMemory/DirectMemory.cpp:1285and:1369).dl_iterate_phdrsetsdlpi_addrto the__APS5DATA,__metaload bias (libc/src/specifics/macos/GuestImages.cpp:33).imageBase + rva(first PT_LOAD) - p_vaddr(relinker/elfpatcher/src/macos/MacOsImage.cpp:511).__TEXTtakes the firstLoadRva(0x10000) bytes, andGuestAllocations.cpp:336requires the image's first loaded page to be its base. The key is therefore never the header.ImageBase(:113) returns_dyld_get_image_header(index).UnregisterImage(GuestAllocations.cpp:343) finds no entry under that key and returns without doing anything.mprotects inside a.guest.prxand then unloads it, the image's pages stay in the allocation registry.guest_flexible_memory_budgetfixture cannot catch this, because it writesdli_fbaseas its load bias.dlpi_addrthatdl_iterate_phdrreports for this image, as the macOS series'ImageBasedoes. Keep the header for theDefaultScopeSymbolcomparison withdli_fbase.DynamicLoader.cpp:134-145:DefaultScopeSymbolreturns null when the firstdlsym(RTLD_DEFAULT)hit is in a local module, even if a global module exports the same name.foo, then module B is loaded with 0x100 and also exportsfoo. dyld returns A'sfoofirst, the filter drops it, and the lookup returns null.RTLD_LOCAL, so the same lookup returns B'sfoo.dlsymon each global module's handle in load order. Otherwise, state this limit in the new debt entry (docs/dev/debt/libkernel.md:145).core/libs/prx/libkernel/File/src/Stdio.cpp:1267: the macOSsceKernelGetdirentriesdoes not have main's directory-descriptor branch.0a64d23bd(feat(libkernel): enumerate archived app directories) addedif (File::IsDirectoryDescriptor(fd)) return File::ReadDirectoryDescriptor(fd, buf, nbytes, basep);to the non-Windows copy. After the rebase, that branch is only in the Linux copy (:1354)./dev/null(DirectoryDescriptor.cpp:246). On macOS,getdirentrieson it therefore reachesfstat, sees a file that is not a directory, and returnsEINVALinstead of the archive's entries.HostWritechecks.Smaller points:
SharedMemory.cpp:133-135callstemp_directory_pathandcanonical(realpath) on every check of an unlinkedanyps5-shm-file. A function-localstatic constwould do this once.f0bb0ae73: "as host Linux does" is not quite right. Linuxpreadvchecks that the descriptor is seekable first, so a write-only pipe end givesESPIPEon Linux andEBADFhere. The code's order (EBADFfirst) is the FreeBSD 11.4 order, so only the wording needs to change.ImageBasethrowsstd::runtime_error(DynamicLoader.cpp:131) when noRTLD_NOLOADprobe returns the module's handle.dlclose_nid_postfixdoes not catch it, so the exception would leave anextern "C"export. I have not found an input that reaches the throw. If the fix for item 1 stores the base when the module is opened,ImageBaseand its throw are no longer needed.Not checked here: Linux, Windows, a build at
6a689187b, and this PR together with #10543 or #10627.AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).
Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-27T13:26:45Z.
Review: DISMISSED
Re-review of
41dc0d130. The new commits fix findings 1 and 3 of my review of6a689187b, the shared-memory point and theImageBasequestion. The A/B below shows the same three tests passing that it showed last time, and no new failures. Finding 2 of my last review was my mistake, see below. I am still requesting changes for items 1 to 4: item 1 comes from the rebase, item 2 I confirmed with a probe, and items 3 and 4 I found by reading the code.Earlier items
dlclosekey: fixed (b65f94a7a).FindImagereads the load bias from__APS5DATA,__meta(version 2, offset 0x08), the same fielddl_iterate_phdrreports asdlpi_addr(libc/src/specifics/macos/GuestImages.cpp). That is the keymprotectregisters images under. An image without that metadata keeps its Mach-O header as the key;UnregisterImagethen does nothing, as before.DefaultScopeSymbolshadowing: this was my mistake.dlsym_nid_postfix(DynamicLoader.cpp:398-409) already runsFindSymbolon every module loaded with 0x100, for all four names, before it callsDefaultScopeSymbol. So in my example, B'sfoowas already found. I'm sorry for the extra work. See item 3 for what this means for the new fallback.sceKernelGetdirentries: fixed (355b6982a). The branch comes after theHostWritechecks, as in the Linux copy.SharedMemory.cpp: the temporary directory is now resolved once (d130c8ee3).ImageBasethrow is gone along withImageBase.Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
The PR no longer applies to my test tree. That tree is mugurc's macOS series (
27e968974) merged withmainat2742004ed2, plus other open macOS fixes. On currentmainalone, theguest_*tests do not link on macOS, as your Tested section says. So "with" is the file set I tested atea0213b6aplus the four new commits (git diff dc9d0ff80 41dc0d130forDynamicLoader.cpp,Stdio.cppandSharedMemory.cpp), which applied without conflicts. "Without" is the same tree without this PR. The tree turnsguest_module_infooff on Apple, so I turned it back on in both states. Both states build with 0 errors.I ran the same 44 tests three times in each state, one run after another:
guest_filesystemguest_kernel_sys_module_internalguest_module_infomodule info check failed at line 34These fail the same way in both states:
guest_dynamic_loaderstops atGuestDynamicLoader.cpp:57(needs #10627).guest_aioandguest_append_writesabort.guest_kernel_app_archive_mmapstops atmmap on a file read from app0.zar ... not implemented.guest_refused_connectfailed in all three "with" runs and in one "without" run, so I ran it 20 more times in each state. It passed 6 of 20 times with this PR and 3 of 20 without. With a-O0 -gbuild, both states stop at the same place:GuestRefusedConnect.cpp:81, the first backlog-drain connect. It fails on this tree without the PR too, so it is not caused by this PR. No log has aValidation Errorline.Findings
docs/dev/debt/libkernel.md:175-176: the rebase added a second copy of theftruncateentry and of thereadventry.:175repeats:171without its last sentence (PPSA04354).:176is an older version of:173, so the tworeadventries now disagree.main(1764e016f8), the file has one of each.sceKernelDlsym(0, ...)finds symbols in modules loaded without 0x100, which contradicts the new debt entry atdocs/dev/debt/libkernel.md:148.sceKernelDlsymwith handle 0 callsdlopen_nid_postfix(nullptr, 2)and thendlsym_nid_postfixon that handle (Module.cpp:173).dlopen(NULL)returns "a handle equivalent toRTLD_DEFAULT" (man 3 dlopen).FindSymbol→Symbol(DynamicLoader.cpp:100,:199) calls plaindlsymon that handle and never applies theHiddenImagefilter. Every module is opened withRTLD_GLOBAL(:354), so this lookup sees all of them.guest_module_info_tests. It loadslibguest_module_fixture.dylibwith flags 2, then looks upGuestModuleAdd:dlsym_nid_postfix(nullptr, ...)returns null.sceKernelDlsym(0, ...)returns 0, with the module's address.sceKernelLoadStartModulealso loads with flags 2 (Module.cpp:292), so this affects every module a title starts.RTLD_LOCAL, so the same call should returnESRCH. I worked that out from the code and did not run it.DefaultScopeSymbol), or open the main program withRTLD_FIRSTand search the global modules after it. Then correct the debt entry.DynamicLoader.cpp:163-168: the new fallback loop inDefaultScopeSymbolcannot find anything.globalsis the setdlsym_nid_postfixhas just searched (:398,:409). The loop'sdlsym(module->native, symbolName)uses one of the four namesFindSymbolalready tried on each of those modules, and each of those lookups returned null.:148, "then looks the name up..." and "that fallback searches each of those modules' dependencies...") and in the PR body describe a path that never changes the result.return nullptrfor a hidden image, or say which input reaches it. Then update the debt entry and the body.Stdio.cpp:1306-1332: the macOSsceKernelGetdirentriesskips entries when the guest deletes entries between calls.baseentries of a fresh listing.rmdirfails withENOTEMPTY. Creating entries between calls can return an entry twice.:174covers hostreaddirandlseekon the same descriptor, but not this case.d_inoand name, or byd_seekoffif APFS fills it in (I have not checked that it does). Otherwise, add this case to the entry.Smaller points:
ModuleInfo.cpp:177-181: on macOS,sceKernelGetModuleInfoFromAddrreportseh_frame_hdras 0, and the debt entry says so. ButsceKernelGetModuleInfoForUnwindalready readsPT_GNU_EH_FRAMEfor relinked images from the__metaprogram headers (Module.cpp, the macOSdl_iterate_phdrbranch). The same source would filleh_frame_hdrhere. Then the body's "eh_frame_hdr is 0 (Mach-O has none)" would also be correct for relinked images.NativeStat.cpp:85-101: if a//falls exactly at the split point (/at indexPATH_MAX - 1andPATH_MAX),reststarts with/, soopenatandfstatatresolve it from the host root. Stripping leading slashes fromrestafter each split would prevent that. I found this by reading the code.FindImage(:116-138): an image with a__metasection of 0x10 to 0x5f bytes is accepted here, butdl_iterate_phdrskips it. Checking for at least 0x60 bytes, asGuestImages.cppdoes, would keep the two in step.guest_aioon macOS needs #10543" are out of date.--no-as-needed/nid_patcher_dynamic_stringsguard is now onmain, soc9b9dac5dno longer changesCMakeLists.txt.d130c8ee3is typedperfwithouttrace_digestnumbers;refactorwould fit.Not checked here: Linux, Windows, a build of the PR's own
DirectoryDescriptor.cppandRtld.cppat this head (my "with" set has theirea0213b6aversions), and this PR together with #10627.AI-assisted: yes (Claude Code applied the PR, ran the tests, read the code and wrote this review).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T05:41:48Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The dependency description is stale and the replacement branch has a real integration conflict. #11872 is closed and was replaced by the read work in #12682 (followed by #12688 and #12700). A pairwise merge preview of this PR’s current head with #12682 conflicts in
core/libs/prx/libkernel/File/src/Stdio.cpp, which both branches change. My earlier comment asked for the order against the replacement IDs; the checklist still names only #11872.What I ran
2f75dd54e9240fed729e9be0a541d8f074fc31e1, currentmain52c09d567d2fa453494dd720fcf53a98149468e4, and replacement PR #12682.git merge-tree --write-treebetween the exact heads of #10552 and #12682, and inspected bothStdio.cppdiffs.Results
maincore/libs/prx/libkernel/File/src/Stdio.cppPlease coordinate the order with the affected PR author(s), update
Depends onto the current open PRs as appropriate, and validate the combinedStdio.cppbehavior after integration. I am not requesting that either PR be closed or abandoned.