Skip to content

Allocate through Wine for targets inside a Proton or Flatpak container #9

Closed

Description

@wleeaf

Since Fedora 44 moved from Wine 11.0 to Wine 11.20 (Staging), code injection into Wine processes fails (the wow64-wine CI job). The legacy Wine and Proton jobs still pass.

Cause. Wine 11.20 reserves the address space around the game's code as PROT_NONE mappings that it manages itself. For the CI fixtures (image at 0x400000), /proc/<pid>/maps shows 0074e000-7ffe0000 and 80000000-200000000 reserved in the 64-bit process, and everything below 4 GiB reserved in the 32-bit (WoW64) one. Cheat Engine places a code cave with mmap(MAP_FIXED_NOREPLACE) in a free gap within ±2 GiB of the hook, and there is none:

  • 64-bit programs: the cave lands far away and the jump back (or a RIP-relative operand in the relocated instruction) cannot reach: Relative memory destination is outside the 2 GiB range.
  • 32-bit programs: no memory below 4 GiB at all: Failed to allocate memory for newmem: Cannot allocate memory. This affects every allocation for a 32-bit program, not only code caves.

Mapping over Wine's reservation is not safe: Wine does not know about the mapping and can later hand the same range to the game.

Fix direction (spike confirmed). Let Wine allocate, as Windows Cheat Engine does: a small Windows helper run in the target's Wine prefix calls OpenProcess + VirtualAllocEx on the target. On Wine 11.20 this returned a committed PAGE_EXECUTE_READWRITE block at 0x3f0000 for both the 64-bit and the 32-bit fixture, within reach of the hook, and VirtualQueryEx reports it as allocated. Still needed:

  • a helper PE built without MinGW (like test/wine_fixture.py builds the fixtures);
  • mapping the Linux pid to the Windows process id;
  • running the helper with the target's Wine binary, prefix and environment, inside the Proton container where needed (ns_attach);
  • freeing such blocks through Wine (VirtualFreeEx), not munmap;
  • checking whether upstream Wine 11.20 reserves the same ranges or only the Staging build.

Until then the injection error names the cause, and the Wine gate records it as a known limitation when the target has no free gap near the hook.

Activity

  1. wleeaf commented on Nov 14, 2026

    @wleeaf
    OwnerAuthor

    Fixed in a76ef9a for targets in the user's own mount namespace. When Wine 11.20 leaves no free gap near the hook (or below 4 GiB for a 32-bit program), Cheat Engine now asks Wine for the memory:

    • A PE32+ helper is generated on the fly and started with the target's own Wine loader, environment and user. It calls OpenProcess + VirtualAllocEx (searching outward from the preferred address in 64 KiB steps), and VirtualFreeEx on release.
    • The Windows process id comes from a TEB (NtTib.Self at +0x30, ClientId at +0x40), cached per process.
    • Wine-owned blocks are freed through Wine from any handle.
    • When every thread of the target is stopped, Wine cannot run the request, so it fails at once with a clear reason.

    The wow64-wine CI job (Fedora 44, Wine 11.20) injects into both the 64-bit and the 32-bit fixture again, and the 32-bit allocation checks run.

    Still open: a target inside a Proton (pressure-vessel) or Flatpak container, where the helper would have to run inside the container. Proton does not reserve these ranges today, so this has no current failure. I'm narrowing this issue to that case.

  2. changed the title [-]Code injection fails under Wine 11.20: no free memory near the hook[/-] [+]Allocate through Wine for targets inside a Proton or Flatpak container[/+] on Nov 14, 2026
  3. wleeaf commented on Nov 20, 2026

    @wleeaf
    OwnerAuthor

    The container case is fixed in #14. For a game in a Proton (Steam Runtime) or Flatpak container, the helper now joins the game's namespaces and runs the container's own Wine. CI checks this with GE-Proton inside SteamLinuxRuntime_4. It's on main now and will ship in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions