hle(host_posix): file mappings are unimplemented, so a title that maps a data file reads nothing #619

Closed
opened 2026-11-28 15:37:07 +00:00 by AnastasisKon · 3 comments
AnastasisKon commented 2026-11-28 15:37:07 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T15:37:07Z.


Summary

host_posix/files.rs answered the file calls a title makes with CreateFile/ReadFile, but nothing for the ones it makes when it maps a data file instead of reading it: CreateFileMappingW, OpenFileMappingW, MapViewOfFile(Ex), FlushViewOfFile and UnmapViewOfFile were all unimplemented, so they landed in the loader's import stub and a title that maps its archives would read nothing.

The interesting part is not the calls but where the view's memory comes from. Every reader of title memory here - the GPU's page table (xmem_physical), the descriptor readers, the tracing - knows the ranges VirtualAlloc made and nothing else, so a host mmap of the file would be invisible to them. A view is therefore title memory holding a copy of that part of the file, made with one pread at the mapping, and a write-through view's bytes go back with pwrite at FlushViewOfFile or UnmapViewOfFile, clamped to what the file had.

What the change does

  • CreateFileMappingW: a section over a file (its size, or the caller's), or over the pagefile for INVALID_HANDLE_VALUE and a size. A name handed out twice is the same section with ERROR_ALREADY_EXISTS, as Windows reports it; OpenFileMappingW finds it by name.
  • MapViewOfFile/MapViewOfFileEx: a view at an offset that must be a multiple of 64 KiB (ERROR_MAPPED_ALIGNMENT), 0 bytes meaning the rest of the section, refused with ERROR_ACCESS_DENIED when it would write a section created read-only. Past the file's end the view is zero, as a view's last page is.
  • A pagefile section's views are windows on one allocation, so memory shared through it is shared between views; a file section's views are separate copies, which is the shortcut where Windows would share pages. Both are written down.
  • UnmapViewOfFile frees a view's own memory; a pagefile view is part of its section and is freed with it.

Tests

Five new ones in files.rs: a view holds the file at its offset and survives the section handle closing; a write view writes through on flush and on unmap without growing the file; the refusals and their error codes; the pagefile section zeroed, shared between two views and found by its name; and a section's views seen through OpenFileMappingW.

Why it matters

A title that maps a data file instead of reading it gets its bytes, and the GPU can read the same addresses, because the view is title memory like any other.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6667466836 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T15:37:07Z. --- ## Summary `host_posix/files.rs` answered the file calls a title makes with `CreateFile`/`ReadFile`, but nothing for the ones it makes when it maps a data file instead of reading it: `CreateFileMappingW`, `OpenFileMappingW`, `MapViewOfFile(Ex)`, `FlushViewOfFile` and `UnmapViewOfFile` were all unimplemented, so they landed in the loader's import stub and a title that maps its archives would read nothing. The interesting part is not the calls but where the view's memory comes from. Every reader of title memory here - the GPU's page table (`xmem_physical`), the descriptor readers, the tracing - knows the ranges `VirtualAlloc` made and nothing else, so a host `mmap` of the file would be invisible to them. A view is therefore title memory holding a copy of that part of the file, made with one `pread` at the mapping, and a write-through view's bytes go back with `pwrite` at `FlushViewOfFile` or `UnmapViewOfFile`, clamped to what the file had. ## What the change does - `CreateFileMappingW`: a section over a file (its size, or the caller's), or over the pagefile for `INVALID_HANDLE_VALUE` and a size. A name handed out twice is the same section with `ERROR_ALREADY_EXISTS`, as Windows reports it; `OpenFileMappingW` finds it by name. - `MapViewOfFile`/`MapViewOfFileEx`: a view at an offset that must be a multiple of 64 KiB (`ERROR_MAPPED_ALIGNMENT`), `0` bytes meaning the rest of the section, refused with `ERROR_ACCESS_DENIED` when it would write a section created read-only. Past the file's end the view is zero, as a view's last page is. - A pagefile section's views are windows on one allocation, so memory shared through it is shared between views; a file section's views are separate copies, which is the shortcut where Windows would share pages. Both are written down. - `UnmapViewOfFile` frees a view's own memory; a pagefile view is part of its section and is freed with it. ## Tests Five new ones in `files.rs`: a view holds the file at its offset and survives the section handle closing; a write view writes through on flush and on unmap without growing the file; the refusals and their error codes; the pagefile section zeroed, shared between two views and found by its name; and a section's views seen through `OpenFileMappingW`. ## Why it matters A title that maps a data file instead of reading it gets its bytes, and the GPU can read the same addresses, because the view is title memory like any other.
AnastasisKon commented 2026-11-28 15:37:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T15:37:15Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7241607016 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619#issuecomment-7241607016). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T15:37:15Z. --- /claim
github-actions[bot] commented 2026-11-28 15:37:25 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T15:37:25Z.


Claimed by @AnastasisKon. Open a draft pull request with Refs #619 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7241609076 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619#issuecomment-7241609076). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T15:37:25Z. --- Claimed by @AnastasisKon. Open a draft pull request with `Refs #619` in its description within 24 hours, or the claim expires.
AnastasisKon commented 2026-11-28 16:31:41 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T16:31:41Z.


Merged with the PR that serves these calls; closing.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7242310972 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619#issuecomment-7242310972). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T16:31:41Z. --- Merged with the PR that serves these calls; closing.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#619
No description provided.