Repository navigation
fix(libkernel): build the file, module and rtld calls on macOS hosts - #10552
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Exports introduced here that are already present in
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Linux check: Ubuntu 24.04, g++ 13.3.0, x86-64 Release (x86-64 chroot under Rosetta in an Apple Silicon VM), on Tests: |
MarcZX10
left a comment
There was a problem hiding this comment.
The macOS AppendingWritev fallback has a correctness hole and overlaps directly with the helper in open PR #10543. Here it treats any descriptor with O_APPEND as an appendable regular file and calls writev even when the saved lseek position is negative. For example, an O_APPEND pipe/non-regular descriptor can be written successfully here although pwritev should fail with ESPIPE; if saving the offset fails, the code also performs the write without being able to restore the shared descriptor position. #10543’s WritevAtEnd checks fstat/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 an O_APPEND pipe and a regular-file offset-preservation case would cover the boundary.
|
@krishalivaibhav #10627 touches the same AI-assisted: yes |
|
@maximilianfv yes, fine with #10627 landing first. I'll drop the |
imellag
left a comment
There was a problem hiding this comment.
Tested head 972a2c6525 on Apple M4 Pro, macOS 27.0.1, Apple clang, x86-64 Release under Rosetta 2. Two points for the rebase.
Conflict in ModuleInfo.cpp. On main 3fcb5e4d76, NativeStat.cpp, SharedMemory.cpp, Stdio.cpp, DynamicLoader.cpp and Rtld.cpp compile with this PR, but ModuleInfo.cpp conflicts. #10230 rewrote sceKernelGetModuleInfoFromAddr:
- it accepts flags 1 and 2;
- it leaves
st_size0; - it builds a
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 Apple SystemImage reads:
#elif defined(__APPLE__)
Dl_info symbol{};
const bool found = Fill(static_cast<std::uintptr_t>(address), result) &&
::dladdr(reinterpret_cast<const void*>(address), &symbol) && symbol.dli_fbase != nullptr;
const GuestImage image{nullptr, found ? reinterpret_cast<std::uintptr_t>(symbol.dli_fbase) : 0};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_statvfs and guest_file_timestamps pass.
guest_module_info aborts at GuestModuleInfo.cpp:68 (info.eh_frame_addr != 0). Apple ld gives the fixture only compact unwind information: otool -l libguest_module_fixture.dylib lists __text and __unwind_info, with no __eh_frame. So the Mach-O branch of Fill leaves the eh_frame fields 0. The eh_frame_hdr check on the next lines can't hold for Mach-O either.
AI-assisted: yes
972a2c6 to
e60d9df
Compare
|
@MarcZX10 thanks. I removed the macOS Since the push I also added a second commit: Tested on M2, x86_64 Release,
|
|
@imellag thanks for testing. The rebased head About AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-reviewed exact head e60d9dfa3a911ebdc0847f229eebae1878e4e487. The earlier O_APPEND fallback concern is resolved by removing that path, and the F_GETPATH addition matches the macOS descriptor-path need. I cannot approve this head yet for two concrete reasons:
- GitHub currently reports the branch as
DIRTYagainstmain; please rebase and rerun checks. - The existing cross-platform
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.
|
Thanks for confirming the macOS fixture has no |
e60d9df to
3206fbd
Compare
|
@MarcZX10 thanks. I rebased onto I added a third commit for
Tested on M2, x86_64 Release,
AI-assisted: yes (Claude Code) |
The long-path fallback in NativeStat opened each intermediate directory with O_RDONLY | O_DIRECTORY, which needs read permission on it. stat and fstatat only need search permission, so a path through an execute-only directory failed with EACCES once it crossed PATH_MAX. O_SEARCH (O_EXEC | O_DIRECTORY on Darwin) needs only search permission and still rejects a non-directory.
The macOS sceKernelGetdirentries wrote *basep and the entry records into buf without entering GuestArena::HostWrite, so the write-watch host-write path never saw those writes. It now opens HostWrite guards for buf over nbytes and for basep before it moves the descriptor offset, and holds them through every write, as the Linux path does. It also rejects a non-directory with EINVAL before the guards, matching Linux.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ed on macOS Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rite on macOS Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tory Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hared memory Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…odule info entries Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2f75dd5 to
3dffebe
Compare
|
@imellag's A/B above already shows this PR is required for the libraries to build on macOS: pull it out of that twelve-PR set and One thing has to be removed first in both arms, or there is nothing to measure: Files that fail to compile: 14 on
The useful half is the residue. Every one of the eight that remain belongs to another open pull request, so none of them is an argument against this one:
I checked each one against that pull request's changed-file list rather than inferring it from the error. Environment: macOS 27.2 (build 26B123), Apple M5, Apple clang 21.0.0 from the Xcode command-line tools, CMake 4.4.0, Ninja 1.13.2, Release with This measures compilation only. I did not run anything: AI-assisted: yes. |
Stale: all four points are addressed on 3dffebe (duplicate debt entry removed, handle-0 dlsym fixed, dead fallback loop removed, getdirentries-after-delete documented in the debt file).
|
@krishalivaibhav we're going to merge this one before #12682, #12688 and #12700, once CI is green on this head, rather than after them as the Depends on line says. Those three are held for a while, and this PR is ready now: maximilianfv's four points are all addressed, and on an M4 every file it changes compiles. No rebase needed from you; when they land, the conflict is two small |
|
@oneandonlydean Thanks, that works for me. I've updated the Depends on line to match: this goes first, and #12682, #12688 and #12700 follow. @Felipebmaitan, this changes the order we agreed: when #10552 lands, your @MarcZX10 The Depends on line your review flagged is now current, so could you take another look when you have time? @javierUDP Thanks for testing this PR on its own against main. |
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 fix(libkernel): answer the thread atexit references as measured on a PS5 #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
main809c7fa (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(e7e3e9c) + #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
main60465af + 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 feat(libkernel): direct memory mappings on macOS hosts #7631, feat(libkernel): process, thread and clock queries on macOS hosts #7804 and feat(libkernel): sceKernelRaiseException on macOS hosts #4630🤖 Generated with Claude Code