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

Closed
opened 2026-11-28 15:41:46 +00:00 by github-bot · 3 comments
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 15:37 UTC · original

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** on GitHub · 2026-11-28 15:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619) ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 15:41:46 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 15:37 UTC · original

/claim

**@⁠AnastasisKon** on GitHub · 2026-11-28 15:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619#issuecomment-7241607016) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 15:37 UTC · original

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

**@⁠github-actions[bot]** on GitHub · 2026-11-28 15:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619#issuecomment-7241609076) Claimed by @⁠AnastasisKon. Open a draft pull request with `Refs #619` in its description within 24 hours, or the claim expires.
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 16:31 UTC · original

Merged with the PR that serves these calls; closing.

**@⁠AnastasisKon** on GitHub · 2026-11-28 16:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/619#issuecomment-7242310972) Merged with the PR that serves these calls; closing.
This discussion has been locked. Commenting is limited to contributors.
No description provided.