Module: wine Branch: master Commit: cbcfaab5191838f8738989fcad7fcb2c490fbe98 URL: https://gitlab.winehq.org/wine/wine/-/commit/cbcfaab5191838f8738989fcad7fcb2...
Author: Paul Gofman pgofman@codeweavers.com Date: Fri Dec 15 16:20:54 2023 -0600
ntdll: Use position independent syscall thunk for NtQueryInformationProcess on i386.
Fixes a regression introduced by commit efd03f40e6e315d89cd1d09c48180aae82033f9f.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55967
---
dlls/ntdll/signal_i386.c | 24 ++++++++++++++++++++++++ dlls/ntdll/tests/virtual.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index 4fff401c88d..37360929ba6 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -73,6 +73,30 @@ extern DWORD EXC_CallHandler( EXCEPTION_RECORD *record, EXCEPTION_REGISTRATION_R PEXCEPTION_HANDLER handler, PEXCEPTION_HANDLER nested_handler );
+#ifdef __WINE_PE_BUILD + +enum syscall_ids +{ +#define SYSCALL_ENTRY(id,name,args) __id_##name = id, +ALL_SYSCALLS32 +#undef SYSCALL_ENTRY +}; + +/******************************************************************* + * NtQueryInformationProcess + */ +void NtQueryInformationProcess_wrapper(void) +{ + asm( ".globl " __ASM_STDCALL("NtQueryInformationProcess", 20) "\n" + __ASM_STDCALL("NtQueryInformationProcess", 20) ":\n\t" + "movl %0,%%eax\n\t" + "call *%%fs:0xc0\n\t" + "ret $20" :: "i" (__id_NtQueryInformationProcess) ); +} +#define NtQueryInformationProcess syscall_NtQueryInformationProcess + +#endif /* __WINE_PE_BUILD */ + /******************************************************************* * syscalls */ diff --git a/dlls/ntdll/tests/virtual.c b/dlls/ntdll/tests/virtual.c index a9dec1b5a8a..011d3f1692f 100644 --- a/dlls/ntdll/tests/virtual.c +++ b/dlls/ntdll/tests/virtual.c @@ -2119,13 +2119,13 @@ static void test_syscalls(void) ptr = MapViewOfFile( mapping, FILE_MAP_READ, 0, 0, 0 ); ok( ptr != NULL, "MapViewOfFile failed err %lu\n", GetLastError() ); CloseHandle( mapping ); - CloseHandle( file ); delta = (char *)ptr - (char *)module;
if (memcmp( ptr, module, 0x1000 )) { skip( "modules are not identical (non-PE build?)\n" ); UnmapViewOfFile( ptr ); + CloseHandle( file ); return; } perform_relocations( ptr, delta ); @@ -2152,12 +2152,40 @@ static void test_syscalls(void) } else { -#ifdef __x86_64__ +#ifdef __i386__ + NTSTATUS (WINAPI *pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, void *, ULONG, ULONG *); + PROCESS_BASIC_INFORMATION pbi; + void *exec_mem, *va_ptr; + ULONG size; + BOOL ret; + + exec_mem = VirtualAlloc( NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE ); + ok( !!exec_mem, "got NULL.\n" ); + + /* NtQueryInformationProcess is special. */ + pNtQueryInformationProcess = (void *)GetProcAddress( module, "NtQueryInformationProcess" ); + va_ptr = RtlImageRvaToVa( RtlImageNtHeader(module), module, + (char *)pNtQueryInformationProcess - (char *)module, NULL ); + ok( !!va_ptr, "offset not found %p / %p\n", pNtQueryInformationProcess, module ); + ret = SetFilePointer( file, (char *)va_ptr - (char *)module, NULL, FILE_BEGIN ); + ok( ret, "got %d, err %lu.\n", ret, GetLastError() ); + ret = ReadFile( file, exec_mem, 32, NULL, NULL ); + ok( ret, "got %d, err %lu.\n", ret, GetLastError() ); + pNtQueryInformationProcess = exec_mem; + /* The thunk still works without relocation. */ + status = pNtQueryInformationProcess( GetCurrentProcess(), ProcessBasicInformation, &pbi, sizeof(pbi), &size ); + ok( !status, "got %#lx.\n", status ); + ok( size == sizeof(pbi), "got %lu.\n", size ); + ok( pbi.PebBaseAddress == NtCurrentTeb()->Peb, "got %p, %p.\n", pbi.PebBaseAddress, NtCurrentTeb()->Peb ); + + VirtualFree( exec_mem, 0, MEM_RELEASE ); +#elif defined __x86_64__ ok( 0, "syscall thunk relocated\n" ); #else skip( "syscall thunk relocated\n" ); #endif } + CloseHandle( file ); UnmapViewOfFile( ptr ); }