ReactOS  0.4.15-dev-1148-g8a4273b
stack.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "dbghelp_private.h"
#include "wine/debug.h"
Include dependency graph for stack.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dbghelp)
 
static DWORD64 WINAPI addr_to_linear (HANDLE hProcess, HANDLE hThread, ADDRESS64 *addr)
 
static BOOL CALLBACK read_mem (HANDLE hProcess, DWORD addr, void *buffer, DWORD size, LPDWORD nread)
 
static BOOL CALLBACK read_mem64 (HANDLE hProcess, DWORD64 addr, void *buffer, DWORD size, LPDWORD nread)
 
static void addr_32to64 (const ADDRESS *addr32, ADDRESS64 *addr64)
 
static void addr_64to32 (const ADDRESS64 *addr64, ADDRESS *addr32)
 
BOOL sw_read_mem (struct cpu_stack_walk *csw, DWORD64 addr, void *ptr, DWORD sz)
 
DWORD64 sw_xlat_addr (struct cpu_stack_walk *csw, ADDRESS64 *addr)
 
voidsw_table_access (struct cpu_stack_walk *csw, DWORD64 addr)
 
DWORD64 sw_module_base (struct cpu_stack_walk *csw, DWORD64 addr)
 
BOOL WINAPI StackWalk (DWORD MachineType, HANDLE hProcess, HANDLE hThread, LPSTACKFRAME frame32, PVOID ctx, PREAD_PROCESS_MEMORY_ROUTINE f_read_mem, PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr)
 
BOOL WINAPI StackWalk64 (DWORD MachineType, HANDLE hProcess, HANDLE hThread, LPSTACKFRAME64 frame, PVOID ctx, PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem, PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr)
 
BOOL WINAPI SymRegisterFunctionEntryCallback (HANDLE hProc, PSYMBOL_FUNCENTRY_CALLBACK cb, PVOID user)
 
BOOL WINAPI SymRegisterFunctionEntryCallback64 (HANDLE hProc, PSYMBOL_FUNCENTRY_CALLBACK64 cb, ULONG64 user)
 

Function Documentation

◆ addr_32to64()

static void addr_32to64 ( const ADDRESS addr32,
ADDRESS64 addr64 
)
inlinestatic

Definition at line 81 of file stack.c.

82 {
83  addr64->Offset = (ULONG64)addr32->Offset;
84  addr64->Segment = addr32->Segment;
85  addr64->Mode = addr32->Mode;
86 }
ADDRESS_MODE Mode
Definition: compat.h:945
WORD Segment
Definition: compat.h:923
DWORD64 Offset
Definition: compat.h:922
DWORD Offset
Definition: compat.h:943
unsigned __int64 ULONG64
Definition: imports.h:198
WORD Segment
Definition: compat.h:944
ADDRESS_MODE Mode
Definition: compat.h:924

Referenced by StackWalk().

◆ addr_64to32()

static void addr_64to32 ( const ADDRESS64 addr64,
ADDRESS addr32 
)
inlinestatic

Definition at line 88 of file stack.c.

89 {
90  addr32->Offset = (ULONG)addr64->Offset;
91  addr32->Segment = addr64->Segment;
92  addr32->Mode = addr64->Mode;
93 }
ADDRESS_MODE Mode
Definition: compat.h:945
WORD Segment
Definition: compat.h:923
DWORD64 Offset
Definition: compat.h:922
DWORD Offset
Definition: compat.h:943
WORD Segment
Definition: compat.h:944
unsigned int ULONG
Definition: retypes.h:1
ADDRESS_MODE Mode
Definition: compat.h:924

Referenced by StackWalk(), and sw_xlat_addr().

◆ addr_to_linear()

static DWORD64 WINAPI addr_to_linear ( HANDLE  hProcess,
HANDLE  hThread,
ADDRESS64 addr 
)
static

Definition at line 34 of file stack.c.

35 {
36  LDT_ENTRY le;
37 
38  switch (addr->Mode)
39  {
40  case AddrMode1616:
41  if (GetThreadSelectorEntry(hThread, addr->Segment, &le))
42  return (le.HighWord.Bits.BaseHi << 24) +
43  (le.HighWord.Bits.BaseMid << 16) + le.BaseLow + LOWORD(addr->Offset);
44  break;
45  case AddrMode1632:
46  if (GetThreadSelectorEntry(hThread, addr->Segment, &le))
47  return (le.HighWord.Bits.BaseHi << 24) +
48  (le.HighWord.Bits.BaseMid << 16) + le.BaseLow + addr->Offset;
49  break;
50  case AddrModeReal:
51  return (DWORD)(LOWORD(addr->Segment) << 4) + addr->Offset;
52  case AddrModeFlat:
53  return addr->Offset;
54  default:
55  FIXME("Unsupported (yet) mode (%x)\n", addr->Mode);
56  return 0;
57  }
58  FIXME("Failed to linearize address %04x:%s (mode %x)\n",
59  addr->Segment, wine_dbgstr_longlong(addr->Offset), addr->Mode);
60  return 0;
61 }
return
Definition: dirsup.c:529
WORD BaseLow
Definition: compat.h:527
#define FIXME(fmt,...)
Definition: debug.h:111
struct _LDT_ENTRY::@349::@351 Bits
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum const GLvoid * addr
Definition: glext.h:9621
union _LDT_ENTRY::@349 HighWord
Definition: compat.h:525
BOOL WINAPI GetThreadSelectorEntry(IN HANDLE hThread, IN DWORD dwSelector, OUT LPLDT_ENTRY lpSelectorEntry)
Definition: thread.c:829
HANDLE hThread
Definition: wizard.c:27
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define LOWORD(l)
Definition: pedump.c:82

Referenced by StackWalk64(), and sw_xlat_addr().

◆ read_mem()

static BOOL CALLBACK read_mem ( HANDLE  hProcess,
DWORD  addr,
void buffer,
DWORD  size,
LPDWORD  nread 
)
static

Definition at line 63 of file stack.c.

65 {
66  SIZE_T r;
67  if (!ReadProcessMemory(hProcess, (void*)(DWORD_PTR)addr, buffer, size, &r)) return FALSE;
68  if (nread) *nread = r;
69  return TRUE;
70 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:506
#define FALSE
Definition: types.h:117
GLsizeiptr size
Definition: glext.h:5919
GLenum const GLvoid * addr
Definition: glext.h:9621
uint32_t DWORD_PTR
Definition: typedefs.h:65
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by StackWalk().

◆ read_mem64()

static BOOL CALLBACK read_mem64 ( HANDLE  hProcess,
DWORD64  addr,
void buffer,
DWORD  size,
LPDWORD  nread 
)
static

Definition at line 72 of file stack.c.

74 {
75  SIZE_T r;
76  if (!ReadProcessMemory(hProcess, (void*)(DWORD_PTR)addr, buffer, size, &r)) return FALSE;
77  if (nread) *nread = r;
78  return TRUE;
79 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint buffer
Definition: glext.h:5915
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
#define ReadProcessMemory(a, b, c, d, e)
Definition: compat.h:506
#define FALSE
Definition: types.h:117
GLsizeiptr size
Definition: glext.h:5919
GLenum const GLvoid * addr
Definition: glext.h:9621
uint32_t DWORD_PTR
Definition: typedefs.h:65
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by StackWalk64().

◆ StackWalk()

BOOL WINAPI StackWalk ( DWORD  MachineType,
HANDLE  hProcess,
HANDLE  hThread,
LPSTACKFRAME  frame32,
PVOID  ctx,
PREAD_PROCESS_MEMORY_ROUTINE  f_read_mem,
PFUNCTION_TABLE_ACCESS_ROUTINE  FunctionTableAccessRoutine,
PGET_MODULE_BASE_ROUTINE  GetModuleBaseRoutine,
PTRANSLATE_ADDRESS_ROUTINE  f_xlat_adr 
)

Definition at line 138 of file stack.c.

144 {
145  struct cpu_stack_walk csw;
146  STACKFRAME64 frame64;
147  BOOL ret;
148  struct cpu* cpu;
149 
150  TRACE("(%d, %p, %p, %p, %p, %p, %p, %p, %p)\n",
151  MachineType, hProcess, hThread, frame32, ctx,
152  f_read_mem, FunctionTableAccessRoutine,
153  GetModuleBaseRoutine, f_xlat_adr);
154 
155  if (!(cpu = cpu_find(MachineType)))
156  {
158  return FALSE;
159  }
160 
161  addr_32to64(&frame32->AddrPC, &frame64.AddrPC);
162  addr_32to64(&frame32->AddrReturn, &frame64.AddrReturn);
163  addr_32to64(&frame32->AddrFrame, &frame64.AddrFrame);
164  addr_32to64(&frame32->AddrStack, &frame64.AddrStack);
165  addr_32to64(&frame32->AddrBStore, &frame64.AddrBStore);
166  frame64.FuncTableEntry = frame32->FuncTableEntry; /* FIXME */
167  frame64.Far = frame32->Far;
168  frame64.Virtual = frame32->Virtual;
169  frame64.Reserved[0] = frame32->Reserved[0];
170  frame64.Reserved[1] = frame32->Reserved[1];
171  frame64.Reserved[2] = frame32->Reserved[2];
172  /* we don't handle KdHelp */
173 
174  csw.hProcess = hProcess;
175  csw.hThread = hThread;
176  csw.is32 = TRUE;
177  csw.cpu = cpu;
178  /* sigh... MS isn't even consistent in the func prototypes */
179  csw.u.s32.f_read_mem = (f_read_mem) ? f_read_mem : read_mem;
180  csw.u.s32.f_xlat_adr = f_xlat_adr;
181  csw.u.s32.f_tabl_acs = (FunctionTableAccessRoutine) ? FunctionTableAccessRoutine : SymFunctionTableAccess;
182  csw.u.s32.f_modl_bas = (GetModuleBaseRoutine) ? GetModuleBaseRoutine : SymGetModuleBase;
183 
184  if ((ret = cpu->stack_walk(&csw, &frame64, ctx)))
185  {
186  addr_64to32(&frame64.AddrPC, &frame32->AddrPC);
187  addr_64to32(&frame64.AddrReturn, &frame32->AddrReturn);
188  addr_64to32(&frame64.AddrFrame, &frame32->AddrFrame);
189  addr_64to32(&frame64.AddrStack, &frame32->AddrStack);
190  addr_64to32(&frame64.AddrBStore, &frame32->AddrBStore);
191  frame32->FuncTableEntry = frame64.FuncTableEntry; /* FIXME */
192  frame32->Params[0] = frame64.Params[0];
193  frame32->Params[1] = frame64.Params[1];
194  frame32->Params[2] = frame64.Params[2];
195  frame32->Params[3] = frame64.Params[3];
196  frame32->Far = frame64.Far;
197  frame32->Virtual = frame64.Virtual;
198  frame32->Reserved[0] = frame64.Reserved[0];
199  frame32->Reserved[1] = frame64.Reserved[1];
200  frame32->Reserved[2] = frame64.Reserved[2];
201  }
202 
203  return ret;
204 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
DWORD Params[4]
Definition: dbghelp.h:2188
PVOID FuncTableEntry
Definition: dbghelp.h:2187
PVOID WINAPI SymFunctionTableAccess(HANDLE, DWORD)
Definition: module.c:1359
#define TRUE
Definition: types.h:120
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
ADDRESS AddrPC
Definition: dbghelp.h:2183
static void addr_64to32(const ADDRESS64 *addr64, ADDRESS *addr32)
Definition: stack.c:88
struct cpu * cpu_find(DWORD machine)
Definition: dbghelp.c:183
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL(* stack_walk)(struct cpu_stack_walk *csw, STACKFRAME64 *frame, union ctx *ctx)
#define TRACE(s)
Definition: solgame.cpp:4
ADDRESS AddrBStore
Definition: dbghelp.h:2193
#define SetLastError(x)
Definition: compat.h:500
int ret
static void addr_32to64(const ADDRESS *addr32, ADDRESS64 *addr64)
Definition: stack.c:81
ADDRESS AddrReturn
Definition: dbghelp.h:2184
static BOOL CALLBACK read_mem(HANDLE hProcess, DWORD addr, void *buffer, DWORD size, LPDWORD nread)
Definition: stack.c:63
DWORD Reserved[3]
Definition: dbghelp.h:2191
HANDLE hThread
Definition: wizard.c:27
ADDRESS AddrFrame
Definition: dbghelp.h:2185
BOOL Virtual
Definition: dbghelp.h:2190
DWORD WINAPI SymGetModuleBase(HANDLE hProcess, DWORD dwAddr)
Definition: module.c:1298
ADDRESS AddrStack
Definition: dbghelp.h:2186
BOOL Far
Definition: dbghelp.h:2189

◆ StackWalk64()

BOOL WINAPI StackWalk64 ( DWORD  MachineType,
HANDLE  hProcess,
HANDLE  hThread,
LPSTACKFRAME64  frame,
PVOID  ctx,
PREAD_PROCESS_MEMORY_ROUTINE64  f_read_mem,
PFUNCTION_TABLE_ACCESS_ROUTINE64  FunctionTableAccessRoutine,
PGET_MODULE_BASE_ROUTINE64  GetModuleBaseRoutine,
PTRANSLATE_ADDRESS_ROUTINE64  f_xlat_adr 
)

Definition at line 210 of file stack.c.

216 {
217  struct cpu_stack_walk csw;
218  struct cpu* cpu;
219 
220  TRACE("(%d, %p, %p, %p, %p, %p, %p, %p, %p)\n",
221  MachineType, hProcess, hThread, frame, ctx,
222  f_read_mem, FunctionTableAccessRoutine,
223  GetModuleBaseRoutine, f_xlat_adr);
224 
225  if (!(cpu = cpu_find(MachineType)))
226  {
228  return FALSE;
229  }
230 
231  csw.hProcess = hProcess;
232  csw.hThread = hThread;
233  csw.is32 = FALSE;
234  csw.cpu = cpu;
235  /* sigh... MS isn't even consistent in the func prototypes */
236  csw.u.s64.f_read_mem = (f_read_mem) ? f_read_mem : read_mem64;
237  csw.u.s64.f_xlat_adr = (f_xlat_adr) ? f_xlat_adr : addr_to_linear;
238  csw.u.s64.f_tabl_acs = (FunctionTableAccessRoutine) ? FunctionTableAccessRoutine : SymFunctionTableAccess64;
239  csw.u.s64.f_modl_bas = (GetModuleBaseRoutine) ? GetModuleBaseRoutine : SymGetModuleBase64;
240 
241  if (!cpu->stack_walk(&csw, frame, ctx)) return FALSE;
242 
243  /* we don't handle KdHelp */
244 
245  return TRUE;
246 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
static DWORD64 WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS64 *addr)
Definition: stack.c:34
static BOOL CALLBACK read_mem64(HANDLE hProcess, DWORD64 addr, void *buffer, DWORD size, LPDWORD nread)
Definition: stack.c:72
#define TRUE
Definition: types.h:120
PVOID WINAPI SymFunctionTableAccess64(HANDLE, DWORD64)
Definition: module.c:1367
_In_ BOOL _In_ HANDLE hProcess
Definition: mapping.h:70
struct cpu * cpu_find(DWORD machine)
Definition: dbghelp.c:183
#define FALSE
Definition: types.h:117
BOOL(* stack_walk)(struct cpu_stack_walk *csw, STACKFRAME64 *frame, union ctx *ctx)
#define TRACE(s)
Definition: solgame.cpp:4
#define SetLastError(x)
Definition: compat.h:500
DWORD64 WINAPI SymGetModuleBase64(HANDLE, DWORD64)
Definition: module.c:1309
HANDLE hThread
Definition: wizard.c:27

Referenced by PrintStackBacktrace().

◆ sw_module_base()

DWORD64 sw_module_base ( struct cpu_stack_walk csw,
DWORD64  addr 
)

Definition at line 127 of file stack.c.

128 {
129  if (csw->is32)
130  return csw->u.s32.f_modl_bas(csw->hProcess, addr);
131  else
132  return csw->u.s64.f_modl_bas(csw->hProcess, addr);
133 }
struct cpu_stack_walk::@367::@369 s64
struct cpu_stack_walk::@367::@368 s32
GLenum const GLvoid * addr
Definition: glext.h:9621
union cpu_stack_walk::@367 u

Referenced by i386_stack_walk().

◆ sw_read_mem()

BOOL sw_read_mem ( struct cpu_stack_walk csw,
DWORD64  addr,
void ptr,
DWORD  sz 
)

Definition at line 95 of file stack.c.

96 {
97  DWORD bytes_read = 0;
98  if (csw->is32)
99  return csw->u.s32.f_read_mem(csw->hProcess, addr, ptr, sz, &bytes_read);
100  else
101  return csw->u.s64.f_read_mem(csw->hProcess, addr, ptr, sz, &bytes_read);
102 }
struct cpu_stack_walk::@367::@369 s64
struct cpu_stack_walk::@367::@368 s32
static PVOID ptr
Definition: dispmode.c:27
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum const GLvoid * addr
Definition: glext.h:9621
union cpu_stack_walk::@367 u

Referenced by apply_frame_state(), eval_expression(), fetch_next_frame32(), i386_stack_walk(), pev_deref(), and set_context_reg().

◆ sw_table_access()

void* sw_table_access ( struct cpu_stack_walk csw,
DWORD64  addr 
)

Definition at line 119 of file stack.c.

120 {
121  if (csw->is32)
122  return csw->u.s32.f_tabl_acs(csw->hProcess, addr);
123  else
124  return csw->u.s64.f_tabl_acs(csw->hProcess, addr);
125 }
struct cpu_stack_walk::@367::@369 s64
struct cpu_stack_walk::@367::@368 s32
GLenum const GLvoid * addr
Definition: glext.h:9621
union cpu_stack_walk::@367 u

Referenced by i386_stack_walk().

◆ sw_xlat_addr()

DWORD64 sw_xlat_addr ( struct cpu_stack_walk csw,
ADDRESS64 addr 
)

Definition at line 104 of file stack.c.

105 {
106  if (addr->Mode == AddrModeFlat) return addr->Offset;
107  if (csw->is32)
108  {
109  ADDRESS addr32;
110 
111  addr_64to32(addr, &addr32);
112  return csw->u.s32.f_xlat_adr(csw->hProcess, csw->hThread, &addr32);
113  }
114  else if (csw->u.s64.f_xlat_adr)
115  return csw->u.s64.f_xlat_adr(csw->hProcess, csw->hThread, addr);
116  return addr_to_linear(csw->hProcess, csw->hThread, addr);
117 }
static DWORD64 WINAPI addr_to_linear(HANDLE hProcess, HANDLE hThread, ADDRESS64 *addr)
Definition: stack.c:34
static void addr_64to32(const ADDRESS64 *addr64, ADDRESS *addr32)
Definition: stack.c:88
struct cpu_stack_walk::@367::@369 s64
struct cpu_stack_walk::@367::@368 s32
GLenum const GLvoid * addr
Definition: glext.h:9621
union cpu_stack_walk::@367 u

Referenced by i386_stack_walk().

◆ SymRegisterFunctionEntryCallback()

BOOL WINAPI SymRegisterFunctionEntryCallback ( HANDLE  hProc,
PSYMBOL_FUNCENTRY_CALLBACK  cb,
PVOID  user 
)

Definition at line 253 of file stack.c.

255 {
256  FIXME("(%p %p %p): stub!\n", hProc, cb, user);
258  return FALSE;
259 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
#define SetLastError(x)
Definition: compat.h:500
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ SymRegisterFunctionEntryCallback64()

BOOL WINAPI SymRegisterFunctionEntryCallback64 ( HANDLE  hProc,
PSYMBOL_FUNCENTRY_CALLBACK64  cb,
ULONG64  user 
)

Definition at line 266 of file stack.c.

269 {
270  FIXME("(%p %p %s): stub!\n", hProc, cb, wine_dbgstr_longlong(user));
272  return FALSE;
273 }
#define FALSE
Definition: types.h:117
#define FIXME(fmt,...)
Definition: debug.h:111
#define SetLastError(x)
Definition: compat.h:500
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
void user(int argc, const char *argv[])
Definition: cmds.c:1350

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dbghelp  )