Repository navigation
feat(libkernel): process, thread and clock queries on macOS hosts - #7804
Conversation
|
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.
|
…queries on macOS hosts (@mugurc) This branch already carried this part of mugurc's macOS series; boykopovar#7804 is the same change split out for main. Merging it records the PR here and in Depends on, so landing it first only shrinks this branch. Its only lines this branch lacked are Time.cpp's Mach and pthread includes in a second place, which duplicate the ones the branch already has, so the merge keeps a single copy and the code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…queries on macOS hosts (@mugurc) This branch already carried this part of mugurc's macOS series; boykopovar#7804 is the same change split out for main. Merging it records the PR here and in Depends on, so landing it first only shrinks this branch. Its only lines this branch lacked are Time.cpp's Mach and pthread includes in a second place, which duplicate the ones the branch already has, so the merge keeps a single copy and the code is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Same setup. Merged after #7631 with no code conflicts: |
imellag
left a comment
There was a problem hiding this comment.
Tested head 4fd1093119 on Apple M4 Pro, macOS 27.0.1, Apple clang, x86-64 Release under Rosetta 2.
Alone on main 3fcb5e4d76: Pthread/src/Thread.cpp and System/src/Process.cpp now compile, with no new build failures.
With the other open macOS build PRs (the same stack as in my review of #7631): guest_getrusage, guest_current_cpu, guest_available_cpumask, guest_thread_cpu_clock, guest_cpu_time_clocks, guest_freebsd_clocks, guest_nanosleep and guest_pthread_stack pass.
guest_system_configuration aborts in CheckVmmapSysctl, which main added after this PR's base (20764888c3, 2026-10-17). kern.proc.vmmap leaves errno at 2 because sceKernelVirtualQuery reads /proc/self/maps on macOS. This doesn't come from this PR: the test passes once f66a4df741 is added (details on #7631).
AI-assisted: yes
|
Merge: Tested on macOS 27.3, Apple M5 Pro, Apple clang, x86_64 Release under Rosetta 2, on that merge plus #4630 and #16591: AI-assisted: yes |
4fd1093 to
d05d509
Compare
|
Rebased onto current |
What
Process, thread and clock queries on macOS hosts. They read
/procor call glibc extensions (pthread_getattr_np,pthread_getcpuclockid,sched_getcpu,RUSAGE_THREAD), solibkerneldoes not compile on macOS without this. Part of the macOS series announced on #1 (#1 (comment))._NSGetArgcand_NSGetArgvinstead of/proc/self/cmdline.pthread_cpu_number_np.getrusagefor a thread, the CPU clock of a guest thread andclock_gettimewith the thread CPU clock (14) read the Machthread_infoof the thread. macOS has nopthread_getcpuclockid, and under Rosetta its ownCLOCK_THREAD_CPUTIME_IDcannot stand in for 14: it advances by about 1/41.7 of the thread's CPU time (24 MHz ticks read as nanoseconds) and reports a 1 ns resolution, so the guest thread's clock and clock 14 would disagree.pthread_get_stackaddr_npandpthread_get_stacksize_np.SleepNanoskeepserrno: macOS'snanosleepleavesETIMEDOUTin it when it returns 0, and the guest'serrnois the host's. This hunk is in the non-Windows branch, so Linux runs it too; Linux'snanosleepleaveserrnoalone on success, so the only change there is that a sleep interrupted and then finished no longer leavesEINTRbehind.guest_pthread_stackallows two frames between the stack top and the first local on macOS, where that local lies 4,464 bytes below the top.The whole-port PRs #7201 and #7332 contain these functions too; #7332 carries this commit from the series.
Tested
macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2.
mainc1ca834 with the rest of the macOS series (ci/macos-series-2on my fork) and the open macOS fixes #6667, #6668, #6969, #6853, #6836, #7524, #6685 and #6686, #6928's change, and three changes from #7332; the libraries do not link on macOS without the series.libkerneldoes not compile on macOS (pthread_getattr_np,pthread_getcpuclockid,sched_getcpu,RUSAGE_THREAD). With itguest_getrusage,guest_current_cpu,guest_available_cpumask,guest_thread_cpu_clock,guest_cpu_time_clocks,guest_freebsd_clocks,guest_nanosleep,guest_system_configurationandguest_pthread_stackpass.CLOCK_THREAD_CPUTIME_ID,guest_thread_cpu_clockaborts. A probe built for x86-64 and run under Rosetta: three busy loops thatthread_infomeasures at 58, 77 and 76 ms moveCLOCK_THREAD_CPUTIME_IDby 1.4, 1.8 and 1.8 ms. Built for arm64, the two agree to the microsecond (130.028 ms each), andCLOCK_PROCESS_CPUTIME_IDagrees withgetrusageunder Rosetta too (373.2 ms each), so only the thread clock needsthread_info.errnorestore inSleepNanos,guest_nanosleepandguest_system_configurationabort.nanosleepthat returns 0 leftETIMEDOUTinerrnoin 20 of 20 calls, under Rosetta and natively.ninja,ninja libsandctest -j4: 1535 tests, 930 passed, 19 failed, the rest skipped (no Vulkan loader in the environment); none of the 19 is among the tests above, and they are the ones listed in feat(libkernel): direct memory mappings on macOS hosts #7631.SleepNanos, every change is in an__APPLE__branch.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)