Repository navigation
fix(libSceGnmDriver): copy the shader registers and packets of sceGnmSet*Shader safely - #24456
Conversation
…Set*Shader safely
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the reviewed implementation preserves packet construction while using checked guest memory copies.
What I ran
Reviewed head 24828c0f142c439d3fae91b8438b07cdb65ff29e. No commands or tests were run in this review; no merged preview was checked. Read description.md, commits.md, manifest.json, diff.patch, Export.cpp, and ShaderWriters.cpp; also read targeted context from libc/src/General.cpp and libSceGnmDriverForNeoMode/Export.cpp. Both files listed as reviewed in the manifest were read in full.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Both changed files read |
| Tests | not run | Test results in description are author reported |
| Copy helper behavior | passed | Checked copy helpers return failure for unmapped ranges |
Findings
Blocking
None.
Non-blocking
None.
Sources
The shader writers read registers into local arrays and write fixed-length packets using checked guest copies (Export.cpp at reviewed head). The copy helpers validate address ranges and report failed guest memory access (General.cpp at reviewed head). The unmapped-pointer tests cover all seven writers (ShaderWriters.cpp at reviewed head).
Not verified
Did not run the test suite, mutation checks, convention checks, or guest pointer audit; their reported outcomes are from the PR description. Did not verify physical console behavior. files.json was not available through the reader, so excluded files beyond those identified by the manifest were not checked.
To get this to a good state
Nothing is required.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
What
The seven shader register writers of
libSceGnmDriver(sceGnmSetPsShader,sceGnmSetVsShader,sceGnmSetCsShader,sceGnmSetEsShader,sceGnmSetGsShader,sceGnmSetHsShaderandsceGnmSetLsShader) indexed the guestregsblock directly and emitted their PM4 packets straight into the guest command buffer. An unmapped register block or command buffer crashed the process instead of failing the call.Each writer now reads the words it uses with one
GuestCopyIn_nid_no_patchinto a host array: 12 for the pixel shader, 7 for the vertex, compute, geometry and hull shaders, 4 for the export and local shaders. It builds its packet in a host array of the packet's fixed length (0x28, 0x1d, 0x19, 0x14, 0x1d, 0x1e and 0x17 dwords) and writes it with oneGuestCopyOut_nid_no_patch. Every packet already covered its whole length, ending with the NOP pad, so the command buffer is not copied in first. An unreadable register block or an unwritable command buffer returns -1, which these writers already return for a short buffer or a non-zero second register. The VGT control writers in the same file fail the same way since 72a75c6. The helpers followReadShaderRegsandWriteCommandBufferinlibSceGnmDriverForNeoMode(dffbd0c). For readable inputs the packets are byte-for-byte the same as on main, and the existinggnm_shader_writerschecks pass unchanged.Not changed
These
tools/guest_pointer_audit.pyfindings in the libraries I looked at were left alone:sceGnmDrawInitDefaultHardwareState200/350andsceGnmDrawInitToDefaultContextState400are fixed in a separate PR.sceGnmSubmitAndFlipCommandBuffersshares its submission path withsceGnmSubmitCommandBuffers, and that path reads the command buffers themselves. It needs its own change.sceUsbdGetDeviceList(fix(libSceUsbd): probe guest memory in the device list, event, transfer and configuration calls #21530) andsceNetGetsockopt/sceNetSetsockopt.UsbdTransferobjects that the other libSceUsbd findings take come fromsceUsbdAllocTransfer, which allocates them on the host withcalloc.sceNetRecvmsgcopies the header in and opensmsgwithGuestArena::HostWritebefore it stores to it.sceNetSyncSignalandsceNetSyncWaitcheck the sync object withGuestWritable_nid_no_patchand then use the mutex and condition variable inside it in place.DnB6WJ91HGgonly takes member addresses for its copy helpers.Overlap
python3 tools/pr_overlap.py --names sceGnmSetPsShader sceGnmSetVsShader sceGnmSetCsShader sceGnmSetEsShader sceGnmSetGsShader sceGnmSetHsShader sceGnmSetLsShader→ all implemented on main, open: none.python3 tools/pr_overlap.py --branch fix/gnm-shader-guest-pointers→ no shared exports. It could not comparecore/libs/prx/libSceGnmDriver/Export.cppwith feat(libSceGnmDriver): share mode-independent command writers #17711 because feat(libSceGnmDriver): share mode-independent command writers #17711 conflicts with main. Its diff addssceGnmSetCsShaderWithModifierandsceGnmSetPsShader350and does not touch the seven writers changed here.Tested
Arch Linux, GCC, Release.
gnm_shader_writers(core/libs/prx/libSceGnmDriver/tests/ShaderWriters.cpp) has a newTestUnmapped:0x10and leaves the command buffer untouched.0x10, the null-register pixel shader included.Mutation checks (repeated after the rebase):
WriteShaderPacketignoring theGuestCopyOut_nid_no_patchresult fails withan unwritable pixel shader buffer was accepted.ReadShaderRegsignoring theGuestCopyIn_nid_no_patchresult fails withan unreadable pixel shader register block was accepted.Re-run after rebasing onto
origin/main0a025bd:ctest --test-dir build -R 'gnm|public_headers'passed 115/115. That coversgnm_shader_writers,gnm_default_state_200,guest_gnm_driver_init_modes, theguest_gnm_draw_*writers,gnm_driver_packetsand the 65public_headerstests.tools/check_conventions.py --base origin/mainpasses, andtools/guest_pointer_audit.py libSceGnmDriverno longer lists the seven writers.tools/progress.py --module libSceGnmDrivergives 53 done / 31 todo, the same asorigin/main.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)