feat(libwebrtc): implement CurrentThreadId #15154

Merged
MarcZX10 merged 4 commits from upstream-pr/15154 into main 2026-11-07 01:16:49 +00:00
MarcZX10 commented 2026-11-02 19:00:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T19:00:55Z.


What

  • rtc::CurrentThreadId() (_ZN3rtc15CurrentThreadIdEv): returns the guest thread id, the value scePthreadGetthreadid() returns on the calling thread. Firmware 13.42 libwebrtc.sprx implements this export as a tail call to scePthreadGetthreadid (reported by BunnyFl from disassembly; not measured on a console).
  • Test: tests/CurrentThreadId.cpp, registered as guest_webrtc_current_thread_id. It checks that the value is positive and stable, differs between two threads, and equals scePthreadGetthreadid() on the main thread and on a second thread.
  • libwebrtc now links libkernel.

Tested

  • Linux, run_tests.sh in a throwaway verify tree at head 7dc9a8e504 (target guest_webrtc_current_thread_id_tests libwebrtc, ctest regex ^(guest_webrtc_current_thread_id|public_headers)$): 1/2 Test #406: public_headers ... Passed, 2/2 Test #3345: guest_webrtc_current_thread_id ... Passed, 100% tests passed, 0 tests failed out of 2. Build exit 0.
  • python3 tools/check_conventions.py: all checks passed. git diff --check: clean.
  • Not run: Windows build and test; the rest of the libwebrtc test set; a negative control on the new head.

Not verified

Left as stubs (dependencies not in the repo or layout not available yet):

  • rtc::LogMessage statics and methods (LogThreads, LogTimestamps, LogToDebug, GetLogToDebug, AddLogToStream, RemoveLogToStream, SetLogToStderr, GetMinLogSeverity, stream): need the logging global state from rtc_base/logging.cc.
  • rtc::SSLAdapter::Create, rtc::Network::~Network, rtc::CopyOnWriteBuffer copy constructor and destructor, rtc::SocketAddress default constructor, copy assignment, IsComplete, IsNil, IsAnyIP, port, ipaddr: need class layouts and related sources not present in this repository.
  • rtc::IPAddress helpers (TruncateIP, CountIPMaskBits, ipv4_address, ipv6_address, v4AddressAsHostOrderInteger): need the IPAddress layout.
  • rtc::RateTracker (AddSamples, ComputeRateForInterval): needs the bucket state layout of the class.
  • rtc::Thread, rtc::ThreadManager, rtc::PlatformThread::Finalize: need the threading runtime.
  • rtc::RecursiveCriticalSection::Enter/Leave, rtc::RTCCertificate::HasExpired, rtc::webrtc_checks_impl::FatalLog, rtc::webrtc_logging_impl::Log: need the upstream platform layer and variadic log plumbing.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5125795910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15154). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T19:00:55Z. --- ### What - `rtc::CurrentThreadId()` (`_ZN3rtc15CurrentThreadIdEv`): returns the guest thread id, the value `scePthreadGetthreadid()` returns on the calling thread. Firmware 13.42 `libwebrtc.sprx` implements this export as a tail call to `scePthreadGetthreadid` (reported by BunnyFl from disassembly; not measured on a console). - Test: `tests/CurrentThreadId.cpp`, registered as `guest_webrtc_current_thread_id`. It checks that the value is positive and stable, differs between two threads, and equals `scePthreadGetthreadid()` on the main thread and on a second thread. - `libwebrtc` now links `libkernel`. ### Tested - Linux, `run_tests.sh` in a throwaway verify tree at head `7dc9a8e504` (target `guest_webrtc_current_thread_id_tests libwebrtc`, ctest regex `^(guest_webrtc_current_thread_id|public_headers)$`): `1/2 Test #406: public_headers ... Passed`, `2/2 Test #3345: guest_webrtc_current_thread_id ... Passed`, `100% tests passed, 0 tests failed out of 2`. Build exit 0. - `python3 tools/check_conventions.py`: all checks passed. `git diff --check`: clean. - Not run: Windows build and test; the rest of the libwebrtc test set; a negative control on the new head. ### Not verified Left as stubs (dependencies not in the repo or layout not available yet): - `rtc::LogMessage` statics and methods (`LogThreads`, `LogTimestamps`, `LogToDebug`, `GetLogToDebug`, `AddLogToStream`, `RemoveLogToStream`, `SetLogToStderr`, `GetMinLogSeverity`, `stream`): need the logging global state from `rtc_base/logging.cc`. - `rtc::SSLAdapter::Create`, `rtc::Network::~Network`, `rtc::CopyOnWriteBuffer` copy constructor and destructor, `rtc::SocketAddress` default constructor, copy assignment, `IsComplete`, `IsNil`, `IsAnyIP`, `port`, `ipaddr`: need class layouts and related sources not present in this repository. - `rtc::IPAddress` helpers (`TruncateIP`, `CountIPMaskBits`, `ipv4_address`, `ipv6_address`, `v4AddressAsHostOrderInteger`): need the `IPAddress` layout. - `rtc::RateTracker` (`AddSamples`, `ComputeRateForInterval`): needs the bucket state layout of the class. - `rtc::Thread`, `rtc::ThreadManager`, `rtc::PlatformThread::Finalize`: need the threading runtime. - `rtc::RecursiveCriticalSection::Enter/Leave`, `rtc::RTCCertificate::HasExpired`, `rtc::webrtc_checks_impl::FatalLog`, `rtc::webrtc_logging_impl::Log`: need the upstream platform layer and variadic log plumbing. ### 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
MarcZX10 commented 2026-11-02 19:07:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T19:07:11Z.

Review: COMMENTED


Reviewed — no blocking findings

I reviewed all three changed files at head ca85b796ca3f5905552771102bcd5228ff983ca6 and found no blocking issue for the documented Linux and Windows hosts; this self-review is not an independent approval.

What I ran

The PR is based on a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8; its exact head merges cleanly into that current main preview. I reviewed the complete diff, test assertions, and registration. Environment: Debian 12, Linux 6.1, Python 3.11.2, Git 2.39.5; no compiler or build was run.

git diff --check a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8...ca85b796ca3f5905552771102bcd5228ff983ca6
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15154 --output-dir /tmp/anyps5-pr-precheck-15154
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8 --head ca85b796ca3f5905552771102bcd5228ff983ca6 --json
python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp
python3 tools/check_conventions.py --base refs/review/15154/main
python3 tools/pr_stack_check.py 15154 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck-15154/stack
python3 tools/pr_overlap.py --branch refs/review/15154/head --repo boykopovar/AnyPS5 --jobs 8
gh pr checks 15154 --repo boykopovar/AnyPS5

The PR description reports a Linux focused CTest pass (1/1); I did not independently run it.

Results

Check Result Note
Diff and conventions passed No whitespace errors; template and conventions passed.
Export audit passed No CurrentThreadId-specific lexical finding; audit has unrelated alias warnings.
Test registration passed CMake registers the test; heuristic warning is a false positive.
Current-main merge preview passed Exact head merges cleanly.
Overlap scan failed Helper could not parse a repository response.
Hosted Windows, conventions and labels not run Still queued at the final check snapshot.
Hosted library portability passed This workflow does not compile libwebrtc/Export.cpp.
Local build, CTest and negative control not run No build was performed.
Check commands and outputs

The precheck's full results table and relevant raw output:

| Check | Status | Command / reason |
|---|---|---|
| build_and_compile | not_applicable | The precheck deliberately does not configure, build, or compile AnyPS5. |
| diff_check | passed | git diff --check a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8...ca85b796ca3f5905552771102bcd5228ff983ca6 |
| conventions_and_pr_template | passed | tools/check_conventions.py against exact base/head/title/body |
| changed_export_abi_audit | failed | helper absent from isolated PR checkout |
| python_syntax | not_applicable | No changed Python implementation files. |
| related_python_unit_tests | not_applicable | No changed tools module with a sibling test suite. |
| python_test_registration | not_applicable | No changed Python tests. |
| live_dependency_and_mergeability_check | passed | pr_stack_check.py |
| build_dependent_cpp_tests | not_applicable | C++ tests require exact-head binaries; precheck does not build. |
| test_quality_heuristics | failed | helper absent from isolated PR checkout |
| negative_controls | not_applicable | No changed Python test module in tools/. |
All conventions checks passed.
{"status":"passed_with_warnings","symbols":388,"CurrentThreadId findings":[]}
{
  "findings": [
    {
      "path": "core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}
pr_overlap: Invalid \\uXXXX escape: line 1 column 655256 (char 655255)
edge-watch\tskipping\t0
linux\tskipping\t0
register-context\tskipping\t0
relinker\tskipping\t0
relinker-asan\tskipping\t0
windows\tpending\t0
write-watch\tskipping\t0
eligibility\tpass\t9s
intake\tpass\t5s
library-portability\tpass\t1m52s
report\tpass\t1m38s
conventions\tpending\t0
labels\tpending\t0

Negative control

Assertion Change to code under test Did the new test fail?
ID is positive and stable on the current thread, and differs between two live threads. No mutation was made. Not run; exact-head CTest requires a build.

Findings

Blocking

None found in the reviewed files for the documented host targets.

Non-blocking

  • The overlap helper failed before completing its scan, so this review does not independently establish that no other open PR overlaps.
  • The test-quality heuristic did not recognize the CMake registration, but CMakeLists.txt explicitly registers guest_webrtc_current_thread_id and applies the Windows library search path.

Sources

Not verified

  • I did not run a local build, CTest, or negative control. The Linux CTest pass is author-reported.
  • Windows hosted tests, conventions and labels were queued at the final status snapshot; approval is withheld until required checks finish.
  • The portability workflow passed but its CMake source list does not include libwebrtc/Export.cpp; it does not verify this implementation.
  • Console behavior and non-Linux POSIX behavior were not tested.
  • The overlap scan did not complete.

To get this to a good state

No code change is requested from this self-review. Let the queued exact-head checks finish; an independent reviewer must assess the change. If the head changes, I will reread the full diff and rerun the same no-build checks and focused CTest when an exact-head build is available.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5741880341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15154#pullrequestreview-5741880341). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T19:07:11Z. **Review:** COMMENTED --- # Reviewed — no blocking findings I reviewed all three changed files at head `ca85b796ca3f5905552771102bcd5228ff983ca6` and found no blocking issue for the documented Linux and Windows hosts; this self-review is not an independent approval. ## What I ran The PR is based on `a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8`; its exact head merges cleanly into that current `main` preview. I reviewed the complete diff, test assertions, and registration. Environment: Debian 12, Linux 6.1, Python 3.11.2, Git 2.39.5; no compiler or build was run. ```sh git diff --check a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8...ca85b796ca3f5905552771102bcd5228ff983ca6 python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 15154 --output-dir /tmp/anyps5-pr-precheck-15154 python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8 --head ca85b796ca3f5905552771102bcd5228ff983ca6 --json python3 tools/pr_test_quality.py --root /marc/AnyPS5 --json core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp python3 tools/check_conventions.py --base refs/review/15154/main python3 tools/pr_stack_check.py 15154 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck-15154/stack python3 tools/pr_overlap.py --branch refs/review/15154/head --repo boykopovar/AnyPS5 --jobs 8 gh pr checks 15154 --repo boykopovar/AnyPS5 ``` The PR description reports a Linux focused CTest pass (1/1); I did not independently run it. ## Results | Check | Result | Note | |---|---|---| | Diff and conventions | passed | No whitespace errors; template and conventions passed. | | Export audit | passed | No `CurrentThreadId`-specific lexical finding; audit has unrelated alias warnings. | | Test registration | passed | CMake registers the test; heuristic warning is a false positive. | | Current-main merge preview | passed | Exact head merges cleanly. | | Overlap scan | failed | Helper could not parse a repository response. | | Hosted Windows, conventions and labels | not run | Still queued at the final check snapshot. | | Hosted library portability | passed | This workflow does not compile `libwebrtc/Export.cpp`. | | Local build, CTest and negative control | not run | No build was performed. | <details> <summary>Check commands and outputs</summary> The precheck's full results table and relevant raw output: ```text | Check | Status | Command / reason | |---|---|---| | build_and_compile | not_applicable | The precheck deliberately does not configure, build, or compile AnyPS5. | | diff_check | passed | git diff --check a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8...ca85b796ca3f5905552771102bcd5228ff983ca6 | | conventions_and_pr_template | passed | tools/check_conventions.py against exact base/head/title/body | | changed_export_abi_audit | failed | helper absent from isolated PR checkout | | python_syntax | not_applicable | No changed Python implementation files. | | related_python_unit_tests | not_applicable | No changed tools module with a sibling test suite. | | python_test_registration | not_applicable | No changed Python tests. | | live_dependency_and_mergeability_check | passed | pr_stack_check.py | | build_dependent_cpp_tests | not_applicable | C++ tests require exact-head binaries; precheck does not build. | | test_quality_heuristics | failed | helper absent from isolated PR checkout | | negative_controls | not_applicable | No changed Python test module in tools/. | ``` ```text All conventions checks passed. ``` ```text {"status":"passed_with_warnings","symbols":388,"CurrentThreadId findings":[]} ``` ```text { "findings": [ { "path": "core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` ```text pr_overlap: Invalid \\uXXXX escape: line 1 column 655256 (char 655255) ``` ```text edge-watch\tskipping\t0 linux\tskipping\t0 register-context\tskipping\t0 relinker\tskipping\t0 relinker-asan\tskipping\t0 windows\tpending\t0 write-watch\tskipping\t0 eligibility\tpass\t9s intake\tpass\t5s library-portability\tpass\t1m52s report\tpass\t1m38s conventions\tpending\t0 labels\tpending\t0 ``` </details> ## Negative control | Assertion | Change to code under test | Did the new test fail? | |---|---|---| | ID is positive and stable on the current thread, and differs between two live threads. | No mutation was made. | Not run; exact-head CTest requires a build. | ## Findings ### Blocking None found in the reviewed files for the documented host targets. ### Non-blocking - The overlap helper failed before completing its scan, so this review does not independently establish that no other open PR overlaps. - The test-quality heuristic did not recognize the CMake registration, but `CMakeLists.txt` explicitly registers `guest_webrtc_current_thread_id` and applies the Windows library search path. ## Sources - [Implementation at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/ca85b796ca3f5905552771102bcd5228ff983ca6/core/libs/prx/libwebrtc/Export.cpp#L469-L475) - [Test assertions at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/ca85b796ca3f5905552771102bcd5228ff983ca6/core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp#L22-L42) - [Test registration at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/ca85b796ca3f5905552771102bcd5228ff983ca6/core/libs/prx/libwebrtc/CMakeLists.txt#L31-L40) - [Pinned WebRTC M134 platform implementation](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/platform_thread_types.cc) ## Not verified - I did not run a local build, CTest, or negative control. The Linux CTest pass is author-reported. - Windows hosted tests, conventions and labels were queued at the final status snapshot; approval is withheld until required checks finish. - The portability workflow passed but its CMake source list does not include `libwebrtc/Export.cpp`; it does not verify this implementation. - Console behavior and non-Linux POSIX behavior were not tested. - The overlap scan did not complete. ## To get this to a good state No code change is requested from this self-review. Let the queued exact-head checks finish; an independent reviewer must assess the change. If the head changes, I will reread the full diff and rerun the same no-build checks and focused CTest when an exact-head build is available.
BunnyFl commented 2026-11-03 23:12:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-03T23:12:52Z.

Review: DISMISSED


@MarcZX10 thanks for this. Two things need to change before it can go in. One is a rule check that fails, the other is a firmware mismatch.

1. public_headers fails. core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8 declares the export again:

extern "C" int APS5_VABI _ZN3rtc15CurrentThreadIdEv_nid_postfix(void);

include/Api.hpp already declares it, and CONTRIBUTING forbids a second declaration in tests. On this head merged onto main (Windows 11, WinLibs GCC, Release), public_headers fails with:

_ZN3rtc15CurrentThreadIdEv_nid_postfix: expected exactly one header declaration; found 2: core\libs\prx\libwebrtc\include\Api.hpp:104, core\libs\prx\libwebrtc\tests\CurrentThreadId.cpp:8

Dropping that line fixes it, since the test already includes prx/libwebrtc/libwebrtc.hpp.

2. The id isn't the one the console returns. In firmware 13.42 system/common/lib/libwebrtc.sprx (sha256 d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314), _ZN3rtc15CurrentThreadIdEv (KXt+l3+jE3I) is a tail call into a PLT stub:

14b7f0: jmp    0x7a2cf0
7a2cf0: jmp    *0x219c02(%rip)        # 0x9bc8f8

The GOT slot 0x9bc8f8 is the import EI-5-jlq2dE, which is scePthreadGetthreadid. So on the console rtc::CurrentThreadId() is exactly the guest pthread's thread id. That is read from disassembly, not measured on a console. The module's own code is stronger evidence here than platform_thread_types.cc. Upstream has no PS5 branch there, and its default branch, which a FreeBSD build would take, is reinterpret_cast<PlatformThreadId>(pthread_self()), not gettid (platform_thread_types.cc).

With this PR the value is the host OS thread id (GetCurrentThreadId or SYS_gettid). AnyPS5's guest ids are a separate counter that starts at 100000 (core/libs/prx/libkernel/Pthread/include/Pthread.hpp:128), and scePthreadGetthreadid returns scePthreadSelf()->tid (core/libs/prx/libkernel/Pthread/src/Thread.cpp:1486). So for the same guest thread, rtc::CurrentThreadId() and scePthreadGetthreadid() give different numbers. A title or library that stores one and compares it with the other gets a mismatch the console never gives.

Suggested fix: return scePthreadGetthreadid(). libwebrtc then needs to link libkernel, since core/libs/prx/libwebrtc/CMakeLists.txt links only opus today. The test could then check _ZN3rtc15CurrentThreadIdEv_nid_postfix() == scePthreadGetthreadid() on the main thread and on a guest thread. Your existing stable and distinct-per-thread checks still hold.

What I ran: this head merged onto main, Windows 11, WinLibs GCC, Release. The _WIN32 branch builds, and guest_webrtc_current_thread_id passes (1 of 1). With main's Export.cpp put back, it aborts (1 of 1 failed). public_headers fails as above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5760819184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15154#pullrequestreview-5760819184). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-03T23:12:52Z. **Review:** DISMISSED --- @MarcZX10 thanks for this. Two things need to change before it can go in. One is a rule check that fails, the other is a firmware mismatch. **1. `public_headers` fails.** `core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8` declares the export again: ```cpp extern "C" int APS5_VABI _ZN3rtc15CurrentThreadIdEv_nid_postfix(void); ``` `include/Api.hpp` already declares it, and CONTRIBUTING forbids a second declaration in tests. On this head merged onto `main` (Windows 11, WinLibs GCC, Release), `public_headers` fails with: ``` _ZN3rtc15CurrentThreadIdEv_nid_postfix: expected exactly one header declaration; found 2: core\libs\prx\libwebrtc\include\Api.hpp:104, core\libs\prx\libwebrtc\tests\CurrentThreadId.cpp:8 ``` Dropping that line fixes it, since the test already includes `prx/libwebrtc/libwebrtc.hpp`. **2. The id isn't the one the console returns.** In firmware 13.42 `system/common/lib/libwebrtc.sprx` (sha256 `d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314`), `_ZN3rtc15CurrentThreadIdEv` (`KXt+l3+jE3I`) is a tail call into a PLT stub: ``` 14b7f0: jmp 0x7a2cf0 7a2cf0: jmp *0x219c02(%rip) # 0x9bc8f8 ``` The GOT slot `0x9bc8f8` is the import `EI-5-jlq2dE`, which is `scePthreadGetthreadid`. So on the console `rtc::CurrentThreadId()` is exactly the guest pthread's thread id. That is read from disassembly, not measured on a console. The module's own code is stronger evidence here than `platform_thread_types.cc`. Upstream has no PS5 branch there, and its default branch, which a FreeBSD build would take, is `reinterpret_cast<PlatformThreadId>(pthread_self())`, not `gettid` ([platform_thread_types.cc](https://webrtc.googlesource.com/src/+/8d78f5de6c27b2c793039989ea381f1428fb0100/rtc_base/platform_thread_types.cc)). With this PR the value is the host OS thread id (`GetCurrentThreadId` or `SYS_gettid`). AnyPS5's guest ids are a separate counter that starts at 100000 (`core/libs/prx/libkernel/Pthread/include/Pthread.hpp:128`), and `scePthreadGetthreadid` returns `scePthreadSelf()->tid` (`core/libs/prx/libkernel/Pthread/src/Thread.cpp:1486`). So for the same guest thread, `rtc::CurrentThreadId()` and `scePthreadGetthreadid()` give different numbers. A title or library that stores one and compares it with the other gets a mismatch the console never gives. Suggested fix: return `scePthreadGetthreadid()`. libwebrtc then needs to link `libkernel`, since `core/libs/prx/libwebrtc/CMakeLists.txt` links only `opus` today. The test could then check `_ZN3rtc15CurrentThreadIdEv_nid_postfix() == scePthreadGetthreadid()` on the main thread and on a guest thread. Your existing stable and distinct-per-thread checks still hold. **What I ran:** this head merged onto `main`, Windows 11, WinLibs GCC, Release. The `_WIN32` branch builds, and `guest_webrtc_current_thread_id` passes (1 of 1). With `main`'s `Export.cpp` put back, it aborts (1 of 1 failed). `public_headers` fails as above.
XairRrR commented 2026-11-04 00:11:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-04T00:11:59Z.

Review: DISMISSED


Reviewed — changes requested

rtc::CurrentThreadId() works and its test is a real one, but the test file makes public_headers fail, and the value doesn't match the guest thread id the console module returns.

What I ran

Head ca85b796ca3f5905552771102bcd5228ff983ca6, merged into main 1c8c0efc8c41314402e6966da5bef6ea3d639d10 (merged tree 7e305ff34529f1d7b2025c45c9259539d10dd918). Debian 13 VM, 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, a clean worktree.

git diff --check 1c8c0efc8c41314402e6966da5bef6ea3d639d10...ca85b796ca3f5905552771102bcd5228ff983ca6
python3 tools/check_conventions.py --base 1c8c0efc8c41314402e6966da5bef6ea3d639d10
ctest --test-dir build --output-on-failure -R '^guest_webrtc_current_thread_id$'
# negative control
git show 1c8c0efc8c41314402e6966da5bef6ea3d639d10:core/libs/prx/libwebrtc/Export.cpp > core/libs/prx/libwebrtc/Export.cpp
ninja -C build -j32 -l32 guest_webrtc_current_thread_id_tests libwebrtc
ctest --test-dir build --output-on-failure -R '^guest_webrtc_current_thread_id$'
git show 7e305ff34529f1d7b2025c45c9259539d10dd918:core/libs/prx/libwebrtc/Export.cpp > core/libs/prx/libwebrtc/Export.cpp
ninja -C build -j32 -l32 guest_webrtc_current_thread_id_tests libwebrtc
ctest --test-dir build -R '^guest_webrtc_current_thread_id$'
git status --porcelain

The prepared run also built the merged tree and ran the 833 selected tests.

Results

Check Result
git diff --check clean
check_conventions.py all checks passed
Configure, build, libs passed
guest_webrtc_current_thread_id passed (0.01 s)
Selected tests (833) 764 passed; 1 new failure: public_headers; 1 known failure on main (unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group), not caused by this PR
check_skips.py error: public_headers_compile_0 did not run because public_headers failed
Vulkan validation not applicable (no AGC driver, shader or VideoOut change)
public_headers
RuntimeError: _ZN3rtc15CurrentThreadIdEv_nid_postfix: expected exactly one header declaration; found 2: core/libs/prx/libwebrtc/include/Api.hpp:104, core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8

Negative control

I put main's core/libs/prx/libwebrtc/Export.cpp back and rebuilt. guest_webrtc_current_thread_id then failed with Subprocess aborted. After I restored the merged file and rebuilt, the test passed again, and git status --porcelain printed nothing.

Findings

Blocking

  1. Duplicate export declaration in the test breaks public_headers. core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8 declares _ZN3rtc15CurrentThreadIdEv_nid_postfix again. core/libs/prx/libwebrtc/include/Api.hpp:104 already declares it. CONTRIBUTING forbids a second declaration, and the prepared run on Linux confirms the public_headers failure that BunnyFl and the AMD CI comment reported. The fix is to delete the line: the test already includes prx/libwebrtc/libwebrtc.hpp.
  2. Host OS thread id instead of guest thread id. Export.cpp:469-475 at head (core/libs/prx/libwebrtc/Export.cpp:449 in the merged tree) returns GetCurrentThreadId() or syscall(SYS_gettid).
    • BunnyFl's disassembly of firmware 13.42 shows that the console export is a tail call to scePthreadGetthreadid. I have no firmware dump here, so I could not confirm the disassembly.
    • I did confirm the AnyPS5 side. Guest ids come from nextThreadId{100000}, and scePthreadGetthreadid returns scePthreadSelf()->tid. So with this PR, the two functions give different numbers for the same guest thread.
    • Upstream's non-Linux POSIX branch doesn't use gettid either, so the cited source doesn't support this choice for the console.
    • Suggested fix: return scePthreadGetthreadid() (declared in core/libs/prx/libkernel/include/Api.hpp:583), and link libwebrtc to libkernel (core/libs/prx/libwebrtc/CMakeLists.txt:15 links only opus). In the test, assert equality with scePthreadGetthreadid() on the main thread and on a guest thread.

Non-blocking

  • The distinct-per-thread check runs a host std::thread (core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:31), not a guest pthread. Once the value comes from the guest thread, the second thread should be created with scePthreadCreate, so the test covers the path titles take.

Not verified

  • The firmware disassembly in BunnyFl's review (I have no module dump).
  • The Windows/MinGW build of the _WIN32 branch (BunnyFl reports it builds and passes).
  • Behaviour on the console.

To get this to a good state

  • Delete the redundant extern "C" declaration from the test.
  • Return the guest thread id through scePthreadGetthreadid(), link libkernel, and extend the test to check that equality on the main thread and on a guest thread.
  • Rerun public_headers and guest_webrtc_current_thread_id.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761324408 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15154#pullrequestreview-5761324408). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-04T00:11:59Z. **Review:** DISMISSED --- # Reviewed — changes requested `rtc::CurrentThreadId()` works and its test is a real one, but the test file makes `public_headers` fail, and the value doesn't match the guest thread id the console module returns. ## What I ran Head `ca85b796ca3f5905552771102bcd5228ff983ca6`, merged into `main` `1c8c0efc8c41314402e6966da5bef6ea3d639d10` (merged tree `7e305ff34529f1d7b2025c45c9259539d10dd918`). Debian 13 VM, 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, a clean worktree. ```sh git diff --check 1c8c0efc8c41314402e6966da5bef6ea3d639d10...ca85b796ca3f5905552771102bcd5228ff983ca6 python3 tools/check_conventions.py --base 1c8c0efc8c41314402e6966da5bef6ea3d639d10 ctest --test-dir build --output-on-failure -R '^guest_webrtc_current_thread_id$' # negative control git show 1c8c0efc8c41314402e6966da5bef6ea3d639d10:core/libs/prx/libwebrtc/Export.cpp > core/libs/prx/libwebrtc/Export.cpp ninja -C build -j32 -l32 guest_webrtc_current_thread_id_tests libwebrtc ctest --test-dir build --output-on-failure -R '^guest_webrtc_current_thread_id$' git show 7e305ff34529f1d7b2025c45c9259539d10dd918:core/libs/prx/libwebrtc/Export.cpp > core/libs/prx/libwebrtc/Export.cpp ninja -C build -j32 -l32 guest_webrtc_current_thread_id_tests libwebrtc ctest --test-dir build -R '^guest_webrtc_current_thread_id$' git status --porcelain ``` The prepared run also built the merged tree and ran the 833 selected tests. ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | all checks passed | | Configure, build, `libs` | passed | | `guest_webrtc_current_thread_id` | passed (0.01 s) | | Selected tests (833) | 764 passed; **1 new failure: `public_headers`**; 1 known failure on `main` (`unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group`), not caused by this PR | | `check_skips.py` | error: `public_headers_compile_0` did not run because `public_headers` failed | | Vulkan validation | not applicable (no AGC driver, shader or VideoOut change) | <details><summary>public_headers</summary> ``` RuntimeError: _ZN3rtc15CurrentThreadIdEv_nid_postfix: expected exactly one header declaration; found 2: core/libs/prx/libwebrtc/include/Api.hpp:104, core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8 ``` </details> ## Negative control I put `main`'s `core/libs/prx/libwebrtc/Export.cpp` back and rebuilt. `guest_webrtc_current_thread_id` then failed with `Subprocess aborted`. After I restored the merged file and rebuilt, the test passed again, and `git status --porcelain` printed nothing. ## Findings ### Blocking 1. **Duplicate export declaration in the test breaks `public_headers`.** [`core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8`](https://github.com/boykopovar/AnyPS5/blob/ca85b796ca3f5905552771102bcd5228ff983ca6/core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp#L8) declares `_ZN3rtc15CurrentThreadIdEv_nid_postfix` again. `core/libs/prx/libwebrtc/include/Api.hpp:104` already declares it. CONTRIBUTING forbids a second declaration, and the prepared run on Linux confirms the `public_headers` failure that BunnyFl and the AMD CI comment reported. The fix is to delete the line: the test already includes `prx/libwebrtc/libwebrtc.hpp`. 2. **Host OS thread id instead of guest thread id.** [`Export.cpp:469-475` at head](https://github.com/boykopovar/AnyPS5/blob/ca85b796ca3f5905552771102bcd5228ff983ca6/core/libs/prx/libwebrtc/Export.cpp#L469-L475) (`core/libs/prx/libwebrtc/Export.cpp:449` in the merged tree) returns `GetCurrentThreadId()` or `syscall(SYS_gettid)`. - BunnyFl's disassembly of firmware 13.42 shows that the console export is a tail call to `scePthreadGetthreadid`. I have no firmware dump here, so I could not confirm the disassembly. - I did confirm the AnyPS5 side. Guest ids come from [`nextThreadId{100000}`](https://github.com/boykopovar/AnyPS5/blob/1c8c0efc8c41314402e6966da5bef6ea3d639d10/core/libs/prx/libkernel/Pthread/include/Pthread.hpp#L128-L128), and [`scePthreadGetthreadid` returns `scePthreadSelf()->tid`](https://github.com/boykopovar/AnyPS5/blob/1c8c0efc8c41314402e6966da5bef6ea3d639d10/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L1485-L1487). So with this PR, the two functions give different numbers for the same guest thread. - Upstream's non-Linux POSIX branch doesn't use `gettid` either, so the cited source doesn't support this choice for the console. - Suggested fix: return `scePthreadGetthreadid()` (declared in `core/libs/prx/libkernel/include/Api.hpp:583`), and link libwebrtc to `libkernel` (`core/libs/prx/libwebrtc/CMakeLists.txt:15` links only `opus`). In the test, assert equality with `scePthreadGetthreadid()` on the main thread and on a guest thread. ### Non-blocking - The distinct-per-thread check runs a host `std::thread` (`core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:31`), not a guest pthread. Once the value comes from the guest thread, the second thread should be created with `scePthreadCreate`, so the test covers the path titles take. ## Not verified - The firmware disassembly in BunnyFl's review (I have no module dump). - The Windows/MinGW build of the `_WIN32` branch (BunnyFl reports it builds and passes). - Behaviour on the console. ## To get this to a good state - Delete the redundant `extern "C"` declaration from the test. - Return the guest thread id through `scePthreadGetthreadid()`, link `libkernel`, and extend the test to check that equality on the main thread and on a guest thread. - Rerun `public_headers` and `guest_webrtc_current_thread_id`. <!-- anyps5-bots job=2186 head=ca85b796ca3f5905552771102bcd5228ff983ca6 -->
BunnyFl commented 2026-11-06 16:28:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-06T16:28:05Z.

Review: COMMENTED


@MarcZX10 re-checked at 7dc9a8e504, thanks for both fixes. My change request was on ca85b796ca. Both points are addressed. What's left is the conflict with main described below; I'm leaving this as a comment for now and will approve once it merges cleanly.

  • public_headers: the test no longer redeclares the export (tests/CurrentThreadId.cpp has no extern line at this head), and public_headers passes below.
  • Guest thread id: Export.cpp:465 now returns scePthreadGetthreadid(), and CurrentThreadId.cpp:37 checks CurrentThreadId() == scePthreadGetthreadid() on the main thread (line 42 does the same on a second thread).

Conflict. GitHub reports the PR as conflicting, and git merge onto main 7383be1a19 stops in core/libs/prx/libwebrtc/CMakeLists.txt: main now has src/RecursiveCriticalSection.cpp and src/TaskQueueBase.cpp either side of target_link_libraries(libwebrtc PRIVATE opus) (core/libs/prx/libwebrtc/CMakeLists.txt:18-20 on main), and this head changes that line to opus libkernel (core/libs/prx/libwebrtc/CMakeLists.txt:8 at this head). Keeping main's three lines with libkernel added resolves it. Could you merge main with that resolution?

What I ran (Windows 11 Pro, WinLibs GCC, Release), on this head merged onto main 7383be1a19 with the conflict resolved that way (local merge 36276150aa; this is not CI's merge):

  • ^(guest_webrtc_.*|public_headers)$: 19 of 19 pass, none unbuilt. That covers the Windows run your Tested section lists as not done.
  • Negative control: with main's Export.cpp put back, guest_webrtc_current_thread_id aborts with _ZN3rtc15CurrentThreadIdEv_nid_postfix not implemented (1 of 1 failed).
  • Mutation: returning scePthreadGetthreadid() + 1 fails the test at CurrentThreadId.cpp:37 (1 of 1 failed), so the new check catches an id that doesn't match the guest one.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5803426876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15154#pullrequestreview-5803426876). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-06T16:28:05Z. **Review:** COMMENTED --- @MarcZX10 re-checked at `7dc9a8e504`, thanks for both fixes. My change request was on `ca85b796ca`. Both points are addressed. What's left is the conflict with `main` described below; I'm leaving this as a comment for now and will approve once it merges cleanly. - **`public_headers`:** the test no longer redeclares the export (`tests/CurrentThreadId.cpp` has no `extern` line at this head), and `public_headers` passes below. - **Guest thread id:** `Export.cpp:465` now returns `scePthreadGetthreadid()`, and `CurrentThreadId.cpp:37` checks `CurrentThreadId() == scePthreadGetthreadid()` on the main thread (line 42 does the same on a second thread). **Conflict.** GitHub reports the PR as conflicting, and `git merge` onto `main` `7383be1a19` stops in `core/libs/prx/libwebrtc/CMakeLists.txt`: `main` now has `src/RecursiveCriticalSection.cpp` and `src/TaskQueueBase.cpp` either side of `target_link_libraries(libwebrtc PRIVATE opus)` (`core/libs/prx/libwebrtc/CMakeLists.txt:18-20` on `main`), and this head changes that line to `opus libkernel` (`core/libs/prx/libwebrtc/CMakeLists.txt:8` at this head). Keeping `main`'s three lines with `libkernel` added resolves it. Could you merge `main` with that resolution? **What I ran** (Windows 11 Pro, WinLibs GCC, Release), on this head merged onto `main` `7383be1a19` with the conflict resolved that way (local merge `36276150aa`; this is not CI's merge): - `^(guest_webrtc_.*|public_headers)$`: 19 of 19 pass, none unbuilt. That covers the Windows run your Tested section lists as not done. - Negative control: with `main`'s `Export.cpp` put back, `guest_webrtc_current_thread_id` aborts with `_ZN3rtc15CurrentThreadIdEv_nid_postfix not implemented` (1 of 1 failed). - Mutation: returning `scePthreadGetthreadid() + 1` fails the test at `CurrentThreadId.cpp:37` (1 of 1 failed), so the new check catches an id that doesn't match the guest one. AI-assisted: yes (Claude Code)
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!15154
No description provided.