/* A normal failure */
return STATUS_INVALID_PARAMETER_3;
}
-
+
/* Do or Do Not. There is no Try */
ASSERT((Disposition != NULL) || !(Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY));
/* Nothing to do */
if (!Ldr) return STATUS_NO_MORE_ENTRIES;
-
+
/* Get the current entry */
LdrEntry = Ldr->EntryInProgress;
if (LdrEntry)
RtlInitEmptyUnicodeString(&RawDllName, NULL, 0);
RedirectName = *DllName;
pRedirectName = &RedirectName;
-
+
/* Initialize state */
RedirectedDll = Locked = FALSE;
LdrEntry = NULL;
/* Acquire the lock */
Status = LdrLockLoaderLock(0, NULL, &Cookie);
if (!NT_SUCCESS(Status)) goto Quickie;
-
+
/* Remember we own it */
Locked = TRUE;
}
/* Unrecoverable SxS failure; */
goto Quickie;
}
-
+ else
+ {
+ ASSERT(pRedirectName == &RedirectName);
+ }
+
/* Set default failure code */
Status = STATUS_DLL_NOT_FOUND;
if (RedirectedDll)
{
/* Check the flag */
- if (LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED)
- {
- /* Use the right name */
- CompareName = &LdrpGetModuleHandleCache->FullDllName;
- }
- else
+ if (!(LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED))
{
goto DontCompare;
}
+
+ /* Use the right name */
+ CompareName = &LdrpGetModuleHandleCache->FullDllName;
}
else
{
/* Check the flag */
- if (!(LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED))
- {
- /* Use the right name */
- CompareName = &LdrpGetModuleHandleCache->BaseDllName;
- }
- else
+ if (LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED)
{
goto DontCompare;
}
+
+ /* Use the right name */
+ CompareName = &LdrpGetModuleHandleCache->BaseDllName;
}
/* Check if the name matches */
/* Setup the string */
RawDllName.MaximumLength = Length;
ASSERT(Length >= sizeof(UNICODE_NULL));
- RawDllName.Length = RawDllName.MaximumLength - sizeof(UNICODE_NULL);
RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
RawDllName.MaximumLength);
goto Quickie;
}
- /* Copy the buffer */
- RtlMoveMemory(RawDllName.Buffer,
- pRedirectName->Buffer,
- 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;
+ /* Copy the string and add extension */
+ RtlCopyUnicodeString(&RawDllName, pRedirectName);
+ RtlAppendUnicodeStringToString(&RawDllName, &LdrApiDefaultExtension);
}
else
{
/* Setup the string */
RawDllName.MaximumLength = pRedirectName->Length + sizeof(WCHAR);
- RawDllName.Length = pRedirectName->Length;
RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
0,
RawDllName.MaximumLength);
goto Quickie;
}
- /* Copy the buffer */
- RtlMoveMemory(RawDllName.Buffer,
- pRedirectName->Buffer,
- pRedirectName->Length);
-
- /* Null terminate */
- RawDllName.Buffer[RawDllName.Length / sizeof(WCHAR)] = UNICODE_NULL;
+ /* Copy the string */
+ RtlCopyUnicodeString(&RawDllName, pRedirectName);
}
/* Display debug string */
if (ShowSnaps)
{
- DPRINT1("LDR: LdrGetDllHandle, searching for %wZ from %ws\n",
+ DPRINT1("LDR: LdrGetDllHandleEx, searching for %wZ from %ws\n",
&RawDllName,
DllPath ? ((ULONG_PTR)DllPath == 1 ? L"" : DllPath) : L"");
}
if (RawDllName.Buffer)
{
/* Free the heap-allocated buffer */
- Status = RtlFreeHeap(RtlGetProcessHeap(), 0, RawDllName.Buffer);
+ RtlFreeHeap(RtlGetProcessHeap(), 0, RawDllName.Buffer);
RawDllName.Buffer = NULL;
}
/* Release lock */
if (Locked)
{
- Status = LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS,
- Cookie);
+ LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS,
+ Cookie);
}
/* Return */
OUT PVOID *DllHandle)
{
/* Call the newer API */
- return LdrGetDllHandleEx(TRUE,
+ return LdrGetDllHandleEx(LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT,
DllPath,
DllCharacteristics,
DllName,
BOOLEAN LockHeld;
ULONG_PTR Cookie;
DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %p)\n", BaseAddress);
-
+
/* Don't do it during shutdown */
if (LdrpShutdownInProgress) return STATUS_SUCCESS;
-
+
/* Check if we should grab the lock */
LockHeld = FALSE;
if (!LdrpInLdrInit)
if (!NT_SUCCESS(Status)) return Status;
LockHeld = TRUE;
}
-
+
/* Make sure the DLL is valid and get its entry */
Status = STATUS_DLL_NOT_FOUND;
if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry))
/* Release it */
LdrUnlockLoaderLock(LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie);
}
-
+
/* Return the status */
return Status;
}