- Merge from trunk up to r45543
[reactos.git] / dll / ntdll / ldr / actctx.c
1
2 #include <ntdll.h>
3 #define NDEBUG
4 #include <debug.h>
5
6 #include "wine/unicode.h"
7
8
9 /***********************************************************************
10 * create_module_activation_context
11 */
12 NTSTATUS create_module_activation_context( LDR_DATA_TABLE_ENTRY *module )
13 {
14 NTSTATUS status;
15 LDR_RESOURCE_INFO info;
16 IMAGE_RESOURCE_DATA_ENTRY *entry;
17
18 info.Type = (ULONG)RT_MANIFEST;
19 info.Name = (ULONG)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
20 info.Language = 0;
21 if (!(status = LdrFindResource_U( module->DllBase, &info, 3, &entry )))
22 {
23 ACTCTXW ctx;
24 ctx.cbSize = sizeof(ctx);
25 ctx.lpSource = NULL;
26 ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
27 ctx.hModule = module->DllBase;
28 ctx.lpResourceName = (LPCWSTR)ISOLATIONAWARE_MANIFEST_RESOURCE_ID;
29 status = RtlCreateActivationContext( &module->EntryPointActivationContext, &ctx );
30 }
31 return status;
32 }
33
34 NTSTATUS find_actctx_dll( LPCWSTR libname, WCHAR *fullname )
35 {
36 static const WCHAR winsxsW[] = {'\\','w','i','n','s','x','s','\\',0};
37 /* FIXME: Handle modules that have a private manifest file
38 static const WCHAR dotManifestW[] = {'.','m','a','n','i','f','e','s','t',0}; */
39
40 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *info;
41 ACTCTX_SECTION_KEYED_DATA data;
42 UNICODE_STRING nameW;
43 NTSTATUS status;
44 SIZE_T needed, size = 1024;
45
46 RtlInitUnicodeString( &nameW, libname );
47 data.cbSize = sizeof(data);
48 status = RtlFindActivationContextSectionString( FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX, NULL,
49 ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
50 &nameW, &data );
51 if (status != STATUS_SUCCESS) return status;
52
53 for (;;)
54 {
55 if (!(info = RtlAllocateHeap( RtlGetProcessHeap(), 0, size )))
56 {
57 status = STATUS_NO_MEMORY;
58 goto done;
59 }
60 status = RtlQueryInformationActivationContext( 0, data.hActCtx, &data.ulAssemblyRosterIndex,
61 AssemblyDetailedInformationInActivationContext,
62 info, size, &needed );
63 if (status == STATUS_SUCCESS) break;
64 if (status != STATUS_BUFFER_TOO_SMALL) goto done;
65 RtlFreeHeap( RtlGetProcessHeap(), 0, info );
66 size = needed;
67 }
68
69 DPRINT("manafestpath === %S\n", info->lpAssemblyManifestPath);
70 DPRINT("DirectoryName === %S\n", info->lpAssemblyDirectoryName);
71 if (!info->lpAssemblyManifestPath || !info->lpAssemblyDirectoryName)
72 {
73 status = STATUS_SXS_KEY_NOT_FOUND;
74 goto done;
75 }
76
77 DPRINT("%S. %S\n", info->lpAssemblyManifestPath, info->lpAssemblyDirectoryName);
78 wcscpy(fullname , SharedUserData->NtSystemRoot);
79 wcscat(fullname, winsxsW);
80 wcscat(fullname, info->lpAssemblyDirectoryName);
81 wcscat(fullname, L"\\");
82 wcscat(fullname, libname);
83 DPRINT("Successfully found a side by side %S\n", fullname);
84 status = STATUS_SUCCESS;
85
86 done:
87 RtlFreeHeap( RtlGetProcessHeap(), 0, info );
88 RtlReleaseActivationContext( data.hActCtx );
89 DPRINT("%S\n", fullname);
90 return status;
91 }