Re: Try Finally...

From: VBDis (vbdis_at_aol.com)
Date: 10/29/04


Date: 29 Oct 2004 03:12:36 GMT

Im Artikel <dib1o0h986j5jguotdk4rlu6t5s7ccaetf@4ax.com>, L D Blake
<not@any.adr> schreibt:

>OK lets try and clear some of this up. Structured Exception Handling is a
>Windows thing. It is governed by guard frames placed in the program's stack.
>These frames are put in place by Delphi's TRY keyword. Each frame contains
>(at minimum) the address of an exception handler and a pointer on the stack
>to the previous frame.

Another thing to clarify:

Even if the records reside in the stack, the list of the guard frames is
implemented by specific links, independent from the subroutine frames in the
call stack. The list head is accessible via FS, the following records by their
built-in links. The total stack record seems to consist of 3 pointers, if I
interpret the code in the CPU window correctly?

In so far I don't like to speak of "the stack", the guard frames form their own
stack (linked list), and walking the call stack (frames) is different from
walking the guard list.

>The hard part for us to understand is that when we do something that causes an
>exception, the exception is not created in Delphi (or whatever language we are
>using), it originates in the operating system. What the language does with an
>active exception is entirely up to the language (and by extension, us).

This applies to "external" exceptions only. There exists no real need to signal
internal exceptions (range checks...) to the OS, it's sufficient when both
internal and external exceptions trigger the same exception /handling/.

Walking the guard list also is not problematic, regardless of whether it's
performed in 1 or 2 passes. In a 2-pass traversal an applicable exception
handler is determined first, and in the second pass the termination handlers
are invoked, followed by the exception handler determined in the first pass.
The second pass is not initiated when the filter expression decided to resume
at the instruction that caused the exception(?). It should be noted that the
exception handler executes only after all termination handlers have executed.

This can be done in a single pass as well, but then the guard list must be
truncated at the same time, because the handlers become no more elective for
another execution, and the stack must be unwound at the same time, so that the
handlers execute in their proper stack frame.

DoDi



Relevant Pages

  • Re: Try Finally...
    ... stack frames on the stack that control program flow into and out of ... so also are guard frames allocated on the stack. ... Exception bubbling uses the chain of guard frames, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Sanity Check: Custom Exception Approach
    ... > One surprising discovery for me is that when I pass the various Exception ... > objects to an error logging routine (which writes details out to an XML ... > entire call stack. ... stack frames, executing finally and fault blocks, up to the frame of the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: exception handling, function call and memory
    ... Those frames are by convention allocated on ... the stack, but I don't think they're technically required to be there (not ... the C++ exception handling mechanism actually entirely ... handler stack, which is to say, with /EHa there's one SEH exception ...
    (microsoft.public.vc.language)
  • Re: x86 exception handling and stack demand
    ... When an exception occurs that will be passed down to user mode as an SEH exception, the kernel arranges for control to return to user mode at a special function in NTDLL, with several parameters on the stack containing information about the exception. ... In XP and later, the system stores a pointer to the initial stack allocation block in the TEB that is used by the kernel to decommit the stack via NtFreeVirtualMemory when the thread is terminated in a non-graceful fashion, closing this leak. ...
    (microsoft.public.win32.programmer.kernel)
  • [PATCH] x86: style fascism for xen assemblies
    ... * a view to being able to inline as much as possible. ... push %eax ... * This is run where a normal iret would be run, with the same stack setup: ... In order to deliver the nested exception properly, ...
    (Linux-Kernel)