2011-03-15 18:56:17 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS NT User Mode Library
|
|
|
|
* FILE: dll/ntdll/ldr/ldrapi.c
|
|
|
|
* PURPOSE: PE Loader Public APIs
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
|
|
|
* Aleksey Bragin (aleksey@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ntdll.h>
|
2014-01-20 12:59:27 +00:00
|
|
|
|
2011-03-15 18:56:17 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2011-07-10 13:23:19 +00:00
|
|
|
LIST_ENTRY LdrpUnloadHead;
|
2016-09-11 20:40:41 +00:00
|
|
|
LONG LdrpLoaderLockAcquisitionCount;
|
2011-07-09 15:32:36 +00:00
|
|
|
BOOLEAN LdrpShowRecursiveLoads, LdrpBreakOnRecursiveDllLoads;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
UNICODE_STRING LdrApiDefaultExtension = RTL_CONSTANT_STRING(L".DLL");
|
2011-11-06 01:34:06 +00:00
|
|
|
ULONG AlternateResourceModuleCount;
|
2015-03-01 15:34:06 +00:00
|
|
|
extern PLDR_MANIFEST_PROBER_ROUTINE LdrpManifestProberRoutine;
|
2011-03-15 18:56:17 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2013-08-30 06:34:16 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrFindCreateProcessManifest(IN ULONG Flags,
|
|
|
|
IN PVOID Image,
|
|
|
|
IN PVOID IdPath,
|
|
|
|
IN ULONG IdPathLength,
|
|
|
|
IN PVOID OutDataEntry)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrDestroyOutOfProcessImage(IN PVOID Image)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrCreateOutOfProcessImage(IN ULONG Flags,
|
|
|
|
IN HANDLE ProcessHandle,
|
|
|
|
IN HANDLE DllHandle,
|
|
|
|
IN PVOID Unknown3)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrAccessOutOfProcessResource(IN PVOID Unknown,
|
|
|
|
IN PVOID Image,
|
|
|
|
IN PVOID Unknown1,
|
|
|
|
IN PVOID Unknown2,
|
|
|
|
IN PVOID Unknown3)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
2015-03-01 15:34:06 +00:00
|
|
|
LdrSetDllManifestProber(
|
|
|
|
_In_ PLDR_MANIFEST_PROBER_ROUTINE Routine)
|
2013-08-30 06:34:16 +00:00
|
|
|
{
|
2015-03-01 15:34:06 +00:00
|
|
|
LdrpManifestProberRoutine = Routine;
|
2013-08-30 06:34:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 01:34:06 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
LdrAlternateResourcesEnabled(VOID)
|
|
|
|
{
|
|
|
|
/* ReactOS does not support this */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-08 21:19:38 +00:00
|
|
|
FORCEINLINE
|
2014-05-04 09:41:01 +00:00
|
|
|
ULONG_PTR
|
2011-07-08 21:19:38 +00:00
|
|
|
LdrpMakeCookie(VOID)
|
|
|
|
{
|
|
|
|
/* Generate a cookie */
|
|
|
|
return (((ULONG_PTR)NtCurrentTeb()->RealClientId.UniqueThread & 0xFFF) << 16) |
|
2016-09-11 20:40:41 +00:00
|
|
|
(_InterlockedIncrement(&LdrpLoaderLockAcquisitionCount) & 0xFFFF);
|
2011-07-08 21:19:38 +00:00
|
|
|
}
|
|
|
|
|
2011-03-15 18:56:17 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrUnlockLoaderLock(IN ULONG Flags,
|
|
|
|
IN ULONG Cookie OPTIONAL)
|
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
DPRINT("LdrUnlockLoaderLock(%x %x)\n", Flags, Cookie);
|
|
|
|
|
|
|
|
/* Check for valid flags */
|
2011-07-08 21:07:31 +00:00
|
|
|
if (Flags & ~LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* Flags are invalid, check how to fail */
|
2011-07-08 21:07:31 +00:00
|
|
|
if (Flags & LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* The caller wants us to raise status */
|
|
|
|
RtlRaiseStatus(STATUS_INVALID_PARAMETER_1);
|
|
|
|
}
|
2011-07-08 21:07:31 +00:00
|
|
|
|
|
|
|
/* A normal failure */
|
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we don't have a cookie, just return */
|
|
|
|
if (!Cookie) return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* Validate the cookie */
|
|
|
|
if ((Cookie & 0xF0000000) ||
|
2018-04-23 09:42:32 +00:00
|
|
|
((Cookie >> 16) ^ (HandleToUlong(NtCurrentTeb()->RealClientId.UniqueThread) & 0xFFF)))
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
DPRINT1("LdrUnlockLoaderLock() called with an invalid cookie!\n");
|
|
|
|
|
|
|
|
/* Invalid cookie, check how to fail */
|
2011-07-08 21:07:31 +00:00
|
|
|
if (Flags & LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* The caller wants us to raise status */
|
|
|
|
RtlRaiseStatus(STATUS_INVALID_PARAMETER_2);
|
|
|
|
}
|
2011-07-08 21:07:31 +00:00
|
|
|
|
|
|
|
/* A normal failure */
|
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ready to release the lock */
|
2011-07-08 21:07:31 +00:00
|
|
|
if (Flags & LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* Do a direct leave */
|
|
|
|
RtlLeaveCriticalSection(&LdrpLoaderLock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Wrap this in SEH, since we're not supposed to raise */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Leave the lock */
|
|
|
|
RtlLeaveCriticalSection(&LdrpLoaderLock);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* We should use the LDR Filter instead */
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* All done */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrLockLoaderLock(IN ULONG Flags,
|
2011-07-08 21:19:38 +00:00
|
|
|
OUT PULONG Disposition OPTIONAL,
|
|
|
|
OUT PULONG_PTR Cookie OPTIONAL)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2011-03-16 14:22:15 +00:00
|
|
|
BOOLEAN InInit = LdrpInLdrInit;
|
2011-03-15 18:56:17 +00:00
|
|
|
|
2011-07-08 21:19:38 +00:00
|
|
|
DPRINT("LdrLockLoaderLock(%x %p %p)\n", Flags, Disposition, Cookie);
|
2011-03-15 18:56:17 +00:00
|
|
|
|
|
|
|
/* Zero out the outputs */
|
2011-07-08 21:19:38 +00:00
|
|
|
if (Disposition) *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_INVALID;
|
2011-03-15 18:56:17 +00:00
|
|
|
if (Cookie) *Cookie = 0;
|
|
|
|
|
|
|
|
/* Validate the flags */
|
2011-04-04 19:35:24 +00:00
|
|
|
if (Flags & ~(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS |
|
2011-03-15 18:56:17 +00:00
|
|
|
LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY))
|
|
|
|
{
|
|
|
|
/* Flags are invalid, check how to fail */
|
2011-04-04 19:35:24 +00:00
|
|
|
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* The caller wants us to raise status */
|
|
|
|
RtlRaiseStatus(STATUS_INVALID_PARAMETER_1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A normal failure */
|
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we got a cookie */
|
|
|
|
if (!Cookie)
|
|
|
|
{
|
|
|
|
/* No cookie check how to fail */
|
2011-04-04 19:35:24 +00:00
|
|
|
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* The caller wants us to raise status */
|
|
|
|
RtlRaiseStatus(STATUS_INVALID_PARAMETER_3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A normal failure */
|
|
|
|
return STATUS_INVALID_PARAMETER_3;
|
|
|
|
}
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-03-15 18:56:17 +00:00
|
|
|
/* If the flag is set, make sure we have a valid pointer to use */
|
2011-07-08 21:19:38 +00:00
|
|
|
if ((Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY) && !(Disposition))
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* No pointer to return the data to */
|
2011-04-04 19:35:24 +00:00
|
|
|
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* The caller wants us to raise status */
|
|
|
|
RtlRaiseStatus(STATUS_INVALID_PARAMETER_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fail */
|
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return now if we are in the init phase */
|
|
|
|
if (InInit) return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* Check what locking semantic to use */
|
2011-04-04 19:35:24 +00:00
|
|
|
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS)
|
2011-03-15 18:56:17 +00:00
|
|
|
{
|
|
|
|
/* Check if we should enter or simply try */
|
|
|
|
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY)
|
|
|
|
{
|
|
|
|
/* Do a try */
|
|
|
|
if (!RtlTryEnterCriticalSection(&LdrpLoaderLock))
|
|
|
|
{
|
|
|
|
/* It's locked */
|
2011-07-08 21:19:38 +00:00
|
|
|
*Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED;
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It worked */
|
2011-07-08 21:19:38 +00:00
|
|
|
*Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
|
|
|
|
*Cookie = LdrpMakeCookie();
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do a enter */
|
|
|
|
RtlEnterCriticalSection(&LdrpLoaderLock);
|
|
|
|
|
|
|
|
/* See if result was requested */
|
2011-07-08 21:19:38 +00:00
|
|
|
if (Disposition) *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
|
|
|
|
*Cookie = LdrpMakeCookie();
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Wrap this in SEH, since we're not supposed to raise */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
/* Check if we should enter or simply try */
|
|
|
|
if (Flags & LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY)
|
|
|
|
{
|
|
|
|
/* Do a try */
|
|
|
|
if (!RtlTryEnterCriticalSection(&LdrpLoaderLock))
|
|
|
|
{
|
|
|
|
/* It's locked */
|
2011-07-08 21:19:38 +00:00
|
|
|
*Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED;
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* It worked */
|
2011-07-08 21:19:38 +00:00
|
|
|
*Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
|
|
|
|
*Cookie = LdrpMakeCookie();
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do an enter */
|
|
|
|
RtlEnterCriticalSection(&LdrpLoaderLock);
|
|
|
|
|
|
|
|
/* See if result was requested */
|
2011-07-08 21:19:38 +00:00
|
|
|
if (Disposition) *Disposition = LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED;
|
|
|
|
*Cookie = LdrpMakeCookie();
|
2011-03-15 18:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* We should use the LDR Filter instead */
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
|
2011-07-08 21:19:38 +00:00
|
|
|
/* Return status */
|
2011-03-15 18:56:17 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2014-03-05 12:06:28 +00:00
|
|
|
DECLSPEC_HOTPATCH
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
LdrLoadDll(IN PWSTR SearchPath OPTIONAL,
|
|
|
|
IN PULONG DllCharacteristics OPTIONAL,
|
|
|
|
IN PUNICODE_STRING DllName,
|
|
|
|
OUT PVOID *BaseAddress)
|
|
|
|
{
|
|
|
|
WCHAR StringBuffer[MAX_PATH];
|
|
|
|
UNICODE_STRING DllString1, DllString2;
|
|
|
|
BOOLEAN RedirectedDll = FALSE;
|
|
|
|
NTSTATUS Status;
|
2017-11-13 14:06:29 +00:00
|
|
|
ULONG_PTR Cookie;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
PUNICODE_STRING OldTldDll;
|
|
|
|
PTEB Teb = NtCurrentTeb();
|
|
|
|
|
|
|
|
/* Initialize the strings */
|
2014-06-23 20:30:54 +00:00
|
|
|
RtlInitEmptyUnicodeString(&DllString1, StringBuffer, sizeof(StringBuffer));
|
2011-07-09 15:32:36 +00:00
|
|
|
RtlInitEmptyUnicodeString(&DllString2, NULL, 0);
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Check if the SxS Assemblies specify another file */
|
|
|
|
Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
|
|
|
|
DllName,
|
|
|
|
&LdrApiDefaultExtension,
|
|
|
|
&DllString1,
|
|
|
|
&DllString2,
|
|
|
|
&DllName,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Check success */
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Let Ldrp know */
|
|
|
|
RedirectedDll = TRUE;
|
|
|
|
}
|
|
|
|
else if (Status != STATUS_SXS_KEY_NOT_FOUND)
|
|
|
|
{
|
|
|
|
/* Unrecoverable SxS failure; did we get a string? */
|
2011-07-09 15:32:36 +00:00
|
|
|
if (DllString2.Buffer) RtlFreeUnicodeString(&DllString2);
|
2011-07-03 21:34:52 +00:00
|
|
|
return Status;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lock the loader lock */
|
|
|
|
LdrLockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, NULL, &Cookie);
|
|
|
|
|
|
|
|
/* Check if there's a TLD DLL being loaded */
|
2011-07-09 15:32:36 +00:00
|
|
|
OldTldDll = LdrpTopLevelDllBeingLoaded;
|
2018-07-29 15:40:42 +00:00
|
|
|
_SEH2_TRY
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
2018-07-29 15:40:42 +00:00
|
|
|
|
|
|
|
if (OldTldDll)
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
2018-07-29 15:40:42 +00:00
|
|
|
/* This is a recursive load, do something about it? */
|
|
|
|
if ((ShowSnaps) || (LdrpShowRecursiveLoads) || (LdrpBreakOnRecursiveDllLoads))
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
2018-07-29 15:40:42 +00:00
|
|
|
/* Print out debug messages */
|
|
|
|
DPRINT1("[%p, %p] LDR: Recursive DLL Load\n",
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
Teb->RealClientId.UniqueProcess,
|
|
|
|
Teb->RealClientId.UniqueThread);
|
2018-07-29 15:40:42 +00:00
|
|
|
DPRINT1("[%p, %p] Previous DLL being loaded \"%wZ\"\n",
|
|
|
|
Teb->RealClientId.UniqueProcess,
|
|
|
|
Teb->RealClientId.UniqueThread,
|
|
|
|
OldTldDll);
|
|
|
|
DPRINT1("[%p, %p] DLL being requested \"%wZ\"\n",
|
|
|
|
Teb->RealClientId.UniqueProcess,
|
|
|
|
Teb->RealClientId.UniqueThread,
|
|
|
|
DllName);
|
|
|
|
|
|
|
|
/* Was it initializing too? */
|
|
|
|
if (!LdrpCurrentDllInitializer)
|
|
|
|
{
|
|
|
|
DPRINT1("[%p, %p] LDR: No DLL Initializer was running\n",
|
|
|
|
Teb->RealClientId.UniqueProcess,
|
|
|
|
Teb->RealClientId.UniqueThread);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPRINT1("[%p, %p] DLL whose initializer was currently running \"%wZ\"\n",
|
|
|
|
Teb->ClientId.UniqueProcess,
|
|
|
|
Teb->ClientId.UniqueThread,
|
|
|
|
&LdrpCurrentDllInitializer->BaseDllName);
|
|
|
|
}
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-29 15:40:42 +00:00
|
|
|
/* Set this one as the TLD DLL being loaded*/
|
|
|
|
LdrpTopLevelDllBeingLoaded = DllName;
|
|
|
|
|
|
|
|
/* Load the DLL */
|
|
|
|
Status = LdrpLoadDll(RedirectedDll,
|
|
|
|
SearchPath,
|
|
|
|
DllCharacteristics,
|
|
|
|
DllName,
|
|
|
|
BaseAddress,
|
|
|
|
TRUE);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((Status != STATUS_NO_SUCH_FILE) &&
|
|
|
|
(Status != STATUS_DLL_NOT_FOUND) &&
|
|
|
|
(Status != STATUS_OBJECT_NAME_NOT_FOUND) &&
|
|
|
|
(Status != STATUS_DLL_INIT_FAILED))
|
|
|
|
{
|
|
|
|
DbgPrintEx(DPFLTR_LDR_ID,
|
|
|
|
DPFLTR_WARNING_LEVEL,
|
|
|
|
"LDR: %s - failing because LdrpLoadDll(%wZ) returned status %x\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
DllName,
|
|
|
|
Status);
|
|
|
|
}
|
2011-07-09 15:32:36 +00:00
|
|
|
}
|
2018-07-29 15:40:42 +00:00
|
|
|
_SEH2_FINALLY
|
2011-07-09 15:32:36 +00:00
|
|
|
{
|
2018-07-29 15:40:42 +00:00
|
|
|
/* Restore the old TLD DLL */
|
|
|
|
LdrpTopLevelDllBeingLoaded = OldTldDll;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
2018-07-29 15:40:42 +00:00
|
|
|
/* Release the lock */
|
|
|
|
LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Do we have a redirect string? */
|
|
|
|
if (DllString2.Buffer) RtlFreeUnicodeString(&DllString2);
|
|
|
|
|
|
|
|
/* Return */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrFindEntryForAddress(PVOID Address,
|
|
|
|
PLDR_DATA_TABLE_ENTRY *Module)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
|
|
|
PIMAGE_NT_HEADERS NtHeader;
|
|
|
|
PPEB_LDR_DATA Ldr = NtCurrentPeb()->Ldr;
|
|
|
|
ULONG_PTR DllBase, DllEnd;
|
|
|
|
|
|
|
|
DPRINT("LdrFindEntryForAddress(Address %p)\n", Address);
|
|
|
|
|
|
|
|
/* Nothing to do */
|
|
|
|
if (!Ldr) return STATUS_NO_MORE_ENTRIES;
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 14:52:07 +00:00
|
|
|
/* Get the current entry */
|
|
|
|
LdrEntry = Ldr->EntryInProgress;
|
|
|
|
if (LdrEntry)
|
|
|
|
{
|
|
|
|
/* Get the NT Headers */
|
|
|
|
NtHeader = RtlImageNtHeader(LdrEntry->DllBase);
|
|
|
|
if (NtHeader)
|
|
|
|
{
|
|
|
|
/* Get the Image Base */
|
|
|
|
DllBase = (ULONG_PTR)LdrEntry->DllBase;
|
|
|
|
DllEnd = DllBase + NtHeader->OptionalHeader.SizeOfImage;
|
|
|
|
|
|
|
|
/* Check if they match */
|
|
|
|
if (((ULONG_PTR)Address >= DllBase) &&
|
|
|
|
((ULONG_PTR)Address < DllEnd))
|
|
|
|
{
|
|
|
|
/* Return it */
|
|
|
|
*Module = LdrEntry;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Loop the module list */
|
|
|
|
ListHead = &Ldr->InMemoryOrderModuleList;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
/* Get the entry and NT Headers */
|
2015-06-15 18:38:57 +00:00
|
|
|
LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
|
2011-07-09 14:52:07 +00:00
|
|
|
NtHeader = RtlImageNtHeader(LdrEntry->DllBase);
|
|
|
|
if (NtHeader)
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
/* Get the Image Base */
|
|
|
|
DllBase = (ULONG_PTR)LdrEntry->DllBase;
|
|
|
|
DllEnd = DllBase + NtHeader->OptionalHeader.SizeOfImage;
|
|
|
|
|
|
|
|
/* Check if they match */
|
|
|
|
if (((ULONG_PTR)Address >= DllBase) &&
|
|
|
|
((ULONG_PTR)Address < DllEnd))
|
|
|
|
{
|
|
|
|
/* Return it */
|
|
|
|
*Module = LdrEntry;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next Entry */
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nothing found */
|
2014-06-23 20:30:54 +00:00
|
|
|
DbgPrintEx(DPFLTR_LDR_ID,
|
|
|
|
DPFLTR_WARNING_LEVEL,
|
|
|
|
"LDR: %s() exiting 0x%08lx\n",
|
|
|
|
__FUNCTION__,
|
|
|
|
STATUS_NO_MORE_ENTRIES);
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
return STATUS_NO_MORE_ENTRIES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrGetDllHandleEx(IN ULONG Flags,
|
|
|
|
IN PWSTR DllPath OPTIONAL,
|
|
|
|
IN PULONG DllCharacteristics OPTIONAL,
|
|
|
|
IN PUNICODE_STRING DllName,
|
|
|
|
OUT PVOID *DllHandle OPTIONAL)
|
|
|
|
{
|
2011-07-09 13:37:47 +00:00
|
|
|
NTSTATUS Status;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
2011-07-09 13:37:47 +00:00
|
|
|
UNICODE_STRING RedirectName, DllString1, RawDllName;
|
|
|
|
PUNICODE_STRING pRedirectName, CompareName;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
PWCHAR p1, p2, p3;
|
2011-07-09 13:37:47 +00:00
|
|
|
BOOLEAN Locked, RedirectedDll;
|
|
|
|
ULONG_PTR Cookie;
|
|
|
|
ULONG LoadFlag, Length;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Initialize the strings */
|
2011-07-09 13:37:47 +00:00
|
|
|
RtlInitEmptyUnicodeString(&DllString1, NULL, 0);
|
|
|
|
RtlInitEmptyUnicodeString(&RawDllName, NULL, 0);
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
RedirectName = *DllName;
|
2011-07-09 13:37:47 +00:00
|
|
|
pRedirectName = &RedirectName;
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Initialize state */
|
|
|
|
RedirectedDll = Locked = FALSE;
|
|
|
|
LdrEntry = NULL;
|
|
|
|
Cookie = 0;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Clear the handle */
|
|
|
|
if (DllHandle) *DllHandle = NULL;
|
|
|
|
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Check for a valid flag combination */
|
|
|
|
if ((Flags & ~(LDR_GET_DLL_HANDLE_EX_PIN | LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT)) ||
|
|
|
|
(!DllHandle && !(Flags & LDR_GET_DLL_HANDLE_EX_PIN)))
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Flags are invalid or no DllHandle given\n");
|
2011-07-09 13:37:47 +00:00
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto Quickie;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If not initializing */
|
|
|
|
if (!LdrpInLdrInit)
|
|
|
|
{
|
|
|
|
/* Acquire the lock */
|
|
|
|
Status = LdrLockLoaderLock(0, NULL, &Cookie);
|
2011-07-09 13:37:47 +00:00
|
|
|
if (!NT_SUCCESS(Status)) goto Quickie;
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Remember we own it */
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
Locked = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the SxS Assemblies specify another file */
|
|
|
|
Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
|
|
|
|
pRedirectName,
|
|
|
|
&LdrApiDefaultExtension,
|
|
|
|
NULL,
|
|
|
|
&DllString1,
|
|
|
|
&pRedirectName,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* Check success */
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Let Ldrp know */
|
|
|
|
RedirectedDll = TRUE;
|
|
|
|
}
|
|
|
|
else if (Status != STATUS_SXS_KEY_NOT_FOUND)
|
|
|
|
{
|
2016-09-11 20:40:41 +00:00
|
|
|
/* Unrecoverable SxS failure */
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
goto Quickie;
|
|
|
|
}
|
2011-07-09 21:48:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(pRedirectName == &RedirectName);
|
|
|
|
}
|
|
|
|
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Set default failure code */
|
|
|
|
Status = STATUS_DLL_NOT_FOUND;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Use the cache if we can */
|
|
|
|
if (LdrpGetModuleHandleCache)
|
|
|
|
{
|
|
|
|
/* Check if we were redirected */
|
|
|
|
if (RedirectedDll)
|
|
|
|
{
|
|
|
|
/* Check the flag */
|
2011-07-09 21:48:59 +00:00
|
|
|
if (!(LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED))
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
goto DontCompare;
|
|
|
|
}
|
2011-07-09 21:48:59 +00:00
|
|
|
|
|
|
|
/* Use the right name */
|
|
|
|
CompareName = &LdrpGetModuleHandleCache->FullDllName;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check the flag */
|
2011-07-09 21:48:59 +00:00
|
|
|
if (LdrpGetModuleHandleCache->Flags & LDRP_REDIRECTED)
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
goto DontCompare;
|
|
|
|
}
|
2011-07-09 21:48:59 +00:00
|
|
|
|
|
|
|
/* Use the right name */
|
|
|
|
CompareName = &LdrpGetModuleHandleCache->BaseDllName;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the name matches */
|
|
|
|
if (RtlEqualUnicodeString(pRedirectName,
|
|
|
|
CompareName,
|
|
|
|
TRUE))
|
|
|
|
{
|
|
|
|
/* Skip the rest */
|
|
|
|
LdrEntry = LdrpGetModuleHandleCache;
|
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
Status = STATUS_SUCCESS;
|
2011-07-09 13:37:47 +00:00
|
|
|
goto Quickie;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DontCompare:
|
|
|
|
/* Find the name without the extension */
|
|
|
|
p1 = pRedirectName->Buffer;
|
|
|
|
p2 = NULL;
|
2011-07-09 13:37:47 +00:00
|
|
|
p3 = &p1[pRedirectName->Length / sizeof(WCHAR)];
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
while (p1 != p3)
|
|
|
|
{
|
|
|
|
if (*p1++ == L'.')
|
|
|
|
{
|
|
|
|
p2 = p1;
|
|
|
|
}
|
|
|
|
else if (*p1 == L'\\')
|
|
|
|
{
|
2011-07-09 13:37:47 +00:00
|
|
|
p2 = NULL;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if no extension was found or if we got a slash */
|
2011-07-09 13:37:47 +00:00
|
|
|
if (!(p2) || (*p2 == L'\\') || (*p2 == L'/'))
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
/* Check that we have space to add one */
|
2011-07-09 13:37:47 +00:00
|
|
|
Length = pRedirectName->Length +
|
|
|
|
LdrApiDefaultExtension.Length + sizeof(UNICODE_NULL);
|
|
|
|
if (Length >= UNICODE_STRING_MAX_BYTES)
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
/* No space to add the extension */
|
2011-07-09 13:37:47 +00:00
|
|
|
Status = STATUS_NAME_TOO_LONG;
|
|
|
|
goto Quickie;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the string */
|
2011-07-09 13:37:47 +00:00
|
|
|
RawDllName.MaximumLength = Length;
|
|
|
|
ASSERT(Length >= sizeof(UNICODE_NULL));
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
RawDllName.MaximumLength);
|
2011-07-09 13:37:47 +00:00
|
|
|
if (!RawDllName.Buffer)
|
|
|
|
{
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto Quickie;
|
|
|
|
}
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
2011-07-09 21:48:59 +00:00
|
|
|
/* Copy the string and add extension */
|
|
|
|
RtlCopyUnicodeString(&RawDllName, pRedirectName);
|
|
|
|
RtlAppendUnicodeStringToString(&RawDllName, &LdrApiDefaultExtension);
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check if there's something in the name */
|
2011-07-09 13:37:47 +00:00
|
|
|
Length = pRedirectName->Length;
|
|
|
|
if (Length)
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
/* Check and remove trailing period */
|
2011-07-09 13:37:47 +00:00
|
|
|
if (pRedirectName->Buffer[Length / sizeof(WCHAR) - sizeof(ANSI_NULL)] == '.')
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
|
|
|
/* Decrease the size */
|
|
|
|
pRedirectName->Length -= sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the string */
|
|
|
|
RawDllName.MaximumLength = pRedirectName->Length + sizeof(WCHAR);
|
|
|
|
RawDllName.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
0,
|
|
|
|
RawDllName.MaximumLength);
|
2011-07-09 13:37:47 +00:00
|
|
|
if (!RawDllName.Buffer)
|
|
|
|
{
|
|
|
|
Status = STATUS_NO_MEMORY;
|
|
|
|
goto Quickie;
|
|
|
|
}
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
2011-07-09 21:48:59 +00:00
|
|
|
/* Copy the string */
|
|
|
|
RtlCopyUnicodeString(&RawDllName, pRedirectName);
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Display debug string */
|
|
|
|
if (ShowSnaps)
|
|
|
|
{
|
2011-07-09 21:48:59 +00:00
|
|
|
DPRINT1("LDR: LdrGetDllHandleEx, searching for %wZ from %ws\n",
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
&RawDllName,
|
|
|
|
DllPath ? ((ULONG_PTR)DllPath == 1 ? L"" : DllPath) : L"");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do the lookup */
|
|
|
|
if (LdrpCheckForLoadedDll(DllPath,
|
|
|
|
&RawDllName,
|
|
|
|
((ULONG_PTR)DllPath == 1) ? TRUE : FALSE,
|
|
|
|
RedirectedDll,
|
|
|
|
&LdrEntry))
|
|
|
|
{
|
|
|
|
/* Update cached entry */
|
|
|
|
LdrpGetModuleHandleCache = LdrEntry;
|
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Make sure to NULL this */
|
|
|
|
LdrEntry = NULL;
|
|
|
|
}
|
2011-07-09 13:37:47 +00:00
|
|
|
Quickie:
|
|
|
|
/* The success path must have a valid loader entry */
|
|
|
|
ASSERT((LdrEntry != NULL) == NT_SUCCESS(Status));
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Check if we got an entry and success */
|
|
|
|
DPRINT("Got LdrEntry->BaseDllName %wZ\n", LdrEntry ? &LdrEntry->BaseDllName : NULL);
|
|
|
|
if ((LdrEntry) && (NT_SUCCESS(Status)))
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Check if the DLL is locked */
|
|
|
|
if ((LdrEntry->LoadCount != 0xFFFF) &&
|
|
|
|
!(Flags & LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT))
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Check what to do with the load count */
|
|
|
|
if (Flags & LDR_GET_DLL_HANDLE_EX_PIN)
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
{
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Pin it */
|
|
|
|
LdrEntry->LoadCount = 0xFFFF;
|
|
|
|
LoadFlag = LDRP_UPDATE_PIN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Increase the load count */
|
|
|
|
LdrEntry->LoadCount++;
|
|
|
|
LoadFlag = LDRP_UPDATE_REFCOUNT;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
|
|
|
|
2011-07-09 13:37:47 +00:00
|
|
|
/* Update the load count now */
|
|
|
|
LdrpUpdateLoadCount2(LdrEntry, LoadFlag);
|
|
|
|
LdrpClearLoadInProgress();
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
2011-07-09 13:37:47 +00:00
|
|
|
|
|
|
|
/* Check if the caller is requesting the handle */
|
|
|
|
if (DllHandle) *DllHandle = LdrEntry->DllBase;
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
}
|
2011-07-09 13:37:47 +00:00
|
|
|
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
/* Free string if needed */
|
|
|
|
if (DllString1.Buffer) RtlFreeUnicodeString(&DllString1);
|
|
|
|
|
|
|
|
/* Free the raw DLL Name if needed */
|
|
|
|
if (RawDllName.Buffer)
|
|
|
|
{
|
|
|
|
/* Free the heap-allocated buffer */
|
2011-07-09 21:48:59 +00:00
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, RawDllName.Buffer);
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
RawDllName.Buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release lock */
|
2011-07-09 13:37:47 +00:00
|
|
|
if (Locked)
|
|
|
|
{
|
2011-07-09 21:48:59 +00:00
|
|
|
LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS,
|
|
|
|
Cookie);
|
2011-07-09 13:37:47 +00:00
|
|
|
}
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
|
|
|
|
/* Return */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrGetDllHandle(IN PWSTR DllPath OPTIONAL,
|
|
|
|
IN PULONG DllCharacteristics OPTIONAL,
|
|
|
|
IN PUNICODE_STRING DllName,
|
|
|
|
OUT PVOID *DllHandle)
|
|
|
|
{
|
|
|
|
/* Call the newer API */
|
2011-07-09 21:48:59 +00:00
|
|
|
return LdrGetDllHandleEx(LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT,
|
[NTDLL/LDR]
- The long awaited LDR rewrite, a commit for testing the new implementation. In case of serious problems it may be reverted (revert should be approved by me).
- Its features include:
* A proper ...everything. Process, thread initialization codes, DLL loading (including compatible path lookup, and compatible/proper loading order of the dependent DLLs, including their initialization) and mapping and section creation, reference counting, relocations, good and understandable PE code for walking import descriptor, snapping, etc etc. Hacks--; GoodCode++;
* Activation contexts operations are now being performed compatible to how Windows performs them (though the actual actctx implementation is still Wine's, it was modified to be compatible). Previously, actctx stuff was added to the ldr code like a pepper is added to the soup: in different places until it starts to work.
* Partial DLL redirection implementation.
* Possibility to support Shim engine and app compat stuff in future.
* More cool stuff, just browse the code.
- I fixed all regressions I could find but one (hang during shutdown of the 3rd stage). The purpose of this commit is to seek and destroy the regressions I couldn't find (if there are any).
- Some of the old rarely called ldr code still remains in startup.c and utils.c. They are subject to be rewritten/removed soon, and every remaining old function is marked with a respective DPRINT1 to see when it's being called.
svn path=/trunk/; revision=52446
2011-06-24 21:30:09 +00:00
|
|
|
DllPath,
|
|
|
|
DllCharacteristics,
|
|
|
|
DllName,
|
|
|
|
DllHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrGetProcedureAddress(IN PVOID BaseAddress,
|
|
|
|
IN PANSI_STRING Name,
|
|
|
|
IN ULONG Ordinal,
|
|
|
|
OUT PVOID *ProcedureAddress)
|
|
|
|
{
|
|
|
|
/* Call the internal routine and tell it to execute DllInit */
|
|
|
|
return LdrpGetProcedureAddress(BaseAddress, Name, Ordinal, ProcedureAddress, TRUE);
|
|
|
|
}
|
|
|
|
|
2011-03-16 09:52:41 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrVerifyImageMatchesChecksum(IN HANDLE FileHandle,
|
|
|
|
IN PLDR_CALLBACK Callback,
|
|
|
|
IN PVOID CallbackContext,
|
|
|
|
OUT PUSHORT ImageCharacteristics)
|
|
|
|
{
|
|
|
|
FILE_STANDARD_INFORMATION FileStandardInfo;
|
|
|
|
PIMAGE_IMPORT_DESCRIPTOR ImportData;
|
2012-02-11 15:30:50 +00:00
|
|
|
PIMAGE_SECTION_HEADER LastSection = NULL;
|
2011-03-16 09:52:41 +00:00
|
|
|
IO_STATUS_BLOCK IoStatusBlock;
|
|
|
|
PIMAGE_NT_HEADERS NtHeader;
|
|
|
|
HANDLE SectionHandle;
|
2011-07-09 14:52:07 +00:00
|
|
|
SIZE_T ViewSize;
|
|
|
|
PVOID ViewBase;
|
|
|
|
BOOLEAN Result, NoActualCheck;
|
2011-03-16 09:52:41 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PVOID ImportName;
|
|
|
|
ULONG Size;
|
|
|
|
DPRINT("LdrVerifyImageMatchesChecksum() called\n");
|
|
|
|
|
2011-07-09 14:52:07 +00:00
|
|
|
/* If the handle has the magic KnownDll flag, skip actual checksums */
|
|
|
|
NoActualCheck = ((ULONG_PTR)FileHandle & 1);
|
|
|
|
|
2011-03-16 09:52:41 +00:00
|
|
|
/* Create the section */
|
|
|
|
Status = NtCreateSection(&SectionHandle,
|
|
|
|
SECTION_MAP_EXECUTE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
PAGE_EXECUTE,
|
|
|
|
SEC_COMMIT,
|
|
|
|
FileHandle);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1 ("NtCreateSection() failed (Status 0x%x)\n", Status);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Map the section */
|
2011-07-09 14:52:07 +00:00
|
|
|
ViewSize = 0;
|
|
|
|
ViewBase = NULL;
|
2011-03-16 09:52:41 +00:00
|
|
|
Status = NtMapViewOfSection(SectionHandle,
|
|
|
|
NtCurrentProcess(),
|
|
|
|
&ViewBase,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&ViewSize,
|
|
|
|
ViewShare,
|
|
|
|
0,
|
|
|
|
PAGE_EXECUTE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("NtMapViewOfSection() failed (Status 0x%x)\n", Status);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the file information */
|
|
|
|
Status = NtQueryInformationFile(FileHandle,
|
|
|
|
&IoStatusBlock,
|
|
|
|
&FileStandardInfo,
|
|
|
|
sizeof(FILE_STANDARD_INFORMATION),
|
|
|
|
FileStandardInformation);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
DPRINT1("NtMapViewOfSection() failed (Status 0x%x)\n", Status);
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), ViewBase);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Protect with SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2011-07-09 14:52:07 +00:00
|
|
|
/* Check if this is the KnownDll hack */
|
|
|
|
if (NoActualCheck)
|
|
|
|
{
|
|
|
|
/* Don't actually do it */
|
|
|
|
Result = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Verify the checksum */
|
|
|
|
Result = LdrVerifyMappedImageMatchesChecksum(ViewBase,
|
|
|
|
FileStandardInfo.EndOfFile.LowPart,
|
|
|
|
FileStandardInfo.EndOfFile.LowPart);
|
|
|
|
}
|
2011-03-16 09:52:41 +00:00
|
|
|
|
|
|
|
/* Check if a callback was supplied */
|
2011-07-09 14:52:07 +00:00
|
|
|
if ((Result) && (Callback))
|
2011-03-16 09:52:41 +00:00
|
|
|
{
|
|
|
|
/* Get the NT Header */
|
|
|
|
NtHeader = RtlImageNtHeader(ViewBase);
|
|
|
|
|
|
|
|
/* Check if caller requested this back */
|
|
|
|
if (ImageCharacteristics)
|
|
|
|
{
|
|
|
|
/* Return to caller */
|
|
|
|
*ImageCharacteristics = NtHeader->FileHeader.Characteristics;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the Import Directory Data */
|
|
|
|
ImportData = RtlImageDirectoryEntryToData(ViewBase,
|
|
|
|
FALSE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_IMPORT,
|
|
|
|
&Size);
|
|
|
|
|
|
|
|
/* Make sure there is one */
|
|
|
|
if (ImportData)
|
|
|
|
{
|
|
|
|
/* Loop the imports */
|
|
|
|
while (ImportData->Name)
|
|
|
|
{
|
|
|
|
/* Get the name */
|
|
|
|
ImportName = RtlImageRvaToVa(NtHeader,
|
|
|
|
ViewBase,
|
|
|
|
ImportData->Name,
|
|
|
|
&LastSection);
|
|
|
|
|
|
|
|
/* Notify the callback */
|
|
|
|
Callback(CallbackContext, ImportName);
|
|
|
|
ImportData++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Fail the request returning STATUS_IMAGE_CHECKSUM_MISMATCH */
|
|
|
|
Result = FALSE;
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
|
|
|
|
/* Unmap file and close handle */
|
|
|
|
NtUnmapViewOfSection(NtCurrentProcess(), ViewBase);
|
|
|
|
NtClose(SectionHandle);
|
|
|
|
|
|
|
|
/* Return status */
|
2011-07-09 14:52:07 +00:00
|
|
|
return Result ? Status : STATUS_IMAGE_CHECKSUM_MISMATCH;
|
2011-03-16 09:52:41 +00:00
|
|
|
}
|
|
|
|
|
2011-03-16 14:22:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrQueryProcessModuleInformationEx(IN ULONG ProcessId,
|
|
|
|
IN ULONG Reserved,
|
2011-09-20 21:04:33 +00:00
|
|
|
OUT PRTL_PROCESS_MODULES ModuleInformation,
|
2011-03-16 14:22:15 +00:00
|
|
|
IN ULONG Size,
|
|
|
|
OUT PULONG ReturnedSize OPTIONAL)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY ModuleListHead, InitListHead;
|
|
|
|
PLIST_ENTRY Entry, InitEntry;
|
|
|
|
PLDR_DATA_TABLE_ENTRY Module, InitModule;
|
|
|
|
PRTL_PROCESS_MODULE_INFORMATION ModulePtr = NULL;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
ULONG UsedSize = sizeof(ULONG);
|
|
|
|
ANSI_STRING AnsiString;
|
|
|
|
PCHAR p;
|
|
|
|
|
|
|
|
DPRINT("LdrQueryProcessModuleInformation() called\n");
|
|
|
|
|
|
|
|
/* Acquire loader lock */
|
|
|
|
RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2011-09-20 21:04:33 +00:00
|
|
|
/* Check if we were given enough space */
|
|
|
|
if (Size < UsedSize)
|
|
|
|
{
|
|
|
|
Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ModuleInformation->NumberOfModules = 0;
|
|
|
|
ModulePtr = &ModuleInformation->Modules[0];
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Traverse the list of modules */
|
2011-03-16 14:22:15 +00:00
|
|
|
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
|
|
|
|
Entry = ModuleListHead->Flink;
|
|
|
|
|
|
|
|
while (Entry != ModuleListHead)
|
|
|
|
{
|
|
|
|
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
|
|
|
|
|
|
|
|
DPRINT(" Module %wZ\n", &Module->FullDllName);
|
|
|
|
|
|
|
|
/* Increase the used size */
|
|
|
|
UsedSize += sizeof(RTL_PROCESS_MODULE_INFORMATION);
|
|
|
|
|
|
|
|
if (UsedSize > Size)
|
|
|
|
{
|
|
|
|
Status = STATUS_INFO_LENGTH_MISMATCH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ModulePtr->ImageBase = Module->DllBase;
|
|
|
|
ModulePtr->ImageSize = Module->SizeOfImage;
|
|
|
|
ModulePtr->Flags = Module->Flags;
|
|
|
|
ModulePtr->LoadCount = Module->LoadCount;
|
|
|
|
ModulePtr->MappedBase = NULL;
|
|
|
|
ModulePtr->InitOrderIndex = 0;
|
|
|
|
ModulePtr->LoadOrderIndex = ModuleInformation->NumberOfModules;
|
|
|
|
|
|
|
|
/* Now get init order index by traversing init list */
|
|
|
|
InitListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList;
|
|
|
|
InitEntry = InitListHead->Flink;
|
|
|
|
|
|
|
|
while (InitEntry != InitListHead)
|
|
|
|
{
|
2015-06-15 18:38:57 +00:00
|
|
|
InitModule = CONTAINING_RECORD(InitEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
|
2011-03-16 14:22:15 +00:00
|
|
|
|
|
|
|
/* Increase the index */
|
|
|
|
ModulePtr->InitOrderIndex++;
|
|
|
|
|
|
|
|
/* Quit the loop if our module is found */
|
|
|
|
if (InitModule == Module) break;
|
|
|
|
|
|
|
|
/* Advance to the next entry */
|
|
|
|
InitEntry = InitEntry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare ANSI string with the module's name */
|
|
|
|
AnsiString.Length = 0;
|
|
|
|
AnsiString.MaximumLength = sizeof(ModulePtr->FullPathName);
|
|
|
|
AnsiString.Buffer = ModulePtr->FullPathName;
|
|
|
|
RtlUnicodeStringToAnsiString(&AnsiString,
|
|
|
|
&Module->FullDllName,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
/* Calculate OffsetToFileName field */
|
|
|
|
p = strrchr(ModulePtr->FullPathName, '\\');
|
|
|
|
if (p != NULL)
|
|
|
|
ModulePtr->OffsetToFileName = p - ModulePtr->FullPathName + 1;
|
|
|
|
else
|
|
|
|
ModulePtr->OffsetToFileName = 0;
|
|
|
|
|
|
|
|
/* Advance to the next module in the output list */
|
|
|
|
ModulePtr++;
|
|
|
|
|
|
|
|
/* Increase number of modules */
|
|
|
|
if (ModuleInformation)
|
|
|
|
ModuleInformation->NumberOfModules++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go to the next entry in the modules list */
|
|
|
|
Entry = Entry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set returned size if it was provided */
|
|
|
|
if (ReturnedSize)
|
|
|
|
*ReturnedSize = UsedSize;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Ignoring the exception */
|
|
|
|
} _SEH2_END;
|
|
|
|
|
|
|
|
/* Release the lock */
|
|
|
|
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
|
|
|
|
|
|
|
DPRINT("LdrQueryProcessModuleInformation() done\n");
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrQueryProcessModuleInformation(IN PRTL_PROCESS_MODULES ModuleInformation,
|
|
|
|
IN ULONG Size,
|
|
|
|
OUT PULONG ReturnedSize OPTIONAL)
|
|
|
|
{
|
|
|
|
/* Call Ex version of the API */
|
|
|
|
return LdrQueryProcessModuleInformationEx(0, 0, ModuleInformation, Size, ReturnedSize);
|
|
|
|
}
|
|
|
|
|
2011-07-10 13:23:19 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2011-03-30 21:21:42 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2011-07-10 13:23:19 +00:00
|
|
|
LdrEnumerateLoadedModules(IN BOOLEAN ReservedFlag,
|
|
|
|
IN PLDR_ENUM_CALLBACK EnumProc,
|
|
|
|
IN PVOID Context)
|
2011-03-30 21:21:42 +00:00
|
|
|
{
|
|
|
|
PLIST_ENTRY ListHead, ListEntry;
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
|
|
|
NTSTATUS Status;
|
2017-11-13 14:06:29 +00:00
|
|
|
ULONG_PTR Cookie;
|
2011-03-30 21:21:42 +00:00
|
|
|
BOOLEAN Stop = FALSE;
|
|
|
|
|
|
|
|
/* Check parameters */
|
2011-07-09 15:32:36 +00:00
|
|
|
if ((ReservedFlag) || !(EnumProc)) return STATUS_INVALID_PARAMETER;
|
2011-03-30 21:21:42 +00:00
|
|
|
|
|
|
|
/* Acquire the loader lock */
|
|
|
|
Status = LdrLockLoaderLock(0, NULL, &Cookie);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
|
|
|
|
/* Loop all the modules and call enum proc */
|
|
|
|
ListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
|
|
|
|
ListEntry = ListHead->Flink;
|
|
|
|
while (ListHead != ListEntry)
|
|
|
|
{
|
|
|
|
/* Get the entry */
|
|
|
|
LdrEntry = CONTAINING_RECORD(ListEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
|
|
|
|
|
|
|
|
/* Call the enumeration proc inside SEH */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
EnumProc(LdrEntry, Context, &Stop);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Ignoring the exception */
|
|
|
|
} _SEH2_END;
|
|
|
|
|
|
|
|
/* Break if we were asked to stop enumeration */
|
|
|
|
if (Stop)
|
|
|
|
{
|
|
|
|
/* Release loader lock */
|
|
|
|
Status = LdrUnlockLoaderLock(0, Cookie);
|
|
|
|
|
|
|
|
/* Reset any successful status to STATUS_SUCCESS, but leave
|
|
|
|
failure to the caller */
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* Return any possible failure status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advance to the next module */
|
|
|
|
ListEntry = ListEntry->Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release loader lock, it must succeed this time */
|
|
|
|
Status = LdrUnlockLoaderLock(0, Cookie);
|
|
|
|
ASSERT(NT_SUCCESS(Status));
|
|
|
|
|
|
|
|
/* Return success */
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
|
|
|
|
{
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
|
|
|
NTSTATUS Status;
|
|
|
|
BOOLEAN LockHeld;
|
|
|
|
ULONG_PTR Cookie;
|
|
|
|
DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %p)\n", BaseAddress);
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/* Don't do it during shutdown */
|
|
|
|
if (LdrpShutdownInProgress) return STATUS_SUCCESS;
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/* Check if we should grab the lock */
|
|
|
|
LockHeld = FALSE;
|
|
|
|
if (!LdrpInLdrInit)
|
|
|
|
{
|
|
|
|
/* Grab the lock */
|
|
|
|
Status = LdrLockLoaderLock(0, NULL, &Cookie);
|
|
|
|
if (!NT_SUCCESS(Status)) return Status;
|
|
|
|
LockHeld = TRUE;
|
|
|
|
}
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/* Make sure the DLL is valid and get its entry */
|
|
|
|
Status = STATUS_DLL_NOT_FOUND;
|
|
|
|
if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry))
|
|
|
|
{
|
|
|
|
/* Get if it has a TLS slot */
|
|
|
|
if (!LdrEntry->TlsIndex)
|
|
|
|
{
|
|
|
|
/* It doesn't, so you're allowed to call this */
|
|
|
|
LdrEntry->Flags |= LDRP_DONT_CALL_FOR_THREADS;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the lock was held */
|
|
|
|
if (LockHeld)
|
|
|
|
{
|
|
|
|
/* Release it */
|
|
|
|
LdrUnlockLoaderLock(LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie);
|
|
|
|
}
|
2011-07-09 21:48:59 +00:00
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/* Return the status */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-07-10 01:34:19 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrAddRefDll(IN ULONG Flags,
|
|
|
|
IN PVOID BaseAddress)
|
|
|
|
{
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2017-11-13 14:06:29 +00:00
|
|
|
ULONG_PTR Cookie;
|
2011-07-10 01:34:19 +00:00
|
|
|
BOOLEAN Locked = FALSE;
|
|
|
|
|
|
|
|
/* Check for invalid flags */
|
|
|
|
if (Flags & ~(LDR_ADDREF_DLL_PIN))
|
|
|
|
{
|
|
|
|
/* Fail with invalid parameter status if so */
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto quickie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acquire the loader lock if not in init phase */
|
|
|
|
if (!LdrpInLdrInit)
|
|
|
|
{
|
|
|
|
/* Acquire the lock */
|
|
|
|
Status = LdrLockLoaderLock(0, NULL, &Cookie);
|
|
|
|
if (!NT_SUCCESS(Status)) goto quickie;
|
|
|
|
Locked = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get this module's data table entry */
|
|
|
|
if (LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry))
|
|
|
|
{
|
|
|
|
if (!LdrEntry)
|
|
|
|
{
|
|
|
|
/* Shouldn't happen */
|
|
|
|
Status = STATUS_INTERNAL_ERROR;
|
|
|
|
goto quickie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this is not a pinned module */
|
|
|
|
if (LdrEntry->LoadCount != 0xFFFF)
|
|
|
|
{
|
|
|
|
/* Update its load count */
|
|
|
|
if (Flags & LDR_ADDREF_DLL_PIN)
|
|
|
|
{
|
|
|
|
/* Pin it by setting load count to -1 */
|
|
|
|
LdrEntry->LoadCount = 0xFFFF;
|
|
|
|
LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_PIN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Increase its load count by one */
|
|
|
|
LdrEntry->LoadCount++;
|
|
|
|
LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_REFCOUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear load in progress */
|
|
|
|
LdrpClearLoadInProgress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* There was an error getting this module's handle, return invalid param status */
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
quickie:
|
|
|
|
/* Check for error case */
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Print debug information */
|
|
|
|
if ((ShowSnaps) || ((Status != STATUS_NO_SUCH_FILE) &&
|
|
|
|
(Status != STATUS_DLL_NOT_FOUND) &&
|
|
|
|
(Status != STATUS_OBJECT_NAME_NOT_FOUND)))
|
|
|
|
{
|
2013-08-29 21:12:40 +00:00
|
|
|
DPRINT1("LDR: LdrAddRefDll(%p) 0x%08lx\n", BaseAddress, Status);
|
2011-07-10 01:34:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the lock if needed */
|
|
|
|
if (Locked) LdrUnlockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, Cookie);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-07-10 13:23:19 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrUnloadDll(IN PVOID BaseAddress)
|
|
|
|
{
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PPEB Peb = NtCurrentPeb();
|
|
|
|
PLDR_DATA_TABLE_ENTRY LdrEntry, CurrentEntry;
|
|
|
|
PVOID EntryPoint;
|
|
|
|
PLIST_ENTRY NextEntry;
|
|
|
|
LIST_ENTRY UnloadList;
|
|
|
|
RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx;
|
|
|
|
PVOID CorImageData;
|
|
|
|
ULONG ComSectionSize;
|
|
|
|
|
|
|
|
/* Get the LDR Lock */
|
|
|
|
if (!LdrpInLdrInit) RtlEnterCriticalSection(Peb->LoaderLock);
|
|
|
|
|
|
|
|
/* Increase the unload count */
|
|
|
|
LdrpActiveUnloadCount++;
|
|
|
|
|
|
|
|
/* Skip unload */
|
|
|
|
if (LdrpShutdownInProgress) goto Quickie;
|
|
|
|
|
|
|
|
/* Make sure the DLL is valid and get its entry */
|
|
|
|
if (!LdrpCheckForLoadedDllHandle(BaseAddress, &LdrEntry))
|
|
|
|
{
|
|
|
|
Status = STATUS_DLL_NOT_FOUND;
|
|
|
|
goto Quickie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the current Load Count */
|
2011-07-10 15:02:00 +00:00
|
|
|
if (LdrEntry->LoadCount != 0xFFFF)
|
2011-07-10 13:23:19 +00:00
|
|
|
{
|
|
|
|
/* Decrease it */
|
|
|
|
LdrEntry->LoadCount--;
|
|
|
|
|
|
|
|
/* If it's a dll */
|
|
|
|
if (LdrEntry->Flags & LDRP_IMAGE_DLL)
|
|
|
|
{
|
|
|
|
/* Set up the Act Ctx */
|
|
|
|
ActCtx.Size = sizeof(ActCtx);
|
|
|
|
ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
|
2011-07-10 16:25:42 +00:00
|
|
|
RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME));
|
2011-07-10 13:23:19 +00:00
|
|
|
|
|
|
|
/* Activate the ActCtx */
|
|
|
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
|
|
|
LdrEntry->EntryPointActivationContext);
|
|
|
|
|
|
|
|
/* Update the load count */
|
|
|
|
LdrpUpdateLoadCount2(LdrEntry, LDRP_UPDATE_DEREFCOUNT);
|
|
|
|
|
|
|
|
/* Release the context */
|
|
|
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The DLL is locked */
|
|
|
|
goto Quickie;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show debug message */
|
|
|
|
if (ShowSnaps) DPRINT1("LDR: UNINIT LIST\n");
|
|
|
|
|
|
|
|
/* Check if this is our only unload and initialize the list if so */
|
|
|
|
if (LdrpActiveUnloadCount == 1) InitializeListHead(&LdrpUnloadHead);
|
|
|
|
|
|
|
|
/* Loop the modules to build the list */
|
|
|
|
NextEntry = Peb->Ldr->InInitializationOrderModuleList.Blink;
|
|
|
|
while (NextEntry != &Peb->Ldr->InInitializationOrderModuleList)
|
|
|
|
{
|
|
|
|
/* Get the entry */
|
|
|
|
LdrEntry = CONTAINING_RECORD(NextEntry,
|
|
|
|
LDR_DATA_TABLE_ENTRY,
|
2015-06-15 18:38:57 +00:00
|
|
|
InInitializationOrderLinks);
|
2011-07-10 13:23:19 +00:00
|
|
|
NextEntry = NextEntry->Blink;
|
|
|
|
|
|
|
|
/* Remove flag */
|
|
|
|
LdrEntry->Flags &= ~LDRP_UNLOAD_IN_PROGRESS;
|
|
|
|
|
|
|
|
/* If the load count is now 0 */
|
|
|
|
if (!LdrEntry->LoadCount)
|
|
|
|
{
|
|
|
|
/* Show message */
|
|
|
|
if (ShowSnaps)
|
|
|
|
{
|
2013-08-29 21:12:40 +00:00
|
|
|
DPRINT1("(%lu) [%ws] %ws (%lx) deinit %p\n",
|
2011-07-10 13:23:19 +00:00
|
|
|
LdrpActiveUnloadCount,
|
|
|
|
LdrEntry->BaseDllName.Buffer,
|
|
|
|
LdrEntry->FullDllName.Buffer,
|
|
|
|
(ULONG)LdrEntry->LoadCount,
|
|
|
|
LdrEntry->EntryPoint);
|
|
|
|
}
|
|
|
|
|
2017-03-04 20:34:36 +00:00
|
|
|
/* Call Shim Engine and notify */
|
|
|
|
if (g_ShimsEnabled)
|
|
|
|
{
|
|
|
|
VOID (NTAPI* SE_DllUnloaded)(PVOID) = RtlDecodeSystemPointer(g_pfnSE_DllUnloaded);
|
|
|
|
SE_DllUnloaded(LdrEntry);
|
|
|
|
}
|
2011-07-10 13:23:19 +00:00
|
|
|
|
|
|
|
/* Unlink it */
|
|
|
|
CurrentEntry = LdrEntry;
|
2015-06-15 18:38:57 +00:00
|
|
|
RemoveEntryList(&CurrentEntry->InInitializationOrderLinks);
|
|
|
|
RemoveEntryList(&CurrentEntry->InMemoryOrderLinks);
|
2011-07-10 13:23:19 +00:00
|
|
|
RemoveEntryList(&CurrentEntry->HashLinks);
|
|
|
|
|
|
|
|
/* If there's more then one active unload */
|
|
|
|
if (LdrpActiveUnloadCount > 1)
|
|
|
|
{
|
|
|
|
/* Flush the cached DLL handle and clear the list */
|
|
|
|
LdrpLoadedDllHandleCache = NULL;
|
2015-06-15 18:38:57 +00:00
|
|
|
CurrentEntry->InMemoryOrderLinks.Flink = NULL;
|
2011-07-10 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the entry on the unload list */
|
|
|
|
InsertTailList(&LdrpUnloadHead, &CurrentEntry->HashLinks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only call the entrypoints once */
|
|
|
|
if (LdrpActiveUnloadCount > 1) goto Quickie;
|
|
|
|
|
|
|
|
/* Now loop the unload list and create our own */
|
|
|
|
InitializeListHead(&UnloadList);
|
|
|
|
CurrentEntry = NULL;
|
|
|
|
NextEntry = LdrpUnloadHead.Flink;
|
|
|
|
while (NextEntry != &LdrpUnloadHead)
|
|
|
|
{
|
|
|
|
/* Get the current entry */
|
|
|
|
LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks);
|
|
|
|
|
2020-04-18 11:53:02 +00:00
|
|
|
LdrpRecordUnloadEvent(LdrEntry);
|
2011-07-10 13:23:19 +00:00
|
|
|
|
|
|
|
/* Set the entry and clear it from the list */
|
|
|
|
CurrentEntry = LdrEntry;
|
|
|
|
LdrpLoadedDllHandleCache = NULL;
|
2015-06-15 18:38:57 +00:00
|
|
|
CurrentEntry->InMemoryOrderLinks.Flink = NULL;
|
2011-07-10 13:23:19 +00:00
|
|
|
|
|
|
|
/* Move it from the global to the local list */
|
|
|
|
RemoveEntryList(&CurrentEntry->HashLinks);
|
|
|
|
InsertTailList(&UnloadList, &CurrentEntry->HashLinks);
|
|
|
|
|
|
|
|
/* Get the entrypoint */
|
|
|
|
EntryPoint = LdrEntry->EntryPoint;
|
|
|
|
|
|
|
|
/* Check if we should call it */
|
|
|
|
if ((EntryPoint) && (LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED))
|
|
|
|
{
|
|
|
|
/* Show message */
|
|
|
|
if (ShowSnaps)
|
|
|
|
{
|
2013-08-29 21:12:40 +00:00
|
|
|
DPRINT1("LDR: Calling deinit %p\n", EntryPoint);
|
2011-07-10 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up the Act Ctx */
|
|
|
|
ActCtx.Size = sizeof(ActCtx);
|
|
|
|
ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
|
2011-07-10 16:25:42 +00:00
|
|
|
RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME));
|
2011-07-10 13:23:19 +00:00
|
|
|
|
|
|
|
/* Activate the ActCtx */
|
|
|
|
RtlActivateActivationContextUnsafeFast(&ActCtx,
|
|
|
|
LdrEntry->EntryPointActivationContext);
|
|
|
|
|
|
|
|
/* Call the entrypoint */
|
2018-04-08 19:51:20 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
LdrpCallInitRoutine(LdrEntry->EntryPoint,
|
|
|
|
LdrEntry->DllBase,
|
|
|
|
DLL_PROCESS_DETACH,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2018-07-29 15:13:42 +00:00
|
|
|
DPRINT1("WARNING: Exception 0x%x during LdrpCallInitRoutine(DLL_PROCESS_DETACH) for %wZ\n",
|
|
|
|
_SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
|
2018-04-08 19:51:20 +00:00
|
|
|
}
|
|
|
|
_SEH2_END;
|
2011-07-10 13:23:19 +00:00
|
|
|
|
|
|
|
/* Release the context */
|
|
|
|
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove it from the list */
|
|
|
|
RemoveEntryList(&CurrentEntry->InLoadOrderLinks);
|
|
|
|
CurrentEntry = NULL;
|
|
|
|
NextEntry = LdrpUnloadHead.Flink;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now loop our local list */
|
|
|
|
NextEntry = UnloadList.Flink;
|
|
|
|
while (NextEntry != &UnloadList)
|
|
|
|
{
|
|
|
|
/* Get the entry */
|
|
|
|
LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, HashLinks);
|
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
CurrentEntry = LdrEntry;
|
|
|
|
|
|
|
|
/* Notify Application Verifier */
|
|
|
|
if (Peb->NtGlobalFlag & FLG_HEAP_ENABLE_TAIL_CHECK)
|
|
|
|
{
|
2018-04-27 20:43:45 +00:00
|
|
|
AVrfDllUnloadNotification(LdrEntry);
|
2011-07-10 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Show message */
|
|
|
|
if (ShowSnaps)
|
|
|
|
{
|
|
|
|
DPRINT1("LDR: Unmapping [%ws]\n", LdrEntry->BaseDllName.Buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a .NET executable */
|
|
|
|
CorImageData = RtlImageDirectoryEntryToData(LdrEntry->DllBase,
|
|
|
|
TRUE,
|
|
|
|
IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR,
|
|
|
|
&ComSectionSize);
|
|
|
|
if (CorImageData)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
DPRINT1(".NET Images are not supported yet\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we should unmap*/
|
|
|
|
if (!(CurrentEntry->Flags & LDR_COR_OWNS_UNMAP))
|
|
|
|
{
|
|
|
|
/* Unmap the DLL */
|
|
|
|
Status = NtUnmapViewOfSection(NtCurrentProcess(),
|
|
|
|
CurrentEntry->DllBase);
|
|
|
|
ASSERT(NT_SUCCESS(Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unload the alternate resource module, if any */
|
|
|
|
LdrUnloadAlternateResourceModule(CurrentEntry->DllBase);
|
|
|
|
|
|
|
|
/* FIXME: Send shutdown notification */
|
|
|
|
//LdrpSendDllNotifications(CurrentEntry, 2, LdrpShutdownInProgress);
|
|
|
|
|
|
|
|
/* Check if a Hotpatch is active */
|
|
|
|
if (LdrEntry->PatchInformation)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
DPRINT1("We don't support Hotpatching yet\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deallocate the Entry */
|
|
|
|
LdrpFinalizeAndDeallocateDataTableEntry(CurrentEntry);
|
|
|
|
|
|
|
|
/* If this is the cached entry, invalidate it */
|
|
|
|
if (LdrpGetModuleHandleCache == CurrentEntry)
|
|
|
|
{
|
|
|
|
LdrpGetModuleHandleCache = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Quickie:
|
|
|
|
/* Decrease unload count */
|
|
|
|
LdrpActiveUnloadCount--;
|
|
|
|
if (!LdrpInLdrInit) RtlLeaveCriticalSection(Peb->LoaderLock);
|
|
|
|
|
|
|
|
/* Return to caller */
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
RtlDllShutdownInProgress(VOID)
|
|
|
|
{
|
|
|
|
/* Return the internal global */
|
|
|
|
return LdrpShutdownInProgress;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
PIMAGE_BASE_RELOCATION
|
|
|
|
NTAPI
|
|
|
|
LdrProcessRelocationBlock(IN ULONG_PTR Address,
|
|
|
|
IN ULONG Count,
|
|
|
|
IN PUSHORT TypeOffset,
|
|
|
|
IN LONG_PTR Delta)
|
|
|
|
{
|
|
|
|
return LdrProcessRelocationBlockLongLong(Address, Count, TypeOffset, Delta);
|
|
|
|
}
|
|
|
|
|
2013-10-05 12:06:59 +00:00
|
|
|
/* FIXME: Add to ntstatus.mc */
|
|
|
|
#define STATUS_MUI_FILE_NOT_FOUND ((NTSTATUS)0xC00B0001L)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrLoadAlternateResourceModule(IN PVOID Module,
|
|
|
|
IN PWSTR Buffer)
|
|
|
|
{
|
|
|
|
/* Is MUI Support enabled? */
|
|
|
|
if (!LdrAlternateResourcesEnabled()) return STATUS_SUCCESS;
|
|
|
|
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_MUI_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2011-07-09 16:15:43 +00:00
|
|
|
/*
|
2011-11-06 01:34:06 +00:00
|
|
|
* @implemented
|
2011-07-09 16:15:43 +00:00
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
LdrUnloadAlternateResourceModule(IN PVOID BaseAddress)
|
|
|
|
{
|
2011-11-06 01:34:06 +00:00
|
|
|
ULONG_PTR Cookie;
|
2012-07-12 14:55:53 +00:00
|
|
|
|
2011-11-06 01:34:06 +00:00
|
|
|
/* Acquire the loader lock */
|
2013-10-23 19:31:41 +00:00
|
|
|
LdrLockLoaderLock(LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS, NULL, &Cookie);
|
2012-07-12 14:55:53 +00:00
|
|
|
|
2011-11-06 01:34:06 +00:00
|
|
|
/* Check if there's any alternate resources loaded */
|
|
|
|
if (AlternateResourceModuleCount)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
}
|
2012-07-12 14:55:53 +00:00
|
|
|
|
2011-11-06 01:34:06 +00:00
|
|
|
/* Release the loader lock */
|
|
|
|
LdrUnlockLoaderLock(1, Cookie);
|
2012-07-12 14:55:53 +00:00
|
|
|
|
2011-11-06 01:34:06 +00:00
|
|
|
/* All done */
|
|
|
|
return TRUE;
|
2011-07-09 16:15:43 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 01:34:06 +00:00
|
|
|
/*
|
2013-10-05 12:06:59 +00:00
|
|
|
* @unimplemented
|
2011-11-06 01:34:06 +00:00
|
|
|
*/
|
2013-10-05 12:06:59 +00:00
|
|
|
BOOLEAN
|
2011-11-06 01:34:06 +00:00
|
|
|
NTAPI
|
2013-10-05 12:06:59 +00:00
|
|
|
LdrFlushAlternateResourceModules(VOID)
|
2011-11-06 01:34:06 +00:00
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
2013-10-05 12:06:59 +00:00
|
|
|
return FALSE;
|
2011-11-06 01:34:06 +00:00
|
|
|
}
|
2012-07-12 14:55:53 +00:00
|
|
|
|
2019-09-21 10:46:01 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
* See https://www.kernelmode.info/forum/viewtopic.php?t=991
|
|
|
|
*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
LdrSetAppCompatDllRedirectionCallback(
|
|
|
|
_In_ ULONG Flags,
|
|
|
|
_In_ PLDR_APP_COMPAT_DLL_REDIRECTION_CALLBACK_FUNCTION CallbackFunction,
|
|
|
|
_In_opt_ PVOID CallbackData)
|
|
|
|
{
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-03-15 18:56:17 +00:00
|
|
|
/* EOF */
|