stack.c 21.7 KB
Newer Older
1 2 3 4 5
/*
 * Stack walking
 *
 * Copyright 1995 Alexandre Julliard
 * Copyright 1996 Eric Youngdale
6
 * Copyright 1999 Ove Kåven
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * Copyright 2004 Eric Pouech
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 23 24 25 26 27 28 29
 */

#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

30 31
#include "ntstatus.h"
#define WIN32_NO_STATUS
32 33
#include "dbghelp_private.h"
#include "winternl.h"
34
#include "wine/winbase16.h"
35 36 37 38 39 40 41 42 43 44 45 46
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);

enum st_mode {stm_start, stm_32bit, stm_16bit, stm_done};

static const char* wine_dbgstr_addr(const ADDRESS* addr)
{
    if (!addr) return "(null)";
    switch (addr->Mode)
    {
    case AddrModeFlat:
47
        return wine_dbg_sprintf("flat<%08x>", addr->Offset);
48
    case AddrMode1616:
49
        return wine_dbg_sprintf("1616<%04x:%04x>", addr->Segment, addr->Offset);
50
    case AddrMode1632:
51
        return wine_dbg_sprintf("1632<%04x:%08x>", addr->Segment, addr->Offset);
52
    case AddrModeReal:
53
        return wine_dbg_sprintf("real<%04x:%04x>", addr->Segment, addr->Offset);
54 55 56 57 58
    default:
        return "unknown";
    }
}

59 60 61
static BOOL CALLBACK read_mem(HANDLE hProcess, DWORD addr, void* buffer,
                              DWORD size, LPDWORD nread)
{
62 63
    SIZE_T      r;
    if (!ReadProcessMemory(hProcess, (void*)addr, buffer, size, &r)) return FALSE;
64
    if (nread) *nread = r;
65
    return TRUE;
66 67
}

68 69 70
static BOOL CALLBACK read_mem64(HANDLE hProcess, DWORD64 addr, void* buffer,
                                DWORD size, LPDWORD nread)
{
71 72
    SIZE_T      r;
    if (!ReadProcessMemory(hProcess, (void*)(DWORD_PTR)addr, buffer, size, &r)) return FALSE;
73
    if (nread) *nread = r;
74
    return TRUE;
75 76
}

77 78 79 80 81 82 83 84 85
/* indexes in Reserved array */
#define __CurrentMode     0
#define __CurrentSwitch   1
#define __NextSwitch      2

#define curr_mode   (frame->Reserved[__CurrentMode])
#define curr_switch (frame->Reserved[__CurrentSwitch])
#define next_switch (frame->Reserved[__NextSwitch])

86 87 88 89 90 91 92 93 94 95 96
struct stack_walk_callback
{
    HANDLE      hProcess;
    HANDLE      hThread;
    BOOL        is32;
    union
    {
        struct
        {
            PREAD_PROCESS_MEMORY_ROUTINE        f_read_mem;
            PTRANSLATE_ADDRESS_ROUTINE          f_xlat_adr;
97 98
            PFUNCTION_TABLE_ACCESS_ROUTINE      f_tabl_acs;
            PGET_MODULE_BASE_ROUTINE            f_modl_bas;
99 100 101 102 103
        } s32;
        struct
        {
            PREAD_PROCESS_MEMORY_ROUTINE64      f_read_mem;
            PTRANSLATE_ADDRESS_ROUTINE64        f_xlat_adr;
104 105
            PFUNCTION_TABLE_ACCESS_ROUTINE64    f_tabl_acs;
            PGET_MODULE_BASE_ROUTINE64          f_modl_bas;
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        } s64;
    } u;
};

static inline void addr_32to64(const ADDRESS* addr32, ADDRESS64* addr64)
{
    addr64->Offset = (ULONG64)addr32->Offset;
    addr64->Segment = addr32->Segment;
    addr64->Mode = addr32->Mode;
}

static inline void addr_64to32(const ADDRESS64* addr64, ADDRESS* addr32)
{
    addr32->Offset = (ULONG)addr64->Offset;
    addr32->Segment = addr64->Segment;
    addr32->Mode = addr64->Mode;
}

static inline BOOL sw_read_mem(struct stack_walk_callback* cb, DWORD addr, void* ptr, DWORD sz)
{
    if (cb->is32)
        return cb->u.s32.f_read_mem(cb->hProcess, addr, ptr, sz, NULL);
    else
        return cb->u.s64.f_read_mem(cb->hProcess, addr, ptr, sz, NULL);
}

static inline DWORD sw_xlat_addr(struct stack_walk_callback* cb, ADDRESS* addr)
{
134 135 136
    if (addr->Mode == AddrModeFlat) return addr->Offset;
    if (cb->is32) return cb->u.s32.f_xlat_adr(cb->hProcess, cb->hThread, addr);
    if (cb->u.s64.f_xlat_adr)
137 138 139 140 141 142
    {
        ADDRESS64       addr64;

        addr_32to64(addr, &addr64);
        return cb->u.s64.f_xlat_adr(cb->hProcess, cb->hThread, &addr64);
    }
143 144 145 146 147 148 149
    return addr_to_linear(cb->hProcess, cb->hThread, addr);
}

static inline void* sw_tabl_acs(struct stack_walk_callback* cb, DWORD addr)
{
    if (cb->is32)
        return cb->u.s32.f_tabl_acs(cb->hProcess, addr);
150
    else
151 152 153 154 155 156 157 158 159
        return cb->u.s64.f_tabl_acs(cb->hProcess, addr);
}

static inline DWORD sw_modl_bas(struct stack_walk_callback* cb, DWORD addr)
{
    if (cb->is32)
        return cb->u.s32.f_modl_bas(cb->hProcess, addr);
    else
        return cb->u.s64.f_modl_bas(cb->hProcess, addr);
160 161 162
}

static BOOL stack_walk(struct stack_walk_callback* cb, LPSTACKFRAME frame)
163 164 165 166 167 168 169 170 171 172 173 174
{
    STACK32FRAME        frame32;
    STACK16FRAME        frame16;
    char                ch;
    ADDRESS             tmp;
    DWORD               p;
    WORD                val;
    BOOL                do_switch;

    /* sanity check */
    if (curr_mode >= stm_done) return FALSE;

175 176
    TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s cSwitch=%08x nSwitch=%08x\n",
          wine_dbgstr_addr(&frame->AddrPC),
177 178 179 180 181 182 183 184 185 186
          wine_dbgstr_addr(&frame->AddrFrame),
          wine_dbgstr_addr(&frame->AddrReturn),
          wine_dbgstr_addr(&frame->AddrStack), 
          curr_mode == stm_start ? "start" : (curr_mode == stm_16bit ? "16bit" : "32bit"),
          curr_switch, next_switch);

    if (curr_mode == stm_start)
    {
        THREAD_BASIC_INFORMATION info;

187 188 189 190 191 192 193
        if ((frame->AddrPC.Mode == AddrModeFlat) &&
            (frame->AddrFrame.Mode != AddrModeFlat))
        {
            WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
            goto done_err;
        }

194 195 196 197
        /* Init done */
        curr_mode = (frame->AddrPC.Mode == AddrModeFlat) ? 
            stm_32bit : stm_16bit;

198
        /* cur_switch holds address of WOW32Reserved field in TEB in debuggee
199 200
         * address space
         */
201
        if (NtQueryInformationThread(cb->hThread, ThreadBasicInformation, &info,
202
                                     sizeof(info), NULL) == STATUS_SUCCESS)
203
        {
204
            curr_switch = (unsigned long)info.TebBaseAddress + FIELD_OFFSET(TEB, WOW32Reserved);
205
            if (!sw_read_mem(cb, curr_switch, &next_switch, sizeof(next_switch)))
206
            {
207
                WARN("Can't read TEB:WOW32Reserved\n");
208 209
                goto done_err;
            }
210
            if (curr_mode == stm_16bit)
211
            {
212
                if (!sw_read_mem(cb, next_switch, &frame32, sizeof(frame32)))
213
                {
214
                    WARN("Bad stack frame 0x%08x\n", next_switch);
215 216 217 218 219 220
                    goto done_err;
                }
                curr_switch = (DWORD)frame32.frame16;
                tmp.Mode    = AddrMode1616;
                tmp.Segment = SELECTOROF(curr_switch);
                tmp.Offset  = OFFSETOF(curr_switch);
221
                if (!sw_read_mem(cb, sw_xlat_addr(cb, &tmp), &ch, sizeof(ch)))
222
                    curr_switch = 0xFFFFFFFF;
223
            }
224 225 226 227 228
            else
            {
                tmp.Mode    = AddrMode1616;
                tmp.Segment = SELECTOROF(next_switch);
                tmp.Offset  = OFFSETOF(next_switch);
229 230
                p = sw_xlat_addr(cb, &tmp);
                if (!sw_read_mem(cb, p, &frame16, sizeof(frame16)))
231
                {
232
                    WARN("Bad stack frame 0x%08x\n", p);
233 234 235
                    goto done_err;
                }
                curr_switch = (DWORD)frame16.frame32;
236

237
                if (!sw_read_mem(cb, curr_switch, &ch, sizeof(ch)))
238 239
                    curr_switch = 0xFFFFFFFF;
            }
240
        }
241 242 243 244 245 246
        else
            /* FIXME: this will allow to work when we're not attached to a live target, 
             * but the 16 <=> 32 switch facility won't be available.
             */
            curr_switch = 0;
        frame->AddrReturn.Mode = frame->AddrStack.Mode = (curr_mode == stm_16bit) ? AddrMode1616 : AddrModeFlat;
247 248 249
        /* don't set up AddrStack on first call. Either the caller has set it up, or
         * we will get it in the next frame
         */
250
        memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore));
251 252 253 254 255 256 257 258 259 260 261 262
    }
    else
    {
        if (frame->AddrFrame.Offset == 0) goto done_err;
        if (frame->AddrFrame.Mode == AddrModeFlat)
        {
            assert(curr_mode == stm_32bit);
            do_switch = curr_switch && frame->AddrFrame.Offset >= curr_switch;
        }
        else
        {
            assert(curr_mode == stm_16bit);
263
            do_switch = curr_switch && 
264 265 266 267 268 269 270 271
                frame->AddrFrame.Segment == SELECTOROF(curr_switch) &&
                frame->AddrFrame.Offset >= OFFSETOF(curr_switch);
        }
	   
        if (do_switch)
        {
            if (curr_mode == stm_16bit)
            {
272
                if (!sw_read_mem(cb, next_switch, &frame32, sizeof(frame32)))
273
                {
274
                    WARN("Bad stack frame 0x%08x\n", next_switch);
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
                    goto done_err;
                }

                frame->AddrPC.Mode        = AddrModeFlat;
                frame->AddrPC.Segment     = 0;
                frame->AddrPC.Offset      = frame32.retaddr;
                frame->AddrFrame.Mode     = AddrModeFlat;
                frame->AddrFrame.Segment  = 0;
                frame->AddrFrame.Offset   = frame32.ebp;

                frame->AddrStack.Mode     = AddrModeFlat;
                frame->AddrStack.Segment  = 0;
                frame->AddrReturn.Mode    = AddrModeFlat;
                frame->AddrReturn.Segment = 0;

                next_switch = curr_switch;
                tmp.Mode    = AddrMode1616;
                tmp.Segment = SELECTOROF(next_switch);
                tmp.Offset  = OFFSETOF(next_switch);
294
                p = sw_xlat_addr(cb, &tmp);
295

296
                if (!sw_read_mem(cb, p, &frame16, sizeof(frame16)))
297
                {
298
                    WARN("Bad stack frame 0x%08x\n", p);
299 300 301 302
                    goto done_err;
                }
                curr_switch = (DWORD)frame16.frame32;
                curr_mode = stm_32bit;
303
                if (!sw_read_mem(cb, curr_switch, &ch, sizeof(ch)))
304
                    curr_switch = 0;
305 306 307 308 309 310
            }
            else
            {
                tmp.Mode    = AddrMode1616;
                tmp.Segment = SELECTOROF(next_switch);
                tmp.Offset  = OFFSETOF(next_switch);
311
                p = sw_xlat_addr(cb, &tmp);
312

313
                if (!sw_read_mem(cb, p, &frame16, sizeof(frame16)))
314
                {
315
                    WARN("Bad stack frame 0x%08x\n", p);
316 317 318 319 320
                    goto done_err;
                }

                TRACE("Got a 16 bit stack switch:"
                      "\n\tframe32: %08lx"
321
                      "\n\tedx:%08x ecx:%08x ebp:%08x"
322
                      "\n\tds:%04x es:%04x fs:%04x gs:%04x"
323 324
                      "\n\tcall_from_ip:%08x module_cs:%04x relay=%08x"
                      "\n\tentry_ip:%04x entry_point:%08x"
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
                      "\n\tbp:%04x ip:%04x cs:%04x\n",
                      (unsigned long)frame16.frame32,
                      frame16.edx, frame16.ecx, frame16.ebp,
                      frame16.ds, frame16.es, frame16.fs, frame16.gs,
                      frame16.callfrom_ip, frame16.module_cs, frame16.relay,
                      frame16.entry_ip, frame16.entry_point,
                      frame16.bp, frame16.ip, frame16.cs);

                      
                frame->AddrPC.Mode       = AddrMode1616;
                frame->AddrPC.Segment    = frame16.cs;
                frame->AddrPC.Offset     = frame16.ip;

                frame->AddrFrame.Mode    = AddrMode1616;
                frame->AddrFrame.Segment = SELECTOROF(next_switch);
                frame->AddrFrame.Offset  = frame16.bp;

                frame->AddrStack.Mode    = AddrMode1616;
                frame->AddrStack.Segment = SELECTOROF(next_switch);

                frame->AddrReturn.Mode    = AddrMode1616;
                frame->AddrReturn.Segment = frame16.cs;

                next_switch = curr_switch;
349
                if (!sw_read_mem(cb, next_switch, &frame32, sizeof(frame32)))
350
                {
351
                    WARN("Bad stack frame 0x%08x\n", next_switch);
352 353 354 355 356 357 358
                    goto done_err;
                }
                curr_switch = (DWORD)frame32.frame16;
                tmp.Mode    = AddrMode1616;
                tmp.Segment = SELECTOROF(curr_switch);
                tmp.Offset  = OFFSETOF(curr_switch);

359
                if (!sw_read_mem(cb, sw_xlat_addr(cb, &tmp), &ch, sizeof(ch)))
360
                    curr_switch = 0;
361 362 363 364 365 366 367 368 369 370
                curr_mode = stm_16bit;
            }
        }
        else
        {
            frame->AddrPC = frame->AddrReturn;
            if (curr_mode == stm_16bit)
            {
                frame->AddrStack.Offset = frame->AddrFrame.Offset + 2 * sizeof(WORD);
                /* "pop up" previous BP value */
371 372
                if (!sw_read_mem(cb, sw_xlat_addr(cb, &frame->AddrFrame),
                                 &val, sizeof(WORD)))
373 374 375 376 377 378 379
                    goto done_err;
                frame->AddrFrame.Offset = val;
            }
            else
            {
                frame->AddrStack.Offset = frame->AddrFrame.Offset + 2 * sizeof(DWORD);
                /* "pop up" previous EBP value */
380 381
                if (!sw_read_mem(cb, frame->AddrFrame.Offset, 
                                 &frame->AddrFrame.Offset, sizeof(DWORD)))
382 383 384 385 386 387 388
                    goto done_err;
            }
        }
    }

    if (curr_mode == stm_16bit)
    {
389
        unsigned int     i;
390

391 392
        p = sw_xlat_addr(cb, &frame->AddrFrame);
        if (!sw_read_mem(cb, p + sizeof(WORD), &val, sizeof(WORD)))
393 394 395
            goto done_err;
        frame->AddrReturn.Offset = val;
        /* get potential cs if a far call was used */
396
        if (!sw_read_mem(cb, p + 2 * sizeof(WORD), &val, sizeof(WORD)))
397 398 399 400 401 402 403 404 405 406 407 408
            goto done_err;
        if (frame->AddrFrame.Offset & 1)
            frame->AddrReturn.Segment = val; /* far call assumed */
        else
        {
            /* not explicitly marked as far call, 
             * but check whether it could be anyway
             */
            if ((val & 7) == 7 && val != frame->AddrReturn.Segment)
            {
                LDT_ENTRY	le;

409
                if (GetThreadSelectorEntry(cb->hThread, val, &le) &&
410 411 412 413 414 415 416 417 418 419
                    (le.HighWord.Bits.Type & 0x08)) /* code segment */
                {
                    /* it is very uncommon to push a code segment cs as
                     * a parameter, so this should work in most cases 
                     */
                    frame->AddrReturn.Segment = val;
                }
	    }
	}
        frame->AddrFrame.Offset &= ~1;
420
        /* we "pop" parameters as 16 bit entities... of course, this won't
421 422 423 424 425
         * work if the parameter is in fact bigger than 16bit, but
         * there's no way to know that here
         */
        for (i = 0; i < sizeof(frame->Params) / sizeof(frame->Params[0]); i++)
        {
426
            sw_read_mem(cb, p + (2 + i) * sizeof(WORD), &val, sizeof(val));
427 428 429 430 431
            frame->Params[i] = val;
        }
    }
    else
    {
432 433
        if (!sw_read_mem(cb, frame->AddrFrame.Offset + sizeof(DWORD),
                         &frame->AddrReturn.Offset, sizeof(DWORD)))
434
        {
435
            WARN("Cannot read new frame offset %08x\n", frame->AddrFrame.Offset + (int)sizeof(DWORD));
436
            goto done_err;
437
        }
438
        sw_read_mem(cb, frame->AddrFrame.Offset + 2 * sizeof(DWORD),
439
                    frame->Params, sizeof(frame->Params));
440 441
    }

442 443 444 445 446 447 448
    frame->Far = TRUE;
    frame->Virtual = TRUE;
    p = sw_xlat_addr(cb, &frame->AddrPC);
    if (p && sw_modl_bas(cb, p))
        frame->FuncTableEntry = sw_tabl_acs(cb, p);
    else
        frame->FuncTableEntry = NULL;
449

450 451
    TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s cSwitch=%08x nSwitch=%08x FuncTable=%p\n",
          wine_dbgstr_addr(&frame->AddrPC),
452 453 454 455
          wine_dbgstr_addr(&frame->AddrFrame),
          wine_dbgstr_addr(&frame->AddrReturn),
          wine_dbgstr_addr(&frame->AddrStack), 
          curr_mode == stm_start ? "start" : (curr_mode == stm_16bit ? "16bit" : "32bit"),
456
          curr_switch, next_switch, frame->FuncTableEntry);
457 458 459 460 461 462

    return TRUE;
done_err:
    curr_mode = stm_done;
    return FALSE;
}
463

464 465 466 467
/***********************************************************************
 *		StackWalk (DBGHELP.@)
 */
BOOL WINAPI StackWalk(DWORD MachineType, HANDLE hProcess, HANDLE hThread,
468
                      LPSTACKFRAME frame, PVOID ctx,
469 470 471 472 473 474 475
                      PREAD_PROCESS_MEMORY_ROUTINE f_read_mem,
                      PFUNCTION_TABLE_ACCESS_ROUTINE FunctionTableAccessRoutine,
                      PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
                      PTRANSLATE_ADDRESS_ROUTINE f_xlat_adr)
{
    struct stack_walk_callback  swcb;

476
    TRACE("(%d, %p, %p, %p, %p, %p, %p, %p, %p)\n",
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
          MachineType, hProcess, hThread, frame, ctx,
          f_read_mem, FunctionTableAccessRoutine,
          GetModuleBaseRoutine, f_xlat_adr);

    if (MachineType != IMAGE_FILE_MACHINE_I386)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    swcb.hProcess = hProcess;
    swcb.hThread = hThread;
    swcb.is32 = TRUE;
    /* sigh... MS isn't even consistent in the func prototypes */
    swcb.u.s32.f_read_mem = (f_read_mem) ? f_read_mem : read_mem;
    swcb.u.s32.f_xlat_adr = (f_xlat_adr) ? f_xlat_adr : addr_to_linear;
493 494
    swcb.u.s32.f_tabl_acs = (FunctionTableAccessRoutine) ? FunctionTableAccessRoutine : SymFunctionTableAccess;
    swcb.u.s32.f_modl_bas = (GetModuleBaseRoutine) ? GetModuleBaseRoutine : SymGetModuleBase;
495 496 497 498 499

    return stack_walk(&swcb, frame);
}


Vitaliy Margolen's avatar
Vitaliy Margolen committed
500 501 502 503
/***********************************************************************
 *		StackWalk64 (DBGHELP.@)
 */
BOOL WINAPI StackWalk64(DWORD MachineType, HANDLE hProcess, HANDLE hThread,
504
                        LPSTACKFRAME64 frame64, PVOID ctx,
Vitaliy Margolen's avatar
Vitaliy Margolen committed
505 506 507 508 509
                        PREAD_PROCESS_MEMORY_ROUTINE64 f_read_mem,
                        PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
                        PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
                        PTRANSLATE_ADDRESS_ROUTINE64 f_xlat_adr)
{
510 511 512 513
    struct stack_walk_callback  swcb;
    STACKFRAME                  frame32;
    BOOL                        ret;

514
    TRACE("(%d, %p, %p, %p, %p, %p, %p, %p, %p)\n",
515
          MachineType, hProcess, hThread, frame64, ctx,
Vitaliy Margolen's avatar
Vitaliy Margolen committed
516 517
          f_read_mem, FunctionTableAccessRoutine,
          GetModuleBaseRoutine, f_xlat_adr);
518 519 520 521 522 523 524 525 526

    if (MachineType != IMAGE_FILE_MACHINE_I386)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    addr_64to32(&frame64->AddrPC,     &frame32.AddrPC);
    addr_64to32(&frame64->AddrReturn, &frame32.AddrReturn);
527
    addr_64to32(&frame64->AddrFrame,  &frame32.AddrFrame);
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
    addr_64to32(&frame64->AddrStack,  &frame32.AddrStack);
    addr_64to32(&frame64->AddrBStore, &frame32.AddrBStore);
    frame32.FuncTableEntry = frame64->FuncTableEntry; /* FIXME */
    frame32.Far = frame64->Far;
    frame32.Virtual = frame64->Virtual;
    frame32.Reserved[0] = (ULONG)frame64->Reserved[0];
    frame32.Reserved[1] = (ULONG)frame64->Reserved[1];
    frame32.Reserved[2] = (ULONG)frame64->Reserved[2];
    /* we don't handle KdHelp */

    swcb.hProcess = hProcess;
    swcb.hThread = hThread;
    swcb.is32 = FALSE;
    /* sigh... MS isn't even consistent in the func prototypes */
    swcb.u.s64.f_read_mem = (f_read_mem) ? f_read_mem : read_mem64;
    swcb.u.s64.f_xlat_adr = f_xlat_adr;
544 545
    swcb.u.s64.f_tabl_acs = (FunctionTableAccessRoutine) ? FunctionTableAccessRoutine : SymFunctionTableAccess64;
    swcb.u.s64.f_modl_bas = (GetModuleBaseRoutine) ? GetModuleBaseRoutine : SymGetModuleBase64;
546 547 548 549 550

    ret = stack_walk(&swcb, &frame32);

    addr_32to64(&frame32.AddrPC,     &frame64->AddrPC);
    addr_32to64(&frame32.AddrReturn, &frame64->AddrReturn);
551
    addr_32to64(&frame32.AddrFrame,  &frame64->AddrFrame);
552 553 554
    addr_32to64(&frame32.AddrStack,  &frame64->AddrStack);
    addr_32to64(&frame32.AddrBStore, &frame64->AddrBStore);
    frame64->FuncTableEntry = frame32.FuncTableEntry; /* FIXME */
555 556 557 558
    frame64->Params[0] = frame32.Params[0];
    frame64->Params[1] = frame32.Params[1];
    frame64->Params[2] = frame32.Params[2];
    frame64->Params[3] = frame32.Params[3];
559 560
    frame64->Far = frame32.Far;
    frame64->Virtual = frame32.Virtual;
561 562 563
    frame64->Reserved[0] = frame32.Reserved[0];
    frame64->Reserved[1] = frame32.Reserved[1];
    frame64->Reserved[2] = frame32.Reserved[2];
564
    /* we don't handle KdHelp */
565 566 567 568 569 570 571 572 573
    frame64->KdHelp.Thread = 0xC000FADE;
    frame64->KdHelp.ThCallbackStack = 0x10;
    frame64->KdHelp.ThCallbackBStore = 0;
    frame64->KdHelp.NextCallback = 0;
    frame64->KdHelp.FramePointer = 0;
    frame64->KdHelp.KiCallUserMode = 0xD000DAFE;
    frame64->KdHelp.KeUserCallbackDispatcher = 0xE000F000;
    frame64->KdHelp.SystemRangeStart = 0xC0000000;
    frame64->KdHelp.Reserved[0] /* KiUserExceptionDispatcher */ = 0xE0005000;
574

575
    return ret;
Vitaliy Margolen's avatar
Vitaliy Margolen committed
576 577
}

578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
/******************************************************************
 *		SymRegisterFunctionEntryCallback (DBGHELP.@)
 *
 *
 */
BOOL WINAPI SymRegisterFunctionEntryCallback(HANDLE hProc,
                                             PSYMBOL_FUNCENTRY_CALLBACK cb, PVOID user)
{
    FIXME("(%p %p %p): stub!\n", hProc, cb, user);
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    return FALSE;
}

/******************************************************************
 *		SymRegisterFunctionEntryCallback64 (DBGHELP.@)
 *
 *
 */
BOOL WINAPI SymRegisterFunctionEntryCallback64(HANDLE hProc,
                                               PSYMBOL_FUNCENTRY_CALLBACK64 cb,
                                               ULONG64 user)
{
    FIXME("(%p %p %s): stub!\n", hProc, cb, wine_dbgstr_longlong(user));
    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    return FALSE;
}