Skip to content

Record file views mapped at an address the program picks - #163

Merged
simonlindholm merged 6 commits into
decompals:mainfrom
ZebulanStanphill:fix-mapviewofex-registration
Nov 1, 2026
Merged

simonlindholm merged 6 commits into
decompals:mainfrom
ZebulanStanphill:fix-mapviewofex-registration

Conversation

@ZebulanStanphill

@ZebulanStanphill ZebulanStanphill commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Background

Windows programs can map a file into memory: MapViewOfFileEx makes the file's contents appear at some address in the program's memory (a "view" of the file). Its last argument, lpBaseAddress, lets the program pick that address itself; if it passes NULL, the system picks one. When the program picks the address, Windows only maps the view there if that memory isn't already in use.

wibo keeps the Windows program's memory (the guest memory) in the low 2 GB of its own address space, and manages that range itself. It keeps a table of which parts of the range are in use, the guest mapping table in src/heap.cpp. VirtualAlloc consults the table to find free memory. Memory that isn't in use may be covered by an inaccessible placeholder mapping (PROT_NONE). On Linux, wibo covers all unused memory in the range with placeholders at startup. On both Linux and macOS, VirtualFree puts a placeholder back over memory it releases.

Problem

mapViewOfFileInternal (in dll/kernel32/memoryapi.cpp, behind both MapViewOfFile and MapViewOfFileEx) only adds a view to the table when wibo picks its address. When the program picks the address, the view is mapped without being recorded. What goes wrong depends on the platform:

  • Linux: MapViewOfFileEx fails with ERROR_INVALID_ADDRESS even when the table shows that memory as free. wibo maps the view with MAP_FIXED_NOREPLACE, which refuses to map over any existing host mapping, and free memory in the range is normally covered by a placeholder (always, in the linker's case below).
  • macOS: there is no MAP_FIXED_NOREPLACE, so wibo uses MAP_FIXED, which maps over whatever is there. MapViewOfFileEx succeeds, but the table still shows that memory as free. A later VirtualAlloc can be given the same addresses, and its mmap silently replaces the view. Mapping a view on top of an existing allocation or view also silently replaces it, where Windows would refuse.

I ran into this with the Xbox 360 linker, link.exe 10.00.10224 from "Visual Studio 2010 for Xbox 360", when linking with /LTCG and /EXPORT. It's in the X360/16.00.10224.00 folder of decomp.dev's compiler bundle, compilers_20260305.zip; the folder is named after the compiler's version. The linker reserves some memory with VirtualAlloc, releases it, maps an output file at that address with MapViewOfFileEx, and then allocates more memory. On Linux the MapViewOfFileEx call fails. On macOS the later allocation lands on top of the output file's view and the link crashes.

Fix

  • New wibo::heap::reserveViewRangeAt checks the address range the program asked for against the table and, if it's free, records it there as in use (claims it), the same way VirtualAlloc handles a requested address. The view is then mapped into that range with MAP_FIXED, replacing the placeholder if there is one; this is safe because the table has already confirmed the range is free.
    • A free range now works on Linux.
    • On both platforms, a range that overlaps an existing allocation or view fails with ERROR_INVALID_ADDRESS, as it does on Windows and under Wine.
    • Views whose address wibo picks were already recorded, so every view is now in the table, and VirtualAlloc can no longer hand out memory that a view occupies.
  • UnmapViewOfFile now puts the placeholder back, as VirtualFree does, instead of calling munmap. wibo does the same if mapping fails after the range was claimed. That way the freed range never becomes a hole where an unrelated mmap, by wibo itself or a library it loads, could land. This applies to every view, not only those at an address the program picked.
  • A base above the highest user address (0x7FFEFFFF, for a program that isn't large-address-aware) now fails with ERROR_INVALID_PARAMETER, which is what Windows returns for MapViewOfFileEx (VirtualAlloc returns ERROR_INVALID_ADDRESS for the same address). Before, this branch had no upper limit, and since the upper 2 GB is no longer blocked, it would try to map there.
  • A view that covers 0x7FFE0000 now fails with ERROR_INVALID_ADDRESS, as on Windows, which always maps the shared user data page there. This includes every view whose base is in range but that runs past 0x7FFEFFFF. Such views already failed in wibo with that error, because on Linux the guest stack is reserved there and on macOS the guest range ends at 0x7E000000; the check makes this independent of where the stack lands.

Testing

There are three new tests, all added to the existing test_createfilemapping fixture (test/test_createfilemapping.c).

test_fixed_address_view_is_not_reallocated reproduces the linker's sequence: reserve memory with VirtualAlloc, release it, and map a file view at that address with MapViewOfFileEx. It then checks that:

  • VirtualAlloc(NULL, ...) returns memory outside the view, and the view's contents survive.
  • VirtualAlloc and MapViewOfFileEx at the view's address fail with ERROR_INVALID_ADDRESS.
  • After UnmapViewOfFile, that address can be reserved again.

test_fixed_address_view_does_not_replace_allocation checks that MapViewOfFileEx at an address that is still allocated fails with ERROR_INVALID_ADDRESS and leaves the allocation's contents intact. It checks both a view covering the whole allocation and a view whose start is free but whose end overlaps an allocation. This case comes from the test in #146, and its author is credited as a co-author of that commit.

test_fixed_address_view_at_top_of_user_range_fails checks that MapViewOfFileEx fails with ERROR_INVALID_PARAMETER for a base past 0x7FFEFFFF (0x7FFF0000 and 0x80000000), and with ERROR_INVALID_ADDRESS for a view that covers 0x7FFE0000 (64 KiB and 64 KiB + 1 byte at 0x7FFE0000, and 128 KiB at 0x7FFD0000).

Windows Server 2025 (a GitHub Actions windows-latest runner, running the 32-bit test program built with mingw): the whole test_createfilemapping fixture passes, including all three new tests (run). Small probe programs show that, for a program that isn't large-address-aware:

  • MapViewOfFileEx at 0x7FFF0000, 0x80000000 or 0x90000000 fails with ERROR_INVALID_PARAMETER, while VirtualAlloc at 0x80000000 fails with ERROR_INVALID_ADDRESS (run).
  • The shared user data page is mapped at 0x7FFE0000, and any view or allocation that covers it fails with ERROR_INVALID_ADDRESS, including views that end at or below 0x7FFEFFFF, such as 128 KiB at 0x7FFD0000 (run).

Wine 9.0 (x86_64 Ubuntu 24.04 VM): the first two tests pass. The third fails, because Wine doesn't (yet in a stable release) enforce the 2 GB limit: it maps the test's view at 0x80000000 (and, in a separate probe, lets VirtualAlloc allocate there), although its GetSystemInfo reports 0x7FFEFFFF as the highest application address, as Windows does.

Local wibo builds:

wibo build Without the fix With the fix
Linux, debug (32-bit) and debug64 (64-bit) presets, same VM first test fails: MapViewOfFileEx fails with ERROR_INVALID_ADDRESS (run on its own, the second passes, since each of its fixed-address views lands on a placeholder or a live allocation) ctest passes, 55/55 for each preset
macOS, Release build (x86_64, run under Rosetta) the first two tests fail: VirtualAlloc returns the view's address, and MapViewOfFileEx over a live allocation succeeds the test_createfilemapping fixture passes, including all three new tests (full suite: see CI)

CI (this repo's workflow, run on my fork): in the run with the fix, the new tests pass in every job that runs the test suite, including all three macOS builds. The two Static, 64-bit jobs run no tests, on main too. The only failure is test_namedpipe (test_namedpipe.c:64) in Build Debug (32-bit) and Build Release (32-bit). It fails the same way in a run of unmodified main (f3570ca), so this PR didn't cause it. test_namedpipe passes in my local 32-bit Linux debug build, so the failure looks specific to the CI runner. (The main run shows commit 0d36348 rather than f3570ca, because I pushed a copy of it, with identical files, to a temporary branch to start it.)

Related PRs

LLM disclosure

This PR was made with an LLM, Claude Opus 5.5 in Claude Code. It tracked down the bug, wrote the fix and the tests, ran the tests on Wine, Linux, macOS and Windows, and drafted this description. A second Claude agent reviewed the change, and its critiques were addressed. I directed the work and reviewed this description.

🤖 Generated with Claude Code

@ZebulanStanphill
ZebulanStanphill marked this pull request as ready for review October 31, 2026 03:51
mapViewOfFileInternal only claimed a range in the guest mapping table
when it picked the address itself. With a caller-supplied base
(MapViewOfFileEx with lpBaseAddress) it went straight to mmap:

- On Linux it used MAP_FIXED_NOREPLACE, but free guest memory is
  normally covered by a PROT_NONE placeholder (VirtualFree(MEM_RELEASE)
  puts it back), so the call failed with ERROR_INVALID_ADDRESS even
  when the table showed the range as free.
- On macOS there is no MAP_FIXED_NOREPLACE, so it used MAP_FIXED but
  left the view out of the table, and the range still looked free: a
  later VirtualAlloc could be given it, and its MAP_FIXED mmap silently
  replaced the view. Mapping over an existing allocation or view
  replaced it the same way.

The Xbox 360 MSVC linker hits this: it reserves a range, releases it,
maps its output file there, and then allocates more memory.

Check and claim a caller-supplied range in the guest mapping table, as
VirtualAlloc does for a requested address, then map it with MAP_FIXED.
Every view is now recorded. UnmapViewOfFile puts the PROT_NONE
placeholder back, as VirtualFree does, instead of unmapping, so an
unrelated host mmap can't land in the freed range. Add a test for the
reserve, release, map, allocate sequence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZebulanStanphill
ZebulanStanphill force-pushed the fix-mapviewofex-registration branch from 17a6eaa to f42f316 Compare October 31, 2026 03:53
@simonlindholm

Copy link
Copy Markdown
Contributor

I'm very confused about how the existing code and what it was meant to do. Is it just broken and nobody noticed until now? (I have vague memories of the memory blocking setup being different before, so maybe it used to work.) Or is it meant to be able to map memory in the upper 2 GB? Can you do some digging with git blame/Discord search?

ZebulanStanphill and others added 3 commits October 31, 2026 10:12
MapViewOfFileEx at an address that is still allocated must fail with
ERROR_INVALID_ADDRESS and leave the allocation intact, both when the
view would cover the whole allocation and when only the end of the
requested range is allocated. Without the previous commit, macOS maps
the view over the allocation and the test fails.

This case comes from the fixed-view test in decompals#146.

Co-authored-by: banteg <4562643+banteg@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MapViewOfFileEx with a base above the highest user address (0x7FFEFFFF
for a process that isn't large-address-aware) fails on Windows with
ERROR_INVALID_PARAMETER, unlike VirtualAlloc, which returns
ERROR_INVALID_ADDRESS for the same address. Check for that before
claiming the range, and test a base at 0x80000000.

Checked on Windows Server 2025 (GitHub Actions windows-latest). Wine
doesn't enforce the limit and maps the view, so the new test fails
there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The base-address limit check matches Windows, not Wine, which maps the
view above 0x7FFEFFFF. Say so next to the check, not only in the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZebulanStanphill

Copy link
Copy Markdown
Contributor Author

Had my agents run over everything a number of times to research and triple-check some stuff, and here's what they found. In short:

  • Is it just broken? Yes, though it indeed used to work, albeit briefly. MapViewOfFileEx's last argument, lpBaseAddress, lets the program choose the address where the view is mapped (its base address); passing NULL lets the system choose. The fixed-base path, meaning the if (baseAddress) branch of mapViewOfFileInternal that handles a program-chosen base address, worked on Linux for about a month after it was written. Then the memory blocking setup changed and this path wasn't updated, so on Linux, MapViewOfFileEx with a base address now fails with ERROR_INVALID_ADDRESS even on free guest memory below 2 GB (except in a gap left by an unmapped view). On macOS (which wibo only began to support after that change) it has never been safe: MapViewOfFileEx succeeds, but the view isn't recorded in the guest mapping table (g_mappings in src/heap.cpp), so later allocations can replace it. It stayed unfixed because wibo's tests never caught it (none passes a base address), and although two other contributors have run into this issue (Add Xbox 360 linker support (fake mspdb PDB interface) #110 and fix: support VC6 precompiled header creation and reuse #146, below), neither of their PRs has been merged.
  • Was it meant to map into the upper 2 GB? No. When the path was written, the upper 2 GB was blocked off. The two commits that unblocked it (52cdd7c and 4dc5993, step 4 below) leave the upper 2 GB "untouched for host code", in 4dc5993's words. wibo also reports 0x7FFEFFFF as the highest application address (GetSystemInfo). On current main, though, nothing stops this path from mapping above 2 GB. This PR rejects a base address above 0x7FFEFFFF the way Windows does, which my agents checked on a Windows runner.

The agents searched through git log/git blame and GitHub issues and PRs, and I had them build old revisions to confirm their findings. I also briefly searched the decomp.me Discord myself, but didn't spot anything relevant there.

I've also updated the PR since your comment with some more tests (including one based on a related scenario also noticed in #146) and an additional upper-limit check to more exactly match Windows behavior (as described below).

What changed
  1. The upper 2 GB is blocked (Force VirtualAlloc allocations to fall below the 2GB mark #36, "Force VirtualAlloc allocations to fall below the 2GB mark"; June 2023): every gap between existing mappings above 2 GB is filled with readable anonymous mappings, so the kernel hands out addresses below 2 GB. Ensure we don't reallocate during 2GB address space block #49 ("Ensure we don't reallocate during 2GB address space block"; Oct 2023) moves this into blockUpper2GB, which runs early in main, before wibo loads the program.

  2. VirtualAlloc and friends are rewritten (41f8388; Oct 1, 2025). Afterwards:

    • VirtualAlloc(NULL) is an mmap with no address hint, so the kernel picks the address.
    • VirtualAlloc at a requested address uses MAP_FIXED_NOREPLACE, so the kernel refuses ranges in use.
    • VirtualFree(MEM_RELEASE) is a plain munmap, so free memory really is unmapped.

    wibo does keep tables of allocations (g_virtualAllocations) and views (g_viewInfo). But the kernel is what picks addresses and what refuses overlaps between allocations and views.

  3. MapViewOfFileEx is added the next day (3249ebf; Oct 2, 2025; "Split advapi32 into separate files (part 2) & more impls for ee-gcc/cygwin"): the fixed-base path uses MAP_FIXED_NOREPLACE (or MAP_FIXED if the system headers don't define that flag), just like VirtualAlloc at a requested address. Under step 2's kernel-managed design, this is safe on Linux with MAP_FIXED_NOREPLACE: the view lands only on free memory, and the kernel won't hand that range to a later allocation.

  4. The blocking moves from the upper 2 GB to the lower 2 GB (52cdd7c on Oct 31, 2025; 4dc5993 on Nov 2, 2025): 52cdd7c removes blockUpper2GB (it doesn't build on its own), and 4dc5993 adds the lower-2 GB blocking that replaces it. 4dc5993's message describes both halves: "Removes blockUpper2GB hack; we now start early in the process and reserve all (available) space in the lower 2GB address space, leaving the upper 2GB untouched for host code". After 4dc5993:

    • On Linux, free memory below 2 GB is covered by PROT_NONE placeholders from startup (blockLower2GB).
    • VirtualAlloc and VirtualFree go through g_mappings, a new table in the new src/heap.cpp, which wibo now uses to pick addresses and check overlaps. VirtualFree(MEM_RELEASE) puts a placeholder back instead of unmapping.
    • The NULL-base path of mapViewOfFileInternal (where wibo picks the address) moves onto g_mappings in the same commit (reserveViewRange, registerViewRange, releaseViewRange). The fixed-base path keeps MAP_FIXED_NOREPLACE, and doesn't record its views in g_mappings.

    MAP_FIXED_NOREPLACE won't replace a placeholder. So on Linux, MapViewOfFileEx with a base address below 2 GB fails with ERROR_INVALID_ADDRESS even when the range is free in g_mappings, unless an unmapped view left a gap there.

  5. macOS support (cc0a887; Nov 8, 2025): macOS has no MAP_FIXED_NOREPLACE, so the fixed-base path takes the MAP_FIXED fallback and succeeds. But that path never records its views in g_mappings, so a later VirtualAlloc can be given the same range and silently replace the view. It also goes wrong the other way: a view mapped over an existing allocation silently replaces that allocation instead of failing.

Why the issue went (partially) unnoticed, and where else it has been encountered

Every existing wibo test that maps a view lets wibo pick the address, so no test exercises the fixed-base path. It had also only worked for about a month, so little could have come to rely on it. Two other contributors did run into it, but neither of their PRs has been merged:

  • Add Xbox 360 linker support (fake mspdb PDB interface) #110, "Add Xbox 360 linker support (fake mspdb PDB interface)" (Feb 2026): it gets an Xbox 360 linker running under wibo for the Dance Central 3 decompilation. (My PR similarly came about from trying to run an Xbox 360 linker, albeit a different version; see the PR description.) Among many other changes, Add Xbox 360 linker support (fake mspdb PDB interface) #110 switches the fixed-base path to plain MAP_FIXED and records the view in g_mappings. That fixes the Linux failure and the macOS reallocation problem, but a view can still silently replace a live allocation.
  • fix: support VC6 precompiled header creation and reuse #146, "fix: support VC6 precompiled header creation and reuse" (Sept 2026): it hit the macOS problem (SIGBUS when VC6 reuses a PCH). Its fix records the view in g_mappings but keeps MAP_FIXED_NOREPLACE, so on Linux, MapViewOfFileEx with a base address below 2 GB still fails in the same way (see the table below).
Mapping above 2 GB: why it wasn't intended, and how Windows and this PR handle it

Why the fixed-base path wasn't meant to map there:

  • When 3249ebf added the fixed-base path, blockUpper2GB had filled the gaps between mappings above 2 GB, so MAP_FIXED_NOREPLACE there would almost always have failed.
  • The rest of wibo kept guest memory below 2 GB. 41f8388's VirtualAlloc unmapped and rejected any result at or above 0x80000000. Since 4dc5993, VirtualAlloc at a requested address rejects any range that doesn't fit below wibo's limit, kTwoGB (today 0x80000000 on Linux and 0x7E000000 on macOS, explained below).
  • 4dc5993 leaves the upper 2 GB "untouched for host code".
  • wibo's GetSystemInfo reports 0x7FFEFFFF as the highest application address. That's what Windows reports for a 32-bit program without IMAGE_FILE_LARGE_ADDRESS_AWARE. wibo doesn't check that flag anywhere, so it treats every program as not large-address-aware.

On current main, though, the fixed-base path has no upper limit, and since 52cdd7c and 4dc5993 nothing blocks the upper 2 GB. So that path tries to map at whatever base address it's given, and on Linux that succeeds if the host has nothing there. On macOS it's worse. wibo's own image starts at 0x7E001000, which is why kTwoGB is 0x7E000000 there. A view at or just above 0x7E000000 can overwrite wibo's image, and a view at a higher base address can overwrite other host mappings.

My agents checked what Windows does on a GitHub Actions windows-latest runner (Windows Server 2025). They ran a small 32-bit probe program, whose source is in the run's commit, and this PR's version of the existing test_createfilemapping fixture (run). For a program that isn't large-address-aware:

  • GetSystemInfo reports 0x7FFEFFFF as the highest application address.
  • MapViewOfFileEx with a base address of 0x7FFF0000, 0x80000000 or 0x90000000 fails with ERROR_INVALID_PARAMETER.
  • VirtualAlloc at 0x80000000 fails with ERROR_INVALID_ADDRESS, on Windows and in wibo.

This PR matches that: a 64 KiB-aligned base address above 0x7FFEFFFF fails with ERROR_INVALID_PARAMETER, and this PR's test test_fixed_address_view_above_2gb_fails checks it at 0x80000000. Separately, a range that doesn't fit below kTwoGB fails with ERROR_INVALID_ADDRESS. That's wibo's existing limit, the same one VirtualAlloc uses, not something we measured on Windows. On macOS it means base addresses from 0x7E000000 to 0x7FFEFFFF are refused, which Windows might allow.

Wine doesn't enforce Windows' 0x7FFEFFFF limit. It maps test_fixed_address_view_above_2gb_fails's view at 0x80000000, so that test fails under Wine. This PR notes that in a comment next to the check. Running the probe under Wine shows the same: Wine also lets VirtualAlloc allocate at 0x80000000, and maps a view at 0x90000000.

Tested revisions

The wibo builds below are 32-bit debug builds in an x86_64 Ubuntu 24.04 VM. Unless a row says otherwise, each ran test_fixed_address_view_is_not_reallocated, the first of this PR's three tests.

wibo before #124 (June 2026) didn't grow a file to the mapping size, so in old builds, writing to a view of the test's empty temp file raises SIGBUS. For the two 2025 builds (9367f00 and a59e002), my agents used a variant of that test that maps a pagefile-backed section (CreateFileMappingA(INVALID_HANDLE_VALUE, ...)) instead. It tests the same address handling.

wibo Result
9367f00 (Oct 28, 2025; two commits before 52cdd7c) No bug. The view is mapped at the chosen address, a later VirtualAlloc lands elsewhere, and the view's contents survive. One difference from what the test expects (and from Windows and Wine): VirtualAlloc at the view's address fails with ERROR_ALREADY_EXISTS, wibo's translation of the kernel's EEXIST. The kernel caught the overlap, not g_virtualAllocations.
a59e002 (Nov 3, 2025; 11 commits after 4dc5993) Fails at the step that worked before: MapViewOfFileEx at the address that was just reserved and released fails with ERROR_INVALID_ADDRESS (487). This uses a59e002 because my agents' build of 4dc5993 itself crashes even on a hello-world program. None of the commits in between touch the fixed-base path or the placeholders.
f3570ca (current main) Fails the same way.
f3570ca + #146's memoryapi.cpp change Still fails on Linux, both in this test and in #146's own test (at its view == base check).
This PR All three of this PR's tests pass, and so does #146's test.

On Windows Server 2025, the whole test_createfilemapping fixture passes (run linked above). Under Wine 9.0, the rest of the fixture passes, but test_fixed_address_view_above_2gb_fails fails.

@simonlindholm simonlindholm 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.

Right, I see, thanks for the thorough investigation!

Comment thread dll/kernel32/memoryapi.cpp Resolved
}
// Windows rejects a base past the user address range with ERROR_INVALID_PARAMETER (VirtualAlloc uses
// ERROR_INVALID_ADDRESS). Wine doesn't enforce the limit and maps the view, so this differs from Wine.
if (baseAddr > kHighestUserAddress) {

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.

while it doesn't really matter: oughtn't this check that the end of the mapping is in bounds rather than the start?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I suppose it conceptually makes sense to check the end as well. In wibo today, a view that runs past the end already fails with ERROR_INVALID_ADDRESS (the same error as on Windows), albeit for incidental reasons:

  • On Linux, wibo reserves the guest stack (the Windows program's main-thread stack) as high as it can below 2 GB, so the stack covers 0x7FFE0000.
  • On macOS, the guest range ends at 0x7E000000, so those addresses are out of range.

So checking the end changes neither whether such a view fails nor which error it gets. But to make the logic more explicit, I've gone ahead and pushed commit 559afe3, which adds an explicit check: a view that covers 0x7FFE0000 will fail with ERROR_INVALID_ADDRESS.

The new check alone would also reject every view the PR's base check does, but it would use the ERROR_INVALID_ADDRESS error code in all cases. Windows, however, uses different errors depending on whether the base itself is past the limit or only the end of the view is (run):

  • A view whose base is past 0x7FFEFFFF fails with ERROR_INVALID_PARAMETER. The base check added by this PR implements that.
  • A view whose base is in range but that runs past the end fails with ERROR_INVALID_ADDRESS instead. Every such view covers the shared user data page at 0x7FFE0000, and views that cover it fail the same way even when they end within the limit (e.g. a 128 KiB view at 0x7FFD0000). So it behaves like an ordinary overlap failure.

Thus, I've kept the base check to better match the precise error codes used by Windows.

The testing added by the PR now covers both kinds of failure, and passes on Windows (run), Linux (32- and 64-bit builds) and macOS. Under Wine it still fails at the 0x80000000 case, as before, since Wine doesn't enforce the 0x7FFEFFFF limit and successfully maps a view there instead of refusing it.

There is a remaining caveat, though: the PR's changes only cover MapViewOfFileEx. On Windows, VirtualAlloc at 0x7FFE0000 or 0x7FFF0000 also fails with ERROR_INVALID_ADDRESS. In wibo, VirtualAlloc there currently fails only because of the stack on Linux, or the 0x7E000000 limit on macOS.

A more complete fix would be to mark 0x7FFE0000–0x7FFFFFFF as taken in the guest mapping table at startup on Linux. (Only Linux needs this, since on macOS the guest range already ends below it, at 0x7E000000.) Allocations and views would then both fail there through the usual overlap check, which would make the view check added in 559afe3 redundant, so it could be removed. But the guest stack could then no longer use that range, so wibo would place the stack 128 KiB lower, entirely below 0x7FFE0000. That seemed like it might be scope-creeping the PR a bit, though, so I was planning to leave it for a follow-up PR… unless you'd prefer it here?

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.

Huh, that's funny, interesting that Windows range-checks like that. No need to follow up on that or send further PRs I think, I doubt there are any applications that rely on the exact error code.

Comment thread dll/kernel32/memoryapi.cpp Resolved
ZebulanStanphill and others added 2 commits October 31, 2026 20:26
Co-authored-by: Simon Lindholm <simon.lindholm10@gmail.com>
Windows always maps the shared user data page at 0x7FFE0000, so a view
that covers it fails with ERROR_INVALID_ADDRESS. That includes every
view whose base is at or below 0x7FFEFFFF but that runs past it. A base
past 0x7FFEFFFF instead gets ERROR_INVALID_PARAMETER, from the existing
check.

Such views already failed in practice: on Linux the guest stack is
reserved at the top of the range, and on macOS the guest range ends at
0x7E000000. With this check, that no longer matters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonlindholm
simonlindholm merged commit c6f6759 into decompals:main Nov 1, 2026
12 checks passed
@ZebulanStanphill
ZebulanStanphill deleted the fix-mapviewofex-registration branch November 2, 2026 13:11
ZebulanStanphill added a commit to ZebulanStanphill/Kinect-Sports-Decomp that referenced this pull request Nov 2, 2026
decompals/wibo#163 records views mapped at a fixed address, one of the
three fixes link.exe /LTCG needs. It landed after 1.2.0; the other two
are still to be proposed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants