Reactos
1/*
2 * Module loader
3 *
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 2006 Mike McCormack
6 * Copyright 1995, 2003, 2019 Alexandre Julliard
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23#include <stdarg.h>
24
25#include "ntstatus.h"
26#define WIN32_NO_STATUS
27#include "windef.h"
28#include "winbase.h"
29#include "winnls.h"
30#include "winternl.h"
31#include "ddk/ntddk.h"
32#include "kernelbase.h"
33#include "wine/list.h"
34#include "wine/asm.h"
35#include "wine/debug.h"
36#include "wine/exception.h"
37
38WINE_DEFAULT_DEBUG_CHANNEL(module);
39
40
41/* to keep track of LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE file handles */
42struct exclusive_datafile
43{
44 struct list entry;
45 HMODULE module;
46 HANDLE file;
47};
48static struct list exclusive_datafile_list = LIST_INIT( exclusive_datafile_list );
49
50static CRITICAL_SECTION exclusive_datafile_list_section;
51static CRITICAL_SECTION_DEBUG critsect_debug =
52{
53 0, 0, &exclusive_datafile_list_section,
54 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
55 0, 0, { (DWORD_PTR)(__FILE__ ": exclusive_datafile_list_section") }
56};
57static CRITICAL_SECTION exclusive_datafile_list_section = { &critsect_debug, -1, 0, 0, 0, 0 };
58
59/***********************************************************************
60 * Modules
61 ***********************************************************************/
62
63
64/******************************************************************
65 * get_proc_address
66 */
67FARPROC WINAPI get_proc_address( HMODULE module, LPCSTR function )
68{
69 FARPROC proc;
70 ANSI_STRING str;
71
72 if (!module) module = NtCurrentTeb()->Peb->ImageBaseAddress;
73
74 if ((ULONG_PTR)function >> 16)
75 {
76 RtlInitAnsiString( &str, function );
77 if (!set_ntstatus( LdrGetProcedureAddress( module, &str, 0, (void**)&proc ))) return NULL;
78 }
79 else if (!set_ntstatus( LdrGetProcedureAddress( module, NULL, LOWORD(function), (void**)&proc )))
80 return NULL;
81
82 return proc;
83}
84
85
86/******************************************************************
87 * load_library_as_datafile
88 */
89static BOOL load_library_as_datafile( LPCWSTR load_path, DWORD flags, LPCWSTR name, HMODULE *mod_ret )
90{
91 WCHAR filenameW[MAX_PATH];
92 HANDLE mapping, file = INVALID_HANDLE_VALUE;
93 HMODULE module = 0;
94 DWORD protect = PAGE_READONLY;
95
96 *mod_ret = 0;
97
98 if (flags & LOAD_LIBRARY_AS_IMAGE_RESOURCE) protect |= SEC_IMAGE;
99
100 if (SearchPathW( NULL, name, L".dll", ARRAY_SIZE( filenameW ), filenameW, NULL ))
101 {
102 file = CreateFileW( filenameW, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE,
103 NULL, OPEN_EXISTING, 0, 0 );
104 }
105 if (file == INVALID_HANDLE_VALUE) return FALSE;
106
107 mapping = CreateFileMappingW( file, NULL, protect, 0, 0, NULL );
108 if (!mapping) goto failed;
109
110 module = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 );
111 CloseHandle( mapping );
112 if (!module) goto failed;
113
114 if (!(flags & LOAD_LIBRARY_AS_IMAGE_RESOURCE))
115 {
116 /* make sure it's a valid PE file */
117 if (!RtlImageNtHeader( module ))
118 {
119 SetLastError( ERROR_BAD_EXE_FORMAT );
120 goto failed;
121 }
122 *mod_ret = (HMODULE)((char *)module + 1); /* set bit 0 for data file module */
123
124 if (flags & LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE)
125 {
126 struct exclusive_datafile *datafile = HeapAlloc( GetProcessHeap(), 0, sizeof(*datafile) );
127 if (!datafile) goto failed;
128 datafile->module = *mod_ret;
129 datafile->file = file;
130 RtlEnterCriticalSection( &exclusive_datafile_list_section );
131 list_add_head( &exclusive_datafile_list, &datafile->entry );
132 RtlLeaveCriticalSection( &exclusive_datafile_list_section );
133 TRACE( "delaying close %p for module %p\n", datafile->file, datafile->module );
134 return TRUE;
135 }
136 }
137 else *mod_ret = (HMODULE)((char *)module + 2); /* set bit 1 for image resource module */
138
139 CloseHandle( file );
140 return TRUE;
141
142failed:
143 if (module) UnmapViewOfFile( module );
144 CloseHandle( file );
145 return FALSE;
146}
147
148
149/******************************************************************
150 * load_library
151 */
152static HMODULE load_library( const UNICODE_STRING *libname, DWORD flags )
153{
154 const DWORD unsupported_flags = LOAD_IGNORE_CODE_AUTHZ_LEVEL | LOAD_LIBRARY_REQUIRE_SIGNED_TARGET;
155 NTSTATUS status;
156 HMODULE module;
157 WCHAR *load_path, *dummy;
158
159 if (flags & unsupported_flags) FIXME( "unsupported flag(s) used %#08lx\n", flags );
160
161 if (!set_ntstatus( LdrGetDllPath( libname->Buffer, flags, &load_path, &dummy ))) return 0;
162
163 if (flags & (LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE |
164 LOAD_LIBRARY_AS_IMAGE_RESOURCE))
165 {
166 if (LdrGetDllHandleEx( 0, load_path, NULL, libname, &module ))
167 load_library_as_datafile( load_path, flags, libname->Buffer, &module );
168 }
169 else
170 {
171 status = LdrLoadDll( load_path, flags, libname, &module );
172 if (!set_ntstatus( status ))
173 {
174 module = 0;
175 if (status == STATUS_DLL_NOT_FOUND && (GetVersion() & 0x80000000))
176 SetLastError( ERROR_DLL_NOT_FOUND );
177 }
178 }
179
180 RtlReleasePath( load_path );
181 return module;
182}
183
184
185/****************************************************************************
186 * AddDllDirectory (kernelbase.@)
187 */
188DLL_DIRECTORY_COOKIE WINAPI DECLSPEC_HOTPATCH AddDllDirectory( const WCHAR *dir )
189{
190 UNICODE_STRING str;
191 void *cookie;
192
193 RtlInitUnicodeString( &str, dir );
194 if (!set_ntstatus( LdrAddDllDirectory( &str, &cookie ))) return NULL;
195 return cookie;
196}
197
198
199/***********************************************************************
200 * DelayLoadFailureHook (kernelbase.@)
201 */
202FARPROC WINAPI DECLSPEC_HOTPATCH DelayLoadFailureHook( LPCSTR name, LPCSTR function )
203{
204 ULONG_PTR args[2];
205
206 if ((ULONG_PTR)function >> 16)
207 ERR( "failed to delay load %s.%s\n", name, function );
208 else
209 ERR( "failed to delay load %s.%u\n", name, LOWORD(function) );
210 args[0] = (ULONG_PTR)name;
211 args[1] = (ULONG_PTR)function;
212 RaiseException( EXCEPTION_WINE_STUB, EXCEPTION_NONCONTINUABLE, 2, args );
213 return NULL;
214}
215
216
217/****************************************************************************
218 * DisableThreadLibraryCalls (kernelbase.@)
219 */
220BOOL WINAPI DECLSPEC_HOTPATCH DisableThreadLibraryCalls( HMODULE module )
221{
222 return set_ntstatus( LdrDisableThreadCalloutsForDll( module ));
223}
224
225
226/***********************************************************************
227 * FreeLibrary (kernelbase.@)
228 */
229BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary( HINSTANCE module )
230{
231 if (!module)
232 {
233 SetLastError( ERROR_INVALID_HANDLE );
234 return FALSE;
235 }
236
237 if ((ULONG_PTR)module & 3) /* this is a datafile module */
238 {
239 void *ptr = (void *)((ULONG_PTR)module & ~3);
240 if (!RtlImageNtHeader( ptr ))
241 {
242 SetLastError( ERROR_BAD_EXE_FORMAT );
243 return FALSE;
244 }
245 if ((ULONG_PTR)module & 1)
246 {
247 struct exclusive_datafile *file;
248
249 RtlEnterCriticalSection( &exclusive_datafile_list_section );
250 LIST_FOR_EACH_ENTRY( file, &exclusive_datafile_list, struct exclusive_datafile, entry )
251 {
252 if (file->module != module) continue;
253 TRACE( "closing %p for module %p\n", file->file, file->module );
254 CloseHandle( file->file );
255 list_remove( &file->entry );
256 HeapFree( GetProcessHeap(), 0, file );
257 break;
258 }
259 RtlLeaveCriticalSection( &exclusive_datafile_list_section );
260 }
261 return UnmapViewOfFile( ptr );
262 }
263
264 return set_ntstatus( LdrUnloadDll( module ));
265}
266
267
268/***********************************************************************
269 * GetModuleFileNameA (kernelbase.@)
270 */
271DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameA( HMODULE module, LPSTR filename, DWORD size )
272{
273 LPWSTR filenameW = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) );
274 DWORD len;
275
276 if (!filenameW)
277 {
278 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
279 return 0;
280 }
281 if ((len = GetModuleFileNameW( module, filenameW, size )))
282 {
283 len = file_name_WtoA( filenameW, len, filename, size );
284 if (len < size)
285 filename[len] = 0;
286 else
287 SetLastError( ERROR_INSUFFICIENT_BUFFER );
288 }
289 HeapFree( GetProcessHeap(), 0, filenameW );
290 return len;
291}
292
293
294/***********************************************************************
295 * GetModuleFileNameW (kernelbase.@)
296 */
297DWORD WINAPI DECLSPEC_HOTPATCH GetModuleFileNameW( HMODULE module, LPWSTR filename, DWORD size )
298{
299 ULONG len = 0;
300 WIN16_SUBSYSTEM_TIB *win16_tib;
301 UNICODE_STRING name;
302 NTSTATUS status;
303
304 if (!module && ((win16_tib = NtCurrentTeb()->Tib.SubSystemTib)) && win16_tib->exe_name)
305 {
306 len = min( size, win16_tib->exe_name->Length / sizeof(WCHAR) );
307 memcpy( filename, win16_tib->exe_name->Buffer, len * sizeof(WCHAR) );
308 if (len < size) filename[len] = 0;
309 goto done;
310 }
311
312 name.Buffer = filename;
313 name.MaximumLength = min( size, UNICODE_STRING_MAX_CHARS ) * sizeof(WCHAR);
314 status = LdrGetDllFullName( module, &name );
315 if (!status || status == STATUS_BUFFER_TOO_SMALL) len = name.Length / sizeof(WCHAR);
316 SetLastError( RtlNtStatusToDosError( status ));
317done:
318 TRACE( "%s\n", debugstr_wn(filename, len) );
319 return len;
320}
321
322
323/***********************************************************************
324 * GetModuleHandleA (kernelbase.@)
325 */
326HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA( LPCSTR module )
327{
328 HMODULE ret;
329
330 GetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, module, &ret );
331 return ret;
332}
333
334
335/***********************************************************************
336 * GetModuleHandleW (kernelbase.@)
337 */
338HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleW( LPCWSTR module )
339{
340 HMODULE ret;
341
342 GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, module, &ret );
343 return ret;
344}
345
346
347/***********************************************************************
348 * GetModuleHandleExA (kernelbase.@)
349 */
350BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExA( DWORD flags, LPCSTR name, HMODULE *module )
351{
352 WCHAR *nameW;
353
354 if (!module)
355 {
356 SetLastError( ERROR_INVALID_PARAMETER );
357 return FALSE;
358 }
359
360 if (!name || (flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
361 return GetModuleHandleExW( flags, (LPCWSTR)name, module );
362
363 if (!(nameW = file_name_AtoW( name, FALSE )))
364 {
365 *module = NULL;
366 SetLastError( ERROR_MOD_NOT_FOUND );
367 return FALSE;
368 }
369 return GetModuleHandleExW( flags, nameW, module );
370}
371
372
373/***********************************************************************
374 * GetModuleHandleExW (kernelbase.@)
375 */
376BOOL WINAPI DECLSPEC_HOTPATCH GetModuleHandleExW( DWORD flags, LPCWSTR name, HMODULE *module )
377{
378 HMODULE ret = NULL;
379 NTSTATUS status;
380 void *dummy;
381
382 if (!module)
383 {
384 SetLastError( ERROR_INVALID_PARAMETER );
385 return FALSE;
386 }
387
388 if ((flags & ~(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT
389 | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
390 || (flags & (GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
391 == (GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
392 {
393 *module = NULL;
394 SetLastError( ERROR_INVALID_PARAMETER );
395 return FALSE;
396 }
397
398 if (name && !(flags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
399 {
400 UNICODE_STRING wstr;
401 ULONG ldr_flags = 0;
402
403 if (flags & GET_MODULE_HANDLE_EX_FLAG_PIN)
404 ldr_flags |= LDR_GET_DLL_HANDLE_EX_FLAG_PIN;
405 if (flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT)
406 ldr_flags |= LDR_GET_DLL_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
407
408 RtlInitUnicodeString( &wstr, name );
409 status = LdrGetDllHandleEx( ldr_flags, NULL, NULL, &wstr, &ret );
410 }
411 else
412 {
413 ret = name ? RtlPcToFileHeader( (void *)name, &dummy ) : NtCurrentTeb()->Peb->ImageBaseAddress;
414
415 if (ret)
416 {
417 if (!(flags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
418 status = LdrAddRefDll( flags & GET_MODULE_HANDLE_EX_FLAG_PIN ? LDR_ADDREF_DLL_PIN : 0, ret );
419 else
420 status = STATUS_SUCCESS;
421 } else status = STATUS_DLL_NOT_FOUND;
422 }
423
424 *module = ret;
425 return set_ntstatus( status );
426}
427
428
429/***********************************************************************
430 * GetProcAddress (kernelbase.@)
431 */
432
433/*
434 * Work around a Delphi bug on x86_64. When delay loading a symbol,
435 * Delphi saves rcx, rdx, r8 and r9 to the stack. It then calls
436 * GetProcAddress(), pops the saved registers and calls the function.
437 * This works fine if all of the parameters are ints. However, since
438 * it does not save xmm0 - 3, it relies on GetProcAddress() preserving
439 * these registers if the function takes floating point parameters.
440 * This wrapper saves xmm0 - 3 to the stack.
441 */
442#ifdef __arm64ec__
443FARPROC WINAPI __attribute__((naked)) GetProcAddress( HMODULE module, LPCSTR function )
444{
445 asm( ".seh_proc \"#GetProcAddress\"\n\t"
446 "stp x29, x30, [sp, #-48]!\n\t"
447 ".seh_save_fplr_x 48\n\t"
448 ".seh_endprologue\n\t"
449 "stp d0, d1, [sp, #16]\n\t"
450 "stp d2, d3, [sp, #32]\n\t"
451 "bl \"#get_proc_address\"\n\t"
452 "ldp d0, d1, [sp, #16]\n\t"
453 "ldp d2, d3, [sp, #32]\n\t"
454 "ldp x29, x30, [sp], #48\n\t"
455 "ret\n\t"
456 ".seh_endproc" );
457}
458#elif defined(__x86_64__)
459__ASM_GLOBAL_FUNC( GetProcAddress,
460 ".byte 0x48\n\t" /* hotpatch prolog */
461 "pushq %rbp\n\t"
462 __ASM_SEH(".seh_pushreg %rbp\n\t")
463 __ASM_CFI(".cfi_adjust_cfa_offset 8\n\t")
464 __ASM_CFI(".cfi_rel_offset %rbp,0\n\t")
465 "movq %rsp,%rbp\n\t"
466 __ASM_SEH(".seh_setframe %rbp,0\n\t")
467 __ASM_CFI(".cfi_def_cfa_register %rbp\n\t")
468 __ASM_SEH(".seh_endprologue\n\t")
469 "subq $0x60,%rsp\n\t"
470 "andq $~15,%rsp\n\t"
471 "movaps %xmm0,0x20(%rsp)\n\t"
472 "movaps %xmm1,0x30(%rsp)\n\t"
473 "movaps %xmm2,0x40(%rsp)\n\t"
474 "movaps %xmm3,0x50(%rsp)\n\t"
475 "call " __ASM_NAME("get_proc_address") "\n\t"
476 "movaps 0x50(%rsp), %xmm3\n\t"
477 "movaps 0x40(%rsp), %xmm2\n\t"
478 "movaps 0x30(%rsp), %xmm1\n\t"
479 "movaps 0x20(%rsp), %xmm0\n\t"
480 "leaq 0(%rbp),%rsp\n\t"
481 __ASM_CFI(".cfi_def_cfa_register %rsp\n\t")
482 "popq %rbp\n\t"
483 __ASM_CFI(".cfi_adjust_cfa_offset -8\n\t")
484 __ASM_CFI(".cfi_same_value %rbp\n\t")
485 "ret" )
486#else /* __x86_64__ */
487
488FARPROC WINAPI DECLSPEC_HOTPATCH GetProcAddress( HMODULE module, LPCSTR function )
489{
490 return get_proc_address( module, function );
491}
492
493#endif /* __x86_64__ */
494
495
496/***********************************************************************
497 * IsApiSetImplemented (kernelbase.@)
498 */
499BOOL WINAPI IsApiSetImplemented( LPCSTR name )
500{
501 UNICODE_STRING str;
502 NTSTATUS status;
503 BOOLEAN in_schema, present;
504
505 if (!RtlCreateUnicodeStringFromAsciiz( &str, name )) return FALSE;
506 status = ApiSetQueryApiSetPresenceEx( &str, &in_schema, &present );
507 RtlFreeUnicodeString( &str );
508 return !status && present;
509}
510
511
512/***********************************************************************
513 * LoadLibraryA (kernelbase.@)
514 */
515HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryA( LPCSTR name )
516{
517 return LoadLibraryExA( name, 0, 0 );
518}
519
520
521/***********************************************************************
522 * LoadLibraryW (kernelbase.@)
523 */
524HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryW( LPCWSTR name )
525{
526 return LoadLibraryExW( name, 0, 0 );
527}
528
529
530/******************************************************************
531 * LoadLibraryExA (kernelbase.@)
532 */
533HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA( LPCSTR name, HANDLE file, DWORD flags )
534{
535 WCHAR *nameW;
536
537 if (!(nameW = file_name_AtoW( name, FALSE ))) return 0;
538 return LoadLibraryExW( nameW, file, flags );
539}
540
541
542/***********************************************************************
543 * LoadLibraryExW (kernelbase.@)
544 */
545HMODULE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW( LPCWSTR name, HANDLE file, DWORD flags )
546{
547 UNICODE_STRING str;
548 HMODULE module;
549
550 if (!name)
551 {
552 SetLastError( ERROR_INVALID_PARAMETER );
553 return 0;
554 }
555 RtlInitUnicodeString( &str, name );
556 if (str.Buffer[str.Length/sizeof(WCHAR) - 1] != ' ') return load_library( &str, flags );
557
558 /* library name has trailing spaces */
559 RtlCreateUnicodeString( &str, name );
560 while (str.Length > sizeof(WCHAR) && str.Buffer[str.Length/sizeof(WCHAR) - 1] == ' ')
561 str.Length -= sizeof(WCHAR);
562
563 str.Buffer[str.Length/sizeof(WCHAR)] = 0;
564 module = load_library( &str, flags );
565 RtlFreeUnicodeString( &str );
566 return module;
567}
568
569
570/***********************************************************************
571 * LoadPackagedLibrary (kernelbase.@)
572 */
573HMODULE WINAPI /* DECLSPEC_HOTPATCH */ LoadPackagedLibrary( LPCWSTR name, DWORD reserved )
574{
575 FIXME( "semi-stub, name %s, reserved %#lx.\n", debugstr_w(name), reserved );
576 SetLastError( APPMODEL_ERROR_NO_PACKAGE );
577 return NULL;
578}
579
580
581/***********************************************************************
582 * LoadAppInitDlls (kernelbase.@)
583 */
584void WINAPI LoadAppInitDlls(void)
585{
586 TRACE( "\n" );
587}
588
589
590/****************************************************************************
591 * RemoveDllDirectory (kernelbase.@)
592 */
593BOOL WINAPI DECLSPEC_HOTPATCH RemoveDllDirectory( DLL_DIRECTORY_COOKIE cookie )
594{
595 return set_ntstatus( LdrRemoveDllDirectory( cookie ));
596}
597
598
599/*************************************************************************
600 * SetDefaultDllDirectories (kernelbase.@)
601 */
602BOOL WINAPI DECLSPEC_HOTPATCH SetDefaultDllDirectories( DWORD flags )
603{
604 return set_ntstatus( LdrSetDefaultDllDirectories( flags ));
605}
606
607
608/***********************************************************************
609 * Resources
610 ***********************************************************************/
611
612
613#define IS_INTRESOURCE(x) (((ULONG_PTR)(x) >> 16) == 0)
614
615/* retrieve the resource name to pass to the ntdll functions */
616static NTSTATUS get_res_nameA( LPCSTR name, UNICODE_STRING *str )
617{
618 if (IS_INTRESOURCE(name))
619 {
620 str->Buffer = ULongToPtr( LOWORD(name) );
621 return STATUS_SUCCESS;
622 }
623 if (name[0] == '#')
624 {
625 ULONG value;
626 if (RtlCharToInteger( name + 1, 10, &value ) != STATUS_SUCCESS || HIWORD(value))
627 return STATUS_INVALID_PARAMETER;
628 str->Buffer = ULongToPtr(value);
629 return STATUS_SUCCESS;
630 }
631 RtlCreateUnicodeStringFromAsciiz( str, name );
632 RtlUpcaseUnicodeString( str, str, FALSE );
633 return STATUS_SUCCESS;
634}
635
636/* retrieve the resource name to pass to the ntdll functions */
637static NTSTATUS get_res_nameW( LPCWSTR name, UNICODE_STRING *str )
638{
639 if (IS_INTRESOURCE(name))
640 {
641 str->Buffer = ULongToPtr( LOWORD(name) );
642 return STATUS_SUCCESS;
643 }
644 if (name[0] == '#')
645 {
646 ULONG value;
647 RtlInitUnicodeString( str, name + 1 );
648 if (RtlUnicodeStringToInteger( str, 10, &value ) != STATUS_SUCCESS || HIWORD(value))
649 return STATUS_INVALID_PARAMETER;
650 str->Buffer = ULongToPtr(value);
651 return STATUS_SUCCESS;
652 }
653 RtlCreateUnicodeString( str, name );
654 RtlUpcaseUnicodeString( str, str, FALSE );
655 return STATUS_SUCCESS;
656}
657
658
659/**********************************************************************
660 * EnumResourceLanguagesExA (kernelbase.@)
661 */
662BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceLanguagesExA( HMODULE module, LPCSTR type, LPCSTR name,
663 ENUMRESLANGPROCA func, LONG_PTR param,
664 DWORD flags, LANGID lang )
665{
666 int i;
667 BOOL ret = FALSE;
668 NTSTATUS status;
669 UNICODE_STRING typeW, nameW;
670 LDR_RESOURCE_INFO info;
671 const IMAGE_RESOURCE_DIRECTORY *basedir, *resdir;
672 const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
673
674 TRACE( "%p %s %s %p %Ix %lx %d\n", module, debugstr_a(type), debugstr_a(name),
675 func, param, flags, lang );
676
677 if (flags & (RESOURCE_ENUM_MUI | RESOURCE_ENUM_MUI_SYSTEM | RESOURCE_ENUM_VALIDATE))
678 FIXME( "unimplemented flags: %lx\n", flags );
679
680 if (!flags) flags = RESOURCE_ENUM_LN | RESOURCE_ENUM_MUI;
681 if (!(flags & RESOURCE_ENUM_LN)) return ret;
682
683 if (!module) module = GetModuleHandleW( 0 );
684 typeW.Buffer = nameW.Buffer = NULL;
685 if ((status = LdrFindResourceDirectory_U( module, NULL, 0, &basedir )) != STATUS_SUCCESS)
686 goto done;
687 if ((status = get_res_nameA( type, &typeW )) != STATUS_SUCCESS)
688 goto done;
689 if ((status = get_res_nameA( name, &nameW )) != STATUS_SUCCESS)
690 goto done;
691 info.Type = (ULONG_PTR)typeW.Buffer;
692 info.Name = (ULONG_PTR)nameW.Buffer;
693 if ((status = LdrFindResourceDirectory_U( module, &info, 2, &resdir )) != STATUS_SUCCESS)
694 goto done;
695
696 et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
697 __TRY
698 {
699 for (i = 0; i < resdir->NumberOfNamedEntries + resdir->NumberOfIdEntries; i++)
700 {
701 ret = func( module, type, name, et[i].Id, param );
702 if (!ret) break;
703 }
704 }
705 __EXCEPT_PAGE_FAULT
706 {
707 ret = FALSE;
708 status = STATUS_ACCESS_VIOLATION;
709 }
710 __ENDTRY
711done:
712 if (!IS_INTRESOURCE(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
713 if (!IS_INTRESOURCE(nameW.Buffer)) HeapFree( GetProcessHeap(), 0, nameW.Buffer );
714 if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
715 return ret;
716}
717
718
719/**********************************************************************
720 * EnumResourceLanguagesExW (kernelbase.@)
721 */
722BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceLanguagesExW( HMODULE module, LPCWSTR type, LPCWSTR name,
723 ENUMRESLANGPROCW func, LONG_PTR param,
724 DWORD flags, LANGID lang )
725{
726 int i;
727 BOOL ret = FALSE;
728 NTSTATUS status;
729 UNICODE_STRING typeW, nameW;
730 LDR_RESOURCE_INFO info;
731 const IMAGE_RESOURCE_DIRECTORY *basedir, *resdir;
732 const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
733
734 TRACE( "%p %s %s %p %Ix %lx %d\n", module, debugstr_w(type), debugstr_w(name),
735 func, param, flags, lang );
736
737 if (flags & (RESOURCE_ENUM_MUI | RESOURCE_ENUM_MUI_SYSTEM | RESOURCE_ENUM_VALIDATE))
738 FIXME( "unimplemented flags: %lx\n", flags );
739
740 if (!flags) flags = RESOURCE_ENUM_LN | RESOURCE_ENUM_MUI;
741 if (!(flags & RESOURCE_ENUM_LN)) return ret;
742
743 if (!module) module = GetModuleHandleW( 0 );
744 typeW.Buffer = nameW.Buffer = NULL;
745 if ((status = LdrFindResourceDirectory_U( module, NULL, 0, &basedir )) != STATUS_SUCCESS)
746 goto done;
747 if ((status = get_res_nameW( type, &typeW )) != STATUS_SUCCESS)
748 goto done;
749 if ((status = get_res_nameW( name, &nameW )) != STATUS_SUCCESS)
750 goto done;
751 info.Type = (ULONG_PTR)typeW.Buffer;
752 info.Name = (ULONG_PTR)nameW.Buffer;
753 if ((status = LdrFindResourceDirectory_U( module, &info, 2, &resdir )) != STATUS_SUCCESS)
754 goto done;
755
756 et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
757 __TRY
758 {
759 for (i = 0; i < resdir->NumberOfNamedEntries + resdir->NumberOfIdEntries; i++)
760 {
761 ret = func( module, type, name, et[i].Id, param );
762 if (!ret) break;
763 }
764 }
765 __EXCEPT_PAGE_FAULT
766 {
767 ret = FALSE;
768 status = STATUS_ACCESS_VIOLATION;
769 }
770 __ENDTRY
771done:
772 if (!IS_INTRESOURCE(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
773 if (!IS_INTRESOURCE(nameW.Buffer)) HeapFree( GetProcessHeap(), 0, nameW.Buffer );
774 if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
775 return ret;
776}
777
778
779/**********************************************************************
780 * EnumResourceNamesExA (kernelbase.@)
781 */
782BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceNamesExA( HMODULE module, LPCSTR type, ENUMRESNAMEPROCA func,
783 LONG_PTR param, DWORD flags, LANGID lang )
784{
785 int i;
786 BOOL ret = FALSE;
787 DWORD len = 0, newlen;
788 LPSTR name = NULL;
789 NTSTATUS status;
790 UNICODE_STRING typeW;
791 LDR_RESOURCE_INFO info;
792 const IMAGE_RESOURCE_DIRECTORY *basedir, *resdir;
793 const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
794 const IMAGE_RESOURCE_DIR_STRING_U *str;
795
796 TRACE( "%p %s %p %Ix\n", module, debugstr_a(type), func, param );
797
798 if (flags & (RESOURCE_ENUM_MUI | RESOURCE_ENUM_MUI_SYSTEM | RESOURCE_ENUM_VALIDATE))
799 FIXME( "unimplemented flags: %lx\n", flags );
800
801 if (!flags) flags = RESOURCE_ENUM_LN | RESOURCE_ENUM_MUI;
802 if (!(flags & RESOURCE_ENUM_LN)) return ret;
803
804 if (!module) module = GetModuleHandleW( 0 );
805 typeW.Buffer = NULL;
806 if ((status = LdrFindResourceDirectory_U( module, NULL, 0, &basedir )) != STATUS_SUCCESS)
807 goto done;
808 if ((status = get_res_nameA( type, &typeW )) != STATUS_SUCCESS)
809 goto done;
810 info.Type = (ULONG_PTR)typeW.Buffer;
811 if ((status = LdrFindResourceDirectory_U( module, &info, 1, &resdir )) != STATUS_SUCCESS)
812 goto done;
813
814 et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
815 __TRY
816 {
817 for (i = 0; i < resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries; i++)
818 {
819 if (et[i].NameIsString)
820 {
821 str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const BYTE *)basedir + et[i].NameOffset);
822 newlen = WideCharToMultiByte(CP_ACP, 0, str->NameString, str->Length, NULL, 0, NULL, NULL);
823 if (newlen + 1 > len)
824 {
825 len = newlen + 1;
826 HeapFree( GetProcessHeap(), 0, name );
827 if (!(name = HeapAlloc( GetProcessHeap(), 0, len + 1 )))
828 {
829 ret = FALSE;
830 break;
831 }
832 }
833 WideCharToMultiByte( CP_ACP, 0, str->NameString, str->Length, name, len, NULL, NULL );
834 name[newlen] = 0;
835 ret = func( module, type, name, param );
836 }
837 else
838 {
839 ret = func( module, type, UIntToPtr(et[i].Id), param );
840 }
841 if (!ret) break;
842 }
843 }
844 __EXCEPT_PAGE_FAULT
845 {
846 ret = FALSE;
847 status = STATUS_ACCESS_VIOLATION;
848 }
849 __ENDTRY
850
851done:
852 HeapFree( GetProcessHeap(), 0, name );
853 if (!IS_INTRESOURCE(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
854 if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
855 return ret;
856}
857
858
859/**********************************************************************
860 * EnumResourceNamesExW (kernelbase.@)
861 */
862BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceNamesExW( HMODULE module, LPCWSTR type, ENUMRESNAMEPROCW func,
863 LONG_PTR param, DWORD flags, LANGID lang )
864{
865 int i, len = 0;
866 BOOL ret = FALSE;
867 LPWSTR name = NULL;
868 NTSTATUS status;
869 UNICODE_STRING typeW;
870 LDR_RESOURCE_INFO info;
871 const IMAGE_RESOURCE_DIRECTORY *basedir, *resdir;
872 const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
873 const IMAGE_RESOURCE_DIR_STRING_U *str;
874
875 TRACE( "%p %s %p %Ix\n", module, debugstr_w(type), func, param );
876
877 if (flags & (RESOURCE_ENUM_MUI | RESOURCE_ENUM_MUI_SYSTEM | RESOURCE_ENUM_VALIDATE))
878 FIXME( "unimplemented flags: %lx\n", flags );
879
880 if (!flags) flags = RESOURCE_ENUM_LN | RESOURCE_ENUM_MUI;
881 if (!(flags & RESOURCE_ENUM_LN)) return ret;
882
883 if (!module) module = GetModuleHandleW( 0 );
884 typeW.Buffer = NULL;
885 if ((status = LdrFindResourceDirectory_U( module, NULL, 0, &basedir )) != STATUS_SUCCESS)
886 goto done;
887 if ((status = get_res_nameW( type, &typeW )) != STATUS_SUCCESS)
888 goto done;
889 info.Type = (ULONG_PTR)typeW.Buffer;
890 if ((status = LdrFindResourceDirectory_U( module, &info, 1, &resdir )) != STATUS_SUCCESS)
891 goto done;
892
893 et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
894 __TRY
895 {
896 for (i = 0; i < resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries; i++)
897 {
898 if (et[i].NameIsString)
899 {
900 str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const BYTE *)basedir + et[i].NameOffset);
901 if (str->Length + 1 > len)
902 {
903 len = str->Length + 1;
904 HeapFree( GetProcessHeap(), 0, name );
905 if (!(name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
906 {
907 ret = FALSE;
908 break;
909 }
910 }
911 memcpy(name, str->NameString, str->Length * sizeof (WCHAR));
912 name[str->Length] = 0;
913 ret = func( module, type, name, param );
914 }
915 else
916 {
917 ret = func( module, type, UIntToPtr(et[i].Id), param );
918 }
919 if (!ret) break;
920 }
921 }
922 __EXCEPT_PAGE_FAULT
923 {
924 ret = FALSE;
925 status = STATUS_ACCESS_VIOLATION;
926 }
927 __ENDTRY
928done:
929 HeapFree( GetProcessHeap(), 0, name );
930 if (!IS_INTRESOURCE(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
931 if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
932 return ret;
933}
934
935
936/**********************************************************************
937 * EnumResourceNamesW (kernelbase.@)
938 */
939BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceNamesW( HMODULE module, LPCWSTR type,
940 ENUMRESNAMEPROCW func, LONG_PTR param )
941{
942 return EnumResourceNamesExW( module, type, func, param, 0, 0 );
943}
944
945
946/**********************************************************************
947 * EnumResourceTypesExA (kernelbase.@)
948 */
949BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceTypesExA( HMODULE module, ENUMRESTYPEPROCA func, LONG_PTR param,
950 DWORD flags, LANGID lang )
951{
952 int i;
953 BOOL ret = FALSE;
954 LPSTR type = NULL;
955 DWORD len = 0, newlen;
956 const IMAGE_RESOURCE_DIRECTORY *resdir;
957 const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
958 const IMAGE_RESOURCE_DIR_STRING_U *str;
959
960 TRACE( "%p %p %Ix\n", module, func, param );
961
962 if (flags & (RESOURCE_ENUM_MUI | RESOURCE_ENUM_MUI_SYSTEM | RESOURCE_ENUM_VALIDATE))
963 FIXME( "unimplemented flags: %lx\n", flags );
964
965 if (!flags) flags = RESOURCE_ENUM_LN | RESOURCE_ENUM_MUI;
966 if (!(flags & RESOURCE_ENUM_LN)) return ret;
967
968 if (!module) module = GetModuleHandleW( 0 );
969
970 if (!set_ntstatus( LdrFindResourceDirectory_U( module, NULL, 0, &resdir ))) return FALSE;
971
972 et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
973 for (i = 0; i < resdir->NumberOfNamedEntries+resdir->NumberOfIdEntries; i++)
974 {
975 if (et[i].NameIsString)
976 {
977 str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const BYTE *)resdir + et[i].NameOffset);
978 newlen = WideCharToMultiByte( CP_ACP, 0, str->NameString, str->Length, NULL, 0, NULL, NULL);
979 if (newlen + 1 > len)
980 {
981 len = newlen + 1;
982 HeapFree( GetProcessHeap(), 0, type );
983 if (!(type = HeapAlloc( GetProcessHeap(), 0, len ))) return FALSE;
984 }
985 WideCharToMultiByte( CP_ACP, 0, str->NameString, str->Length, type, len, NULL, NULL);
986 type[newlen] = 0;
987 ret = func( module, type, param );
988 }
989 else
990 {
991 ret = func( module, UIntToPtr(et[i].Id), param );
992 }
993 if (!ret) break;
994 }
995 HeapFree( GetProcessHeap(), 0, type );
996 return ret;
997}
998
999
1000/**********************************************************************
1001 * EnumResourceTypesExW (kernelbase.@)
1002 */
1003BOOL WINAPI DECLSPEC_HOTPATCH EnumResourceTypesExW( HMODULE module, ENUMRESTYPEPROCW func, LONG_PTR param,
1004 DWORD flags, LANGID lang )
1005{
1006 int i, len = 0;
1007 BOOL ret = FALSE;
1008 LPWSTR type = NULL;
1009 const IMAGE_RESOURCE_DIRECTORY *resdir;
1010 const IMAGE_RESOURCE_DIRECTORY_ENTRY *et;
1011 const IMAGE_RESOURCE_DIR_STRING_U *str;
1012
1013 TRACE( "%p %p %Ix\n", module, func, param );
1014
1015 if (!flags) flags = RESOURCE_ENUM_LN | RESOURCE_ENUM_MUI;
1016 if (!(flags & RESOURCE_ENUM_LN)) return ret;
1017
1018 if (!module) module = GetModuleHandleW( 0 );
1019
1020 if (!set_ntstatus( LdrFindResourceDirectory_U( module, NULL, 0, &resdir ))) return FALSE;
1021
1022 et = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(resdir + 1);
1023 for (i = 0; i < resdir->NumberOfNamedEntries + resdir->NumberOfIdEntries; i++)
1024 {
1025 if (et[i].NameIsString)
1026 {
1027 str = (const IMAGE_RESOURCE_DIR_STRING_U *)((const BYTE *)resdir + et[i].NameOffset);
1028 if (str->Length + 1 > len)
1029 {
1030 len = str->Length + 1;
1031 HeapFree( GetProcessHeap(), 0, type );
1032 if (!(type = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return FALSE;
1033 }
1034 memcpy(type, str->NameString, str->Length * sizeof (WCHAR));
1035 type[str->Length] = 0;
1036 ret = func( module, type, param );
1037 }
1038 else
1039 {
1040 ret = func( module, UIntToPtr(et[i].Id), param );
1041 }
1042 if (!ret) break;
1043 }
1044 HeapFree( GetProcessHeap(), 0, type );
1045 return ret;
1046}
1047
1048
1049/**********************************************************************
1050 * FindResourceExW (kernelbase.@)
1051 */
1052HRSRC WINAPI DECLSPEC_HOTPATCH FindResourceExW( HMODULE module, LPCWSTR type, LPCWSTR name, WORD lang )
1053{
1054 NTSTATUS status;
1055 UNICODE_STRING nameW, typeW;
1056 LDR_RESOURCE_INFO info;
1057 const IMAGE_RESOURCE_DATA_ENTRY *entry = NULL;
1058
1059 TRACE( "%p %s %s %04x\n", module, debugstr_w(type), debugstr_w(name), lang );
1060
1061 if (!module) module = GetModuleHandleW( 0 );
1062 nameW.Buffer = typeW.Buffer = NULL;
1063
1064 __TRY
1065 {
1066 if ((status = get_res_nameW( name, &nameW )) != STATUS_SUCCESS) goto done;
1067 if ((status = get_res_nameW( type, &typeW )) != STATUS_SUCCESS) goto done;
1068 info.Type = (ULONG_PTR)typeW.Buffer;
1069 info.Name = (ULONG_PTR)nameW.Buffer;
1070 info.Language = lang;
1071 status = LdrFindResource_U( module, &info, 3, &entry );
1072 done:
1073 if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
1074 }
1075 __EXCEPT_PAGE_FAULT
1076 {
1077 SetLastError( ERROR_INVALID_PARAMETER );
1078 }
1079 __ENDTRY
1080
1081 if (!IS_INTRESOURCE(nameW.Buffer)) HeapFree( GetProcessHeap(), 0, nameW.Buffer );
1082 if (!IS_INTRESOURCE(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
1083 return (HRSRC)entry;
1084}
1085
1086
1087/**********************************************************************
1088 * FindResourceW (kernelbase.@)
1089 */
1090HRSRC WINAPI DECLSPEC_HOTPATCH FindResourceW( HINSTANCE module, LPCWSTR name, LPCWSTR type )
1091{
1092 return FindResourceExW( module, type, name, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) );
1093}
1094
1095
1096/**********************************************************************
1097 * FreeResource (kernelbase.@)
1098 */
1099BOOL WINAPI DECLSPEC_HOTPATCH FreeResource( HGLOBAL handle )
1100{
1101 return FALSE;
1102}
1103
1104
1105/**********************************************************************
1106 * LoadResource (kernelbase.@)
1107 */
1108HGLOBAL WINAPI DECLSPEC_HOTPATCH LoadResource( HINSTANCE module, HRSRC rsrc )
1109{
1110 void *ret;
1111
1112 TRACE( "%p %p\n", module, rsrc );
1113
1114 if (!rsrc) return 0;
1115 if (!module) module = GetModuleHandleW( 0 );
1116 if (!set_ntstatus( LdrAccessResource( module, (IMAGE_RESOURCE_DATA_ENTRY *)rsrc, &ret, NULL )))
1117 return 0;
1118 return ret;
1119}
1120
1121
1122/**********************************************************************
1123 * LockResource (kernelbase.@)
1124 */
1125LPVOID WINAPI DECLSPEC_HOTPATCH LockResource( HGLOBAL handle )
1126{
1127 return handle;
1128}
1129
1130
1131/**********************************************************************
1132 * SizeofResource (kernelbase.@)
1133 */
1134DWORD WINAPI DECLSPEC_HOTPATCH SizeofResource( HINSTANCE module, HRSRC rsrc )
1135{
1136 if (!rsrc) return 0;
1137 return ((IMAGE_RESOURCE_DATA_ENTRY *)rsrc)->Size;
1138}
1139
1140
1141/***********************************************************************
1142 * Activation contexts
1143 ***********************************************************************/
1144
1145
1146/***********************************************************************
1147 * ActivateActCtx (kernelbase.@)
1148 */
1149BOOL WINAPI DECLSPEC_HOTPATCH ActivateActCtx( HANDLE context, ULONG_PTR *cookie )
1150{
1151 return set_ntstatus( RtlActivateActivationContext( 0, context, cookie ));
1152}
1153
1154
1155/***********************************************************************
1156 * AddRefActCtx (kernelbase.@)
1157 */
1158void WINAPI DECLSPEC_HOTPATCH AddRefActCtx( HANDLE context )
1159{
1160 RtlAddRefActivationContext( context );
1161}
1162
1163
1164/***********************************************************************
1165 * CreateActCtxW (kernelbase.@)
1166 */
1167HANDLE WINAPI DECLSPEC_HOTPATCH CreateActCtxW( PCACTCTXW ctx )
1168{
1169 HANDLE context;
1170
1171 TRACE( "%p %08lx\n", ctx, ctx ? ctx->dwFlags : 0 );
1172
1173 if (!set_ntstatus( RtlCreateActivationContext( &context, ctx ))) return INVALID_HANDLE_VALUE;
1174 return context;
1175}
1176
1177
1178/***********************************************************************
1179 * DeactivateActCtx (kernelbase.@)
1180 */
1181BOOL WINAPI DECLSPEC_HOTPATCH DeactivateActCtx( DWORD flags, ULONG_PTR cookie )
1182{
1183 RtlDeactivateActivationContext( flags, cookie );
1184 return TRUE;
1185}
1186
1187
1188/***********************************************************************
1189 * FindActCtxSectionGuid (kernelbase.@)
1190 */
1191BOOL WINAPI DECLSPEC_HOTPATCH FindActCtxSectionGuid( DWORD flags, const GUID *ext_guid, ULONG id,
1192 const GUID *guid, PACTCTX_SECTION_KEYED_DATA info )
1193{
1194 return set_ntstatus( RtlFindActivationContextSectionGuid( flags, ext_guid, id, guid, info ));
1195}
1196
1197
1198/***********************************************************************
1199 * FindActCtxSectionStringW (kernelbase.@)
1200 */
1201BOOL WINAPI DECLSPEC_HOTPATCH FindActCtxSectionStringW( DWORD flags, const GUID *ext_guid, ULONG id,
1202 LPCWSTR str, PACTCTX_SECTION_KEYED_DATA info )
1203{
1204 UNICODE_STRING us;
1205
1206 if (!info)
1207 {
1208 SetLastError( ERROR_INVALID_PARAMETER );
1209 return FALSE;
1210 }
1211 RtlInitUnicodeString( &us, str );
1212 return set_ntstatus( RtlFindActivationContextSectionString( flags, ext_guid, id, &us, info ));
1213}
1214
1215
1216/***********************************************************************
1217 * GetCurrentActCtx (kernelbase.@)
1218 */
1219BOOL WINAPI DECLSPEC_HOTPATCH GetCurrentActCtx( HANDLE *pcontext )
1220{
1221 return set_ntstatus( RtlGetActiveActivationContext( pcontext ));
1222}
1223
1224
1225/***********************************************************************
1226 * QueryActCtxSettingsW (kernelbase.@)
1227 */
1228BOOL WINAPI DECLSPEC_HOTPATCH QueryActCtxSettingsW( DWORD flags, HANDLE ctx, const WCHAR *ns,
1229 const WCHAR *settings, WCHAR *buffer, SIZE_T size,
1230 SIZE_T *written )
1231{
1232 return set_ntstatus( RtlQueryActivationContextApplicationSettings( flags, ctx, ns, settings,
1233 buffer, size, written ));
1234}
1235
1236
1237/***********************************************************************
1238 * QueryActCtxW (kernelbase.@)
1239 */
1240BOOL WINAPI DECLSPEC_HOTPATCH QueryActCtxW( DWORD flags, HANDLE context, PVOID inst, ULONG class,
1241 PVOID buffer, SIZE_T size, SIZE_T *written )
1242{
1243 return set_ntstatus( RtlQueryInformationActivationContext( flags, context, inst, class,
1244 buffer, size, written ));
1245}
1246
1247
1248/***********************************************************************
1249 * ReleaseActCtx (kernelbase.@)
1250 */
1251void WINAPI DECLSPEC_HOTPATCH ReleaseActCtx( HANDLE context )
1252{
1253 RtlReleaseActivationContext( context );
1254}
1255
1256
1257/***********************************************************************
1258 * ZombifyActCtx (kernelbase.@)
1259 */
1260BOOL WINAPI DECLSPEC_HOTPATCH ZombifyActCtx( HANDLE context )
1261{
1262 return set_ntstatus( RtlZombifyActivationContext( context ));
1263}