Author: peterw
Date: Thu Oct 11 03:14:20 2007
New Revision: 29486
URL:
http://svn.reactos.org/svn/reactos?rev=29486&view=rev
Log:
- Two small Ldr cleanup patches (ntdll and kernel32) by: Mike Nordell
Modified:
trunk/reactos/dll/ntdll/ldr/utils.c
trunk/reactos/dll/win32/kernel32/misc/ldr.c
Modified: trunk/reactos/dll/ntdll/ldr/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/utils.c?rev=…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/utils.c (original)
+++ trunk/reactos/dll/ntdll/ldr/utils.c Thu Oct 11 03:14:20 2007
@@ -731,38 +731,30 @@
LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
IN PULONG LoadFlags OPTIONAL,
IN PUNICODE_STRING Name,
- OUT PVOID *BaseAddress OPTIONAL)
+ OUT PVOID *BaseAddress /* also known as HMODULE*, and PHANDLE
'DllHandle' */)
{
NTSTATUS Status;
- PLDR_DATA_TABLE_ENTRY Module;
+ PLDR_DATA_TABLE_ENTRY Module;
+
+ PPEB Peb = NtCurrentPeb();
TRACE_LDR("LdrLoadDll, loading %wZ%s%S\n",
Name,
SearchPath ? L" from " : L"",
SearchPath ? SearchPath : L"");
- if (Name == NULL)
- {
- if (BaseAddress)
- *BaseAddress = NtCurrentPeb()->ImageBaseAddress;
- return STATUS_SUCCESS;
- }
-
- if (BaseAddress)
- *BaseAddress = NULL;
-
Status = LdrpLoadModule(SearchPath, LoadFlags ? *LoadFlags : 0, Name, &Module,
BaseAddress);
- if (NT_SUCCESS(Status)
- && (!LoadFlags || 0 == (*LoadFlags & LOAD_LIBRARY_AS_DATAFILE)))
- {
- RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
+
+ if (NT_SUCCESS(Status) &&
+ (!LoadFlags || 0 == (*LoadFlags & LOAD_LIBRARY_AS_DATAFILE)))
+ {
+ RtlEnterCriticalSection(Peb->LoaderLock);
Status = LdrpAttachProcess();
- RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
- if (NT_SUCCESS(Status) && BaseAddress)
- {
- *BaseAddress = Module->DllBase;
- }
- }
+ RtlLeaveCriticalSection(Peb->LoaderLock);
+ }
+
+ *BaseAddress = NT_SUCCESS(Status) ? Module->DllBase : NULL;
+
return Status;
}
@@ -1324,7 +1316,7 @@
}
static NTSTATUS
-LdrpGetOrLoadModule(PWCHAR SerachPath,
+LdrpGetOrLoadModule(PWCHAR SearchPath,
PCHAR Name,
PLDR_DATA_TABLE_ENTRY* Module,
BOOLEAN Load)
@@ -1345,7 +1337,7 @@
Status = LdrFindEntryForName (&DllName, Module, Load);
if (Load && !NT_SUCCESS(Status))
{
- Status = LdrpLoadModule(SerachPath,
+ Status = LdrpLoadModule(SearchPath,
NtCurrentPeb()->Ldr->Initialized ? 0 :
LDRP_PROCESS_CREATION_TIME,
&DllName,
Module,
Modified: trunk/reactos/dll/win32/kernel32/misc/ldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/ld…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/ldr.c (original)
+++ trunk/reactos/dll/win32/kernel32/misc/ldr.c Thu Oct 11 03:14:20 2007
@@ -34,10 +34,10 @@
LPWSTR STDCALL
GetDllLoadPath(LPCWSTR lpModule)
{
- ULONG Pos = 0, Length = 0;
- PWCHAR EnvironmentBufferW = NULL;
- LPCWSTR lpModuleEnd = NULL;
- UNICODE_STRING ModuleName;
+ ULONG Pos = 0, Length = 0;
+ PWCHAR EnvironmentBufferW = NULL;
+ LPCWSTR lpModuleEnd = NULL;
+ UNICODE_STRING ModuleName;
if (lpModule != NULL)
{
@@ -45,16 +45,18 @@
}
else
{
- ModuleName =
NtCurrentTeb()->ProcessEnvironmentBlock->ProcessParameters->ImagePathName;
- lpModule = ModuleName.Buffer;
- lpModuleEnd = lpModule + (ModuleName.Length / sizeof(WCHAR));
+ ModuleName = NtCurrentPeb()->ProcessParameters->ImagePathName;
+ lpModule = ModuleName.Buffer;
+ lpModuleEnd = lpModule + (ModuleName.Length / sizeof(WCHAR));
}
if (lpModule != NULL)
{
- while (lpModuleEnd > lpModule && *lpModuleEnd != L'/'
&&
- *lpModuleEnd != L'\\' && *lpModuleEnd != L':')
+ while (lpModuleEnd > lpModule && *lpModuleEnd != L'/' &&
+ *lpModuleEnd != L'\\' && *lpModuleEnd != L':')
+ {
--lpModuleEnd;
+ }
Length = (lpModuleEnd - lpModule) + 1;
}
@@ -64,9 +66,11 @@
Length += GetEnvironmentVariableW(L"PATH", NULL, 0);
EnvironmentBufferW = RtlAllocateHeap(RtlGetProcessHeap(), 0,
- Length * sizeof(WCHAR));
+ Length * sizeof(WCHAR));
if (EnvironmentBufferW == NULL)
+ {
return NULL;
+ }
if (lpModule)
{
@@ -75,6 +79,7 @@
Pos += lpModuleEnd - lpModule;
EnvironmentBufferW[Pos++] = L';';
}
+
Pos += GetCurrentDirectoryW(Length, EnvironmentBufferW + Pos);
EnvironmentBufferW[Pos++] = L';';
Pos += GetSystemDirectoryW(EnvironmentBufferW + Pos, Length - Pos);
@@ -412,40 +417,28 @@
STDCALL
GetModuleHandleA ( LPCSTR lpModuleName )
{
- UNICODE_STRING UnicodeName;
ANSI_STRING ModuleName;
- PVOID BaseAddress;
NTSTATUS Status;
+ PTEB pTeb = NtCurrentTeb();
if (lpModuleName == NULL)
- return ((HMODULE)NtCurrentPeb()->ImageBaseAddress);
- RtlInitAnsiString (&ModuleName,
- (LPSTR)lpModuleName);
-
- /* convert ansi (or oem) string to unicode */
- if (bIsFileApiAnsi)
- RtlAnsiStringToUnicodeString (&UnicodeName,
- &ModuleName,
- TRUE);
- else
- RtlOemStringToUnicodeString (&UnicodeName,
- &ModuleName,
- TRUE);
-
- Status = LdrGetDllHandle (0,
- 0,
- &UnicodeName,
- &BaseAddress);
-
- RtlFreeUnicodeString (&UnicodeName);
-
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return NULL;
- }
-
- return ((HMODULE)BaseAddress);
+ {
+ return ((HMODULE)pTeb->ProcessEnvironmentBlock->ImageBaseAddress);
+ }
+
+ RtlInitAnsiString(&ModuleName, lpModuleName);
+
+ Status = RtlAnsiStringToUnicodeString(&pTeb->StaticUnicodeString,
+ &ModuleName,
+ FALSE);
+
+ if (NT_SUCCESS(Status))
+ {
+ return GetModuleHandleW(pTeb->StaticUnicodeString.Buffer);
+ }
+
+ SetLastErrorByStatus(Status);
+ return FALSE;
}
@@ -556,30 +549,24 @@
IN LPCSTR lpModuleName OPTIONAL,
OUT HMODULE* phModule)
{
- UNICODE_STRING UnicodeName;
ANSI_STRING ModuleName;
LPCWSTR lpModuleNameW;
NTSTATUS Status;
BOOL Ret;
+ PTEB pTeb = NtCurrentTeb();
+
if (dwFlags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)
{
lpModuleNameW = (LPCWSTR)lpModuleName;
}
else
{
- RtlInitAnsiString(&ModuleName,
- (LPSTR)lpModuleName);
-
- /* convert ansi (or oem) string to unicode */
- if (bIsFileApiAnsi)
- Status = RtlAnsiStringToUnicodeString(&UnicodeName,
- &ModuleName,
- TRUE);
- else
- Status = RtlOemStringToUnicodeString(&UnicodeName,
- &ModuleName,
- TRUE);
+ RtlInitAnsiString(&ModuleName, lpModuleName);
+
+ Status = RtlAnsiStringToUnicodeString(&pTeb->StaticUnicodeString,
+ &ModuleName,
+ FALSE);
if (!NT_SUCCESS(Status))
{
@@ -587,17 +574,12 @@
return FALSE;
}
- lpModuleNameW = UnicodeName.Buffer;
+ lpModuleNameW = pTeb->StaticUnicodeString.Buffer;
}
Ret = GetModuleHandleExW(dwFlags,
lpModuleNameW,
phModule);
-
- if (!(dwFlags & GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS))
- {
- RtlFreeUnicodeString(&UnicodeName);
- }
return Ret;
}