feat(libwebrtc): implement the rtc::LogMessage statics and PendingTaskSafetyFlag state accessors #15211

Merged
simnJS merged 4 commits from upstream-pr/15211 into main 2026-11-07 06:38:27 +00:00
simnJS commented 2026-11-02 20:47:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simnJS on 2026-11-02T20:47:59Z.


What

Implements 11 libwebrtc exports: the nine rtc::LogMessage statics (GetMinLogSeverity, GetLogToDebug, LogToDebug, LogThreads, LogTimestamps, SetLogToStderr, AddLogToStream, RemoveLogToStream, IsNoop) and webrtc::PendingTaskSafetyFlag::SetNotAlive and alive.

They are adapted from rtc_base/logging.cc and api/task_queue/pending_task_safety_flag.cc, whose logic is the same at M127 (e0b28a6a81a989c1f5c89e30fcd247870047390d) and M134 (8d78f5de6c27b2c793039989ea381f1428fb0100), the two bounds the debt file gives for the module, apart from a [[maybe_unused]] and includes. Adding a null or already registered sink throws, where upstream writes through it or loops.

The debt file records what these exports assume about the console build and what a comparison with the console would close: NDEBUG, so the default severity is LS_NONE; RTC_LOG_ENABLED(), which places LogSink::next_ at offset 8 and min_severity_ at 16; and disabled DCHECKs, so the RTC_DCHECK_RUN_ON of SetNotAlive and alive does not apply.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: guest_webrtc_log_message and guest_webrtc_pending_task_safety_flag pass (severities, ordering, sink removal, invalid arguments, safety flag state). Only these tests were run, not the full suite. Not run on Linux or on a title.

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:5127184887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15211). Originally posted by [simnJS](https://github.com/simnJS) on 2026-11-02T20:47:59Z. --- ### What Implements 11 libwebrtc exports: the nine `rtc::LogMessage` statics (`GetMinLogSeverity`, `GetLogToDebug`, `LogToDebug`, `LogThreads`, `LogTimestamps`, `SetLogToStderr`, `AddLogToStream`, `RemoveLogToStream`, `IsNoop`) and `webrtc::PendingTaskSafetyFlag::SetNotAlive` and `alive`. They are adapted from `rtc_base/logging.cc` and `api/task_queue/pending_task_safety_flag.cc`, whose logic is the same at M127 (e0b28a6a81a989c1f5c89e30fcd247870047390d) and M134 (8d78f5de6c27b2c793039989ea381f1428fb0100), the two bounds the debt file gives for the module, apart from a `[[maybe_unused]]` and includes. Adding a null or already registered sink throws, where upstream writes through it or loops. The debt file records what these exports assume about the console build and what a comparison with the console would close: `NDEBUG`, so the default severity is `LS_NONE`; `RTC_LOG_ENABLED()`, which places `LogSink::next_` at offset 8 and `min_severity_` at 16; and disabled `DCHECK`s, so the `RTC_DCHECK_RUN_ON` of `SetNotAlive` and `alive` does not apply. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release: `guest_webrtc_log_message` and `guest_webrtc_pending_task_safety_flag` pass (severities, ordering, sink removal, invalid arguments, safety flag state). Only these tests were run, not the full suite. Not run on Linux or on a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
BunnyFl commented 2026-11-03 23:36:05 +00:00 (Migrated from github.com)

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

Review: APPROVED


@simnJS approved at ea45c4dc50. The firmware agrees with each assumption your debt entry lists.

What I ran: this head merged onto main (merge 593238cc56), Windows 11, WinLibs GCC, Release.

  • guest_webrtc_log_message, guest_webrtc_pending_task_safety_flag and public_headers pass (3 of 3).
  • Mutation: with g_minSeverity starting at WebRtcLsInfo instead of WebRtcLsNone, guest_webrtc_log_message fails at LogMessage.cpp:142, the initial-default check (1 of 1 failed). A swap of main's files has nothing to restore: the definitions are in the new src/LogMessage.cpp.

Firmware: 13.42 system/common/lib/libwebrtc.sprx (sha256 d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314), read from disassembly, not run.

  • Initial values: the statics at 0x9c0060 hold 01 01 00 00 04 00 00 00 04 00 00 00. That is stderr logging on and streams empty, then the debug severity (0x9c0064) and the minimum severity (0x9c0068) both 4, LS_NONE. These are writable, so I also disassembled the whole code segment: every store to 0x9c0064 or 0x9c0068 is inside LogToDebug, AddLogToStream or RemoveLogToStream, and no initializer writes them. So the NDEBUG default is the starting value.
  • AddLogToStream (0x153bd0):
    • It stores the severity at 0x10(%rbx) (153bf3) and links next_ at 0x8(%rbx) (153bfd). That gives the offsets 8 and 16 your static_asserts pin.
    • It pushes the sink at the head (0x9c0770) and clears streams-empty (153c08).
    • It recomputes the minimum over the debug severity and every sink (153c20–153c31).
    • It neither checks for null nor checks for duplicates. A null sink faults at 153bf3, and that is what your throw replaces.
  • RemoveLogToStream (0x153c90): unlinks the first match, sets streams-empty to whether the list is now empty, then recomputes the minimum. If the sink isn't found, it still runs both updates. Your loop does the same.
  • LogToDebug (0x153a20): stores the debug severity, then recomputes the minimum under the lock.
  • IsNoop (0x154040): returns false when the severity is at least the debug or the minimum severity, otherwise the streams-empty byte. That is your condition.
  • PendingTaskSafetyFlag: SetNotAlive (0x3be5b0) is movb $0x0,0x4(%rdi) and alive (0x3be5d0) is movzbl 0x4(%rdi),%eax. So alive is at offset 4, as your static_assert says, and neither does a sequence check.

One thing for whoever wires up more of LogMessage later: the firmware creates its logging mutex lazily (the guard at 0x9c07a8, around 153c43–153c7d). The function-local static std::mutex here behaves the same as far as these exports can tell.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761011800 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15211#pullrequestreview-5761011800). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-03T23:36:05Z. **Review:** APPROVED --- @simnJS approved at `ea45c4dc50`. The firmware agrees with each assumption your debt entry lists. **What I ran:** this head merged onto `main` (merge `593238cc56`), Windows 11, WinLibs GCC, Release. - `guest_webrtc_log_message`, `guest_webrtc_pending_task_safety_flag` and `public_headers` pass (3 of 3). - **Mutation:** with `g_minSeverity` starting at `WebRtcLsInfo` instead of `WebRtcLsNone`, `guest_webrtc_log_message` fails at `LogMessage.cpp:142`, the initial-default check (1 of 1 failed). A swap of `main`'s files has nothing to restore: the definitions are in the new `src/LogMessage.cpp`. **Firmware:** 13.42 `system/common/lib/libwebrtc.sprx` (sha256 `d59d0caf6967329b39201a2a0bd6df7b994516f21701b9801908db6735ae5314`), read from disassembly, not run. - **Initial values:** the statics at `0x9c0060` hold `01 01 00 00 04 00 00 00 04 00 00 00`. That is stderr logging on and streams empty, then the debug severity (`0x9c0064`) and the minimum severity (`0x9c0068`) both 4, `LS_NONE`. These are writable, so I also disassembled the whole code segment: every store to `0x9c0064` or `0x9c0068` is inside `LogToDebug`, `AddLogToStream` or `RemoveLogToStream`, and no initializer writes them. So the `NDEBUG` default is the starting value. - **`AddLogToStream` (`0x153bd0`):** - It stores the severity at `0x10(%rbx)` (`153bf3`) and links `next_` at `0x8(%rbx)` (`153bfd`). That gives the offsets 8 and 16 your `static_assert`s pin. - It pushes the sink at the head (`0x9c0770`) and clears streams-empty (`153c08`). - It recomputes the minimum over the debug severity and every sink (`153c20`–`153c31`). - It neither checks for null nor checks for duplicates. A null sink faults at `153bf3`, and that is what your throw replaces. - **`RemoveLogToStream` (`0x153c90`):** unlinks the first match, sets streams-empty to whether the list is now empty, then recomputes the minimum. If the sink isn't found, it still runs both updates. Your loop does the same. - **`LogToDebug` (`0x153a20`):** stores the debug severity, then recomputes the minimum under the lock. - **`IsNoop` (`0x154040`):** returns false when the severity is at least the debug or the minimum severity, otherwise the streams-empty byte. That is your condition. - **`PendingTaskSafetyFlag`:** `SetNotAlive` (`0x3be5b0`) is `movb $0x0,0x4(%rdi)` and `alive` (`0x3be5d0`) is `movzbl 0x4(%rdi),%eax`. So `alive` is at offset 4, as your `static_assert` says, and neither does a sequence check. One thing for whoever wires up more of `LogMessage` later: the firmware creates its logging mutex lazily (the guard at `0x9c07a8`, around `153c43`–`153c7d`). The function-local `static std::mutex` here behaves the same as far as these exports can tell.
BunnyFl commented 2026-11-06 18:34:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-06T18:34:35Z.

Review: COMMENTED


@simnJS re-checked at 2f22d9f03d. The code is unchanged, but there is one count I should have caught at my approval.

The debt count is one too high, at my approval too. docs/dev/debt/libwebrtc.md:5 says 329 exports. Counted from the files, the entry's number is the throwing stubs in core/libs/prx/libwebrtc/Export.cpp plus the 60 bound by NID:

throwing stubs entry says stubs + 60
this PR's base 4f41f4c375 291 351 351
main 9fb6149d12 279 339 339
ea45c4dc50 (my approval) 280 341 340
this head 2f22d9f03d 268 329 328

The PR removes 11 stubs (the nine rtc::LogMessage functions and the two PendingTaskSafetyFlag accessors), but the count drops by 10. So it should read 328. My approval at ea45c4dc50 missed this, sorry about that.

One unrelated change from a merge, non-blocking. One of the two main merges since my approval reordered two includes in core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp, a file this PR doesn't otherwise touch. MediaExports.hpp moved below JsonExports.hpp (:17-18), and WtfValueExports.hpp moved to :22, where main has them at :17, :18 and :20. It builds either way. Taking main's version of that file would keep it out of the diff.

What I ran

The PR's own +/- lines in Export.cpp are the same as at ea45c4dc50; only the hunk boundaries moved with main. Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, Release, this head merged onto current main (merge dcac827b51):

  • guest_webrtc_log_message, guest_webrtc_pending_task_safety_flag and public_headers: 3 of 3 pass.
  • Mutation, as at my approval, on a fresh merge (f6327979fb): with g_minSeverity starting at WebRtcLsInfo instead of WebRtcLsNone (src/LogMessage.cpp:52), guest_webrtc_log_message aborts (0xc0000409), 0 of 1 pass.
  • tools/check_conventions.py --base upstream/main --head on this head: all checks pass.

With the count fixed, my approval stands.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5805097188 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15211#pullrequestreview-5805097188). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-06T18:34:35Z. **Review:** COMMENTED --- @simnJS re-checked at `2f22d9f03d`. The code is unchanged, but there is one count I should have caught at my approval. **The debt count is one too high, at my approval too.** `docs/dev/debt/libwebrtc.md:5` says 329 exports. Counted from the files, the entry's number is the throwing stubs in `core/libs/prx/libwebrtc/Export.cpp` plus the 60 bound by NID: | | throwing stubs | entry says | stubs + 60 | |---|---|---|---| | this PR's base `4f41f4c375` | 291 | 351 | 351 | | `main` `9fb6149d12` | 279 | 339 | 339 | | `ea45c4dc50` (my approval) | 280 | 341 | 340 | | this head `2f22d9f03d` | 268 | 329 | 328 | The PR removes 11 stubs (the nine `rtc::LogMessage` functions and the two `PendingTaskSafetyFlag` accessors), but the count drops by 10. So it should read **328**. My approval at `ea45c4dc50` missed this, sorry about that. **One unrelated change from a merge, non-blocking.** One of the two `main` merges since my approval reordered two includes in `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp`, a file this PR doesn't otherwise touch. `MediaExports.hpp` moved below `JsonExports.hpp` (`:17-18`), and `WtfValueExports.hpp` moved to `:22`, where `main` has them at `:17`, `:18` and `:20`. It builds either way. Taking `main`'s version of that file would keep it out of the diff. ## What I ran The PR's own +/- lines in `Export.cpp` are the same as at `ea45c4dc50`; only the hunk boundaries moved with `main`. Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, Release, this head merged onto current `main` (merge `dcac827b51`): - `guest_webrtc_log_message`, `guest_webrtc_pending_task_safety_flag` and `public_headers`: 3 of 3 pass. - **Mutation**, as at my approval, on a fresh merge (`f6327979fb`): with `g_minSeverity` starting at `WebRtcLsInfo` instead of `WebRtcLsNone` (`src/LogMessage.cpp:52`), `guest_webrtc_log_message` aborts (`0xc0000409`), 0 of 1 pass. - `tools/check_conventions.py --base upstream/main --head` on this head: all checks pass. With the count fixed, my approval stands. 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!15211
No description provided.