Proposal: a GuestPtr<T> type for guest pointer parameters, piloted on one library #19123

Open
opened 2026-11-12 20:19:08 +00:00 by Ethan-Hainline · 0 comments
Ethan-Hainline commented 2026-11-12 20:19:08 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Ethan-Hainline on 2026-11-12T20:19:08Z.


What

tools/guest_pointer_audit.py (from #14446) reports every export that reads or writes a guest pointer parameter without GuestCopyIn, GuestCopyOut or a CopyGuest* helper. On main e917850d23 it reports 3,672 findings, of which 1,237 contain a direct dereference and 1,023 are a bare *p with no member access, call or index. The per-function fixes keep arriving: #14445 counted 28 EFAULT pull requests in two days on Oct 29–30, and the same pattern is still being opened. That issue was closed because nobody took the structural fix, not because it was rejected.

This proposes the structural fix, with a small pilot instead of a flag day.

Proposal

A GuestPtr<T> (name open) that holds a guest address and cannot be used as a host T*:

  • construction only from the raw guest address at the export boundary, where the ABI stays a plain pointer;
  • access only through CopyIn/CopyOut (and the existing CopyGuest* helpers), which return the console error on a fault and preserve errno;
  • no implicit conversion, no operator*, no operator->, no data();
  • an optional GuestSpan<T> later for counted arrays.

An export would look like:

int sceExample(GuestPtr<const Params> params, GuestPtr<Result> out) {
    auto in = params.CopyIn();          // throws/returns the documented error
    out.CopyOut(MakeResult(*in));
}

The existing GuestCopyIn/GuestCopyOut helpers stay as the implementation; the type is the compile-time gate that stops new direct accesses.

Pilot

One library, chosen so the change is reviewable and does not collide with the open EFAULT PRs. libSceVideoOut is the suggested pilot: the audit reports 25 findings there, 5 of them bare dereferences, and no open pull request changes core/libs/prx/libSceVideoOut/Export.cpp. libSceHttp is the larger alternative (38 findings, 21 bare dereferences, also no open Export.cpp PR). The pilot would:

  1. add the type and its tests;
  2. convert that library's pointer exports and make guest_pointer_audit.py report zero direct accesses for it;
  3. add the audit as a per-library gate for the converted library only, so new direct accesses fail CI there while the rest of the tree keeps its current debt.

If the type is accepted, later libraries convert one at a time; the audit count becomes the burn-down metric. The largest pure-dereference buckets on this main are libc 120, libSceNpCppWebApi 114 (mostly C++ member access on objects, not all guest-pointer bugs), libSceJson2 78, libkernel 71, libSceNpCommon 43, libSceNKWebKit 40, libSceFont 33 and libSceIcu 33.

Questions

  1. Is a strong GuestPtr<T> in export signatures acceptable, or should the type be used only inside the implementation with raw pointers at the ABI boundary?
  2. Is libSceVideoOut the right pilot, or should it be a smaller library (libSceZlib has 1 finding) or a larger one?
  3. Should the audit gate be per library from the start, or only after a library is converted?
  4. Is the const/span split wanted now, or only the single-pointer type?

I can write the pilot once the direction is chosen. AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6358255043 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/19123). Originally posted by [Ethan-Hainline](https://github.com/Ethan-Hainline) on 2026-11-12T20:19:08Z. --- ### What `tools/guest_pointer_audit.py` (from #14446) reports every export that reads or writes a guest pointer parameter without `GuestCopyIn`, `GuestCopyOut` or a `CopyGuest*` helper. On `main` `e917850d23` it reports **3,672 findings**, of which **1,237 contain a direct dereference** and **1,023 are a bare `*p` with no member access, call or index**. The per-function fixes keep arriving: #14445 counted 28 `EFAULT` pull requests in two days on Oct 29–30, and the same pattern is still being opened. That issue was closed because nobody took the structural fix, not because it was rejected. This proposes the structural fix, with a small pilot instead of a flag day. ### Proposal A `GuestPtr<T>` (name open) that holds a guest address and cannot be used as a host `T*`: - construction only from the raw guest address at the export boundary, where the ABI stays a plain pointer; - access only through `CopyIn`/`CopyOut` (and the existing `CopyGuest*` helpers), which return the console error on a fault and preserve `errno`; - no implicit conversion, no `operator*`, no `operator->`, no `data()`; - an optional `GuestSpan<T>` later for counted arrays. An export would look like: ```cpp int sceExample(GuestPtr<const Params> params, GuestPtr<Result> out) { auto in = params.CopyIn(); // throws/returns the documented error out.CopyOut(MakeResult(*in)); } ``` The existing `GuestCopyIn`/`GuestCopyOut` helpers stay as the implementation; the type is the compile-time gate that stops new direct accesses. ### Pilot One library, chosen so the change is reviewable and does not collide with the open `EFAULT` PRs. **`libSceVideoOut`** is the suggested pilot: the audit reports 25 findings there, 5 of them bare dereferences, and no open pull request changes `core/libs/prx/libSceVideoOut/Export.cpp`. `libSceHttp` is the larger alternative (38 findings, 21 bare dereferences, also no open Export.cpp PR). The pilot would: 1. add the type and its tests; 2. convert that library's pointer exports and make `guest_pointer_audit.py` report zero direct accesses for it; 3. add the audit as a **per-library gate** for the converted library only, so new direct accesses fail CI there while the rest of the tree keeps its current debt. If the type is accepted, later libraries convert one at a time; the audit count becomes the burn-down metric. The largest pure-dereference buckets on this main are `libc` 120, `libSceNpCppWebApi` 114 (mostly C++ member access on objects, not all guest-pointer bugs), `libSceJson2` 78, `libkernel` 71, `libSceNpCommon` 43, `libSceNKWebKit` 40, `libSceFont` 33 and `libSceIcu` 33. ### Questions 1. Is a strong `GuestPtr<T>` in export signatures acceptable, or should the type be used only inside the implementation with raw pointers at the ABI boundary? 2. Is `libSceVideoOut` the right pilot, or should it be a smaller library (`libSceZlib` has 1 finding) or a larger one? 3. Should the audit gate be per library from the start, or only after a library is converted? 4. Is the const/span split wanted now, or only the single-pointer type? I can write the pilot once the direction is chosen. AI-assisted: yes.
Sign in to join this conversation.
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#19123
No description provided.