다음을 통해 공유


Virtual Unwinding (Windows CE 5.0)

Send Feedback

To reconstruct the context that existed on entry to a routine, SEH for RISC processors uses a process called Virtual Unwinding to emulate a small subset of instructions in prolog and epilog code.

Virtual unwinding provides a syntactically efficient way of transferring control from the kernel exception handler to user-mode code.

In virtual unwinding, the kernel traverses the call stack to find an appropriate exception handler.

Starting with a CPU context record and an instruction address, the unwinding process interprets instructions in the prolog or epilog to reconstruct the context, as it existed before the function call.

The Virtual Unwinder uses a PDATA structure to determine the procedure start, the procedure end, and the prolog end. The PDATA structure can also contain a pointer to an exception handler.

The subset of prolog and epilog code that the Virtual Unwinder emulates includes the following:

  • Adding or subtracting a value from a register
  • Loading or storing a register on the stack frame
  • Loading integer constants into registers
  • Moving between registers

The Virtual Unwinder ignores other instructions found in the prolog or epilog sequences.

The following list shows the steps the Virtual Unwinder performs:

  1. Search the prolog for an instruction that saves the frame pointer, the stack pointer, or the link register.

    If the instruction is present, the instruction saves all permanent registers the Virtual Unwinder must restore.

    If the instruction is not present, the link register contains the return address, and the Virtual Unwinder updates only the program counter.

  2. Search for an instruction in the prolog that writes the frame pointer. The unwinding process restores all registers from this address down, starting from the lowest numbered register to the highest numbered register.

  3. Search for an instruction that writes the stack. If such an instruction exists, the unwinding process must reverse-execute the stack link. The right operand to this subtract is the stack size, which is a constant immediate value.

  4. If execution stops inside a prolog, the Virtual Unwinder determines if an instruction that saves the permanent registers executed, and if a stack link executed.

    • If the function has not saved the permanent registers, the Unwinder copies the value in the link register to the program counter register.
    • If the function saved the register values, and if no stack link executed, the Unwinder updates the permanent registers from the stack pointer.
    • If execution stopped in a prolog with a linked stack, the Unwinder reverse-executes the prolog.

Note   All functions that move the stack pointer must have an associated PDATA structure for SEH to work. These include any function that allocates stack space, calls other functions, saves permanent registers, or has an exception handler. A leaf function (that is, a function that calls no other functions) that does not modify a permanent register does not need PDATA. In this case, the Unwinder updates the program counter from the link register and continues to the next frame.

See Also

SEH in RISC Environments | Prolog-Epilog Example | PDATA Structures

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.