build(libkernel): compile Thread on macOS #11246

Closed
iamthehimansh wants to merge 1 commit from upstream-pr/11246 into main
iamthehimansh commented 2026-10-25 22:32:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by iamthehimansh on 2026-10-25T22:32:25Z.


What

Next part of splitting #8658: libkernel's Pthread/src/Thread.cpp does not compile on macOS. The change is macOS-only; Linux and Windows compile the same code as before.

  • Stack bounds: macOS has no pthread_getattr_np. It takes the stack top from pthread_get_stackaddr_np and the size from pthread_get_stacksize_np.
  • Thread CPU time: macOS has no pthread_getcpuclockid. The thread's Mach port is stored when the thread starts, and its user plus system time is read with thread_info(THREAD_BASIC_INFO). Pthread.hpp holds that port in place of the clockid_t on macOS.

#11201 and #10856 also change Thread.cpp, in other functions; neither touches these lines.

Tested

macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on main at b90d009d9: Pthread/src/Thread.cpp.o and Pthread/Posix/Thread.cpp.o compile, where main fails the first. The libkernel tests cannot run on macOS until the rest of libkernel builds (#11240 and follow-ups), so this is a compile check only. On #8658's branch the same code passed guest_thread_cpu_clock 3 of 3 runs. For Linux and Windows, I checked each file's view under unifdef -U__APPLE__, with -D__linux__ and with -D_WIN32: it equals main. python3 tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Cana)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009381488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11246). Originally posted by [iamthehimansh](https://github.com/iamthehimansh) on 2026-10-25T22:32:25Z. --- ### What Next part of splitting #8658: `libkernel`'s `Pthread/src/Thread.cpp` does not compile on macOS. The change is macOS-only; Linux and Windows compile the same code as before. - Stack bounds: macOS has no `pthread_getattr_np`. It takes the stack top from `pthread_get_stackaddr_np` and the size from `pthread_get_stacksize_np`. - Thread CPU time: macOS has no `pthread_getcpuclockid`. The thread's Mach port is stored when the thread starts, and its user plus system time is read with `thread_info(THREAD_BASIC_INFO)`. `Pthread.hpp` holds that port in place of the `clockid_t` on macOS. #11201 and #10856 also change `Thread.cpp`, in other functions; neither touches these lines. ### Tested macOS 26 on an Apple M2 Pro, x86_64 under Rosetta 2, Release with Ninja, on `main` at `b90d009d9`: `Pthread/src/Thread.cpp.o` and `Pthread/Posix/Thread.cpp.o` compile, where `main` fails the first. The `libkernel` tests cannot run on macOS until the rest of `libkernel` builds (#11240 and follow-ups), so this is a compile check only. On #8658's branch the same code passed `guest_thread_cpu_clock` 3 of 3 runs. For Linux and Windows, I checked each file's view under `unifdef -U__APPLE__`, with `-D__linux__` and with `-D_WIN32`: it equals `main`. `python3 tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes ([Cana](https://cana.build))
MarcZX10 commented 2026-10-25 22:34:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:34:09Z.

Review: COMMENTED


The macOS branches are consistent with the APIs used: the stack bounds come from the pthread stack address/size, and the cached pthread_mach_thread_np port is queried with THREAD_BASIC_INFO for user plus system CPU time. I did not find a concrete code defect. The checks on this head pass eligibility, conventions, intake, labels and report; product/build jobs are skipped, and the PR's local evidence is compile-only.

Because both changed behaviors are macOS-only, could someone with macOS run the existing guest-thread stack and CPU-clock tests (or add focused coverage if those tests do not exercise these branches) before merge? I have not run the runtime paths on macOS, so I am leaving this as a comment rather than approving on compile evidence alone.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645697092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11246#pullrequestreview-5645697092). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:34:09Z. **Review:** COMMENTED --- The macOS branches are consistent with the APIs used: the stack bounds come from the pthread stack address/size, and the cached `pthread_mach_thread_np` port is queried with `THREAD_BASIC_INFO` for user plus system CPU time. I did not find a concrete code defect. The checks on this head pass eligibility, conventions, intake, labels and report; product/build jobs are skipped, and the PR's local evidence is compile-only. Because both changed behaviors are macOS-only, could someone with macOS run the existing guest-thread stack and CPU-clock tests (or add focused coverage if those tests do not exercise these branches) before merge? I have not run the runtime paths on macOS, so I am leaving this as a comment rather than approving on compile evidence alone.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11246
No description provided.