From 71bb1a35f5123367b7b804617ec224097fe24a6b Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Thu, 26 May 2016 15:55:53 +0200 Subject: [PATCH] Added patch to avoid sorting InMemoryOrderModuleList by memory address. --- ...t-the-InMemoryOrderModuleList-by-mem.patch | 70 +++++++++++++++++++ .../ntdll-InMemoryOrderModuleList/definition | 1 + patches/patchinstall.sh | 19 +++++ 3 files changed, 90 insertions(+) create mode 100644 patches/ntdll-InMemoryOrderModuleList/0001-ntdll-Do-not-sort-the-InMemoryOrderModuleList-by-mem.patch create mode 100644 patches/ntdll-InMemoryOrderModuleList/definition diff --git a/patches/ntdll-InMemoryOrderModuleList/0001-ntdll-Do-not-sort-the-InMemoryOrderModuleList-by-mem.patch b/patches/ntdll-InMemoryOrderModuleList/0001-ntdll-Do-not-sort-the-InMemoryOrderModuleList-by-mem.patch new file mode 100644 index 00000000..47874340 --- /dev/null +++ b/patches/ntdll-InMemoryOrderModuleList/0001-ntdll-Do-not-sort-the-InMemoryOrderModuleList-by-mem.patch @@ -0,0 +1,70 @@ +From b8f84b9dea7d81bf4b32853ad7c20cef9d466baa Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Michael=20M=C3=BCller?= +Date: Thu, 26 May 2016 02:27:29 +0200 +Subject: ntdll: Do not sort the InMemoryOrderModuleList by memory addresses. + +--- + 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 + diff --git a/patches/ntdll-InMemoryOrderModuleList/definition b/patches/ntdll-InMemoryOrderModuleList/definition new file mode 100644 index 00000000..cde6e9e1 --- /dev/null +++ b/patches/ntdll-InMemoryOrderModuleList/definition @@ -0,0 +1 @@ +Fixes: [40623] Do not sort the InMemoryOrderModuleList by memory addresses diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 4be3f9bf..1731289a 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -215,6 +215,7 @@ patch_enable_all () enable_ntdll_Fix_Alignment="$1" enable_ntdll_Heap_FreeLists="$1" enable_ntdll_Hide_Wine_Exports="$1" + enable_ntdll_InMemoryOrderModuleList="$1" enable_ntdll_Junction_Points="$1" enable_ntdll_Loader_Machine_Type="$1" enable_ntdll_NtAccessCheck="$1" @@ -823,6 +824,9 @@ patch_enable () ntdll-Hide_Wine_Exports) enable_ntdll_Hide_Wine_Exports="$2" ;; + ntdll-InMemoryOrderModuleList) + enable_ntdll_InMemoryOrderModuleList="$2" + ;; ntdll-Junction_Points) enable_ntdll_Junction_Points="$2" ;; @@ -4932,6 +4936,21 @@ if test "$enable_ntdll_Hide_Wine_Exports" -eq 1; then ) >> "$patchlist" fi +# Patchset ntdll-InMemoryOrderModuleList +# | +# | This patchset fixes the following Wine bugs: +# | * [#40623] Do not sort the InMemoryOrderModuleList by memory addresses +# | +# | Modified files: +# | * dlls/ntdll/loader.c +# | +if test "$enable_ntdll_InMemoryOrderModuleList" -eq 1; then + patch_apply ntdll-InMemoryOrderModuleList/0001-ntdll-Do-not-sort-the-InMemoryOrderModuleList-by-mem.patch + ( + echo '+ { "Michael Müller", "ntdll: Do not sort the InMemoryOrderModuleList by memory addresses.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ntdll-NtQueryEaFile # | # | Modified files: