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
9 * Jacek Caban for CodeWeavers
11 * Stefan Ginsberg (stefan__100__@hotmail.com)
15 /* Based on Wine 1.1.26 */
17 /* INCLUDES *****************************************************************/
23 #include <wine/unicode.h>
25 BOOLEAN RtlpNotAllowingMultipleActivation
;
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 )
37 #define ACTCTX_MAGIC 0xC07E3E11
39 #define ACTCTX_FAKE_HANDLE ((HANDLE) 0xf00baa)
40 #define ACTCTX_FAKE_COOKIE ((ULONG_PTR) 0xf00bad)
62 struct assembly_version
70 struct assembly_identity
77 struct assembly_version version
;
121 unsigned int allocated
;
128 struct entity_array entities
;
133 APPLICATION_MANIFEST
,
135 ASSEMBLY_SHARED_MANIFEST
,
140 enum assembly_type type
;
141 struct assembly_identity id
;
142 struct file_info manifest
;
145 struct dll_redirect
*dlls
;
146 unsigned int num_dlls
;
147 unsigned int allocated_dlls
;
148 struct entity_array entities
;
151 typedef struct _ACTIVATION_CONTEXT
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
;
164 ACTIVATION_CONTEXT
*actctx
;
165 struct assembly_identity
*dependencies
;
166 unsigned int num_dependencies
;
167 unsigned int allocated_dependencies
;
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};
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};
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};
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};
213 static ACTIVATION_CONTEXT system_actctx
= { ACTCTX_MAGIC
, 1 };
214 static ACTIVATION_CONTEXT
*process_actctx
= &system_actctx
;
216 static WCHAR
*strdupW(const WCHAR
* str
)
220 if (!(ptr
= RtlAllocateHeap(RtlGetProcessHeap(), 0, (strlenW(str
) + 1) * sizeof(WCHAR
))))
222 return strcpyW(ptr
, str
);
225 static WCHAR
*xmlstrdupW(const xmlstr_t
* str
)
229 if ((strW
= RtlAllocateHeap(RtlGetProcessHeap(), 0, (str
->len
+ 1) * sizeof(WCHAR
))))
231 memcpy( strW
, str
->ptr
, str
->len
* sizeof(WCHAR
) );
237 static UNICODE_STRING
xmlstr2unicode(const xmlstr_t
*xmlstr
)
241 res
.Buffer
= (PWSTR
)xmlstr
->ptr
;
242 res
.Length
= res
.MaximumLength
= (USHORT
)xmlstr
->len
* sizeof(WCHAR
);
247 static inline BOOL
xmlstr_cmp(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
249 return !strncmpW(xmlstr
->ptr
, str
, xmlstr
->len
) && !str
[xmlstr
->len
];
252 static inline BOOL
xmlstr_cmpi(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
254 return !strncmpiW(xmlstr
->ptr
, str
, xmlstr
->len
) && !str
[xmlstr
->len
];
257 static inline BOOL
xmlstr_cmp_end(const xmlstr_t
* xmlstr
, const WCHAR
*str
)
259 return (xmlstr
->len
&& xmlstr
->ptr
[0] == '/' &&
260 !strncmpW(xmlstr
->ptr
+ 1, str
, xmlstr
->len
- 1) && !str
[xmlstr
->len
- 1]);
263 static inline BOOL
isxmlspace( WCHAR ch
)
265 return (ch
== ' ' || ch
== '\r' || ch
== '\n' || ch
== '\t');
268 static struct assembly
*add_assembly(ACTIVATION_CONTEXT
*actctx
, enum assembly_type at
)
270 struct assembly
*assembly
;
272 if (actctx
->num_assemblies
== actctx
->allocated_assemblies
)
275 unsigned int new_count
;
276 if (actctx
->assemblies
)
278 new_count
= actctx
->allocated_assemblies
* 2;
279 ptr
= RtlReAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
280 actctx
->assemblies
, new_count
* sizeof(*assembly
) );
285 ptr
= RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*assembly
) );
287 if (!ptr
) return NULL
;
288 actctx
->assemblies
= ptr
;
289 actctx
->allocated_assemblies
= new_count
;
292 assembly
= &actctx
->assemblies
[actctx
->num_assemblies
++];
297 static struct dll_redirect
* add_dll_redirect(struct assembly
* assembly
)
299 if (assembly
->num_dlls
== assembly
->allocated_dlls
)
302 unsigned int new_count
;
305 new_count
= assembly
->allocated_dlls
* 2;
306 ptr
= RtlReAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
307 assembly
->dlls
, new_count
* sizeof(*assembly
->dlls
) );
312 ptr
= RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*assembly
->dlls
) );
314 if (!ptr
) return NULL
;
315 assembly
->dlls
= ptr
;
316 assembly
->allocated_dlls
= new_count
;
318 return &assembly
->dlls
[assembly
->num_dlls
++];
321 static void free_assembly_identity(struct assembly_identity
*ai
)
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
);
330 static struct entity
* add_entity(struct entity_array
*array
, DWORD kind
)
332 struct entity
* entity
;
334 if (array
->num
== array
->allocated
)
337 unsigned int new_count
;
340 new_count
= array
->allocated
* 2;
341 ptr
= RtlReAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
,
342 array
->base
, new_count
* sizeof(*array
->base
) );
347 ptr
= RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, new_count
* sizeof(*array
->base
) );
349 if (!ptr
) return NULL
;
351 array
->allocated
= new_count
;
353 entity
= &array
->base
[array
->num
++];
358 static void free_entity_array(struct entity_array
*array
)
361 for (i
= 0; i
< array
->num
; i
++)
363 struct entity
*entity
= &array
->base
[i
];
364 switch (entity
->kind
)
366 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
:
367 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.comclass
.clsid
);
369 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
:
370 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.proxy
.iid
);
371 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.proxy
.name
);
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
);
378 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
379 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.class.name
);
381 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
:
382 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.clrclass
.name
);
383 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.clrclass
.clsid
);
385 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
:
386 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.clrsurrogate
.name
);
387 RtlFreeHeap(RtlGetProcessHeap(), 0, entity
->u
.clrsurrogate
.clsid
);
390 DPRINT1("Unknown entity kind %u\n", entity
->kind
);
393 RtlFreeHeap( RtlGetProcessHeap(), 0, array
->base
);
396 static BOOL
is_matching_string( const WCHAR
*str1
, const WCHAR
*str2
)
398 if (!str1
) return !str2
;
399 return str2
&& !strcmpiW( str1
, str2
);
402 static BOOL
is_matching_identity( const struct assembly_identity
*id1
,
403 const struct assembly_identity
*id2
)
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
;
409 if (id1
->language
&& id2
->language
&& strcmpiW( id1
->language
, id2
->language
))
411 static const WCHAR wildcardW
[] = {'*',0};
412 if (strcmpW( wildcardW
, id1
->language
) && strcmpW( wildcardW
, id2
->language
))
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
;
423 static BOOL
add_dependent_assembly_id(struct actctx_loader
* acl
,
424 struct assembly_identity
* ai
)
428 /* check if we already have that assembly */
430 for (i
= 0; i
< acl
->actctx
->num_assemblies
; i
++)
431 if (is_matching_identity( ai
, &acl
->actctx
->assemblies
[i
].id
))
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
);
439 for (i
= 0; i
< acl
->num_dependencies
; i
++)
440 if (is_matching_identity( ai
, &acl
->dependencies
[i
] ))
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
);
448 if (acl
->num_dependencies
== acl
->allocated_dependencies
)
451 unsigned int new_count
;
452 if (acl
->dependencies
)
454 new_count
= acl
->allocated_dependencies
* 2;
455 ptr
= RtlReAllocateHeap(RtlGetProcessHeap(), 0, acl
->dependencies
,
456 new_count
* sizeof(acl
->dependencies
[0]));
461 ptr
= RtlAllocateHeap(RtlGetProcessHeap(), 0, new_count
* sizeof(acl
->dependencies
[0]));
463 if (!ptr
) return FALSE
;
464 acl
->dependencies
= ptr
;
465 acl
->allocated_dependencies
= new_count
;
467 acl
->dependencies
[acl
->num_dependencies
++] = *ai
;
472 static void free_depend_manifests(struct actctx_loader
* acl
)
475 for (i
= 0; i
< acl
->num_dependencies
; i
++)
476 free_assembly_identity(&acl
->dependencies
[i
]);
477 RtlFreeHeap(RtlGetProcessHeap(), 0, acl
->dependencies
);
480 static WCHAR
*build_assembly_dir(struct assembly_identity
* ai
)
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};
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
);
494 if (!(ret
= RtlAllocateHeap( RtlGetProcessHeap(), 0, size
))) return NULL
;
496 strcpyW( ret
, arch
);
497 strcatW( ret
, undW
);
498 strcatW( ret
, name
);
499 strcatW( ret
, undW
);
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
);
511 static inline void append_string( WCHAR
*buffer
, const WCHAR
*prefix
, const WCHAR
*str
)
516 strcatW( buffer
, prefix
);
525 static WCHAR
*build_assembly_id( const struct assembly_identity
*ai
)
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};
532 WCHAR version
[64], *ret
;
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;
543 if (!(ret
= RtlAllocateHeap( RtlGetProcessHeap(), 0, (size
+ 1) * sizeof(WCHAR
) )))
546 if (ai
->name
) strcpyW( ret
, ai
->name
);
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
);
555 static ACTIVATION_CONTEXT
*check_actctx( HANDLE h
)
557 ACTIVATION_CONTEXT
*ret
= NULL
, *actctx
= h
;
559 if (!h
|| h
== INVALID_HANDLE_VALUE
) return NULL
;
562 if (actctx
&& actctx
->magic
== ACTCTX_MAGIC
) ret
= actctx
;
564 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
566 DPRINT1("Invalid activation context handle!\n");
572 static inline void actctx_addref( ACTIVATION_CONTEXT
*actctx
)
574 InterlockedExchangeAdd( &actctx
->ref_count
, 1 );
577 static void actctx_release( ACTIVATION_CONTEXT
*actctx
)
579 if (InterlockedExchangeAdd( &actctx
->ref_count
, -1 ) == 1)
583 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
585 struct assembly
*assembly
= &actctx
->assemblies
[i
];
586 for (j
= 0; j
< assembly
->num_dlls
; j
++)
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
);
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
);
599 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx
->config
.info
);
600 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx
->appdir
.info
);
601 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx
->assemblies
);
603 RtlFreeHeap( RtlGetProcessHeap(), 0, actctx
);
607 static BOOL
next_xml_attr(xmlbuf_t
* xmlbuf
, xmlstr_t
* name
, xmlstr_t
* value
,
608 BOOL
* error
, BOOL
* end
)
614 while (xmlbuf
->ptr
< xmlbuf
->end
&& isxmlspace(*xmlbuf
->ptr
))
617 if (xmlbuf
->ptr
== xmlbuf
->end
) return FALSE
;
619 if (*xmlbuf
->ptr
== '/')
622 if (xmlbuf
->ptr
== xmlbuf
->end
|| *xmlbuf
->ptr
!= '>')
631 if (*xmlbuf
->ptr
== '>')
639 while (ptr
< xmlbuf
->end
&& *ptr
!= '=' && *ptr
!= '>' && !isxmlspace(*ptr
)) ptr
++;
641 if (ptr
== xmlbuf
->end
|| *ptr
!= '=') return FALSE
;
643 name
->ptr
= xmlbuf
->ptr
;
644 name
->len
= (ULONG
)(ptr
- xmlbuf
->ptr
);
648 if (ptr
== xmlbuf
->end
|| (*ptr
!= '"' && *ptr
!= '\'')) return FALSE
;
651 if (ptr
== xmlbuf
->end
) return FALSE
;
653 ptr
= memchrW(ptr
, ptr
[-1], xmlbuf
->end
- ptr
);
656 xmlbuf
->ptr
= xmlbuf
->end
;
660 value
->len
= (ULONG
)(ptr
- value
->ptr
);
661 xmlbuf
->ptr
= ptr
+ 1;
663 if (xmlbuf
->ptr
== xmlbuf
->end
) return FALSE
;
669 static BOOL
next_xml_elem(xmlbuf_t
* xmlbuf
, xmlstr_t
* elem
)
675 ptr
= memchrW(xmlbuf
->ptr
, '<', xmlbuf
->end
- xmlbuf
->ptr
);
678 xmlbuf
->ptr
= xmlbuf
->end
;
682 if (ptr
+ 3 < xmlbuf
->end
&& ptr
[0] == '!' && ptr
[1] == '-' && ptr
[2] == '-') /* skip comment */
684 for (ptr
+= 3; ptr
+ 3 <= xmlbuf
->end
; ptr
++)
685 if (ptr
[0] == '-' && ptr
[1] == '-' && ptr
[2] == '>') break;
687 if (ptr
+ 3 > xmlbuf
->end
)
689 xmlbuf
->ptr
= xmlbuf
->end
;
692 xmlbuf
->ptr
= ptr
+ 3;
698 while (ptr
< xmlbuf
->end
&& !isxmlspace(*ptr
) && *ptr
!= '>' && (*ptr
!= '/' || ptr
== xmlbuf
->ptr
))
701 elem
->ptr
= xmlbuf
->ptr
;
702 elem
->len
= (ULONG
)(ptr
- xmlbuf
->ptr
);
704 return xmlbuf
->ptr
!= xmlbuf
->end
;
707 static BOOL
parse_xml_header(xmlbuf_t
* xmlbuf
)
709 /* FIXME: parse attributes */
712 for (ptr
= xmlbuf
->ptr
; ptr
< xmlbuf
->end
- 1; ptr
++)
714 if (ptr
[0] == '?' && ptr
[1] == '>')
716 xmlbuf
->ptr
= ptr
+ 2;
723 static BOOL
parse_text_content(xmlbuf_t
* xmlbuf
, xmlstr_t
* content
)
725 const WCHAR
*ptr
= memchrW(xmlbuf
->ptr
, '<', xmlbuf
->end
- xmlbuf
->ptr
);
727 if (!ptr
) return FALSE
;
729 content
->ptr
= xmlbuf
->ptr
;
730 content
->len
= (ULONG
)(ptr
- xmlbuf
->ptr
);
736 static BOOL
parse_version(const xmlstr_t
*str
, struct assembly_version
*version
)
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
++)
747 if (*curr
>= '0' && *curr
<= '9')
749 ver
[pos
] = ver
[pos
] * 10 + *curr
- '0';
750 if (ver
[pos
] >= 0x10000) goto error
;
752 else if (*curr
== '.')
754 if (++pos
>= 4) goto error
;
758 version
->major
= ver
[0];
759 version
->minor
= ver
[1];
760 version
->build
= ver
[2];
761 version
->revision
= ver
[3];
765 strU
= xmlstr2unicode(str
);
766 DPRINT1( "Wrong version definition in manifest file (%wZ)\n", &strU
);
770 static BOOL
parse_expect_elem(xmlbuf_t
* xmlbuf
, const WCHAR
* name
)
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
);
781 static BOOL
parse_expect_no_attr(xmlbuf_t
* xmlbuf
, BOOL
* end
)
783 xmlstr_t attr_name
, attr_value
;
784 UNICODE_STRING attr_nameU
, attr_valueU
;
787 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, end
))
789 attr_nameU
= xmlstr2unicode(&attr_name
);
790 attr_valueU
= xmlstr2unicode(&attr_value
);
791 DPRINT1( "unexpected attr %wZ=%wZ\n", &attr_nameU
,
797 static BOOL
parse_end_element(xmlbuf_t
*xmlbuf
)
800 return parse_expect_no_attr(xmlbuf
, &end
) && !end
;
803 static BOOL
parse_expect_end_elem(xmlbuf_t
*xmlbuf
, const WCHAR
*name
)
806 UNICODE_STRING elemU
;
807 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
808 if (!xmlstr_cmp_end(&elem
, name
))
810 elemU
= xmlstr2unicode(&elem
);
811 DPRINT1( "unexpected element %wZ\n", &elemU
);
814 return parse_end_element(xmlbuf
);
817 static BOOL
parse_unknown_elem(xmlbuf_t
*xmlbuf
, const xmlstr_t
*unknown_elem
)
819 xmlstr_t attr_name
, attr_value
, elem
;
820 BOOL end
= FALSE
, error
, ret
= TRUE
;
822 while(next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
));
823 if(error
|| end
) return end
;
825 while(ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
827 if(*elem
.ptr
== '/' && elem
.len
- 1 == unknown_elem
->len
&&
828 !strncmpW(elem
.ptr
+1, unknown_elem
->ptr
, unknown_elem
->len
))
831 ret
= parse_unknown_elem(xmlbuf
, &elem
);
834 return ret
&& parse_end_element(xmlbuf
);
837 static BOOL
parse_assembly_identity_elem(xmlbuf_t
* xmlbuf
, ACTIVATION_CONTEXT
* actctx
,
838 struct assembly_identity
* ai
)
840 xmlstr_t attr_name
, attr_value
;
841 BOOL end
= FALSE
, error
;
842 UNICODE_STRING attr_valueU
, attr_nameU
;
844 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
846 if (xmlstr_cmp(&attr_name
, g_nameW
))
848 if (!(ai
->name
= xmlstrdupW(&attr_value
))) return FALSE
;
850 else if (xmlstr_cmp(&attr_name
, typeW
))
852 if (!(ai
->type
= xmlstrdupW(&attr_value
))) return FALSE
;
854 else if (xmlstr_cmp(&attr_name
, versionW
))
856 if (!parse_version(&attr_value
, &ai
->version
)) return FALSE
;
858 else if (xmlstr_cmp(&attr_name
, processorArchitectureW
))
860 if (!(ai
->arch
= xmlstrdupW(&attr_value
))) return FALSE
;
862 else if (xmlstr_cmp(&attr_name
, publicKeyTokenW
))
864 if (!(ai
->public_key
= xmlstrdupW(&attr_value
))) return FALSE
;
866 else if (xmlstr_cmp(&attr_name
, languageW
))
868 if (!(ai
->language
= xmlstrdupW(&attr_value
))) return FALSE
;
869 DPRINT1("Unsupported yet language attribute (%S)\n",
874 attr_nameU
= xmlstr2unicode(&attr_name
);
875 attr_valueU
= xmlstr2unicode(&attr_value
);
876 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
880 if (error
|| end
) return end
;
881 return parse_expect_end_elem(xmlbuf
, assemblyIdentityW
);
884 static BOOL
parse_com_class_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
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
;
891 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
)))
894 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
896 if (xmlstr_cmp(&attr_name
, clsidW
))
898 if (!(entity
->u
.comclass
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
902 attr_nameU
= xmlstr2unicode(&attr_name
);
903 attr_valueU
= xmlstr2unicode(&attr_value
);
904 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
908 if (error
|| end
) return end
;
910 while ((ret
= next_xml_elem(xmlbuf
, &elem
)))
912 if (xmlstr_cmp_end(&elem
, comClassW
))
914 ret
= parse_end_element(xmlbuf
);
919 attr_nameU
= xmlstr2unicode(&elem
);
920 DPRINT1("unknown elem %wZ\n", &attr_nameU
);
921 ret
= parse_unknown_elem(xmlbuf
, &elem
);
927 static BOOL
parse_cominterface_proxy_stub_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
929 xmlstr_t attr_name
, attr_value
;
930 BOOL end
= FALSE
, error
;
931 struct entity
* entity
;
932 UNICODE_STRING attr_valueU
, attr_nameU
;
934 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
)))
937 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
939 if (xmlstr_cmp(&attr_name
, iidW
))
941 if (!(entity
->u
.proxy
.iid
= xmlstrdupW(&attr_value
))) return FALSE
;
943 if (xmlstr_cmp(&attr_name
, g_nameW
))
945 if (!(entity
->u
.proxy
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
949 attr_nameU
= xmlstr2unicode(&attr_name
);
950 attr_valueU
= xmlstr2unicode(&attr_value
);
951 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
955 if (error
|| end
) return end
;
956 return parse_expect_end_elem(xmlbuf
, comInterfaceProxyStubW
);
959 static BOOL
parse_typelib_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
961 xmlstr_t attr_name
, attr_value
;
962 BOOL end
= FALSE
, error
;
963 struct entity
* entity
;
964 UNICODE_STRING attr_valueU
, attr_nameU
;
966 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
)))
969 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
971 if (xmlstr_cmp(&attr_name
, tlbidW
))
973 if (!(entity
->u
.typelib
.tlbid
= xmlstrdupW(&attr_value
))) return FALSE
;
975 if (xmlstr_cmp(&attr_name
, versionW
))
977 if (!(entity
->u
.typelib
.version
= xmlstrdupW(&attr_value
))) return FALSE
;
979 if (xmlstr_cmp(&attr_name
, helpdirW
))
981 if (!(entity
->u
.typelib
.helpdir
= xmlstrdupW(&attr_value
))) return FALSE
;
985 attr_nameU
= xmlstr2unicode(&attr_name
);
986 attr_valueU
= xmlstr2unicode(&attr_value
);
987 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
991 if (error
|| end
) return end
;
992 return parse_expect_end_elem(xmlbuf
, typelibW
);
995 static BOOL
parse_window_class_elem(xmlbuf_t
* xmlbuf
, struct dll_redirect
* dll
)
997 xmlstr_t elem
, content
;
998 BOOL end
= FALSE
, ret
= TRUE
;
999 struct entity
* entity
;
1000 UNICODE_STRING elemU
;
1002 if (!(entity
= add_entity(&dll
->entities
, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)))
1005 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1006 if (end
) return FALSE
;
1008 if (!parse_text_content(xmlbuf
, &content
)) return FALSE
;
1010 if (!(entity
->u
.class.name
= xmlstrdupW(&content
))) return FALSE
;
1012 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1014 if (xmlstr_cmp_end(&elem
, windowClassW
))
1016 ret
= parse_end_element(xmlbuf
);
1021 elemU
= xmlstr2unicode(&elem
);
1022 DPRINT1("unknown elem %wZ\n", &elemU
);
1023 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1030 static BOOL
parse_binding_redirect_elem(xmlbuf_t
* xmlbuf
)
1032 xmlstr_t attr_name
, attr_value
;
1033 UNICODE_STRING attr_valueU
, attr_nameU
;
1034 BOOL end
= FALSE
, error
;
1036 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1038 attr_nameU
= xmlstr2unicode(&attr_name
);
1039 attr_valueU
= xmlstr2unicode(&attr_value
);
1041 if (xmlstr_cmp(&attr_name
, oldVersionW
))
1043 DPRINT1("Not stored yet oldVersion=%wZ\n", &attr_valueU
);
1045 else if (xmlstr_cmp(&attr_name
, newVersionW
))
1047 DPRINT1("Not stored yet newVersion=%wZ\n", &attr_valueU
);
1051 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
1055 if (error
|| end
) return end
;
1056 return parse_expect_end_elem(xmlbuf
, bindingRedirectW
);
1059 static BOOL
parse_description_elem(xmlbuf_t
* xmlbuf
)
1061 xmlstr_t elem
, content
;
1062 UNICODE_STRING elemU
;
1063 BOOL end
= FALSE
, ret
= TRUE
;
1065 if (!parse_expect_no_attr(xmlbuf
, &end
) || end
||
1066 !parse_text_content(xmlbuf
, &content
))
1069 elemU
= xmlstr2unicode(&content
);
1070 DPRINT("Got description %wZ\n", &elemU
);
1072 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1074 if (xmlstr_cmp_end(&elem
, descriptionW
))
1076 ret
= parse_end_element(xmlbuf
);
1081 elemU
= xmlstr2unicode(&elem
);
1082 DPRINT1("unknown elem %wZ\n", &elemU
);
1083 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1090 static BOOL
parse_com_interface_external_proxy_stub_elem(xmlbuf_t
* xmlbuf
,
1091 struct assembly
* assembly
)
1093 xmlstr_t attr_name
, attr_value
;
1094 BOOL end
= FALSE
, error
;
1095 struct entity
* entity
;
1097 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
);
1098 if (!entity
) return FALSE
;
1100 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1102 if (xmlstr_cmp(&attr_name
, iidW
))
1104 if (!(entity
->u
.proxy
.iid
= xmlstrdupW(&attr_value
))) return FALSE
;
1106 if (xmlstr_cmp(&attr_name
, g_nameW
))
1108 if (!(entity
->u
.proxy
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1112 DPRINT1("unknown attr %S=%S\n", attr_name
.ptr
, attr_value
.ptr
);
1116 if (error
|| end
) return end
;
1117 return parse_expect_end_elem(xmlbuf
, comInterfaceExternalProxyStubW
);
1120 static BOOL
parse_clr_class_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1122 xmlstr_t attr_name
, attr_value
;
1123 UNICODE_STRING attr_nameU
, attr_valueU
;
1124 BOOL end
= FALSE
, error
;
1125 struct entity
* entity
;
1127 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
);
1128 if (!entity
) return FALSE
;
1130 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1132 if (xmlstr_cmp(&attr_name
, g_nameW
))
1134 if (!(entity
->u
.clrclass
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1136 else if (xmlstr_cmp(&attr_name
, clsidW
))
1138 if (!(entity
->u
.clrclass
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
1142 attr_nameU
= xmlstr2unicode(&attr_name
);
1143 attr_valueU
= xmlstr2unicode(&attr_value
);
1144 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
1148 if (error
|| end
) return end
;
1149 return parse_expect_end_elem(xmlbuf
, clrClassW
);
1152 static BOOL
parse_clr_surrogate_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
1154 xmlstr_t attr_name
, attr_value
;
1155 UNICODE_STRING attr_nameU
, attr_valueU
;
1156 BOOL end
= FALSE
, error
;
1157 struct entity
* entity
;
1159 entity
= add_entity(&assembly
->entities
, ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
);
1160 if (!entity
) return FALSE
;
1162 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1164 if (xmlstr_cmp(&attr_name
, g_nameW
))
1166 if (!(entity
->u
.clrsurrogate
.name
= xmlstrdupW(&attr_value
))) return FALSE
;
1168 else if (xmlstr_cmp(&attr_name
, clsidW
))
1170 if (!(entity
->u
.clrsurrogate
.clsid
= xmlstrdupW(&attr_value
))) return FALSE
;
1174 attr_nameU
= xmlstr2unicode(&attr_name
);
1175 attr_valueU
= xmlstr2unicode(&attr_value
);
1176 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
1180 if (error
|| end
) return end
;
1181 return parse_expect_end_elem(xmlbuf
, clrSurrogateW
);
1184 static BOOL
parse_dependent_assembly_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
, BOOL optional
)
1186 struct assembly_identity ai
;
1188 BOOL end
= FALSE
, ret
= TRUE
;
1190 if (!parse_expect_no_attr(xmlbuf
, &end
) || end
) return end
;
1192 memset(&ai
, 0, sizeof(ai
));
1193 ai
.optional
= optional
;
1195 if (!parse_expect_elem(xmlbuf
, assemblyIdentityW
) ||
1196 !parse_assembly_identity_elem(xmlbuf
, acl
->actctx
, &ai
))
1199 /* store the newly found identity for later loading */
1200 if (!add_dependent_assembly_id(acl
, &ai
)) return FALSE
;
1202 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1204 if (xmlstr_cmp_end(&elem
, dependentAssemblyW
))
1206 ret
= parse_end_element(xmlbuf
);
1209 else if (xmlstr_cmp(&elem
, bindingRedirectW
))
1211 ret
= parse_binding_redirect_elem(xmlbuf
);
1215 DPRINT1("unknown elem %S\n", elem
.ptr
);
1216 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1223 static BOOL
parse_dependency_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
)
1225 xmlstr_t attr_name
, attr_value
, elem
;
1226 UNICODE_STRING attr_nameU
, attr_valueU
;
1227 BOOL end
= FALSE
, ret
= TRUE
, error
, optional
= FALSE
;
1229 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1231 attr_nameU
= xmlstr2unicode(&attr_name
);
1232 attr_valueU
= xmlstr2unicode(&attr_value
);
1234 if (xmlstr_cmp(&attr_name
, optionalW
))
1236 static const WCHAR yesW
[] = {'y','e','s',0};
1237 optional
= xmlstr_cmpi( &attr_value
, yesW
);
1238 DPRINT1("optional=%wZ\n", &attr_valueU
);
1242 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
1246 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1248 if (xmlstr_cmp_end(&elem
, dependencyW
))
1250 ret
= parse_end_element(xmlbuf
);
1253 else if (xmlstr_cmp(&elem
, dependentAssemblyW
))
1255 ret
= parse_dependent_assembly_elem(xmlbuf
, acl
, optional
);
1259 attr_nameU
= xmlstr2unicode(&elem
);
1260 DPRINT1("unknown element %wZ\n", &attr_nameU
);
1261 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1268 static BOOL
parse_noinherit_elem(xmlbuf_t
* xmlbuf
)
1272 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1273 return end
|| parse_expect_end_elem(xmlbuf
, noInheritW
);
1276 static BOOL
parse_noinheritable_elem(xmlbuf_t
* xmlbuf
)
1280 if (!parse_expect_no_attr(xmlbuf
, &end
)) return FALSE
;
1281 return end
|| parse_expect_end_elem(xmlbuf
, noInheritableW
);
1284 static BOOL
parse_file_elem(xmlbuf_t
* xmlbuf
, struct assembly
* assembly
)
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
;
1291 if (!(dll
= add_dll_redirect(assembly
))) return FALSE
;
1293 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1295 attr_nameU
= xmlstr2unicode(&attr_name
);
1296 attr_valueU
= xmlstr2unicode(&attr_value
);
1298 if (xmlstr_cmp(&attr_name
, g_nameW
))
1300 if (!(dll
->name
= xmlstrdupW(&attr_value
))) return FALSE
;
1301 DPRINT("name=%wZ\n", &attr_valueU
);
1303 else if (xmlstr_cmp(&attr_name
, hashW
))
1305 if (!(dll
->hash
= xmlstrdupW(&attr_value
))) return FALSE
;
1307 else if (xmlstr_cmp(&attr_name
, hashalgW
))
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
);
1315 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
1319 if (error
|| !dll
->name
) return FALSE
;
1320 if (end
) return TRUE
;
1322 while (ret
&& (ret
= next_xml_elem(xmlbuf
, &elem
)))
1324 if (xmlstr_cmp_end(&elem
, fileW
))
1326 ret
= parse_end_element(xmlbuf
);
1329 else if (xmlstr_cmp(&elem
, comClassW
))
1331 ret
= parse_com_class_elem(xmlbuf
, dll
);
1333 else if (xmlstr_cmp(&elem
, comInterfaceProxyStubW
))
1335 ret
= parse_cominterface_proxy_stub_elem(xmlbuf
, dll
);
1337 else if (xmlstr_cmp(&elem
, asmv2hashW
))
1339 DPRINT1("asmv2hash (undocumented) not supported\n");
1340 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1342 else if (xmlstr_cmp(&elem
, typelibW
))
1344 ret
= parse_typelib_elem(xmlbuf
, dll
);
1346 else if (xmlstr_cmp(&elem
, windowClassW
))
1348 ret
= parse_window_class_elem(xmlbuf
, dll
);
1352 attr_nameU
= xmlstr2unicode(&elem
);
1353 DPRINT1("unknown elem %wZ\n", &attr_nameU
);
1354 ret
= parse_unknown_elem( xmlbuf
, &elem
);
1361 static BOOL
parse_assembly_elem(xmlbuf_t
* xmlbuf
, struct actctx_loader
* acl
,
1362 struct assembly
* assembly
,
1363 struct assembly_identity
* expected_ai
)
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
;
1369 while (next_xml_attr(xmlbuf
, &attr_name
, &attr_value
, &error
, &end
))
1371 attr_nameU
= xmlstr2unicode(&attr_name
);
1372 attr_valueU
= xmlstr2unicode(&attr_value
);
1374 if (xmlstr_cmp(&attr_name
, manifestVersionW
))
1376 static const WCHAR v10W
[] = {'1','.','0',0};
1377 if (!xmlstr_cmp(&attr_value
, v10W
))
1379 DPRINT1("wrong version %wZ\n", &attr_valueU
);
1384 else if (xmlstr_cmp(&attr_name
, xmlnsW
))
1386 if (!xmlstr_cmp(&attr_value
, manifestv1W
) && !xmlstr_cmp(&attr_value
, manifestv3W
))
1388 DPRINT1("wrong namespace %wZ\n", &attr_valueU
);
1395 DPRINT1("unknown attr %wZ=%wZ\n", &attr_nameU
, &attr_valueU
);
1399 if (error
|| end
|| !xmlns
|| !version
) return FALSE
;
1400 if (!next_xml_elem(xmlbuf
, &elem
)) return FALSE
;
1402 if (assembly
->type
== APPLICATION_MANIFEST
&& xmlstr_cmp(&elem
, noInheritW
))
1404 if (!parse_noinherit_elem(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
))
1406 assembly
->no_inherit
= TRUE
;
1409 if (xmlstr_cmp(&elem
, noInheritableW
))
1411 if (!parse_noinheritable_elem(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
))
1414 else if ((assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
) &&
1415 assembly
->no_inherit
)
1420 if (xmlstr_cmp_end(&elem
, assemblyW
))
1422 ret
= parse_end_element(xmlbuf
);
1425 else if (xmlstr_cmp(&elem
, descriptionW
))
1427 ret
= parse_description_elem(xmlbuf
);
1429 else if (xmlstr_cmp(&elem
, comInterfaceExternalProxyStubW
))
1431 ret
= parse_com_interface_external_proxy_stub_elem(xmlbuf
, assembly
);
1433 else if (xmlstr_cmp(&elem
, dependencyW
))
1435 ret
= parse_dependency_elem(xmlbuf
, acl
);
1437 else if (xmlstr_cmp(&elem
, fileW
))
1439 ret
= parse_file_elem(xmlbuf
, assembly
);
1441 else if (xmlstr_cmp(&elem
, clrClassW
))
1443 ret
= parse_clr_class_elem(xmlbuf
, assembly
);
1445 else if (xmlstr_cmp(&elem
, clrSurrogateW
))
1447 ret
= parse_clr_surrogate_elem(xmlbuf
, assembly
);
1449 else if (xmlstr_cmp(&elem
, assemblyIdentityW
))
1451 if (!parse_assembly_identity_elem(xmlbuf
, acl
->actctx
, &assembly
->id
)) return FALSE
;
1455 /* FIXME: more tests */
1456 if (assembly
->type
== ASSEMBLY_MANIFEST
&&
1457 memcmp(&assembly
->id
.version
, &expected_ai
->version
, sizeof(assembly
->id
.version
)))
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
);
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
)))
1473 DPRINT1("wrong version for shared assembly manifest\n");
1480 attr_nameU
= xmlstr2unicode(&elem
);
1481 DPRINT1("unknown element %wZ\n", &attr_nameU
);
1482 ret
= parse_unknown_elem(xmlbuf
, &elem
);
1484 if (ret
) ret
= next_xml_elem(xmlbuf
, &elem
);
1490 static NTSTATUS
parse_manifest_buffer( struct actctx_loader
* acl
, struct assembly
*assembly
,
1491 struct assembly_identity
* ai
, xmlbuf_t
*xmlbuf
)
1494 UNICODE_STRING elemU
;
1496 if (!next_xml_elem(xmlbuf
, &elem
)) return STATUS_SXS_CANT_GEN_ACTCTX
;
1498 if (xmlstr_cmp(&elem
, g_xmlW
) &&
1499 (!parse_xml_header(xmlbuf
) || !next_xml_elem(xmlbuf
, &elem
)))
1500 return STATUS_SXS_CANT_GEN_ACTCTX
;
1502 if (!xmlstr_cmp(&elem
, assemblyW
))
1504 elemU
= xmlstr2unicode(&elem
);
1505 DPRINT1("root element is %wZ, not <assembly>\n", &elemU
);
1506 return STATUS_SXS_CANT_GEN_ACTCTX
;
1509 if (!parse_assembly_elem(xmlbuf
, acl
, assembly
, ai
))
1511 DPRINT1("failed to parse manifest %S\n", assembly
->manifest
.info
);
1512 return STATUS_SXS_CANT_GEN_ACTCTX
;
1515 if (next_xml_elem(xmlbuf
, &elem
))
1517 elemU
= xmlstr2unicode(&elem
);
1518 DPRINT1("unexpected element %wZ\n", &elemU
);
1519 return STATUS_SXS_CANT_GEN_ACTCTX
;
1522 if (xmlbuf
->ptr
!= xmlbuf
->end
)
1524 DPRINT1("parse error\n");
1525 return STATUS_SXS_CANT_GEN_ACTCTX
;
1527 return STATUS_SUCCESS
;
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
)
1536 struct assembly
*assembly
;
1539 DPRINT( "parsing manifest loaded from %S base dir %S\n", filename
, directory
);
1541 if (!(assembly
= add_assembly(acl
->actctx
, shared
? ASSEMBLY_SHARED_MANIFEST
: ASSEMBLY_MANIFEST
)))
1542 return STATUS_SXS_CANT_GEN_ACTCTX
;
1544 if (directory
&& !(assembly
->directory
= strdupW(directory
)))
1545 return STATUS_NO_MEMORY
;
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
;
1551 unicode_tests
= IS_TEXT_UNICODE_SIGNATURE
| IS_TEXT_UNICODE_REVERSE_SIGNATURE
;
1552 if (RtlIsTextUnicode((PVOID
)buffer
, (ULONG
)size
, &unicode_tests
))
1554 xmlbuf
.ptr
= buffer
;
1555 xmlbuf
.end
= xmlbuf
.ptr
+ size
/ sizeof(WCHAR
);
1556 status
= parse_manifest_buffer( acl
, assembly
, ai
, &xmlbuf
);
1558 else if (unicode_tests
& IS_TEXT_UNICODE_REVERSE_SIGNATURE
)
1560 const WCHAR
*buf
= buffer
;
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
);
1575 /* TODO: this doesn't handle arbitrary encodings */
1577 UNICODE_STRING xmlW
;
1579 ASSERT(size
< MAXUSHORT
);
1580 xmlA
.Buffer
= (PCHAR
)buffer
;
1581 xmlA
.Length
= xmlA
.MaximumLength
= (USHORT
)size
;
1585 status
= RtlAnsiStringToUnicodeString(&xmlW
, &xmlA
, TRUE
);
1587 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1589 DPRINT1("Exception accessing buffer\n");
1590 return STATUS_SXS_CANT_GEN_ACTCTX
;
1594 if (!NT_SUCCESS(status
))
1596 DPRINT1("RtlAnsiStringToUnicodeString failed with %lx\n", status
);
1597 return STATUS_SXS_CANT_GEN_ACTCTX
;
1599 ASSERT(xmlW
.Buffer
!= NULL
);
1601 xmlbuf
.ptr
= xmlW
.Buffer
;
1602 xmlbuf
.end
= xmlbuf
.ptr
+ xmlW
.Length
/ sizeof(WCHAR
);
1603 status
= parse_manifest_buffer( acl
, assembly
, ai
, &xmlbuf
);
1605 RtlFreeUnicodeString(&xmlW
);
1610 static NTSTATUS
open_nt_file( HANDLE
*handle
, UNICODE_STRING
*name
)
1612 OBJECT_ATTRIBUTES attr
;
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
,
1622 GENERIC_READ
| SYNCHRONIZE
,
1625 FILE_SYNCHRONOUS_IO_ALERT
);
1628 static NTSTATUS
get_module_filename( HMODULE module
, UNICODE_STRING
*str
, USHORT extra_len
)
1632 LDR_DATA_TABLE_ENTRY
*pldr
;
1634 LdrLockLoaderLock(0, NULL
, &magic
);
1635 status
= LdrFindEntryForAddress( module
, &pldr
);
1636 if (status
== STATUS_SUCCESS
)
1638 if ((str
->Buffer
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
1639 pldr
->FullDllName
.Length
+ extra_len
+ sizeof(WCHAR
) )))
1641 memcpy( str
->Buffer
, pldr
->FullDllName
.Buffer
, pldr
->FullDllName
.Length
+ sizeof(WCHAR
) );
1642 str
->Length
= pldr
->FullDllName
.Length
;
1643 str
->MaximumLength
= pldr
->FullDllName
.Length
+ extra_len
+ sizeof(WCHAR
);
1645 else status
= STATUS_NO_MEMORY
;
1647 LdrUnlockLoaderLock(0, magic
);
1651 static NTSTATUS
get_manifest_in_module( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1652 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
,
1653 HANDLE hModule
, LPCWSTR resname
, ULONG lang
)
1656 UNICODE_STRING nameW
;
1657 LDR_RESOURCE_INFO info
;
1658 IMAGE_RESOURCE_DATA_ENTRY
* entry
= NULL
;
1661 //DPRINT( "looking for res %s in module %p %s\n", resname,
1662 // hModule, filename );
1665 if (TRACE_ON(actctx
))
1667 if (!filename
&& !get_module_filename( hModule
, &nameW
, 0 ))
1669 DPRINT( "looking for res %s in module %p %s\n", debugstr_w(resname
),
1670 hModule
, debugstr_w(nameW
.Buffer
) );
1671 RtlFreeUnicodeString( &nameW
);
1673 else DPRINT( "looking for res %s in module %p %s\n", debugstr_w(resname
),
1674 hModule
, debugstr_w(filename
) );
1678 if (!resname
) return STATUS_INVALID_PARAMETER
;
1680 info
.Type
= (ULONG_PTR
)RT_MANIFEST
;
1681 info
.Language
= lang
;
1682 if (!((ULONG_PTR
)resname
>> 16))
1684 info
.Name
= (ULONG_PTR
)resname
;
1685 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1687 else if (resname
[0] == '#')
1690 RtlInitUnicodeString(&nameW
, resname
+ 1);
1691 if (RtlUnicodeStringToInteger(&nameW
, 10, &value
) != STATUS_SUCCESS
|| HIWORD(value
))
1692 return STATUS_INVALID_PARAMETER
;
1694 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1698 RtlCreateUnicodeString(&nameW
, resname
);
1699 RtlUpcaseUnicodeString(&nameW
, &nameW
, FALSE
);
1700 info
.Name
= (ULONG_PTR
)nameW
.Buffer
;
1701 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1702 RtlFreeUnicodeString(&nameW
);
1704 if (status
== STATUS_SUCCESS
) status
= LdrAccessResource(hModule
, entry
, &ptr
, NULL
);
1706 if (status
== STATUS_SUCCESS
)
1707 status
= parse_manifest(acl
, ai
, filename
, directory
, shared
, ptr
, entry
->Size
);
1712 static NTSTATUS
get_manifest_in_pe_file( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1713 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
,
1714 HANDLE file
, LPCWSTR resname
, ULONG lang
)
1717 OBJECT_ATTRIBUTES attr
;
1719 LARGE_INTEGER offset
;
1724 DPRINT( "looking for res %S in %S\n", resname
, filename
);
1726 attr
.Length
= sizeof(attr
);
1727 attr
.RootDirectory
= 0;
1728 attr
.ObjectName
= NULL
;
1729 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1730 attr
.SecurityDescriptor
= NULL
;
1731 attr
.SecurityQualityOfService
= NULL
;
1734 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
| SECTION_MAP_READ
,
1735 &attr
, &size
, PAGE_READONLY
, SEC_COMMIT
, file
);
1736 if (status
!= STATUS_SUCCESS
) return status
;
1738 offset
.QuadPart
= 0;
1741 status
= NtMapViewOfSection( mapping
, NtCurrentProcess(), &base
, 0, 0, &offset
,
1742 &count
, ViewShare
, 0, PAGE_READONLY
);
1744 if (status
!= STATUS_SUCCESS
) return status
;
1746 if (RtlImageNtHeader(base
)) /* we got a PE file */
1748 HANDLE module
= (HMODULE
)((ULONG_PTR
)base
| 1); /* make it a LOAD_LIBRARY_AS_DATAFILE handle */
1749 status
= get_manifest_in_module( acl
, ai
, filename
, directory
, shared
, module
, resname
, lang
);
1751 else status
= STATUS_INVALID_IMAGE_FORMAT
;
1753 NtUnmapViewOfSection( NtCurrentProcess(), base
);
1757 static NTSTATUS
get_manifest_in_manifest_file( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1758 LPCWSTR filename
, LPCWSTR directory
, BOOL shared
, HANDLE file
)
1760 FILE_STANDARD_INFORMATION info
;
1763 OBJECT_ATTRIBUTES attr
;
1765 LARGE_INTEGER offset
;
1770 DPRINT( "loading manifest file %S\n", filename
);
1772 attr
.Length
= sizeof(attr
);
1773 attr
.RootDirectory
= 0;
1774 attr
.ObjectName
= NULL
;
1775 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1776 attr
.SecurityDescriptor
= NULL
;
1777 attr
.SecurityQualityOfService
= NULL
;
1780 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
| SECTION_MAP_READ
,
1781 &attr
, &size
, PAGE_READONLY
, SEC_COMMIT
, file
);
1783 if (status
!= STATUS_SUCCESS
) return status
;
1785 offset
.QuadPart
= 0;
1788 status
= NtMapViewOfSection( mapping
, NtCurrentProcess(), &base
, 0, 0, &offset
,
1789 &count
, ViewShare
, 0, PAGE_READONLY
);
1791 if (status
!= STATUS_SUCCESS
) return status
;
1793 /* Fixme: WINE uses FileEndOfFileInformation with NtQueryInformationFile. */
1794 status
= NtQueryInformationFile( file
, &io
, &info
, sizeof(info
), FileStandardInformation
);
1796 if (status
== STATUS_SUCCESS
)
1797 status
= parse_manifest(acl
, ai
, filename
, directory
, shared
, base
, (SIZE_T
)info
.EndOfFile
.QuadPart
);
1799 NtUnmapViewOfSection( NtCurrentProcess(), base
);
1804 /* try to load the .manifest file associated to the file */
1805 static NTSTATUS
get_manifest_in_associated_manifest( struct actctx_loader
* acl
, struct assembly_identity
* ai
,
1806 LPCWSTR filename
, LPCWSTR directory
, HMODULE module
, LPCWSTR resname
)
1808 static const WCHAR fmtW
[] = { '.','%','l','u',0 };
1811 UNICODE_STRING nameW
;
1813 ULONG_PTR resid
= (ULONG_PTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
1815 if (!((ULONG_PTR
)resname
>> 16)) resid
= (ULONG_PTR
)resname
& 0xffff;
1817 DPRINT( "looking for manifest associated with %S id %lu\n", filename
, resid
);
1819 if (module
) /* use the module filename */
1821 UNICODE_STRING name
;
1823 if (!(status
= get_module_filename( module
, &name
, sizeof(dotManifestW
) + 10*sizeof(WCHAR
) )))
1825 if (resid
!= 1) sprintfW( name
.Buffer
+ strlenW(name
.Buffer
), fmtW
, resid
);
1826 strcatW( name
.Buffer
, dotManifestW
);
1827 if (!RtlDosPathNameToNtPathName_U( name
.Buffer
, &nameW
, NULL
, NULL
))
1828 status
= STATUS_RESOURCE_DATA_NOT_FOUND
;
1829 RtlFreeUnicodeString( &name
);
1831 if (status
) return status
;
1835 if (!(buffer
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
1836 (strlenW(filename
) + 10) * sizeof(WCHAR
) + sizeof(dotManifestW
) )))
1837 return STATUS_NO_MEMORY
;
1838 strcpyW( buffer
, filename
);
1839 if (resid
!= 1) sprintfW( buffer
+ strlenW(buffer
), fmtW
, resid
);
1840 strcatW( buffer
, dotManifestW
);
1841 RtlInitUnicodeString( &nameW
, buffer
);
1844 if (!open_nt_file( &file
, &nameW
))
1846 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
1849 else status
= STATUS_RESOURCE_DATA_NOT_FOUND
;
1850 RtlFreeUnicodeString( &nameW
);
1854 static WCHAR
*lookup_manifest_file( HANDLE dir
, struct assembly_identity
*ai
)
1856 static const WCHAR lookup_fmtW
[] =
1857 {'%','s','_','%','s','_','%','s','_','%','u','.','%','u','.','*','.','*','_',
1859 '.','m','a','n','i','f','e','s','t',0};
1861 WCHAR
*lookup
, *ret
= NULL
;
1862 UNICODE_STRING lookup_us
;
1864 unsigned int data_pos
= 0, data_len
;
1867 if (!(lookup
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
1868 (strlenW(ai
->arch
) + strlenW(ai
->name
)
1869 + strlenW(ai
->public_key
) + 20) * sizeof(WCHAR
)
1870 + sizeof(lookup_fmtW
) )))
1873 sprintfW( lookup
, lookup_fmtW
, ai
->arch
, ai
->name
, ai
->public_key
, ai
->version
.major
, ai
->version
.minor
);
1874 RtlInitUnicodeString( &lookup_us
, lookup
);
1876 NtQueryDirectoryFile( dir
, 0, NULL
, NULL
, &io
, buffer
, sizeof(buffer
),
1877 FileBothDirectoryInformation
, FALSE
, &lookup_us
, TRUE
);
1878 if (io
.Status
== STATUS_SUCCESS
)
1880 FILE_BOTH_DIR_INFORMATION
*dir_info
;
1882 ULONG build
, revision
;
1884 data_len
= (ULONG
)io
.Information
;
1888 if (data_pos
>= data_len
)
1890 NtQueryDirectoryFile( dir
, 0, NULL
, NULL
, &io
, buffer
, sizeof(buffer
),
1891 FileBothDirectoryInformation
, FALSE
, &lookup_us
, FALSE
);
1892 if (io
.Status
!= STATUS_SUCCESS
) break;
1893 data_len
= (ULONG
)io
.Information
;
1896 dir_info
= (FILE_BOTH_DIR_INFORMATION
*)(buffer
+ data_pos
);
1898 if (dir_info
->NextEntryOffset
) data_pos
+= dir_info
->NextEntryOffset
;
1899 else data_pos
= data_len
;
1901 tmp
= (WCHAR
*)dir_info
->FileName
+ (strchrW(lookup
, '*') - lookup
);
1903 if (build
< ai
->version
.build
) continue;
1904 tmp
= strchrW(tmp
, '.') + 1;
1905 revision
= atoiW(tmp
);
1906 if (build
== ai
->version
.build
&& revision
< ai
->version
.revision
)
1908 ai
->version
.build
= (USHORT
)build
;
1909 ai
->version
.revision
= (USHORT
)revision
;
1911 if ((ret
= RtlAllocateHeap( RtlGetProcessHeap(), 0, dir_info
->FileNameLength
* sizeof(WCHAR
) )))
1913 memcpy( ret
, dir_info
->FileName
, dir_info
->FileNameLength
);
1914 ret
[dir_info
->FileNameLength
/sizeof(WCHAR
)] = 0;
1919 else DPRINT1("no matching file for %S\n", lookup
);
1920 RtlFreeHeap( RtlGetProcessHeap(), 0, lookup
);
1924 static NTSTATUS
lookup_winsxs(struct actctx_loader
* acl
, struct assembly_identity
* ai
)
1926 struct assembly_identity sxs_ai
;
1927 UNICODE_STRING path_us
;
1928 OBJECT_ATTRIBUTES attr
;
1930 WCHAR
*path
, *file
= NULL
;
1933 static const WCHAR manifest_dirW
[] =
1934 {'\\','w','i','n','s','x','s','\\','m','a','n','i','f','e','s','t','s',0};
1936 if (!ai
->arch
|| !ai
->name
|| !ai
->public_key
) return STATUS_NO_SUCH_FILE
;
1938 if (!(path
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
1939 ((strlenW(SharedUserData
->NtSystemRoot
) + 1) *sizeof(WCHAR
)) + sizeof(manifest_dirW
) )))
1940 return STATUS_NO_MEMORY
;
1942 memcpy( path
, SharedUserData
->NtSystemRoot
, strlenW(SharedUserData
->NtSystemRoot
) * sizeof(WCHAR
) );
1943 memcpy( path
+ strlenW(SharedUserData
->NtSystemRoot
), manifest_dirW
, sizeof(manifest_dirW
) );
1945 if (!RtlDosPathNameToNtPathName_U( path
, &path_us
, NULL
, NULL
))
1947 RtlFreeHeap( RtlGetProcessHeap(), 0, path
);
1948 return STATUS_NO_SUCH_FILE
;
1950 RtlFreeHeap( RtlGetProcessHeap(), 0, path
);
1952 attr
.Length
= sizeof(attr
);
1953 attr
.RootDirectory
= 0;
1954 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1955 attr
.ObjectName
= &path_us
;
1956 attr
.SecurityDescriptor
= NULL
;
1957 attr
.SecurityQualityOfService
= NULL
;
1959 if (!NtOpenFile(&handle
,
1960 GENERIC_READ
| SYNCHRONIZE
,
1962 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1963 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
))
1966 file
= lookup_manifest_file( handle
, &sxs_ai
);
1971 RtlFreeUnicodeString( &path_us
);
1972 return STATUS_NO_SUCH_FILE
;
1975 /* append file name to directory path */
1976 if (!(path
= RtlReAllocateHeap( RtlGetProcessHeap(), 0, path_us
.Buffer
,
1977 path_us
.Length
+ (strlenW(file
) + 2) * sizeof(WCHAR
) )))
1979 RtlFreeHeap( RtlGetProcessHeap(), 0, file
);
1980 RtlFreeUnicodeString( &path_us
);
1981 return STATUS_NO_MEMORY
;
1984 path
[path_us
.Length
/sizeof(WCHAR
)] = '\\';
1985 strcpyW( path
+ path_us
.Length
/sizeof(WCHAR
) + 1, file
);
1986 RtlInitUnicodeString( &path_us
, path
);
1987 *strrchrW(file
, '.') = 0; /* remove .manifest extension */
1989 if (!open_nt_file( &handle
, &path_us
))
1991 io
.Status
= get_manifest_in_manifest_file(acl
, &sxs_ai
, path_us
.Buffer
, file
, TRUE
, handle
);
1994 else io
.Status
= STATUS_NO_SUCH_FILE
;
1996 RtlFreeHeap( RtlGetProcessHeap(), 0, file
);
1997 RtlFreeUnicodeString( &path_us
);
2001 static NTSTATUS
lookup_assembly(struct actctx_loader
* acl
,
2002 struct assembly_identity
* ai
)
2004 static const WCHAR dotDllW
[] = {'.','d','l','l',0};
2006 WCHAR
*buffer
, *p
, *directory
;
2008 UNICODE_STRING nameW
;
2011 DPRINT( "looking for name=%S version=%u.%u.%u.%u arch=%S\n",
2012 ai
->name
, ai
->version
.major
, ai
->version
.minor
, ai
->version
.build
, ai
->version
.revision
, ai
->arch
);
2014 if ((status
= lookup_winsxs(acl
, ai
)) != STATUS_NO_SUCH_FILE
) return status
;
2016 /* FIXME: add support for language specific lookup */
2018 nameW
.Buffer
= NULL
;
2019 if (!(buffer
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
2020 (strlenW(acl
->actctx
->appdir
.info
) + 2 * strlenW(ai
->name
) + 2) * sizeof(WCHAR
) + sizeof(dotManifestW
) )))
2021 return STATUS_NO_MEMORY
;
2023 if (!(directory
= build_assembly_dir( ai
)))
2025 RtlFreeHeap( RtlGetProcessHeap(), 0, buffer
);
2026 return STATUS_NO_MEMORY
;
2029 /* lookup in appdir\name.dll
2030 * appdir\name.manifest
2031 * appdir\name\name.dll
2032 * appdir\name\name.manifest
2034 strcpyW( buffer
, acl
->actctx
->appdir
.info
);
2035 p
= buffer
+ strlenW(buffer
);
2036 for (i
= 0; i
< 2; i
++)
2039 strcpyW( p
, ai
->name
);
2042 strcpyW( p
, dotDllW
);
2043 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
2045 status
= open_nt_file( &file
, &nameW
);
2048 status
= get_manifest_in_pe_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
,
2049 (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
, 0 );
2053 RtlFreeUnicodeString( &nameW
);
2056 strcpyW( p
, dotManifestW
);
2057 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
2059 status
= open_nt_file( &file
, &nameW
);
2062 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
2066 RtlFreeUnicodeString( &nameW
);
2068 status
= STATUS_SXS_ASSEMBLY_NOT_FOUND
;
2070 RtlFreeUnicodeString( &nameW
);
2071 RtlFreeHeap( RtlGetProcessHeap(), 0, directory
);
2072 RtlFreeHeap( RtlGetProcessHeap(), 0, buffer
);
2076 static NTSTATUS
parse_depend_manifests(struct actctx_loader
* acl
)
2078 NTSTATUS status
= STATUS_SUCCESS
;
2081 for (i
= 0; i
< acl
->num_dependencies
; i
++)
2083 if (lookup_assembly(acl
, &acl
->dependencies
[i
]) != STATUS_SUCCESS
)
2085 if (!acl
->dependencies
[i
].optional
)
2087 DPRINT1( "Could not find dependent assembly %S\n", acl
->dependencies
[i
].name
);
2088 status
= STATUS_SXS_CANT_GEN_ACTCTX
;
2093 /* FIXME should now iterate through all refs */
2097 /* find the appropriate activation context for RtlQueryInformationActivationContext */
2098 static NTSTATUS
find_query_actctx( HANDLE
*handle
, DWORD flags
, ULONG
class )
2100 NTSTATUS status
= STATUS_SUCCESS
;
2102 if (flags
& QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX
)
2104 if (*handle
) return STATUS_INVALID_PARAMETER
;
2106 if (NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2107 *handle
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
->ActivationContext
;
2109 else if (flags
& (QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS
|QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
))
2112 LDR_DATA_TABLE_ENTRY
*pldr
;
2114 if (!*handle
) return STATUS_INVALID_PARAMETER
;
2116 LdrLockLoaderLock( 0, NULL
, &magic
);
2117 if (!LdrFindEntryForAddress( *handle
, &pldr
))
2119 if ((flags
& QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
) && *handle
!= pldr
->DllBase
)
2120 status
= STATUS_DLL_NOT_FOUND
;
2122 *handle
= pldr
->EntryPointActivationContext
;
2124 else status
= STATUS_DLL_NOT_FOUND
;
2125 LdrUnlockLoaderLock( 0, magic
);
2127 else if (!*handle
&& (class != ActivationContextBasicInformation
))
2128 *handle
= process_actctx
;
2133 static NTSTATUS
fill_keyed_data(PACTCTX_SECTION_KEYED_DATA data
, PVOID v1
, PVOID v2
, unsigned int i
)
2135 data
->ulDataFormatVersion
= 1;
2137 data
->ulLength
= 20; /* FIXME */
2138 data
->lpSectionGlobalData
= NULL
; /* FIXME */
2139 data
->ulSectionGlobalDataLength
= 0; /* FIXME */
2140 data
->lpSectionBase
= v2
;
2141 data
->ulSectionTotalLength
= 0; /* FIXME */
2142 data
->hActCtx
= NULL
;
2143 if (data
->cbSize
>= offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
) + sizeof(ULONG
))
2144 data
->ulAssemblyRosterIndex
= i
+ 1;
2146 return STATUS_SUCCESS
;
2149 static NTSTATUS
find_dll_redirection(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2150 PACTCTX_SECTION_KEYED_DATA data
)
2152 unsigned int i
, j
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2154 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2156 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2157 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2159 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2160 if (!strncmpiW(section_name
->Buffer
, dll
->name
, snlen
) && !dll
->name
[snlen
])
2161 return fill_keyed_data(data
, dll
, assembly
, i
);
2164 return STATUS_SXS_KEY_NOT_FOUND
;
2167 static NTSTATUS
find_window_class(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2168 PACTCTX_SECTION_KEYED_DATA data
)
2170 unsigned int i
, j
, k
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2172 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2174 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2175 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2177 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2178 for (k
= 0; k
< dll
->entities
.num
; k
++)
2180 struct entity
*entity
= &dll
->entities
.base
[k
];
2181 if (entity
->kind
== ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)
2183 if (!strncmpiW(section_name
->Buffer
, entity
->u
.class.name
, snlen
) && !entity
->u
.class.name
[snlen
])
2184 return fill_keyed_data(data
, entity
, dll
, i
);
2189 return STATUS_SXS_KEY_NOT_FOUND
;
2192 static NTSTATUS
find_string(ACTIVATION_CONTEXT
* actctx
, ULONG section_kind
,
2193 const UNICODE_STRING
*section_name
,
2194 DWORD flags
, PACTCTX_SECTION_KEYED_DATA data
)
2198 switch (section_kind
)
2200 case ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
:
2201 status
= find_dll_redirection(actctx
, section_name
, data
);
2203 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
2204 status
= find_window_class(actctx
, section_name
, data
);
2206 case ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION
:
2207 case ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION
:
2208 case ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION
:
2209 case ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION
:
2210 case ACTIVATION_CONTEXT_SECTION_GLOBAL_OBJECT_RENAME_TABLE
:
2211 case ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES
:
2212 DPRINT1("Unsupported yet section_kind %x\n", section_kind
);
2213 return STATUS_SXS_SECTION_NOT_FOUND
;
2215 DPRINT1("Unknown section_kind %x\n", section_kind
);
2216 return STATUS_SXS_SECTION_NOT_FOUND
;
2219 if (status
!= STATUS_SUCCESS
) return status
;
2221 if (flags
& FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
)
2223 actctx_addref(actctx
);
2224 data
->hActCtx
= actctx
;
2226 return STATUS_SUCCESS
;
2229 /* initialize the activation context for the current process */
2230 void actctx_init(void)
2235 ctx
.cbSize
= sizeof(ctx
);
2236 ctx
.lpSource
= NULL
;
2237 ctx
.dwFlags
= ACTCTX_FLAG_RESOURCE_NAME_VALID
| ACTCTX_FLAG_HMODULE_VALID
;
2238 ctx
.hModule
= NtCurrentTeb()->ProcessEnvironmentBlock
->ImageBaseAddress
;
2239 ctx
.lpResourceName
= (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
2241 if (!RtlCreateActivationContext( &handle
, &ctx
)) process_actctx
= check_actctx(handle
);
2244 /* FUNCTIONS ***************************************************************/
2246 NTSTATUS WINAPI
RtlCreateActivationContext( HANDLE
*handle
, void *ptr
)
2248 const ACTCTXW
*pActCtx
= ptr
;
2249 const WCHAR
*directory
= NULL
;
2250 ACTIVATION_CONTEXT
*actctx
;
2251 UNICODE_STRING nameW
;
2253 NTSTATUS status
= STATUS_NO_MEMORY
;
2255 struct actctx_loader acl
;
2257 DPRINT("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
2259 if (!pActCtx
|| pActCtx
->cbSize
< sizeof(*pActCtx
) ||
2260 (pActCtx
->dwFlags
& ~ACTCTX_FLAGS_ALL
))
2261 return STATUS_INVALID_PARAMETER
;
2264 if (!(actctx
= RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*actctx
) )))
2265 return STATUS_NO_MEMORY
;
2267 actctx
->magic
= ACTCTX_MAGIC
;
2268 actctx
->ref_count
= 1;
2269 actctx
->config
.type
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
;
2270 actctx
->config
.info
= NULL
;
2271 actctx
->appdir
.type
= ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE
;
2272 if (pActCtx
->dwFlags
& ACTCTX_FLAG_APPLICATION_NAME_VALID
)
2274 if (!(actctx
->appdir
.info
= strdupW( pActCtx
->lpApplicationName
))) goto error
;
2282 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
) module
= pActCtx
->hModule
;
2283 else module
= NtCurrentTeb()->ProcessEnvironmentBlock
->ImageBaseAddress
;
2285 status
= get_module_filename(module
, &dir
, 0);
2286 if (!NT_SUCCESS(status
)) goto error
;
2287 if ((p
= strrchrW( dir
.Buffer
, '\\' ))) p
[1] = 0;
2288 actctx
->appdir
.info
= dir
.Buffer
;
2291 nameW
.Buffer
= NULL
;
2292 if (pActCtx
->lpSource
)
2294 if (!RtlDosPathNameToNtPathName_U(pActCtx
->lpSource
, &nameW
, NULL
, NULL
))
2296 status
= STATUS_NO_SUCH_FILE
;
2299 status
= open_nt_file( &file
, &nameW
);
2300 if (!NT_SUCCESS(status
))
2302 RtlFreeUnicodeString( &nameW
);
2307 acl
.actctx
= actctx
;
2308 acl
.dependencies
= NULL
;
2309 acl
.num_dependencies
= 0;
2310 acl
.allocated_dependencies
= 0;
2312 if (pActCtx
->dwFlags
& ACTCTX_FLAG_LANGID_VALID
) lang
= pActCtx
->wLangId
;
2313 if (pActCtx
->dwFlags
& ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
) directory
= pActCtx
->lpAssemblyDirectory
;
2315 if (pActCtx
->dwFlags
& ACTCTX_FLAG_RESOURCE_NAME_VALID
)
2317 /* if we have a resource it's a PE file */
2318 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
)
2320 status
= get_manifest_in_module( &acl
, NULL
, NULL
, directory
, FALSE
, pActCtx
->hModule
,
2321 pActCtx
->lpResourceName
, lang
);
2322 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2323 /* FIXME: what to do if pActCtx->lpSource is set */
2324 status
= get_manifest_in_associated_manifest( &acl
, NULL
, NULL
, directory
,
2325 pActCtx
->hModule
, pActCtx
->lpResourceName
);
2327 else if (pActCtx
->lpSource
)
2329 status
= get_manifest_in_pe_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
,
2330 file
, pActCtx
->lpResourceName
, lang
);
2331 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2332 status
= get_manifest_in_associated_manifest( &acl
, NULL
, nameW
.Buffer
, directory
,
2333 NULL
, pActCtx
->lpResourceName
);
2335 else status
= STATUS_INVALID_PARAMETER
;
2339 status
= get_manifest_in_manifest_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
, file
);
2342 if (file
) NtClose( file
);
2343 RtlFreeUnicodeString( &nameW
);
2345 if (NT_SUCCESS(status
)) status
= parse_depend_manifests(&acl
);
2346 free_depend_manifests( &acl
);
2348 if (NT_SUCCESS(status
))
2350 else actctx_release( actctx
);
2354 if (file
) NtClose( file
);
2355 actctx_release( actctx
);
2361 RtlAddRefActivationContext(HANDLE handle
)
2363 ACTIVATION_CONTEXT
*actctx
;
2365 if ((actctx
= check_actctx( handle
))) actctx_addref( actctx
);
2370 RtlReleaseActivationContext( HANDLE handle
)
2372 ACTIVATION_CONTEXT
*actctx
;
2374 if ((actctx
= check_actctx( handle
))) actctx_release( actctx
);
2378 NTAPI
RtlActivateActivationContextEx( ULONG flags
, PTEB tebAddress
, HANDLE handle
, PULONG_PTR cookie
)
2380 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2382 if (!(frame
= RtlAllocateHeap( RtlGetProcessHeap(), 0, sizeof(*frame
) )))
2383 return STATUS_NO_MEMORY
;
2385 frame
->Previous
= tebAddress
->ActivationContextStackPointer
->ActiveFrame
;
2386 frame
->ActivationContext
= handle
;
2389 tebAddress
->ActivationContextStackPointer
->ActiveFrame
= frame
;
2390 RtlAddRefActivationContext( handle
);
2392 *cookie
= (ULONG_PTR
)frame
;
2393 DPRINT( "%p cookie=%lx\n", handle
, *cookie
);
2394 return STATUS_SUCCESS
;
2399 NTAPI
RtlActivateActivationContext( ULONG flags
, HANDLE handle
, PULONG_PTR cookie
)
2401 return RtlActivateActivationContextEx(flags
, NtCurrentTeb(), handle
, cookie
);
2406 RtlDeactivateActivationContext( ULONG flags
, ULONG_PTR cookie
)
2408 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
, *top
;
2410 DPRINT( "%x cookie=%lx\n", flags
, cookie
);
2412 /* find the right frame */
2413 top
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
;
2414 for (frame
= top
; frame
; frame
= frame
->Previous
)
2415 if ((ULONG_PTR
)frame
== cookie
) break;
2418 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION
);
2420 if (frame
!= top
&& !(flags
& DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION
))
2421 RtlRaiseStatus( STATUS_SXS_EARLY_DEACTIVATION
);
2423 /* pop everything up to and including frame */
2424 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= frame
->Previous
;
2426 while (top
!= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2428 frame
= top
->Previous
;
2429 RtlReleaseActivationContext( top
->ActivationContext
);
2430 RtlFreeHeap( RtlGetProcessHeap(), 0, top
);
2434 return STATUS_SUCCESS
;
2439 RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack
)
2441 PRTL_ACTIVATION_CONTEXT_STACK_FRAME ActiveFrame
, PrevFrame
;
2443 /* Nothing to do if there is no stack */
2446 /* Get the current active frame */
2447 ActiveFrame
= Stack
->ActiveFrame
;
2449 /* Go through them in backwards order and release */
2452 PrevFrame
= ActiveFrame
->Previous
;
2453 RtlReleaseActivationContext(ActiveFrame
->ActivationContext
);
2454 RtlFreeHeap(RtlGetProcessHeap(), 0, ActiveFrame
);
2455 ActiveFrame
= PrevFrame
;
2458 /* Zero out the active frame */
2459 Stack
->ActiveFrame
= NULL
;
2461 /* TODO: Empty the Frame List Cache */
2462 ASSERT(IsListEmpty(&Stack
->FrameListCache
));
2464 /* Free activation stack memory */
2465 RtlFreeHeap(RtlGetProcessHeap(), 0, Stack
);
2469 NTAPI
RtlFreeThreadActivationContextStack(VOID
)
2471 RtlFreeActivationContextStack(NtCurrentTeb()->ActivationContextStackPointer
);
2472 NtCurrentTeb()->ActivationContextStackPointer
= NULL
;
2477 NTAPI
RtlGetActiveActivationContext( HANDLE
*handle
)
2479 if (NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2481 *handle
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
->ActivationContext
;
2482 RtlAddRefActivationContext( *handle
);
2487 return STATUS_SUCCESS
;
2492 NTAPI
RtlIsActivationContextActive( HANDLE handle
)
2494 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2496 for (frame
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
; frame
; frame
= frame
->Previous
)
2497 if (frame
->ActivationContext
== handle
) return TRUE
;
2503 RtlQueryInformationActivationContext( ULONG flags
, HANDLE handle
, PVOID subinst
,
2504 ULONG
class, PVOID buffer
,
2505 SIZE_T bufsize
, SIZE_T
*retlen
)
2507 ACTIVATION_CONTEXT
*actctx
;
2510 DPRINT("%08x %p %p %u %p %Iu %p\n", flags
, handle
,
2511 subinst
, class, buffer
, bufsize
, retlen
);
2513 if (retlen
) *retlen
= 0;
2514 if ((status
= find_query_actctx( &handle
, flags
, class ))) return status
;
2518 case ActivationContextBasicInformation
:
2520 ACTIVATION_CONTEXT_BASIC_INFORMATION
*info
= buffer
;
2522 if (retlen
) *retlen
= sizeof(*info
);
2523 if (!info
|| bufsize
< sizeof(*info
)) return STATUS_BUFFER_TOO_SMALL
;
2525 info
->hActCtx
= handle
;
2526 info
->dwFlags
= 0; /* FIXME */
2527 if (!(flags
& QUERY_ACTCTX_FLAG_NO_ADDREF
)) RtlAddRefActivationContext( handle
);
2531 case ActivationContextDetailedInformation
:
2533 ACTIVATION_CONTEXT_DETAILED_INFORMATION
*acdi
= buffer
;
2534 struct assembly
*assembly
= NULL
;
2535 SIZE_T len
, manifest_len
= 0, config_len
= 0, appdir_len
= 0;
2538 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2540 if (actctx
->num_assemblies
) assembly
= actctx
->assemblies
;
2542 if (assembly
&& assembly
->manifest
.info
)
2543 manifest_len
= strlenW(assembly
->manifest
.info
) + 1;
2544 if (actctx
->config
.info
) config_len
= strlenW(actctx
->config
.info
) + 1;
2545 if (actctx
->appdir
.info
) appdir_len
= strlenW(actctx
->appdir
.info
) + 1;
2546 len
= sizeof(*acdi
) + (manifest_len
+ config_len
+ appdir_len
) * sizeof(WCHAR
);
2548 if (retlen
) *retlen
= len
;
2549 if (!buffer
|| bufsize
< len
) return STATUS_BUFFER_TOO_SMALL
;
2552 acdi
->ulFormatVersion
= assembly
? 1 : 0; /* FIXME */
2553 acdi
->ulAssemblyCount
= actctx
->num_assemblies
;
2554 acdi
->ulRootManifestPathType
= assembly
? assembly
->manifest
.type
: 0 /* FIXME */;
2555 acdi
->ulRootManifestPathChars
= assembly
&& assembly
->manifest
.info
? (DWORD
)manifest_len
- 1 : 0;
2556 acdi
->ulRootConfigurationPathType
= actctx
->config
.type
;
2557 acdi
->ulRootConfigurationPathChars
= actctx
->config
.info
? (DWORD
)config_len
- 1 : 0;
2558 acdi
->ulAppDirPathType
= actctx
->appdir
.type
;
2559 acdi
->ulAppDirPathChars
= actctx
->appdir
.info
? (DWORD
)appdir_len
- 1 : 0;
2560 ptr
= (LPWSTR
)(acdi
+ 1);
2563 acdi
->lpRootManifestPath
= ptr
;
2564 memcpy(ptr
, assembly
->manifest
.info
, manifest_len
* sizeof(WCHAR
));
2565 ptr
+= manifest_len
;
2567 else acdi
->lpRootManifestPath
= NULL
;
2570 acdi
->lpRootConfigurationPath
= ptr
;
2571 memcpy(ptr
, actctx
->config
.info
, config_len
* sizeof(WCHAR
));
2574 else acdi
->lpRootConfigurationPath
= NULL
;
2577 acdi
->lpAppDirPath
= ptr
;
2578 memcpy(ptr
, actctx
->appdir
.info
, appdir_len
* sizeof(WCHAR
));
2580 else acdi
->lpAppDirPath
= NULL
;
2584 case AssemblyDetailedInformationInActivationContext
:
2586 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
*afdi
= buffer
;
2587 struct assembly
*assembly
;
2590 SIZE_T len
, id_len
= 0, ad_len
= 0, path_len
= 0;
2593 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2594 if (!subinst
) return STATUS_INVALID_PARAMETER
;
2596 index
= *(DWORD
*)subinst
;
2597 if (!index
|| index
> actctx
->num_assemblies
) return STATUS_INVALID_PARAMETER
;
2599 assembly
= &actctx
->assemblies
[index
- 1];
2601 if (!(assembly_id
= build_assembly_id( &assembly
->id
))) return STATUS_NO_MEMORY
;
2602 id_len
= strlenW(assembly_id
) + 1;
2603 if (assembly
->directory
) ad_len
= strlenW(assembly
->directory
) + 1;
2605 if (assembly
->manifest
.info
&&
2606 (assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
))
2607 path_len
= strlenW(assembly
->manifest
.info
) + 1;
2609 len
= sizeof(*afdi
) + (id_len
+ ad_len
+ path_len
) * sizeof(WCHAR
);
2611 if (retlen
) *retlen
= len
;
2612 if (!buffer
|| bufsize
< len
)
2614 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly_id
);
2615 return STATUS_BUFFER_TOO_SMALL
;
2618 afdi
->ulFlags
= 0; /* FIXME */
2619 afdi
->ulEncodedAssemblyIdentityLength
= (DWORD
)(id_len
- 1) * sizeof(WCHAR
);
2620 afdi
->ulManifestPathType
= assembly
->manifest
.type
;
2621 afdi
->ulManifestPathLength
= assembly
->manifest
.info
? (DWORD
)(path_len
- 1) * sizeof(WCHAR
) : 0;
2622 /* FIXME afdi->liManifestLastWriteTime = 0; */
2623 afdi
->ulPolicyPathType
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
; /* FIXME */
2624 afdi
->ulPolicyPathLength
= 0;
2625 /* FIXME afdi->liPolicyLastWriteTime = 0; */
2626 afdi
->ulMetadataSatelliteRosterIndex
= 0; /* FIXME */
2627 afdi
->ulManifestVersionMajor
= 1;
2628 afdi
->ulManifestVersionMinor
= 0;
2629 afdi
->ulPolicyVersionMajor
= 0; /* FIXME */
2630 afdi
->ulPolicyVersionMinor
= 0; /* FIXME */
2631 afdi
->ulAssemblyDirectoryNameLength
= ad_len
? (DWORD
)(ad_len
- 1) * sizeof(WCHAR
) : 0;
2632 ptr
= (LPWSTR
)(afdi
+ 1);
2633 afdi
->lpAssemblyEncodedAssemblyIdentity
= ptr
;
2634 memcpy( ptr
, assembly_id
, id_len
* sizeof(WCHAR
) );
2638 afdi
->lpAssemblyManifestPath
= ptr
;
2639 memcpy(ptr
, assembly
->manifest
.info
, path_len
* sizeof(WCHAR
));
2641 } else afdi
->lpAssemblyManifestPath
= NULL
;
2642 afdi
->lpAssemblyPolicyPath
= NULL
; /* FIXME */
2645 afdi
->lpAssemblyDirectoryName
= ptr
;
2646 memcpy(ptr
, assembly
->directory
, ad_len
* sizeof(WCHAR
));
2649 else afdi
->lpAssemblyDirectoryName
= NULL
;
2650 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly_id
);
2654 case FileInformationInAssemblyOfAssemblyInActivationContext
:
2656 const ACTIVATION_CONTEXT_QUERY_INDEX
*acqi
= subinst
;
2657 ASSEMBLY_FILE_DETAILED_INFORMATION
*afdi
= buffer
;
2658 struct assembly
*assembly
;
2659 struct dll_redirect
*dll
;
2660 SIZE_T len
, dll_len
= 0;
2663 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2664 if (!acqi
) return STATUS_INVALID_PARAMETER
;
2666 if (acqi
->ulAssemblyIndex
>= actctx
->num_assemblies
)
2667 return STATUS_INVALID_PARAMETER
;
2668 assembly
= &actctx
->assemblies
[acqi
->ulAssemblyIndex
];
2670 if (acqi
->ulFileIndexInAssembly
>= assembly
->num_dlls
)
2671 return STATUS_INVALID_PARAMETER
;
2672 dll
= &assembly
->dlls
[acqi
->ulFileIndexInAssembly
];
2674 if (dll
->name
) dll_len
= strlenW(dll
->name
) + 1;
2675 len
= sizeof(*afdi
) + dll_len
* sizeof(WCHAR
);
2677 if (!buffer
|| bufsize
< len
)
2679 if (retlen
) *retlen
= len
;
2680 return STATUS_BUFFER_TOO_SMALL
;
2682 if (retlen
) *retlen
= 0; /* yes that's what native does !! */
2683 afdi
->ulFlags
= ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
;
2684 afdi
->ulFilenameLength
= dll_len
? (DWORD
)(dll_len
- 1) * sizeof(WCHAR
) : 0;
2685 afdi
->ulPathLength
= 0; /* FIXME */
2686 ptr
= (LPWSTR
)(afdi
+ 1);
2689 afdi
->lpFileName
= ptr
;
2690 memcpy( ptr
, dll
->name
, dll_len
* sizeof(WCHAR
) );
2691 } else afdi
->lpFileName
= NULL
;
2692 afdi
->lpFilePath
= NULL
; /* FIXME */
2697 DPRINT( "class %u not implemented\n", class );
2698 return STATUS_NOT_IMPLEMENTED
;
2700 return STATUS_SUCCESS
;
2705 RtlQueryInformationActiveActivationContext(ULONG ulInfoClass
,
2707 SIZE_T cbBuffer OPTIONAL
,
2708 SIZE_T
*pcbWrittenOrRequired OPTIONAL
)
2710 return RtlQueryInformationActivationContext(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX
,
2716 pcbWrittenOrRequired
);
2719 #define FIND_ACTCTX_RETURN_FLAGS 0x00000002
2720 #define FIND_ACTCTX_RETURN_ASSEMBLY_METADATA 0x00000004
2721 #define FIND_ACTCTX_VALID_MASK (FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX | FIND_ACTCTX_RETURN_FLAGS | FIND_ACTCTX_RETURN_ASSEMBLY_METADATA)
2725 RtlpFindActivationContextSection_CheckParameters( ULONG flags
, const GUID
*guid
, ULONG section_kind
,
2726 UNICODE_STRING
*section_name
, PACTCTX_SECTION_KEYED_DATA data
)
2728 /* Check general parameter combinations */
2729 if (!section_name
||
2730 (flags
& ~FIND_ACTCTX_VALID_MASK
) ||
2731 ((flags
& FIND_ACTCTX_VALID_MASK
) && !data
) ||
2732 (data
&& data
->cbSize
< offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
)))
2734 DPRINT1("invalid parameter\n");
2735 return STATUS_INVALID_PARAMETER
;
2739 if (flags
& FIND_ACTCTX_RETURN_FLAGS
||
2740 flags
& FIND_ACTCTX_RETURN_ASSEMBLY_METADATA
)
2742 DPRINT1("unknown flags %08x\n", flags
);
2743 return STATUS_INVALID_PARAMETER
;
2746 return STATUS_SUCCESS
;
2751 RtlFindActivationContextSectionString( ULONG flags
, const GUID
*guid
, ULONG section_kind
,
2752 UNICODE_STRING
*section_name
, PVOID ptr
)
2754 PACTCTX_SECTION_KEYED_DATA data
= ptr
;
2757 status
= RtlpFindActivationContextSection_CheckParameters(flags
, guid
, section_kind
, section_name
, data
);
2758 if (!NT_SUCCESS(status
)) return status
;
2760 status
= STATUS_SXS_KEY_NOT_FOUND
;
2762 /* if there is no data, but params are valid,
2763 we return that sxs key is not found to be at least somehow compatible */
2764 if (!data
) return status
;
2766 ASSERT(NtCurrentTeb());
2767 ASSERT(NtCurrentTeb()->ActivationContextStackPointer
);
2769 if (NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2771 ACTIVATION_CONTEXT
*actctx
= check_actctx(NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
->ActivationContext
);
2772 if (actctx
) status
= find_string( actctx
, section_kind
, section_name
, flags
, data
);
2775 if (status
!= STATUS_SUCCESS
)
2776 status
= find_string( process_actctx
, section_kind
, section_name
, flags
, data
);
2785 RtlAllocateActivationContextStack(IN PACTIVATION_CONTEXT_STACK
*Stack
)
2787 PACTIVATION_CONTEXT_STACK ContextStack
;
2789 /* Check if it's already allocated */
2790 if (*Stack
) return STATUS_SUCCESS
;
2792 /* Allocate space for the context stack */
2793 ContextStack
= RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ACTIVATION_CONTEXT_STACK
));
2796 return STATUS_NO_MEMORY
;
2799 /* Initialize the context stack */
2800 ContextStack
->Flags
= 0;
2801 ContextStack
->ActiveFrame
= NULL
;
2802 InitializeListHead(&ContextStack
->FrameListCache
);
2803 ContextStack
->NextCookieSequenceNumber
= 1;
2804 ContextStack
->StackId
= 1; //TODO: Timer-based
2806 *Stack
= ContextStack
;
2808 return STATUS_SUCCESS
;
2811 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
2813 RtlActivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame
,
2816 #if NEW_NTDLL_LOADER
2817 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*ActiveFrame
;
2819 /* Get the curren active frame */
2820 ActiveFrame
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
;
2822 DPRINT1("ActiveFrame %p, &Frame->Frame %p, Context %p\n", ActiveFrame
, &Frame
->Frame
, Context
);
2824 /* Actually activate it */
2825 Frame
->Frame
.Previous
= ActiveFrame
;
2826 Frame
->Frame
.ActivationContext
= Context
;
2827 Frame
->Frame
.Flags
= 0;
2829 /* Check if we can activate this context */
2830 if ((ActiveFrame
&& (ActiveFrame
->ActivationContext
!= Context
)) ||
2833 /* Set new active frame */
2834 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= &Frame
->Frame
;
2835 return &Frame
->Frame
;
2838 /* We can get here only one way: it was already activated */
2839 DPRINT1("Trying to activate improper activation context\n");
2841 /* Activate only if we are allowing multiple activation */
2842 if (!RtlpNotAllowingMultipleActivation
)
2844 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= &Frame
->Frame
;
2849 Frame
->Frame
.Flags
= 0x30;
2852 /* Return pointer to the activation frame */
2853 return &Frame
->Frame
;
2856 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
= &Frame
->Frame
;
2858 frame
->Previous
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
;
2859 frame
->ActivationContext
= Context
;
2862 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= frame
;
2864 return STATUS_SUCCESS
;
2868 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
2870 RtlDeactivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame
)
2872 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2873 //RTL_ACTIVATION_CONTEXT_STACK_FRAME *top;
2875 /* find the right frame */
2876 //top = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame;
2877 frame
= &Frame
->Frame
;
2881 DPRINT1("No top frame!\n");
2882 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION
);
2885 /* pop everything up to and including frame */
2886 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= frame
->Previous
;
2894 RtlZombifyActivationContext(PVOID Context
)
2898 if (Context
== ACTCTX_FAKE_HANDLE
)
2899 return STATUS_SUCCESS
;
2901 return STATUS_NOT_IMPLEMENTED
;