Skip to content

feat(libkernel): implement pthread_timedjoin_np - #8890

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
UnhealthyKraken:feat/libkernel-pthread-timedjoin
Oct 23, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
UnhealthyKraken:feat/libkernel-pthread-timedjoin

Conversation

@UnhealthyKraken

@UnhealthyKraken UnhealthyKraken commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Implement pthread_timedjoin_np (PkS44IGrDkM) through the existing guest join lifecycle. A timed-out or canceled join releases its claim and leaves the target joinable; success retains the existing native teardown and return-value handling. Validate deadlines before thread arguments, preserve POSIX errno, and convert absolute realtime deadlines without overflowing on distant dates.

The public PS5 SDK supplies the prototype, the public 3.20 table and symbol database corroborate the NID, and FreeBSD libthr supplies the behavior reference. PS5 behavior and module/library versions remain unmeasured. The debt entry records realtime recheck granularity and the limitation that final native teardown after guest completion is unbounded. General scoped sys/web fallback merged in #8867; the remaining throwing sys declaration is removed here to satisfy the current duplicate-export rule, with actual-library sys/web regression coverage in dependent #9582.

Tested

Windows x86-64, GCC 15.2, Release; isolated checkout based on aa408677b0e794cf59f314ebcf9a716ede638295. No games or USB hardware used.

Regression added first: both normal/coarse modes fail on the baseline's missing export. With identical test executables and only the unpatched kernel swapped, baseline passes 14 existing tests and fails the two new cases; candidate passes all 16. After rebasing, the full affected libs build succeeds and 17/17 tests pass, including all 354 patched libraries loading with zero failures. Loading checks linkage only.

Coverage includes invalid/null deadline precedence, null/self/detached/already-joined targets, past/future/distant deadlines, completed-target success with an expired deadline, unchanged deadline/errno, return-slot bounds, timeout-and-retry, competing joiners, cancellation and claim release. Existing join/detach/self/second-join, cancellation/recovery and sleep-cancellation cases pass. Tests run in normal and coarse modes where registered. No Linux/macOS or console execution; host scheduling latency and wall-clock adjustment were not injected.

Conventions, whitespace and test registration pass (1146 targets, none unregistered). Independent read-only review found no actionable defect and did not rerun tests. The required overlap report was reviewed manually, including its base-conflicted shared-file warnings: no duplicate timed-join export. #7149 adds stack reaping to the native join tail and may need adaptation to the shared helper if merged; #6044 reorganizes tests. No dependency on either.

Review follow-up

Merged current main 329efe1bfdaff116c57cdf62718026ee4f5521ae without rewriting published history. Canonical #8890 head: 235ea5fd2260c6327eab43a82f08fd70c2236925; dependent #9582 head: da52d09106ac0353b8b0d9f4de526d1c1b4caeb7. The shared Thread.cpp is identical between these heads. The refreshed combined stack rebuilt affected Windows libraries and passed all 20 selected timed-join, sys/web import, lifecycle/cancellation, kernel-sys and patched-library suites. This is a combined-stack run, not a separate run of the prerequisite-only DLL. Linux/macOS and console execution remain unavailable locally. Test registration and conventions were rechecked. The refreshed checker rejects #8890 alone while the duplicate sys discovery declaration exists, so its deletion is now included in #8890 (235ea5f). #9582 retains the actual-library sys/web regression coverage. The final combined tree is byte-for-byte identical to tested stack 4158a67; this history adjustment changes no tested source.

Proposed integration order is #8890 followed by #9582. Coordination with #7149 must retain its successful Windows join stack reaping in the shared join-success path and its detach/exit behavior. #9713 must retain its five sys implementations while dropping their discovery declarations and this follow-up's timed-join declaration. If #6044 lands first, move/register the new tests according to its final directory/helper/label conventions. These external landing agreements are pending; the unrelated branches were not combined or tested here. There is no duplicate timed-join provider.
The latest overlap scan (upstream snapshot b7d1d47) reports textual conflicts with #9713 and #9770, plus 22 base-conflicted shared-file warnings. Manual inspection also identifies #4563: its Reap-before-native-wait protocol must be retained inside the shared success path if combined, with AwaitReap/detach handling preserved. #9770 removes/reorganizes the adjacent registration block; keep the timed-join wrapper and verify registration after either landing order. No combined validation of these external branches is claimed. These coordination items remain open rather than being presented as clean integration.

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

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Progress report (b7d1d47 → 235ea5f)

📈 System libraries: 43.24% (+0.01%, +1 implemented, -1 removed functions)

✅ 1 implemented
Library Name
libkernel pthread_timedjoin_np_nid_postfix
🗑️ 1 removed
Library Name
libkernel_sys pthread_timedjoin_np_nid_postfix

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 3986 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 4563 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6149 docs/dev/debt/libkernel.md
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6830 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7149 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 7509 docs/dev/debt/libkernel.md
PR 7565 core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 7653 docs/dev/debt/libkernel.md
PR 8010 docs/dev/debt/libkernel.md
PR 8520 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 8553 docs/dev/debt/libkernel.md
PR 8592 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 9019 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9040 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9103 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9133 docs/dev/debt/libkernel.md
PR 9161 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9162 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9172 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9322 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9442 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9447 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp
PR 9561 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9573 core/libs/prx/libkernel/Pthread/src/Thread.cpp
core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9669 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 9693 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel_sys/Export.Discovery.cpp
docs/dev/debt/libkernel.md
PR 9713 core/libs/prx/libkernel_sys/Export.Discovery.cpp
PR 9823 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp

@MarcZX10

Copy link
Copy Markdown
Contributor

I checked the overlap report against #8837: that PR adds the same pthread_timedjoin_np_nid_postfix name as a throwing export in libkernel_sys, while this implementation is built into libkernel. Is the SDK import inventory clear that this NID is only requested from libkernel? If a title imports it from libkernel_sys, that provider will still resolve to the throwing stub after #8837 merges, so it may be worth documenting or testing the module-scoped case.

@xdCloudy

Copy link
Copy Markdown
Contributor

I checked the public PS5 3.20 export bindings: NID PkS44IGrDkM (pthread_timedjoin_np) is listed by both libkernel_sys.c at line 9177 and libkernel.c at line 8192.

So the inventory shows this export in both providers, not only libkernel. My #8837 declaration reflects the libkernel_sys entry; AnyPS5’s implementation there is still a throwing placeholder. That means the module-scoped resolution question Marc raised remains relevant if an import requests it from libkernel_sys.

@Filip722

Copy link
Copy Markdown
Contributor

Linux integration validation of exact head c44f3b59f741f50485b36af225639c6edcd6a547: all 16 selected lifecycle/cancellation cases pass, including both timed-join registrations. The two new timed-join cases also each pass three consecutive executions.

The tests load the actual full-project libkernel.prx and exercise deadline validation precedence, self/null/detached/already-joined targets, timeout then retry, completed targets with expired deadlines, distant deadlines, errno/deadline/return-slot preservation, competing joiners, and cancellation releasing the join claim so the target remains joinable. Existing join/detach, self/second-join, cancellation/recovery, and sleep-cancellation controls pass.

Negative control: kept the same test executables, replaced only the two changed pthread implementation files with merge-base aa408677b0e794cf59f314ebcf9a716ede638295, and rebuilt libkernel. Result: 14 controls pass; only the two new cases fail, both reporting pthread_timedjoin_np export is missing. Restoring the exact PR sources and rebuilding makes both cases pass again.

Also ran the repository's NID packaging commands on a temporary kernel copy, using an export-preservation list generated from the same built libc. The patched ELF contains exactly one defined PkS44IGrDkM export. This verifies symbol packaging, not a complete patched-runtime load or the separate module-scoped provider question.

Environment: Debian 13.7 x86-64, Linux 7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC 15.2.0, CMake 3.31.6. Full Release configuration with BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, bundled dependencies; built libkernel, all selected executables and the NID tool with two jobs.

ctest --test-dir build \
  -R '^(guest_timed_join_(normal|coarse)|guest_pthread_(join_detach|join_self|second_join|cancel|cancel_recovery|cancel_recovery_coarse)|guest_sleep_cancel_.*)$' \
  --parallel 2 -V
ctest --test-dir build -R '^guest_timed_join_(normal|coarse)$' --repeat until-fail:3 -V

Tracked sources restored to the named head. This run uses canonical libkernel; libkernel_sys-scoped imports remain outside this evidence. No injected wall-clock adjustment, new Windows/macOS run, PS5 hardware, title, GPU or full repository test-suite run.

AI-assisted testing and report.

@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

The inventory is not limited to libkernel: the pinned public 3.20 table also lists PkS44IGrDkM in libkernel_sys. This PR implements and tests the canonical libkernel provider only. I updated the description to state that explicitly.

#8837 is merged with a throwing libkernel_sys declaration. Although #8867 is also merged and #8853 is closed, its requested-variant-first search means an existing variant stub can shadow the canonical implementation. That fallback change alone does not establish working timed-join calls through the stub, and I am not claiming sys/web-scoped behavior here. The separate provider gap remains outside this focused runtime implementation.

I also recorded Filip722's canonical-libkernel Linux results with the exact tested head and attribution. No runtime code changed in this follow-up; existing validation limits remain.

@github-actions github-actions Bot added the fix error Closes an issue (Fixes #N) label Oct 22, 2026
@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

The remaining provider limitation is addressed in dependent follow-up #9582, keeping this PR's canonical implementation unchanged. It removes libkernel_sys's throwing declaration so the existing requested-variant-first resolver can fall through to libkernel. libkernel_web already falls through correctly and is retained as a passing control. No duplicate export or resolver-priority change is introduced.

The regressions relink synthetic ELF executables with actual NID-scoped imports and load real patched libraries. They cover null/invalid deadlines, validation before an invalid thread pointer, and a create/timed-join round trip with the full-width return value. With identical generated executables and only the variant DLL swapped, baseline gives four sys failures/four web passes; candidate passes all eight cases, then 80 repeated executions. The full Windows libs build and 20 selected suites pass, including the 360-library loader. #9582 records the initial sandbox filesystem failure, normal-permission baseline comparison, skipped symlink cases and unavailable platform/hardware validation.

#9582 declares Depends on #8890. Neither PR has been merged by me. AI-assisted: yes.

@UnhealthyKraken

Copy link
Copy Markdown
Contributor Author

Refreshed onto main 329efe1 with history-preserving merges. #8890 is now 235ea5f; #9582 is da52d09. All 20 selected Windows suites pass, including actual sys/web imports, canonical normal/coarse timed join, lifecycle/cancellation, kernel-sys and patched-library loading. Conventions, registration (1176 executables, none unregistered) and whitespace pass. No Linux/macOS or console retest; the full repository suite was not run.

The current conventions checker newly rejects the prerequisite alone while the duplicate sys discovery declaration exists. I therefore included that deletion in #8890; #9582 now retains the scoped-import regressions. The final combined tree is identical to the tested 4158a67 tree, and the regression-first baseline evidence remains in the PR description. No published history was rewritten. The invalid-deadline/valid-self precedence control is retained.

Proposed order: #8890, then #9582. @Pouare514 (#7149), preserve your successful Windows join ReapRetiredWinStacks call in the shared success path, and the detach/exit retirement logic. @poonasor (#4563), the Reap-before-native-wait handshake similarly belongs in that shared path if your protocol lands, preserving AwaitReap and detach handling. @simonbronk (#9713), retain your five sys implementations and remove their discovery stubs together with the timed-join stub; this is an adjacent deletion conflict. @giannireale (#9770), your removal/reorganization of the adjacent registration block must retain the timed-join wrapper and correct registration. @TaymKal (#6044), if the test reorganization lands first, I will adapt the canonical and sys/web fixtures to its final paths/helpers/labels. Please confirm the intended landing order for these overlaps. These external branches were not combined/tested here, and agreement remains pending.

The refreshed overlap scan reports #9713/#9770 textual conflicts and 22 base-conflicted shared-file warnings; their shared diffs were inspected, including the lifecycle interactions above. The generic intake hold was withdrawn, so I am not treating it as a blocker. The wider audit will pause after this review-follow-up pass.

@github-actions github-actions Bot added prx and removed fix error Closes an issue (Fixes #N) labels Oct 22, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 22, 2026
@oneandonlydean
oneandonlydean merged commit c31f139 into boykopovar:main Oct 23, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants