[WINESYNC] dbghelp: Determine the wine loader name from the target process's architecture.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>

wine commit id a981edf0bc7c828e6b55fdc73b51a2f457043c4a by Zebediah Figura <zfigura@codeweavers.com>
This commit is contained in:
winesync 2020-09-11 13:00:06 +02:00 committed by Jérôme Gardou
parent 3346544802
commit f69be6c561
8 changed files with 112 additions and 88 deletions

View File

@ -71,8 +71,8 @@ __RtlImageRvaToSection(
PVOID
__RtlImageRvaToVa
(const IMAGE_NT_HEADERS* NtHeader,
PVOID BaseAddress,
(const IMAGE_NT_HEADERS* NtHeader,
PVOID BaseAddress,
ULONG Rva,
PIMAGE_SECTION_HEADER *SectionHeader)
{
@ -160,7 +160,7 @@ HANDLE __CreateFileW(
{
char buf[MAX_PATH];
HANDLE res;
WideCharToMultiByte(CP_ACP, 0, lpFileName, -1, buf, MAX_PATH, NULL, NULL);
res = CreateFileA(buf, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
return res;
@ -187,7 +187,7 @@ void* __MapViewOfFile(HANDLE file,DWORD d1,DWORD d2,DWORD d3,SIZE_T s)
free(result);
return NULL;
}
return result;
}
@ -222,15 +222,15 @@ __WideCharToMultiByte(UINT page, DWORD flags, LPCWSTR src, INT srclen,
}
if (srclen < 0) srclen = strlenW(src) + 1;
if(!dstlen)
return srclen;
for(i=0; i<srclen && i<dstlen; i++)
dst[i] = src[i] & 0xFF;
if (used) *used = FALSE;
return i;
}
@ -247,7 +247,7 @@ __MultiByteToWideChar(UINT page, DWORD flags, LPCSTR src, INT srclen,
}
if (srclen < 0) srclen = strlen(src) + 1;
if(!dstlen)
return srclen;
@ -394,3 +394,9 @@ const char *wine_dbgstr_wn( const WCHAR *str, int n )
*dst++ = 0;
return res;
}
BOOL __IsWow64Process(HANDLE Process, BOOL* is_wow64)
{
*is_wow64 = FALSE;
return TRUE;
}

View File

@ -400,7 +400,7 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD
#define INVALID_HANDLE_VALUE (HANDLE)(-1)
#define HeapAlloc __HeapAlloc
#define HeapReAlloc __HeapReAlloc
#define HeapFree(x,y,z) free(z)
#define HeapFree(x,y,z) free(z)
#define GetProcessHeap() 1
#define GetProcessId(x) 8
#define lstrcpynW __lstrcpynW
@ -422,6 +422,8 @@ typedef struct _EXCEPTION_REGISTRATION_RECORD
#define GetCurrentDirectoryW(x, y) 0
#define GetFileSizeEx __GetFileSizeEx
#define ReadProcessMemory(a,b,c,d,e) 0
#define GetCurrentProcess() (HANDLE)1
#define IsWow64Process __IsWow64Process
void* __HeapAlloc(int heap, int flags, size_t size);
void* __HeapReAlloc(int heap, DWORD d2, void *slab, SIZE_T newsize);
@ -432,6 +434,7 @@ void* __MapViewOfFile(HANDLE file,DWORD d1,DWORD d2,DWORD d3,SIZE_T s);
BOOL __UnmapViewOfFile(const void*);
LPSTR __lstrcpynA(LPSTR,LPCSTR,int);
BOOL __GetFileSizeEx(HANDLE,PLARGE_INTEGER);
BOOL WINAPI __IsWow64Process(HANDLE,BOOL*);
#define OPEN_EXISTING 3
#define FILE_MAP_READ SECTION_MAP_READ
typedef struct _LDT_ENTRY {
@ -673,7 +676,7 @@ typedef VOID IMAGEHLP_CONTEXT, *PIMAGEHLP_CONTEXT;
#define SYMFLAG_PUBLIC_CODE 0x00400000
#define UNDNAME_COMPLETE (0x0000)
#define UNDNAME_NAME_ONLY (0x1000)
typedef struct _TI_FINDCHILDREN_PARAMS
typedef struct _TI_FINDCHILDREN_PARAMS
{
ULONG Count;
ULONG Start;
@ -709,7 +712,7 @@ typedef struct _SYMBOL_INFO
ULONG MaxNameLen;
CHAR Name[1];
} SYMBOL_INFO, *PSYMBOL_INFO;
typedef enum
typedef enum
{
SymNone = 0,
SymCoff,
@ -791,7 +794,7 @@ typedef BOOL (CALLBACK *PFIND_EXE_FILE_CALLBACKW)(HANDLE, PCWSTR, PVOID);
#define FindExecutableImageExW __FindExecutableImageExW
HANDLE __FindExecutableImageExW(PCWSTR, PCWSTR, PWSTR, PFIND_EXE_FILE_CALLBACKW, PVOID);
DWORD WINAPI UnDecorateSymbolName(PCSTR, PSTR, DWORD, DWORD);
typedef enum _THREAD_WRITE_FLAGS
typedef enum _THREAD_WRITE_FLAGS
{
ThreadWriteThread = 0x0001,
ThreadWriteStack = 0x0002,
@ -911,7 +914,7 @@ typedef struct _IMAGEHLP_MODULE64
} IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64;
typedef DWORD RVA;
typedef ULONG64 RVA64;
typedef enum _MINIDUMP_TYPE
typedef enum _MINIDUMP_TYPE
{
MiniDumpNormal = 0x0000,
MiniDumpWithDataSegs = 0x0001,
@ -938,7 +941,7 @@ typedef struct _MINIDUMP_THREAD_CALLBACK
ULONG64 StackBase;
ULONG64 StackEnd;
} MINIDUMP_THREAD_CALLBACK, *PMINIDUMP_THREAD_CALLBACK;
typedef struct _MINIDUMP_THREAD_EX_CALLBACK
typedef struct _MINIDUMP_THREAD_EX_CALLBACK
{
ULONG ThreadId;
HANDLE ThreadHandle;
@ -949,7 +952,7 @@ typedef struct _MINIDUMP_THREAD_EX_CALLBACK
ULONG64 BackingStoreBase;
ULONG64 BackingStoreEnd;
} MINIDUMP_THREAD_EX_CALLBACK, *PMINIDUMP_THREAD_EX_CALLBACK;
typedef struct _MINIDUMP_MODULE_CALLBACK
typedef struct _MINIDUMP_MODULE_CALLBACK
{
PWCHAR FullPath;
ULONG64 BaseOfImage;
@ -966,16 +969,16 @@ typedef struct _MINIDUMP_INCLUDE_THREAD_CALLBACK
{
ULONG ThreadId;
} MINIDUMP_INCLUDE_THREAD_CALLBACK, *PMINIDUMP_INCLUDE_THREAD_CALLBACK;
typedef struct _MINIDUMP_INCLUDE_MODULE_CALLBACK
typedef struct _MINIDUMP_INCLUDE_MODULE_CALLBACK
{
ULONG64 BaseOfImage;
} MINIDUMP_INCLUDE_MODULE_CALLBACK, *PMINIDUMP_INCLUDE_MODULE_CALLBACK;
typedef struct _MINIDUMP_CALLBACK_INPUT
typedef struct _MINIDUMP_CALLBACK_INPUT
{
ULONG ProcessId;
HANDLE ProcessHandle;
ULONG CallbackType;
union
union
{
MINIDUMP_THREAD_CALLBACK Thread;
MINIDUMP_THREAD_EX_CALLBACK ThreadEx;
@ -986,7 +989,7 @@ typedef struct _MINIDUMP_CALLBACK_INPUT
} MINIDUMP_CALLBACK_INPUT, *PMINIDUMP_CALLBACK_INPUT;
typedef struct _MINIDUMP_CALLBACK_OUTPUT
{
union
union
{
ULONG ModuleWriteFlags;
ULONG ThreadWriteFlags;
@ -998,7 +1001,7 @@ typedef struct _MINIDUMP_CALLBACK_OUTPUT
} DUMMYUNIONNAME;
} MINIDUMP_CALLBACK_OUTPUT, *PMINIDUMP_CALLBACK_OUTPUT;
typedef BOOL (WINAPI* MINIDUMP_CALLBACK_ROUTINE)(PVOID, const PMINIDUMP_CALLBACK_INPUT, PMINIDUMP_CALLBACK_OUTPUT);
typedef struct _MINIDUMP_CALLBACK_INFORMATION
typedef struct _MINIDUMP_CALLBACK_INFORMATION
{
MINIDUMP_CALLBACK_ROUTINE CallbackRoutine;
void* CallbackParam;
@ -1060,7 +1063,7 @@ typedef struct _STACKFRAME64
DWORD64 Reserved[3];
KDHELP64 KdHelp;
} STACKFRAME64, *LPSTACKFRAME64;
typedef enum _IMAGEHLP_SYMBOL_TYPE_INFO
typedef enum _IMAGEHLP_SYMBOL_TYPE_INFO
{
TI_GET_SYMTAG,
TI_GET_SYMNAME,
@ -1245,13 +1248,13 @@ enum SymTagEnum
SymTagPointerType,
SymTagArrayType,
SymTagBaseType,
SymTagTypedef,
SymTagTypedef,
SymTagBaseClass,
SymTagFriend,
SymTagFunctionArgType,
SymTagFuncDebugStart,
SymTagFunctionArgType,
SymTagFuncDebugStart,
SymTagFuncDebugEnd,
SymTagUsingNamespace,
SymTagUsingNamespace,
SymTagVTableShape,
SymTagVTable,
SymTagCustom,
@ -1867,7 +1870,7 @@ typedef enum
THUNK_ORDINAL_ADJUSTOR,
THUNK_ORDINAL_VCALL,
THUNK_ORDINAL_PCODE,
THUNK_ORDINAL_LOAD
THUNK_ORDINAL_LOAD
} THUNK_ORDINAL;
typedef enum CV_call_e

View File

@ -309,6 +309,7 @@ static BOOL check_live_target(struct process* pcs)
BOOL WINAPI SymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeProcess)
{
struct process* pcs;
BOOL wow64, child_wow64;
TRACE("(%p %s %u)\n", hProcess, debugstr_w(UserSearchPath), fInvadeProcess);
@ -326,6 +327,12 @@ BOOL WINAPI SymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeP
pcs->handle = hProcess;
IsWow64Process(GetCurrentProcess(), &wow64);
if (!IsWow64Process(hProcess, &child_wow64))
return FALSE;
pcs->is_64bit = (sizeof(void *) == 8 || wow64) && !child_wow64;
if (UserSearchPath)
{
pcs->search_path = lstrcpyW(HeapAlloc(GetProcessHeap(), 0,

View File

@ -415,7 +415,7 @@ struct module
struct wine_rb_tree sources_offsets_tree;
};
struct process
struct process
{
struct process* next;
HANDLE handle;
@ -433,6 +433,8 @@ struct process
unsigned buffer_size;
void* buffer;
BOOL is_64bit;
};
struct line_info
@ -639,11 +641,13 @@ extern void module_reset_debug_info(struct module* module) DECLSPEC_HIDD
extern BOOL module_remove(struct process* pcs,
struct module* module) DECLSPEC_HIDDEN;
extern void module_set_module(struct module* module, const WCHAR* name) DECLSPEC_HIDDEN;
extern const WCHAR *get_wine_loader_name(void) DECLSPEC_HIDDEN;
#ifndef __REACTOS__
extern WCHAR * get_wine_loader_name(struct process *pcs) DECLSPEC_HIDDEN;
#endif
/* msc.c */
extern BOOL pe_load_debug_directory(const struct process* pcs,
struct module* module,
struct module* module,
const BYTE* mapping,
const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg) DECLSPEC_HIDDEN;
@ -657,7 +661,7 @@ extern BOOL pdb_virtual_unwind(struct cpu_stack_walk* csw, DWORD_PTR ip,
/* path.c */
extern BOOL path_find_symbol_file(const struct process* pcs, const struct module* module,
PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2,
PCSTR full_path, const GUID* guid, DWORD dw1, DWORD dw2,
PSTR buffer, BOOL* is_unmatched) DECLSPEC_HIDDEN;
/* pe_module.c */
@ -720,14 +724,14 @@ extern struct symt_compiland*
symt_new_compiland(struct module* module, unsigned long address,
unsigned src_idx) DECLSPEC_HIDDEN;
extern struct symt_public*
symt_new_public(struct module* module,
struct symt_compiland* parent,
symt_new_public(struct module* module,
struct symt_compiland* parent,
const char* typename,
BOOL is_function,
unsigned long address,
unsigned size) DECLSPEC_HIDDEN;
extern struct symt_data*
symt_new_global_variable(struct module* module,
symt_new_global_variable(struct module* module,
struct symt_compiland* parent,
const char* name, unsigned is_static,
struct location loc, unsigned long size,
@ -738,31 +742,31 @@ extern struct symt_function*
const char* name,
unsigned long addr, unsigned long size,
struct symt* type) DECLSPEC_HIDDEN;
extern BOOL symt_normalize_function(struct module* module,
extern BOOL symt_normalize_function(struct module* module,
const struct symt_function* func) DECLSPEC_HIDDEN;
extern void symt_add_func_line(struct module* module,
struct symt_function* func,
unsigned source_idx, int line_num,
struct symt_function* func,
unsigned source_idx, int line_num,
unsigned long offset) DECLSPEC_HIDDEN;
extern struct symt_data*
symt_add_func_local(struct module* module,
struct symt_function* func,
symt_add_func_local(struct module* module,
struct symt_function* func,
enum DataKind dt, const struct location* loc,
struct symt_block* block,
struct symt* type, const char* name) DECLSPEC_HIDDEN;
extern struct symt_block*
symt_open_func_block(struct module* module,
symt_open_func_block(struct module* module,
struct symt_function* func,
struct symt_block* block,
struct symt_block* block,
unsigned pc, unsigned len) DECLSPEC_HIDDEN;
extern struct symt_block*
symt_close_func_block(struct module* module,
symt_close_func_block(struct module* module,
const struct symt_function* func,
struct symt_block* block, unsigned pc) DECLSPEC_HIDDEN;
extern struct symt_hierarchy_point*
symt_add_function_point(struct module* module,
symt_add_function_point(struct module* module,
struct symt_function* func,
enum SymTagEnum point,
enum SymTagEnum point,
const struct location* loc,
const char* name) DECLSPEC_HIDDEN;
extern BOOL symt_fill_func_line_info(const struct module* module,
@ -770,7 +774,7 @@ extern BOOL symt_fill_func_line_info(const struct module* module,
DWORD64 addr, IMAGEHLP_LINE64* line) DECLSPEC_HIDDEN;
extern BOOL symt_get_func_line_next(const struct module* module, PIMAGEHLP_LINE64 line) DECLSPEC_HIDDEN;
extern struct symt_thunk*
symt_new_thunk(struct module* module,
symt_new_thunk(struct module* module,
struct symt_compiland* parent,
const char* name, THUNK_ORDINAL ord,
unsigned long addr, unsigned long size) DECLSPEC_HIDDEN;
@ -791,38 +795,38 @@ extern void symt_init_basic(struct module* module) DECLSPEC_HIDDEN;
extern BOOL symt_get_info(struct module* module, const struct symt* type,
IMAGEHLP_SYMBOL_TYPE_INFO req, void* pInfo) DECLSPEC_HIDDEN;
extern struct symt_basic*
symt_new_basic(struct module* module, enum BasicType,
symt_new_basic(struct module* module, enum BasicType,
const char* typename, unsigned size) DECLSPEC_HIDDEN;
extern struct symt_udt*
symt_new_udt(struct module* module, const char* typename,
unsigned size, enum UdtKind kind) DECLSPEC_HIDDEN;
extern BOOL symt_set_udt_size(struct module* module,
struct symt_udt* type, unsigned size) DECLSPEC_HIDDEN;
extern BOOL symt_add_udt_element(struct module* module,
struct symt_udt* udt_type,
extern BOOL symt_add_udt_element(struct module* module,
struct symt_udt* udt_type,
const char* name,
struct symt* elt_type, unsigned offset,
struct symt* elt_type, unsigned offset,
unsigned size) DECLSPEC_HIDDEN;
extern struct symt_enum*
symt_new_enum(struct module* module, const char* typename,
struct symt* basetype) DECLSPEC_HIDDEN;
extern BOOL symt_add_enum_element(struct module* module,
struct symt_enum* enum_type,
extern BOOL symt_add_enum_element(struct module* module,
struct symt_enum* enum_type,
const char* name, int value) DECLSPEC_HIDDEN;
extern struct symt_array*
symt_new_array(struct module* module, int min, int max,
symt_new_array(struct module* module, int min, int max,
struct symt* base, struct symt* index) DECLSPEC_HIDDEN;
extern struct symt_function_signature*
symt_new_function_signature(struct module* module,
symt_new_function_signature(struct module* module,
struct symt* ret_type,
enum CV_call_e call_conv) DECLSPEC_HIDDEN;
extern BOOL symt_add_function_signature_parameter(struct module* module,
struct symt_function_signature* sig,
struct symt* param) DECLSPEC_HIDDEN;
extern struct symt_pointer*
symt_new_pointer(struct module* module,
symt_new_pointer(struct module* module,
struct symt* ref_type,
unsigned long size) DECLSPEC_HIDDEN;
extern struct symt_typedef*
symt_new_typedef(struct module* module, struct symt* ref,
symt_new_typedef(struct module* module, struct symt* ref,
const char* name) DECLSPEC_HIDDEN;

View File

@ -50,6 +50,7 @@
#include "wine/library.h"
#include "wine/debug.h"
#include "wine/heap.h"
#ifdef __ELF__
@ -1568,13 +1569,17 @@ static BOOL elf_enum_modules_internal(const struct process* pcs,
*/
static BOOL elf_search_loader(struct process* pcs, struct elf_info* elf_info)
{
WCHAR *loader = get_wine_loader_name(pcs);
PROCESS_BASIC_INFORMATION pbi;
ULONG_PTR base = 0;
BOOL ret;
if (!NtQueryInformationProcess( pcs->handle, ProcessBasicInformation, &pbi, sizeof(pbi), NULL ))
ReadProcessMemory( pcs->handle, &pbi.PebBaseAddress->Reserved[0], &base, sizeof(base), NULL );
return elf_search_and_load_file(pcs, get_wine_loader_name(), base, 0, elf_info);
ret = elf_search_and_load_file(pcs, loader, base, 0, elf_info);
heap_free(loader);
return ret;
}
/******************************************************************

View File

@ -1703,6 +1703,7 @@ BOOL macho_synchronize_module_list(struct process* pcs)
*/
static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_info)
{
WCHAR *loader = get_wine_loader_name(pcs);
BOOL ret = FALSE;
ULONG_PTR dyld_image_info_address;
struct dyld_all_image_infos image_infos;
@ -1757,7 +1758,8 @@ static BOOL macho_search_loader(struct process* pcs, struct macho_info* macho_in
}
if (!ret)
ret = macho_search_and_load_file(pcs, get_wine_loader_name(), 0, macho_info);
ret = macho_search_and_load_file(pcs, loader, 0, macho_info);
heap_free(loader);
return ret;
}

View File

@ -149,44 +149,41 @@ void module_set_module(struct module* module, const WCHAR* name)
module_fill_module(name, module->modulename, sizeof(module->modulename) / sizeof(module->modulename[0]));
}
const WCHAR *get_wine_loader_name(void)
#ifndef __REACTOS__
/* Returned string must be freed by caller */
WCHAR *get_wine_loader_name(struct process *pcs)
{
static const BOOL is_win64 = sizeof(void *) > sizeof(int); /* FIXME: should depend on target process */
static const WCHAR wineW[] = {'w','i','n','e',0};
static const WCHAR suffixW[] = {'6','4',0};
static const WCHAR *loader;
WCHAR *buffer, *p;
const char *env;
if (!loader)
/* All binaries are loaded with WINELOADER (if run from tree) or by the
* main executable
*/
if ((env = getenv("WINELOADER")))
{
WCHAR *p, *buffer;
const char *ptr;
/* All binaries are loaded with WINELOADER (if run from tree) or by the
* main executable
*/
if ((ptr = getenv("WINELOADER")))
{
DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, NULL, 0 );
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
MultiByteToWideChar( CP_UNIXCP, 0, ptr, -1, buffer, len );
}
else
{
buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(wineW) + 2 * sizeof(WCHAR) );
strcpyW( buffer, wineW );
}
p = buffer + strlenW( buffer ) - strlenW( suffixW );
if (p > buffer && !strcmpW( p, suffixW ))
{
if (!is_win64) *p = 0;
}
else if (is_win64) strcatW( buffer, suffixW );
TRACE( "returning %s\n", debugstr_w(buffer) );
loader = buffer;
DWORD len = 2 + MultiByteToWideChar( CP_UNIXCP, 0, env, -1, NULL, 0 );
buffer = heap_alloc( len * sizeof(WCHAR) );
MultiByteToWideChar( CP_UNIXCP, 0, env, -1, buffer, len );
}
return loader;
else
{
buffer = heap_alloc( sizeof(wineW) + 2 * sizeof(WCHAR) );
strcpyW( buffer, wineW );
}
p = buffer + strlenW( buffer ) - strlenW( suffixW );
if (p > buffer && !strcmpW( p, suffixW ))
*p = 0;
if (pcs->is_64bit)
strcatW(buffer, suffixW);
TRACE( "returning %s\n", debugstr_w(buffer) );
return buffer;
}
#endif
static const char* get_module_type(enum module_type type, BOOL virtual)
{

View File

@ -3,4 +3,4 @@ directories:
files:
include/dbghelp.h: sdk/include/psdk/dbghelp.h
tags:
wine: 9b973eee9e06a3dca7a6c5739741446bf46e27f5
wine: a981edf0bc7c828e6b55fdc73b51a2f457043c4a