From 4156a716b01c0ebd8ac7dba11806d574fa2eb7f6 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 25 Jul 2007 16:50:32 +0200 Subject: [PATCH] ntdll: Create the per-module activation context at module load time. --- dlls/ntdll/loader.c | 33 +++++++++++++++++++++++++++++++++ include/winternl.h | 1 + 2 files changed, 34 insertions(+) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 207d39156ee..700b6732ee2 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -48,6 +48,10 @@ WINE_DECLARE_DEBUG_CHANNEL(snoop); WINE_DECLARE_DEBUG_CHANNEL(loaddll); WINE_DECLARE_DEBUG_CHANNEL(imports); +/* we don't want to include winuser.h */ +#define RT_MANIFEST ((ULONG_PTR)24) +#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID ((ULONG_PTR)2) + typedef DWORD (CALLBACK *DLLENTRYPROC)(HMODULE,DWORD,LPVOID); static int process_detaching = 0; /* set on process detach to avoid deadlocks with thread detach */ @@ -578,6 +582,32 @@ done: } +/*********************************************************************** + * create_module_activation_context + */ +static NTSTATUS create_module_activation_context( LDR_MODULE *module ) +{ + NTSTATUS status; + LDR_RESOURCE_INFO info; + const IMAGE_RESOURCE_DATA_ENTRY *entry; + + info.Type = RT_MANIFEST; + info.Name = ISOLATIONAWARE_MANIFEST_RESOURCE_ID; + info.Language = 0; + if (!(status = LdrFindResource_U( module->BaseAddress, &info, 3, &entry ))) + { + ACTCTXW ctx; + ctx.cbSize = sizeof(ctx); + ctx.lpSource = NULL; + ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID; + ctx.hModule = module->BaseAddress; + ctx.lpResourceName = (LPCWSTR)ISOLATIONAWARE_MANIFEST_RESOURCE_ID; + status = RtlCreateActivationContext( &module->ActivationContext, &ctx ); + } + return status; +} + + /**************************************************************** * fixup_imports * @@ -594,6 +624,7 @@ static NTSTATUS fixup_imports( WINE_MODREF *wm, LPCWSTR load_path ) if (!(wm->ldr.Flags & LDR_DONT_RESOLVE_REFS)) return STATUS_SUCCESS; /* already done */ wm->ldr.Flags &= ~LDR_DONT_RESOLVE_REFS; + create_module_activation_context( &wm->ldr ); if (!(imports = RtlImageDirectoryEntryToData( wm->ldr.BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &size ))) @@ -651,6 +682,7 @@ static WINE_MODREF *alloc_module( HMODULE hModule, LPCWSTR filename ) wm->ldr.SectionHandle = NULL; wm->ldr.CheckSum = 0; wm->ldr.TimeDateStamp = 0; + wm->ldr.ActivationContext = 0; RtlCreateUnicodeString( &wm->ldr.FullDllName, filename ); if ((p = strrchrW( wm->ldr.FullDllName.Buffer, '\\' ))) p++; @@ -1983,6 +2015,7 @@ static void free_modref( WINE_MODREF *wm ) } SERVER_END_REQ; + RtlReleaseActivationContext( wm->ldr.ActivationContext ); NtUnmapViewOfSection( NtCurrentProcess(), wm->ldr.BaseAddress ); if (wm->ldr.Flags & LDR_WINE_INTERNAL) wine_dll_unload( wm->ldr.SectionHandle ); if (cached_modref == wm) cached_modref = NULL; diff --git a/include/winternl.h b/include/winternl.h index bd9508f08ef..372e4d4db9b 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2357,6 +2357,7 @@ typedef struct _LDR_MODULE HANDLE SectionHandle; ULONG CheckSum; ULONG TimeDateStamp; + HANDLE ActivationContext; } LDR_MODULE, *PLDR_MODULE; /* those defines are (some of the) regular LDR_MODULE.Flags values */