fix(libkernel): measure the guest stack on Apple #12112
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12112"
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 wanderingbug on 2026-10-27T21:24:55Z.
What
Darwin has no
pthread_getattr_np. Current main still calls it fromHostStackLimits, so that function does not compile on macOS. This PR reads the host stack withpthread_get_stackaddr_npandpthread_get_stacksize_np. The address is the high end of the stack.CallGuestOnMeasuredStackis[[gnu::noinline]]. It samples the stack pointer, registers that window, callsAps5CallGuestEntry, and emits a memory clobber so Clang does not tail-call it. The extra 320 KiB host margin is added only on Apple.GuestThreadSelfprints the worker window after join. Windows guard-page paths stay as they are.Open PR #7804 also queries
pthread_get_stackaddr_npandpthread_get_stacksize_npfor host stack limits, and does not addCallGuestOnMeasuredStack. If #7804 merges first, the duplicateHostStackLimitslines can be dropped while keepingCallGuestOnMeasuredStack.Tested
Linux, gcc 13, Release, against upstream main
e0cd1259a9. Rebuilt libkernel. Passed guest_thread_self and guest_pthread_stack.python3 tools/check_conventions.py --base upstream/mainpassed.Guest smoke on the combined reference f91b74b1c passed on Apple M1 Max, macOS 27, Rosetta 2.
Checklist
main(e0cd1259a9). Open PR #7804 also queriespthread_get_stackaddr_npandpthread_get_stacksize_npfor host stack limits, and does not addCallGuestOnMeasuredStack.NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt filePull request closed