Skip to content

fix(fspy-shm): map the Windows IPC view above Cygwin's fixed layout - #952

Merged
wan9chi merged 2 commits into
voidzero-dev:mainfrom
ReemX:fix/fspy-shm-above-msys
Nov 12, 2026
Merged

wan9chi merged 2 commits into
voidzero-dev:mainfrom
ReemX:fix/fspy-shm-above-msys

Conversation

@ReemX

@ReemX ReemX commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #830.

Cause

The injected DLL maps the whole 4 GiB IPC view during DLL_PROCESS_ATTACH, before msys-2.0.dll initializes, and lets the system pick the address. A Cygwin/MSYS2 process keeps a fixed layout (winsup/cygwin/local_includes/memory_layout.h): the executable at 0x100400000, the DLL at 0x180040000, shared regions at 0x1a0000000-0x200000000, then DLL arenas, thread stacks, the cygheap, and an mmap arena up to 0x700000000000. Up to about 4032 MiB the view still fits in the hole below the executable. A 4 GiB view doesn't, so it lands above sh.exe, over the shared regions, and msys-2.0.dll's fixed-address MapViewOfFileEx for shared.5 fails with error 487. The threshold measurements are in voidzero-dev/vite-plus#3121.

Change

ShmHandle::map on Windows now asks MapViewOfFile3 for an address at or above 0x7000_0000_0000 (Cygwin's MMAP_STORAGE_HIGH), which leaves the view clear of every range Cygwin places at a fixed address. User space goes up to 0x7FFF_FFFE_FFFF, so there is about 16 TiB of room.

  • MapViewOfFile3 is looked up in kernelbase.dll at run time, not imported, so the DLL still loads on Windows 10 before 1803 (Server 2016). There, or if the call fails, map falls back to the plain MapViewOfFile it used before.
  • Capacity is unchanged. Capping it under 4 GiB on Windows would also stop the crash, but only while the view happens to fit below the executable.

Tests

On Windows 11 (10.0.26200) with Git for Windows 2.56.0.windows.4 (bash 5.3.15):

  • New four_gib_mapping_lies_above_the_cygwin_fixed_layout checks that both the creating and the opening view land above 0x7000_0000_0000. cargo test -p fspy_shm -p fspy_nostd passes, and so does cargo clippy -p fspy_nostd -p fspy_shm --all-targets -- -D warnings.
  • End to end with vt run: a cached task (node probe.mjs) whose script spawns Git Bash's sh.exe -c, with vt cache clean before each run:
    • at b3e73102 (main), 3/3 runs fail with bash.exe: *** fatal error - MapViewOfFileEx 'shared.5'(0x12C, size 60344, m 0, created 0), Win32 error 487. Terminating.
    • with this change, 3/3 runs pass and sh prints its version.

AI-assisted (Claude Opus 5.5): I reviewed the change and ran the Windows tests above.

Reem and others added 2 commits November 12, 2026 10:15
The 4 GiB view the injected DLL maps before msys-2.0.dll starts lands on Cygwin's fixed-address shared regions, so MSYS2 programs in tracked tasks fail with Win32 error 487. Ask MapViewOfFile3 for an address at or above Cygwin's mmap arena, falling back to MapViewOfFile where it is unavailable. Fixes voidzero-dev#830.
Replace `map_view_of_file_above`, which returned `Option<Result<_>>` and
fixed read-write access and offset 0, with `get_map_view_of_file3()`
returning `Option<MapViewOfFile3>` and `MapViewOfFile3::call`, a thin
wrapper that takes protection, offset, size, and an optional lowest
address. `None` now only means the function is missing; whether to fall
back stays in `fspy_shm`. The value is `Copy`, so callers can keep it
without hidden global state in `fspy_nostd`.

Document why the lookup is loader-lock safe, use `GetCurrentProcess()`
instead of a hand-written pseudo-handle, and test the wrapper in
`fspy_nostd` against a paging-file mapping. Add the changelog entry and
describe the view placement in the `fspy_shm` README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01978g7Vcc3w5QWZTswuUsoN
@wan9chi
wan9chi force-pushed the fix/fspy-shm-above-msys branch from dd815b7 to e3b7d4c Compare November 12, 2026 02:16
@voidzero-dev voidzero-dev deleted a comment from cursor Bot Nov 12, 2026

@wan9chi wan9chi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

@wan9chi
wan9chi merged commit bd11071 into voidzero-dev:main Nov 12, 2026
20 checks passed
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.

Windows: automatic filesystem tracking makes Git/MSYS sh.exe fail with MapViewOfFileEx error 487

3 participants