Added tests for patch ntdll-loader_EntryPoint.

This commit is contained in:
Sebastian Lackner 2014-10-03 22:18:32 +02:00
parent b585bfb7f4
commit 7f43d57d01
4 changed files with 150 additions and 40 deletions

View File

@ -768,11 +768,12 @@ ntdll-WRITECOPY.ok:
# | * [#33034] Set ldr.EntryPoint for main executable
# |
# | Modified files:
# | * dlls/ntdll/loader.c
# | * dlls/kernel32/tests/module.c, dlls/ntdll/loader.c
# |
.INTERMEDIATE: ntdll-loader_EntryPoint.ok
ntdll-loader_EntryPoint.ok:
$(call APPLY_FILE,ntdll-loader_EntryPoint/0001-ntdll-Set-ldr.EntryPoint-for-main-executable.patch)
$(call APPLY_FILE,ntdll-loader_EntryPoint/0001-kernel32-tests-Add-tests-for-K32GetModuleInformation.patch)
$(call APPLY_FILE,ntdll-loader_EntryPoint/0002-ntdll-Set-ldr.EntryPoint-for-main-executable.-resend.patch)
@( \
echo '+ { "ntdll-loader_EntryPoint", "Sebastian Lackner", "Set ldr.EntryPoint for main executable." },'; \
) > ntdll-loader_EntryPoint.ok

View File

@ -0,0 +1,94 @@
From 7e25c6c4537604eab67b3b62a97a23a3057b59c0 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 1 Oct 2014 17:35:22 +0200
Subject: kernel32/tests: Add tests for K32GetModuleInformation.
Test to confirm AFs analysis from bug 33034.
---
dlls/kernel32/tests/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
index 0d140a4..fb0130d 100644
--- a/dlls/kernel32/tests/module.c
+++ b/dlls/kernel32/tests/module.c
@@ -20,12 +20,14 @@
#include "wine/test.h"
#include <windows.h>
+#include <psapi.h>
static DWORD (WINAPI *pGetDllDirectoryA)(DWORD,LPSTR);
static DWORD (WINAPI *pGetDllDirectoryW)(DWORD,LPWSTR);
static BOOL (WINAPI *pSetDllDirectoryA)(LPCSTR);
static BOOL (WINAPI *pGetModuleHandleExA)(DWORD,LPCSTR,HMODULE*);
static BOOL (WINAPI *pGetModuleHandleExW)(DWORD,LPCWSTR,HMODULE*);
+static BOOL (WINAPI *pK32GetModuleInformation)(HANDLE,HMODULE,MODULEINFO*,DWORD);
static BOOL is_unicode_enabled = TRUE;
@@ -514,7 +516,20 @@ static void init_pointers(void)
MAKEFUNC(SetDllDirectoryA);
MAKEFUNC(GetModuleHandleExA);
MAKEFUNC(GetModuleHandleExW);
+ MAKEFUNC(K32GetModuleInformation);
#undef MAKEFUNC
+
+ /* not all Windows versions export this in kernel32 */
+ if (!pK32GetModuleInformation)
+ {
+ HMODULE hPsapi = LoadLibraryA("psapi.dll");
+ if (hPsapi)
+ {
+ pK32GetModuleInformation = (void *)GetProcAddress(hPsapi, "GetModuleInformation");
+ if (!pK32GetModuleInformation) FreeLibrary(hPsapi);
+ }
+ }
+
}
static void testGetModuleHandleEx(void)
@@ -696,6 +711,34 @@ static void testGetModuleHandleEx(void)
FreeLibrary( mod_kernel32 );
}
+static void testK32GetModuleInformation(void)
+{
+ MODULEINFO info;
+ HMODULE mod;
+ BOOL ret;
+
+ if (!pK32GetModuleInformation)
+ {
+ win_skip("K32GetModuleInformation not available\n");
+ return;
+ }
+
+ mod = GetModuleHandleA(NULL);
+ memset(&info, 0xAA, sizeof(info));
+ ret = pK32GetModuleInformation(GetCurrentProcess(), mod, &info, sizeof(info));
+ ok(ret, "K32GetModuleInformation failed for main module\n");
+ ok(info.lpBaseOfDll == mod, "Wrong info.lpBaseOfDll = %p, expected %p\n", info.lpBaseOfDll, mod);
+ todo_wine
+ ok(info.EntryPoint != NULL, "Expected nonzero entrypoint\n");
+
+ mod = GetModuleHandleA("kernel32.dll");
+ memset(&info, 0xAA, sizeof(info));
+ ret = pK32GetModuleInformation(GetCurrentProcess(), mod, &info, sizeof(info));
+ ok(ret, "K32GetModuleInformation failed for kernel32 module\n");
+ ok(info.lpBaseOfDll == mod, "Wrong info.lpBaseOfDll = %p, expected %p\n", info.lpBaseOfDll, mod);
+ ok(info.EntryPoint != NULL, "Expected nonzero entrypoint\n");
+}
+
START_TEST(module)
{
WCHAR filenameW[MAX_PATH];
@@ -724,4 +767,5 @@ START_TEST(module)
testGetProcAddress_Wrong();
testLoadLibraryEx();
testGetModuleHandleEx();
+ testK32GetModuleInformation();
}
--
2.1.1

View File

@ -1,38 +0,0 @@
From 63a62bb5903e62f161b7e5972662220c606d702f Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 2 Aug 2014 18:27:20 +0200
Subject: ntdll: Set ldr.EntryPoint for main executable.
---
dlls/ntdll/loader.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 79aa341..c869d8f 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -921,9 +921,10 @@ static WINE_MODREF *alloc_module( HMODULE hModule, LPCWSTR filename )
else p = wm->ldr.FullDllName.Buffer;
RtlInitUnicodeString( &wm->ldr.BaseDllName, p );
- if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && !is_dll_native_subsystem( hModule, nt, p ))
+ if (!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) || !is_dll_native_subsystem( hModule, nt, p ))
{
- wm->ldr.Flags |= LDR_IMAGE_IS_DLL;
+ if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
+ wm->ldr.Flags |= LDR_IMAGE_IS_DLL;
if (nt->OptionalHeader.AddressOfEntryPoint)
wm->ldr.EntryPoint = (char *)hModule + nt->OptionalHeader.AddressOfEntryPoint;
}
@@ -1049,7 +1050,7 @@ static NTSTATUS MODULE_InitDLL( WINE_MODREF *wm, UINT reason, LPVOID lpReserved
if (wm->ldr.Flags & LDR_DONT_RESOLVE_REFS) return STATUS_SUCCESS;
if (wm->ldr.TlsIndex != -1) call_tls_callbacks( wm->ldr.BaseAddress, reason );
- if (!entry) return STATUS_SUCCESS;
+ if (!entry || !(wm->ldr.Flags & LDR_IMAGE_IS_DLL)) return STATUS_SUCCESS;
if (TRACE_ON(relay))
{
--
1.7.9.5

View File

@ -0,0 +1,53 @@
From 0819075c75d740657873e01d35e8673070c49442 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Wed, 1 Oct 2014 17:35:28 +0200
Subject: ntdll: Set ldr.EntryPoint for main executable. (resend)
Fixes: https://bugs.winehq.org/show_bug.cgi?id=33034
No code change (besides the removed todo_wine).
---
dlls/kernel32/tests/module.c | 1 -
dlls/ntdll/loader.c | 7 ++++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/dlls/kernel32/tests/module.c b/dlls/kernel32/tests/module.c
index fb0130d..56b6494 100644
--- a/dlls/kernel32/tests/module.c
+++ b/dlls/kernel32/tests/module.c
@@ -728,7 +728,6 @@ static void testK32GetModuleInformation(void)
ret = pK32GetModuleInformation(GetCurrentProcess(), mod, &info, sizeof(info));
ok(ret, "K32GetModuleInformation failed for main module\n");
ok(info.lpBaseOfDll == mod, "Wrong info.lpBaseOfDll = %p, expected %p\n", info.lpBaseOfDll, mod);
- todo_wine
ok(info.EntryPoint != NULL, "Expected nonzero entrypoint\n");
mod = GetModuleHandleA("kernel32.dll");
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 18ae29c..3c2fc56 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -934,9 +934,10 @@ static WINE_MODREF *alloc_module( HMODULE hModule, LPCWSTR filename )
else p = wm->ldr.FullDllName.Buffer;
RtlInitUnicodeString( &wm->ldr.BaseDllName, p );
- if ((nt->FileHeader.Characteristics & IMAGE_FILE_DLL) && !is_dll_native_subsystem( hModule, nt, p ))
+ if (!(nt->FileHeader.Characteristics & IMAGE_FILE_DLL) || !is_dll_native_subsystem( hModule, nt, p ))
{
- wm->ldr.Flags |= LDR_IMAGE_IS_DLL;
+ if (nt->FileHeader.Characteristics & IMAGE_FILE_DLL)
+ wm->ldr.Flags |= LDR_IMAGE_IS_DLL;
if (nt->OptionalHeader.AddressOfEntryPoint)
wm->ldr.EntryPoint = (char *)hModule + nt->OptionalHeader.AddressOfEntryPoint;
}
@@ -1062,7 +1063,7 @@ static NTSTATUS MODULE_InitDLL( WINE_MODREF *wm, UINT reason, LPVOID lpReserved
if (wm->ldr.Flags & LDR_DONT_RESOLVE_REFS) return STATUS_SUCCESS;
if (wm->ldr.TlsIndex != -1) call_tls_callbacks( wm->ldr.BaseAddress, reason );
- if (!entry) return STATUS_SUCCESS;
+ if (!entry || !(wm->ldr.Flags & LDR_IMAGE_IS_DLL)) return STATUS_SUCCESS;
if (TRACE_ON(relay))
{
--
2.1.1