ReactOS  0.4.14-dev-52-g6116262
loader.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for loader.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS WINAPI BasepInitializeTermsrvFpns (VOID)
 
DWORD WINAPI BasepGetModuleHandleExParameterValidation (DWORD dwFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
 
PVOID WINAPI BasepMapModuleHandle (HMODULE hModule, BOOLEAN AsDataFile)
 
BOOL WINAPI DisableThreadLibraryCalls (IN HMODULE hLibModule)
 
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA (LPCSTR lpLibFileName)
 
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA (LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
 
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryW (LPCWSTR lpLibFileName)
 
static NTSTATUS BasepLoadLibraryAsDatafile (PWSTR Path, LPCWSTR Name, HMODULE *hModule)
 
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW (LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
 
FARPROC WINAPI GetProcAddress (HMODULE hModule, LPCSTR lpProcName)
 
BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary (HINSTANCE hLibModule)
 
VOID WINAPI FreeLibraryAndExitThread (HMODULE hLibModule, DWORD dwExitCode)
 
DWORD WINAPI GetModuleFileNameA (HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
 
DWORD WINAPI GetModuleFileNameW (HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
 
HMODULE WINAPI GetModuleHandleForUnicodeString (PUNICODE_STRING ModuleName)
 
BOOLEAN WINAPI BasepGetModuleHandleExW (BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
 
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA (LPCSTR lpModuleName)
 
HMODULE WINAPI GetModuleHandleW (LPCWSTR lpModuleName)
 
BOOL WINAPI GetModuleHandleExW (IN DWORD dwFlags, IN LPCWSTR lpwModuleName OPTIONAL, OUT HMODULE *phModule)
 
BOOL WINAPI GetModuleHandleExA (IN DWORD dwFlags, IN LPCSTR lpModuleName OPTIONAL, OUT HMODULE *phModule)
 
DWORD WINAPI LoadModule (LPCSTR lpModuleName, LPVOID lpParameterBlock)
 
FARPROC WINAPI DelayLoadFailureHook (LPCSTR pszDllName, LPCSTR pszProcName)
 
BOOL WINAPI UTRegister (HMODULE hModule, LPSTR lpsz16BITDLL, LPSTR lpszInitName, LPSTR lpszProcName, FARPROC *ppfn32Thunk, FARPROC pfnUT32CallBack, LPVOID lpBuff)
 
VOID WINAPI UTUnRegister (HMODULE hModule)
 
BOOL WINAPI BaseQueryModuleData (IN LPSTR ModuleName, IN LPSTR Unknown, IN PVOID Unknown2, IN PVOID Unknown3, IN PVOID Unknown4)
 
NTSTATUS WINAPI BaseProcessInitPostImport (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file loader.c.

Function Documentation

◆ BasepGetModuleHandleExParameterValidation()

DWORD WINAPI BasepGetModuleHandleExParameterValidation ( DWORD  dwFlags,
LPCWSTR  lpwModuleName,
HMODULE phModule 
)

Definition at line 26 of file loader.c.

29 {
30  /* Set phModule to 0 if it's not a NULL pointer */
31  if (phModule) *phModule = 0;
32 
33  /* Check for invalid flags combination */
34  if (dwFlags & ~(GET_MODULE_HANDLE_EX_FLAG_PIN |
35  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT |
36  GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS) ||
37  ((dwFlags & GET_MODULE_HANDLE_EX_FLAG_PIN) &&
38  (dwFlags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT)) ||
39  (!lpwModuleName && (dwFlags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
40  )
41  {
44  }
45 
46  /* Check 2nd parameter */
47  if (!phModule)
48  {
51  }
52 
53  /* Return what we have according to the module name */
54  if (lpwModuleName)
55  {
57  }
58 
59  /* No name given, so put ImageBaseAddress there */
60  *phModule = (HMODULE)NtCurrentPeb()->ImageBaseAddress;
61 
63 }
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_ERROR
Definition: kernel32.h:107
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:461
HANDLE HMODULE
Definition: typedefs.h:75
#define NtCurrentPeb()
Definition: FLS.c:20
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS
Definition: kernel32.h:108
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_CONTINUE
Definition: kernel32.h:109

Referenced by BasepGetModuleHandleExW(), GetModuleHandleExA(), and GetModuleHandleExW().

◆ BasepGetModuleHandleExW()

BOOLEAN WINAPI BasepGetModuleHandleExW ( BOOLEAN  NoLock,
DWORD  dwPublicFlags,
LPCWSTR  lpwModuleName,
HMODULE phModule 
)

Definition at line 725 of file loader.c.

726 {
728  NTSTATUS Status = STATUS_SUCCESS, Status2;
729  HANDLE hModule = NULL;
730  UNICODE_STRING ModuleNameU;
731  DWORD dwValid;
732  BOOLEAN Redirected = FALSE; // FIXME
733 
734  /* Validate parameters */
735  dwValid = BasepGetModuleHandleExParameterValidation(dwPublicFlags, lpwModuleName, phModule);
737 
738  /* Acquire lock if necessary */
739  if (!NoLock)
740  {
742  if (!NT_SUCCESS(Status))
743  {
744  /* Fail */
746  if (phModule) *phModule = NULL;
747  return NT_SUCCESS(Status);
748  }
749  }
750 
751  if (!(dwPublicFlags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
752  {
753  /* Create a unicode string out of module name */
754  RtlInitUnicodeString(&ModuleNameU, lpwModuleName);
755 
756  // FIXME: Do some redirected DLL stuff?
757  if (Redirected)
758  {
760  }
761 
762  if (!hModule)
763  {
765  if (!hModule)
766  {
767  /* Last error is already set, so just return failure by setting status */
769  goto quickie;
770  }
771  }
772  }
773  else
774  {
775  /* Perform Pc to file header to get module instance */
776  hModule = (HMODULE)RtlPcToFileHeader((PVOID)lpwModuleName,
777  (PVOID*)&hModule);
778 
779  /* Check if it succeeded */
780  if (!hModule)
781  {
782  /* Set "dll not found" status and quit */
784  goto quickie;
785  }
786  }
787 
788  /* Check if changing reference is not forbidden */
789  if (!(dwPublicFlags & GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT))
790  {
791  /* Add reference to this DLL */
792  Status = LdrAddRefDll((dwPublicFlags & GET_MODULE_HANDLE_EX_FLAG_PIN) ? LDR_ADDREF_DLL_PIN : 0,
793  hModule);
794  }
795 
796 quickie:
797  /* Set last error in case of failure */
798  if (!NT_SUCCESS(Status))
800 
801  /* Unlock loader lock if it was acquired */
802  if (!NoLock)
803  {
804  Status2 = LdrUnlockLoaderLock(0, Cookie);
805  ASSERT(NT_SUCCESS(Status2));
806  }
807 
808  /* Set the module handle to the caller */
809  if (phModule) *phModule = hModule;
810 
811  /* Return TRUE on success and FALSE otherwise */
812  return NT_SUCCESS(Status);
813 }
NTSTATUS NTAPI LdrUnlockLoaderLock(IN ULONG Flags, IN ULONG Cookie OPTIONAL)
Definition: ldrapi.c:101
NTSTATUS NTAPI LdrAddRefDll(IN ULONG Flags, IN PVOID BaseAddress)
Definition: ldrapi.c:1237
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI LdrLockLoaderLock(IN ULONG Flags, OUT PULONG Disposition OPTIONAL, OUT PULONG_PTR Cookie OPTIONAL)
Definition: ldrapi.c:173
PVOID NTAPI RtlPcToFileHeader(IN PVOID PcValue, PVOID *BaseOfImage)
Definition: libsupp.c:616
uint32_t ULONG_PTR
Definition: typedefs.h:63
HMODULE WINAPI GetModuleHandleForUnicodeString(PUNICODE_STRING ModuleName)
Definition: loader.c:676
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:13
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
HANDLE HMODULE
Definition: typedefs.h:75
DWORD WINAPI BasepGetModuleHandleExParameterValidation(DWORD dwFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
Definition: loader.c:26
#define STATUS_DLL_NOT_FOUND
Definition: ntstatus.h:531
#define LDR_ADDREF_DLL_PIN
Definition: ldrtypes.h:71
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNIMPLEMENTED
Definition: debug.h:114
return STATUS_SUCCESS
Definition: btrfs.c:2966
HMODULE hModule
Definition: animate.c:44
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_CONTINUE
Definition: kernel32.h:109

Referenced by GetModuleHandleExA(), GetModuleHandleExW(), and GetModuleHandleW().

◆ BasepInitializeTermsrvFpns()

NTSTATUS WINAPI BasepInitializeTermsrvFpns ( VOID  )

Definition at line 18 of file loader.c.

19 {
22 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define UNIMPLEMENTED
Definition: debug.h:114

Referenced by BaseProcessInitPostImport().

◆ BasepLoadLibraryAsDatafile()

static NTSTATUS BasepLoadLibraryAsDatafile ( PWSTR  Path,
LPCWSTR  Name,
HMODULE hModule 
)
static

Definition at line 188 of file loader.c.

189 {
190  WCHAR FilenameW[MAX_PATH];
192  HANDLE hMapping;
194  PVOID lpBaseAddress = NULL;
195  SIZE_T ViewSize = 0;
196  //PUNICODE_STRING OriginalName;
197  //UNICODE_STRING dotDLL = RTL_CONSTANT_STRING(L".DLL");
198 
199  /* Zero out handle value */
200  *hModule = 0;
201 
202  DPRINT("BasepLoadLibraryAsDatafile(%S %S %p)\n", Path, Name, hModule);
203 
204  /*Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
205  Name,
206  &dotDLL,
207  RedirName,
208  RedirName2,
209  &OriginalName2,
210  NULL,
211  NULL,
212  NULL);*/
213 
214  /* Try to search for it */
215  if (!SearchPathW(Path,
216  Name,
217  L".DLL",
218  sizeof(FilenameW) / sizeof(FilenameW[0]),
219  FilenameW,
220  NULL))
221  {
222  /* Return last status value directly */
223  return NtCurrentTeb()->LastStatusValue;
224  }
225 
226  /* Open this file we found */
227  hFile = CreateFileW(FilenameW,
228  GENERIC_READ,
230  NULL,
232  0,
233  0);
234 
235  /* If opening failed - return last status value */
236  if (hFile == INVALID_HANDLE_VALUE) return NtCurrentTeb()->LastStatusValue;
237 
238  /* Create file mapping */
239  hMapping = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
240 
241  /* Close the file handle */
243 
244  /* If creating file mapping failed - return last status value */
245  if (!hMapping) return NtCurrentTeb()->LastStatusValue;
246 
247  /* Map view of section */
248  Status = NtMapViewOfSection(hMapping,
250  &lpBaseAddress,
251  0,
252  0,
253  0,
254  &ViewSize,
255  ViewShare,
256  0,
257  PAGE_READONLY);
258 
259  /* Close handle to the section */
260  CloseHandle(hMapping);
261 
262  /* If mapping view of section failed - return last status value */
263  if (!NT_SUCCESS(Status)) return NtCurrentTeb()->LastStatusValue;
264 
265  /* Make sure it's a valid PE file */
266  if (!RtlImageNtHeader(lpBaseAddress))
267  {
268  /* Unmap the view and return failure status */
269  UnmapViewOfFile(lpBaseAddress);
271  }
272 
273  /* Set low bit of handle to indicate datafile module */
274  *hModule = (HMODULE)((ULONG_PTR)lpBaseAddress | 1);
275 
276  /* Load alternate resource module */
277  //LdrLoadAlternateResourceModule(*hModule, FilenameW);
278 
279  return STATUS_SUCCESS;
280 }
#define CloseHandle
Definition: compat.h:398
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define FILE_SHARE_READ
Definition: compat.h:125
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI NtMapViewOfSection(IN HANDLE SectionHandle, IN HANDLE ProcessHandle, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3554
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define OPEN_EXISTING
Definition: compat.h:426
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:401
#define MAX_PATH
Definition: compat.h:26
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
Status
Definition: gdiplustypes.h:24
HANDLE HMODULE
Definition: typedefs.h:75
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PRTL_UNICODE_STRING_BUFFER Path
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
#define PAGE_READONLY
Definition: compat.h:127
#define RtlImageNtHeader
Definition: compat.h:457
#define CreateFileW
Definition: compat.h:400
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define UnmapViewOfFile
Definition: compat.h:403
HMODULE hModule
Definition: animate.c:44

Referenced by LoadLibraryExW().

◆ BasepMapModuleHandle()

PVOID WINAPI BasepMapModuleHandle ( HMODULE  hModule,
BOOLEAN  AsDataFile 
)

Definition at line 67 of file loader.c.

68 {
69  /* If no handle is provided - use current image base address */
70  if (!hModule) return NtCurrentPeb()->ImageBaseAddress;
71 
72  /* Check if it's a normal or a datafile one */
73  if (LDR_IS_DATAFILE(hModule) && !AsDataFile)
74  return NULL;
75 
76  /* It's a normal DLL, just return its handle */
77  return hModule;
78 }
#define LDR_IS_DATAFILE(handle)
Definition: ldrtypes.h:103
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentPeb()
Definition: FLS.c:20
HMODULE hModule
Definition: animate.c:44

Referenced by GetModuleFileNameW(), and GetProcAddress().

◆ BaseProcessInitPostImport()

NTSTATUS WINAPI BaseProcessInitPostImport ( VOID  )

Definition at line 1143 of file loader.c.

1144 {
1145  DPRINT("Post-init called\n");
1146 
1147  /* Check if this is a terminal server */
1148  if (SharedUserData->SuiteMask & VER_SUITE_TERMINAL)
1149  {
1150  /* Initialize TS pointers */
1151  return BasepInitializeTermsrvFpns();
1152  }
1153 
1154  /* FIXME: Initialize TS pointers */
1155  return STATUS_SUCCESS;
1156 }
#define VER_SUITE_TERMINAL
NTSTATUS WINAPI BasepInitializeTermsrvFpns(VOID)
Definition: loader.c:18
void DPRINT(...)
Definition: polytest.cpp:61
#define SharedUserData
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ BaseQueryModuleData()

BOOL WINAPI BaseQueryModuleData ( IN LPSTR  ModuleName,
IN LPSTR  Unknown,
IN PVOID  Unknown2,
IN PVOID  Unknown3,
IN PVOID  Unknown4 
)

Definition at line 1123 of file loader.c.

1128 {
1129  DPRINT1("BaseQueryModuleData called: %s %s %p %p %p\n",
1130  ModuleName,
1131  Unknown,
1132  Unknown2,
1133  Unknown3,
1134  Unknown4);
1135  return FALSE;
1136 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES IN DWORD Unknown3
Definition: conport.c:35
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1264
PRTL_UNICODE_STRING_BUFFER PULONG PULONG Unknown4
#define DPRINT1
Definition: precomp.h:8

◆ DelayLoadFailureHook()

FARPROC WINAPI DelayLoadFailureHook ( LPCSTR  pszDllName,
LPCSTR  pszProcName 
)

Definition at line 1092 of file loader.c.

1093 {
1094  STUB;
1095  return NULL;
1096 }
smooth NULL
Definition: ftsmooth.c:416
#define STUB
Definition: kernel32.h:27

◆ DisableThreadLibraryCalls()

BOOL WINAPI DisableThreadLibraryCalls ( IN HMODULE  hLibModule)

Definition at line 85 of file loader.c.

87 {
89 
90  /* Disable thread library calls */
92 
93  /* If it wasn't success - set last error and return failure */
94  if (!NT_SUCCESS(Status))
95  {
97  return FALSE;
98  }
99 
100  /* Return success */
101  return TRUE;
102 }
HINSTANCE hLibModule
Definition: sfc.c:23
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
Definition: ldrapi.c:1187

Referenced by _CorDllMain(), DllMain(), if(), LpkDllInitialize(), STRMBASE_DllMain(), WIC_DllMain(), and wined3d_dll_init().

◆ FreeLibrary()

BOOL WINAPI DECLSPEC_HOTPATCH FreeLibrary ( HINSTANCE  hLibModule)

Definition at line 460 of file loader.c.

461 {
463  PIMAGE_NT_HEADERS NtHeaders;
464 
466  {
467  // FIXME: This SEH should go inside RtlImageNtHeader instead
468  // See https://jira.reactos.org/browse/CORE-14857
469  _SEH2_TRY
470  {
471  /* This is a LOAD_LIBRARY_AS_DATAFILE module, check if it's a valid one */
472  NtHeaders = RtlImageNtHeader((PVOID)((ULONG_PTR)hLibModule & ~1));
473  }
475  {
476  NtHeaders = NULL;
477  } _SEH2_END
478 
479  if (NtHeaders)
480  {
481  /* Unmap view */
483 
484  /* Unload alternate resource module */
486  }
487  else
489  }
490  else
491  {
492  /* Just unload it */
494  }
495 
496  /* Check what kind of status we got */
497  if (!NT_SUCCESS(Status))
498  {
499  /* Set last error */
501 
502  /* Return failure */
503  return FALSE;
504  }
505 
506  /* Return success */
507  return TRUE;
508 }
HINSTANCE hLibModule
Definition: sfc.c:23
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
#define TRUE
Definition: types.h:120
#define LDR_IS_DATAFILE(handle)
Definition: ldrtypes.h:103
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NtCurrentProcess()
Definition: nt_native.h:1657
BOOLEAN NTAPI LdrUnloadAlternateResourceModule(IN PVOID BaseAddress)
Definition: ldrapi.c:1630
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:345
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI LdrUnloadDll(IN PVOID BaseAddress)
Definition: ldrapi.c:1322
_SEH2_END
Definition: create.c:4424
#define RtlImageNtHeader
Definition: compat.h:457
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by child_process(), dll_entry_point(), map_image_section(), test_filenames(), test_image_mapping(), test_import_resolution(), test_Loader(), test_ResolveDelayLoadedAPI(), test_section_access(), and wine_dlclose().

◆ FreeLibraryAndExitThread()

VOID WINAPI FreeLibraryAndExitThread ( HMODULE  hLibModule,
DWORD  dwExitCode 
)

Definition at line 516 of file loader.c.

518 {
519 
521  {
522  /* This is a LOAD_LIBRARY_AS_DATAFILE module */
524  {
525  /* Unmap view */
527 
528  /* Unload alternate resource module */
530  }
531  }
532  else
533  {
534  /* Just unload it */
536  }
537 
538  /* Exit thread */
539  ExitThread(dwExitCode);
540 }
HINSTANCE hLibModule
Definition: sfc.c:23
NTSTATUS NTAPI NtUnmapViewOfSection(IN HANDLE ProcessHandle, IN PVOID BaseAddress)
Definition: section.c:3782
#define LDR_IS_DATAFILE(handle)
Definition: ldrtypes.h:103
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:364
#define NtCurrentProcess()
Definition: nt_native.h:1657
BOOLEAN NTAPI LdrUnloadAlternateResourceModule(IN PVOID BaseAddress)
Definition: ldrapi.c:1630
NTSTATUS NTAPI LdrUnloadDll(IN PVOID BaseAddress)
Definition: ldrapi.c:1322
#define RtlImageNtHeader
Definition: compat.h:457

Referenced by collect_connections_proc(), connection_collector(), ExitThreadApc(), GPNotificationThreadProc(), LookupThreadProc(), CSysTray::SysTrayThreadProc(), wined3d_cs_run(), and WsAsyncThread().

◆ GetModuleFileNameA()

DWORD WINAPI GetModuleFileNameA ( HINSTANCE  hModule,
LPSTR  lpFilename,
DWORD  nSize 
)

Definition at line 548 of file loader.c.

551 {
552  UNICODE_STRING FilenameW;
553  ANSI_STRING FilenameA;
555  DWORD Length = 0, LengthToCopy;
556 
557  /* Allocate a unicode buffer */
558  FilenameW.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, nSize * sizeof(WCHAR));
559  if (!FilenameW.Buffer)
560  {
562  return 0;
563  }
564 
565  /* Call unicode API */
566  FilenameW.Length = (USHORT)GetModuleFileNameW(hModule, FilenameW.Buffer, nSize) * sizeof(WCHAR);
567  FilenameW.MaximumLength = FilenameW.Length + sizeof(WCHAR);
568 
569  if (FilenameW.Length)
570  {
571  /* Convert to ansi string */
572  Status = BasepUnicodeStringTo8BitString(&FilenameA, &FilenameW, TRUE);
573  if (!NT_SUCCESS(Status))
574  {
575  /* Set last error, free string and return failure */
577  RtlFreeUnicodeString(&FilenameW);
578  return 0;
579  }
580 
581  /* Calculate size to copy */
582  Length = min(nSize, FilenameA.Length);
583 
584  /* Include terminating zero */
585  if (nSize > Length)
586  LengthToCopy = Length + 1;
587  else
588  LengthToCopy = nSize;
589 
590  /* Now copy back to the caller amount he asked */
591  RtlMoveMemory(lpFilename, FilenameA.Buffer, LengthToCopy);
592 
593  /* Free ansi filename */
594  RtlFreeAnsiString(&FilenameA);
595  }
596 
597  /* Free unicode filename */
598  RtlFreeHeap(RtlGetProcessHeap(), 0, FilenameW.Buffer);
599 
600  /* Return length copied */
601  return Length;
602 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:609
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
PRTL_CONVERT_STRINGA BasepUnicodeStringTo8BitString
Definition: utils.c:27
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define min(a, b)
Definition: monoChain.cc:55
HMODULE hModule
Definition: animate.c:44

Referenced by __getmainargs(), _assert(), _module_name_from_addr(), AssertFail(), create_proc(), doChild(), FreeLibrary(), get_app_key(), GetWindowModuleFileNameA(), init_test(), InstallService(), MLLoadLibraryA(), rdp_send_logon_info(), register_current_module_typelib(), register_service(), register_service_exA(), run_child_process(), run_js_script(), setup_dsound_options(), START_TEST(), STRMBASE_DllGetClassObject(), test(), test_32bit_win(), test_ExitCode(), test_extra_block(), test_filenames(), test_GetMappedFileName(), test_GetModuleBaseName(), test_GetModuleFileNameEx(), test_GetSetConsoleInputExeName(), test_GetWindowModuleFileName(), test_IME(), test_info_size(), test_inheritance(), test_internet_features_registry(), test_load_save(), test_LoadLibraryEx_search_flags(), test_loadlibraryshim(), test_LocalizedNames(), test_QueryFullProcessImageNameA(), test_VerQueryValueA(), testGetModuleFileName(), testGetModuleFileName_Wrong(), TestGetModuleFileNameA(), and wined3d_dll_init().

◆ GetModuleFileNameW()

DWORD WINAPI GetModuleFileNameW ( HINSTANCE  hModule,
LPWSTR  lpFilename,
DWORD  nSize 
)

Definition at line 609 of file loader.c.

612 {
614  PLDR_DATA_TABLE_ENTRY Module;
615  ULONG Length = 0;
617  PPEB Peb;
618 
620 
621  /* Upscale nSize from chars to bytes */
622  nSize *= sizeof(WCHAR);
623 
624  _SEH2_TRY
625  {
626  /* We don't use per-thread cur dir now */
627  //PRTL_PERTHREAD_CURDIR PerThreadCurdir = (PRTL_PERTHREAD_CURDIR)teb->NtTib.SubSystemTib;
628 
629  Peb = NtCurrentPeb ();
630 
631  /* Acquire a loader lock */
633 
634  /* Traverse the module list */
637  while (Entry != ModuleListHead)
638  {
639  Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
640 
641  /* Check if this is the requested module */
642  if (Module->DllBase == (PVOID)hModule)
643  {
644  /* Calculate size to copy */
646 
647  /* Copy contents */
648  RtlMoveMemory(lpFilename, Module->FullDllName.Buffer, Length);
649 
650  /* Subtract a terminating zero */
651  if (Length == Module->FullDllName.MaximumLength)
652  Length -= sizeof(WCHAR);
653 
654  /* Break out of the loop */
655  break;
656  }
657 
658  /* Advance to the next entry */
659  Entry = Entry->Flink;
660  }
661  }
663  {
665  Length = 0;
666  } _SEH2_END
667 
668  /* Release the loader lock */
670 
671  return Length / sizeof(WCHAR);
672 }
#define LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS
Definition: ldrtypes.h:76
PPEB Peb
Definition: dllmain.c:27
struct _Entry Entry
Definition: kefuncs.h:640
NTSTATUS NTAPI LdrUnlockLoaderLock(IN ULONG Flags, IN ULONG Cookie OPTIONAL)
Definition: ldrapi.c:101
USHORT MaximumLength
Definition: env_spec_w32.h:370
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2024
NTSTATUS NTAPI LdrLockLoaderLock(IN ULONG Flags, OUT PULONG Disposition OPTIONAL, OUT PULONG_PTR Cookie OPTIONAL)
Definition: ldrapi.c:173
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID DllBase
Definition: btrfs_drv.h:1784
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:13
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: btrfs_drv.h:1780
Definition: typedefs.h:117
_SEH2_END
Definition: create.c:4424
#define NtCurrentPeb()
Definition: FLS.c:20
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1816
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1786
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
base of all file and directory entries
Definition: entries.h:82
PVOID WINAPI BasepMapModuleHandle(HMODULE hModule, BOOLEAN AsDataFile)
Definition: loader.c:67
HMODULE hModule
Definition: animate.c:44

Referenced by __report_error(), __wgetmainargs(), _CorExeMain(), _CreateActCtxFromFile(), _CreateV5ActCtx(), _DoDLLInjection(), _RunRemoteTest(), AMovieDllRegisterServer2(), AtlLoadTypeLib(), ATL::AtlLoadTypeLib(), AtlUpdateRegistryFromResourceD(), CommandLineToArgvW(), ATL::CAtlModule::CommonInitRegistrar(), create_registrar(), CURSORICON_LoadImageW(), BtrfsVolPropSheet::DeviceDlgProc(), DllRegisterServer(), ExtractAssociatedIconW(), FILEDLG95_MRU_load_filename(), FILEDLG95_MRU_save_filename(), get_mmioFromProfile(), CConfiguration::GetConfigurationFromFile(), CRegistryFolderExtractIcon::GetIconLocation(), CNtObjectFolderExtractIcon::GetIconLocation(), CNetConUiObject::GetIconLocation(), GetModuleFileNameA(), BtrfsIconOverlay::GetOverlayInfo(), GetWindowModuleFileNameW(), Host_get_FullName(), Host_get_Path(), if(), init_dbghelp_version(), init_paths(), InitLogs(), InitTestData(), InstallEventSource(), IntSetWindowsHook(), BtrfsContextMenu::InvokeCommand(), load_process_feature(), load_typelib(), SEALED_::LoadTypeLibrary(), LPK_ApplyMirroring(), MLBuildResURLW(), MLLoadLibraryW(), NdrDllRegisterProxy(), BtrfsPropSheet::open_as_admin(), BtrfsBalance::PauseBalance(), ReallyFixupVTable(), register_clsid(), register_service(), register_service_exW(), RegisterComponent(), RegisterInShimCache(), BtrfsVolPropSheet::ResetStats(), ResProtocolInfo_ParseUrl(), RetrieveCurrentModuleNTDirectory(), RunApphelpCacheControlTests(), search_res_tlb(), set_firewall(), SetWinEventHook(), BtrfsVolPropSheet::ShowScrub(), ShowUsage(), START_TEST(), BtrfsBalance::StartBalance(), StartChild(), BtrfsBalance::StopBalance(), CSysTray::SysTrayThreadProc(), taskdialog_get_exe_name(), test_32bit_win(), Test_ApphelpCheckRunApp(), test_commandline2argv(), test_FakeDLL(), test_FileMapping(), Test_GetMatchingExe(), Test_ImageSection(), test_Load(), test_NetFwAuthorizedApplication(), test_QueryFullProcessImageNameW(), test_WTSEnumerateProcessesW(), TestDllStartup(), testGetModuleFileName(), testGetModuleFileName_Wrong(), TestGetModuleFileNameW(), TestPrivMoveFileIdentityW(), TestRedirection(), TestStaticDestruct(), User32CallEventProcFromKernel(), validate_SDBQUERYRESULT_size(), and write_predefined_strings().

◆ GetModuleHandleA()

HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA ( LPCSTR  lpModuleName)

Definition at line 821 of file loader.c.

822 {
823  PUNICODE_STRING ModuleNameW;
824  PTEB pTeb = NtCurrentTeb();
825 
826  /* Check if we have no name to convert */
827  if (!lpModuleName)
829 
830  /* Convert module name to unicode */
831  ModuleNameW = Basep8BitStringToStaticUnicodeString(lpModuleName);
832 
833  /* Call W version if conversion was successful */
834  if (ModuleNameW)
835  return GetModuleHandleW(ModuleNameW->Buffer);
836 
837  /* Return failure */
838  return 0;
839 }
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:188
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
PVOID ImageBaseAddress
Definition: ntddk_ex.h:245
Definition: compat.h:484
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847

Referenced by __mingw_get_msvcrt_handle(), add_128x15_bitmap(), build_toolbar(), check_address(), check_class(), check_dialog_style(), check_z_order_debug(), child_process(), cleanup(), compat_catpath(), create_animate(), create_async_message_window(), create_custom_parent_window(), create_dde_server(), create_dde_window(), create_edit_control(), create_listview_control(), create_main_test_wnd(), create_monthcal_control(), create_pager_control(), create_parent(), create_parent_window(), create_progress(), create_rebar_control(), create_testfontfile(), create_trackbar(), create_trackbar2(), create_treeview_control(), create_updown_control(), createMainWnd(), createParentWindow(), CreateRemoteThread(), CreateTestWindow(), destroy_dde_window(), detect_locale(), DliHook(), dll_entry_point(), DllMain(), DllUnregisterServer(), do_child(), do_parent(), doChild(), drop_window_therad(), dsm_RegisterWindowClasses(), dump_system_info(), EDIT_WM_ContextMenu(), empty_dlg_proc2(), EnumResourceLanguagesA(), EnumResourceNamesA(), EnumResourceTypesA(), ExceptionFilter(), ExtractIconExW(), General_DoTest(), get_host_winver(), get_mono_path(), get_res_data(), GetDriverVersion(), GetEnvStatus(), hook_WaitForInputIdle(), IME_DoTest(), include_pac_utils(), init(), Init(), init_aes_environment(), init_base_environment(), init_func_ptrs(), init_funcs(), init_function_pointers(), init_function_ptrs(), init_functionpointers(), init_functions(), init_pointers(), init_procs(), init_test(), init_tests(), init_threadpool(), InitFunctionPointers(), InitFunctionPtrs(), is_lang_english(), is_module_loaded(), is_process_limited(), load_it_up(), load_resource(), load_v6_module(), LoadResource(), loadShell32(), mdi_RegisterWindowClasses(), MSVCRT_locale_to_LCID(), MyUserYield(), MyWndProc(), NPSAuthenticationDialogA(), path_to_pidl(), print_version(), rebuild_toolbar(), register_child_wnd_class(), register_class(), register_classes(), register_dummy_class(), register_menu_check_class(), register_parent_class(), register_parent_wnd_class(), register_style_check_class(), register_test_notify_class(), register_testwindow_class(), register_window_class(), register_window_classes(), register_wmime_keydown_class(), RegisterClassHelper(), registerParentWindowClass(), RegisterWindowClasses(), running_under_wine(), scrollbar_test_init(), setup_pointers(), sheet_callback(), ShowUsage(), START_TEST(), subclass_button(), subclass_combobox(), subclass_edit(), subclass_static(), test_accelerators(), test_AccessCheck(), test_acmDriverAdd(), test_add_bitmap(), test_add_string(), test_aligned(), test_arrange(), test_attach_input(), test_ax_win(), test_bad_control_class(), test_builtinproc(), test_buttons(), test_capture_4(), test_change_focus(), test_CheckMenuRadioItem(), test_child_window_from_point(), test_clipboard_viewers(), test_comctl32_class(), test_converttoemfplus(), test_cookie_attrs(), test_CoWaitForMultipleHandles(), test_crash_couninitialize(), test_create(), test_create_view_template(), test_CreateActCtx(), test_createeffect(), test_createtoolbarex(), test_CreateUpDownControl(), test_CreateWindow(), test_csparentdc(), test_custom_default_button(), test_customdraw(), test_data_cache(), test_dc_layout(), test_default_handler_run(), test_DeleteDC(), test_dialog_messages(), test_dialog_parent(), test_DialogBoxParam(), test_dialogmode(), test_directory_filename(), test_disableowner(), test_drawimage(), test_EM_SETTEXTEX(), test_EN_LINK(), test_EndDialog(), test_EnumProcessModules(), test_eventMask(), test_events(), test_ExitCode(), test_ExtractIcon(), test_FakeDLL(), test_filenames(), test_fullscreen(), test_GdiConvertToDevmodeW(), test_gdiis(), test_GdipInitializePalette(), test_GetConsoleFontInfo(), test_GetConsoleFontSize(), test_GetConsoleScreenBufferInfoEx(), Test_GetDCEx_Cached(), Test_GetDCEx_CS_CLASSDC(), Test_GetDCEx_CS_Mixed(), Test_GetDCEx_CS_OWNDC(), Test_GetDCEx_CS_SwitchedStyle(), test_GetFileVersionInfoEx(), Test_GetKeyState(), test_GetLargestConsoleWindowSize(), test_GetLastActivePopup(), test_GetListBoxInfo(), test_GetMappedFileName(), test_GetModuleBaseName(), test_GetModuleFileNameEx(), test_GetModuleInformation(), test_GetPhysicallyInstalledSystemMemory(), test_GetProcAddress(), test_GetProcessImageFileName(), test_GetScrollBarInfo(), test_GetSetConsoleInputExeName(), test_getstring(), test_gettext(), test_GetUpdateRect(), test_GetWindowModuleFileName(), test_heap(), test_HeapQueryInformation(), test_hotkey(), test_I_UpdateStore(), test_IgnoreFreeLibrary(), test_IME(), test_ImmGetCompositionString(), test_ImmMessages(), test_import_resolution(), test_ImportDescriptors(), test_Input_blackbox(), test_Input_mouse(), test_Input_whitebox(), test_InSendMessage(), test_instances(), test_invisible_create(), test_iocp_callback(), test_IsWindowUnicode(), test_launch_app_registry(), test_layout(), test_ldap_parse_sort_control(), test_LdrAddRefDll(), test_listbox_dlgdir(), test_Loader(), test_LoadImage(), test_LoadStringA(), test_LoadStringW(), test_longtextA(), test_LVM_GETCOUNTPERPAGE(), test_maximum_allowed(), test_md5_ctx(), test_mdi(), test_MDI_child_stack(), test_MDI_create(), test_mdi_messages(), test_menu_hilitemenuitem(), test_menu_input(), test_menu_messages(), test_message_from_hmodule(), test_messages(), test_mouse_ll_hook(), test_mru(), test_msidecomposedesc(), test_NdrDllGetClassObject(), test_NdrDllRegisterProxy(), test_nopage(), test_noresize(), test_normal_imports(), test_NtAreMappedFilesTheSame(), test_null_filename(), test_obsolete_flags(), test_ok(), test_ole_initialization(), test_ordinal_imports(), test_pager(), test_param_check(), test_pe_checksum(), test_PlaySound(), test_popup_zorder(), test_propertytovariant(), test_proxy_used_in_wrong_thread(), test_PSM_ADDPAGE(), test_PSM_INSERTPAGE(), test_queryvirtualmemory(), test_quit_message(), test_redraw(), test_redrawnow(), test_registrar(), test_resizable2(), test_resize(), test_RpcExceptionFilter(), test_set_clipboard_DRAWCLIPBOARD(), test_set_hook(), test_set_window_style(), test_SetConsoleFont(), Test_SetCursorPos(), test_setinfo(), test_sha_ctx(), test_SHChangeNotify(), test_SHCreateWorkerWindowA(), test_shell_window(), test_SHSetWindowBits(), test_Sign_Media(), test_SIPLoad(), test_sizes(), test_smresult(), test_sscanf_s(), test_stgcreatestorageex(), test_stillimage_aggregation(), test_subitem_rect(), test_swscanf_s(), test_thick_child_size(), test_thread_start_address(), test_timer(), test_title(), test_tooltip(), test_treeview_classinfo(), test_TTM_ADDTOOL(), test_ttm_gettoolinfo(), test_TTN_SHOW(), test_update_region(), test_updown_buddy(), test_updown_create(), test_UuidCreateSequential(), test_varianttoproperty(), test_verifyRevocation(), test_version_flag_versus_aw(), test_WaitForInputIdle(), test_winevents(), test_winproc_handles(), test_wiznavigation(), test_wm_notify(), test_WM_NOTIFY(), test_wndproc(), test_write_watch(), testGetModuleFileName(), testK32GetModuleInformation(), testNestedLoadLibraryA(), wined3d_adapter_init(), WINMM_CheckForMMSystem(), and write_typelib().

◆ GetModuleHandleExA()

BOOL WINAPI GetModuleHandleExA ( IN DWORD  dwFlags,
IN LPCSTR lpModuleName  OPTIONAL,
OUT HMODULE phModule 
)

Definition at line 905 of file loader.c.

908 {
909  PUNICODE_STRING lpModuleNameW;
910  DWORD dwValid;
911  BOOL Ret;
912 
913  /* Validate parameters */
914  dwValid = BasepGetModuleHandleExParameterValidation(dwFlags, (LPCWSTR)lpModuleName, phModule);
915 
916  /* If result is invalid parameter - return failure */
918 
919  /* If result is 2, there is no need to do anything - return success. */
921 
922  /* Check if we don't need to convert the name */
923  if (dwFlags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
924  {
925  /* Call the extended version of the API without conversion */
927  dwFlags,
928  (LPCWSTR)lpModuleName,
929  phModule);
930  }
931  else
932  {
933  /* Convert module name to unicode */
934  lpModuleNameW = Basep8BitStringToStaticUnicodeString(lpModuleName);
935 
936  /* Return FALSE if conversion failed */
937  if (!lpModuleNameW) return FALSE;
938 
939  /* Call the extended version of the API */
941  dwFlags,
942  lpModuleNameW->Buffer,
943  phModule);
944  }
945 
946  /* Return result */
947  return Ret;
948 }
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:188
#define TRUE
Definition: types.h:120
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_ERROR
Definition: kernel32.h:107
BOOLEAN WINAPI BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
Definition: loader.c:725
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
DWORD WINAPI BasepGetModuleHandleExParameterValidation(DWORD dwFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
Definition: loader.c:26
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS
Definition: kernel32.h:108

Referenced by testGetModuleHandleEx().

◆ GetModuleHandleExW()

BOOL WINAPI GetModuleHandleExW ( IN DWORD  dwFlags,
IN LPCWSTR lpwModuleName  OPTIONAL,
OUT HMODULE phModule 
)

Definition at line 875 of file loader.c.

878 {
879  DWORD dwValid;
880  BOOL Ret;
881 
882  /* Validate parameters */
883  dwValid = BasepGetModuleHandleExParameterValidation(dwFlags, lpwModuleName, phModule);
884 
885  /* If result is invalid parameter - return failure */
887 
888  /* If result is 2, there is no need to do anything - return success. */
890 
891  /* Use common helper routine */
893  dwFlags,
894  lpwModuleName,
895  phModule);
896 
897  return Ret;
898 }
#define TRUE
Definition: types.h:120
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_ERROR
Definition: kernel32.h:107
BOOLEAN WINAPI BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
Definition: loader.c:725
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
DWORD WINAPI BasepGetModuleHandleExParameterValidation(DWORD dwFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
Definition: loader.c:26
#define BASEP_GET_MODULE_HANDLE_EX_PARAMETER_VALIDATION_SUCCESS
Definition: kernel32.h:108

Referenced by cache_connection(), ATL::CAtlBaseModule::CAtlBaseModule(), ATL::CAtlComModule::CAtlComModule(), DllMain(), GPNotificationThreadProc(), http_release_netconn(), LookupThreadProc(), testGetModuleHandleEx(), and wined3d_cs_create().

◆ GetModuleHandleForUnicodeString()

HMODULE WINAPI GetModuleHandleForUnicodeString ( PUNICODE_STRING  ModuleName)

Definition at line 676 of file loader.c.

677 {
679  PVOID Module;
680  LPWSTR DllPath;
681 
682  /* Try to get a handle with a magic value of 1 for DllPath */
683  Status = LdrGetDllHandle((LPWSTR)1, NULL, ModuleName, &Module);
684 
685  /* If that succeeded - we're done */
686  if (NT_SUCCESS(Status)) return Module;
687 
688  /* If not, then the path should be computed */
690  if (!DllPath)
691  {
693  }
694  else
695  {
696  _SEH2_TRY
697  {
699  }
701  {
702  /* Fail with the SEH error */
704  }
705  _SEH2_END;
706  }
707 
708  /* Free the DllPath */
709  RtlFreeHeap(RtlGetProcessHeap(), 0, DllPath);
710 
711  /* In case of error set last win32 error and return NULL */
712  if (!NT_SUCCESS(Status))
713  {
714  DPRINT("Failure acquiring DLL module '%wZ' handle, Status 0x%08X\n", ModuleName, Status);
716  Module = 0;
717  }
718 
719  /* Return module */
720  return (HMODULE)Module;
721 }
NTSTATUS NTAPI LdrGetDllHandle(IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle)
Definition: ldrapi.c:805
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1264
_SEH2_TRY
Definition: create.c:4250
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
LPWSTR WINAPI BaseComputeProcessDllPath(IN LPWSTR FullPath, IN PVOID Environment)
Definition: path.c:420
_SEH2_END
Definition: create.c:4424
static const char const char * DllPath
Definition: image.c:34
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by BasepGetModuleHandleExW().

◆ GetModuleHandleW()

HMODULE WINAPI GetModuleHandleW ( LPCWSTR  lpModuleName)

Definition at line 847 of file loader.c.

848 {
851 
852  /* If current module is requested - return it right away */
853  if (!lpModuleName)
854  return ((HMODULE)NtCurrentPeb()->ImageBaseAddress);
855 
856  /* Use common helper routine */
858  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
859  lpModuleName,
860  &hModule);
861 
862  /* If it wasn't successful - return NULL */
863  if (!Success) hModule = NULL;
864 
865  /* Return the handle */
866  return hModule;
867 }
#define TRUE
Definition: types.h:120
BOOLEAN WINAPI BasepGetModuleHandleExW(BOOLEAN NoLock, DWORD dwPublicFlags, LPCWSTR lpwModuleName, HMODULE *phModule)
Definition: loader.c:725
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define NtCurrentPeb()
Definition: FLS.c:20
HMODULE hModule
Definition: animate.c:44

Referenced by _CorExeMain(), CBandSiteMenu::_CreateMenuPart(), CBandSiteMenu::_CreateNewISFBand(), _DoDLLInjection(), CBandSiteBase::_OnContextMenu(), _SHCreateDesktop(), _SHDesktopMessageLoop(), _ShellDDEInit(), CBandSiteMenu::_ShowToolbarError(), AddTextButton(), AllocAndLoadString(), ApplicationPage_OnSwitchTo(), ApplicationPageOnNotify(), ask_confirm(), AtlAxWinInit(), cleanup(), CMenuBand_CreateInstance(), Confirm(), CDeviceManager::Create(), create_clipbrd_window(), create_listview_controlW(), create_parent_window(), create_syslink(), create_test_windows(), device_tests(), dialog_about(), dialog_viewproperties(), DoEntry(), DoLoadStrings(), DrawThemeText(), EnumerateConnectedDrives(), EnumJoysticks(), EnumResourceLanguagesW(), EnumResourceNamesW(), EnumResourceTypesW(), EnumWindowsProc(), execute_test(), exit(), extract_resource(), fetch_shlwapi_ordinal(), FILEDLG95_MRU_load_filename(), FILEDLG95_MRU_save_filename(), FindResourceExA(), FindResourceExW(), General_DoTest(), get_print_file_filter(), BtrfsContextMenu::get_uac_icon(), GetComCtl32Version(), GetLocalsplFuncs(), GetModuleHandleA(), GetOwnerModuleFromTagEntry(), GetProc(), GetResource(), GetSeconds(), GetSpoolssFunc(), GetSystemCPU(), CConfiguration::GetSystemInformation(), ie_dialog_about(), IME_DoTest(), ImmGetContextThreadFunc(), init(), init_dbghelp_version(), init_preview(), InitializeAPI(), InitThreads(), IntInitializeImmEntryTable(), IsWininetLoaded(), IsWinsockLoaded(), joystick_tests(), keyboard_tests(), load_message(), LsapInitSids(), LsarpLookupPrivilegeDisplayName(), MCIWndCreateW(), MessageBoxWithResStringW(), mouse_tests(), msg_spy_init(), newfile_proc(), OLEClipbrd_UnInitialize(), OnCommand(), OnCreate(), output_error(), output_message(), output_value(), paraformat_proc(), preview_exit(), preview_proc(), PrintNetMessage(), CISFBand::QueryContextMenu(), register_iewindow_class(), register_notifyformat_class(), register_parent_wnd_class(), RegisterClassExWOWW(), RegisterWindowClasses(), RichEditOleCallback_GetContextMenu(), run_test(), SampInitializeSAM(), START_TEST(), taskkill_message(), taskkill_message_printfW(), test_actctx_classes(), test_builtinproc(), test_default_ime_disabled_cb(), test_default_ime_window_cancel_cb(), test_default_ime_window_cb(), test_default_ime_with_message_only_window_cb(), test_directory_filename(), test_find_resource(), test_GetInterfaceName(), test_icons(), test_ime_processkey(), test_ImmDefaultHwnd(), test_Input_unicode(), test_LoadImage(), test_longtextW(), test_message_conversion(), test_null_filename(), test_rtti(), Test_SetCursorPos(), test_track(), test_wm_notifyformat(), test_write_watch(), TestManualInstantiation(), TestSoftModalMsgBox(), toggle_num_pages(), TrayIcon_ShellAddTrayIcon(), UnloadAppInitDlls(), update_preview_statusbar(), UpdatePerUserImmEnabling(), User32CallEventProcFromKernel(), User32CallHookProcFromKernel(), User32CreateWindowEx(), UserpFormatMessages(), WhoamiLoadRcString(), WineFile_OnRun(), WinMain(), wWinMain(), and XCOPY_LoadMessage().

◆ GetProcAddress()

FARPROC WINAPI GetProcAddress ( HMODULE  hModule,
LPCSTR  lpProcName 
)

Definition at line 401 of file loader.c.

402 {
403  ANSI_STRING ProcedureName, *ProcNamePtr = NULL;
404  FARPROC fnExp = NULL;
406  PVOID hMapped;
407  ULONG Ordinal = 0;
408 
409  if ((ULONG_PTR)lpProcName > MAXUSHORT)
410  {
411  /* Look up by name */
412  RtlInitAnsiString(&ProcedureName, (LPSTR)lpProcName);
413  ProcNamePtr = &ProcedureName;
414  }
415  else
416  {
417  /* Look up by ordinal */
418  Ordinal = PtrToUlong(lpProcName);
419  }
420 
421  /* Map provided handle */
422  hMapped = BasepMapModuleHandle(hModule, FALSE);
423 
424  /* Get the proc address */
425  Status = LdrGetProcedureAddress(hMapped,
426  ProcNamePtr,
427  Ordinal,
428  (PVOID*)&fnExp);
429 
430  if (!NT_SUCCESS(Status))
431  {
433  return NULL;
434  }
435 
436  /* Check for a special case when returned pointer is
437  the same as image's base address */
438  if (fnExp == hMapped)
439  {
440  /* Set correct error code */
441  if (HIWORD(lpProcName) != 0)
443  else
445 
446  return NULL;
447  }
448 
449  /* All good, return procedure pointer */
450  return fnExp;
451 }
LONG NTSTATUS
Definition: precomp.h:26
char * LPSTR
Definition: xmlstorage.h:182
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:63
NTSTATUS NTAPI LdrGetProcedureAddress(IN PVOID BaseAddress, IN PANSI_STRING Name, IN ULONG Ordinal, OUT PVOID *ProcedureAddress)
Definition: ldrapi.c:823
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define PtrToUlong(u)
Definition: config.h:107
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define STATUS_ORDINAL_NOT_FOUND
Definition: ntstatus.h:534
#define MAXUSHORT
Definition: typedefs.h:81
#define STATUS_ENTRYPOINT_NOT_FOUND
Definition: ntstatus.h:535
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
int(* FARPROC)()
Definition: compat.h:28
PVOID WINAPI BasepMapModuleHandle(HMODULE hModule, BOOLEAN AsDataFile)
Definition: loader.c:67
HMODULE hModule
Definition: animate.c:44

Referenced by START_TEST(), test_FakeDLL(), test_import_resolution(), test_ResolveDelayLoadedAPI(), and wine_dlsym().

◆ LoadLibraryA()

HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA ( LPCSTR  lpLibFileName)

Definition at line 111 of file loader.c.

112 {
113  static const CHAR TwainDllName[] = "twain_32.dll";
114  LPSTR PathBuffer;
115  UINT Len;
117 
118  /* Treat twain_32.dll in a special way (what a surprise...) */
119  if (lpLibFileName && !_strcmpi(lpLibFileName, TwainDllName))
120  {
121  /* Allocate space for the buffer */
122  PathBuffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, MAX_PATH + sizeof(ANSI_NULL));
123  if (PathBuffer)
124  {
125  /* Get windows dir in this buffer */
126  Len = GetWindowsDirectoryA(PathBuffer, MAX_PATH);
127  if ((Len != 0) && (Len < (MAX_PATH - sizeof(TwainDllName) - sizeof('\\'))))
128  {
129  /* We successfully got windows directory. Concatenate twain_32.dll to it */
130  PathBuffer[Len] = '\\';
131  strcpy(&PathBuffer[Len + 1], TwainDllName);
132 
133  /* And recursively call ourselves with a new string */
134  Result = LoadLibraryA(PathBuffer);
135 
136  /* If it was successful - free memory and return result */
137  if (Result)
138  {
139  RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
140  return Result;
141  }
142  }
143 
144  /* Free allocated buffer */
145  RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
146  }
147  }
148 
149  /* Call the Ex version of the API */
150  return LoadLibraryExA(lpLibFileName, 0, 0);
151 }
char CHAR
Definition: xmlstorage.h:175
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
char * LPSTR
Definition: xmlstorage.h:182
#define ANSI_NULL
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
#define MAX_PATH
Definition: compat.h:26
#define Len
Definition: deflate.h:82
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2336
unsigned int UINT
Definition: ndis.h:50
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:159
_Check_return_ _CRTIMP int __cdecl _strcmpi(_In_z_ const char *_Str1, _In_z_ const char *_Str2)

Referenced by __delayLoadHelper2(), _loaddll(), child_process(), create_printer_dc(), CRYPT_CreateKeyProv(), Direct3DCreate9(), DliFailHook(), DliHook(), dll_entry_point(), DP_LoadSP(), EnableDialogTheme(), ExceptionFilter(), Extract(), extract_cabinet_file(), ExtractFilesA(), FGetComponentPath(), get_corversion(), GetFileNamePreview(), GetUIVersion(), init(), Init(), init_function_pointers(), init_function_ptrs(), init_functionpointers(), init_functions(), init_gdip(), init_pointers(), init_test_functions(), init_tests(), InitFuncPtrs(), InitFunctionPtr(), InitFunctionPtrs(), load_functions(), load_v6_module(), LoadCABINETDll(), LoadCOM(), loadIPHlpApi(), ATL::CImage::COMMON::LoadLib(), LoadLibraryList(), LoadShimDLL(), MACRO_RegisterRoutine(), main(), MCICDA_drvOpen(), MLLoadLibraryA(), msi_dialog_scrolltext_control(), parse_url_from_outside(), prepare_test(), profile_items_callback(), propvar_changetype(), rand_s(), RegisterDeviceNotificationW(), SHDOCVW_LoadShell32(), START_TEST(), test_AdvInstallFile(), test_DeviceCapabilities(), test_filenames(), test_GetModuleInformation(), test_IgnoreFreeLibrary(), test_image_mapping(), test_import_resolution(), test_Input_unicode(), test_LdrAddRefDll(), test_Loader(), test_LoadIconWithScaleDown(), test_onefile(), test_res_protocol(), test_ResolveDelayLoadedAPI(), test_section_access(), test_SetDefaultDllDirectories(), test_shell_imagelist(), test_typelib(), test_WICCreateBitmapFromSectionEx(), testGetModuleHandleEx(), testLoadLibraryA(), testLoadLibraryA_Wrong(), testNestedLoadLibraryA(), ThirdPartyVDDBop(), twain_add_onedriver(), TWAIN_OpenDS(), UIINSERTOBJECTDLG_AddControl(), UnregisterDeviceNotification(), use_common(), vmr_create(), WhichPlatform(), wine_dlopen(), WinMain(), WsNpInitialize(), and WspiapiLoad().

◆ LoadLibraryExA()

HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA ( LPCSTR  lpLibFileName,
HANDLE  hFile,
DWORD  dwFlags 
)

Definition at line 159 of file loader.c.

162 {
163  PUNICODE_STRING FileNameW;
164 
165  /* Convert file name to unicode */
166  if (!(FileNameW = Basep8BitStringToStaticUnicodeString(lpLibFileName)))
167  return NULL;
168 
169  /* And call W version of the API */
170  return LoadLibraryExW(FileNameW->Buffer, hFile, dwFlags);
171 }
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:188
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
smooth NULL
Definition: ftsmooth.c:416
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ HANDLE hFile
Definition: mswsock.h:90

Referenced by extract_test_proc(), LoadLibraryA(), LoadModuleWithSymbolsFullPath(), map_image_section(), SHPinDllOfCLSID(), START_TEST(), test_import_resolution(), test_Loader(), test_LoadLibraryEx_search_flags(), test_pe_checksum(), test_SetDefaultDllDirectories(), and testLoadLibraryEx().

◆ LoadLibraryExW()

HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW ( LPCWSTR  lpLibFileName,
HANDLE  hFile,
DWORD  dwFlags 
)

Definition at line 288 of file loader.c.

291 {
292  UNICODE_STRING DllName;
296  ULONG DllCharacteristics = 0;
297  BOOL FreeString = FALSE;
298 
299  /* Check for any flags LdrLoadDll might be interested in */
301  {
302  /* Tell LDR to treat it as an EXE */
303  DllCharacteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
304  }
305 
306  /* Build up a unicode dll name from null-terminated string */
307  RtlInitUnicodeString(&DllName, (LPWSTR)lpLibFileName);
308 
309  /* Lazy-initialize BasepExeLdrEntry */
310  if (!BasepExeLdrEntry)
312 
313  /* Check if that module is our exe*/
316  {
317  /* Lengths match and it's not a datafile, so perform name comparison */
319  {
320  /* That's us! */
321  return BasepExeLdrEntry->DllBase;
322  }
323  }
324 
325  /* Check for trailing spaces and remove them if necessary */
326  if (DllName.Buffer[DllName.Length/sizeof(WCHAR) - 1] == L' ')
327  {
328  RtlCreateUnicodeString(&DllName, (LPWSTR)lpLibFileName);
329  while (DllName.Length > sizeof(WCHAR) &&
330  DllName.Buffer[DllName.Length/sizeof(WCHAR) - 1] == L' ')
331  {
332  DllName.Length -= sizeof(WCHAR);
333  }
334  DllName.Buffer[DllName.Length/sizeof(WCHAR)] = UNICODE_NULL;
335  FreeString = TRUE;
336  }
337 
338  /* Compute the load path */
340  DllName.Buffer : NULL,
341  NULL);
342  if (!SearchPath)
343  {
344  /* Getting DLL path failed, so set last error, free mem and return */
346  if (FreeString) RtlFreeUnicodeString(&DllName);
347  return NULL;
348  }
349 
350  _SEH2_TRY
351  {
353  {
354  /* If the image is loaded as a datafile, try to get its handle */
355  Status = LdrGetDllHandleEx(0, SearchPath, NULL, &DllName, (PVOID*)&hInst);
356  if (!NT_SUCCESS(Status))
357  {
358  /* It's not loaded yet - so load it up */
360  }
361  _SEH2_YIELD(goto done;)
362  }
363 
364  /* Call the API Properly */
366  &DllCharacteristics,
367  &DllName,
368  (PVOID*)&hInst);
369  }
371  {
373  } _SEH2_END;
374 
375 
376 done:
377  /* Free SearchPath buffer */
378  RtlFreeHeap(RtlGetProcessHeap(), 0, SearchPath);
379 
380  /* Free DllName string if it was dynamically allocated */
381  if (FreeString) RtlFreeUnicodeString(&DllName);
382 
383  /* Set last error in failure case */
384  if (!NT_SUCCESS(Status))
385  {
386  DPRINT1("LoadLibraryExW(%ls) failing with status %lx\n", lpLibFileName, Status);
388  return NULL;
389  }
390 
391  /* Return loaded module handle */
392  return hInst;
393 }
NTSTATUS NTAPI LdrGetDllHandleEx(IN ULONG Flags, IN PWSTR DllPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *DllHandle OPTIONAL)
Definition: ldrapi.c:522
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define LOAD_WITH_ALTERED_SEARCH_PATH
Definition: winbase.h:339
#define SearchPath
Definition: winbase.h:3717
_SEH2_TRY
Definition: create.c:4250
PVOID DllBase
Definition: btrfs_drv.h:1784
#define UNICODE_NULL
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
PLDR_DATA_TABLE_ENTRY BasepExeLdrEntry
Definition: proc.c:25
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define DONT_RESOLVE_DLL_REFERENCES
Definition: winbase.h:337
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static const WCHAR L[]
Definition: oid.c:1250
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
NTSTATUS NTAPI DECLSPEC_HOTPATCH LdrLoadDll(IN PWSTR SearchPath OPTIONAL, IN PULONG DllCharacteristics OPTIONAL, IN PUNICODE_STRING DllName, OUT PVOID *BaseAddress)
Definition: ldrapi.c:310
static NTSTATUS BasepLoadLibraryAsDatafile(PWSTR Path, LPCWSTR Name, HMODULE *hModule)
Definition: loader.c:188
NTSTATUS NTAPI LdrEnumerateLoadedModules(IN BOOLEAN ReservedFlag, IN PLDR_ENUM_CALLBACK EnumProc, IN PVOID Context)
Definition: ldrapi.c:1120
VOID NTAPI BasepLocateExeLdrEntry(IN PLDR_DATA_TABLE_ENTRY Entry, IN PVOID Context, OUT BOOLEAN *StopEnumeration)
Definition: utils.c:156
Status
Definition: gdiplustypes.h:24
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:338
LPWSTR WINAPI BaseComputeProcessDllPath(IN LPWSTR FullPath, IN PVOID Environment)
Definition: path.c:420
_SEH2_END
Definition: create.c:4424
HINSTANCE hInst
Definition: dxdiag.c:13
#define NtCurrentPeb()
Definition: FLS.c:20
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1786
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)

Referenced by add_zone_to_listview(), CoLoadLibrary(), COMPOBJ_DllList_Add(), CClassNode::ConvertResourceDescriptorToString(), CURSORICON_CopyImage(), DIALOG_SYMBOL_DlgProc(), do_register_dll(), DoExtractIcon(), DoLoadIcons(), EngLoadModule(), get_shdoclc(), GetFileVersionInfoExW(), GetFileVersionInfoSizeExW(), GetMessageStringFromDll(), GetServiceDllFunction(), ITERATE_RegisterTypeLibraries(), load_xul(), LoadLibraryExA(), LoadLibraryW(), LoadProc(), MSSTYLES_OpenThemeFile(), register_ocxs_callback(), RegisterOCX(), RegLoadMUIStringW(), ATL::CRegObject::resource_register(), resource_register(), ResProtocol_Start(), ResProtocolInfo_ParseUrl(), RunDlgProc(), SHCoCreateInstance(), TestDllRedirection(), TLB_PEFile_Open(), User32CallEventProcFromKernel(), and User32CallHookProcFromKernel().

◆ LoadLibraryW()

HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryW ( LPCWSTR  lpLibFileName)

Definition at line 179 of file loader.c.

180 {
181  /* Call Ex version of the API */
182  return LoadLibraryExW(lpLibFileName, 0, 0);
183 }
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288

◆ LoadModule()

DWORD WINAPI LoadModule ( LPCSTR  lpModuleName,
LPVOID  lpParameterBlock 
)

Definition at line 956 of file loader.c.

958 {
959  STARTUPINFOA StartupInfo;
960  PROCESS_INFORMATION ProcessInformation;
961  LOADPARMS32 *LoadParams;
962  char FileName[MAX_PATH];
963  LPSTR CommandLine;
964  DWORD Length, Error;
965  BOOL ProcessStatus;
966  ANSI_STRING AnsiStr;
967  UNICODE_STRING UnicStr;
969  HANDLE Handle;
970 
971  LoadParams = (LOADPARMS32*)lpParameterBlock;
972 
973  /* Check load parameters */
974  if (LoadParams->dwReserved || LoadParams->wMagicValue != 2)
975  {
976  /* Fail with invalid param error */
978  return 0;
979  }
980 
981  /* Search path */
982  Length = SearchPathA(NULL, lpModuleName, ".exe", MAX_PATH, FileName, NULL);
983 
984  /* Check if path was found */
985  if (Length && Length < MAX_PATH)
986  {
987  /* Build StartupInfo */
988  RtlZeroMemory(&StartupInfo, sizeof(StartupInfo));
989 
990  StartupInfo.cb = sizeof(STARTUPINFOA);
991  StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
992  StartupInfo.wShowWindow = LoadParams->wCmdShow;
993 
994  /* Allocate command line buffer */
995  CommandLine = RtlAllocateHeap(RtlGetProcessHeap(),
997  (ULONG)LoadParams->lpCmdLine[0] + Length + 2);
998 
999  /* Put module name there, then a space, and then copy provided command line,
1000  and null-terminate it */
1001  RtlCopyMemory(CommandLine, FileName, Length);
1002  CommandLine[Length] = ' ';
1003  RtlCopyMemory(&CommandLine[Length + 1], &LoadParams->lpCmdLine[1], (ULONG)LoadParams->lpCmdLine[0]);
1004  CommandLine[Length + 1 + (ULONG)LoadParams->lpCmdLine[0]] = 0;
1005 
1006  /* Create the process */
1007  ProcessStatus = CreateProcessA(FileName,
1008  CommandLine,
1009  NULL,
1010  NULL,
1011  FALSE,
1012  0,
1013  LoadParams->lpEnvAddress,
1014  NULL,
1015  &StartupInfo,
1016  &ProcessInformation);
1017 
1018  /* Free the command line buffer */
1019  RtlFreeHeap(RtlGetProcessHeap(), 0, CommandLine);
1020 
1021  if (!ProcessStatus)
1022  {
1023  /* Creating process failed, return right error code */
1024  Error = GetLastError();
1025  switch(Error)
1026  {
1027  case ERROR_BAD_EXE_FORMAT:
1028  return ERROR_BAD_FORMAT;
1029 
1030  case ERROR_FILE_NOT_FOUND:
1031  case ERROR_PATH_NOT_FOUND:
1032  return Error;
1033  }
1034 
1035  /* Return 0 otherwise */
1036  return 0;
1037  }
1038 
1039  /* Wait up to 30 seconds for the process to become idle */
1041  {
1042  UserWaitForInputIdleRoutine(ProcessInformation.hProcess, 30000);
1043  }
1044 
1045  /* Close handles */
1046  NtClose(ProcessInformation.hThread);
1047  NtClose(ProcessInformation.hProcess);
1048 
1049  /* Return magic success value (33) */
1050  return 33;
1051  }
1052 
1053  /* The path was not found, create an ansi string from
1054  the module name and convert it to unicode */
1055  RtlInitAnsiString(&AnsiStr, lpModuleName);
1056  if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(&UnicStr,&AnsiStr,TRUE)))
1057  return ERROR_FILE_NOT_FOUND;
1058 
1059  /* Determine path type */
1061 
1062  /* Free the unicode module name */
1063  RtlFreeUnicodeString(&UnicStr);
1064 
1065  /* If it's a relative path, return file not found */
1067  return ERROR_FILE_NOT_FOUND;
1068 
1069  /* If not, try to open it */
1070  Handle = CreateFile(lpModuleName,
1071  GENERIC_READ,
1073  NULL,
1074  OPEN_EXISTING,
1076  NULL);
1077 
1079  {
1080  /* Opening file succeeded for some reason, close the handle and return file not found anyway */
1082  return ERROR_FILE_NOT_FOUND;
1083  }
1084 
1085  /* Return last error which CreateFile set during an attempt to open it */
1086  return GetLastError();
1087 }
struct _STARTUPINFOA STARTUPINFOA
#define ERROR_BAD_FORMAT
Definition: winerror.h:114
enum _RTL_PATH_TYPE RTL_PATH_TYPE
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define CloseHandle
Definition: compat.h:398
LPSTR lpCmdLine
Definition: kernel32.h:74
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LPSTR lpEnvAddress
Definition: kernel32.h:73
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD dwFlags
Definition: winbase.h:807
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
char * LPSTR
Definition: xmlstorage.h:182
WORD wMagicValue
Definition: kernel32.h:75
#define FILE_SHARE_READ
Definition: compat.h:125
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
static IN ULONG IN PWSTR OUT PCWSTR OUT PBOOLEAN OUT PATH_TYPE_AND_UNKNOWN * PathType
DWORD WINAPI SearchPathA(IN LPCSTR lpPath OPTIONAL, IN LPCSTR lpFileName, IN LPCSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart OPTIONAL)
Definition: path.c:1122
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ERROR_BAD_EXE_FORMAT
Definition: winerror.h:251
smooth NULL
Definition: ftsmooth.c:416
WaitForInputIdleType UserWaitForInputIdleRoutine
Definition: proc.c:20
static const OBJECT_ATTRIBUTES const LARGE_INTEGER ULONG
Definition: loader.c:57
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define OPEN_EXISTING
Definition: compat.h:426
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
_In_ HANDLE Handle
Definition: extypes.h:390
DWORD cb
Definition: winbase.h:796
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4742
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
BOOL Error
Definition: chkdsk.c:66
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
WORD wCmdShow
Definition: kernel32.h:76
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
WORD wShowWindow
Definition: winbase.h:808
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
DWORD dwReserved
Definition: kernel32.h:77
NTSYSAPI RTL_PATH_TYPE NTAPI RtlDetermineDosPathNameType_U(_In_ PCWSTR Path)

◆ UTRegister()

BOOL WINAPI UTRegister ( HMODULE  hModule,
LPSTR  lpsz16BITDLL,
LPSTR  lpszInitName,
LPSTR  lpszProcName,
FARPROC ppfn32Thunk,
FARPROC  pfnUT32CallBack,
LPVOID  lpBuff 
)

Definition at line 1101 of file loader.c.

1105 {
1106  STUB;
1107  return 0;
1108 }
#define STUB
Definition: kernel32.h:27

◆ UTUnRegister()

VOID WINAPI UTUnRegister ( HMODULE  hModule)

Definition at line 1113 of file loader.c.

1114 {
1115  STUB;
1116 }
#define STUB
Definition: kernel32.h:27