Skip to content

Windows 11 emulation issue and possible fix #1594

@uintmax

Description

@uintmax

Problem

On Windows 11, the dev branch currently fails to emulate PE binaries compiled with MSVC. It makes a call to abort() before reaching the program's main function.
The master branch does not have this problem yet, because a change has only been made recently. This commit improved Windows emulation by executing the _initterm_e export of ucrtbase.dll. Unfortunately, Windows 11 made some breaking changes in ucrtbase.dll, which causes the early program termination now.

Fix

This problem can be easily fixed by adding kernel32.dll to the key_dlls tuple.

Reason:
_initterm_e gets supplied a pointer to a function which eventually checks for a FLS index stored in the .data section. This however fails, because FlsAlloc has never been called for this index. The main function of ucrtbase.dll would usually make this call to FlsAlloc. However, we never reach that call, because ucrtbase.dll bails out early. This is due to a call to VerifyVersionInfoW, which can not be resolved, because it gets imported via the virtual DLL api-ms-win-core-kernel32-legacy-l1-1-1.dll. The key_dlls tuple responsible for resolving these kinds of imports does not include kernel32.dll yet. This results in the existing hook also not to be called.

Adding kernel32.dll to the key_dlls before kernelbase.dll and ntdll.dll would fix the problem. All Windows and PE tests would work correctly again.
I am however not sure if that's the best solution, considering that just one import needs kernel32.dll for now. On the other hand it may make it more future-proof.

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