ntdll: Support ISOLATIONAWARE_MANIFEST_RESOURCE_ID (#18889)

Match Windows behavior when locating and retrieving the assembly manifest from a DLL.

Following is the explanation as to how this MR is sufficient for supporting isolation-aware DLLs and fixing #18889.


From Microsoft documentation, Using Side-by-Side Assemblies as a Resource outlines the significance of each reserved manifest resource ID.

Further investigation reveals the following:

  1. CREATEPROCESS_MANIFEST_RESOURCE_ID (value: 1): This is used for process-wide initial (NULL) activation context.

  2. ISOLATIONAWARE_MANIFEST_RESOURCE_ID (value: 2): This is used to specify the assembly manifest that the loader (Ldr) uses to resolve static imports. Also, this is used by isolation-aware wrappers defined in *.inl files included in the Windows SDK (include\um) when the ISOLATION_AWARE_ENABLED macro is defined as a nonzero value.

  3. ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID (value: 3): Ignored by the loader when resolving static imports. This is used by isolation-aware API wrappers defined in *.inl files included in the Windows SDK (include\um) when the ISOLATION_AWARE_ENABLED macro is defined as a nonzero value.

    • Usage documentation: IsolationAwareCleanup function
    • Intended container module type: EXE and DLL.
    • Lifetime of the associated activation context: Alive until the application calls IsolationAwareCleanup1. Owned by the isolation-aware API wrapper library (part of the Windows SDK, rather than being a system DLL).
    • Isolation-aware: Yes.

The ISOLATION_AWARE_ENABLED macro is documented in Isolating Components as well as Specifying a Default Activation Context. When ISOLATION_AWARE_ENABLED macro is defined as a nonzero value, then the isolation-aware API wrapper library is enabled. The isolation-aware API wrapper library is responsible for:

  • Creating (lazily) and destroying activation context (in IsolationAwareCleanup), if the manifest resource ID is ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID.2
    • Note: the isolation-aware API wrapper library does not manage the activation context's lifetime and delegates the responsibility to the system loader if the manifest resource ID is ISOLATIONAWARE_MANIFEST_RESOURCE_ID.
  • Intercepting Win32 API calls for automatic activation context activation. Each API wrapper activates the "isolation-aware" activation context (obtaining one if it did not exist) before calling the original procedure, and deactivates it before returning.

The isolation-aware wrappers may be either be defined inline, or compiled into static libraries that are linked into the final application executable.

From the information above as well as the tests included in this merge request, we can infer the following:

  1. Although side-by-side awareness is a cross-cutting concern, the activation of activation contexts itself is not usually performed automatically by the system for the application (with the sole exception of process-wide activation context associated with CREATEPROCESS_MANIFEST_RESOURCE_ID, and static import resolution).
  2. ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID is treated like any other resource ID (from 0x0004 to 0xffff) as far as the loader is concerned.
  3. The resource ID of the manifest only concerns how the module containing the manifest intends to use the manifest. In fact, for DLLs that do not statically import symbols from side-by-side assemblies, the three resource IDs above are basically equivalent. A DLL can elect not to use manifest resources at all, and manage activation context and library loading by itself.

This is why I believe that this merge request is sufficient in completing the isolation-aware component support in Wine; the heavy lifting is done in the application side, not the system.

EDIT: Fix a few typos and unclear wording.


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=18889

  1. According to the documentation, the application is presumably responsible for calling IsolationAwareCleanup from DllMain on fdwReason = DLL_PROCESS_DETACH.

  2. IsolationAwareCleanup § Remarks, from Microsoft documentation.

Edited by Jinoh Kang

Merge request reports

Loading