fix(libSceGLSlimVSH): copy generated GL object names out through a checked write #20804

Merged
milescoviello merged 1 commit from upstream-pr/20804 into main 2026-11-15 16:26:03 +00:00
milescoviello commented 2026-11-15 15:48:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-15T15:48:54Z.


What

glGenBuffers, glGenTextures, glGenFramebuffers and glGenRenderbuffers all go through the shared Generate_nid_no_patch helper. That helper wrote the new names into the guest output array with std::copy, so an array pointing at unmapped memory faulted the host. The library's debt file already lists this, noting that tools/guest_pointer_audit.py can't see it.

The helper already builds the names in a host vector. It now copies that vector out with one GuestCopyOut_nid_no_patch and only then commits the reserved names to the object map. An unwritable array sets GL_OUT_OF_MEMORY (0x0505), the code the debt entry names, and leaves the object map unchanged, so a later call gets the same names. Valid calls and the existing negative-count and oversized-count errors are unchanged.

The debt entry is rewritten through a ## change fragment under docs/dev/debt/changes/. It records 0x0505 as a host-safety fallback, since console behaviour here is not measured.

Tested

Linux (Ubuntu 26.04.1), GCC 15.2, Release.

  • guest_glslim_state (GuestPointerFaults), new cases:
    • glGenBuffers(2, 0x10) sets 0x0505 and leaves errno at 71. The next glGenBuffers(1, ...) returns the same name a valid call returned just before, after that name was deleted, so the failed call reserved nothing.
    • glGenTextures, glGenRenderbuffers and glGenFramebuffers with 0x10 set 0x0505.
  • The rest of guest_glslim_state and guest_glslim_query_surface, guest_glslim_eglgetconfigs and guest_glslim_ipc_returns still pass.
  • Negative control: State.hpp from main with these tests dies with SIGSEGV at address 0x10.
  • tools/check_conventions.py passes on the branch and this body. tools/debt_fold.py --check passes with the fragment applied.
  • Merges with my other GLSlim PRs #20798 and #20802:
    • git merge-tree is clean against main, #14212, #20798 and #20802.
    • An octopus merge of the three branches onto main passes debt_fold.py --check.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5324395547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20804). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-15T15:48:54Z. --- ### What `glGenBuffers`, `glGenTextures`, `glGenFramebuffers` and `glGenRenderbuffers` all go through the shared `Generate_nid_no_patch` helper. That helper wrote the new names into the guest output array with `std::copy`, so an array pointing at unmapped memory faulted the host. The library's debt file already lists this, noting that `tools/guest_pointer_audit.py` can't see it. The helper already builds the names in a host vector. It now copies that vector out with one `GuestCopyOut_nid_no_patch` and only then commits the reserved names to the object map. An unwritable array sets `GL_OUT_OF_MEMORY` (0x0505), the code the debt entry names, and leaves the object map unchanged, so a later call gets the same names. Valid calls and the existing negative-count and oversized-count errors are unchanged. The debt entry is rewritten through a `## change` fragment under `docs/dev/debt/changes/`. It records 0x0505 as a host-safety fallback, since console behaviour here is not measured. ### Tested Linux (Ubuntu 26.04.1), GCC 15.2, Release. - `guest_glslim_state` (`GuestPointerFaults`), new cases: - `glGenBuffers(2, 0x10)` sets 0x0505 and leaves `errno` at 71. The next `glGenBuffers(1, ...)` returns the same name a valid call returned just before, after that name was deleted, so the failed call reserved nothing. - `glGenTextures`, `glGenRenderbuffers` and `glGenFramebuffers` with `0x10` set 0x0505. - The rest of `guest_glslim_state` and `guest_glslim_query_surface`, `guest_glslim_eglgetconfigs` and `guest_glslim_ipc_returns` still pass. - Negative control: `State.hpp` from `main` with these tests dies with SIGSEGV at address `0x10`. - `tools/check_conventions.py` passes on the branch and this body. `tools/debt_fold.py --check` passes with the fragment applied. - Merges with my other GLSlim PRs #20798 and #20802: - `git merge-tree` is clean against `main`, #14212, #20798 and #20802. - An octopus merge of the three branches onto `main` passes `debt_fold.py --check`. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
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!20804
No description provided.