Skip to content

fix(libkernel): check memory pool statistics output - #18818

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
THEMANnt:fix/libkernel-memory-pool-stats-output
Nov 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
THEMANnt:fix/libkernel-memory-pool-stats-output

Conversation

@THEMANnt

Copy link
Copy Markdown
Contributor

What

Snapshot the memory-pool block counts under the pool lock and use the checked guest copy to return them. An unwritable result returns EFAULT. The existing checks for a null pointer or undersized record still return EINVAL.

Tested

Windows x64, WinLibs GCC 15.2, Release. The guest_memory suite passed with the new unmapped output case, the size checks, and the existing block-count assertions after committing memory. The shared test hunks in #17553 cover direct-memory release, outside the block-statistics check.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@JJenkx

JJenkx commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 11a03196f0, merged onto main feebbc84fe (160c12ee02, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • guest_memory, guest_mmap_executable, guest_mmap_fixed_anonymous pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@github-actions

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 17553 core/libs/tests/GuestMemory.cpp

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 11a03196f0:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_memory_tests built cleanly.
  • CTest (guest_memory_pool_stats, guest_memory_resource, guest_memory_lifetime, guest_memory, guest_mmap_fixed_anonymous, guest_mmap_executable):
    1/6 Test  #859: guest_memory_pool_stats ..........   Passed    0.04 sec
    2/6 Test  #956: guest_memory_resource ............   Passed    0.04 sec
    3/6 Test #4379: guest_memory_lifetime ............   Passed    0.06 sec
    4/6 Test #4629: guest_mmap_executable ............   Passed    0.06 sec
    5/6 Test #4628: guest_mmap_fixed_anonymous .......   Passed    0.02 sec
    6/6 Test #4627: guest_memory .....................   Passed    3.76 sec
    100% tests passed, 0 tests failed out of 6
    
  • Negative control: with core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp reverted to main and the new tests kept, the suite fails:
    1/6 Test #4379: guest_memory_lifetime ............   Passed    0.05 sec
    2/6 Test #4629: guest_mmap_executable ............   Passed    0.05 sec
    3/6 Test  #859: guest_memory_pool_stats ..........   Passed    0.04 sec
    4/6 Test  #956: guest_memory_resource ............   Passed    0.03 sec
    5/6 Test #4628: guest_mmap_fixed_anonymous .......   Passed    0.02 sec
    6/6 Test #4627: guest_memory .....................***Exception: SegFault  0.47 sec
    83% tests passed, 1 tests failed out of 6
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp: verified sceKernelMemoryPoolGetBlockStats maintains input validation returning SCE_KERNEL_ERROR_EINVAL when output is nullptr or output_size is smaller than sizeof(KernelMemoryPoolBlockStats)
    • core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp: verified pool.mutex is properly acquired to protect the snapshot calculations from pool.expandedBytes and pool.committedBytes and released before copying to guest memory
    • core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp: verified value initialization of KernelMemoryPoolBlockStats stats{} correctly zeroes cached block fields (available_cached_blocks and allocated_cached_blocks) with no uninitialized memory leaks
    • core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp: verified GuestCopyOut_nid_no_patch copies exact struct size and properly translates failure into SCE_KERNEL_ERROR_EFAULT without holding pool.mutex during the copy
    • core/libs/tests/GuestMemory.cpp: verified CheckMemoryPoolBlockStats exercises the new unmapped pointer path returning SCE_KERNEL_ERROR_EFAULT alongside existing null, undersized, and success assertions
    • AGENTS.md compliance: verified no comments were introduced in modified files, PR title adheres to Conventional Commits, and no unauthorized files or workarounds were committed
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The change takes the pool counts under the lock, then returns them through the checked guest copy, so an unwritable output gives EFAULT; I found no defect in the code I read at head 11a0319.

What I ran

  • Head SHA: 11a0319
  • Read the run folder (description, commits, manifest, diff) and the head files through the repository reader.
  • No build or test was run in this review.
repo_read.py search GuestCopyOut_nid_no_patch
repo_read.py cat core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp 1 20
repo_read.py cat core/libs/prx/libkernel/DirectMemory/MemoryPoolExport.cpp 100 131
repo_read.py search KernelMemoryPoolBlockStats
repo_read.py search "bool GuestCopyOut_nid_no_patch"
repo_read.py cat core/libs/SceTypes.hpp 148 158
repo_read.py cat core/libs/prx/libc/src/General.cpp 820 845

Results

Check Result Note
Diff read passed Both changed files
Build not run No builds in this review
guest_memory suite not run Author reports a Windows run

Findings

Blocking

None.

Non-blocking

None found in the code read.

Sources

Not verified

  • The Linux branch of GuestCopyOut_nid_no_patch (after line 845) was not read. The new test expects EFAULT for address 1, which depends on that branch returning false.
  • core/libs/tests/GuestMemory.cpp: only the hunk at lines 4188-4191 was read, not the rest of CheckMemoryPoolBlockStats.
  • Other callers of sceKernelMemoryPoolGetBlockStats were not searched.
  • Nothing was built or run here. The Windows run is the author's report, not repeated.

To get this to a good state

No change is required from the code read. If a Linux run of guest_memory is available, it would confirm the EFAULT case on that path.

@oneandonlydean
oneandonlydean merged commit 63a14c5 into boykopovar:main Nov 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants