Patching 32-bit Windows executables for allocating memory beyond 2GB

A lot of modern Windows games built for 32-bit are memory bound at times. Depending on the game, that can affect Wine more than native Windows. Final Fantasy XIV would crash by running out of the 2GB space on my system under Wine, for example. To work around this it can be useful to load the process with the LARGE_ADDRESS_AWARE flag. Enabling that flag will let the application allocate memory beyond the 2GB boundary a 32-bit Win32 application is limited to (Windows divides its memory into lower 2GB userspace and upper 2GB kernel ranges). That flag is set on linking time when building the executable and official Wine builds respect the flag.

There's a couple ways to force enabling it. You could patch Wine's loader to enable the flag for every 32-bit application but that would break some of them due to assumptions about the size of process address space. The other option is to patch the flag into the executable, letting you use a common build of Wine with applications that do not work with the LARGE_ADDRESS_AWARE flag.

I wrote this Python port of a C# Stack Overflow solution to patching the flag in. Turns out that patching FFXIV doesn't actually work because the game refuses to connect with the modified executable, but maybe it'll be useful to someone trying to run a different game in unmodified Wine.

The solution for FFXIV was to use Andrew Church's patch to add an environment variable, WINEFORCELARGEADDRESSAWARE, to enable the flag without modifying the executable.

Comments