[NTDLL/LDR]

- Fix CMake build
- Don't override failure status in LdrGetDllHandleEx
- Minor improvements
Fixes loading of mshtml.tlb in 2nd stage. Patch by Thomas Faber

svn path=/trunk/; revision=52591
This commit is contained in:
Rafal Harabien 2011-07-09 21:48:59 +00:00
parent 03c817cabf
commit 2bd7185260
2 changed files with 31 additions and 49 deletions

View file

@ -20,8 +20,6 @@ list(APPEND SOURCE
ldr/ldrinit.c ldr/ldrinit.c
ldr/ldrpe.c ldr/ldrpe.c
ldr/ldrutils.c ldr/ldrutils.c
ldr/startup.c
ldr/utils.c
rtl/libsupp.c rtl/libsupp.c
rtl/version.c rtl/version.c
def/ntdll.rc def/ntdll.rc

View file

@ -148,7 +148,7 @@ LdrLockLoaderLock(IN ULONG Flags,
/* A normal failure */ /* A normal failure */
return STATUS_INVALID_PARAMETER_3; return STATUS_INVALID_PARAMETER_3;
} }
/* Do or Do Not. There is no Try */ /* Do or Do Not. There is no Try */
ASSERT((Disposition != NULL) || !(Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY)); ASSERT((Disposition != NULL) || !(Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY));
@ -388,7 +388,7 @@ LdrFindEntryForAddress(PVOID Address,
/* Nothing to do */ /* Nothing to do */
if (!Ldr) return STATUS_NO_MORE_ENTRIES; if (!Ldr) return STATUS_NO_MORE_ENTRIES;
/* Get the current entry */ /* Get the current entry */
LdrEntry = Ldr->EntryInProgress; LdrEntry = Ldr->EntryInProgress;
if (LdrEntry) if (LdrEntry)
@ -471,7 +471,7 @@ LdrGetDllHandleEx(IN ULONG Flags,
RtlInitEmptyUnicodeString(&RawDllName, NULL, 0); RtlInitEmptyUnicodeString(&RawDllName, NULL, 0);
RedirectName = *DllName; RedirectName = *DllName;
pRedirectName = &RedirectName; pRedirectName = &RedirectName;
/* Initialize state */ /* Initialize state */
RedirectedDll = Locked = FALSE; RedirectedDll = Locked = FALSE;
LdrEntry = NULL; LdrEntry = NULL;
@ -495,7 +495,7 @@ LdrGetDllHandleEx(IN ULONG Flags,
/* Acquire the lock */ /* Acquire the lock */
Status = LdrLockLoaderLock(0, NULL, &Cookie); Status = LdrLockLoaderLock(0, NULL, &Cookie);
if (!NT_SUCCESS(Status)) goto Quickie; if (!NT_SUCCESS(Status)) goto Quickie;
/* Remember we own it */ /* Remember we own it */
Locked = TRUE; Locked = TRUE;
} }
@ -522,7 +522,11 @@ LdrGetDllHandleEx(IN ULONG Flags,
/* Unrecoverable SxS failure; */ /* Unrecoverable SxS failure; */
goto Quickie; goto Quickie;
} }
else
{
ASSERT(pRedirectName == &RedirectName);
}
/* Set default failure code */ /* Set default failure code */
Status = STATUS_DLL_NOT_FOUND; Status = STATUS_DLL_NOT_FOUND;
@ -533,28 +537,24 @@ LdrGetDllHandleEx(IN ULONG Flags,
if (RedirectedDll) if (RedirectedDll)
{ {
/* Check the flag */ /* Check the flag */
if (LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED) if (!(LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED))
{
/* Use the right name */
CompareName = &LdrpGetModuleHandleCache->FullDllName;
}
else
{ {
goto DontCompare; goto DontCompare;
} }
/* Use the right name */
CompareName = &LdrpGetModuleHandleCache->FullDllName;
} }
else else
{ {
/* Check the flag */ /* Check the flag */
if (!(LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED)) if (LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED)
{
/* Use the right name */
CompareName = &LdrpGetModuleHandleCache->BaseDllName;
}
else
{ {
goto DontCompare; goto DontCompare;
} }
/* Use the right name */
CompareName = &LdrpGetModuleHandleCache->BaseDllName;
} }
/* Check if the name matches */ /* Check if the name matches */
@ -604,7 +604,6 @@ DontCompare:
/* Setup the string */ /* Setup the string */
RawDllName.MaximumLength = Length; RawDllName.MaximumLength = Length;
ASSERT(Length >= sizeof(UNICODE_NULL)); ASSERT(Length >= sizeof(UNICODE_NULL));
RawDllName.Length = RawDllName.MaximumLength - sizeof(UNICODE_NULL);
RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0, 0,
RawDllName.MaximumLength); RawDllName.MaximumLength);
@ -614,18 +613,9 @@ DontCompare:
goto Quickie; goto Quickie;
} }
/* Copy the buffer */ /* Copy the string and add extension */
RtlMoveMemory(RawDllName.Buffer, RtlCopyUnicodeString(&RawDllName, pRedirectName);
pRedirectName->Buffer, RtlAppendUnicodeStringToString(&RawDllName, &LdrApiDefaultExtension);
pRedirectName->Length);
/* Add extension */
RtlMoveMemory((PVOID)((ULONG_PTR)RawDllName.Buffer + pRedirectName->Length),
LdrApiDefaultExtension.Buffer,
LdrApiDefaultExtension.Length);
/* Null terminate */
RawDllName.Buffer[RawDllName.Length / sizeof(WCHAR)] = UNICODE_NULL;
} }
else else
{ {
@ -643,7 +633,6 @@ DontCompare:
/* Setup the string */ /* Setup the string */
RawDllName.MaximumLength = pRedirectName->Length + sizeof(WCHAR); RawDllName.MaximumLength = pRedirectName->Length + sizeof(WCHAR);
RawDllName.Length = pRedirectName->Length;
RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0, 0,
RawDllName.MaximumLength); RawDllName.MaximumLength);
@ -653,19 +642,14 @@ DontCompare:
goto Quickie; goto Quickie;
} }
/* Copy the buffer */ /* Copy the string */
RtlMoveMemory(RawDllName.Buffer, RtlCopyUnicodeString(&RawDllName, pRedirectName);
pRedirectName->Buffer,
pRedirectName->Length);
/* Null terminate */
RawDllName.Buffer[RawDllName.Length / sizeof(WCHAR)] = UNICODE_NULL;
} }
/* Display debug string */ /* Display debug string */
if (ShowSnaps) if (ShowSnaps)
{ {
DPRINT1("LDR: LdrGetDllHandle, searching for %wZ from %ws\n", DPRINT1("LDR: LdrGetDllHandleEx, searching for %wZ from %ws\n",
&RawDllName, &RawDllName,
DllPath ? ((ULONG_PTR)DllPath == 1 ? L"" : DllPath) : L""); DllPath ? ((ULONG_PTR)DllPath == 1 ? L"" : DllPath) : L"");
} }
@ -730,15 +714,15 @@ Quickie:
if (RawDllName.Buffer) if (RawDllName.Buffer)
{ {
/* Free the heap-allocated buffer */ /* Free the heap-allocated buffer */
Status = RtlFreeHeap(RtlGetProcessHeap(), 0, RawDllName.Buffer); RtlFreeHeap(RtlGetProcessHeap(), 0, RawDllName.Buffer);
RawDllName.Buffer = NULL; RawDllName.Buffer = NULL;
} }
/* Release lock */ /* Release lock */
if (Locked) if (Locked)
{ {
Status = LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS,
Cookie); Cookie);
} }
/* Return */ /* Return */
@ -756,7 +740,7 @@ LdrGetDllHandle(IN PWSTR DllPath OPTIONAL,
OUT PVOID *DllHandle) OUT PVOID *DllHandle)
{ {
/* Call the newer API */ /* Call the newer API */
return LdrGetDllHandleEx(TRUE, return LdrGetDllHandleEx(LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT,
DllPath, DllPath,
DllCharacteristics, DllCharacteristics,
DllName, DllName,
@ -1134,10 +1118,10 @@ LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
BOOLEAN LockHeld; BOOLEAN LockHeld;
ULONG_PTR Cookie; ULONG_PTR Cookie;
DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %p)\n", BaseAddress); DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %p)\n", BaseAddress);
/* Don't do it during shutdown */ /* Don't do it during shutdown */
if (LdrpShutdownInProgress) return STATUS_SUCCESS; if (LdrpShutdownInProgress) return STATUS_SUCCESS;
/* Check if we should grab the lock */ /* Check if we should grab the lock */
LockHeld = FALSE; LockHeld = FALSE;
if (!LdrpInLdrInit) if (!LdrpInLdrInit)
@ -1147,7 +1131,7 @@ LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
if (!NT_SUCCESS(Status)) return Status; if (!NT_SUCCESS(Status)) return Status;
LockHeld = TRUE; LockHeld = TRUE;
} }
/* Make sure the DLL is valid and get its entry */ /* Make sure the DLL is valid and get its entry */
Status = STATUS_DLL_NOT_FOUND; Status = STATUS_DLL_NOT_FOUND;
if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry)) if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry))
@ -1167,7 +1151,7 @@ LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
/* Release it */ /* Release it */
LdrUnlockLoaderLock(LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie); LdrUnlockLoaderLock(LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie);
} }
/* Return the status */ /* Return the status */
return Status; return Status;
} }