[1/2] ntdll: Do not sort InMemoryOrderModuleList by memory address.

Sebastian Lackner sebastian at fds-team.de
Wed Jul 6 23:43:25 CDT 2016


From: Michael Müller <michael at fds-team.de>

Signed-off-by: Michael Müller <michael at fds-team.de>
Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---

Tests show that both InLoadOrderModuleList and InMemoryOrderModuleList are
identical lists, and especially that they are not sorted by memory address.
Probably this was the case for older versions of Windows?

 dlls/ntdll/loader.c |   19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index a0049fe..d9176d7 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -355,7 +355,6 @@ static WINE_MODREF *get_modref( HMODULE hmod )
         mod = CONTAINING_RECORD(entry, LDR_MODULE, InMemoryOrderModuleList);
         if (mod->BaseAddress == hmod)
             return cached_modref = CONTAINING_RECORD(mod, WINE_MODREF, ldr);
-        if (mod->BaseAddress > (void*)hmod) break;
     }
     return NULL;
 }
@@ -932,7 +931,6 @@ static WINE_MODREF *alloc_module( HMODULE hModule, LPCWSTR filename )
     WINE_MODREF *wm;
     const WCHAR *p;
     const IMAGE_NT_HEADERS *nt = RtlImageNtHeader(hModule);
-    PLIST_ENTRY entry, mark;
 
     if (!(wm = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*wm) ))) return NULL;
 
@@ -965,18 +963,8 @@ static WINE_MODREF *alloc_module( HMODULE hModule, LPCWSTR filename )
 
     InsertTailList(&NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList,
                    &wm->ldr.InLoadOrderModuleList);
-
-    /* insert module in MemoryList, sorted in increasing base addresses */
-    mark = &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList;
-    for (entry = mark->Flink; entry != mark; entry = entry->Flink)
-    {
-        if (CONTAINING_RECORD(entry, LDR_MODULE, InMemoryOrderModuleList)->BaseAddress > wm->ldr.BaseAddress)
-            break;
-    }
-    entry->Blink->Flink = &wm->ldr.InMemoryOrderModuleList;
-    wm->ldr.InMemoryOrderModuleList.Blink = entry->Blink;
-    wm->ldr.InMemoryOrderModuleList.Flink = entry;
-    entry->Blink = &wm->ldr.InMemoryOrderModuleList;
+    InsertTailList(&NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList,
+                   &wm->ldr.InMemoryOrderModuleList);
 
     /* wait until init is called for inserting into this list */
     wm->ldr.InInitializationOrderModuleList.Flink = NULL;
@@ -1386,7 +1374,6 @@ NTSTATUS WINAPI LdrFindEntryForAddress(const void* addr, PLDR_MODULE* pmod)
             *pmod = mod;
             return STATUS_SUCCESS;
         }
-        if (mod->BaseAddress > addr) break;
     }
     return STATUS_NO_MORE_ENTRIES;
 }
@@ -3088,6 +3075,8 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
     /* the main exe needs to be the first in the load order list */
     RemoveEntryList( &wm->ldr.InLoadOrderModuleList );
     InsertHeadList( &peb->LdrData->InLoadOrderModuleList, &wm->ldr.InLoadOrderModuleList );
+    RemoveEntryList( &wm->ldr.InMemoryOrderModuleList );
+    InsertHeadList( &peb->LdrData->InMemoryOrderModuleList, &wm->ldr.InMemoryOrderModuleList );
 
     if ((status = virtual_alloc_thread_stack( NtCurrentTeb(), 0, 0 )) != STATUS_SUCCESS) goto error;
     if ((status = server_init_process_done()) != STATUS_SUCCESS) goto error;
-- 
2.8.0



More information about the wine-patches mailing list