Repository navigation
kernelx: report the physical memory layout (XMemGetPhysicalMemoryLayout) #3352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ pub fn exports() -> Vec<(&'static str, usize)> { | |
| XMemFreePhysicalPages, | ||
| XMemTransferMemory, | ||
| XMemGetWorkingSetStatistics, | ||
| XMemGetPhysicalMemoryLayout, | ||
| XMemIsToolsMemAvailable, | ||
| TitleMemoryStatus, | ||
| JobTitleMemoryStatus, | ||
|
|
@@ -1639,6 +1640,22 @@ pub unsafe extern "system" fn XMemGetWorkingSetStatistics(_flags: u32, stats: *m | |
| 1 | ||
| } | ||
|
|
||
| /// `BOOL XMemGetPhysicalMemoryLayout(XMEM_PHYSICAL_MEMORY_LAYOUT* layout)`: two ULONG_PTR fields – | ||
| /// the lowest title physical page number, then the lowest page number of GPU-optimal-bandwidth | ||
| /// ("fast") memory. The console splits the title's physical memory into standard- and | ||
| /// GPU-optimal-bandwidth regions; here it is one pool with no bandwidth split, so both are 0 – all | ||
| /// title memory counts as GPU-optimal from page 0, matching the single fast-memory pool | ||
| /// `XMemGetWorkingSetStatistics` reports. | ||
| pub unsafe extern "system" fn XMemGetPhysicalMemoryLayout(layout: *mut u8) -> BOOL { | ||
| if layout.is_null() { | ||
| fnd::SetLastError(fnd::ERROR_INVALID_PARAMETER); | ||
| return 0; | ||
| } | ||
| (layout as *mut usize).write_unaligned(0); // LowestPageNumber | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LowestPageNumber is reported as 0, but XCL's allocator never hands out page 0: |
||
| (layout.add(std::mem::size_of::<usize>()) as *mut usize).write_unaligned(0); // LowestPageNumberGpuOptimalBandwidth | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not certain about this one: with both fields equal, the standard-bandwidth region is empty (GpuOptimal - Lowest = 0), which no real console reports, since Series X and S both have a non-empty standard region. A title that splits its budget from |
||
| 1 | ||
| } | ||
|
|
||
| /// `BOOL XMemTransferMemory(direction, size)`: moving budget between the title and the tools | ||
| /// pools – there is one budget here | ||
| pub unsafe extern "system" fn XMemTransferMemory(_direction: u32, _size: usize) -> BOOL { | ||
|
|
@@ -3237,6 +3254,19 @@ pub unsafe extern "system" fn DisableThreadLibraryCalls(h: usize) -> BOOL { | |
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn physical_memory_layout_writes_both_page_numbers() { | ||
| // 0xCC..-filled buffer with a guard word after the two fields | ||
| let mut buf = [usize::MAX; 3]; | ||
| unsafe { | ||
| assert_eq!(XMemGetPhysicalMemoryLayout(buf.as_mut_ptr() as *mut u8), 1); | ||
| assert_eq!(XMemGetPhysicalMemoryLayout(std::ptr::null_mut()), 0, "null layout fails"); | ||
| } | ||
| assert_eq!(buf[0], 0, "LowestPageNumber"); | ||
| assert_eq!(buf[1], 0, "LowestPageNumberGpuOptimalBandwidth"); | ||
| assert_eq!(buf[2], usize::MAX, "nothing written past the two fields"); | ||
| } | ||
|
|
||
| /// `XCL_COHERENT_HEAPS=sparse[:N]`: which heaps go to the sparse windows | ||
| #[test] | ||
| fn sparse_heaps_setting() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not certain about this one: the XMEM_PHYSICAL_MEMORY_LAYOUT layout (exactly two ULONG_PTR fields, no size/version field) is assumed and written through an untyped
*mut u8, with no cited source, and no title has been seen calling it. If the real struct has more fields or a leading size/version, the title reads uninitialised stack for them after a TRUE return, which is worse than the old failure return. A#[repr(C)]struct likeTitleMemoryStatusTwould at least pin the assumed layout.