Changeset 136 for trunk


Ignore:
Timestamp:
Oct 18, 2006, 11:58:35 PM (19 years ago)
Author:
dmik
Message:

Kernel: Added the Qt-wide OS/2 system exception handler (see ticket:33 for details). It may be disabled by defining QT_PM_NO_SYSEXCEPTIONS when building Qt.

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/qwindowdefs_pm.h

    r113 r136  
    9999const ULONG QT_EXTRAWINDATASIZE = sizeof(LONG) * 2;
    100100
    101 #ifdef __cplusplus
    102101class Q_EXPORT QPMObjectWindow
    103102{
     
    124123    HWND w;
    125124};
    126 #endif
     125
     126// OS/2 system exception handler callback interface
     127
     128enum QtSysXcptReq
     129{
     130    QtSysXcptReq_AppName = 0,
     131    QtSysXcptReq_AppVer = 1,
     132    QtSysXcptReq_ReportTo = 2,
     133    QtSysXcptReq_ReportSubj = 3,
     134};
     135
     136typedef void (*QtSysXcptWriter)( const char *str );
     137typedef int (*QtSysXcptCallback)( QtSysXcptReq req, QtSysXcptWriter writer,
     138                                  int reserved );
     139
     140Q_EXPORT QtSysXcptCallback qInstallSysXcptCallback( QtSysXcptCallback cb );
    127141
    128142#endif
  • trunk/src/kernel/qapplication_pm.cpp

    r126 r136  
    66** Copyright (C) 1992-2003 Trolltech AS.  All rights reserved.
    77** Copyright (C) 2004 Norman ASA.  Initial OS/2 Port.
    8 ** Copyright (C) 2005 netlabs.org.  Further OS/2 Development.
     8** Copyright (C) 2005-2006 netlabs.org.  Further OS/2 Development.
    99**
    1010** This file is part of the kernel module of the Qt GUI Toolkit.
     
    453453 *****************************************************************************/
    454454
     455#if !defined(QT_PM_NO_SYSEXCEPTIONS)   
     456extern // defined in qsysxcpt_pm.cpp
     457ULONG APIENTRY qt_exceptionHandler( PEXCEPTIONREPORTRECORD pReportRec,
     458                                    PEXCEPTIONREGISTRATIONRECORD pRegRec,
     459                                    PCONTEXTRECORD pContextRec,
     460                                    PVOID pv );
     461ERR qt_libcExceptionHandler = NULL;
     462#endif
     463
    455464// need to get default font?
    456465extern bool qt_app_has_font;
     
    458467void qt_init( int *argcptr, char **argv, QApplication::Type )
    459468{
     469#if !defined(QT_PM_NO_SYSEXCEPTIONS)
     470    // Since the exception registration record can only be located on the stack,
     471    // we can enable our exception handling on the main thread only if the LIBC
     472    // library of the compiler provides an exception handler (already allocated
     473    // on the stack before main() is called). In this case, we replace the LIBC
     474    // exception handler's pointer with our own (not nice but what to do?) and
     475    // call the former (to let it do signal processing and the stuff) after we
     476    // generate the trap file. Note that if there is no LIBC exception handler
     477    // provided, qt_libcExceptionHandler will remain NULL to tell QThread not to
     478    // install our exception handler for newly created threads (all or nothing).
     479    {
     480        PTIB ptib = NULL;
     481        PPIB ppib = NULL;
     482        DosGetInfoBlocks( &ptib, &ppib );
     483       
     484        Q_ASSERT( ptib && ppib );
     485        if ( ptib && ppib ) {
     486            if ( ptib->tib_pexchain != END_OF_CHAIN ) {
     487                PEXCEPTIONREGISTRATIONRECORD rec =
     488                    (PEXCEPTIONREGISTRATIONRECORD) ptib->tib_pexchain;
     489                qt_libcExceptionHandler = rec->ExceptionHandler;
     490                rec->ExceptionHandler = qt_exceptionHandler;
     491            } else {
     492                Q_ASSERT( 0 /* no exception handler for the main thread */ );
     493            }
     494        }
     495    }
     496#endif
    460497
    461498#if defined(QT_DEBUG)
     
    539576//@@TODO (dmik): remove?
    540577//    QInputContext::shutdown();
     578
     579#if !defined(QT_PM_NO_SYSEXCEPTIONS)
     580    // remove the exception handler if it was installed in qt_init()
     581    if ( qt_libcExceptionHandler ) {
     582        PTIB ptib = NULL;
     583        PPIB ppib = NULL;
     584        DosGetInfoBlocks( &ptib, &ppib );
     585       
     586        Q_ASSERT( ptib && ppib );
     587        if ( ptib && ppib ) {
     588            Q_ASSERT( ptib->tib_pexchain != END_OF_CHAIN );
     589            if ( ptib->tib_pexchain != END_OF_CHAIN ) {
     590                PEXCEPTIONREGISTRATIONRECORD rec =
     591                    (PEXCEPTIONREGISTRATIONRECORD) ptib->tib_pexchain;
     592                Q_ASSERT( rec->ExceptionHandler == qt_exceptionHandler );
     593                if ( rec->ExceptionHandler == qt_exceptionHandler ) {
     594                    rec->ExceptionHandler = qt_libcExceptionHandler;
     595                    qt_libcExceptionHandler = NULL;
     596                }
     597            }
     598        }
     599    }
     600#endif
    541601}
    542602
  • trunk/src/kernel/qt_kernel.pri

    r128 r136  
    140140                  $$KERNEL_CPP/qthread_pm.cpp \
    141141                  $$KERNEL_CPP/qwidget_pm.cpp \
    142                   $$KERNEL_CPP/qfontengine_pm.cpp
     142                  $$KERNEL_CPP/qfontengine_pm.cpp \
     143                  $$KERNEL_CPP/qsysxcpt_pm.cpp
    143144
    144145        unix:x11 {
  • trunk/src/kernel/qthread_pm.cpp

    r125 r136  
    3939
    4040#include "qt_os2.h"
     41
     42#if !defined(QT_PM_NO_SYSEXCEPTIONS)
     43extern // defined in qsysxcpt_pm.cpp
     44ULONG APIENTRY qt_exceptionHandler( PEXCEPTIONREPORTRECORD pReportRec,
     45                                    PEXCEPTIONREGISTRATIONRECORD pRegRec,
     46                                    PCONTEXTRECORD pContextRec,
     47                                    PVOID pv );
     48extern ERR qt_libcExceptionHandler; // defined in qapplication_pm.cpp
     49#endif
    4150
    4251#include "qthread.h"
     
    106115    LocalStorage = arg [1];
    107116
     117#if !defined(QT_PM_NO_SYSEXCEPTIONS)
     118    // don't set the exception handler if not able to do it for main thread
     119    bool setException = qt_libcExceptionHandler != NULL;
     120    EXCEPTIONREGISTRATIONRECORD excRegRec = { 0, qt_exceptionHandler };
     121    if ( setException )
     122        DosSetExceptionHandler( &excRegRec );
     123#endif
     124
    108125    ( (QThread *) arg[0] )->run();
    109126
    110127    finish( (QThreadInstance *) arg[1] );
    111128
     129#if !defined(QT_PM_NO_SYSEXCEPTIONS)
     130    if ( setException )
     131        DosUnsetExceptionHandler( &excRegRec );
     132#endif
     133   
    112134    return;
    113135}
Note: See TracChangeset for help on using the changeset viewer.