fix(libkernel): check the SoC sensor channel before the pointer and set errno as measured on a PS5 #11182

Merged
orezraey merged 3 commits from upstream-pr/11182 into main 2026-10-26 12:02:20 +00:00
orezraey commented 2026-10-25 20:50:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orezraey on 2026-10-25T20:50:12Z.


What

sceKernelGetSocSensorTemperature now checks the channel before the output pointer, using the range a retail PS5 (firmware 13.60) accepts (0 to 64). It and sceKernelGetCpuTemperature now also set errno along with the SCE_KERNEL_ERROR_* code, as the console does. Measured with homebrew probes from a payload process; the sources and console logs are in this gist (ptemp, ptemp3).

On the console:

  • Channel range. Channels 0 to 64 return 0. Channels 0 to 63 read 49 to 54 °C, varying by about 1 between reads. Channel 64 always reads -49. Every channel from 65 to 300 returns 0x80020016 with errno 22 and writes nothing, and so do -1, INT_MAX and INT_MIN.
  • Channel before pointer. A null output with channel -1 or 256 returns 0x80020016 with errno 22; a null output with channel 0 faults (SIGSEGV).
  • errno is set. sceKernelGetCpuTemperature(nullptr) returns 0x8002000e with errno 14.

Before, AnyPS5 checked the pointer first (EFAULT even for an invalid channel), accepted only channels 0 to 2, and set no errno.

Channels 3 to 64 exist on the console but have no host counterpart, so a call for one with a non-null output throws instead of returning a value or an error the console does not give. A channel 0 to 2 the host has no sensor for still returns EINVAL, as before. A null output with a valid channel keeps returning EFAULT where the console faults. The debt entry now starts with these differences.

Before and after

Case PS5 AnyPS5 before AnyPS5 now
sceKernelGetSocSensorTemperature channel 65 to 300, -1, INT_MAX 0x80020016, errno 22 0x80020016, errno not set 0x80020016, errno 22
invalid channel with a null output 0x80020016 0x8002000e (EFAULT) 0x80020016
channel 3 to 64 0 and a temperature 0x80020016 throws (no host sensor, debt)
sceKernelGetCpuTemperature(nullptr) 0x8002000e, errno 14 0x8002000e, errno not set 0x8002000e, errno 14
valid channel with a null output faults EFAULT EFAULT

Tested

Head 57781bd219 on main 5a2744c55e: guest_thermal_sensors passes 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL, GCC 16.2). With the ThermalSensors.cpp change reverted, the updated test fails.

  • Channels -1, 65, 256, INT_MAX and INT_MIN return EINVAL with errno 22 and leave the output untouched, with a null output too.
  • Channels 3, 15, 32 and 64 give EFAULT with errno 14 for a null output. The test does not call them with a non-null output, since they are valid on the console and only throw until a host sensor maps them.
  • A null output to sceKernelGetCpuTemperature and to channel 0 sets errno 14.

tools/check_conventions.py 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: #10901 (it adds a debt entry next to the one this PR rewrites; merge order only)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008579947 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11182). Originally posted by [orezraey](https://github.com/orezraey) on 2026-10-25T20:50:12Z. --- ### What `sceKernelGetSocSensorTemperature` now checks the channel before the output pointer, using the range a retail PS5 (firmware 13.60) accepts (0 to 64). It and `sceKernelGetCpuTemperature` now also set `errno` along with the `SCE_KERNEL_ERROR_*` code, as the console does. Measured with homebrew probes from a payload process; the sources and console logs are in [this gist](https://gist.github.com/orezraey/1984818a6a7851841e854793e7b04325) (`ptemp`, `ptemp3`). On the console: - **Channel range.** Channels 0 to 64 return 0. Channels 0 to 63 read 49 to 54 °C, varying by about 1 between reads. Channel 64 always reads -49. Every channel from 65 to 300 returns `0x80020016` with `errno` 22 and writes nothing, and so do -1, `INT_MAX` and `INT_MIN`. - **Channel before pointer.** A null output with channel -1 or 256 returns `0x80020016` with `errno` 22; a null output with channel 0 faults (`SIGSEGV`). - **errno is set.** `sceKernelGetCpuTemperature(nullptr)` returns `0x8002000e` with `errno` 14. Before, AnyPS5 checked the pointer first (`EFAULT` even for an invalid channel), accepted only channels 0 to 2, and set no `errno`. Channels 3 to 64 exist on the console but have no host counterpart, so a call for one with a non-null output throws instead of returning a value or an error the console does not give. A channel 0 to 2 the host has no sensor for still returns `EINVAL`, as before. A null output with a valid channel keeps returning `EFAULT` where the console faults. The debt entry now starts with these differences. **Before and after** | Case | PS5 | AnyPS5 before | AnyPS5 now | |---|---|---|---| | `sceKernelGetSocSensorTemperature` channel 65 to 300, -1, `INT_MAX` | `0x80020016`, `errno` 22 | `0x80020016`, `errno` not set | `0x80020016`, `errno` 22 | | invalid channel with a null output | `0x80020016` | `0x8002000e` (`EFAULT`) | `0x80020016` | | channel 3 to 64 | 0 and a temperature | `0x80020016` | throws (no host sensor, debt) | | `sceKernelGetCpuTemperature(nullptr)` | `0x8002000e`, `errno` 14 | `0x8002000e`, `errno` not set | `0x8002000e`, `errno` 14 | | valid channel with a null output | faults | `EFAULT` | `EFAULT` | ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Head `57781bd219` on `main` `5a2744c55e`: `guest_thermal_sensors` passes 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and 3 times out of 3 on Linux (WSL, GCC 16.2). With the `ThermalSensors.cpp` change reverted, the updated test fails. - Channels -1, 65, 256, `INT_MAX` and `INT_MIN` return `EINVAL` with `errno` 22 and leave the output untouched, with a null output too. - Channels 3, 15, 32 and 64 give `EFAULT` with `errno` 14 for a null output. The test does not call them with a non-null output, since they are valid on the console and only throw until a host sensor maps them. - A null output to `sceKernelGetCpuTemperature` and to channel 0 sets `errno` 14. `tools/check_conventions.py` passes. ### 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: #10901 (it adds a debt entry next to the one this PR rewrites; merge order only) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 20:51:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T20:51:39Z.

Review: COMMENTED


I checked the cited firmware 13.60 probe: channels 0–64 return success (channel 64 reports -49), and 65+ return EINVAL. This change accepts the measured range but then returns EINVAL for every valid channel 3–64 (sensorId >= 3), and the new test locks that in for 3, 32 and 64. That makes EINVAL mean "no host mapping" even though the console accepts those IDs. Since CONTRIBUTING says an export must implement its behavior or throw, could these valid-but-unimplemented channels use the documented unimplemented path until a generic mapping is available, or otherwise make the intentional console mismatch explicit? The debt entry records the gap, but the return value still presents these channels as invalid. Also, the new test checks the EFAULT return for null outputs on channels 3/32/64 but does not assert errno == 14 there, unlike the other error cases.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645233309 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11182#pullrequestreview-5645233309). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T20:51:39Z. **Review:** COMMENTED --- I checked the cited firmware 13.60 probe: channels 0–64 return success (channel 64 reports -49), and 65+ return EINVAL. This change accepts the measured range but then returns EINVAL for every valid channel 3–64 (sensorId >= 3), and the new test locks that in for 3, 32 and 64. That makes EINVAL mean "no host mapping" even though the console accepts those IDs. Since CONTRIBUTING says an export must implement its behavior or throw, could these valid-but-unimplemented channels use the documented unimplemented path until a generic mapping is available, or otherwise make the intentional console mismatch explicit? The debt entry records the gap, but the return value still presents these channels as invalid. Also, the new test checks the EFAULT return for null outputs on channels 3/32/64 but does not assert errno == 14 there, unlike the other error cases.
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!11182
No description provided.