On Fri, 16 Jan 2009 08:37:20 -0800, Ian Lance Taylor <i...@google.com> wrote: > "Vincent R." <foru...@smartmobili.com> writes: > >> I am working on a gcc-4.1.2 and I would like to know how the prologue >> length from a function can be calculated. > > The question is not well formed. The instructions which are part of > the prologue (e.g., saving callee-saved registers onto the stack) can > be interspersed with instructions which are part of the function > proper. This happens routinely in gcc's second scheduling pass. > Ok I will check.
> >> Indeed I am trying to evaluate what needs to be done to implement SEH and >> one requirement is to be able to >> fill a structure holding information like function length and prologue >> length. > > I haven't looked at SEH. How does it use this sort of information? > What should happen when the prologue is not a unitary block of > instructions? > > Ian >From msdn : To locate appropriate handlers when an exception occurs in Win32 environments other than x86, the system first determines the frames that reside on the callstack, along with their associated functions in code. Any function can have a handler associated with it. If so, the system gives the handler associated with the function an opportunity to handle the exception. As with x86, the system invokes handlers in reverse order; that is, it first invokes the handler whose corresponding frames were most recently pushed onto the stack. To determine the frames on the stack, the system simulates the execution of a portion of each function's code in reverse. This simulation creates a CPU context similar to the state the real CPU context held at the point of entry to that function. This process of reverse execution is known as Virtual Unwinding, because the stack unwind is only being simulated, not actually performed. The portion of the code that is reversed is known as the prolog of the function. It consists of instructions that modify the stack pointer and set up the stack frame immediately upon entry to the function. To virtually unwind, the system needs a small amount of information about each function. This information is contained in data structures called PDATA structures. A PDATA structure marks where a function begins and ends in the code stream, as well as the location of the function prolog. For instance here is the information associated to a simple seh example : FuncStart PrologLen FuncLen ThirtyTwoBit ExceptionFlag Comment 00011008 0x4 0x15 1 1 wmain() 0001105c 0x1 0x9 1 0 filter_func() 000110a0 0x2 0x93 1 0 crtstart_ParseArgsWW 000112f4 0x4 0x30 1 1 mainWCRTStartup() That's why I was asking about prolog length...