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
, GENERIC_READ
, &attr
, &io
, FILE_SHARE_READ
, FILE_SYNCHRONOUS_IO_ALERT
);
1624 static NTSTATUS
get_module_filename( HMODULE module
, UNICODE_STRING
*str
, USHORT extra_len
)
1628 LDR_DATA_TABLE_ENTRY
*pldr
;
1630 LdrLockLoaderLock(0, NULL
, &magic
);
1631 status
= LdrFindEntryForAddress( module
, &pldr
);
1632 if (status
== STATUS_SUCCESS
)
1634 if ((str
->Buffer
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
1635 pldr
->FullDllName
.Length
+ extra_len
+ sizeof(WCHAR
) )))
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
);
1641 else status
= STATUS_NO_MEMORY
;
1643 LdrUnlockLoaderLock(0, magic
);
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
)
1652 UNICODE_STRING nameW
;
1653 LDR_RESOURCE_INFO info
;
1654 IMAGE_RESOURCE_DATA_ENTRY
* entry
= NULL
;
1657 //DPRINT( "looking for res %s in module %p %s\n", resname,
1658 // hModule, filename );
1661 if (TRACE_ON(actctx
))
1663 if (!filename
&& !get_module_filename( hModule
, &nameW
, 0 ))
1665 DPRINT( "looking for res %s in module %p %s\n", debugstr_w(resname
),
1666 hModule
, debugstr_w(nameW
.Buffer
) );
1667 RtlFreeUnicodeString( &nameW
);
1669 else DPRINT( "looking for res %s in module %p %s\n", debugstr_w(resname
),
1670 hModule
, debugstr_w(filename
) );
1674 if (!resname
) return STATUS_INVALID_PARAMETER
;
1676 info
.Type
= (ULONG_PTR
)RT_MANIFEST
;
1677 info
.Language
= lang
;
1678 if (!((ULONG_PTR
)resname
>> 16))
1680 info
.Name
= (ULONG_PTR
)resname
;
1681 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
1683 else if (resname
[0] == '#')
1686 RtlInitUnicodeString(&nameW
, resname
+ 1);
1687 if (RtlUnicodeStringToInteger(&nameW
, 10, &value
) != STATUS_SUCCESS
|| HIWORD(value
))
1688 return STATUS_INVALID_PARAMETER
;
1690 status
= LdrFindResource_U(hModule
, &info
, 3, &entry
);
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
);
1700 if (status
== STATUS_SUCCESS
) status
= LdrAccessResource(hModule
, entry
, &ptr
, NULL
);
1702 if (status
== STATUS_SUCCESS
)
1703 status
= parse_manifest(acl
, ai
, filename
, directory
, shared
, ptr
, entry
->Size
);
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
)
1713 OBJECT_ATTRIBUTES attr
;
1715 LARGE_INTEGER offset
;
1720 DPRINT( "looking for res %S in %S\n", resname
, filename
);
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
;
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
;
1734 offset
.QuadPart
= 0;
1737 status
= NtMapViewOfSection( mapping
, NtCurrentProcess(), &base
, 0, 0, &offset
,
1738 &count
, ViewShare
, 0, PAGE_READONLY
);
1740 if (status
!= STATUS_SUCCESS
) return status
;
1742 if (RtlImageNtHeader(base
)) /* we got a PE file */
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
);
1747 else status
= STATUS_INVALID_IMAGE_FORMAT
;
1749 NtUnmapViewOfSection( NtCurrentProcess(), base
);
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
)
1756 FILE_STANDARD_INFORMATION info
;
1759 OBJECT_ATTRIBUTES attr
;
1761 LARGE_INTEGER offset
;
1766 DPRINT( "loading manifest file %S\n", filename
);
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
;
1776 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
| SECTION_MAP_READ
,
1777 &attr
, &size
, PAGE_READONLY
, SEC_COMMIT
, file
);
1779 if (status
!= STATUS_SUCCESS
) return status
;
1781 offset
.QuadPart
= 0;
1784 status
= NtMapViewOfSection( mapping
, NtCurrentProcess(), &base
, 0, 0, &offset
,
1785 &count
, ViewShare
, 0, PAGE_READONLY
);
1787 if (status
!= STATUS_SUCCESS
) return status
;
1789 /* Fixme: WINE uses FileEndOfFileInformation with NtQueryInformationFile. */
1790 status
= NtQueryInformationFile( file
, &io
, &info
, sizeof(info
), FileStandardInformation
);
1792 if (status
== STATUS_SUCCESS
)
1793 status
= parse_manifest(acl
, ai
, filename
, directory
, shared
, base
, (SIZE_T
)info
.EndOfFile
.QuadPart
);
1795 NtUnmapViewOfSection( NtCurrentProcess(), base
);
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
)
1804 static const WCHAR fmtW
[] = { '.','%','l','u',0 };
1807 UNICODE_STRING nameW
;
1809 ULONG_PTR resid
= (ULONG_PTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
;
1811 if (!((ULONG_PTR
)resname
>> 16)) resid
= (ULONG_PTR
)resname
& 0xffff;
1813 DPRINT( "looking for manifest associated with %S id %lu\n", filename
, resid
);
1815 if (module
) /* use the module filename */
1817 UNICODE_STRING name
;
1819 if (!(status
= get_module_filename( module
, &name
, sizeof(dotManifestW
) + 10*sizeof(WCHAR
) )))
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
);
1827 if (status
) return status
;
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
);
1840 if (!open_nt_file( &file
, &nameW
))
1842 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
1845 else status
= STATUS_RESOURCE_DATA_NOT_FOUND
;
1846 RtlFreeUnicodeString( &nameW
);
1850 static WCHAR
*lookup_manifest_file( HANDLE dir
, struct assembly_identity
*ai
)
1852 static const WCHAR lookup_fmtW
[] =
1853 {'%','s','_','%','s','_','%','s','_','%','u','.','%','u','.','*','.','*','_',
1855 '.','m','a','n','i','f','e','s','t',0};
1857 WCHAR
*lookup
, *ret
= NULL
;
1858 UNICODE_STRING lookup_us
;
1860 unsigned int data_pos
= 0, data_len
;
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
) )))
1869 sprintfW( lookup
, lookup_fmtW
, ai
->arch
, ai
->name
, ai
->public_key
, ai
->version
.major
, ai
->version
.minor
);
1870 RtlInitUnicodeString( &lookup_us
, lookup
);
1872 NtQueryDirectoryFile( dir
, 0, NULL
, NULL
, &io
, buffer
, sizeof(buffer
),
1873 FileBothDirectoryInformation
, FALSE
, &lookup_us
, TRUE
);
1874 if (io
.Status
== STATUS_SUCCESS
)
1876 FILE_BOTH_DIR_INFORMATION
*dir_info
;
1878 ULONG build
, revision
;
1880 data_len
= (ULONG
)io
.Information
;
1884 if (data_pos
>= data_len
)
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
;
1892 dir_info
= (FILE_BOTH_DIR_INFORMATION
*)(buffer
+ data_pos
);
1894 if (dir_info
->NextEntryOffset
) data_pos
+= dir_info
->NextEntryOffset
;
1895 else data_pos
= data_len
;
1897 tmp
= (WCHAR
*)dir_info
->FileName
+ (strchrW(lookup
, '*') - lookup
);
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
)
1904 ai
->version
.build
= (USHORT
)build
;
1905 ai
->version
.revision
= (USHORT
)revision
;
1907 if ((ret
= RtlAllocateHeap( RtlGetProcessHeap(), 0, dir_info
->FileNameLength
* sizeof(WCHAR
) )))
1909 memcpy( ret
, dir_info
->FileName
, dir_info
->FileNameLength
);
1910 ret
[dir_info
->FileNameLength
/sizeof(WCHAR
)] = 0;
1915 else DPRINT1("no matching file for %S\n", lookup
);
1916 RtlFreeHeap( RtlGetProcessHeap(), 0, lookup
);
1920 static NTSTATUS
lookup_winsxs(struct actctx_loader
* acl
, struct assembly_identity
* ai
)
1922 struct assembly_identity sxs_ai
;
1923 UNICODE_STRING path_us
;
1924 OBJECT_ATTRIBUTES attr
;
1926 WCHAR
*path
, *file
= NULL
;
1929 static const WCHAR manifest_dirW
[] =
1930 {'\\','w','i','n','s','x','s','\\','m','a','n','i','f','e','s','t','s',0};
1932 if (!ai
->arch
|| !ai
->name
|| !ai
->public_key
) return STATUS_NO_SUCH_FILE
;
1934 if (!(path
= RtlAllocateHeap( RtlGetProcessHeap(), 0,
1935 ((strlenW(SharedUserData
->NtSystemRoot
) + 1) *sizeof(WCHAR
)) + sizeof(manifest_dirW
) )))
1936 return STATUS_NO_MEMORY
;
1938 memcpy( path
, SharedUserData
->NtSystemRoot
, strlenW(SharedUserData
->NtSystemRoot
) * sizeof(WCHAR
) );
1939 memcpy( path
+ strlenW(SharedUserData
->NtSystemRoot
), manifest_dirW
, sizeof(manifest_dirW
) );
1941 if (!RtlDosPathNameToNtPathName_U( path
, &path_us
, NULL
, NULL
))
1943 RtlFreeHeap( RtlGetProcessHeap(), 0, path
);
1944 return STATUS_NO_SUCH_FILE
;
1946 RtlFreeHeap( RtlGetProcessHeap(), 0, path
);
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
;
1955 if (!NtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1956 FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
))
1959 file
= lookup_manifest_file( handle
, &sxs_ai
);
1964 RtlFreeUnicodeString( &path_us
);
1965 return STATUS_NO_SUCH_FILE
;
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
) )))
1972 RtlFreeHeap( RtlGetProcessHeap(), 0, file
);
1973 RtlFreeUnicodeString( &path_us
);
1974 return STATUS_NO_MEMORY
;
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 */
1982 if (!open_nt_file( &handle
, &path_us
))
1984 io
.Status
= get_manifest_in_manifest_file(acl
, &sxs_ai
, path_us
.Buffer
, file
, TRUE
, handle
);
1987 else io
.Status
= STATUS_NO_SUCH_FILE
;
1989 RtlFreeHeap( RtlGetProcessHeap(), 0, file
);
1990 RtlFreeUnicodeString( &path_us
);
1994 static NTSTATUS
lookup_assembly(struct actctx_loader
* acl
,
1995 struct assembly_identity
* ai
)
1997 static const WCHAR dotDllW
[] = {'.','d','l','l',0};
1999 WCHAR
*buffer
, *p
, *directory
;
2001 UNICODE_STRING nameW
;
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
);
2007 if ((status
= lookup_winsxs(acl
, ai
)) != STATUS_NO_SUCH_FILE
) return status
;
2009 /* FIXME: add support for language specific lookup */
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
;
2016 if (!(directory
= build_assembly_dir( ai
)))
2018 RtlFreeHeap( RtlGetProcessHeap(), 0, buffer
);
2019 return STATUS_NO_MEMORY
;
2022 /* lookup in appdir\name.dll
2023 * appdir\name.manifest
2024 * appdir\name\name.dll
2025 * appdir\name\name.manifest
2027 strcpyW( buffer
, acl
->actctx
->appdir
.info
);
2028 p
= buffer
+ strlenW(buffer
);
2029 for (i
= 0; i
< 2; i
++)
2032 strcpyW( p
, ai
->name
);
2035 strcpyW( p
, dotDllW
);
2036 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
2038 status
= open_nt_file( &file
, &nameW
);
2041 status
= get_manifest_in_pe_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
,
2042 (LPCWSTR
)CREATEPROCESS_MANIFEST_RESOURCE_ID
, 0 );
2046 RtlFreeUnicodeString( &nameW
);
2049 strcpyW( p
, dotManifestW
);
2050 if (RtlDosPathNameToNtPathName_U( buffer
, &nameW
, NULL
, NULL
))
2052 status
= open_nt_file( &file
, &nameW
);
2055 status
= get_manifest_in_manifest_file( acl
, ai
, nameW
.Buffer
, directory
, FALSE
, file
);
2059 RtlFreeUnicodeString( &nameW
);
2061 status
= STATUS_SXS_ASSEMBLY_NOT_FOUND
;
2063 RtlFreeUnicodeString( &nameW
);
2064 RtlFreeHeap( RtlGetProcessHeap(), 0, directory
);
2065 RtlFreeHeap( RtlGetProcessHeap(), 0, buffer
);
2069 static NTSTATUS
parse_depend_manifests(struct actctx_loader
* acl
)
2071 NTSTATUS status
= STATUS_SUCCESS
;
2074 for (i
= 0; i
< acl
->num_dependencies
; i
++)
2076 if (lookup_assembly(acl
, &acl
->dependencies
[i
]) != STATUS_SUCCESS
)
2078 if (!acl
->dependencies
[i
].optional
)
2080 DPRINT1( "Could not find dependent assembly %S\n", acl
->dependencies
[i
].name
);
2081 status
= STATUS_SXS_CANT_GEN_ACTCTX
;
2086 /* FIXME should now iterate through all refs */
2090 /* find the appropriate activation context for RtlQueryInformationActivationContext */
2091 static NTSTATUS
find_query_actctx( HANDLE
*handle
, DWORD flags
, ULONG
class )
2093 NTSTATUS status
= STATUS_SUCCESS
;
2095 if (flags
& QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX
)
2097 if (*handle
) return STATUS_INVALID_PARAMETER
;
2099 if (NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2100 *handle
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
->ActivationContext
;
2102 else if (flags
& (QUERY_ACTCTX_FLAG_ACTCTX_IS_ADDRESS
|QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
))
2105 LDR_DATA_TABLE_ENTRY
*pldr
;
2107 if (!*handle
) return STATUS_INVALID_PARAMETER
;
2109 LdrLockLoaderLock( 0, NULL
, &magic
);
2110 if (!LdrFindEntryForAddress( *handle
, &pldr
))
2112 if ((flags
& QUERY_ACTCTX_FLAG_ACTCTX_IS_HMODULE
) && *handle
!= pldr
->DllBase
)
2113 status
= STATUS_DLL_NOT_FOUND
;
2115 *handle
= pldr
->EntryPointActivationContext
;
2117 else status
= STATUS_DLL_NOT_FOUND
;
2118 LdrUnlockLoaderLock( 0, magic
);
2120 else if (!*handle
&& (class != ActivationContextBasicInformation
))
2121 *handle
= process_actctx
;
2126 static NTSTATUS
fill_keyed_data(PACTCTX_SECTION_KEYED_DATA data
, PVOID v1
, PVOID v2
, unsigned int i
)
2128 data
->ulDataFormatVersion
= 1;
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;
2139 return STATUS_SUCCESS
;
2142 static NTSTATUS
find_dll_redirection(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2143 PACTCTX_SECTION_KEYED_DATA data
)
2145 unsigned int i
, j
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2147 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2149 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2150 for (j
= 0; j
< assembly
->num_dlls
; j
++)
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
);
2157 return STATUS_SXS_KEY_NOT_FOUND
;
2160 static NTSTATUS
find_window_class(ACTIVATION_CONTEXT
* actctx
, const UNICODE_STRING
*section_name
,
2161 PACTCTX_SECTION_KEYED_DATA data
)
2163 unsigned int i
, j
, k
, snlen
= section_name
->Length
/ sizeof(WCHAR
);
2165 for (i
= 0; i
< actctx
->num_assemblies
; i
++)
2167 struct assembly
*assembly
= &actctx
->assemblies
[i
];
2168 for (j
= 0; j
< assembly
->num_dlls
; j
++)
2170 struct dll_redirect
*dll
= &assembly
->dlls
[j
];
2171 for (k
= 0; k
< dll
->entities
.num
; k
++)
2173 struct entity
*entity
= &dll
->entities
.base
[k
];
2174 if (entity
->kind
== ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
)
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
);
2182 return STATUS_SXS_KEY_NOT_FOUND
;
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
)
2191 switch (section_kind
)
2193 case ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
:
2194 status
= find_dll_redirection(actctx
, section_name
, data
);
2196 case ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
:
2197 status
= find_window_class(actctx
, section_name
, data
);
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
;
2208 DPRINT1("Unknown section_kind %x\n", section_kind
);
2209 return STATUS_SXS_SECTION_NOT_FOUND
;
2212 if (status
!= STATUS_SUCCESS
) return status
;
2214 if (flags
& FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
)
2216 actctx_addref(actctx
);
2217 data
->hActCtx
= actctx
;
2219 return STATUS_SUCCESS
;
2222 /* initialize the activation context for the current process */
2223 void actctx_init(void)
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
;
2234 if (!RtlCreateActivationContext( &handle
, &ctx
)) process_actctx
= check_actctx(handle
);
2237 /* FUNCTIONS ***************************************************************/
2239 NTSTATUS WINAPI
RtlCreateActivationContext( HANDLE
*handle
, void *ptr
)
2241 const ACTCTXW
*pActCtx
= ptr
;
2242 const WCHAR
*directory
= NULL
;
2243 ACTIVATION_CONTEXT
*actctx
;
2244 UNICODE_STRING nameW
;
2246 NTSTATUS status
= STATUS_NO_MEMORY
;
2248 struct actctx_loader acl
;
2250 DPRINT("%p %08x\n", pActCtx
, pActCtx
? pActCtx
->dwFlags
: 0);
2252 if (!pActCtx
|| pActCtx
->cbSize
< sizeof(*pActCtx
) ||
2253 (pActCtx
->dwFlags
& ~ACTCTX_FLAGS_ALL
))
2254 return STATUS_INVALID_PARAMETER
;
2257 if (!(actctx
= RtlAllocateHeap( RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*actctx
) )))
2258 return STATUS_NO_MEMORY
;
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
)
2267 if (!(actctx
->appdir
.info
= strdupW( pActCtx
->lpApplicationName
))) goto error
;
2275 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
) module
= pActCtx
->hModule
;
2276 else module
= NtCurrentTeb()->ProcessEnvironmentBlock
->ImageBaseAddress
;
2278 status
= get_module_filename(module
, &dir
, 0);
2279 if (!NT_SUCCESS(status
)) goto error
;
2280 if ((p
= strrchrW( dir
.Buffer
, '\\' ))) p
[1] = 0;
2281 actctx
->appdir
.info
= dir
.Buffer
;
2284 nameW
.Buffer
= NULL
;
2285 if (pActCtx
->lpSource
)
2287 if (!RtlDosPathNameToNtPathName_U(pActCtx
->lpSource
, &nameW
, NULL
, NULL
))
2289 status
= STATUS_NO_SUCH_FILE
;
2292 status
= open_nt_file( &file
, &nameW
);
2293 if (!NT_SUCCESS(status
))
2295 RtlFreeUnicodeString( &nameW
);
2300 acl
.actctx
= actctx
;
2301 acl
.dependencies
= NULL
;
2302 acl
.num_dependencies
= 0;
2303 acl
.allocated_dependencies
= 0;
2305 if (pActCtx
->dwFlags
& ACTCTX_FLAG_LANGID_VALID
) lang
= pActCtx
->wLangId
;
2306 if (pActCtx
->dwFlags
& ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID
) directory
= pActCtx
->lpAssemblyDirectory
;
2308 if (pActCtx
->dwFlags
& ACTCTX_FLAG_RESOURCE_NAME_VALID
)
2310 /* if we have a resource it's a PE file */
2311 if (pActCtx
->dwFlags
& ACTCTX_FLAG_HMODULE_VALID
)
2313 status
= get_manifest_in_module( &acl
, NULL
, NULL
, directory
, FALSE
, pActCtx
->hModule
,
2314 pActCtx
->lpResourceName
, lang
);
2315 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2316 /* FIXME: what to do if pActCtx->lpSource is set */
2317 status
= get_manifest_in_associated_manifest( &acl
, NULL
, NULL
, directory
,
2318 pActCtx
->hModule
, pActCtx
->lpResourceName
);
2320 else if (pActCtx
->lpSource
)
2322 status
= get_manifest_in_pe_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
,
2323 file
, pActCtx
->lpResourceName
, lang
);
2324 if (status
&& status
!= STATUS_SXS_CANT_GEN_ACTCTX
)
2325 status
= get_manifest_in_associated_manifest( &acl
, NULL
, nameW
.Buffer
, directory
,
2326 NULL
, pActCtx
->lpResourceName
);
2328 else status
= STATUS_INVALID_PARAMETER
;
2332 status
= get_manifest_in_manifest_file( &acl
, NULL
, nameW
.Buffer
, directory
, FALSE
, file
);
2335 if (file
) NtClose( file
);
2336 RtlFreeUnicodeString( &nameW
);
2338 if (NT_SUCCESS(status
)) status
= parse_depend_manifests(&acl
);
2339 free_depend_manifests( &acl
);
2341 if (NT_SUCCESS(status
))
2343 else actctx_release( actctx
);
2347 if (file
) NtClose( file
);
2348 actctx_release( actctx
);
2354 RtlAddRefActivationContext(HANDLE handle
)
2356 ACTIVATION_CONTEXT
*actctx
;
2358 if ((actctx
= check_actctx( handle
))) actctx_addref( actctx
);
2363 RtlReleaseActivationContext( HANDLE handle
)
2365 ACTIVATION_CONTEXT
*actctx
;
2367 if ((actctx
= check_actctx( handle
))) actctx_release( actctx
);
2371 NTAPI
RtlActivateActivationContextEx( ULONG flags
, PTEB tebAddress
, HANDLE handle
, PULONG_PTR cookie
)
2373 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2375 if (!(frame
= RtlAllocateHeap( RtlGetProcessHeap(), 0, sizeof(*frame
) )))
2376 return STATUS_NO_MEMORY
;
2378 frame
->Previous
= tebAddress
->ActivationContextStackPointer
->ActiveFrame
;
2379 frame
->ActivationContext
= handle
;
2382 tebAddress
->ActivationContextStackPointer
->ActiveFrame
= frame
;
2383 RtlAddRefActivationContext( handle
);
2385 *cookie
= (ULONG_PTR
)frame
;
2386 DPRINT( "%p cookie=%lx\n", handle
, *cookie
);
2387 return STATUS_SUCCESS
;
2392 NTAPI
RtlActivateActivationContext( ULONG flags
, HANDLE handle
, PULONG_PTR cookie
)
2394 return RtlActivateActivationContextEx(flags
, NtCurrentTeb(), handle
, cookie
);
2399 RtlDeactivateActivationContext( ULONG flags
, ULONG_PTR cookie
)
2401 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
, *top
;
2403 DPRINT( "%x cookie=%lx\n", flags
, cookie
);
2405 /* find the right frame */
2406 top
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
;
2407 for (frame
= top
; frame
; frame
= frame
->Previous
)
2408 if ((ULONG_PTR
)frame
== cookie
) break;
2411 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION
);
2413 if (frame
!= top
&& !(flags
& DEACTIVATE_ACTCTX_FLAG_FORCE_EARLY_DEACTIVATION
))
2414 RtlRaiseStatus( STATUS_SXS_EARLY_DEACTIVATION
);
2416 /* pop everything up to and including frame */
2417 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= frame
->Previous
;
2419 while (top
!= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2421 frame
= top
->Previous
;
2422 RtlReleaseActivationContext( top
->ActivationContext
);
2423 RtlFreeHeap( RtlGetProcessHeap(), 0, top
);
2427 return STATUS_SUCCESS
;
2432 RtlFreeActivationContextStack(IN PACTIVATION_CONTEXT_STACK Stack
)
2434 PRTL_ACTIVATION_CONTEXT_STACK_FRAME ActiveFrame
, PrevFrame
;
2436 /* Nothing to do if there is no stack */
2439 /* Get the current active frame */
2440 ActiveFrame
= Stack
->ActiveFrame
;
2442 /* Go through them in backwards order and release */
2445 PrevFrame
= ActiveFrame
->Previous
;
2446 RtlReleaseActivationContext(ActiveFrame
->ActivationContext
);
2447 RtlFreeHeap(RtlGetProcessHeap(), 0, ActiveFrame
);
2448 ActiveFrame
= PrevFrame
;
2451 /* Zero out the active frame */
2452 Stack
->ActiveFrame
= NULL
;
2454 /* TODO: Empty the Frame List Cache */
2455 ASSERT(IsListEmpty(&Stack
->FrameListCache
));
2457 /* Free activation stack memory */
2458 RtlFreeHeap(RtlGetProcessHeap(), 0, Stack
);
2462 NTAPI
RtlFreeThreadActivationContextStack(VOID
)
2464 RtlFreeActivationContextStack(NtCurrentTeb()->ActivationContextStackPointer
);
2465 NtCurrentTeb()->ActivationContextStackPointer
= NULL
;
2470 NTAPI
RtlGetActiveActivationContext( HANDLE
*handle
)
2472 if (NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2474 *handle
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
->ActivationContext
;
2475 RtlAddRefActivationContext( *handle
);
2480 return STATUS_SUCCESS
;
2485 NTAPI
RtlIsActivationContextActive( HANDLE handle
)
2487 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2489 for (frame
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
; frame
; frame
= frame
->Previous
)
2490 if (frame
->ActivationContext
== handle
) return TRUE
;
2496 RtlQueryInformationActivationContext( ULONG flags
, HANDLE handle
, PVOID subinst
,
2497 ULONG
class, PVOID buffer
,
2498 SIZE_T bufsize
, SIZE_T
*retlen
)
2500 ACTIVATION_CONTEXT
*actctx
;
2503 DPRINT("%08x %p %p %u %p %Iu %p\n", flags
, handle
,
2504 subinst
, class, buffer
, bufsize
, retlen
);
2506 if (retlen
) *retlen
= 0;
2507 if ((status
= find_query_actctx( &handle
, flags
, class ))) return status
;
2511 case ActivationContextBasicInformation
:
2513 ACTIVATION_CONTEXT_BASIC_INFORMATION
*info
= buffer
;
2515 if (retlen
) *retlen
= sizeof(*info
);
2516 if (!info
|| bufsize
< sizeof(*info
)) return STATUS_BUFFER_TOO_SMALL
;
2518 info
->hActCtx
= handle
;
2519 info
->dwFlags
= 0; /* FIXME */
2520 if (!(flags
& QUERY_ACTCTX_FLAG_NO_ADDREF
)) RtlAddRefActivationContext( handle
);
2524 case ActivationContextDetailedInformation
:
2526 ACTIVATION_CONTEXT_DETAILED_INFORMATION
*acdi
= buffer
;
2527 struct assembly
*assembly
= NULL
;
2528 SIZE_T len
, manifest_len
= 0, config_len
= 0, appdir_len
= 0;
2531 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2533 if (actctx
->num_assemblies
) assembly
= actctx
->assemblies
;
2535 if (assembly
&& assembly
->manifest
.info
)
2536 manifest_len
= strlenW(assembly
->manifest
.info
) + 1;
2537 if (actctx
->config
.info
) config_len
= strlenW(actctx
->config
.info
) + 1;
2538 if (actctx
->appdir
.info
) appdir_len
= strlenW(actctx
->appdir
.info
) + 1;
2539 len
= sizeof(*acdi
) + (manifest_len
+ config_len
+ appdir_len
) * sizeof(WCHAR
);
2541 if (retlen
) *retlen
= len
;
2542 if (!buffer
|| bufsize
< len
) return STATUS_BUFFER_TOO_SMALL
;
2545 acdi
->ulFormatVersion
= assembly
? 1 : 0; /* FIXME */
2546 acdi
->ulAssemblyCount
= actctx
->num_assemblies
;
2547 acdi
->ulRootManifestPathType
= assembly
? assembly
->manifest
.type
: 0 /* FIXME */;
2548 acdi
->ulRootManifestPathChars
= assembly
&& assembly
->manifest
.info
? (DWORD
)manifest_len
- 1 : 0;
2549 acdi
->ulRootConfigurationPathType
= actctx
->config
.type
;
2550 acdi
->ulRootConfigurationPathChars
= actctx
->config
.info
? (DWORD
)config_len
- 1 : 0;
2551 acdi
->ulAppDirPathType
= actctx
->appdir
.type
;
2552 acdi
->ulAppDirPathChars
= actctx
->appdir
.info
? (DWORD
)appdir_len
- 1 : 0;
2553 ptr
= (LPWSTR
)(acdi
+ 1);
2556 acdi
->lpRootManifestPath
= ptr
;
2557 memcpy(ptr
, assembly
->manifest
.info
, manifest_len
* sizeof(WCHAR
));
2558 ptr
+= manifest_len
;
2560 else acdi
->lpRootManifestPath
= NULL
;
2563 acdi
->lpRootConfigurationPath
= ptr
;
2564 memcpy(ptr
, actctx
->config
.info
, config_len
* sizeof(WCHAR
));
2567 else acdi
->lpRootConfigurationPath
= NULL
;
2570 acdi
->lpAppDirPath
= ptr
;
2571 memcpy(ptr
, actctx
->appdir
.info
, appdir_len
* sizeof(WCHAR
));
2573 else acdi
->lpAppDirPath
= NULL
;
2577 case AssemblyDetailedInformationInActivationContext
:
2579 ACTIVATION_CONTEXT_ASSEMBLY_DETAILED_INFORMATION
*afdi
= buffer
;
2580 struct assembly
*assembly
;
2583 SIZE_T len
, id_len
= 0, ad_len
= 0, path_len
= 0;
2586 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2587 if (!subinst
) return STATUS_INVALID_PARAMETER
;
2589 index
= *(DWORD
*)subinst
;
2590 if (!index
|| index
> actctx
->num_assemblies
) return STATUS_INVALID_PARAMETER
;
2592 assembly
= &actctx
->assemblies
[index
- 1];
2594 if (!(assembly_id
= build_assembly_id( &assembly
->id
))) return STATUS_NO_MEMORY
;
2595 id_len
= strlenW(assembly_id
) + 1;
2596 if (assembly
->directory
) ad_len
= strlenW(assembly
->directory
) + 1;
2598 if (assembly
->manifest
.info
&&
2599 (assembly
->type
== ASSEMBLY_MANIFEST
|| assembly
->type
== ASSEMBLY_SHARED_MANIFEST
))
2600 path_len
= strlenW(assembly
->manifest
.info
) + 1;
2602 len
= sizeof(*afdi
) + (id_len
+ ad_len
+ path_len
) * sizeof(WCHAR
);
2604 if (retlen
) *retlen
= len
;
2605 if (!buffer
|| bufsize
< len
)
2607 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly_id
);
2608 return STATUS_BUFFER_TOO_SMALL
;
2611 afdi
->ulFlags
= 0; /* FIXME */
2612 afdi
->ulEncodedAssemblyIdentityLength
= (DWORD
)(id_len
- 1) * sizeof(WCHAR
);
2613 afdi
->ulManifestPathType
= assembly
->manifest
.type
;
2614 afdi
->ulManifestPathLength
= assembly
->manifest
.info
? (DWORD
)(path_len
- 1) * sizeof(WCHAR
) : 0;
2615 /* FIXME afdi->liManifestLastWriteTime = 0; */
2616 afdi
->ulPolicyPathType
= ACTIVATION_CONTEXT_PATH_TYPE_NONE
; /* FIXME */
2617 afdi
->ulPolicyPathLength
= 0;
2618 /* FIXME afdi->liPolicyLastWriteTime = 0; */
2619 afdi
->ulMetadataSatelliteRosterIndex
= 0; /* FIXME */
2620 afdi
->ulManifestVersionMajor
= 1;
2621 afdi
->ulManifestVersionMinor
= 0;
2622 afdi
->ulPolicyVersionMajor
= 0; /* FIXME */
2623 afdi
->ulPolicyVersionMinor
= 0; /* FIXME */
2624 afdi
->ulAssemblyDirectoryNameLength
= ad_len
? (DWORD
)(ad_len
- 1) * sizeof(WCHAR
) : 0;
2625 ptr
= (LPWSTR
)(afdi
+ 1);
2626 afdi
->lpAssemblyEncodedAssemblyIdentity
= ptr
;
2627 memcpy( ptr
, assembly_id
, id_len
* sizeof(WCHAR
) );
2631 afdi
->lpAssemblyManifestPath
= ptr
;
2632 memcpy(ptr
, assembly
->manifest
.info
, path_len
* sizeof(WCHAR
));
2634 } else afdi
->lpAssemblyManifestPath
= NULL
;
2635 afdi
->lpAssemblyPolicyPath
= NULL
; /* FIXME */
2638 afdi
->lpAssemblyDirectoryName
= ptr
;
2639 memcpy(ptr
, assembly
->directory
, ad_len
* sizeof(WCHAR
));
2642 else afdi
->lpAssemblyDirectoryName
= NULL
;
2643 RtlFreeHeap( RtlGetProcessHeap(), 0, assembly_id
);
2647 case FileInformationInAssemblyOfAssemblyInActivationContext
:
2649 const ACTIVATION_CONTEXT_QUERY_INDEX
*acqi
= subinst
;
2650 ASSEMBLY_FILE_DETAILED_INFORMATION
*afdi
= buffer
;
2651 struct assembly
*assembly
;
2652 struct dll_redirect
*dll
;
2653 SIZE_T len
, dll_len
= 0;
2656 if (!(actctx
= check_actctx(handle
))) return STATUS_INVALID_PARAMETER
;
2657 if (!acqi
) return STATUS_INVALID_PARAMETER
;
2659 if (acqi
->ulAssemblyIndex
>= actctx
->num_assemblies
)
2660 return STATUS_INVALID_PARAMETER
;
2661 assembly
= &actctx
->assemblies
[acqi
->ulAssemblyIndex
];
2663 if (acqi
->ulFileIndexInAssembly
>= assembly
->num_dlls
)
2664 return STATUS_INVALID_PARAMETER
;
2665 dll
= &assembly
->dlls
[acqi
->ulFileIndexInAssembly
];
2667 if (dll
->name
) dll_len
= strlenW(dll
->name
) + 1;
2668 len
= sizeof(*afdi
) + dll_len
* sizeof(WCHAR
);
2670 if (!buffer
|| bufsize
< len
)
2672 if (retlen
) *retlen
= len
;
2673 return STATUS_BUFFER_TOO_SMALL
;
2675 if (retlen
) *retlen
= 0; /* yes that's what native does !! */
2676 afdi
->ulFlags
= ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION
;
2677 afdi
->ulFilenameLength
= dll_len
? (DWORD
)(dll_len
- 1) * sizeof(WCHAR
) : 0;
2678 afdi
->ulPathLength
= 0; /* FIXME */
2679 ptr
= (LPWSTR
)(afdi
+ 1);
2682 afdi
->lpFileName
= ptr
;
2683 memcpy( ptr
, dll
->name
, dll_len
* sizeof(WCHAR
) );
2684 } else afdi
->lpFileName
= NULL
;
2685 afdi
->lpFilePath
= NULL
; /* FIXME */
2690 DPRINT( "class %u not implemented\n", class );
2691 return STATUS_NOT_IMPLEMENTED
;
2693 return STATUS_SUCCESS
;
2698 RtlQueryInformationActiveActivationContext(ULONG ulInfoClass
,
2700 SIZE_T cbBuffer OPTIONAL
,
2701 SIZE_T
*pcbWrittenOrRequired OPTIONAL
)
2703 return RtlQueryInformationActivationContext(QUERY_ACTCTX_FLAG_USE_ACTIVE_ACTCTX
,
2709 pcbWrittenOrRequired
);
2712 #define FIND_ACTCTX_RETURN_FLAGS 0x00000002
2713 #define FIND_ACTCTX_RETURN_ASSEMBLY_METADATA 0x00000004
2714 #define FIND_ACTCTX_VALID_MASK (FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX | FIND_ACTCTX_RETURN_FLAGS | FIND_ACTCTX_RETURN_ASSEMBLY_METADATA)
2718 RtlpFindActivationContextSection_CheckParameters( ULONG flags
, const GUID
*guid
, ULONG section_kind
,
2719 UNICODE_STRING
*section_name
, PACTCTX_SECTION_KEYED_DATA data
)
2721 /* Check general parameter combinations */
2722 if (!section_name
||
2723 (flags
& ~FIND_ACTCTX_VALID_MASK
) ||
2724 ((flags
& FIND_ACTCTX_VALID_MASK
) && !data
) ||
2725 (data
&& data
->cbSize
< offsetof(ACTCTX_SECTION_KEYED_DATA
, ulAssemblyRosterIndex
)))
2727 DPRINT1("invalid parameter\n");
2728 return STATUS_INVALID_PARAMETER
;
2732 if (flags
& FIND_ACTCTX_RETURN_FLAGS
||
2733 flags
& FIND_ACTCTX_RETURN_ASSEMBLY_METADATA
)
2735 DPRINT1("unknown flags %08x\n", flags
);
2736 return STATUS_INVALID_PARAMETER
;
2739 return STATUS_SUCCESS
;
2744 RtlFindActivationContextSectionString( ULONG flags
, const GUID
*guid
, ULONG section_kind
,
2745 UNICODE_STRING
*section_name
, PVOID ptr
)
2747 PACTCTX_SECTION_KEYED_DATA data
= ptr
;
2750 status
= RtlpFindActivationContextSection_CheckParameters(flags
, guid
, section_kind
, section_name
, data
);
2751 if (!NT_SUCCESS(status
)) return status
;
2753 status
= STATUS_SXS_KEY_NOT_FOUND
;
2755 /* if there is no data, but params are valid,
2756 we return that sxs key is not found to be at least somehow compatible */
2757 if (!data
) return status
;
2759 ASSERT(NtCurrentTeb());
2760 ASSERT(NtCurrentTeb()->ActivationContextStackPointer
);
2762 if (NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
)
2764 ACTIVATION_CONTEXT
*actctx
= check_actctx(NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
->ActivationContext
);
2765 if (actctx
) status
= find_string( actctx
, section_kind
, section_name
, flags
, data
);
2768 if (status
!= STATUS_SUCCESS
)
2769 status
= find_string( process_actctx
, section_kind
, section_name
, flags
, data
);
2778 RtlAllocateActivationContextStack(IN PACTIVATION_CONTEXT_STACK
*Stack
)
2780 PACTIVATION_CONTEXT_STACK ContextStack
;
2782 /* Check if it's already allocated */
2783 if (*Stack
) return STATUS_SUCCESS
;
2785 /* Allocate space for the context stack */
2786 ContextStack
= RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ACTIVATION_CONTEXT_STACK
));
2789 return STATUS_NO_MEMORY
;
2792 /* Initialize the context stack */
2793 ContextStack
->Flags
= 0;
2794 ContextStack
->ActiveFrame
= NULL
;
2795 InitializeListHead(&ContextStack
->FrameListCache
);
2796 ContextStack
->NextCookieSequenceNumber
= 1;
2797 ContextStack
->StackId
= 1; //TODO: Timer-based
2799 *Stack
= ContextStack
;
2801 return STATUS_SUCCESS
;
2804 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
2806 RtlActivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame
,
2809 #if NEW_NTDLL_LOADER
2810 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*ActiveFrame
;
2812 /* Get the curren active frame */
2813 ActiveFrame
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
;
2815 DPRINT1("ActiveFrame %p, &Frame->Frame %p, Context %p\n", ActiveFrame
, &Frame
->Frame
, Context
);
2817 /* Actually activate it */
2818 Frame
->Frame
.Previous
= ActiveFrame
;
2819 Frame
->Frame
.ActivationContext
= Context
;
2820 Frame
->Frame
.Flags
= 0;
2822 /* Check if we can activate this context */
2823 if ((ActiveFrame
&& (ActiveFrame
->ActivationContext
!= Context
)) ||
2826 /* Set new active frame */
2827 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= &Frame
->Frame
;
2828 return &Frame
->Frame
;
2831 /* We can get here only one way: it was already activated */
2832 DPRINT1("Trying to activate improper activation context\n");
2834 /* Activate only if we are allowing multiple activation */
2835 if (!RtlpNotAllowingMultipleActivation
)
2837 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= &Frame
->Frame
;
2842 Frame
->Frame
.Flags
= 0x30;
2845 /* Return pointer to the activation frame */
2846 return &Frame
->Frame
;
2849 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
= &Frame
->Frame
;
2851 frame
->Previous
= NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
;
2852 frame
->ActivationContext
= Context
;
2855 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= frame
;
2857 return STATUS_SUCCESS
;
2861 PRTL_ACTIVATION_CONTEXT_STACK_FRAME
2863 RtlDeactivateActivationContextUnsafeFast(IN PRTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame
)
2865 RTL_ACTIVATION_CONTEXT_STACK_FRAME
*frame
;
2866 //RTL_ACTIVATION_CONTEXT_STACK_FRAME *top;
2868 /* find the right frame */
2869 //top = NtCurrentTeb()->ActivationContextStackPointer->ActiveFrame;
2870 frame
= &Frame
->Frame
;
2874 DPRINT1("No top frame!\n");
2875 RtlRaiseStatus( STATUS_SXS_INVALID_DEACTIVATION
);
2878 /* pop everything up to and including frame */
2879 NtCurrentTeb()->ActivationContextStackPointer
->ActiveFrame
= frame
->Previous
;
2887 RtlZombifyActivationContext(PVOID Context
)
2891 if (Context
== ACTCTX_FAKE_HANDLE
)
2892 return STATUS_SUCCESS
;
2894 return STATUS_NOT_IMPLEMENTED
;