feat(libwebrtc): implement CurrentThreadId #15154
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15154"
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 MarcZX10 on 2026-11-02T19:00:55Z.
What
rtc::CurrentThreadId()(_ZN3rtc15CurrentThreadIdEv): returns the guest thread id, the valuescePthreadGetthreadid()returns on the calling thread. Firmware 13.42libwebrtc.sprximplements this export as a tail call toscePthreadGetthreadid(reported by BunnyFl from disassembly; not measured on a console).tests/CurrentThreadId.cpp, registered asguest_webrtc_current_thread_id. It checks that the value is positive and stable, differs between two threads, and equalsscePthreadGetthreadid()on the main thread and on a second thread.libwebrtcnow linkslibkernel.Tested
run_tests.shin a throwaway verify tree at head7dc9a8e504(targetguest_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 verified
Left as stubs (dependencies not in the repo or layout not available yet):
rtc::LogMessagestatics and methods (LogThreads,LogTimestamps,LogToDebug,GetLogToDebug,AddLogToStream,RemoveLogToStream,SetLogToStderr,GetMinLogSeverity,stream): need the logging global state fromrtc_base/logging.cc.rtc::SSLAdapter::Create,rtc::Network::~Network,rtc::CopyOnWriteBuffercopy constructor and destructor,rtc::SocketAddressdefault constructor, copy assignment,IsComplete,IsNil,IsAnyIP,port,ipaddr: need class layouts and related sources not present in this repository.rtc::IPAddresshelpers (TruncateIP,CountIPMaskBits,ipv4_address,ipv6_address,v4AddressAsHostOrderInteger): need theIPAddresslayout.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
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)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
ca85b796ca3f5905552771102bcd5228ff983ca6and 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 currentmainpreview. 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.The PR description reports a Linux focused CTest pass (1/1); I did not independently run it.
Results
CurrentThreadId-specific lexical finding; audit has unrelated alias warnings.libwebrtc/Export.cpp.Check commands and outputs
The precheck's full results table and relevant raw output:
Negative control
Findings
Blocking
None found in the reviewed files for the documented host targets.
Non-blocking
CMakeLists.txtexplicitly registersguest_webrtc_current_thread_idand applies the Windows library search path.Sources
Not verified
libwebrtc/Export.cpp; it does not verify this implementation.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.
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_headersfails.core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8declares the export again:include/Api.hppalready declares it, and CONTRIBUTING forbids a second declaration in tests. On this head merged ontomain(Windows 11, WinLibs GCC, Release),public_headersfails with: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(sha256d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314),_ZN3rtc15CurrentThreadIdEv(KXt+l3+jE3I) is a tail call into a PLT stub:The GOT slot
0x9bc8f8is the importEI-5-jlq2dE, which isscePthreadGetthreadid. So on the consolertc::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 thanplatform_thread_types.cc. Upstream has no PS5 branch there, and its default branch, which a FreeBSD build would take, isreinterpret_cast<PlatformThreadId>(pthread_self()), notgettid(platform_thread_types.cc).With this PR the value is the host OS thread id (
GetCurrentThreadIdorSYS_gettid). AnyPS5's guest ids are a separate counter that starts at 100000 (core/libs/prx/libkernel/Pthread/include/Pthread.hpp:128), andscePthreadGetthreadidreturnsscePthreadSelf()->tid(core/libs/prx/libkernel/Pthread/src/Thread.cpp:1486). So for the same guest thread,rtc::CurrentThreadId()andscePthreadGetthreadid()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 linklibkernel, sincecore/libs/prx/libwebrtc/CMakeLists.txtlinks onlyopustoday. 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_WIN32branch builds, andguest_webrtc_current_thread_idpasses (1 of 1). Withmain'sExport.cppput back, it aborts (1 of 1 failed).public_headersfails as above.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 makespublic_headersfail, and the value doesn't match the guest thread id the console module returns.What I ran
Head
ca85b796ca3f5905552771102bcd5228ff983ca6, merged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10(merged tree7e305ff34529f1d7b2025c45c9259539d10dd918). Debian 13 VM, 32 vCPU (Xeon Gold 6136), GCC 14.2.0, Release, Ninja, a clean worktree.The prepared run also built the merged tree and ran the 833 selected tests.
Results
git diff --checkcheck_conventions.pylibsguest_webrtc_current_thread_idpublic_headers; 1 known failure onmain(unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group), not caused by this PRcheck_skips.pypublic_headers_compile_0did not run becausepublic_headersfailedpublic_headers
Negative control
I put
main'score/libs/prx/libwebrtc/Export.cppback and rebuilt.guest_webrtc_current_thread_idthen failed withSubprocess aborted. After I restored the merged file and rebuilt, the test passed again, andgit status --porcelainprinted nothing.Findings
Blocking
public_headers.core/libs/prx/libwebrtc/tests/CurrentThreadId.cpp:8declares_ZN3rtc15CurrentThreadIdEv_nid_postfixagain.core/libs/prx/libwebrtc/include/Api.hpp:104already declares it. CONTRIBUTING forbids a second declaration, and the prepared run on Linux confirms thepublic_headersfailure that BunnyFl and the AMD CI comment reported. The fix is to delete the line: the test already includesprx/libwebrtc/libwebrtc.hpp.Export.cpp:469-475at head (core/libs/prx/libwebrtc/Export.cpp:449in the merged tree) returnsGetCurrentThreadId()orsyscall(SYS_gettid).scePthreadGetthreadid. I have no firmware dump here, so I could not confirm the disassembly.nextThreadId{100000}, andscePthreadGetthreadidreturnsscePthreadSelf()->tid. So with this PR, the two functions give different numbers for the same guest thread.gettideither, so the cited source doesn't support this choice for the console.scePthreadGetthreadid()(declared incore/libs/prx/libkernel/include/Api.hpp:583), and link libwebrtc tolibkernel(core/libs/prx/libwebrtc/CMakeLists.txt:15links onlyopus). In the test, assert equality withscePthreadGetthreadid()on the main thread and on a guest thread.Non-blocking
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 withscePthreadCreate, so the test covers the path titles take.Not verified
_WIN32branch (BunnyFl reports it builds and passes).To get this to a good state
extern "C"declaration from the test.scePthreadGetthreadid(), linklibkernel, and extend the test to check that equality on the main thread and on a guest thread.public_headersandguest_webrtc_current_thread_id.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 onca85b796ca. Both points are addressed. What's left is the conflict withmaindescribed 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.cpphas noexternline at this head), andpublic_headerspasses below.Export.cpp:465now returnsscePthreadGetthreadid(), andCurrentThreadId.cpp:37checksCurrentThreadId() == scePthreadGetthreadid()on the main thread (line 42 does the same on a second thread).Conflict. GitHub reports the PR as conflicting, and
git mergeontomain7383be1a19stops incore/libs/prx/libwebrtc/CMakeLists.txt:mainnow hassrc/RecursiveCriticalSection.cppandsrc/TaskQueueBase.cppeither side oftarget_link_libraries(libwebrtc PRIVATE opus)(core/libs/prx/libwebrtc/CMakeLists.txt:18-20onmain), and this head changes that line toopus libkernel(core/libs/prx/libwebrtc/CMakeLists.txt:8at this head). Keepingmain's three lines withlibkerneladded resolves it. Could you mergemainwith that resolution?What I ran (Windows 11 Pro, WinLibs GCC, Release), on this head merged onto
main7383be1a19with the conflict resolved that way (local merge36276150aa; 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.main'sExport.cppput back,guest_webrtc_current_thread_idaborts with_ZN3rtc15CurrentThreadIdEv_nid_postfix not implemented(1 of 1 failed).scePthreadGetthreadid() + 1fails the test atCurrentThreadId.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)