Fix multiple memory-safety bugs, two UAF races, and complete missing F64 VOPC compares #1313

Closed
github-bot wants to merge 12 commits from gh-pr/1313/head into gh-pr/1313/base
Owner

@⁠HamsterCL on GitHub · 2026-10-09 15:46 UTC · original
HamsterCL:fix/memory-safety-shader-f64-vopc → main · +737 −121 · 27 files · 12 commits · closed without merging

Summary

  • Fix a Windows-specific networking bug where an unrecognized SOL_SOCKET option fell through to the native setsockopt/getsockopt call instead of being rejected, returning the wrong error code.
  • Fix 17 guest-input memory-safety bugs (PM4 command processor, ELF/SELF loader, cheat-file patcher, memory-mapped file I/O, AJM audio decoder, PRT aperture) and 2 use-after-free races (file descriptor table, kernel semaphores) found during a review pass.
  • Complete the double-precision (F64) VOPC compare opcode table in the shader recompiler — only 4 of 30 real opcodes were implemented; the rest fell back instead of compiling natively.

Testing

Full kyty_tests suite (53/53) passes after every change. The F64 opcode work also extends two existing GPU-executed tests (VectorCompareExecWaveMasks, VectorCompareF64Edges) to check real Vulkan execution output against independent plain-C++ double comparisons across NaN/signed-zero/subnormal edge cases, not just that it compiles.

AI involvement disclosure

Per this repo's contribution guidelines: this change was developed with AI assistance (code review to identify candidates, and implementation of the fixes). I reviewed, tested, and am responsible for the correctness of everything submitted here — see the Testing section above and the individual commit messages for the reasoning behind each fix.

**@⁠HamsterCL** on GitHub · 2026-10-09 15:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313) `HamsterCL:fix/memory-safety-shader-f64-vopc` → `main` · +737 −121 · 27 files · 12 commits · closed without merging ## Summary - Fix a Windows-specific networking bug where an unrecognized `SOL_SOCKET` option fell through to the native `setsockopt`/`getsockopt` call instead of being rejected, returning the wrong error code. - Fix 17 guest-input memory-safety bugs (PM4 command processor, ELF/SELF loader, cheat-file patcher, memory-mapped file I/O, AJM audio decoder, PRT aperture) and 2 use-after-free races (file descriptor table, kernel semaphores) found during a review pass. - Complete the double-precision (F64) VOPC compare opcode table in the shader recompiler — only 4 of 30 real opcodes were implemented; the rest fell back instead of compiling natively. ## Testing Full `kyty_tests` suite (53/53) passes after every change. The F64 opcode work also extends two existing GPU-executed tests (`VectorCompareExecWaveMasks`, `VectorCompareF64Edges`) to check real Vulkan execution output against independent plain-C++ `double` comparisons across NaN/signed-zero/subnormal edge cases, not just that it compiles. ## AI involvement disclosure Per this repo's contribution guidelines: this change was developed with AI assistance (code review to identify candidates, and implementation of the fixes). I reviewed, tested, and am responsible for the correctness of everything submitted here — see the Testing section above and the individual commit messages for the reasoning behind each fix.
ConvertSocketOptionName() returned the raw option value on Windows for
any SOL_SOCKET option not in its switch, so a genuinely invalid option
(e.g. the guest passing 0x7fffffff) was forwarded to native Winsock
instead of being rejected as ENOPROTOOPT. Winsock reports that case as
WSAEINVAL rather than WSAENOPROTOOPT, which broke the guest's expected
ENOPROTOOPT error contract (kernel_file_system_tests).

Add an explicit SO_RCVTIMEO (0x1006) case so it keeps working now that
unmapped options return -1 unconditionally instead of only on non-Windows.
Guest-controlled values were trusted without validation in several
places, letting a crafted game/ELF/PM4 stream read or write outside
intended bounds:

- pm4Handlers.cpp: IT_WRITE_DATA underflowed dw_num-2 to ~4B when
  dw_num was 0 or 1; IT_WRITE_CONST_RAM/IT_DUMP_CONST_RAM validated
  offset and dw_num independently but not their sum against the
  fixed-size const RAM array, allowing OOB read/write past it.
- runtimeLinker.cpp: LoadProgramToMemory used p_filesz unclamped
  against p_memsz (unlike the PT_TLS case a few lines below, which
  already clamps), and GetRelocationInfo indexed the symbol table
  with an unvalidated relocation symbol index.
- elf.cpp: LoadSegment indexed m_phdr with a SELF segment's embedded
  program-header index without checking it against e_phnum.
- sysWindowsFileIO.cpp / sysLinuxFileIO.cpp: SysFileSeek on a
  memory-backed file set ptr from an unclamped offset, which could
  later underflow the read/write length check and defeat its bounds
  clamp.
- ajm.cpp: AjmDecodeSplitInstance summed guest-supplied buffer sizes
  into a size_t with no overflow check, then copied the original
  (un-wrapped) sizes into a vector sized from the wrapped sum.

Also fixes two use-after-free races where Kernel*Close/Delete could
free an object a concurrent call on another thread was still using:

- fileSystem.cpp: DeleteDescriptor() could delete a File while
  another thread held a pointer from GetFile() mid-operation. Added
  a reference count on File, pinned by GetFile() and released by a
  new FileGuard RAII helper at every call site; deletion now defers
  to the last release when pending.
- semaphore.cpp: KernelDeleteSema() could free a KernelSemaPrivate
  while KernelWaitSema/Signal/Poll/Cancel was still validating or
  about to lock it. Added a small handle registry (PinSema/UnpinSema/
  RequestDeleteSema) so delete is deferred until no call is in
  flight.

Full kyty_tests suite (53/53) passes after these changes.
Memory safety:
- memory.cpp: KernelSetPrtAperture checked address < PRT_APERTURE_START
  but not address > PRT_APERTURE_END, so PRT_APERTURE_END - address
  underflowed for an above-range address, defeating the len bounds
  check entirely and letting MapGpuRange run on an attacker-chosen
  address/length.
- pm4Handlers.cpp: CpOpGetLodStats memset'd a guest-supplied
  destination for a fully guest-controlled buffer_size with no upper
  bound at all (not even an off-by-one, unlike every other handler in
  this file) — capped it to the same 0x3fff-dword ceiling used
  throughout pm4Handlers.cpp, and replaced the "// Hack?" comment with
  a one-line explanation of what the completion-flag write actually
  does.
- gamePatch.cpp: IsInsideProgram's `address + size <= base + mapped_size`
  bounds check overflowed for an address near UINT64_MAX (reachable via
  a crafted cheat-file offset through Translate()), bypassing the check
  and letting ApplyWrites memcpy to an arbitrary address. Rewritten
  with subtraction so it can't wrap.

Shader recompiler correctness:
- ShaderDecoder.cpp: DecodeScalarSource/DecodeScalarDestination called
  EXIT() — an unconditional process _Exit(), confirmed via
  DbgExitHandler/DbgExit — for any scalar operand code outside the
  cases they special-case (e.g. TTMP trap-temp registers). Any shader
  touching one of those gaps crashed the whole emulator instead of
  degrading gracefully like unknown opcodes do elsewhere via
  SetUnsupported(); now logs and falls back to OperandKind::Unknown.
- ValueOpcodes.cpp: HasSideEffects() didn't list ValueOpcode::Sendmsg,
  so a S_SENDMSG translated for a result nothing else reads (e.g. a
  GS/HS completion signal) could be stripped by DeadCodeElimination,
  silently dropping a real hardware signal.
- ShaderCFG.cpp: ResolveSetpcJumpTable/ResolveSetpcDwordJumpTable
  required 4/3 preceding instructions but only ever read back 3/2,
  rejecting a valid GETPC-based computed jump table when the idiom is
  the first thing in the function.

Full kyty_tests suite (53/53) still passes after these changes.

Investigated but intentionally not changed (documented for the
record, not applied blind):
- VectorAluOps.cpp VOPC_OPCODE_LIST is missing ~26 double-precision
  compare opcodes. Completing it correctly needs new IR ValueOpcodes,
  new SPIR-V emitter codegen, and changes across 6 files — a feature
  addition, not a bounded fix, and not verifiable here without a real
  double-precision-compare shader to render and compare pixel output.
- The "use Common::AlignUp/AlignDown instead of hand-rolled bitmask
  alignment" suggestion doesn't hold up: memory.cpp uses the raw
  bitmask form consistently at every call site (not just the one
  flagged), so switching one spot would make it less consistent with
  its own file, not more.
- Merging VirtualRangesOverlap (memory.cpp) with ImageRangeOverlaps
  (imageInfo.h) would force one overflow policy onto both: one clamps
  to UINT64_MAX, the other EXIT()s. Picking either changes real
  behavior for one of the two subsystems for a cosmetic de-dup with no
  bug behind it.
- The triplicated "split range, keep remainders" logic in
  memory.cpp/FlexibleMemory/PooledMemory each carry different
  per-block metadata and one uses a different container; unifying
  them means a new generic abstraction or a data-structure change to
  a working allocator, for style only.
- The per-draw expanded_indices allocation in renderDraw.cpp is real
  but reusing a scratch buffer safely requires confirming
  ExecutePreparedDraw never defers consumption of index_source.host_data
  past this call, which isn't verifiable without rendering a real
  frame to check for corruption.
VOPC_OPCODE_LIST had only 4 of the 30 real RDNA2 double-precision
compare opcodes (V_CMP_EQ_F64, V_CMP_LE_F64, V_CMPX_LE_F64,
V_CMPX_GE_F64); any other F64 vector compare a shader used (e.g.
v_cmp_lt_f64, v_cmpx_eq_f64) failed opcode lookup and fell back
instead of compiling natively.

Added the remaining 26 opcodes end to end, following the exact
semantic mapping already used for the F32/F16 variants in this file
(LG = ordered "<>", N* = IEEE unordered negation of the same-named
ordered predicate, O/U = is-ordered/is-unordered via isnan):

- ir/opcodes/ValueOpcodes.inc: 9 new F64 relational ValueOpcodes
  (FPOrd/FPUnord {NotEqual,LessThan,GreaterThan,...}64) plus FPIsNan64,
  mirroring the existing F32 set.
- backend/spirv: EMIT_NATIVE entries mapping each to its native SPIR-V
  op (OpFOrdLessThan, OpFUnordEqual, etc. - core SPIR-V 1.0, same
  Float64 capability the 4 existing F64 compares already require) and
  an EmitFPIsNan64 mirroring EmitFPIsNan32.
- frontend/decode: 26 new Opcode enum values and VOPC_OPCODE_LIST
  entries (DPP unsupported, matching the existing F64 entries);
  extended SupportsVopcSdwa, IsVopcFloatCompareOpcode and
  IsVopcCompareExec, which each separately classified the old 4.
- frontend/translate: IncludeInstructionVectorRegisters now marks all
  30 F64 compares (not just 4) as reading 64-bit VGPR pairs;
  EmitVector dispatches each to EmitFloatCompare with its new
  ValueOpcode; EmitFloatOrderedCompare (used for O/U) gained an is64
  parameter instead of being hardcoded to F32.

Verified, not just compiled: extended VectorCompareExecWaveMasks
(added the 12 new CMPX_*_F64 opcodes against its existing NaN/signed-
zero/subnormal wave-mask test vectors) and VectorCompareF64Edges
(added 6 of the 14 new non-X opcodes against its IEEE edge-case
pairs), both checking actual Vulkan execution output against
independent plain-C++ double comparisons - not a derivation of this
same implementation. Full kyty_tests suite (53/53) passes, including
these extended cases running on real GPU hardware.
# Conflicts:
#	src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h
- semaphore.cpp: Fix a hang introduced by the earlier UAF fix. Deferring
  deletion until the last pinned caller's Unpin() meant a thread blocked
  in Wait() with no timeout would never wake up after KernelDeleteSema(),
  because waking it was the destructor's job and the destructor never ran
  while that thread was still pinned. Split "mark deleted + wake waiters"
  into a new MarkDeleted(), called immediately by RequestDeleteSema()
  regardless of ref_count; only the actual free is deferred.
- network.cpp: Fix a regression in the SOL_SOCKET fix. Giving SO_RCVTIMEO
  (0x1006) an explicit mapping made Setsockopt/Getsockopt pass the raw
  guest int straight to the host on Linux, where SO_RCVTIMEO needs a
  timeval, not a bare int (unlike SO_SNDTIMEO's existing conversion,
  which already handles this for 0x1105). Added the matching conversion,
  confirmed against this codebase's own convention: RCVTIMEO is
  milliseconds here, not microseconds like SNDTIMEO (verified by running
  the existing Windows-only receive-timeout tests, which regressed when
  the two were naively unified under one conversion).
- runtimeLinker.cpp: The p_filesz/p_memsz fix clamped against the
  alignment-rounded segment size instead of the real declared p_memsz,
  which could still let LoadSegment copy past a small segment into
  whatever follows it in memory. Now rejects p_filesz > p_memsz outright.
  Also added a range check validating that DT_OS_SYMTAB/DT_OS_SYMTABSZ
  (guest-controlled) actually lie within the program's mapped memory,
  since the earlier relocation-index bounds check trusted the declared
  size without checking it against real backing storage.
- ShaderDecoder.{cpp,h} + ImageOps/MemoryOps/ScalarAluOps/VectorAluOps.cpp:
  Setting OperandKind::Unknown on an unrecognized scalar operand did not
  actually prevent the crash it was meant to avoid - ReadRawU32 still
  aborts on an Unknown-kind operand it's asked to read. DecodeScalarSource
  and DecodeScalarDestination now take the owning Instruction and call
  SetUnsupported() directly, matching how every other "can't decode this"
  case in this file already defers to the translator's existing bail-out
  instead of leaving a landmine for whatever reads the operand next.
- graphicsRun.cpp: ProcessPm4 ran a PM4 handler before checking whether
  the packet's own declared length fit in the command buffer's remaining
  space - only checking after, via the handler's return value. A handler
  like CpOpWriteData could already read past the command span by the time
  that check ran. Added the length check before dispatch.

Verified: full kyty_tests suite (53/53) passes, including kernel_file_system
(semaphore/socket fixes - recv-timeout tests specifically re-run to confirm
the unit fix), shader_recompiler_compute (operand-decode path), and the
PM4/loader tests.

Not applied: the review's 7th finding (src/kernel/fileSystem.cpp) - an
emergency-shutdown-time race between CloseAll()/Shutdown() and an active
FileGuard, reachable only during a crash/quick_exit path, not normal
operation. The suggested fix is a shutdown barrier blocking new filesystem
calls and waiting for in-flight ones; given it touches the crash-handling
path itself, a barrier that can block is a real risk of turning a crash
into a hang, which needs more validation than this pass can give it
blind. Left for a follow-up.
dw is remaining_dw from ProcessPm4 (includes the packet header), but
buffer here is already offset past both the header and CpOpSetContextReg's
own first operand word. The combined AA-sample-control + centroid-priority
shortcut read up to buffer[19], which needs dw >= 21 dwords available, not
>= 20 as checked - at dw == 20 the dw >= 20 check passed one dword short
and buffer[19] read past the command span. Found by CodeRabbit while
re-reviewing the ProcessPm4 length-check fix in the same file.
CloseAll() no longer deletes Files still pinned by another thread (they are
marked pending_delete and freed by the last ReleaseFile()), and Shutdown()
leaks g_files in that case instead of destroying it under a live FileGuard.
The DT_OS_SYMTAB extent check now only runs when a symbol table exists, so
ELFs without one no longer hit EXIT.
Comments only; addresses CodeRabbit's docstring-coverage check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:52:37 +00:00
github-bot closed this pull request 2026-11-26 09:52:37 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:52 UTC · original · edited 2026-10-09 17:52 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The changes add F64 vector comparison support across shader decoding, translation, SPIR-V emission, and compute tests. They also update file and semaphore handle lifetime tracking. Other changes add bounds checks to memory-backed seeks, GPU commands, kernel memory operations, library inputs, and loader paths. The changes also add receive-timeout socket option conversion and adjust shader decoding and jump-table handling.

Suggested reviewers: nmzik


Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🟡 Moderate · up to fcd74

The file-lifetime changes still leave races. A close can run during an active read or write. Shutdown can free the mount-point manager while a file open is still using it. A malformed game binary can cause a small out-of-bounds read. These issues should be resolved before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 8.82% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 102 functions across 26 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly summarizes the main changes: memory-safety fixes, use-after-free race fixes, and completion of F64 VOPC comparisons.
Description check Passed The description directly matches the changeset and explains the networking fix, memory-safety fixes, race fixes, F64 comparison work, and testing.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:52 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#issuecomment-6084378220) · edited 2026-10-09 17:52 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1313?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The changes add F64 vector comparison support across shader decoding, translation, SPIR-V emission, and compute tests. They also update file and semaphore handle lifetime tracking. Other changes add bounds checks to memory-backed seeks, GPU commands, kernel memory operations, library inputs, and loader paths. The changes also add receive-timeout socket option conversion and adjust shader decoding and jump-table handling. **Suggested reviewers:** `nmzik` <hr> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"fcd74b7c5359a264b1915200e796644f3bfc1147" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **🟡 Moderate** · up to `fcd74` <!-- final_review_risk_coverage:{"sourceCommitId":"fcd74b7c5359a264b1915200e796644f3bfc1147","coveredCommitId":"fcd74b7c5359a264b1915200e796644f3bfc1147","kind":"reviewed"} --> The file-lifetime changes still leave races. A close can run during an active read or write. Shutdown can free the mount-point manager while a file open is still using it. A malformed game binary can cause a small out-of-bounds read. These issues should be resolved before merge. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 8.82% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 102 functions across 26 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main changes: memory-safety fixes, use-after-free race fixes, and completion of F64 VOPC comparisons. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly matches the changeset and explains the networking fix, memory-safety fixes, race fixes, F64 comparison work, and testing. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <hr> </details> <hr> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1313)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) <hr> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -2630,6 +2640,8 @@ KYTY_CP_OP_PARSER(CpOpWriteData) {
auto dw_num = (cmd_id >> 16u) & 0x3fffu;
EXIT_NOT_IMPLEMENTED(dw_num < 2);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 16:19 UTC

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
rg -n -C 8 'CpOpWriteData|KYTY_PM4_LEN|ProcessIndirectBuffer|num_dw' \
  src/graphics/guest_gpu/command_processor

Repository: KytyPS5/KytyPS5

Length of output: 42157


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- CpOpWriteData ---'
nl -ba src/graphics/guest_gpu/command_processor/pm4Handlers.cpp | sed -n '2628,2675p'
printf '%s\n' '--- Process definitions and calls ---'
rg -n -C 12 --glob '*.{cpp,h}' -e 'Pm4ProcessResult CommandProcessor::Process|ProcessIndirectBuffer|g_cp_op_func|cp_op\\(' src/graphics/guest_gpu/command_processor
printf '%s\n' '--- commandProcessor.cpp candidate blocks ---'
rg -n 'Process\\(|ProcessIndirectBuffer|g_cp_op_func' src/graphics/guest_gpu/command_processor/commandProcessor.cpp

Repository: KytyPS5/KytyPS5

Length of output: 2280


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- command-processor files ---'
rg --files src/graphics/guest_gpu/command_processor | sort
printf '%s\n' '--- Process and dispatch references ---'
rg -n -F --glob '*.{cpp,h}' -- 'CommandProcessor::Process' src/graphics/guest_gpu/command_processor || true
rg -n -F --glob '*.{cpp,h}' -- 'ProcessIndirectBuffer' src/graphics/guest_gpu/command_processor || true
rg -n -F --glob '*.{cpp,h}' -- 'g_cp_op_func' src/graphics/guest_gpu/command_processor || true
printf '%s\n' '--- likely implementation blocks ---'
for f in src/graphics/guest_gpu/command_processor/*.cpp; do
  if rg -q -F -- 'ProcessIndirectBuffer' "$f" || rg -q -F -- 'Pm4ProcessResult' "$f"; then
    printf '%s\n' "--- $f ---"
    rg -n -C 25 -F -- 'ProcessIndirectBuffer' "$f" || true
    rg -n -C 35 -F -- 'Pm4ProcessResult' "$f" || true
  fi
done

Repository: KytyPS5/KytyPS5

Length of output: 11755


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- global definitions ---'
rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'CommandProcessor::Process' . || true
rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'CommandProcessor::ProcessIndirectBuffer' . || true
rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'ProcessIndirectBuffer(std::span' . || true
printf '%s\n' '--- command processor declarations and related loop symbols ---'
rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'Pm4Execution' . || true
rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'Pm4ProcessResult' . || true
printf '%s\n' '--- candidate files ---'
rg --files | rg -i 'command.?processor|pm4|graphics' | head -200

Repository: KytyPS5/KytyPS5

Length of output: 22424


🏁 Script executed:

set -euo pipefail
nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '620,680p'

Repository: KytyPS5/KytyPS5

Length of output: 2670


🏁 Script executed:

set -euo pipefail
nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '673,745p'

Repository: KytyPS5/KytyPS5

Length of output: 3740


🏁 Script executed:

set -euo pipefail
nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '733,790p'

Repository: KytyPS5/KytyPS5

Length of output: 2646


Reject truncated PM4 packets before invoking the handler.

ProcessPm4 invokes the handler before checking whether the declared packet length fits in remaining_dw. CpOpWriteData can therefore read past the command span before the post-dispatch check runs.

Suggested fix
+		const auto declared_packet_dw = KYTY_PM4_LEN(packet_header);
+		EXIT_NOT_IMPLEMENTED(declared_packet_dw == 0 || declared_packet_dw > remaining_dw);
+
 		const auto packet_dw =
 			handler(*this, packet_header & ~1u, packet + 1, remaining_dw, total_dw) + 1;

✅ Addressed in commit 4db4296

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991240) · edited 2026-10-09 16:19 UTC **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/usr/bin/env bash set -euo pipefail rg -n -C 8 'CpOpWriteData|KYTY_PM4_LEN|ProcessIndirectBuffer|num_dw' \ src/graphics/guest_gpu/command_processor ``` Repository: KytyPS5/KytyPS5 Length of output: 42157 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- CpOpWriteData ---' nl -ba src/graphics/guest_gpu/command_processor/pm4Handlers.cpp | sed -n '2628,2675p' printf '%s\n' '--- Process definitions and calls ---' rg -n -C 12 --glob '*.{cpp,h}' -e 'Pm4ProcessResult CommandProcessor::Process|ProcessIndirectBuffer|g_cp_op_func|cp_op\\(' src/graphics/guest_gpu/command_processor printf '%s\n' '--- commandProcessor.cpp candidate blocks ---' rg -n 'Process\\(|ProcessIndirectBuffer|g_cp_op_func' src/graphics/guest_gpu/command_processor/commandProcessor.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 2280 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- command-processor files ---' rg --files src/graphics/guest_gpu/command_processor | sort printf '%s\n' '--- Process and dispatch references ---' rg -n -F --glob '*.{cpp,h}' -- 'CommandProcessor::Process' src/graphics/guest_gpu/command_processor || true rg -n -F --glob '*.{cpp,h}' -- 'ProcessIndirectBuffer' src/graphics/guest_gpu/command_processor || true rg -n -F --glob '*.{cpp,h}' -- 'g_cp_op_func' src/graphics/guest_gpu/command_processor || true printf '%s\n' '--- likely implementation blocks ---' for f in src/graphics/guest_gpu/command_processor/*.cpp; do if rg -q -F -- 'ProcessIndirectBuffer' "$f" || rg -q -F -- 'Pm4ProcessResult' "$f"; then printf '%s\n' "--- $f ---" rg -n -C 25 -F -- 'ProcessIndirectBuffer' "$f" || true rg -n -C 35 -F -- 'Pm4ProcessResult' "$f" || true fi done ``` Repository: KytyPS5/KytyPS5 Length of output: 11755 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- global definitions ---' rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'CommandProcessor::Process' . || true rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'CommandProcessor::ProcessIndirectBuffer' . || true rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'ProcessIndirectBuffer(std::span' . || true printf '%s\n' '--- command processor declarations and related loop symbols ---' rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'Pm4Execution' . || true rg -n -F --glob '*.{cpp,h,cc,cxx}' -- 'Pm4ProcessResult' . || true printf '%s\n' '--- candidate files ---' rg --files | rg -i 'command.?processor|pm4|graphics' | head -200 ``` Repository: KytyPS5/KytyPS5 Length of output: 22424 --- 🏁 Script executed: ```bash set -euo pipefail nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '620,680p' ``` Repository: KytyPS5/KytyPS5 Length of output: 2670 --- 🏁 Script executed: ```bash set -euo pipefail nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '673,745p' ``` Repository: KytyPS5/KytyPS5 Length of output: 3740 --- 🏁 Script executed: ```bash set -euo pipefail nl -ba src/graphics/guest_gpu/graphicsRun.cpp | sed -n '733,790p' ``` Repository: KytyPS5/KytyPS5 Length of output: 2646 --- </details> **Reject truncated PM4 packets before invoking the handler.** `ProcessPm4` invokes the handler before checking whether the declared packet length fits in `remaining_dw`. `CpOpWriteData` can therefore read past the command span before the post-dispatch check runs. <details> <summary>Suggested fix</summary> ```diff + const auto declared_packet_dw = KYTY_PM4_LEN(packet_header); + EXIT_NOT_IMPLEMENTED(declared_packet_dw == 0 || declared_packet_dw > remaining_dw); + const auto packet_dw = handler(*this, packet_header & ~1u, packet + 1, remaining_dw, total_dw) + 1; ``` </details> <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:5ee5ead18996790d75098e4a --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4db4296
@ -269,0 +274,4 @@
// Unknown operand left unchecked would otherwise reach a reader that
// aborts the emulator instead of degrading gracefully.
SetUnsupported(inst, inst.family, inst.opcode_id, "unsupported scalar source operand");
operand.kind = OperandKind::Unknown;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 16:19 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect operand handling in the translation layer without running repository code.
rg -n -C 4 'OperandKind::Unknown|SetUnsupported\(|MayHaveSideEffects\(' src/graphics/shader/recompiler/frontend src/graphics/shader/recompiler/ir

Repository: KytyPS5/KytyPS5

Length of output: 41554


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- decoder fallback and declarations ---'
rg -n -C 12 -F -- 'OperandKind::Unknown' src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
printf '%s\n' '--- BuildGraph and translation entrypoints ---'
rg -n -C 10 -F -- 'BuildGraph' src/graphics/shader/recompiler
rg -n -C 10 -F -- 'TranslateInstruction' src/graphics/shader/recompiler
rg -n -C 10 -F -- 'ReadScalarSource' src/graphics/shader/recompiler/frontend
rg -n -C 10 -F -- 'ReadScalarDestination' src/graphics/shader/recompiler/frontend
printf '%s\n' '--- all Unknown handling in translation/frontend ---'
rg -n -C 5 -F -- 'OperandKind::Unknown' src/graphics/shader/recompiler/frontend

Repository: KytyPS5/KytyPS5

Length of output: 29538


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- translator operand helpers ---'
rg -n -C 18 -F -- 'SourceAt(const Decoder::Instruction' src/graphics/shader/recompiler/frontend/translate
rg -n -C 18 -F -- 'DestinationOperand(const Decoder::Instruction' src/graphics/shader/recompiler/frontend/translate
rg -n -C 12 -F -- 'ReadU32' src/graphics/shader/recompiler/frontend/translate
rg -n -C 12 -F -- 'WriteOperand' src/graphics/shader/recompiler/frontend/translate
printf '%s\n' '--- scalar translation dispatch and representative readers ---'
rg -n -C 18 -F -- 'case Decoder::Opcode::S_' src/graphics/shader/recompiler/frontend/translate
rg -n -C 18 -F -- 'TranslateScalar' src/graphics/shader/recompiler/frontend/translate
printf '%s\n' '--- SetUnsupported implementation ---'
rg -n -C 12 -F -- 'void SetUnsupported' src/graphics/shader/recompiler/frontend/decode

Repository: KytyPS5/KytyPS5

Length of output: 45669


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- exact operand helper definitions ---'
rg -n -F -- 'Translator::ReadRawU32' src/graphics/shader/recompiler/frontend/translate
rg -n -F -- 'Translator::ReadU32(' src/graphics/shader/recompiler/frontend/translate
rg -n -F -- 'Translator::WriteRawU32' src/graphics/shader/recompiler/frontend/translate
rg -n -F -- 'Translator::WriteOperand' src/graphics/shader/recompiler/frontend/translate
printf '%s\n' '--- helper source blocks ---'
sed -n '100,260p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- scalar instruction call sites ---'
rg -n -C 5 -F -- 'ReadU32(inst.src0)' src/graphics/shader/recompiler/frontend/translate/Scalar.cpp src/graphics/shader/recompiler/frontend/translate/Integer.cpp

Repository: KytyPS5/KytyPS5

Length of output: 38611


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- write helpers ---'
sed -n '260,410p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp
printf '%s\n' '--- read helper ---'
sed -n '460,490p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp

Repository: KytyPS5/KytyPS5

Length of output: 6622


Mark instructions with unknown scalar operands as unsupported.

OperandKind::Unknown does not stop translation. ReadU32 reaches ReadRawU32, whose default branch calls EXIT for an unknown source. An unknown destination can also reach the destination writer and call EXIT. After DecodeScalarSource or DecodeScalarDestination returns Unknown, mark the containing instruction with SetUnsupported before translation.

✅ Addressed in commit 4db4296

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991248) · edited 2026-10-09 16:19 UTC **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect operand handling in the translation layer without running repository code. rg -n -C 4 'OperandKind::Unknown|SetUnsupported\(|MayHaveSideEffects\(' src/graphics/shader/recompiler/frontend src/graphics/shader/recompiler/ir ``` Repository: KytyPS5/KytyPS5 Length of output: 41554 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- decoder fallback and declarations ---' rg -n -C 12 -F -- 'OperandKind::Unknown' src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h printf '%s\n' '--- BuildGraph and translation entrypoints ---' rg -n -C 10 -F -- 'BuildGraph' src/graphics/shader/recompiler rg -n -C 10 -F -- 'TranslateInstruction' src/graphics/shader/recompiler rg -n -C 10 -F -- 'ReadScalarSource' src/graphics/shader/recompiler/frontend rg -n -C 10 -F -- 'ReadScalarDestination' src/graphics/shader/recompiler/frontend printf '%s\n' '--- all Unknown handling in translation/frontend ---' rg -n -C 5 -F -- 'OperandKind::Unknown' src/graphics/shader/recompiler/frontend ``` Repository: KytyPS5/KytyPS5 Length of output: 29538 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- translator operand helpers ---' rg -n -C 18 -F -- 'SourceAt(const Decoder::Instruction' src/graphics/shader/recompiler/frontend/translate rg -n -C 18 -F -- 'DestinationOperand(const Decoder::Instruction' src/graphics/shader/recompiler/frontend/translate rg -n -C 12 -F -- 'ReadU32' src/graphics/shader/recompiler/frontend/translate rg -n -C 12 -F -- 'WriteOperand' src/graphics/shader/recompiler/frontend/translate printf '%s\n' '--- scalar translation dispatch and representative readers ---' rg -n -C 18 -F -- 'case Decoder::Opcode::S_' src/graphics/shader/recompiler/frontend/translate rg -n -C 18 -F -- 'TranslateScalar' src/graphics/shader/recompiler/frontend/translate printf '%s\n' '--- SetUnsupported implementation ---' rg -n -C 12 -F -- 'void SetUnsupported' src/graphics/shader/recompiler/frontend/decode ``` Repository: KytyPS5/KytyPS5 Length of output: 45669 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- exact operand helper definitions ---' rg -n -F -- 'Translator::ReadRawU32' src/graphics/shader/recompiler/frontend/translate rg -n -F -- 'Translator::ReadU32(' src/graphics/shader/recompiler/frontend/translate rg -n -F -- 'Translator::WriteRawU32' src/graphics/shader/recompiler/frontend/translate rg -n -F -- 'Translator::WriteOperand' src/graphics/shader/recompiler/frontend/translate printf '%s\n' '--- helper source blocks ---' sed -n '100,260p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- scalar instruction call sites ---' rg -n -C 5 -F -- 'ReadU32(inst.src0)' src/graphics/shader/recompiler/frontend/translate/Scalar.cpp src/graphics/shader/recompiler/frontend/translate/Integer.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 38611 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- write helpers ---' sed -n '260,410p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp printf '%s\n' '--- read helper ---' sed -n '460,490p' src/graphics/shader/recompiler/frontend/translate/Translate.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 6622 --- </details> **Mark instructions with unknown scalar operands as unsupported.** `OperandKind::Unknown` does not stop translation. `ReadU32` reaches `ReadRawU32`, whose default branch calls `EXIT` for an unknown source. An unknown destination can also reach the destination writer and call `EXIT`. After `DecodeScalarSource` or `DecodeScalarDestination` returns `Unknown`, mark the containing instruction with `SetUnsupported` before translation. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:46bcc7b88d0efa33093b737a --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4db4296
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 17:27 UTC
On src/kernel/fileSystem.cpp line 122 (outdated):

@@ -98,6 +119,8 @@ class FileDescriptors {
 static MountPoints*     g_mount_points = nullptr;
 static FileDescriptors* g_files        = nullptr;
 
+FileGuard::~FileGuard() { g_files->ReleaseFile(m_file); }

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- fileSystem.cpp relevant symbols ---'
rg -n -F --glob 'src/kernel/fileSystem.cpp' -e 'FileGuard' -e 'CloseAll' -e 'Shutdown' -e 'g_files' -e 'ReleaseFile' -e 'DeleteDescriptor'
printf '%s\n' '--- fileSystem.cpp surrounding implementation ---'
sed -n '1,230p' src/kernel/fileSystem.cpp
printf '%s\n' '--- shutdown and filesystem lifecycle references ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'FileSystem::Shutdown' -e 'fileSystem::Shutdown' -e 'g_files' -e 'CloseAll()' src
printf '%s\n' '--- declarations and lifecycle context ---'
rg -n -F --glob '*.{h,hpp,cpp}' -e 'class FileDescriptors' -e 'struct FileDescriptors' -e 'class FileGuard' -e 'FileDescriptors::Shutdown' -e 'FileDescriptors::CloseAll' src

Repository: KytyPS5/KytyPS5

Length of output: 13956


🏁 Script executed:

set -eu
printf '%s\n' '--- reference counting and shutdown implementation ---'
nl -ba src/kernel/fileSystem.cpp | sed -n '215,325p'
nl -ba src/kernel/fileSystem.cpp | sed -n '420,460p'
printf '%s\n' '--- filesystem lifecycle declaration ---'
nl -ba src/kernel/fileSystem.h | sed -n '1,90p'
printf '%s\n' '--- exact lifecycle call sites ---'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'FileSystem::Init' -e 'FileSystem::Shutdown' -e 'FileSystem::EmergencyShutdown' -e 'LibKernel::FileSystem::Init' -e 'LibKernel::FileSystem::Shutdown' -e 'LibKernel::FileSystem::EmergencyShutdown' . || test "$?" -eq 1
printf '%s\n' '--- all shutdown-related call sites in kernel and application lifecycle files ---'
rg -n --glob '*.{cpp,h,hpp}' '(^|::)(EmergencyShutdown|Shutdown)\s*\(' src | head -200

Repository: KytyPS5/KytyPS5

Length of output: 9429


🏁 Script executed:

set -eu
printf '%s\n' '--- lifecycle manager declarations and implementation ---'
rg -n --glob '*.{cpp,h,hpp}' -e 'class Subsystems' -e 'Subsystems::' -e 'Lifecycle' src/common src/kernel src | head -240
printf '%s\n' '--- subsystem lifecycle source ---'
nl -ba src/common/subsystems.cpp | sed -n '1,180p'
rg -n -F --glob '*.{cpp,h,hpp}' -e 'Subsystems::Initialize' -e 'Subsystems::Shutdown' -e 'Subsystems::EmergencyShutdown' -e 'InitializeSubsystem' -e 'ShutdownSubsystem' src tests
printf '%s\n' '--- filesystem test lifecycle context ---'
nl -ba tests/KernelFileSystemTests.cpp | sed -n '1680,1750p'

Repository: KytyPS5/KytyPS5

Length of output: 9340


🏁 Script executed:

set -eu
printf '%s\n' '--- emulator lifecycle registration and destruction ---'
nl -ba src/emulator.cpp | sed -n '120,220p'
printf '%s\n' '--- pthread lifecycle declaration ---'
nl -ba src/kernel/pthread.h | sed -n '1,40p'
printf '%s\n' '--- subsystem shutdown implementation ---'
nl -ba src/common/subsystems.cpp | sed -n '19,42p'
nl -ba src/common/subsystems.h | sed -n '1,80p'

Repository: KytyPS5/KytyPS5

Length of output: 7864


Keep the descriptor registry alive until guards finish.

The emergency shutdown path runs while guest threads are still active. CloseAll() deletes referenced File objects, and Shutdown() then deletes g_files. An active FileGuard can therefore access both objects after destruction.

Add a shutdown barrier that prevents new filesystem calls, waits for existing callers and guards to exit, and only then calls CloseAll() and deletes g_files.

✅ Addressed in commits 64235b9 to fcd74b7

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991259) · edited 2026-10-09 17:27 UTC On `src/kernel/fileSystem.cpp` line 122 (outdated): ```diff @@ -98,6 +119,8 @@ class FileDescriptors { static MountPoints* g_mount_points = nullptr; static FileDescriptors* g_files = nullptr; +FileGuard::~FileGuard() { g_files->ReleaseFile(m_file); } ``` **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -eu printf '%s\n' '--- fileSystem.cpp relevant symbols ---' rg -n -F --glob 'src/kernel/fileSystem.cpp' -e 'FileGuard' -e 'CloseAll' -e 'Shutdown' -e 'g_files' -e 'ReleaseFile' -e 'DeleteDescriptor' printf '%s\n' '--- fileSystem.cpp surrounding implementation ---' sed -n '1,230p' src/kernel/fileSystem.cpp printf '%s\n' '--- shutdown and filesystem lifecycle references ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'FileSystem::Shutdown' -e 'fileSystem::Shutdown' -e 'g_files' -e 'CloseAll()' src printf '%s\n' '--- declarations and lifecycle context ---' rg -n -F --glob '*.{h,hpp,cpp}' -e 'class FileDescriptors' -e 'struct FileDescriptors' -e 'class FileGuard' -e 'FileDescriptors::Shutdown' -e 'FileDescriptors::CloseAll' src ``` Repository: KytyPS5/KytyPS5 Length of output: 13956 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- reference counting and shutdown implementation ---' nl -ba src/kernel/fileSystem.cpp | sed -n '215,325p' nl -ba src/kernel/fileSystem.cpp | sed -n '420,460p' printf '%s\n' '--- filesystem lifecycle declaration ---' nl -ba src/kernel/fileSystem.h | sed -n '1,90p' printf '%s\n' '--- exact lifecycle call sites ---' rg -n -F --glob '*.{cpp,h,hpp}' -e 'FileSystem::Init' -e 'FileSystem::Shutdown' -e 'FileSystem::EmergencyShutdown' -e 'LibKernel::FileSystem::Init' -e 'LibKernel::FileSystem::Shutdown' -e 'LibKernel::FileSystem::EmergencyShutdown' . || test "$?" -eq 1 printf '%s\n' '--- all shutdown-related call sites in kernel and application lifecycle files ---' rg -n --glob '*.{cpp,h,hpp}' '(^|::)(EmergencyShutdown|Shutdown)\s*\(' src | head -200 ``` Repository: KytyPS5/KytyPS5 Length of output: 9429 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- lifecycle manager declarations and implementation ---' rg -n --glob '*.{cpp,h,hpp}' -e 'class Subsystems' -e 'Subsystems::' -e 'Lifecycle' src/common src/kernel src | head -240 printf '%s\n' '--- subsystem lifecycle source ---' nl -ba src/common/subsystems.cpp | sed -n '1,180p' rg -n -F --glob '*.{cpp,h,hpp}' -e 'Subsystems::Initialize' -e 'Subsystems::Shutdown' -e 'Subsystems::EmergencyShutdown' -e 'InitializeSubsystem' -e 'ShutdownSubsystem' src tests printf '%s\n' '--- filesystem test lifecycle context ---' nl -ba tests/KernelFileSystemTests.cpp | sed -n '1680,1750p' ``` Repository: KytyPS5/KytyPS5 Length of output: 9340 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- emulator lifecycle registration and destruction ---' nl -ba src/emulator.cpp | sed -n '120,220p' printf '%s\n' '--- pthread lifecycle declaration ---' nl -ba src/kernel/pthread.h | sed -n '1,40p' printf '%s\n' '--- subsystem shutdown implementation ---' nl -ba src/common/subsystems.cpp | sed -n '19,42p' nl -ba src/common/subsystems.h | sed -n '1,80p' ``` Repository: KytyPS5/KytyPS5 Length of output: 7864 --- </details> **Keep the descriptor registry alive until guards finish.** The emergency shutdown path runs while guest threads are still active. `CloseAll()` deletes referenced `File` objects, and `Shutdown()` then deletes `g_files`. An active `FileGuard` can therefore access both objects after destruction. Add a shutdown barrier that prevents new filesystem calls, waits for existing callers and guards to exit, and only then calls `CloseAll()` and deletes `g_files`. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d3da1c16f78f986423cd0422 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 64235b9 to fcd74b7
@ -76,0 +147,4 @@
sem->MarkDeleted();
UnpinSema(sem);
return true;
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 16:19 UTC

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Wake blocked waiters when deletion is deferred.

Before this change, KernelDeleteSema ran ~KernelSemaPrivate() immediately. That destructor set every waiter's result to Result::Deleted and called m_cond_var.SignalAll(). Now a thread blocked in KernelWaitSema holds a pin for the whole sem->Wait(...) call.

If that thread waits with no timeout (time == nullptr), here is what happens:

  • RequestDeleteSema only sets pending_delete = true and returns. It does not run the destructor.
  • Nothing marks the semaphore deleted, and nothing wakes the waiter.
  • No new caller can signal the semaphore, because PinSema now rejects pending handles.
  • The waiter stays blocked forever, and the object leaks.

This affects real code. In src/libs/audio3d.cpp:61-66, the playback loop waits on port->playback_sema with nullptr and only exits when it gets a non-OK result. Before this change, it got KERNEL_ERROR_EACCES on delete. After this change, that thread never exits after the port semaphore is deleted. Timed waiters still return, but they report a timeout instead of EACCES.

Fix: split the "mark deleted and wake waiters" step out of the destructor. Call it under the semaphore's own mutex when deletion is requested, whether the semaphore is pinned or not. The last UnpinSema then only frees the memory.

🐛 Proposed fix
--- "a/src/kernel/semaphore.cpp"
+++ "b/src/kernel/semaphore.cpp"
@@ -119,25 +119,22 @@
 // Called from KernelDeleteSema(). Returns false for an unknown/already
 // deleted handle; otherwise deletes immediately, or defers to the matching
 // UnpinSema() once every in-flight call on this handle has returned.
 bool RequestDeleteSema(KernelSemaPrivate* sem) {
 	bool delete_now = false;
 	{
 		Common::LockGuard lock(g_sema_registry_mutex);
 		auto              it = g_sema_registry.find(sem);
 		if (it == g_sema_registry.end() || it->second.pending_delete) {
 			return false;
 		}
 		it->second.pending_delete = true;
+		// Still pinned by this thread: no other thread can free sem yet.
+		it->second.ref_count++;
-		if (it->second.ref_count == 0) {
-			g_sema_registry.erase(it);
-			delete_now = true;
-		}
 	}
-	if (delete_now) {
-		delete sem;
-	}
+	sem->MarkDeleted(); // set Status::Deleted, set waiter results to Result::Deleted, SignalAll
+	UnpinSema(sem);     // frees the object now, or when the last waiter unpins
 	return true;
 }
 
 } // namespace
 

Add void MarkDeleted(); to KernelSemaPrivate, using the wake logic that is now in the destructor. The destructor can keep its loop that waits for m_waiting_threads to empty.

✅ Addressed in commit 4db4296

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991271) · edited 2026-10-09 16:19 UTC **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** **Wake blocked waiters when deletion is deferred.** Before this change, `KernelDeleteSema` ran `~KernelSemaPrivate()` immediately. That destructor set every waiter's result to `Result::Deleted` and called `m_cond_var.SignalAll()`. Now a thread blocked in `KernelWaitSema` holds a pin for the whole `sem->Wait(...)` call. If that thread waits with no timeout (`time == nullptr`), here is what happens: - `RequestDeleteSema` only sets `pending_delete = true` and returns. It does not run the destructor. - Nothing marks the semaphore deleted, and nothing wakes the waiter. - No new caller can signal the semaphore, because `PinSema` now rejects pending handles. - The waiter stays blocked forever, and the object leaks. This affects real code. In `src/libs/audio3d.cpp:61-66`, the playback loop waits on `port->playback_sema` with `nullptr` and only exits when it gets a non-`OK` result. Before this change, it got `KERNEL_ERROR_EACCES` on delete. After this change, that thread never exits after the port semaphore is deleted. Timed waiters still return, but they report a timeout instead of `EACCES`. Fix: split the "mark deleted and wake waiters" step out of the destructor. Call it under the semaphore's own mutex when deletion is requested, whether the semaphore is pinned or not. The last `UnpinSema` then only frees the memory. <details> <summary>🐛 Proposed fix</summary> ```diff --- "a/src/kernel/semaphore.cpp" +++ "b/src/kernel/semaphore.cpp" @@ -119,25 +119,22 @@ // Called from KernelDeleteSema(). Returns false for an unknown/already // deleted handle; otherwise deletes immediately, or defers to the matching // UnpinSema() once every in-flight call on this handle has returned. bool RequestDeleteSema(KernelSemaPrivate* sem) { bool delete_now = false; { Common::LockGuard lock(g_sema_registry_mutex); auto it = g_sema_registry.find(sem); if (it == g_sema_registry.end() || it->second.pending_delete) { return false; } it->second.pending_delete = true; + // Still pinned by this thread: no other thread can free sem yet. + it->second.ref_count++; - if (it->second.ref_count == 0) { - g_sema_registry.erase(it); - delete_now = true; - } } - if (delete_now) { - delete sem; - } + sem->MarkDeleted(); // set Status::Deleted, set waiter results to Result::Deleted, SignalAll + UnpinSema(sem); // frees the object now, or when the last waiter unpins return true; } } // namespace ``` Add `void MarkDeleted();` to `KernelSemaPrivate`, using the wake logic that is now in the destructor. The destructor can keep its loop that waits for `m_waiting_threads` to empty. </details> <!-- fingerprinting:phantom:medusa:pangolin --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:805573c3d2e0c88193364a56 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4db4296
@ -1070,3 +1071,4 @@
case 0x0020: return SO_BROADCAST;
case 0x1001: return SO_SNDBUF;
case 0x1002: return SO_RCVBUF;
case 0x1006: return SO_RCVTIMEO;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 16:19 UTC

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Convert the receive-timeout value before calling the host API.

On Linux, Setsockopt passes the guest's four-byte value directly to SO_RCVTIMEO. Linux requires a timeval, so the 0x1006 call in tests/KernelFileSystemTests.cpp:1221-1268 fails instead of setting a timeout. Add receive-timeout conversion in Setsockopt and Getsockopt, as the existing 0x1105 send-timeout paths do.

✅ Addressed in commit 4db4296

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991277) · edited 2026-10-09 16:19 UTC **🎯 Functional Correctness** | **🟠 Major** | **🏗️ Heavy lift** **Convert the receive-timeout value before calling the host API.** On Linux, `Setsockopt` passes the guest's four-byte value directly to `SO_RCVTIMEO`. Linux requires a `timeval`, so the `0x1006` call in `tests/KernelFileSystemTests.cpp:1221-1268` fails instead of setting a timeout. Add receive-timeout conversion in `Setsockopt` and `Getsockopt`, as the existing `0x1105` send-timeout paths do. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:8430ebcb74fbf1df90f24f4f --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4db4296
@ -827,1 +828,4 @@
case R_X86_64_64: {
EXIT_NOT_IMPLEMENTED(
symbols == nullptr ||
symbol >= program->dynamic_info->symbol_table_total_size / sizeof(Elf64_Sym));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 16:19 UTC

🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift

Validate the symbol-table extent before using its declared size.

symbol_table_total_size comes from the guest ELF's DT_OS_SYMTABSZ at Line 1909. symbol_table is also derived from guest ELF metadata at Line 1908. This check trusts both values, so a malformed ELF can pass the index check while symbols[symbol] reads outside its backing storage. CreateSymbolDatabase also iterates the declared size before relocation at Lines 2083-2088. Validate the table pointer and full byte range against its actual backing storage before any symbol-table access.

✅ Addressed in commit 4db4296

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991286) · edited 2026-10-09 16:19 UTC **🔒 Security & Privacy** | **🟠 Major** | **🏗️ Heavy lift** **Validate the symbol-table extent before using its declared size.** `symbol_table_total_size` comes from the guest ELF's `DT_OS_SYMTABSZ` at Line 1909. `symbol_table` is also derived from guest ELF metadata at Line 1908. This check trusts both values, so a malformed ELF can pass the index check while `symbols[symbol]` reads outside its backing storage. `CreateSymbolDatabase` also iterates the declared size before relocation at Lines 2083-2088. Validate the table pointer and full byte range against its actual backing storage before any symbol-table access. <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:013c41596a15c35aaa15bb56 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4db4296
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · edited 2026-10-09 16:19 UTC
On src/loader/runtimeLinker.cpp line 1731 (outdated):

@@ -1724,8 +1727,8 @@ void RuntimeLinker::LoadProgramToMemory(Program* program) {
 	for (Elf64_Half i = 0; i < ehdr->e_phnum; i++) {
 		if (phdr[i].p_memsz != 0 && (phdr[i].p_type == PT_LOAD || phdr[i].p_type == PT_OS_RELRO)) {
 			uint64_t segment_addr        = phdr[i].p_vaddr + program->base_vaddr;
-			uint64_t segment_file_size   = phdr[i].p_filesz;
 			uint64_t segment_memory_size = GetAlignedSize(phdr + i);
+			uint64_t segment_file_size   = std::min(phdr[i].p_filesz, segment_memory_size);

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Bound file data by p_memsz, not its aligned size.

GetAlignedSize can round p_memsz up to p_align. For example, p_memsz = 0x100, p_align = 0x4000, and p_filesz = 0x2000 leave segment_file_size at 0x2000. LoadSegment then copies beyond the segment's declared memory range and can overwrite another segment if their ranges overlap. Reject headers where p_filesz > p_memsz.

Proposed fix
--- "a/src/loader/runtimeLinker.cpp"
+++ "b/src/loader/runtimeLinker.cpp"
@@ -1728,7 +1728,8 @@
 		if (phdr[i].p_memsz != 0 && (phdr[i].p_type == PT_LOAD || phdr[i].p_type == PT_OS_RELRO)) {
 			uint64_t segment_addr        = phdr[i].p_vaddr + program->base_vaddr;
 			uint64_t segment_memory_size = GetAlignedSize(phdr + i);
-			uint64_t segment_file_size   = std::min(phdr[i].p_filesz, segment_memory_size);
+			EXIT_NOT_IMPLEMENTED(phdr[i].p_filesz > phdr[i].p_memsz);
+			uint64_t segment_file_size   = phdr[i].p_filesz;
 			auto     mode                = GetMode(phdr[i].p_flags);
 
 			LOGF("[%d] addr        = 0x%016" PRIx64 "\n"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

			EXIT_NOT_IMPLEMENTED(phdr[i].p_filesz > phdr[i].p_memsz);
			uint64_t segment_file_size   = phdr[i].p_filesz;

✅ Addressed in commit 4db4296

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4231991296) · edited 2026-10-09 16:19 UTC On `src/loader/runtimeLinker.cpp` line 1731 (outdated): ```diff @@ -1724,8 +1727,8 @@ void RuntimeLinker::LoadProgramToMemory(Program* program) { for (Elf64_Half i = 0; i < ehdr->e_phnum; i++) { if (phdr[i].p_memsz != 0 && (phdr[i].p_type == PT_LOAD || phdr[i].p_type == PT_OS_RELRO)) { uint64_t segment_addr = phdr[i].p_vaddr + program->base_vaddr; - uint64_t segment_file_size = phdr[i].p_filesz; uint64_t segment_memory_size = GetAlignedSize(phdr + i); + uint64_t segment_file_size = std::min(phdr[i].p_filesz, segment_memory_size); ``` **🗄️ Data Integrity & Integration** | **🟡 Minor** | **⚡ Quick win** **Bound file data by `p_memsz`, not its aligned size.** `GetAlignedSize` can round `p_memsz` up to `p_align`. For example, `p_memsz = 0x100`, `p_align = 0x4000`, and `p_filesz = 0x2000` leave `segment_file_size` at `0x2000`. `LoadSegment` then copies beyond the segment's declared memory range and can overwrite another segment if their ranges overlap. Reject headers where `p_filesz > p_memsz`. <details> <summary>Proposed fix</summary> ```diff --- "a/src/loader/runtimeLinker.cpp" +++ "b/src/loader/runtimeLinker.cpp" @@ -1728,7 +1728,8 @@ if (phdr[i].p_memsz != 0 && (phdr[i].p_type == PT_LOAD || phdr[i].p_type == PT_OS_RELRO)) { uint64_t segment_addr = phdr[i].p_vaddr + program->base_vaddr; uint64_t segment_memory_size = GetAlignedSize(phdr + i); - uint64_t segment_file_size = std::min(phdr[i].p_filesz, segment_memory_size); + EXIT_NOT_IMPLEMENTED(phdr[i].p_filesz > phdr[i].p_memsz); + uint64_t segment_file_size = phdr[i].p_filesz; auto mode = GetMode(phdr[i].p_flags); LOGF("[%d] addr = 0x%016" PRIx64 "\n" ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion EXIT_NOT_IMPLEMENTED(phdr[i].p_filesz > phdr[i].p_memsz); uint64_t segment_file_size = phdr[i].p_filesz; ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:106237f2fc64a2adf2ab16e4 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 4db4296
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 15:53 UTC · original · reviewed

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Synchronize host-file close with active operations. · fileSystem.cpp:642-644

src/kernel/fileSystem.cpp:642-644
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Synchronize host-file close with active operations.

If KernelRead holds a FileGuard and is using file->f, KernelClose can call file->f.Close() concurrently. The reference keeps File allocated, but it does not keep the host file open. A concurrent read or write can therefore use a closed host handle. Coordinate close with active operations before closing the handle.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fb1738d9-1ab5-4561-a7fc-84eabd7d04ec
📥 Commits

Reviewing files that changed from the base of the PR and between 4c8fc53a85 and 9a77d9c560.

📒 Files selected for processing (24)
  • src/common/platform/sysLinuxFileIO.cpp
  • src/common/platform/sysWindowsFileIO.cpp
  • src/graphics/guest_gpu/command_processor/pm4Handlers.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterAlu.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h
  • src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
  • src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
  • src/graphics/shader/recompiler/frontend/translate/Compare.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translator.h
  • src/graphics/shader/recompiler/frontend/translate/Vector.cpp
  • src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cpp
  • src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc
  • src/kernel/fileSystem.cpp
  • src/kernel/memory.cpp
  • src/kernel/semaphore.cpp
  • src/libs/ajm.cpp
  • src/libs/network.cpp
  • src/loader/elf.cpp
  • src/loader/gamePatch.cpp
  • src/loader/runtimeLinker.cpp
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#pullrequestreview-5472353245) · **reviewed** **Actionable comments posted: 7** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟠 Major</strong> · Synchronize host-file close with active operations. · <code>fileSystem.cpp:642-644</code></summary><blockquote> > > `src/kernel/fileSystem.cpp:642-644` > **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** > > **Synchronize host-file close with active operations.** > > If KernelRead holds a FileGuard and is using `file->f`, KernelClose can call `file->f.Close()` concurrently. The reference keeps `File` allocated, but it does not keep the host file open. A concurrent read or write can therefore use a closed host handle. Coordinate close with active operations before closing the handle. > > <!-- cr-comment:v1:4ffd68a4d8b04815265dd880 --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `fb1738d9-1ab5-4561-a7fc-84eabd7d04ec` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 4c8fc53a8582543200caa697acad2a9f09937cec and 9a77d9c560cf4fd6dd2a7a80a31e2d4741c80c94. </details> <details> <summary>📒 Files selected for processing (24)</summary> * `src/common/platform/sysLinuxFileIO.cpp` * `src/common/platform/sysWindowsFileIO.cpp` * `src/graphics/guest_gpu/command_processor/pm4Handlers.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterAlu.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h` * `src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h` * `src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp` * `src/graphics/shader/recompiler/frontend/translate/Compare.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translator.h` * `src/graphics/shader/recompiler/frontend/translate/Vector.cpp` * `src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cpp` * `src/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inc` * `src/kernel/fileSystem.cpp` * `src/kernel/memory.cpp` * `src/kernel/semaphore.cpp` * `src/libs/ajm.cpp` * `src/libs/network.cpp` * `src/loader/elf.cpp` * `src/loader/gamePatch.cpp` * `src/loader/runtimeLinker.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=f69d834b-6621-4bc4-86b7-e140e53cb92d attempt=c5d2e0d7-744f-4cb2-972d-ed7202bdfc75 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 16:02 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Handle an unknown scalar destination in the same way. · ShaderDecoder.cpp:295-296

src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp:295-296
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Handle an unknown scalar destination in the same way.

An Unknown destination can reach the destination writer and abort there. Mark the instruction with SetUnsupported when DecodeScalarDestination yields Unknown. This is the same root cause as the source operand case.

♻️ Duplicate comments (1)
src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp (1)

273-274: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Mark the instruction unsupported when a scalar source operand is unknown.

DecodeScalarSource now returns OperandKind::Unknown instead of calling EXIT. The decoder callers do not mark the instruction with SetUnsupported. A reserved scalar code therefore reaches translation, and translation can still call EXIT there. The change only moves the abort and loses the decode-time context. Past review comments already raised this point.

Mark the containing instruction with SetUnsupported after decoding when any operand has kind Unknown. Alternatively, return a status from the decode helpers.


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9f1d3c5-dcef-416b-81d1-0b1577aa5513
📥 Commits

Reviewing files that changed from the base of the PR and between 9a77d9c560 and 8166180eec.

📒 Files selected for processing (7)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h
  • src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
  • src/graphics/shader/recompiler/frontend/translate/Translate.cpp
  • src/graphics/shader/recompiler/frontend/translate/Translator.h
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 16:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#pullrequestreview-5472458047) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong>🟡 Minor</strong> · Handle an unknown scalar destination in the same way. · <code>ShaderDecoder.cpp:295-296</code></summary><blockquote> > > `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp:295-296` > **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** > > **Handle an unknown scalar destination in the same way.** > > An `Unknown` destination can reach the destination writer and abort there. Mark the instruction with `SetUnsupported` when `DecodeScalarDestination` yields `Unknown`. This is the same root cause as the source operand case. > > <!-- cr-comment:v1:b1954ee401b941f74a8d59bd --> > > </blockquote></details> <details> <summary>♻️ Duplicate comments (1)</summary><blockquote> <details> <summary>src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp (1)</summary><blockquote> `273-274`: **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Mark the instruction unsupported when a scalar source operand is unknown.** `DecodeScalarSource` now returns `OperandKind::Unknown` instead of calling `EXIT`. The decoder callers do not mark the instruction with `SetUnsupported`. A reserved scalar code therefore reaches translation, and translation can still call `EXIT` there. The change only moves the abort and loses the decode-time context. Past review comments already raised this point. Mark the containing instruction with `SetUnsupported` after decoding when any operand has kind `Unknown`. Alternatively, return a status from the decode helpers. <!-- cr-comment:v1:be3c7e361e0c1f41979b942b --> </blockquote></details> </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `e9f1d3c5-dcef-416b-81d1-0b1577aa5513` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 9a77d9c560cf4fd6dd2a7a80a31e2d4741c80c94 and 8166180eecb0bfa9e34c279808b037c601169412. </details> <details> <summary>📒 Files selected for processing (7)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.h` * `src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h` * `src/graphics/shader/recompiler/frontend/translate/Translate.cpp` * `src/graphics/shader/recompiler/frontend/translate/Translator.h` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=e031b9c8-02a3-4bd3-bf42-bfe7f7a67049 attempt=19a217fb-a3e4-4a83-abf5-bcfac68a05ef batch=1/1 -->
@ -751,0 +754,4 @@
// packet that claims to be longer than what's actually left in the command
// buffer before dispatch, so a handler can never read past the command span.
const auto declared_packet_dw = KYTY_PM4_LEN(packet_header);
EXIT_NOT_IMPLEMENTED(declared_packet_dw == 0 || declared_packet_dw > remaining_dw);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 16:24 UTC · original · edited 2026-10-09 16:29 UTC

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

handler_file="$(fd -i '^pm4Handlers\.cpp$' | head -n1)"
printf 'Handler file: %s\n' "$handler_file"
rg -n -A28 -B4 'HwCtxSetAaSampleControl|CpOpSetContextReg' "$handler_file"
rg -n -A6 -B4 'declared_packet_dw|handler\(\*this' src/graphics/guest_gpu/graphicsRun.cpp

Repository: KytyPS5/KytyPS5

Length of output: 3032


🏁 Script executed:

set -euo pipefail
printf '%s\n' '--- ProcessPm4 context ---'
sed -n '700,775p' src/graphics/guest_gpu/graphicsRun.cpp
printf '%s\n' '--- PM4 length definitions and handler macro ---'
rg -n -F -- 'KYTY_PM4_LEN' src/graphics/guest_gpu
rg -n -F -- 'KYTY_HW_CTX_PARSER' src/graphics/guest_gpu/command_processor
printf '%s\n' '--- complete AA sample handler ---'
sed -n '220,275p' src/graphics/guest_gpu/command_processor/pm4Handlers.cpp
printf '%s\n' '--- PM4 packet/header definitions ---'
rg -n -F -- 'remaining_dw' src/graphics/guest_gpu/graphicsRun.cpp src/graphics/guest_gpu

Repository: KytyPS5/KytyPS5

Length of output: 18432


Require the complete combined packet before reading its payload.

remaining_dw includes the packet header, but buffer starts at packet + 1. When remaining_dw == 20, the dw >= 20 condition allows the combined path even though only 19 payload dwords remain. buffer[19] then reads beyond the command span.

🐛 Suggested fix
-	if (dw >= 20 && buffer[16] == 0xc0026900 && buffer[17] == Pm4::PA_SC_CENTROID_PRIORITY_0) {
+	if (dw >= 21 && buffer[16] == 0xc0026900 && buffer[17] == Pm4::PA_SC_CENTROID_PRIORITY_0) {

✅ Addressed in commit 565f452

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 16:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4232267003) · edited 2026-10-09 16:29 UTC **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/usr/bin/env bash set -euo pipefail handler_file="$(fd -i '^pm4Handlers\.cpp$' | head -n1)" printf 'Handler file: %s\n' "$handler_file" rg -n -A28 -B4 'HwCtxSetAaSampleControl|CpOpSetContextReg' "$handler_file" rg -n -A6 -B4 'declared_packet_dw|handler\(\*this' src/graphics/guest_gpu/graphicsRun.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 3032 --- 🏁 Script executed: ```bash set -euo pipefail printf '%s\n' '--- ProcessPm4 context ---' sed -n '700,775p' src/graphics/guest_gpu/graphicsRun.cpp printf '%s\n' '--- PM4 length definitions and handler macro ---' rg -n -F -- 'KYTY_PM4_LEN' src/graphics/guest_gpu rg -n -F -- 'KYTY_HW_CTX_PARSER' src/graphics/guest_gpu/command_processor printf '%s\n' '--- complete AA sample handler ---' sed -n '220,275p' src/graphics/guest_gpu/command_processor/pm4Handlers.cpp printf '%s\n' '--- PM4 packet/header definitions ---' rg -n -F -- 'remaining_dw' src/graphics/guest_gpu/graphicsRun.cpp src/graphics/guest_gpu ``` Repository: KytyPS5/KytyPS5 Length of output: 18432 --- </details> **Require the complete combined packet before reading its payload.** `remaining_dw` includes the packet header, but `buffer` starts at `packet + 1`. When `remaining_dw == 20`, the `dw >= 20` condition allows the combined path even though only 19 payload dwords remain. `buffer[19]` then reads beyond the command span. <details> <summary>🐛 Suggested fix</summary> ```diff - if (dw >= 20 && buffer[16] == 0xc0026900 && buffer[17] == Pm4::PA_SC_CENTROID_PRIORITY_0) { + if (dw >= 21 && buffer[16] == 0xc0026900 && buffer[17] == Pm4::PA_SC_CENTROID_PRIORITY_0) { ``` </details> <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:8a4ae8fd95c4028c988797f6 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 565f452
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 16:24 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b4055251-14e2-4366-b06a-ffe1ab7a5f62
📥 Commits

Reviewing files that changed from the base of the PR and between 8166180eec and 4db4296166.

📒 Files selected for processing (10)
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp
  • src/graphics/shader/recompiler/frontend/decode/MemoryOps.cpp
  • src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
  • src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp
  • src/kernel/semaphore.cpp
  • src/libs/network.cpp
  • src/loader/runtimeLinker.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/loader/runtimeLinker.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp
  • src/kernel/semaphore.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 16:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#pullrequestreview-5472679036) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `b4055251-14e2-4366-b06a-ffe1ab7a5f62` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 8166180eecb0bfa9e34c279808b037c601169412 and 4db429616632fbbdd45cf91d3999fa6b41e349b1. </details> <details> <summary>📒 Files selected for processing (10)</summary> * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/shader/recompiler/frontend/decode/ImageOps.cpp` * `src/graphics/shader/recompiler/frontend/decode/MemoryOps.cpp` * `src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h` * `src/graphics/shader/recompiler/frontend/decode/VectorAluOps.cpp` * `src/kernel/semaphore.cpp` * `src/libs/network.cpp` * `src/loader/runtimeLinker.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary> * src/loader/runtimeLinker.cpp * src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cpp * src/kernel/semaphore.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=e43819fd-ebca-47d6-ae65-a05237b4fabd attempt=b375ae88-a8b9-4219-89c2-a67baed8eae7 batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 17:22 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 943b2830-7dd9-4edd-a71c-4c5a22f527a7
📥 Commits

Reviewing files that changed from the base of the PR and between 565f4528f8 and 49e66334a1.

📒 Files selected for processing (6)
  • src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp
  • src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h
  • src/graphics/shader/recompiler/frontend/translate/Translator.h
  • src/kernel/fileSystem.cpp
  • src/kernel/semaphore.cpp
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 17:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#pullrequestreview-5473238690) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `943b2830-7dd9-4edd-a71c-4c5a22f527a7` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 565f4528f881e4ced2387044db0aad70a4c3838b and 49e66334a12b7a6810c6e0047ceb68b25622021e. </details> <details> <summary>📒 Files selected for processing (6)</summary> * `src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp` * `src/graphics/shader/recompiler/frontend/decode/ShaderDecoder.h` * `src/graphics/shader/recompiler/frontend/translate/Translator.h` * `src/kernel/fileSystem.cpp` * `src/kernel/semaphore.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=d66d80d4-4228-46c5-a67b-906d7fdc5c32 attempt=860f0854-b365-4d67-a902-c0de7a5160ff batch=1/1 -->
@ -835,0 +859,4 @@
// Decodes a scalar source operand; unsupported codes mark inst unsupported instead of aborting.
void DecodeScalarSource(uint32_t code, uint32_t pc, Instruction& inst, Operand& operand);
// Decodes a scalar destination operand; unsupported codes mark inst unsupported instead of aborting.
void DecodeScalarDestination(uint32_t code, uint32_t pc, Instruction& inst, Operand& operand);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 17:22 UTC · original · edited 2026-10-09 17:26 UTC

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Update the remaining DecodeScalarDestination call.

DecodeScalarDestination now requires inst. The S_GETREG_B32 and S_MOVK_I32 branch at Line 231 of src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp still calls it with three arguments. This prevents compilation. Pass inst at that call site.

✅ Addressed in commit 64235b9

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 17:22 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4232747824) · edited 2026-10-09 17:26 UTC **🎯 Functional Correctness** | **🔴 Critical** | **⚡ Quick win** **Update the remaining `DecodeScalarDestination` call.** `DecodeScalarDestination` now requires `inst`. The `S_GETREG_B32` and `S_MOVK_I32` branch at Line 231 of `src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp` still calls it with three arguments. This prevents compilation. Pass `inst` at that call site. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:dd54a6c3fc82b4998d9ad4e3 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 64235b9
Author
Owner

@⁠HamsterCL on GitHub · 2026-10-09 17:31 UTC · original

@⁠coderabbitai review

**@⁠HamsterCL** on GitHub · 2026-10-09 17:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#issuecomment-6085953098) @⁠coderabbitai review
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 17:31 UTC · original · edited 2026-10-09 17:35 UTC

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 17:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#issuecomment-6085955203) · edited 2026-10-09 17:35 UTC <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: v2:b20cdc19294c0a457966839166fe82014304acc27222b18643e304e441610240 --> <details> <summary>✅ Action performed</summary> Review finished. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused. </details>
@ -388,0 +480,4 @@
g_files = nullptr;
delete g_mount_points;
g_mount_points = nullptr;
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 17:35 UTC · original · edited 2026-10-09 17:39 UTC

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Keep mount points alive while file calls remain active.

If CloseAllFiles() returns false while KernelOpen() is between GetFile() and ResolvePath(), Shutdown() retains g_files but deletes g_mount_points. KernelOpen() then dereferences the deleted mount-point manager. Drain active filesystem calls before deleting either manager, or retain both until those calls finish.

✅ Addressed in commits 2fad740 to 038fbb6

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 17:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4232856098) · edited 2026-10-09 17:39 UTC **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** **Keep mount points alive while file calls remain active.** If `CloseAllFiles()` returns `false` while `KernelOpen()` is between `GetFile()` and `ResolvePath()`, `Shutdown()` retains `g_files` but deletes `g_mount_points`. `KernelOpen()` then dereferences the deleted mount-point manager. Drain active filesystem calls before deleting either manager, or retain both until those calls finish. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:966e9ffaf36f5e9dd8359634 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 2fad740 to 038fbb6
@ -1907,0 +1914,4 @@
// DT_OS_SYMTAB/DT_OS_SYMTABSZ are guest-controlled; make sure the declared
// symbol table actually lies within this program's mapped memory before
// anything (GetRelocationInfo, CreateSymbolDatabase) indexes into it.
if (program->dynamic_info->symbol_table != nullptr) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 17:35 UTC · original · edited 2026-10-09 17:39 UTC

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Reject symbol-table sizes that contain a partial entry.

This check accepts a declared size that is not a multiple of sizeof(Elf64_Sym). CreateSymbolDatabase then advances by whole entries while the pointer is still below the declared end. For example, a 32-byte table can trigger a read of a full second entry at offset 24. If the table ends at mapped_size, that read extends 16 bytes beyond the allocation and can fault. Reject sizes that do not contain a whole number of entries.

Proposed fix
 		EXIT_NOT_IMPLEMENTED(symtab_offset > program->mapped_size ||
 		                     program->dynamic_info->symbol_table_total_size >
-		                         program->mapped_size - symtab_offset);
+		                         program->mapped_size - symtab_offset ||
+		                     program->dynamic_info->symbol_table_total_size %
+		                             sizeof(Elf64_Sym) != 0);

✅ Addressed in commits 2fad740 to 038fbb6

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 17:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#discussion_r4232856107) · edited 2026-10-09 17:39 UTC **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** **Reject symbol-table sizes that contain a partial entry.** This check accepts a declared size that is not a multiple of `sizeof(Elf64_Sym)`. `CreateSymbolDatabase` then advances by whole entries while the pointer is still below the declared end. For example, a 32-byte table can trigger a read of a full second entry at offset 24. If the table ends at `mapped_size`, that read extends 16 bytes beyond the allocation and can fault. Reject sizes that do not contain a whole number of entries. <details> <summary>Proposed fix</summary> ```diff EXIT_NOT_IMPLEMENTED(symtab_offset > program->mapped_size || program->dynamic_info->symbol_table_total_size > - program->mapped_size - symtab_offset); + program->mapped_size - symtab_offset || + program->dynamic_info->symbol_table_total_size % + sizeof(Elf64_Sym) != 0); ``` </details> <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:4eaa77182a42f1f8cd0cdffa --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commits 2fad740 to 038fbb6
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 17:35 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9011144c-b963-49d7-a924-9a82743d08d6
📥 Commits

Reviewing files that changed from the base of the PR and between 49e66334a1 and fcd74b7c5359a264b1915200e796644f3bfc1147.

📒 Files selected for processing (3)
  • src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp
  • src/kernel/fileSystem.cpp
  • src/loader/runtimeLinker.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 17:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#pullrequestreview-5473364123) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9011144c-b963-49d7-a924-9a82743d08d6` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 49e66334a12b7a6810c6e0047ceb68b25622021e and fcd74b7c5359a264b1915200e796644f3bfc1147. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/shader/recompiler/frontend/decode/ScalarAluOps.cpp` * `src/kernel/fileSystem.cpp` * `src/loader/runtimeLinker.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=7cf223c2-620a-4f9b-a0b9-b5b09b5db184 attempt=6b3498fc-a2a8-41a5-8ca2-1752f8303f53 batch=1/1 -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-09 19:03 UTC · original

Credited

**@⁠Nmzik** on GitHub · 2026-10-09 19:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#issuecomment-6087421447) Credited
Author
Owner

@⁠HamsterCL on GitHub · 2026-10-09 20:35 UTC · original

@⁠coderabbitai review

**@⁠HamsterCL** on GitHub · 2026-10-09 20:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#issuecomment-6088817841) @⁠coderabbitai review
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:35 UTC · original

⚠️ Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1313#issuecomment-6088820087) <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: v2:82a5433f3b72f942f6bb28b194203a5900b66397526910e10035c06718692b75 --> <details> <summary>⚠️ Action not completed</summary> Pull request is closed. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused. </details>

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.