[RTL]
[reactos.git] / reactos / lib / rtl / actctx.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Runtime Library
4 * PURPOSE: Activation Context Support
5 * FILE: lib/rtl/actctx.c
6 * PROGRAMERS:
7 * Jon Griffiths
8 * Eric Pouech
9 * Jacek Caban for CodeWeavers
10 * Alexandre Julliard
11 * Stefan Ginsberg (stefan__100__@hotmail.com)
12 * Samuel SerapiĆ³n
13 */
14
15 /* Based on Wine 1.1.26 */
16
17 /* INCLUDES *****************************************************************/
18 #include <rtl.h>
19
20 #define NDEBUG
21 #include <debug.h>
22
23 #include <wine/unicode.h>
24
25 BOOLEAN RtlpNotAllowingMultipleActivation;
26
27 #define ACTCTX_FLAGS_ALL (\
28 ACTCTX_FLAG_PROCESSOR_ARCHITECTURE_VALID |\
29 ACTCTX_FLAG_LANGID_VALID |\
30 ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID |\
31 ACTCTX_FLAG_RESOURCE_NAME_VALID |\
32 ACTCTX_FLAG_SET_PROCESS_DEFAULT |\
33 ACTCTX_FLAG_APPLICATION_NAME_VALID |\
34 ACTCTX_FLAG_SOURCE_IS_ASSEMBLYREF |\
35 ACTCTX_FLAG_HMODULE_VALID )
36
37 #define ACTCTX_MAGIC 0xC07E3E11
38
39 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
40 #define ACTCTX_FAKE_COOKIE ((ULONG_PTR) 0xf00bad)
41
42
43
44 typedef struct
45 {
46 const WCHAR *ptr;
47 unsigned int len;
48 } xmlstr_t;
49
50 typedef struct
51 {
52 const WCHAR *ptr;
53 const WCHAR *end;
54 } xmlbuf_t;
55
56 struct file_info
57 {
58 ULONG type;
59 WCHAR *info;
60 };
61
62 struct assembly_version
63 {
64 USHORT major;
65 USHORT minor;
66 USHORT build;
67 USHORT revision;
68 };
69
70 struct assembly_identity
71 {
72 WCHAR *name;
73 WCHAR *arch;
74 WCHAR *public_key;
75 WCHAR *language;
76 WCHAR *type;
77 struct assembly_version version;
78 BOOL optional;
79 };
80
81 struct entity
82 {
83 DWORD kind;
84 union
85 {
86 struct
87 {
88 WCHAR *tlbid;
89 WCHAR *version;
90 WCHAR *helpdir;
91 } typelib;
92 struct
93 {
94 WCHAR *clsid;
95 } comclass;
96 struct {
97 WCHAR *iid;
98 WCHAR *name;
99 } proxy;
100 struct
101 {
102 WCHAR *name;
103 } class;
104 struct
105 {
106 WCHAR *name;
107 WCHAR *clsid;
108 } clrclass;
109 struct
110 {
111 WCHAR *name;
112 WCHAR *clsid;
113 } clrsurrogate;
114 } u;
115 };
116
117 struct entity_array
118 {
119 struct entity *base;
120 unsigned int num;
121 unsigned int allocated;
122 };
123
124 struct dll_redirect
125 {
126 WCHAR *name;
127 WCHAR *hash;
128 struct entity_array entities;
129 };
130
131 enum assembly_type
132 {
133 APPLICATION_MANIFEST,
134 ASSEMBLY_MANIFEST,
135 ASSEMBLY_SHARED_MANIFEST,
136 };
137
138 struct assembly
139 {
140 enum assembly_type type;
141 struct assembly_identity id;
142 struct file_info manifest;
143 WCHAR *directory;
144 BOOL no_inherit;
145 struct dll_redirect *dlls;
146 unsigned int num_dlls;
147 unsigned int allocated_dlls;
148 struct entity_array entities;
149 };
150
151 typedef struct _ACTIVATION_CONTEXT
152 {
153 ULONG magic;
154 long ref_count;
155 struct file_info config;
156 struct file_info appdir;
157 struct assembly *assemblies;
158 unsigned int num_assemblies;
159 unsigned int allocated_assemblies;
160 } ACTIVATION_CONTEXT;
161
162 struct actctx_loader
163 {
164 ACTIVATION_CONTEXT *actctx;
165 struct assembly_identity *dependencies;
166 unsigned int num_dependencies;
167 unsigned int allocated_dependencies;
168 };
169
170 static const WCHAR assemblyW[] = {'a','s','s','e','m','b','l','y',0};
171 static const WCHAR assemblyIdentityW[] = {'a','s','s','e','m','b','l','y','I','d','e','n','t','i','t','y',0};
172 static const WCHAR bindingRedirectW[] = {'b','i','n','d','i','n','g','R','e','d','i','r','e','c','t',0};
173 static const WCHAR clrClassW[] = {'c','l','r','C','l','a','s','s',0};
174 static const WCHAR clrSurrogateW[] = {'c','l','r','S','u','r','r','o','g','a','t','e',0};
175 static const WCHAR comClassW[] = {'c','o','m','C','l','a','s','s',0};
176 static const WCHAR comInterfaceExternalProxyStubW[] = {'c','o','m','I','n','t','e','r','f','a','c','e','E','x','t','e','r','n','a','l','P','r','o','x','y','S','t','u','b',0};
177 static const WCHAR comInterfaceProxyStubW[] = {'c','o','m','I','n','t','e','r','f','a','c','e','P','r','o','x','y','S','t','u','b',0};
178 static const WCHAR dependencyW[] = {'d','e','p','e','n','d','e','n','c','y',0};
179 static const WCHAR dependentAssemblyW[] = {'d','e','p','e','n','d','e','n','t','A','s','s','e','m','b','l','y',0};
180 static const WCHAR descriptionW[] = {'d','e','s','c','r','i','p','t','i','o','n',0};
181 static const WCHAR fileW[] = {'f','i','l','e',0};
182 static const WCHAR asmv2hashW[] = {'a','s','m','v','2',':','h','a','s','h',0};
183 static const WCHAR noInheritW[] = {'n','o','I','n','h','e','r','i','t',0};
184 static const WCHAR noInheritableW[] = {'n','o','I','n','h','e','r','i','t','a','b','l','e',0};
185 static const WCHAR typelibW[] = {'t','y','p','e','l','i','b',0};
186 static const WCHAR windowClassW[] = {'w','i','n','d','o','w','C','l','a','s','s',0};
187
188 static const WCHAR clsidW[] = {'c','l','s','i','d',0};
189 static const WCHAR hashW[] = {'h','a','s','h',0};
190 static const WCHAR hashalgW[] = {'h','a','s','h','a','l','g',0};
191 static const WCHAR helpdirW[] = {'h','e','l','p','d','i','r',0};
192 static const WCHAR iidW[] = {'i','i','d',0};
193 static const WCHAR languageW[] = {'l','a','n','g','u','a','g','e',0};
194 static const WCHAR manifestVersionW[] = {'m','a','n','i','f','e','s','t','V','e','r','s','i','o','n',0};
195 static const WCHAR g_nameW[] = {'n','a','m','e',0};
196 static const WCHAR newVersionW[] = {'n','e','w','V','e','r','s','i','o','n',0};
197 static const WCHAR oldVersionW[] = {'o','l','d','V','e','r','s','i','o','n',0};
198 static const WCHAR optionalW[] = {'o','p','t','i','o','n','a','l',0};
199 static const WCHAR processorArchitectureW[] = {'p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e',0};
200 static const WCHAR publicKeyTokenW[] = {'p','u','b','l','i','c','K','e','y','T','o','k','e','n',0};
201 static const WCHAR tlbidW[] = {'t','l','b','i','d',0};
202 static const WCHAR typeW[] = {'t','y','p','e',0};
203 static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0};
204 static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
205
206 static const WCHAR g_xmlW[] = {'?','x','m','l',0};
207 static const WCHAR manifestv1W[] = {'u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','a','s','m','.','v','1',0};
208 static const WCHAR manifestv3W[] = {'u','r','n',':','s','c','h','e','m','a','s','-','m','i','c','r','o','s','o','f','t','-','c','o','m',':','a','s','m','.','v','3',0};
209
210 static const WCHAR dotManifestW[] = {'.','m','a','n','i','f','e','s','t',0};
211 static const WCHAR version_formatW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
212
213 static ACTIVATION_CONTEXT system_actctx = { ACTCTX_MAGIC, 1 };
214 static ACTIVATION_CONTEXT *process_actctx = &system_actctx;
215
216 static WCHAR *strdupW(const WCHAR* str)
217 {
218 WCHAR* ptr;
219
220 if (!(ptr = RtlAllocateHeap(RtlGetProcessHeap(), 0, (strlenW(str) + 1) * sizeof(WCHAR))))
221 return NULL;
222 return strcpyW(ptr, str);
223 }
224
225 static WCHAR *xmlstrdupW(const xmlstr_t* str)
226 {
227 WCHAR *strW;
228
229 if ((strW = RtlAllocateHeap(RtlGetProcessHeap(), 0, (str->len + 1) * sizeof(WCHAR))))
230 {
231 memcpy( strW, str->ptr, str->len * sizeof(WCHAR) );
232 strW[str->len] = 0;
233 }
234 return strW;
235 }
236
237 static UNICODE_STRING xmlstr2unicode(const xmlstr_t *xmlstr)
238 {
239 UNICODE_STRING res;
240
241 res.Buffer = (PWSTR)xmlstr->ptr;
242 res.Length = res.MaximumLength = (USHORT)xmlstr->len * sizeof(WCHAR);
243
244 return res;
245 }
246
247 static inline BOOL xmlstr_cmp(const xmlstr_t* xmlstr, const WCHAR *str)
248 {
249 return !strncmpW(xmlstr->ptr, str, xmlstr->len) && !str[xmlstr->len];
250 }
251
252 static inline BOOL xmlstr_cmpi(const xmlstr_t* xmlstr, const WCHAR *str)
253 {
254 return !strncmpiW(xmlstr->ptr, str, xmlstr->len) && !str[xmlstr->len];
255 }
256
257 static inline BOOL xmlstr_cmp_end(const xmlstr_t* xmlstr, const WCHAR *str)
258 {
259 return (xmlstr->len && xmlstr->ptr[0] == '/' &&
260 !strncmpW(xmlstr->ptr + 1, str, xmlstr->len - 1) && !str[xmlstr->len - 1]);
261 }
262
263 static inline BOOL isxmlspace( WCHAR ch )
264 {
265 return (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t');
266 }
267
268 static struct assembly *add_assembly(ACTIVATION_CONTEXT *actctx, enum assembly_type at)
269 {
270 struct assembly *assembly;
271
272 if (actctx->num_assemblies == actctx->allocated_assemblies)
273 {
274 void *ptr;
275 unsigned int new_count;
276 if (actctx->assemblies)
277 {
278 new_count = actctx->allocated_assemblies * 2;
279 ptr = RtlReAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY,
280 actctx->assemblies, new_count * sizeof(*assembly) );
281 }
282 else
283 {
284 new_count = 4;
285 ptr = RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY, new_count * sizeof(*assembly) );
286 }
287 if (!ptr) return NULL;
288 actctx->assemblies = ptr;
289 actctx->allocated_assemblies = new_count;
290 }
291
292 assembly = &actctx->assemblies[actctx->num_assemblies++];
293 assembly->type = at;
294 return assembly;
295 }
296
297 static struct dll_redirect* add_dll_redirect(struct assembly* assembly)
298 {
299 if (assembly->num_dlls == assembly->allocated_dlls)
300 {
301 void *ptr;
302 unsigned int new_count;
303 if (assembly->dlls)
304 {
305 new_count = assembly->allocated_dlls * 2;
306 ptr = RtlReAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY,
307 assembly->dlls, new_count * sizeof(*assembly->dlls) );
308 }
309 else
310 {
311 new_count = 4;
312 ptr = RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY, new_count * sizeof(*assembly->dlls) );
313 }
314 if (!ptr) return NULL;
315 assembly->dlls = ptr;
316 assembly->allocated_dlls = new_count;
317 }
318 return &assembly->dlls[assembly->num_dlls++];
319 }
320
321 static void free_assembly_identity(struct assembly_identity *ai)
322 {
323 RtlFreeHeap( RtlGetProcessHeap(), 0, ai->name );
324 RtlFreeHeap( RtlGetProcessHeap(), 0, ai->arch );
325 RtlFreeHeap( RtlGetProcessHeap(), 0, ai->public_key );
326 RtlFreeHeap( RtlGetProcessHeap(), 0, ai->language );
327 RtlFreeHeap( RtlGetProcessHeap(), 0, ai->type );
328 }
329
330 static struct entity* add_entity(struct entity_array *array, DWORD kind)
331 {
332 struct entity* entity;
333
334 if (array->num == array->allocated)
335 {
336 void *ptr;
337 unsigned int new_count;
338 if (array->base)
339 {
340 new_count = array->allocated * 2;
341 ptr = RtlReAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY,
342 array->base, new_count * sizeof(*array->base) );
343 }
344 else
345 {
346 new_count = 4;
347 ptr = RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY, new_count * sizeof(*array->base) );
348 }
349 if (!ptr) return NULL;
350 array->base = ptr;
351 array->allocated = new_count;
352 }
353 entity = &array->base[array->num++];
354 entity->kind = kind;
355 return entity;
356 }
357
358 static void free_entity_array(struct entity_array *array)
359 {
360 unsigned int i;
361 for (i = 0; i < array->num; i++)
362 {
363 struct entity *entity = &array->base[i];
364 switch (entity->kind)
365 {
366 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION:
367 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.comclass.clsid);
368 break;
369 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION:
370 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.proxy.iid);
371 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.proxy.name);
372 break;
373 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION:
374 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.typelib.tlbid);
375 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.typelib.version);
376 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.typelib.helpdir);
377 break;
378 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION:
379 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.class.name);
380 break;
381 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION:
382 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.clrclass.name);
383 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.clrclass.clsid);
384 break;
385 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES:
386 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.clrsurrogate.name);
387 RtlFreeHeap(RtlGetProcessHeap(), 0, entity->u.clrsurrogate.clsid);
388 break;
389 default:
390 DPRINT1("Unknown entity kind %d\n", entity->kind);
391 }
392 }
393 RtlFreeHeap( RtlGetProcessHeap(), 0, array->base );
394 }
395
396 static BOOL is_matching_string( const WCHAR *str1, const WCHAR *str2 )
397 {
398 if (!str1) return !str2;
399 return str2 && !strcmpiW( str1, str2 );
400 }
401
402 static BOOL is_matching_identity( const struct assembly_identity *id1,
403 const struct assembly_identity *id2 )
404 {
405 if (!is_matching_string( id1->name, id2->name )) return FALSE;
406 if (!is_matching_string( id1->arch, id2->arch )) return FALSE;
407 if (!is_matching_string( id1->public_key, id2->public_key )) return FALSE;
408
409 if (id1->language && id2->language && strcmpiW( id1->language, id2->language ))
410 {
411 static const WCHAR wildcardW[] = {'*',0};
412 if (strcmpW( wildcardW, id1->language ) && strcmpW( wildcardW, id2->language ))
413 return FALSE;
414 }
415 if (id1->version.major != id2->version.major) return FALSE;
416 if (id1->version.minor != id2->version.minor) return FALSE;
417 if (id1->version.build > id2->version.build) return FALSE;
418 if (id1->version.build == id2->version.build &&
419 id1->version.revision > id2->version.revision) return FALSE;
420 return TRUE;
421 }
422
423 static BOOL add_dependent_assembly_id(struct actctx_loader* acl,
424 struct assembly_identity* ai)
425 {
426 unsigned int i;
427
428 /* check if we already have that assembly */
429
430 for (i = 0; i < acl->actctx->num_assemblies; i++)
431 if (is_matching_identity( ai, &acl->actctx->assemblies[i].id ))
432 {
433 DPRINT( "reusing existing assembly for %S arch %S version %u.%u.%u.%u\n",
434 ai->name, ai->arch, ai->version.major, ai->version.minor,
435 ai->version.build, ai->version.revision );
436 return TRUE;
437 }
438
439 for (i = 0; i < acl->num_dependencies; i++)
440 if (is_matching_identity( ai, &acl->dependencies[i] ))
441 {
442 DPRINT( "reusing existing dependency for %S arch %S version %u.%u.%u.%u\n",
443 ai->name, ai->arch, ai->version.major, ai->version.minor,
444 ai->version.build, ai->version.revision );
445 return TRUE;
446 }
447
448 if (acl->num_dependencies == acl->allocated_dependencies)
449 {
450 void *ptr;
451 unsigned int new_count;
452 if (acl->dependencies)
453 {
454 new_count = acl->allocated_dependencies * 2;
455 ptr = RtlReAllocateHeap(RtlGetProcessHeap(), 0, acl->dependencies,
456 new_count * sizeof(acl->dependencies[0]));
457 }
458 else
459 {
460 new_count = 4;
461 ptr = RtlAllocateHeap(RtlGetProcessHeap(), 0, new_count * sizeof(acl->dependencies[0]));
462 }
463 if (!ptr) return FALSE;
464 acl->dependencies = ptr;
465 acl->allocated_dependencies = new_count;
466 }
467 acl->dependencies[acl->num_dependencies++] = *ai;
468
469 return TRUE;
470 }
471
472 static void free_depend_manifests(struct actctx_loader* acl)
473 {
474 unsigned int i;
475 for (i = 0; i < acl->num_dependencies; i++)
476 free_assembly_identity(&acl->dependencies[i]);
477 RtlFreeHeap(RtlGetProcessHeap(), 0, acl->dependencies);
478 }
479
480 static WCHAR *build_assembly_dir(struct assembly_identity* ai)
481 {
482 static const WCHAR undW[] = {'_',0};
483 static const WCHAR noneW[] = {'n','o','n','e',0};
484 static const WCHAR mskeyW[] = {'d','e','a','d','b','e','e','f',0};
485
486 const WCHAR *arch = ai->arch ? ai->arch : noneW;
487 const WCHAR *key = ai->public_key ? ai->public_key : noneW;
488 const WCHAR *lang = ai->language ? ai->language : noneW;
489 const WCHAR *name = ai->name ? ai->name : noneW;
490 SIZE_T size = (strlenW(arch) + 1 + strlenW(name) + 1 + strlenW(key) + 24 + 1 +
491 strlenW(lang) + 1) * sizeof(WCHAR) + sizeof(mskeyW);
492 WCHAR *ret;
493
494 if (!(ret = RtlAllocateHeap( RtlGetProcessHeap(), 0, size ))) return NULL;
495
496 strcpyW( ret, arch );
497 strcatW( ret, undW );
498 strcatW( ret, name );
499 strcatW( ret, undW );
500 strcatW( ret, key );
501 strcatW( ret, undW );
502 sprintfW( ret + strlenW(ret), version_formatW,
503 ai->version.major, ai->version.minor, ai->version.build, ai->version.revision );
504 strcatW( ret, undW );
505 strcatW( ret, lang );
506 strcatW( ret, undW );
507 strcatW( ret, mskeyW );
508 return ret;
509 }
510
511 static inline void append_string( WCHAR *buffer, const WCHAR *prefix, const WCHAR *str )
512 {
513 WCHAR *p = buffer;
514
515 if (!str) return;
516 strcatW( buffer, prefix );
517 p += strlenW(p);
518 *p++ = '"';
519 strcpyW( p, str );
520 p += strlenW(p);
521 *p++ = '"';
522 *p = 0;
523 }
524
525 static WCHAR *build_assembly_id( const struct assembly_identity *ai )
526 {
527 static const WCHAR archW[] =
528 {',','p','r','o','c','e','s','s','o','r','A','r','c','h','i','t','e','c','t','u','r','e','=',0};
529 static const WCHAR public_keyW[] =
530 {',','p','u','b','l','i','c','K','e','y','T','o','k','e','n','=',0};
531
532 WCHAR version[64], *ret;
533 SIZE_T size = 0;
534
535 sprintfW( version, version_formatW,
536 ai->version.major, ai->version.minor, ai->version.build, ai->version.revision );
537 if (ai->name) size += strlenW(ai->name);
538 if (ai->arch) size += strlenW(archW) + strlenW(ai->arch) + 2;
539 if (ai->public_key) size += strlenW(public_keyW) + strlenW(ai->public_key) + 2;
540 if (ai->type) size += 1 + strlenW(typeW) + 1 + strlenW(ai->type) + 2;
541 size += 1+ strlenW(versionW) + 1 + strlenW(version) + 2;
542
543 if (!(ret = RtlAllocateHeap( RtlGetProcessHeap(), 0, (size + 1) * sizeof(WCHAR) )))
544 return NULL;
545
546 if (ai->name) strcpyW( ret, ai->name );
547 else *ret = 0;
548 append_string( ret, archW, ai->arch );
549 append_string( ret, public_keyW, ai->public_key );
550 append_string( ret, typeW, ai->type );
551 append_string( ret, versionW, version );
552 return ret;
553 }
554
555 static ACTIVATION_CONTEXT *check_actctx( HANDLE h )
556 {
557 ACTIVATION_CONTEXT *ret = NULL, *actctx = h;
558
559 if (!h || h == INVALID_HANDLE_VALUE) return NULL;
560 _SEH2_TRY
561 {
562 if (actctx && actctx->magic == ACTCTX_MAGIC) ret = actctx;
563 }
564 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
565 {
566 DPRINT1("Invalid activation context handle!\n");
567 }
568 _SEH2_END;
569 return ret;
570 }
571
572 static inline void actctx_addref( ACTIVATION_CONTEXT *actctx )
573 {
574 InterlockedExchangeAdd( &actctx->ref_count, 1 );
575 }
576
577 static void actctx_release( ACTIVATION_CONTEXT *actctx )
578 {
579 if (InterlockedExchangeAdd( &actctx->ref_count, -1 ) == 1)
580 {
581 unsigned int i, j;
582
583 for (i = 0; i < actctx->num_assemblies; i++)
584 {
585 struct assembly *assembly = &actctx->assemblies[i];
586 for (j = 0; j < assembly->num_dlls; j++)
587 {
588 struct dll_redirect *dll = &assembly->dlls[j];
589 free_entity_array( &dll->entities );
590 RtlFreeHeap( RtlGetProcessHeap(), 0, dll->name );
591 RtlFreeHeap( RtlGetProcessHeap(), 0, dll->hash );
592 }
593 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly->dlls );
594 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly->manifest.info );
595 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly->directory );
596 free_entity_array( &assembly->entities );
597 free_assembly_identity(&assembly->id);
598 }
599 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx->config.info );
600 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx->appdir.info );
601 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx->assemblies );
602 actctx->magic = 0;
603 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx );
604 }
605 }
606
607 static BOOL next_xml_attr(xmlbuf_t* xmlbuf, xmlstr_t* name, xmlstr_t* value,
608 BOOL* error, BOOL* end)
609 {
610 const WCHAR* ptr;
611
612 *error = TRUE;
613
614 while (xmlbuf->ptr < xmlbuf->end && isxmlspace(*xmlbuf->ptr))
615 xmlbuf->ptr++;
616
617 if (xmlbuf->ptr == xmlbuf->end) return FALSE;
618
619 if (*xmlbuf->ptr == '/')
620 {
621 xmlbuf->ptr++;
622 if (xmlbuf->ptr == xmlbuf->end || *xmlbuf->ptr != '>')
623 return FALSE;
624
625 xmlbuf->ptr++;
626 *end = TRUE;
627 *error = FALSE;
628 return FALSE;
629 }
630
631 if (*xmlbuf->ptr == '>')
632 {
633 xmlbuf->ptr++;
634 *error = FALSE;
635 return FALSE;
636 }
637
638 ptr = xmlbuf->ptr;
639 while (ptr < xmlbuf->end && *ptr != '=' && *ptr != '>' && !isxmlspace(*ptr)) ptr++;
640
641 if (ptr == xmlbuf->end || *ptr != '=') return FALSE;
642
643 name->ptr = xmlbuf->ptr;
644 name->len = (ULONG)(ptr - xmlbuf->ptr);
645 xmlbuf->ptr = ptr;
646
647 ptr++;
648 if (ptr == xmlbuf->end || (*ptr != '"' && *ptr != '\'')) return FALSE;
649
650 value->ptr = ++ptr;
651 if (ptr == xmlbuf->end) return FALSE;
652
653 ptr = memchrW(ptr, ptr[-1], xmlbuf->end - ptr);
654 if (!ptr)
655 {
656 xmlbuf->ptr = xmlbuf->end;
657 return FALSE;
658 }
659
660 value->len = (ULONG)(ptr - value->ptr);
661 xmlbuf->ptr = ptr + 1;
662
663 if (xmlbuf->ptr == xmlbuf->end) return FALSE;
664
665 *error = FALSE;
666 return TRUE;
667 }
668
669 static BOOL next_xml_elem(xmlbuf_t* xmlbuf, xmlstr_t* elem)
670 {
671 const WCHAR* ptr;
672
673 for (;;)
674 {
675 ptr = memchrW(xmlbuf->ptr, '<', xmlbuf->end - xmlbuf->ptr);
676 if (!ptr)
677 {
678 xmlbuf->ptr = xmlbuf->end;
679 return FALSE;
680 }
681 ptr++;
682 if (ptr + 3 < xmlbuf->end && ptr[0] == '!' && ptr[1] == '-' && ptr[2] == '-') /* skip comment */
683 {
684 for (ptr += 3; ptr + 3 <= xmlbuf->end; ptr++)
685 if (ptr[0] == '-' && ptr[1] == '-' && ptr[2] == '>') break;
686
687 if (ptr + 3 > xmlbuf->end)
688 {
689 xmlbuf->ptr = xmlbuf->end;
690 return FALSE;
691 }
692 xmlbuf->ptr = ptr + 3;
693 }
694 else break;
695 }
696
697 xmlbuf->ptr = ptr;
698 while (ptr < xmlbuf->end && !isxmlspace(*ptr) && *ptr != '>' && (*ptr != '/' || ptr == xmlbuf->ptr))
699 ptr++;
700
701 elem->ptr = xmlbuf->ptr;
702 elem->len = (ULONG)(ptr - xmlbuf->ptr);
703 xmlbuf->ptr = ptr;
704 return xmlbuf->ptr != xmlbuf->end;
705 }
706
707 static BOOL parse_xml_header(xmlbuf_t* xmlbuf)
708 {
709 /* FIXME: parse attributes */
710 const WCHAR *ptr;
711
712 for (ptr = xmlbuf->ptr; ptr < xmlbuf->end - 1; ptr++)
713 {
714 if (ptr[0] == '?' && ptr[1] == '>')
715 {
716 xmlbuf->ptr = ptr + 2;
717 return TRUE;
718 }
719 }
720 return FALSE;
721 }
722
723 static BOOL parse_text_content(xmlbuf_t* xmlbuf, xmlstr_t* content)
724 {
725 const WCHAR *ptr = memchrW(xmlbuf->ptr, '<', xmlbuf->end - xmlbuf->ptr);
726
727 if (!ptr) return FALSE;
728
729 content->ptr = xmlbuf->ptr;
730 content->len = (ULONG)(ptr - xmlbuf->ptr);
731 xmlbuf->ptr = ptr;
732
733 return TRUE;
734 }
735
736 static BOOL parse_version(const xmlstr_t *str, struct assembly_version *version)
737 {
738 unsigned int ver[4];
739 unsigned int pos;
740 const WCHAR *curr;
741 UNICODE_STRING strU;
742
743 /* major.minor.build.revision */
744 ver[0] = ver[1] = ver[2] = ver[3] = pos = 0;
745 for (curr = str->ptr; curr < str->ptr + str->len; curr++)
746 {
747 if (*curr >= '0' && *curr <= '9')
748 {
749 ver[pos] = ver[pos] * 10 + *curr - '0';
750 if (ver[pos] >= 0x10000) goto error;
751 }
752 else if (*curr == '.')
753 {
754 if (++pos >= 4) goto error;
755 }
756 else goto error;
757 }
758 version->major = ver[0];
759 version->minor = ver[1];
760 version->build = ver[2];
761 version->revision = ver[3];
762 return TRUE;
763
764 error:
765 strU = xmlstr2unicode(str);
766 DPRINT1( "Wrong version definition in manifest file (%wZ)\n", &strU );
767 return FALSE;
768 }
769
770 static BOOL parse_expect_elem(xmlbuf_t* xmlbuf, const WCHAR* name)
771 {
772 xmlstr_t elem;
773 UNICODE_STRING elemU;
774 if (!next_xml_elem(xmlbuf, &elem)) return FALSE;
775 if (xmlstr_cmp(&elem, name)) return TRUE;
776 elemU = xmlstr2unicode(&elem);
777 DPRINT1( "unexpected element %wZ\n", &elemU );
778 return FALSE;
779 }
780
781 static BOOL parse_expect_no_attr(xmlbuf_t* xmlbuf, BOOL* end)
782 {
783 xmlstr_t attr_name, attr_value;
784 UNICODE_STRING attr_nameU, attr_valueU;
785 BOOL error;
786
787 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, end))
788 {
789 attr_nameU = xmlstr2unicode(&attr_name);
790 attr_valueU = xmlstr2unicode(&attr_name);
791 DPRINT1( "unexpected attr %S=%S\n", &attr_nameU,
792 &attr_valueU);
793 }
794 return !error;
795 }
796
797 static BOOL parse_end_element(xmlbuf_t *xmlbuf)
798 {
799 BOOL end = FALSE;
800 return parse_expect_no_attr(xmlbuf, &end) && !end;
801 }
802
803 static BOOL parse_expect_end_elem(xmlbuf_t *xmlbuf, const WCHAR *name)
804 {
805 xmlstr_t elem;
806 UNICODE_STRING elemU;
807 if (!next_xml_elem(xmlbuf, &elem)) return FALSE;
808 if (!xmlstr_cmp_end(&elem, name))
809 {
810 elemU = xmlstr2unicode(&elem);
811 DPRINT1( "unexpected element %wZ\n", &elemU );
812 return FALSE;
813 }
814 return parse_end_element(xmlbuf);
815 }
816
817 static BOOL parse_unknown_elem(xmlbuf_t *xmlbuf, const xmlstr_t *unknown_elem)
818 {
819 xmlstr_t attr_name, attr_value, elem;
820 BOOL end = FALSE, error, ret = TRUE;
821
822 while(next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end));
823 if(error || end) return end;
824
825 while(ret && (ret = next_xml_elem(xmlbuf, &elem)))
826 {
827 if(*elem.ptr == '/' && elem.len - 1 == unknown_elem->len &&
828 !strncmpW(elem.ptr+1, unknown_elem->ptr, unknown_elem->len))
829 break;
830 else
831 ret = parse_unknown_elem(xmlbuf, &elem);
832 }
833
834 return ret && parse_end_element(xmlbuf);
835 }
836
837 static BOOL parse_assembly_identity_elem(xmlbuf_t* xmlbuf, ACTIVATION_CONTEXT* actctx,
838 struct assembly_identity* ai)
839 {
840 xmlstr_t attr_name, attr_value;
841 BOOL end = FALSE, error;
842 UNICODE_STRING attr_valueU, attr_nameU;
843
844 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
845 {
846 if (xmlstr_cmp(&attr_name, g_nameW))
847 {
848 if (!(ai->name = xmlstrdupW(&attr_value))) return FALSE;
849 }
850 else if (xmlstr_cmp(&attr_name, typeW))
851 {
852 if (!(ai->type = xmlstrdupW(&attr_value))) return FALSE;
853 }
854 else if (xmlstr_cmp(&attr_name, versionW))
855 {
856 if (!parse_version(&attr_value, &ai->version)) return FALSE;
857 }
858 else if (xmlstr_cmp(&attr_name, processorArchitectureW))
859 {
860 if (!(ai->arch = xmlstrdupW(&attr_value))) return FALSE;
861 }
862 else if (xmlstr_cmp(&attr_name, publicKeyTokenW))
863 {
864 if (!(ai->public_key = xmlstrdupW(&attr_value))) return FALSE;
865 }
866 else if (xmlstr_cmp(&attr_name, languageW))
867 {
868 if (!(ai->language = xmlstrdupW(&attr_value))) return FALSE;
869 DPRINT1("Unsupported yet language attribute (%S)\n",
870 ai->language);
871 }
872 else
873 {
874 attr_nameU = xmlstr2unicode(&attr_name);
875 attr_valueU = xmlstr2unicode(&attr_value);
876 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
877 }
878 }
879
880 if (error || end) return end;
881 return parse_expect_end_elem(xmlbuf, assemblyIdentityW);
882 }
883
884 static BOOL parse_com_class_elem(xmlbuf_t* xmlbuf, struct dll_redirect* dll)
885 {
886 xmlstr_t elem, attr_name, attr_value;
887 BOOL ret, end = FALSE, error;
888 struct entity* entity;
889 UNICODE_STRING attr_valueU, attr_nameU;
890
891 if (!(entity = add_entity(&dll->entities, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION)))
892 return FALSE;
893
894 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
895 {
896 if (xmlstr_cmp(&attr_name, clsidW))
897 {
898 if (!(entity->u.comclass.clsid = xmlstrdupW(&attr_value))) return FALSE;
899 }
900 else
901 {
902 attr_nameU = xmlstr2unicode(&attr_name);
903 attr_valueU = xmlstr2unicode(&attr_value);
904 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
905 }
906 }
907
908 if (error || end) return end;
909
910 while ((ret = next_xml_elem(xmlbuf, &elem)))
911 {
912 if (xmlstr_cmp_end(&elem, comClassW))
913 {
914 ret = parse_end_element(xmlbuf);
915 break;
916 }
917 else
918 {
919 attr_nameU = xmlstr2unicode(&elem);
920 DPRINT1("unknown elem %wZ\n", &attr_nameU);
921 ret = parse_unknown_elem(xmlbuf, &elem);
922 }
923 }
924 return ret;
925 }
926
927 static BOOL parse_cominterface_proxy_stub_elem(xmlbuf_t* xmlbuf, struct dll_redirect* dll)
928 {
929 xmlstr_t attr_name, attr_value;
930 BOOL end = FALSE, error;
931 struct entity* entity;
932 UNICODE_STRING attr_valueU, attr_nameU;
933
934 if (!(entity = add_entity(&dll->entities, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION)))
935 return FALSE;
936
937 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
938 {
939 if (xmlstr_cmp(&attr_name, iidW))
940 {
941 if (!(entity->u.proxy.iid = xmlstrdupW(&attr_value))) return FALSE;
942 }
943 if (xmlstr_cmp(&attr_name, g_nameW))
944 {
945 if (!(entity->u.proxy.name = xmlstrdupW(&attr_value))) return FALSE;
946 }
947 else
948 {
949 attr_nameU = xmlstr2unicode(&attr_name);
950 attr_valueU = xmlstr2unicode(&attr_value);
951 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
952 }
953 }
954
955 if (error || end) return end;
956 return parse_expect_end_elem(xmlbuf, comInterfaceProxyStubW);
957 }
958
959 static BOOL parse_typelib_elem(xmlbuf_t* xmlbuf, struct dll_redirect* dll)
960 {
961 xmlstr_t attr_name, attr_value;
962 BOOL end = FALSE, error;
963 struct entity* entity;
964 UNICODE_STRING attr_valueU, attr_nameU;
965
966 if (!(entity = add_entity(&dll->entities, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION)))
967 return FALSE;
968
969 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
970 {
971 if (xmlstr_cmp(&attr_name, tlbidW))
972 {
973 if (!(entity->u.typelib.tlbid = xmlstrdupW(&attr_value))) return FALSE;
974 }
975 if (xmlstr_cmp(&attr_name, versionW))
976 {
977 if (!(entity->u.typelib.version = xmlstrdupW(&attr_value))) return FALSE;
978 }
979 if (xmlstr_cmp(&attr_name, helpdirW))
980 {
981 if (!(entity->u.typelib.helpdir = xmlstrdupW(&attr_value))) return FALSE;
982 }
983 else
984 {
985 attr_nameU = xmlstr2unicode(&attr_name);
986 attr_valueU = xmlstr2unicode(&attr_value);
987 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
988 }
989 }
990
991 if (error || end) return end;
992 return parse_expect_end_elem(xmlbuf, typelibW);
993 }
994
995 static BOOL parse_window_class_elem(xmlbuf_t* xmlbuf, struct dll_redirect* dll)
996 {
997 xmlstr_t elem, content;
998 BOOL end = FALSE, ret = TRUE;
999 struct entity* entity;
1000 UNICODE_STRING elemU;
1001
1002 if (!(entity = add_entity(&dll->entities, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION)))
1003 return FALSE;
1004
1005 if (!parse_expect_no_attr(xmlbuf, &end)) return FALSE;
1006 if (end) return FALSE;
1007
1008 if (!parse_text_content(xmlbuf, &content)) return FALSE;
1009
1010 if (!(entity->u.class.name = xmlstrdupW(&content))) return FALSE;
1011
1012 while (ret && (ret = next_xml_elem(xmlbuf, &elem)))
1013 {
1014 if (xmlstr_cmp_end(&elem, windowClassW))
1015 {
1016 ret = parse_end_element(xmlbuf);
1017 break;
1018 }
1019 else
1020 {
1021 elemU = xmlstr2unicode(&elem);
1022 DPRINT1("unknown elem %wZ\n", &elemU);
1023 ret = parse_unknown_elem(xmlbuf, &elem);
1024 }
1025 }
1026
1027 return ret;
1028 }
1029
1030 static BOOL parse_binding_redirect_elem(xmlbuf_t* xmlbuf)
1031 {
1032 xmlstr_t attr_name, attr_value;
1033 UNICODE_STRING attr_valueU, attr_nameU;
1034 BOOL end = FALSE, error;
1035
1036 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1037 {
1038 attr_nameU = xmlstr2unicode(&attr_name);
1039 attr_valueU = xmlstr2unicode(&attr_value);
1040
1041 if (xmlstr_cmp(&attr_name, oldVersionW))
1042 {
1043 DPRINT1("Not stored yet oldVersion=%wZ\n", &attr_valueU);
1044 }
1045 else if (xmlstr_cmp(&attr_name, newVersionW))
1046 {
1047 DPRINT1("Not stored yet newVersion=%wZ\n", &attr_valueU);
1048 }
1049 else
1050 {
1051 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
1052 }
1053 }
1054
1055 if (error || end) return end;
1056 return parse_expect_end_elem(xmlbuf, bindingRedirectW);
1057 }
1058
1059 static BOOL parse_description_elem(xmlbuf_t* xmlbuf)
1060 {
1061 xmlstr_t elem, content;
1062 UNICODE_STRING elemU;
1063 BOOL end = FALSE, ret = TRUE;
1064
1065 if (!parse_expect_no_attr(xmlbuf, &end) || end ||
1066 !parse_text_content(xmlbuf, &content))
1067 return FALSE;
1068
1069 elemU = xmlstr2unicode(&content);
1070 DPRINT("Got description %wZ\n", &elemU);
1071
1072 while (ret && (ret = next_xml_elem(xmlbuf, &elem)))
1073 {
1074 if (xmlstr_cmp_end(&elem, descriptionW))
1075 {
1076 ret = parse_end_element(xmlbuf);
1077 break;
1078 }
1079 else
1080 {
1081 elemU = xmlstr2unicode(&elem);
1082 DPRINT1("unknown elem %wZ\n", &elemU);
1083 ret = parse_unknown_elem(xmlbuf, &elem);
1084 }
1085 }
1086
1087 return ret;
1088 }
1089
1090 static BOOL parse_com_interface_external_proxy_stub_elem(xmlbuf_t* xmlbuf,
1091 struct assembly* assembly)
1092 {
1093 xmlstr_t attr_name, attr_value;
1094 BOOL end = FALSE, error;
1095 struct entity* entity;
1096
1097 entity = add_entity(&assembly->entities, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION);
1098 if (!entity) return FALSE;
1099
1100 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1101 {
1102 if (xmlstr_cmp(&attr_name, iidW))
1103 {
1104 if (!(entity->u.proxy.iid = xmlstrdupW(&attr_value))) return FALSE;
1105 }
1106 if (xmlstr_cmp(&attr_name, g_nameW))
1107 {
1108 if (!(entity->u.proxy.name = xmlstrdupW(&attr_value))) return FALSE;
1109 }
1110 else
1111 {
1112 DPRINT1("unknown attr %S=%S\n", attr_name.ptr, attr_value.ptr);
1113 }
1114 }
1115
1116 if (error || end) return end;
1117 return parse_expect_end_elem(xmlbuf, comInterfaceExternalProxyStubW);
1118 }
1119
1120 static BOOL parse_clr_class_elem(xmlbuf_t* xmlbuf, struct assembly* assembly)
1121 {
1122 xmlstr_t attr_name, attr_value;
1123 UNICODE_STRING attr_nameU, attr_valueU;
1124 BOOL end = FALSE, error;
1125 struct entity* entity;
1126
1127 entity = add_entity(&assembly->entities, ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION);
1128 if (!entity) return FALSE;
1129
1130 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1131 {
1132 if (xmlstr_cmp(&attr_name, g_nameW))
1133 {
1134 if (!(entity->u.clrclass.name = xmlstrdupW(&attr_value))) return FALSE;
1135 }
1136 else if (xmlstr_cmp(&attr_name, clsidW))
1137 {
1138 if (!(entity->u.clrclass.clsid = xmlstrdupW(&attr_value))) return FALSE;
1139 }
1140 else
1141 {
1142 attr_nameU = xmlstr2unicode(&attr_name);
1143 attr_valueU = xmlstr2unicode(&attr_value);
1144 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
1145 }
1146 }
1147
1148 if (error || end) return end;
1149 return parse_expect_end_elem(xmlbuf, clrClassW);
1150 }
1151
1152 static BOOL parse_clr_surrogate_elem(xmlbuf_t* xmlbuf, struct assembly* assembly)
1153 {
1154 xmlstr_t attr_name, attr_value;
1155 UNICODE_STRING attr_nameU, attr_valueU;
1156 BOOL end = FALSE, error;
1157 struct entity* entity;
1158
1159 entity = add_entity(&assembly->entities, ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES);
1160 if (!entity) return FALSE;
1161
1162 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1163 {
1164 if (xmlstr_cmp(&attr_name, g_nameW))
1165 {
1166 if (!(entity->u.clrsurrogate.name = xmlstrdupW(&attr_value))) return FALSE;
1167 }
1168 else if (xmlstr_cmp(&attr_name, clsidW))
1169 {
1170 if (!(entity->u.clrsurrogate.clsid = xmlstrdupW(&attr_value))) return FALSE;
1171 }
1172 else
1173 {
1174 attr_nameU = xmlstr2unicode(&attr_name);
1175 attr_valueU = xmlstr2unicode(&attr_value);
1176 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
1177 }
1178 }
1179
1180 if (error || end) return end;
1181 return parse_expect_end_elem(xmlbuf, clrSurrogateW);
1182 }
1183
1184 static BOOL parse_dependent_assembly_elem(xmlbuf_t* xmlbuf, struct actctx_loader* acl, BOOL optional)
1185 {
1186 struct assembly_identity ai;
1187 xmlstr_t elem;
1188 BOOL end = FALSE, ret = TRUE;
1189
1190 if (!parse_expect_no_attr(xmlbuf, &end) || end) return end;
1191
1192 memset(&ai, 0, sizeof(ai));
1193 ai.optional = optional;
1194
1195 if (!parse_expect_elem(xmlbuf, assemblyIdentityW) ||
1196 !parse_assembly_identity_elem(xmlbuf, acl->actctx, &ai))
1197 return FALSE;
1198
1199 /* store the newly found identity for later loading */
1200 if (!add_dependent_assembly_id(acl, &ai)) return FALSE;
1201
1202 while (ret && (ret = next_xml_elem(xmlbuf, &elem)))
1203 {
1204 if (xmlstr_cmp_end(&elem, dependentAssemblyW))
1205 {
1206 ret = parse_end_element(xmlbuf);
1207 break;
1208 }
1209 else if (xmlstr_cmp(&elem, bindingRedirectW))
1210 {
1211 ret = parse_binding_redirect_elem(xmlbuf);
1212 }
1213 else
1214 {
1215 DPRINT1("unknown elem %S\n", elem.ptr);
1216 ret = parse_unknown_elem(xmlbuf, &elem);
1217 }
1218 }
1219
1220 return ret;
1221 }
1222
1223 static BOOL parse_dependency_elem(xmlbuf_t* xmlbuf, struct actctx_loader* acl)
1224 {
1225 xmlstr_t attr_name, attr_value, elem;
1226 UNICODE_STRING attr_nameU, attr_valueU;
1227 BOOL end = FALSE, ret = TRUE, error, optional = FALSE;
1228
1229 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1230 {
1231 attr_nameU = xmlstr2unicode(&attr_name);
1232 attr_valueU = xmlstr2unicode(&attr_value);
1233
1234 if (xmlstr_cmp(&attr_name, optionalW))
1235 {
1236 static const WCHAR yesW[] = {'y','e','s',0};
1237 optional = xmlstr_cmpi( &attr_value, yesW );
1238 DPRINT1("optional=%wZ\n", &attr_valueU);
1239 }
1240 else
1241 {
1242 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
1243 }
1244 }
1245
1246 while (ret && (ret = next_xml_elem(xmlbuf, &elem)))
1247 {
1248 if (xmlstr_cmp_end(&elem, dependencyW))
1249 {
1250 ret = parse_end_element(xmlbuf);
1251 break;
1252 }
1253 else if (xmlstr_cmp(&elem, dependentAssemblyW))
1254 {
1255 ret = parse_dependent_assembly_elem(xmlbuf, acl, optional);
1256 }
1257 else
1258 {
1259 attr_nameU = xmlstr2unicode(&elem);
1260 DPRINT1("unknown element %wZ\n", &attr_nameU);
1261 ret = parse_unknown_elem(xmlbuf, &elem);
1262 }
1263 }
1264
1265 return ret;
1266 }
1267
1268 static BOOL parse_noinherit_elem(xmlbuf_t* xmlbuf)
1269 {
1270 BOOL end = FALSE;
1271
1272 if (!parse_expect_no_attr(xmlbuf, &end)) return FALSE;
1273 return end || parse_expect_end_elem(xmlbuf, noInheritW);
1274 }
1275
1276 static BOOL parse_noinheritable_elem(xmlbuf_t* xmlbuf)
1277 {
1278 BOOL end = FALSE;
1279
1280 if (!parse_expect_no_attr(xmlbuf, &end)) return FALSE;
1281 return end || parse_expect_end_elem(xmlbuf, noInheritableW);
1282 }
1283
1284 static BOOL parse_file_elem(xmlbuf_t* xmlbuf, struct assembly* assembly)
1285 {
1286 xmlstr_t attr_name, attr_value, elem;
1287 UNICODE_STRING attr_nameU, attr_valueU;
1288 BOOL end = FALSE, error, ret = TRUE;
1289 struct dll_redirect* dll;
1290
1291 if (!(dll = add_dll_redirect(assembly))) return FALSE;
1292
1293 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1294 {
1295 attr_nameU = xmlstr2unicode(&attr_name);
1296 attr_valueU = xmlstr2unicode(&attr_value);
1297
1298 if (xmlstr_cmp(&attr_name, g_nameW))
1299 {
1300 if (!(dll->name = xmlstrdupW(&attr_value))) return FALSE;
1301 DPRINT("name=%wZ\n", &attr_valueU);
1302 }
1303 else if (xmlstr_cmp(&attr_name, hashW))
1304 {
1305 if (!(dll->hash = xmlstrdupW(&attr_value))) return FALSE;
1306 }
1307 else if (xmlstr_cmp(&attr_name, hashalgW))
1308 {
1309 static const WCHAR sha1W[] = {'S','H','A','1',0};
1310 if (!xmlstr_cmpi(&attr_value, sha1W))
1311 DPRINT1("hashalg should be SHA1, got %wZ\n", &attr_valueU);
1312 }
1313 else
1314 {
1315 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
1316 }
1317 }
1318
1319 if (error || !dll->name) return FALSE;
1320 if (end) return TRUE;
1321
1322 while (ret && (ret = next_xml_elem(xmlbuf, &elem)))
1323 {
1324 if (xmlstr_cmp_end(&elem, fileW))
1325 {
1326 ret = parse_end_element(xmlbuf);
1327 break;
1328 }
1329 else if (xmlstr_cmp(&elem, comClassW))
1330 {
1331 ret = parse_com_class_elem(xmlbuf, dll);
1332 }
1333 else if (xmlstr_cmp(&elem, comInterfaceProxyStubW))
1334 {
1335 ret = parse_cominterface_proxy_stub_elem(xmlbuf, dll);
1336 }
1337 else if (xmlstr_cmp(&elem, asmv2hashW))
1338 {
1339 DPRINT1("asmv2hash (undocumented) not supported\n");
1340 ret = parse_unknown_elem(xmlbuf, &elem);
1341 }
1342 else if (xmlstr_cmp(&elem, typelibW))
1343 {
1344 ret = parse_typelib_elem(xmlbuf, dll);
1345 }
1346 else if (xmlstr_cmp(&elem, windowClassW))
1347 {
1348 ret = parse_window_class_elem(xmlbuf, dll);
1349 }
1350 else
1351 {
1352 attr_nameU = xmlstr2unicode(&elem);
1353 DPRINT1("unknown elem %wZ\n", &attr_nameU);
1354 ret = parse_unknown_elem( xmlbuf, &elem );
1355 }
1356 }
1357
1358 return ret;
1359 }
1360
1361 static BOOL parse_assembly_elem(xmlbuf_t* xmlbuf, struct actctx_loader* acl,
1362 struct assembly* assembly,
1363 struct assembly_identity* expected_ai)
1364 {
1365 xmlstr_t attr_name, attr_value, elem;
1366 UNICODE_STRING attr_nameU, attr_valueU;
1367 BOOL end = FALSE, error, version = FALSE, xmlns = FALSE, ret = TRUE;
1368
1369 while (next_xml_attr(xmlbuf, &attr_name, &attr_value, &error, &end))
1370 {
1371 attr_nameU = xmlstr2unicode(&attr_name);
1372 attr_valueU = xmlstr2unicode(&attr_value);
1373
1374 if (xmlstr_cmp(&attr_name, manifestVersionW))
1375 {
1376 static const WCHAR v10W[] = {'1','.','0',0};
1377 if (!xmlstr_cmp(&attr_value, v10W))
1378 {
1379 DPRINT1("wrong version %wZ\n", &attr_valueU);
1380 return FALSE;
1381 }
1382 version = TRUE;
1383 }
1384 else if (xmlstr_cmp(&attr_name, xmlnsW))
1385 {
1386 if (!xmlstr_cmp(&attr_value, manifestv1W) && !xmlstr_cmp(&attr_value, manifestv3W))
1387 {
1388 DPRINT1("wrong namespace %wZ\n", &attr_valueU);
1389 return FALSE;
1390 }
1391 xmlns = TRUE;
1392 }
1393 else
1394 {
1395 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU, &attr_valueU);
1396 }
1397 }
1398
1399 if (error || end || !xmlns || !version) return FALSE;
1400 if (!next_xml_elem(xmlbuf, &elem)) return FALSE;
1401
1402 if (assembly->type == APPLICATION_MANIFEST && xmlstr_cmp(&elem, noInheritW))
1403 {
1404 if (!parse_noinherit_elem(xmlbuf) || !next_xml_elem(xmlbuf, &elem))
1405 return FALSE;
1406 assembly->no_inherit = TRUE;
1407 }
1408
1409 if (xmlstr_cmp(&elem, noInheritableW))
1410 {
1411 if (!parse_noinheritable_elem(xmlbuf) || !next_xml_elem(xmlbuf, &elem))
1412 return FALSE;
1413 }
1414 else if ((assembly->type == ASSEMBLY_MANIFEST || assembly->type == ASSEMBLY_SHARED_MANIFEST) &&
1415 assembly->no_inherit)
1416 return FALSE;
1417
1418 while (ret)
1419 {
1420 if (xmlstr_cmp_end(&elem, assemblyW))
1421 {
1422 ret = parse_end_element(xmlbuf);
1423 break;
1424 }
1425 else if (xmlstr_cmp(&elem, descriptionW))
1426 {
1427 ret = parse_description_elem(xmlbuf);
1428 }
1429 else if (xmlstr_cmp(&elem, comInterfaceExternalProxyStubW))
1430 {
1431 ret = parse_com_interface_external_proxy_stub_elem(xmlbuf, assembly);
1432 }
1433 else if (xmlstr_cmp(&elem, dependencyW))
1434 {
1435 ret = parse_dependency_elem(xmlbuf, acl);
1436 }
1437 else if (xmlstr_cmp(&elem, fileW))
1438 {
1439 ret = parse_file_elem(xmlbuf, assembly);
1440 }
1441 else if (xmlstr_cmp(&elem, clrClassW))
1442 {
1443 ret = parse_clr_class_elem(xmlbuf, assembly);
1444 }
1445 else if (xmlstr_cmp(&elem, clrSurrogateW))
1446 {
1447 ret = parse_clr_surrogate_elem(xmlbuf, assembly);
1448 }
1449 else if (xmlstr_cmp(&elem, assemblyIdentityW))
1450 {
1451 if (!parse_assembly_identity_elem(xmlbuf, acl->actctx, &assembly->id)) return FALSE;
1452
1453 if (expected_ai)
1454 {
1455 /* FIXME: more tests */
1456 if (assembly->type == ASSEMBLY_MANIFEST &&
1457 memcmp(&assembly->id.version, &expected_ai->version, sizeof(assembly->id.version)))
1458 {
1459 DPRINT1("wrong version for assembly manifest: %u.%u.%u.%u / %u.%u.%u.%u\n",
1460 expected_ai->version.major, expected_ai->version.minor,
1461 expected_ai->version.build, expected_ai->version.revision,
1462 assembly->id.version.major, assembly->id.version.minor,
1463 assembly->id.version.build, assembly->id.version.revision);
1464 ret = FALSE;
1465 }
1466 else if (assembly->type == ASSEMBLY_SHARED_MANIFEST &&
1467 (assembly->id.version.major != expected_ai->version.major ||
1468 assembly->id.version.minor != expected_ai->version.minor ||
1469 assembly->id.version.build < expected_ai->version.build ||
1470 (assembly->id.version.build == expected_ai->version.build &&
1471 assembly->id.version.revision < expected_ai->version.revision)))
1472 {
1473 DPRINT1("wrong version for shared assembly manifest\n");
1474 ret = FALSE;
1475 }
1476 }
1477 }
1478 else
1479 {
1480 attr_nameU = xmlstr2unicode(&elem);
1481 DPRINT1("unknown element %wZ\n", &attr_nameU);
1482 ret = parse_unknown_elem(xmlbuf, &elem);
1483 }
1484 if (ret) ret = next_xml_elem(xmlbuf, &elem);
1485 }
1486
1487 return ret;
1488 }
1489
1490 static NTSTATUS parse_manifest_buffer( struct actctx_loader* acl, struct assembly *assembly,
1491 struct assembly_identity* ai, xmlbuf_t *xmlbuf )
1492 {
1493 xmlstr_t elem;
1494 UNICODE_STRING elemU;
1495
1496 if (!next_xml_elem(xmlbuf, &elem)) return STATUS_SXS_CANT_GEN_ACTCTX;
1497
1498 if (xmlstr_cmp(&elem, g_xmlW) &&
1499 (!parse_xml_header(xmlbuf) || !next_xml_elem(xmlbuf, &elem)))
1500 return STATUS_SXS_CANT_GEN_ACTCTX;
1501
1502 if (!xmlstr_cmp(&elem, assemblyW))
1503 {
1504 elemU = xmlstr2unicode(&elem);
1505 DPRINT1("root element is %wZ, not <assembly>\n", &elemU);
1506 return STATUS_SXS_CANT_GEN_ACTCTX;
1507 }
1508
1509 if (!parse_assembly_elem(xmlbuf, acl, assembly, ai))
1510 {
1511 DPRINT1("failed to parse manifest %S\n", assembly->manifest.info );
1512 return STATUS_SXS_CANT_GEN_ACTCTX;
1513 }
1514
1515 if (next_xml_elem(xmlbuf, &elem))
1516 {
1517 elemU = xmlstr2unicode(&elem);
1518 DPRINT1("unexpected element %wZ\n", &elemU);
1519 return STATUS_SXS_CANT_GEN_ACTCTX;
1520 }
1521
1522 if (xmlbuf->ptr != xmlbuf->end)
1523 {
1524 DPRINT1("parse error\n");
1525 return STATUS_SXS_CANT_GEN_ACTCTX;
1526 }
1527 return STATUS_SUCCESS;
1528 }
1529
1530 static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_identity* ai,
1531 LPCWSTR filename, LPCWSTR directory, BOOL shared,
1532 const void *buffer, SIZE_T size )
1533 {
1534 xmlbuf_t xmlbuf;
1535 NTSTATUS status;
1536 struct assembly *assembly;
1537 int unicode_tests;
1538
1539 DPRINT( "parsing manifest loaded from %S base dir %S\n", filename, directory );
1540
1541 if (!(assembly = add_assembly(acl->actctx, shared ? ASSEMBLY_SHARED_MANIFEST : ASSEMBLY_MANIFEST)))
1542 return STATUS_SXS_CANT_GEN_ACTCTX;
1543
1544 if (directory && !(assembly->directory = strdupW(directory)))
1545 return STATUS_NO_MEMORY;
1546
1547 if (filename) assembly->manifest.info = strdupW( filename + 4 /* skip \??\ prefix */ );
1548 assembly->manifest.type = assembly->manifest.info ? ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE
1549 : ACTIVATION_CONTEXT_PATH_TYPE_NONE;
1550
1551 unicode_tests = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE;
1552 if (RtlIsTextUnicode((PVOID)buffer, (ULONG)size, &unicode_tests ))
1553 {
1554 xmlbuf.ptr = buffer;
1555 xmlbuf.end = xmlbuf.ptr + size / sizeof(WCHAR);
1556 status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
1557 }
1558 else if (unicode_tests & IS_TEXT_UNICODE_REVERSE_SIGNATURE)
1559 {
1560 const WCHAR *buf = buffer;
1561 WCHAR *new_buff;
1562 unsigned int i;
1563
1564 if (!(new_buff = RtlAllocateHeap( RtlGetProcessHeap(), 0, size )))
1565 return STATUS_NO_MEMORY;
1566 for (i = 0; i < size / sizeof(WCHAR); i++)
1567 new_buff[i] = RtlUshortByteSwap( buf[i] );
1568 xmlbuf.ptr = new_buff;
1569 xmlbuf.end = xmlbuf.ptr + size / sizeof(WCHAR);
1570 status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
1571 RtlFreeHeap( RtlGetProcessHeap(), 0, new_buff );
1572 }
1573 else
1574 {
1575 /* TODO: this doesn't handle arbitrary encodings */
1576 ANSI_STRING xmlA;
1577 UNICODE_STRING xmlW;
1578
1579 ASSERT(size < MAXUSHORT);
1580 xmlA.Buffer = (PCHAR)buffer;
1581 xmlA.Length = xmlA.MaximumLength = (USHORT)size;
1582
1583 _SEH2_TRY
1584 {
1585 status = RtlAnsiStringToUnicodeString(&xmlW, &xmlA, TRUE);
1586 }
1587 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
1588 {
1589 DPRINT1("Exception accessing buffer\n");
1590 return STATUS_SXS_CANT_GEN_ACTCTX;
1591 }
1592 _SEH2_END;
1593
1594 if (!NT_SUCCESS(status))
1595 {
1596 DPRINT1("RtlAnsiStringToUnicodeString failed with %lx\n", status);
1597 return STATUS_SXS_CANT_GEN_ACTCTX;
1598 }
1599 ASSERT(xmlW.Buffer != NULL);
1600
1601 xmlbuf.ptr = xmlW.Buffer;
1602 xmlbuf.end = xmlbuf.ptr + xmlW.Length / sizeof(WCHAR);
1603 status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
1604
1605 RtlFreeUnicodeString(&xmlW);
1606 }
1607 return status;
1608 }
1609
1610 static NTSTATUS open_nt_file( HANDLE *handle, UNICODE_STRING *name )
1611 {
1612 OBJECT_ATTRIBUTES attr;
1613 IO_STATUS_BLOCK io;
1614
1615 attr.Length = sizeof(attr);
1616 attr.RootDirectory = 0;
1617 attr.Attributes = OBJ_CASE_INSENSITIVE;
1618 attr.ObjectName = name;
1619 attr.SecurityDescriptor = NULL;
1620 attr.SecurityQualityOfService = NULL;
1621 return NtOpenFile( handle, GENERIC_READ, &attr, &io, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_ALERT );
1622 }
1623
1624 static NTSTATUS get_module_filename( HMODULE module, UNICODE_STRING *str, USHORT extra_len )
1625 {
1626 NTSTATUS status;
1627 ULONG magic;
1628 LDR_DATA_TABLE_ENTRY *pldr;
1629
1630 LdrLockLoaderLock(0, NULL, &magic);
1631 status = LdrFindEntryForAddress( module, &pldr );
1632 if (status == STATUS_SUCCESS)
1633 {
1634 if ((str->Buffer = RtlAllocateHeap( RtlGetProcessHeap(), 0,
1635 pldr->FullDllName.Length + extra_len + sizeof(WCHAR) )))
1636 {
1637 memcpy( str->Buffer, pldr->FullDllName.Buffer, pldr->FullDllName.Length + sizeof(WCHAR) );
1638 str->Length = pldr->FullDllName.Length;
1639 str->MaximumLength = pldr->FullDllName.Length + extra_len + sizeof(WCHAR);
1640 }
1641 else status = STATUS_NO_MEMORY;
1642 }
1643 LdrUnlockLoaderLock(0, magic);
1644 return status;
1645 }
1646
1647 static NTSTATUS get_manifest_in_module( struct actctx_loader* acl, struct assembly_identity* ai,
1648 LPCWSTR filename, LPCWSTR directory, BOOL shared,
1649 HANDLE hModule, LPCWSTR resname, ULONG lang )
1650 {
1651 NTSTATUS status;
1652 UNICODE_STRING nameW;
1653 LDR_RESOURCE_INFO info;
1654 IMAGE_RESOURCE_DATA_ENTRY* entry = NULL;
1655 void *ptr;
1656
1657 //DPRINT( "looking for res %s in module %p %s\n", resname,
1658 // hModule, filename );
1659
1660 #if 0
1661 if (TRACE_ON(actctx))
1662 {
1663 if (!filename && !get_module_filename( hModule, &nameW, 0 ))
1664 {
1665 DPRINT( "looking for res %s in module %p %s\n", debugstr_w(resname),
1666 hModule, debugstr_w(nameW.Buffer) );
1667 RtlFreeUnicodeString( &nameW );
1668 }
1669 else DPRINT( "looking for res %s in module %p %s\n", debugstr_w(resname),
1670 hModule, debugstr_w(filename) );
1671 }
1672 #endif
1673
1674 if (!resname) return STATUS_INVALID_PARAMETER;
1675
1676 info.Type = (ULONG_PTR)RT_MANIFEST;
1677 info.Language = lang;
1678 if (!((ULONG_PTR)resname >> 16))
1679 {
1680 info.Name = (ULONG_PTR)resname;
1681 status = LdrFindResource_U(hModule, &info, 3, &entry);
1682 }
1683 else if (resname[0] == '#')
1684 {
1685 ULONG value;
1686 RtlInitUnicodeString(&nameW, resname + 1);
1687 if (RtlUnicodeStringToInteger(&nameW, 10, &value) != STATUS_SUCCESS || HIWORD(value))
1688 return STATUS_INVALID_PARAMETER;
1689 info.Name = value;
1690 status = LdrFindResource_U(hModule, &info, 3, &entry);
1691 }
1692 else
1693 {
1694 RtlCreateUnicodeString(&nameW, resname);
1695 RtlUpcaseUnicodeString(&nameW, &nameW, FALSE);
1696 info.Name = (ULONG_PTR)nameW.Buffer;
1697 status = LdrFindResource_U(hModule, &info, 3, &entry);
1698 RtlFreeUnicodeString(&nameW);
1699 }
1700 if (status == STATUS_SUCCESS) status = LdrAccessResource(hModule, entry, &ptr, NULL);
1701
1702 if (status == STATUS_SUCCESS)
1703 status = parse_manifest(acl, ai, filename, directory, shared, ptr, entry->Size);
1704
1705 return status;
1706 }
1707
1708 static NTSTATUS get_manifest_in_pe_file( struct actctx_loader* acl, struct assembly_identity* ai,
1709 LPCWSTR filename, LPCWSTR directory, BOOL shared,
1710 HANDLE file, LPCWSTR resname, ULONG lang )
1711 {
1712 HANDLE mapping;
1713 OBJECT_ATTRIBUTES attr;
1714 LARGE_INTEGER size;
1715 LARGE_INTEGER offset;
1716 NTSTATUS status;
1717 SIZE_T count;
1718 void *base;
1719
1720 DPRINT( "looking for res %S in %S\n", resname, filename );
1721
1722 attr.Length = sizeof(attr);
1723 attr.RootDirectory = 0;
1724 attr.ObjectName = NULL;
1725 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
1726 attr.SecurityDescriptor = NULL;
1727 attr.SecurityQualityOfService = NULL;
1728
1729 size.QuadPart = 0;
1730 status = NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ,
1731 &attr, &size, PAGE_READONLY, SEC_COMMIT, file );
1732 if (status != STATUS_SUCCESS) return status;
1733
1734 offset.QuadPart = 0;
1735 count = 0;
1736 base = NULL;
1737 status = NtMapViewOfSection( mapping, NtCurrentProcess(), &base, 0, 0, &offset,
1738 &count, ViewShare, 0, PAGE_READONLY );
1739 NtClose( mapping );
1740 if (status != STATUS_SUCCESS) return status;
1741
1742 if (RtlImageNtHeader(base)) /* we got a PE file */
1743 {
1744 HANDLE module = (HMODULE)((ULONG_PTR)base | 1); /* make it a LOAD_LIBRARY_AS_DATAFILE handle */
1745 status = get_manifest_in_module( acl, ai, filename, directory, shared, module, resname, lang );
1746 }
1747 else status = STATUS_INVALID_IMAGE_FORMAT;
1748
1749 NtUnmapViewOfSection( NtCurrentProcess(), base );
1750 return status;
1751 }
1752
1753 static NTSTATUS get_manifest_in_manifest_file( struct actctx_loader* acl, struct assembly_identity* ai,
1754 LPCWSTR filename, LPCWSTR directory, BOOL shared, HANDLE file )
1755 {
1756 FILE_STANDARD_INFORMATION info;
1757 IO_STATUS_BLOCK io;
1758 HANDLE mapping;
1759 OBJECT_ATTRIBUTES attr;
1760 LARGE_INTEGER size;
1761 LARGE_INTEGER offset;
1762 NTSTATUS status;
1763 SIZE_T count;
1764 void *base;
1765
1766 DPRINT( "loading manifest file %S\n", filename );
1767
1768 attr.Length = sizeof(attr);
1769 attr.RootDirectory = 0;
1770 attr.ObjectName = NULL;
1771 attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
1772 attr.SecurityDescriptor = NULL;
1773 attr.SecurityQualityOfService = NULL;
1774
1775 size.QuadPart = 0;
1776 status = NtCreateSection( &mapping, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ,
1777 &attr, &size, PAGE_READONLY, SEC_COMMIT, file );
1778
1779 if (status != STATUS_SUCCESS) return status;
1780
1781 offset.QuadPart = 0;
1782 count = 0;
1783 base = NULL;
1784 status = NtMapViewOfSection( mapping, NtCurrentProcess(), &base, 0, 0, &offset,
1785 &count, ViewShare, 0, PAGE_READONLY );
1786
1787 if (status != STATUS_SUCCESS) return status;
1788
1789 /* Fixme: WINE uses FileEndOfFileInformation with NtQueryInformationFile. */
1790 status = NtQueryInformationFile( file, &io, &info, sizeof(info), FileStandardInformation);
1791
1792 if (status == STATUS_SUCCESS)
1793 status = parse_manifest(acl, ai, filename, directory, shared, base, (SIZE_T)info.EndOfFile.QuadPart);
1794
1795 NtUnmapViewOfSection( NtCurrentProcess(), base );
1796 NtClose( mapping );
1797 return status;
1798 }
1799
1800 /* try to load the .manifest file associated to the file */
1801 static NTSTATUS get_manifest_in_associated_manifest( struct actctx_loader* acl, struct assembly_identity* ai,
1802 LPCWSTR filename, LPCWSTR directory, HMODULE module, LPCWSTR resname )
1803 {
1804 static const WCHAR fmtW[] = { '.','%','l','u',0 };
1805 WCHAR *buffer;
1806 NTSTATUS status;
1807 UNICODE_STRING nameW;
1808 HANDLE file;
1809 ULONG_PTR resid = (ULONG_PTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
1810
1811 if (!((ULONG_PTR)resname >> 16)) resid = (ULONG_PTR)resname & 0xffff;
1812
1813 DPRINT( "looking for manifest associated with %S id %lu\n", filename, resid );
1814
1815 if (module) /* use the module filename */
1816 {
1817 UNICODE_STRING name;
1818
1819 if (!(status = get_module_filename( module, &name, sizeof(dotManifestW) + 10*sizeof(WCHAR) )))
1820 {
1821 if (resid != 1) sprintfW( name.Buffer + strlenW(name.Buffer), fmtW, resid );
1822 strcatW( name.Buffer, dotManifestW );
1823 if (!RtlDosPathNameToNtPathName_U( name.Buffer, &nameW, NULL, NULL ))
1824 status = STATUS_RESOURCE_DATA_NOT_FOUND;
1825 RtlFreeUnicodeString( &name );
1826 }
1827 if (status) return status;
1828 }
1829 else
1830 {
1831 if (!(buffer = RtlAllocateHeap( RtlGetProcessHeap(), 0,
1832 (strlenW(filename) + 10) * sizeof(WCHAR) + sizeof(dotManifestW) )))
1833 return STATUS_NO_MEMORY;
1834 strcpyW( buffer, filename );
1835 if (resid != 1) sprintfW( buffer + strlenW(buffer), fmtW, resid );
1836 strcatW( buffer, dotManifestW );
1837 RtlInitUnicodeString( &nameW, buffer );
1838 }
1839
1840 if (!open_nt_file( &file, &nameW ))
1841 {
1842 status = get_manifest_in_manifest_file( acl, ai, nameW.Buffer, directory, FALSE, file );
1843 NtClose( file );
1844 }
1845 else status = STATUS_RESOURCE_DATA_NOT_FOUND;
1846 RtlFreeUnicodeString( &nameW );
1847 return status;
1848 }
1849
1850 static WCHAR *lookup_manifest_file( HANDLE dir, struct assembly_identity *ai )
1851 {
1852 static const WCHAR lookup_fmtW[] =
1853 {'%','s','_','%','s','_','%','s','_','%','u','.','%','u','.','*','.','*','_',
1854 '*', /* FIXME */
1855 '.','m','a','n','i','f','e','s','t',0};
1856
1857 WCHAR *lookup, *ret = NULL;
1858 UNICODE_STRING lookup_us;
1859 IO_STATUS_BLOCK io;
1860 unsigned int data_pos = 0, data_len;
1861 char buffer[8192];
1862
1863 if (!(lookup = RtlAllocateHeap( RtlGetProcessHeap(), 0,
1864 (strlenW(ai->arch) + strlenW(ai->name)
1865 + strlenW(ai->public_key) + 20) * sizeof(WCHAR)
1866 + sizeof(lookup_fmtW) )))
1867 return NULL;
1868
1869 sprintfW( lookup, lookup_fmtW, ai->arch, ai->name, ai->public_key, ai->version.major, ai->version.minor);
1870 RtlInitUnicodeString( &lookup_us, lookup );
1871
1872 NtQueryDirectoryFile( dir, 0, NULL, NULL, &io, buffer, sizeof(buffer),
1873 FileBothDirectoryInformation, FALSE, &lookup_us, TRUE );
1874 if (io.Status == STATUS_SUCCESS)
1875 {
1876 FILE_BOTH_DIR_INFORMATION *dir_info;
1877 WCHAR *tmp;
1878 ULONG build, revision;
1879
1880 data_len = (ULONG)io.Information;
1881
1882 for (;;)
1883 {
1884 if (data_pos >= data_len)
1885 {
1886 NtQueryDirectoryFile( dir, 0, NULL, NULL, &io, buffer, sizeof(buffer),
1887 FileBothDirectoryInformation, FALSE, &lookup_us, FALSE );
1888 if (io.Status != STATUS_SUCCESS) break;
1889 data_len = (ULONG)io.Information;
1890 data_pos = 0;
1891 }
1892 dir_info = (FILE_BOTH_DIR_INFORMATION*)(buffer + data_pos);
1893
1894 if (dir_info->NextEntryOffset) data_pos += dir_info->NextEntryOffset;
1895 else data_pos = data_len;
1896
1897 tmp = (WCHAR *)dir_info->FileName + (strchrW(lookup, '*') - lookup);
1898 build = atoiW(tmp);
1899 if (build < ai->version.build) continue;
1900 tmp = strchrW(tmp, '.') + 1;
1901 revision = atoiW(tmp);
1902 if (build == ai->version.build && revision < ai->version.revision)
1903 continue;
1904 ai->version.build = (USHORT)build;
1905 ai->version.revision = (USHORT)revision;
1906
1907 if ((ret = RtlAllocateHeap( RtlGetProcessHeap(), 0, dir_info->FileNameLength * sizeof(WCHAR) )))
1908 {
1909 memcpy( ret, dir_info->FileName, dir_info->FileNameLength );
1910 ret[dir_info->FileNameLength/sizeof(WCHAR)] = 0;
1911 }
1912 break;
1913 }
1914 }
1915 else DPRINT1("no matching file for %S\n", lookup);
1916 RtlFreeHeap( RtlGetProcessHeap(), 0, lookup );
1917 return ret;
1918 }
1919
1920 static NTSTATUS lookup_winsxs(struct actctx_loader* acl, struct assembly_identity* ai)
1921 {
1922 struct assembly_identity sxs_ai;
1923 UNICODE_STRING path_us;
1924 OBJECT_ATTRIBUTES attr;
1925 IO_STATUS_BLOCK io;
1926 WCHAR *path, *file = NULL;
1927 HANDLE handle;
1928
1929 static const WCHAR manifest_dirW[] =
1930 {'\\','w','i','n','s','x','s','\\','m','a','n','i','f','e','s','t','s',0};
1931
1932 if (!ai->arch || !ai->name || !ai->public_key) return STATUS_NO_SUCH_FILE;
1933
1934 if (!(path = RtlAllocateHeap( RtlGetProcessHeap(), 0,
1935 ((strlenW(SharedUserData->NtSystemRoot) + 1) *sizeof(WCHAR)) + sizeof(manifest_dirW) )))
1936 return STATUS_NO_MEMORY;
1937
1938 memcpy( path, SharedUserData->NtSystemRoot, strlenW(SharedUserData->NtSystemRoot) * sizeof(WCHAR) );
1939 memcpy( path + strlenW(SharedUserData->NtSystemRoot), manifest_dirW, sizeof(manifest_dirW) );
1940
1941 if (!RtlDosPathNameToNtPathName_U( path, &path_us, NULL, NULL ))
1942 {
1943 RtlFreeHeap( RtlGetProcessHeap(), 0, path );
1944 return STATUS_NO_SUCH_FILE;
1945 }
1946 RtlFreeHeap( RtlGetProcessHeap(), 0, path );
1947
1948 attr.Length = sizeof(attr);
1949 attr.RootDirectory = 0;
1950 attr.Attributes = OBJ_CASE_INSENSITIVE;
1951 attr.ObjectName = &path_us;
1952 attr.SecurityDescriptor = NULL;
1953 attr.SecurityQualityOfService = NULL;
1954
1955 if (!NtOpenFile( &handle, GENERIC_READ, &attr, &io, FILE_SHARE_READ | FILE_SHARE_WRITE,
1956 FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ))
1957 {
1958 sxs_ai = *ai;
1959 file = lookup_manifest_file( handle, &sxs_ai );
1960 NtClose( handle );
1961 }
1962 if (!file)
1963 {
1964 RtlFreeUnicodeString( &path_us );
1965 return STATUS_NO_SUCH_FILE;
1966 }
1967
1968 /* append file name to directory path */
1969 if (!(path = RtlReAllocateHeap( RtlGetProcessHeap(), 0, path_us.Buffer,
1970 path_us.Length + (strlenW(file) + 2) * sizeof(WCHAR) )))
1971 {
1972 RtlFreeHeap( RtlGetProcessHeap(), 0, file );
1973 RtlFreeUnicodeString( &path_us );
1974 return STATUS_NO_MEMORY;
1975 }
1976
1977 path[path_us.Length/sizeof(WCHAR)] = '\\';
1978 strcpyW( path + path_us.Length/sizeof(WCHAR) + 1, file );
1979 RtlInitUnicodeString( &path_us, path );
1980 *strrchrW(file, '.') = 0; /* remove .manifest extension */
1981
1982 if (!open_nt_file( &handle, &path_us ))
1983 {
1984 io.Status = get_manifest_in_manifest_file(acl, &sxs_ai, path_us.Buffer, file, TRUE, handle);
1985 NtClose( handle );
1986 }
1987 else io.Status = STATUS_NO_SUCH_FILE;
1988
1989 RtlFreeHeap( RtlGetProcessHeap(), 0, file );
1990 RtlFreeUnicodeString( &path_us );
1991 return io.Status;
1992 }
1993
1994 static NTSTATUS lookup_assembly(struct actctx_loader* acl,
1995 struct assembly_identity* ai)
1996 {
1997 static const WCHAR dotDllW[] = {'.','d','l','l',0};
1998 unsigned int i;
1999 WCHAR *buffer, *p, *directory;
2000 NTSTATUS status;
2001 UNICODE_STRING nameW;
2002 HANDLE file;
2003
2004 DPRINT( "looking for name=%S version=%u.%u.%u.%u arch=%S\n",
2005 ai->name, ai->version.major, ai->version.minor, ai->version.build, ai->version.revision, ai->arch );
2006
2007 if ((status = lookup_winsxs(acl, ai)) != STATUS_NO_SUCH_FILE) return status;
2008
2009 /* FIXME: add support for language specific lookup */
2010
2011 nameW.Buffer = NULL;
2012 if (!(buffer = RtlAllocateHeap( RtlGetProcessHeap(), 0,
2013 (strlenW(acl->actctx->appdir.info) + 2 * strlenW(ai->name) + 2) * sizeof(WCHAR) + sizeof(dotManifestW) )))
2014 return STATUS_NO_MEMORY;
2015
2016 if (!(directory = build_assembly_dir( ai )))
2017 {
2018 RtlFreeHeap( RtlGetProcessHeap(), 0, buffer );
2019 return STATUS_NO_MEMORY;
2020 }
2021
2022 /* lookup in appdir\name.dll
2023 * appdir\name.manifest
2024 * appdir\name\name.dll
2025 * appdir\name\name.manifest
2026 */
2027 strcpyW( buffer, acl->actctx->appdir.info );
2028 p = buffer + strlenW(buffer);
2029 for (i = 0; i < 2; i++)
2030 {
2031 *p++ = '\\';
2032 strcpyW( p, ai->name );
2033 p += strlenW(p);
2034
2035 strcpyW( p, dotDllW );
2036 if (RtlDosPathNameToNtPathName_U( buffer, &nameW, NULL, NULL ))
2037 {
2038 status = open_nt_file( &file, &nameW );
2039 if (!status)
2040 {
2041 status = get_manifest_in_pe_file( acl, ai, nameW.Buffer, directory, FALSE, file,
2042 (LPCWSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID, 0 );
2043 NtClose( file );
2044 break;
2045 }
2046 RtlFreeUnicodeString( &nameW );
2047 }
2048
2049 strcpyW( p, dotManifestW );
2050 if (RtlDosPathNameToNtPathName_U( buffer, &nameW, NULL, NULL ))
2051 {
2052 status = open_nt_file( &file, &nameW );
2053 if (!status)
2054 {
2055 status = get_manifest_in_manifest_file( acl, ai, nameW.Buffer, directory, FALSE, file );
2056 NtClose( file );
2057 break;
2058 }
2059 RtlFreeUnicodeString( &nameW );
2060 }
2061 status = STATUS_SXS_ASSEMBLY_NOT_FOUND;
2062 }
2063 RtlFreeUnicodeString( &nameW );
2064 RtlFreeHeap( RtlGetProcessHeap(), 0, directory );
2065 RtlFreeHeap( RtlGetProcessHeap(), 0, buffer );
2066 return status;
2067 }
2068
2069 static NTSTATUS parse_depend_manifests(struct actctx_loader* acl)
2070 {
2071 NTSTATUS status = STATUS_SUCCESS;
2072 unsigned int i;
2073
2074 for (i = 0; i < acl->num_dependencies; i++)
2075 {
2076 if (lookup_assembly(acl, &acl->dependencies[i]) != STATUS_SUCCESS)
2077 {
2078 if (!acl->dependencies[i].optional)
2079 {
2080 DPRINT1( "Could not find dependent assembly %S\n", acl->dependencies[i].name );
2081 status = STATUS_SXS_CANT_GEN_ACTCTX;
2082 break;
2083 }
2084 }
2085 }
2086 /* FIXME should now iterate through all refs */
2087 return status;
2088 }
2089
2090 /* find the appropriate activation context for RtlQueryInformationActivationContext */
2091 static NTSTATUS find_query_actctx( HANDLE *handle, DWORD flags, ULONG class )
2092 {
2093 NTSTATUS status = STATUS_SUCCESS;
2094
2095 if (flags & QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX)
2096 {
2097 if (*handle) return STATUS_INVALID_PARAMETER;
2098
2099 if (NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame)
2100 *handle = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame->ActivationContext;
2101 }
2102 else if (flags & (QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS|QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE))
2103 {
2104 ULONG magic;
2105 LDR_DATA_TABLE_ENTRY *pldr;
2106
2107 if (!*handle) return STATUS_INVALID_PARAMETER;
2108
2109 LdrLockLoaderLock( 0, NULL, &magic );
2110 if (!LdrFindEntryForAddress( *handle, &pldr ))
2111 {
2112 if ((flags & QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE) && *handle != pldr->DllBase)
2113 status = STATUS_DLL_NOT_FOUND;
2114 else
2115 *handle = pldr->EntryPointActivationContext;
2116 }
2117 else status = STATUS_DLL_NOT_FOUND;
2118 LdrUnlockLoaderLock( 0, magic );
2119 }
2120 else if (!*handle && (class != ActivationContextBasicInformation))
2121 *handle = process_actctx;
2122
2123 return status;
2124 }
2125
2126 static NTSTATUS fill_keyed_data(PACTCTX_SECTION_KEYED_DATA data, PVOID v1, PVOID v2, unsigned int i)
2127 {
2128 data->ulDataFormatVersion = 1;
2129 data->lpData = v1;
2130 data->ulLength = 20; /* FIXME */
2131 data->lpSectionGlobalData = NULL; /* FIXME */
2132 data->ulSectionGlobalDataLength = 0; /* FIXME */
2133 data->lpSectionBase = v2;
2134 data->ulSectionTotalLength = 0; /* FIXME */
2135 data->hActCtx = NULL;
2136 if (data->cbSize >= offsetof(ACTCTX_SECTION_KEYED_DATA, ulAssemblyRosterIndex) + sizeof(ULONG))
2137 data->ulAssemblyRosterIndex = i + 1;
2138
2139 return STATUS_SUCCESS;
2140 }
2141
2142 static NTSTATUS find_dll_redirection(ACTIVATION_CONTEXT* actctx, const UNICODE_STRING *section_name,
2143 PACTCTX_SECTION_KEYED_DATA data)
2144 {
2145 unsigned int i, j, snlen = section_name->Length / sizeof(WCHAR);
2146
2147 for (i = 0; i < actctx->num_assemblies; i++)
2148 {
2149 struct assembly *assembly = &actctx->assemblies[i];
2150 for (j = 0; j < assembly->num_dlls; j++)
2151 {
2152 struct dll_redirect *dll = &assembly->dlls[j];
2153 if (!strncmpiW(section_name->Buffer, dll->name, snlen) && !dll->name[snlen])
2154 return fill_keyed_data(data, dll, assembly, i);
2155 }
2156 }
2157 return STATUS_SXS_KEY_NOT_FOUND;
2158 }
2159
2160 static NTSTATUS find_window_class(ACTIVATION_CONTEXT* actctx, const UNICODE_STRING *section_name,
2161 PACTCTX_SECTION_KEYED_DATA data)
2162 {
2163 unsigned int i, j, k, snlen = section_name->Length / sizeof(WCHAR);
2164
2165 for (i = 0; i < actctx->num_assemblies; i++)
2166 {
2167 struct assembly *assembly = &actctx->assemblies[i];
2168 for (j = 0; j < assembly->num_dlls; j++)
2169 {
2170 struct dll_redirect *dll = &assembly->dlls[j];
2171 for (k = 0; k < dll->entities.num; k++)
2172 {
2173 struct entity *entity = &dll->entities.base[k];
2174 if (entity->kind == ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION)
2175 {
2176 if (!strncmpiW(section_name->Buffer, entity->u.class.name, snlen) && !entity->u.class.name[snlen])
2177 return fill_keyed_data(data, entity, dll, i);
2178 }
2179 }
2180 }
2181 }
2182 return STATUS_SXS_KEY_NOT_FOUND;
2183 }
2184
2185 static NTSTATUS find_string(ACTIVATION_CONTEXT* actctx, ULONG section_kind,
2186 const UNICODE_STRING *section_name,
2187 DWORD flags, PACTCTX_SECTION_KEYED_DATA data)
2188 {
2189 NTSTATUS status;
2190
2191 switch (section_kind)
2192 {
2193 case ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION:
2194 status = find_dll_redirection(actctx, section_name, data);
2195 break;
2196 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION:
2197 status = find_window_class(actctx, section_name, data);
2198 break;
2199 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION:
2200 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION:
2201 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION:
2202 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION:
2203 case ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE:
2204 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES:
2205 DPRINT1("Unsupported yet section_kind %x\n", section_kind);
2206 return STATUS_SXS_SECTION_NOT_FOUND;
2207 default:
2208 DPRINT1("Unknown section_kind %x\n", section_kind);
2209 return STATUS_SXS_SECTION_NOT_FOUND;
2210 }
2211
2212 if (status != STATUS_SUCCESS) return status;
2213
2214 if (flags & FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX)
2215 {
2216 actctx_addref(actctx);
2217 data->hActCtx = actctx;
2218 }
2219 return STATUS_SUCCESS;
2220 }
2221
2222 /* initialize the activation context for the current process */
2223 void actctx_init(void)
2224 {
2225 ACTCTXW ctx;
2226 HANDLE handle;
2227
2228 ctx.cbSize = sizeof(ctx);
2229 ctx.lpSource = NULL;
2230 ctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_HMODULE_VALID;
2231 ctx.hModule = NtCurrentTeb()->ProcessEnvironmentBlock->ImageBaseAddress;
2232 ctx.lpResourceName = (LPCWSTR)CREATEPROCESS_MANIFEST_RESOURCE_ID;
2233
2234 if (!RtlCreateActivationContext( &handle, &ctx )) process_actctx = check_actctx(handle);
2235 }
2236
2237 /* FUNCTIONS ***************************************************************/
2238
2239 NTSTATUS WINAPI RtlCreateActivationContext( HANDLE *handle, void *ptr )
2240 {
2241 const ACTCTXW *pActCtx = ptr;
2242 const WCHAR *directory = NULL;
2243 ACTIVATION_CONTEXT *actctx;
2244 UNICODE_STRING nameW;
2245 ULONG lang = 0;
2246 NTSTATUS status = STATUS_NO_MEMORY;
2247 HANDLE file = 0;
2248 struct actctx_loader acl;
2249
2250 DPRINT("%p %08x\n", pActCtx, pActCtx ? pActCtx->dwFlags : 0);
2251
2252 if (!pActCtx || pActCtx->cbSize < sizeof(*pActCtx) ||
2253 (pActCtx->dwFlags & ~ACTCTX_FLAGS_ALL))
2254 return STATUS_INVALID_PARAMETER;
2255
2256
2257 if (!(actctx = RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*actctx) )))
2258 return STATUS_NO_MEMORY;
2259
2260 actctx->magic = ACTCTX_MAGIC;
2261 actctx->ref_count = 1;
2262 actctx->config.type = ACTIVATION_CONTEXT_PATH_TYPE_NONE;
2263 actctx->config.info = NULL;
2264 actctx->appdir.type = ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE;
2265 if (pActCtx->dwFlags & ACTCTX_FLAG_APPLICATION_NAME_VALID)
2266 {
2267 if (!(actctx->appdir.info = strdupW( pActCtx->lpApplicationName ))) goto error;
2268 }
2269 else
2270 {
2271 UNICODE_STRING dir;
2272 WCHAR *p;
2273 HMODULE module;
2274
2275 if (pActCtx->dwFlags & ACTCTX_FLAG_HMODULE_VALID) module = pActCtx->hModule;
2276 else module = NtCurrentTeb()->ProcessEnvironmentBlock->ImageBaseAddress;
2277
2278 if ((status = get_module_filename( module, &dir, 0 ))) goto error;
2279 if ((p = strrchrW( dir.Buffer, '\\' ))) p[1] = 0;
2280 actctx->appdir.info = dir.Buffer;
2281 }
2282
2283 nameW.Buffer = NULL;
2284 if (pActCtx->lpSource)
2285 {
2286 if (!RtlDosPathNameToNtPathName_U(pActCtx->lpSource, &nameW, NULL, NULL))
2287 {
2288 status = STATUS_NO_SUCH_FILE;
2289 goto error;
2290 }
2291 status = open_nt_file( &file, &nameW );
2292 if (status)
2293 {
2294 RtlFreeUnicodeString( &nameW );
2295 goto error;
2296 }
2297 }
2298
2299 acl.actctx = actctx;
2300 acl.dependencies = NULL;
2301 acl.num_dependencies = 0;
2302 acl.allocated_dependencies = 0;
2303
2304 if (pActCtx->dwFlags & ACTCTX_FLAG_LANGID_VALID) lang = pActCtx->wLangId;
2305 if (pActCtx->dwFlags & ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID) directory = pActCtx->lpAssemblyDirectory;
2306
2307 if (pActCtx->dwFlags & ACTCTX_FLAG_RESOURCE_NAME_VALID)
2308 {
2309 /* if we have a resource it's a PE file */
2310 if (pActCtx->dwFlags & ACTCTX_FLAG_HMODULE_VALID)
2311 {
2312 status = get_manifest_in_module( &acl, NULL, NULL, directory, FALSE, pActCtx->hModule,
2313 pActCtx->lpResourceName, lang );
2314 if (status && status != STATUS_SXS_CANT_GEN_ACTCTX)
2315 /* FIXME: what to do if pActCtx->lpSource is set */
2316 status = get_manifest_in_associated_manifest( &acl, NULL, NULL, directory,
2317 pActCtx->hModule, pActCtx->lpResourceName );
2318 }
2319 else if (pActCtx->lpSource)
2320 {
2321 status = get_manifest_in_pe_file( &acl, NULL, nameW.Buffer, directory, FALSE,
2322 file, pActCtx->lpResourceName, lang );
2323 if (status && status != STATUS_SXS_CANT_GEN_ACTCTX)
2324 status = get_manifest_in_associated_manifest( &acl, NULL, nameW.Buffer, directory,
2325 NULL, pActCtx->lpResourceName );
2326 }
2327 else status = STATUS_INVALID_PARAMETER;
2328 }
2329 else
2330 {
2331 status = get_manifest_in_manifest_file( &acl, NULL, nameW.Buffer, directory, FALSE, file );
2332 }
2333
2334 if (file) NtClose( file );
2335 RtlFreeUnicodeString( &nameW );
2336
2337 if (status == STATUS_SUCCESS) status = parse_depend_manifests(&acl);
2338 free_depend_manifests( &acl );
2339
2340 if (status == STATUS_SUCCESS) *handle = actctx;
2341 else actctx_release( actctx );
2342 return status;
2343
2344 error:
2345 if (file) NtClose( file );
2346 actctx_release( actctx );
2347 return status;
2348 }
2349
2350 VOID
2351 NTAPI
2352 RtlAddRefActivationContext(HANDLE handle)
2353 {
2354 ACTIVATION_CONTEXT *actctx;
2355
2356 if ((actctx = check_actctx( handle ))) actctx_addref( actctx );
2357 }
2358
2359 VOID
2360 NTAPI
2361 RtlReleaseActivationContext( HANDLE handle )
2362 {
2363 ACTIVATION_CONTEXT *actctx;
2364
2365 if ((actctx = check_actctx( handle ))) actctx_release( actctx );
2366 }
2367
2368 NTSTATUS
2369 NTAPI RtlActivateActivationContextEx( ULONG flags, PTEB tebAddress, HANDLE handle, PULONG_PTR cookie )
2370 {
2371 RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame;
2372
2373 if (!(frame = RtlAllocateHeap( RtlGetProcessHeap(), 0, sizeof(*frame) )))
2374 return STATUS_NO_MEMORY;
2375
2376 frame->Previous = tebAddress->ActivationContextStackPointer->ActiveFrame;
2377 frame->ActivationContext = handle;
2378 frame->Flags = 0;
2379
2380 tebAddress->ActivationContextStackPointer->ActiveFrame = frame;
2381 RtlAddRefActivationContext( handle );
2382
2383 *cookie = (ULONG_PTR)frame;
2384 DPRINT( "%p cookie=%lx\n", handle, *cookie );
2385 return STATUS_SUCCESS;
2386 }
2387
2388
2389 NTSTATUS
2390 NTAPI RtlActivateActivationContext( ULONG flags, HANDLE handle, PULONG_PTR cookie )
2391 {
2392 return RtlActivateActivationContextEx(flags, NtCurrentTeb(), handle, cookie);
2393 }
2394
2395 NTSTATUS
2396 NTAPI
2397 RtlDeactivateActivationContext( ULONG flags, ULONG_PTR cookie )
2398 {
2399 RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame, *top;
2400
2401 DPRINT( "%x cookie=%lx\n", flags, cookie );
2402
2403 /* find the right frame */
2404 top = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame;
2405 for (frame = top; frame; frame = frame->Previous)
2406 if ((ULONG_PTR)frame == cookie) break;
2407
2408 if (!frame)
2409 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION );
2410
2411 if (frame != top && !(flags & DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION))
2412 RtlRaiseStatus( STATUS_SXS_EARLY_DEACTIVATION );
2413
2414 /* pop everything up to and including frame */
2415 NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame = frame->Previous;
2416
2417 while (top != NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame)
2418 {
2419 frame = top->Previous;
2420 RtlReleaseActivationContext( top->ActivationContext );
2421 RtlFreeHeap( RtlGetProcessHeap(), 0, top );
2422 top = frame;
2423 }
2424
2425 return STATUS_SUCCESS;
2426 }
2427
2428 VOID
2429 NTAPI
2430 RtlFreeActivationContextStack(PACTIVATION_CONTEXT_STACK Stack)
2431 {
2432 PRTL_ACTIVATION_CONTEXT_STACK_FRAME ActiveFrame, PrevFrame;
2433
2434 /* Nothing to do if there is no stack */
2435 if (!Stack) return;
2436
2437 /* Get the current active frame */
2438 ActiveFrame = Stack->ActiveFrame;
2439
2440 /* Go through them in backwards order and release */
2441 while (ActiveFrame)
2442 {
2443 PrevFrame = ActiveFrame->Previous;
2444 RtlReleaseActivationContext(ActiveFrame->ActivationContext);
2445 RtlFreeHeap(RtlGetProcessHeap(), 0, ActiveFrame);
2446 ActiveFrame = PrevFrame;
2447 }
2448
2449 /* Zero out the active frame */
2450 Stack->ActiveFrame = NULL;
2451
2452 /* TODO: Empty the Frame List Cache */
2453 ASSERT(IsListEmpty(&Stack->FrameListCache));
2454
2455 /* Free activation stack memory */
2456 RtlFreeHeap(RtlGetProcessHeap(), 0, Stack);
2457 }
2458
2459 VOID
2460 NTAPI RtlFreeThreadActivationContextStack(void)
2461 {
2462 RtlFreeActivationContextStack(NtCurrentTeb()->ActivationContextStackPointer);
2463 NtCurrentTeb()->ActivationContextStackPointer = NULL;
2464 }
2465
2466
2467 NTSTATUS
2468 NTAPI RtlGetActiveActivationContext( HANDLE *handle )
2469 {
2470 if (NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame)
2471 {
2472 *handle = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame->ActivationContext;
2473 RtlAddRefActivationContext( *handle );
2474 }
2475 else
2476 *handle = 0;
2477
2478 return STATUS_SUCCESS;
2479 }
2480
2481
2482 BOOLEAN
2483 NTAPI RtlIsActivationContextActive( HANDLE handle )
2484 {
2485 RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame;
2486
2487 for (frame = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame; frame; frame = frame->Previous)
2488 if (frame->ActivationContext == handle) return TRUE;
2489 return FALSE;
2490 }
2491
2492 NTSTATUS
2493 NTAPI
2494 RtlQueryInformationActivationContext( ULONG flags, HANDLE handle, PVOID subinst,
2495 ULONG class, PVOID buffer,
2496 SIZE_T bufsize, SIZE_T *retlen )
2497 {
2498 ACTIVATION_CONTEXT *actctx;
2499 NTSTATUS status;
2500
2501 DPRINT("%08x %p %p %u %p %ld %p\n", flags, handle,
2502 subinst, class, buffer, bufsize, retlen);
2503
2504 if (retlen) *retlen = 0;
2505 if ((status = find_query_actctx( &handle, flags, class ))) return status;
2506
2507 switch (class)
2508 {
2509 case ActivationContextBasicInformation:
2510 {
2511 ACTIVATION_CONTEXT_BASIC_INFORMATION *info = buffer;
2512
2513 if (retlen) *retlen = sizeof(*info);
2514 if (!info || bufsize < sizeof(*info)) return STATUS_BUFFER_TOO_SMALL;
2515
2516 info->hActCtx = handle;
2517 info->dwFlags = 0; /* FIXME */
2518 if (!(flags & QUERY_ACTCTX_FLAG_NO_ADDREF)) RtlAddRefActivationContext( handle );
2519 }
2520 break;
2521
2522 case ActivationContextDetailedInformation:
2523 {
2524 ACTIVATION_CONTEXT_DETAILED_INFORMATION *acdi = buffer;
2525 struct assembly *assembly = NULL;
2526 SIZE_T len, manifest_len = 0, config_len = 0, appdir_len = 0;
2527 LPWSTR ptr;
2528
2529 if (!(actctx = check_actctx(handle))) return STATUS_INVALID_PARAMETER;
2530
2531 if (actctx->num_assemblies) assembly = actctx->assemblies;
2532
2533 if (assembly && assembly->manifest.info)
2534 manifest_len = strlenW(assembly->manifest.info) + 1;
2535 if (actctx->config.info) config_len = strlenW(actctx->config.info) + 1;
2536 if (actctx->appdir.info) appdir_len = strlenW(actctx->appdir.info) + 1;
2537 len = sizeof(*acdi) + (manifest_len + config_len + appdir_len) * sizeof(WCHAR);
2538
2539 if (retlen) *retlen = len;
2540 if (!buffer || bufsize < len) return STATUS_BUFFER_TOO_SMALL;
2541
2542 acdi->dwFlags = 0;
2543 acdi->ulFormatVersion = assembly ? 1 : 0; /* FIXME */
2544 acdi->ulAssemblyCount = actctx->num_assemblies;
2545 acdi->ulRootManifestPathType = assembly ? assembly->manifest.type : 0 /* FIXME */;
2546 acdi->ulRootManifestPathChars = assembly && assembly->manifest.info ? (DWORD)manifest_len - 1 : 0;
2547 acdi->ulRootConfigurationPathType = actctx->config.type;
2548 acdi->ulRootConfigurationPathChars = actctx->config.info ? (DWORD)config_len - 1 : 0;
2549 acdi->ulAppDirPathType = actctx->appdir.type;
2550 acdi->ulAppDirPathChars = actctx->appdir.info ? (DWORD)appdir_len - 1 : 0;
2551 ptr = (LPWSTR)(acdi + 1);
2552 if (manifest_len)
2553 {
2554 acdi->lpRootManifestPath = ptr;
2555 memcpy(ptr, assembly->manifest.info, manifest_len * sizeof(WCHAR));
2556 ptr += manifest_len;
2557 }
2558 else acdi->lpRootManifestPath = NULL;
2559 if (config_len)
2560 {
2561 acdi->lpRootConfigurationPath = ptr;
2562 memcpy(ptr, actctx->config.info, config_len * sizeof(WCHAR));
2563 ptr += config_len;
2564 }
2565 else acdi->lpRootConfigurationPath = NULL;
2566 if (appdir_len)
2567 {
2568 acdi->lpAppDirPath = ptr;
2569 memcpy(ptr, actctx->appdir.info, appdir_len * sizeof(WCHAR));
2570 }
2571 else acdi->lpAppDirPath = NULL;
2572 }
2573 break;
2574
2575 case AssemblyDetailedInformationInActivationContext:
2576 {
2577 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION *afdi = buffer;
2578 struct assembly *assembly;
2579 WCHAR *assembly_id;
2580 DWORD index;
2581 SIZE_T len, id_len = 0, ad_len = 0, path_len = 0;
2582 LPWSTR ptr;
2583
2584 if (!(actctx = check_actctx(handle))) return STATUS_INVALID_PARAMETER;
2585 if (!subinst) return STATUS_INVALID_PARAMETER;
2586
2587 index = *(DWORD*)subinst;
2588 if (!index || index > actctx->num_assemblies) return STATUS_INVALID_PARAMETER;
2589
2590 assembly = &actctx->assemblies[index - 1];
2591
2592 if (!(assembly_id = build_assembly_id( &assembly->id ))) return STATUS_NO_MEMORY;
2593 id_len = strlenW(assembly_id) + 1;
2594 if (assembly->directory) ad_len = strlenW(assembly->directory) + 1;
2595
2596 if (assembly->manifest.info &&
2597 (assembly->type == ASSEMBLY_MANIFEST || assembly->type == ASSEMBLY_SHARED_MANIFEST))
2598 path_len = strlenW(assembly->manifest.info) + 1;
2599
2600 len = sizeof(*afdi) + (id_len + ad_len + path_len) * sizeof(WCHAR);
2601
2602 if (retlen) *retlen = len;
2603 if (!buffer || bufsize < len)
2604 {
2605 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly_id );
2606 return STATUS_BUFFER_TOO_SMALL;
2607 }
2608
2609 afdi->ulFlags = 0; /* FIXME */
2610 afdi->ulEncodedAssemblyIdentityLength = (DWORD)(id_len - 1) * sizeof(WCHAR);
2611 afdi->ulManifestPathType = assembly->manifest.type;
2612 afdi->ulManifestPathLength = assembly->manifest.info ? (DWORD)(path_len - 1) * sizeof(WCHAR) : 0;
2613 /* FIXME afdi->liManifestLastWriteTime = 0; */
2614 afdi->ulPolicyPathType = ACTIVATION_CONTEXT_PATH_TYPE_NONE; /* FIXME */
2615 afdi->ulPolicyPathLength = 0;
2616 /* FIXME afdi->liPolicyLastWriteTime = 0; */
2617 afdi->ulMetadataSatelliteRosterIndex = 0; /* FIXME */
2618 afdi->ulManifestVersionMajor = 1;
2619 afdi->ulManifestVersionMinor = 0;
2620 afdi->ulPolicyVersionMajor = 0; /* FIXME */
2621 afdi->ulPolicyVersionMinor = 0; /* FIXME */
2622 afdi->ulAssemblyDirectoryNameLength = ad_len ? (DWORD)(ad_len - 1) * sizeof(WCHAR) : 0;
2623 ptr = (LPWSTR)(afdi + 1);
2624 afdi->lpAssemblyEncodedAssemblyIdentity = ptr;
2625 memcpy( ptr, assembly_id, id_len * sizeof(WCHAR) );
2626 ptr += id_len;
2627 if (path_len)
2628 {
2629 afdi->lpAssemblyManifestPath = ptr;
2630 memcpy(ptr, assembly->manifest.info, path_len * sizeof(WCHAR));
2631 ptr += path_len;
2632 } else afdi->lpAssemblyManifestPath = NULL;
2633 afdi->lpAssemblyPolicyPath = NULL; /* FIXME */
2634 if (ad_len)
2635 {
2636 afdi->lpAssemblyDirectoryName = ptr;
2637 memcpy(ptr, assembly->directory, ad_len * sizeof(WCHAR));
2638 ptr += ad_len;
2639 }
2640 else afdi->lpAssemblyDirectoryName = NULL;
2641 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly_id );
2642 }
2643 break;
2644
2645 case FileInformationInAssemblyOfAssemblyInActivationContext:
2646 {
2647 const ACTIVATION_CONTEXT_QUERY_INDEX *acqi = subinst;
2648 ASSEMBLY_FILE_DETAILED_INFORMATION *afdi = buffer;
2649 struct assembly *assembly;
2650 struct dll_redirect *dll;
2651 SIZE_T len, dll_len = 0;
2652 LPWSTR ptr;
2653
2654 if (!(actctx = check_actctx(handle))) return STATUS_INVALID_PARAMETER;
2655 if (!acqi) return STATUS_INVALID_PARAMETER;
2656
2657 if (acqi->ulAssemblyIndex >= actctx->num_assemblies)
2658 return STATUS_INVALID_PARAMETER;
2659 assembly = &actctx->assemblies[acqi->ulAssemblyIndex];
2660
2661 if (acqi->ulFileIndexInAssembly >= assembly->num_dlls)
2662 return STATUS_INVALID_PARAMETER;
2663 dll = &assembly->dlls[acqi->ulFileIndexInAssembly];
2664
2665 if (dll->name) dll_len = strlenW(dll->name) + 1;
2666 len = sizeof(*afdi) + dll_len * sizeof(WCHAR);
2667
2668 if (!buffer || bufsize < len)
2669 {
2670 if (retlen) *retlen = len;
2671 return STATUS_BUFFER_TOO_SMALL;
2672 }
2673 if (retlen) *retlen = 0; /* yes that's what native does !! */
2674 afdi->ulFlags = ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION;
2675 afdi->ulFilenameLength = dll_len ? (DWORD)(dll_len - 1) * sizeof(WCHAR) : 0;
2676 afdi->ulPathLength = 0; /* FIXME */
2677 ptr = (LPWSTR)(afdi + 1);
2678 if (dll_len)
2679 {
2680 afdi->lpFileName = ptr;
2681 memcpy( ptr, dll->name, dll_len * sizeof(WCHAR) );
2682 } else afdi->lpFileName = NULL;
2683 afdi->lpFilePath = NULL; /* FIXME */
2684 }
2685 break;
2686
2687 default:
2688 DPRINT( "class %u not implemented\n", class );
2689 return STATUS_NOT_IMPLEMENTED;
2690 }
2691 return STATUS_SUCCESS;
2692 }
2693
2694 NTSTATUS
2695 NTAPI
2696 RtlQueryInformationActiveActivationContext(ULONG ulInfoClass,
2697 PVOID pvBuffer,
2698 SIZE_T cbBuffer OPTIONAL,
2699 SIZE_T *pcbWrittenOrRequired OPTIONAL)
2700 {
2701 return RtlQueryInformationActivationContext(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX,
2702 NULL,
2703 NULL,
2704 ulInfoClass,
2705 pvBuffer,
2706 cbBuffer,
2707 pcbWrittenOrRequired);
2708 }
2709
2710 #define FIND_ACTCTX_RETURN_FLAGS 0x00000002
2711 #define FIND_ACTCTX_RETURN_ASSEMBLY_METADATA 0x00000004
2712 #define FIND_ACTCTX_VALID_MASK (FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX | FIND_ACTCTX_RETURN_FLAGS | FIND_ACTCTX_RETURN_ASSEMBLY_METADATA)
2713
2714 NTSTATUS
2715 NTAPI
2716 RtlpFindActivationContextSection_CheckParameters( ULONG flags, const GUID *guid, ULONG section_kind,
2717 UNICODE_STRING *section_name, PACTCTX_SECTION_KEYED_DATA data )
2718 {
2719 /* Check general parameter combinations */
2720 if (!section_name ||
2721 (flags & ~FIND_ACTCTX_VALID_MASK) ||
2722 ((flags & FIND_ACTCTX_VALID_MASK) && !data) ||
2723 (data && data->cbSize < offsetof(ACTCTX_SECTION_KEYED_DATA, ulAssemblyRosterIndex)))
2724 {
2725 DPRINT1("invalid parameter\n");
2726 return STATUS_INVALID_PARAMETER;
2727 }
2728
2729 /* TODO */
2730 if (flags & FIND_ACTCTX_RETURN_FLAGS ||
2731 flags & FIND_ACTCTX_RETURN_ASSEMBLY_METADATA)
2732 {
2733 DPRINT1("unknown flags %08x\n", flags);
2734 return STATUS_INVALID_PARAMETER;
2735 }
2736
2737 return STATUS_SUCCESS;
2738 }
2739
2740 NTSTATUS
2741 NTAPI
2742 RtlFindActivationContextSectionString( ULONG flags, const GUID *guid, ULONG section_kind,
2743 UNICODE_STRING *section_name, PVOID ptr )
2744 {
2745 PACTCTX_SECTION_KEYED_DATA data = ptr;
2746 NTSTATUS status;
2747
2748 status = RtlpFindActivationContextSection_CheckParameters(flags, guid, section_kind, section_name, data);
2749 if (!NT_SUCCESS(status)) return status;
2750
2751 status = STATUS_SXS_KEY_NOT_FOUND;
2752
2753 /* if there is no data, but params are valid,
2754 we return that sxs key is not found to be at least somehow compatible */
2755 if (!data) return status;
2756
2757 ASSERT(NtCurrentTeb());
2758 ASSERT(NtCurrentTeb()->ActivationContextStackPointer);
2759
2760 if (NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame)
2761 {
2762 ACTIVATION_CONTEXT *actctx = check_actctx(NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame->ActivationContext);
2763 if (actctx) status = find_string( actctx, section_kind, section_name, flags, data );
2764 }
2765
2766 if (status != STATUS_SUCCESS)
2767 status = find_string( process_actctx, section_kind, section_name, flags, data );
2768
2769 return status;
2770 }
2771
2772 /* Stubs */
2773
2774 NTSTATUS
2775 NTAPI
2776 RtlAllocateActivationContextStack(IN PVOID *Context)
2777 {
2778 PACTIVATION_CONTEXT_STACK ContextStack;
2779
2780 /* Check if it's already allocated */
2781 if (*Context) return STATUS_SUCCESS;
2782
2783 /* Allocate space for the context stack */
2784 ContextStack = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (ACTIVATION_CONTEXT_STACK) );
2785 if (!ContextStack)
2786 {
2787 return STATUS_NO_MEMORY;
2788 }
2789
2790 /* Initialize the context stack */
2791 ContextStack->Flags = 0;
2792 ContextStack->ActiveFrame = NULL;
2793 InitializeListHead(&ContextStack->FrameListCache);
2794 ContextStack->NextCookieSequenceNumber = 1;
2795 ContextStack->StackId = 1; //TODO: Timer-based
2796
2797 *Context = ContextStack;
2798
2799 return STATUS_SUCCESS;
2800 }
2801
2802 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
2803 FASTCALL
2804 RtlActivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame,
2805 IN PVOID Context)
2806 {
2807 #if NEW_NTDLL_LOADER
2808 RTL_ACTIVATION_CONTEXT_STACK_FRAME *ActiveFrame;
2809
2810 /* Get the curren active frame */
2811 ActiveFrame = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame;
2812
2813 DPRINT1("ActiveFrame %p, &Frame->Frame %p, Context %p\n", ActiveFrame, &Frame->Frame, Context);
2814
2815 /* Actually activate it */
2816 Frame->Frame.Previous = ActiveFrame;
2817 Frame->Frame.ActivationContext = Context;
2818 Frame->Frame.Flags = 0;
2819
2820 /* Check if we can activate this context */
2821 if ((ActiveFrame && (ActiveFrame->ActivationContext != Context)) ||
2822 Context)
2823 {
2824 /* Set new active frame */
2825 NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame = &Frame->Frame;
2826 return &Frame->Frame;
2827 }
2828
2829 /* We can get here only one way: it was already activated */
2830 DPRINT1("Trying to activate improper activation context\n");
2831
2832 /* Activate only if we are allowing multiple activation */
2833 if (!RtlpNotAllowingMultipleActivation)
2834 {
2835 NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame = &Frame->Frame;
2836 }
2837 else
2838 {
2839 /* Set flag */
2840 Frame->Frame.Flags = 0x30;
2841 }
2842
2843 /* Return pointer to the activation frame */
2844 return &Frame->Frame;
2845 #else
2846
2847 RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame = &Frame->Frame;
2848
2849 frame->Previous = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame;
2850 frame->ActivationContext = Context;
2851 frame->Flags = 0;
2852
2853 NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame = frame;
2854
2855 return STATUS_SUCCESS;
2856 #endif
2857 }
2858
2859 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
2860 FASTCALL
2861 RtlDeactivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame)
2862 {
2863 RTL_ACTIVATION_CONTEXT_STACK_FRAME *frame;
2864 //RTL_ACTIVATION_CONTEXT_STACK_FRAME *top;
2865
2866 /* find the right frame */
2867 //top = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame;
2868 frame = &Frame->Frame;
2869
2870 if (!frame)
2871 {
2872 DPRINT1("No top frame!\n");
2873 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION );
2874 }
2875
2876 /* pop everything up to and including frame */
2877 NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame = frame->Previous;
2878
2879 return frame;
2880 }
2881
2882
2883 NTSTATUS
2884 NTAPI
2885 RtlZombifyActivationContext(PVOID Context)
2886 {
2887 UNIMPLEMENTED;
2888
2889 if (Context == ACTCTX_FAKE_HANDLE)
2890 return STATUS_SUCCESS;
2891
2892 return STATUS_NOT_IMPLEMENTED;
2893 }
2894