#117 Structured Exception Handling broken

closed
Danny Smith
gcc (462)
2002-08-05
2002-03-04
David Gravereaux
No

Although the following compiles cleanly, it doesn't
work.

#include <windows.h>

int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, int nCmdShow)
{
int a, b = 0;

__try {
a = 666 / b; /* divide by zero */
}
__except (EXCEPTION_EXECUTE_HANDLER) {
MessageBox(0, "went boom and caught", "",
MB_OK);
}
return 0;
}

Discussion

  • Danny Smith
    Danny Smith
    2002-03-04

    Logged In: YES
    user_id=11494

    This is not really a bug. It is a compiler feature that
    has never been implemented in GCC. I believe that members
    of the ReactOs team are working on patches to GCC to allow
    SEH. Perhaps you could check on their progess and find out
    what help they need.

    Danny

     
  • Logged In: YES
    user_id=7549

    Sorry, I'd like to help, but I have too many hobbies
    already ;)

    Without a real implimentation of SEH, Tcl 8.4 crashes due
    to a test that's run against a Win2K bug regarding garbage
    in a GUI (WinMain) app's STARTUPINFO that's caused by the
    default loader. Any call to GetStdHandle
    (STD_OUTPUT_HANDLE) returns an invalid handle rather than
    zero or INVALID_HANDLE_VALUE. Without an IsValidHandle()
    function where Tcl uses SEH in the validity test, any
    WinMain app that embedds Tcl, calls [puts] without a
    redirection channel, and starts on Win2K, will crash when
    MinGW compiled Tcl.

    I'd change Tcl to not use SEH if there was any sort of
    alternate approach that exists. But there doesn't seem to
    be.

    Ya know... I'll look into rewriting that part of Tcl in
    inline assembly to see if I can get around the missing
    intrinsic. Thanks.

     
  • Danny Smith
    Danny Smith
    2002-03-04

    Logged In: YES
    user_id=11494

    Would this work for your problem? Install a custom
    exception handler that does the right thing for
    STATUS_INVALID_HANDLE. Then revert back to the old handler.

    Danny

     
  • Logged In: YES
    user_id=7549

    Yes, exactly. I'd have to figure it out how to do it,
    though. Not sure... I just looked at
    http://www.jorgon.freeserve.co.uk/ExceptFrame.htm

    #ifdef __MINGW__
    asm {
    push ebp
    push <safeSpot>
    push <exceptSpot>
    push fs:[0]
    mov fs:[0], esp
    }
    {
    #else
    __try {
    #endif

    ??? I have no clue what I'm doing, nor do I know the AT&T
    asm syntax :)

     
  • Logged In: YES
    user_id=7549

    This is as close as I can get conceptualizing this. Do you
    have any code samples? Thanks.

    http://cvs.sourceforge.net/cgi-
    bin/viewcvs.cgi/tcl/tcl/win/tclWinChan.c?rev=1.20&content-
    type=text/vnd.viewcvs-markup

    Index: tclWinChan.c

    =======
    RCS file: /cvsroot/tcl/tcl/win/tclWinChan.c,v
    retrieving revision 1.20
    diff -c -r1.20 tclWinChan.c
    *** tclWinChan.c 15 Feb 2002 14:28:51 -0000 1.20
    --- tclWinChan.c 4 Mar 2002 23:27:45 -0000
    ***************
    *** 983,989 ****
    --- 983,1003 ----
    * of this duped handle which might throw
    EXCEPTION_INVALID_HANDLE.
    */

    + #ifdef __MINGW__
    + asm {
    + push ebp
    + mov ebp, esp
    + push -1
    + push <???safeSpot???>
    + push OFFSET FLAT:__except_handler3
    + mov eax, DWORD PTR fs:__except_list
    + push eax
    + mov DWORD PTR fs:__except_list, esp
    + }
    + {
    + #else
    __try {
    + #endif
    CloseHandle(dupedHandle);
    }
    __except (EXCEPTION_EXECUTE_HANDLER) {

     
  • Danny Smith
    Danny Smith
    2002-03-05

    Logged In: YES
    user_id=11494

    I was thinking of using something like:
    BOOL IsValid
    UINT oldErrorMode = SetErrorMode
    (SEM_FAILCRITICALERRORS); /* turn off SEM error handling) */
    IsValid =CloseHandle(dupedHandle)) {
    /* inspect the error value with GetLastError() if
    necessary */
    SetErrorMode(oldErrorMode); /* turn it back on */
    if (!IsValid)
    DoTheNotValidThing();
    else
    DoTheValidThing();

    I do soemthing like that when testing if the user has a
    disk in the A: drive.

     
  • Logged In: YES
    user_id=7549

    That's good. I'll see what that does. Thanks!

     
  • Logged In: YES
    user_id=7549

    progress is going just peachy :)
    Just thought I'd pass on the note and the cross-ref.

    http://sourceforge.net/tracker/index.php?
    func=detail&aid=525746&group_id=10894&atid=310894

     
  • Earnie Boyd
    Earnie Boyd
    2002-08-05

    • status: open --> closed