Ignore:
Timestamp:
Mar 9, 2012, 10:26:22 PM (13 years ago)
Author:
dmik
Message:

kernel32: Release log file lock on unexpected thread termination.

This fixes hard deadlocks in debug builds when the application is killed
or terminated with Ctrl-C.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/dbglog.cpp

    r21959 r21979  
    317317}
    318318
     319static ULONG _System WriteLogExcHandler(PEXCEPTIONREPORTRECORD pReport,
     320                                        PEXCEPTIONREGISTRATIONRECORD pRegRec,
     321                                        PCONTEXTRECORD pContext,
     322                                        PVOID pv)
     323{
     324    switch (pReport->ExceptionNum)
     325    {
     326    case XCPT_PROCESS_TERMINATE:
     327    case XCPT_ASYNC_PROCESS_TERMINATE:
     328    case XCPT_UNWIND:
     329        // disable further (possibly, recursive) handler calls
     330        DosUnsetExceptionHandler(pRegRec);
     331        // free the mutex to avoid deadlocks and make sure other threads can print
     332        logMutex.leave();
     333        break;
     334    }
     335
     336    return XCPT_CONTINUE_SEARCH;
     337}
     338
    319339int SYSTEM WriteLog(const char *tekst, ...)
    320340{
     
    322342    va_list argptr;
    323343    TEB *teb = GetThreadTEB();
     344
     345    EXCEPTIONREGISTRATIONRECORD RegRec = {0, WriteLogExcHandler};
     346    DosSetExceptionHandler(&RegRec);
    324347
    325348    logMutex.enter();
     
    396419        if(teb->o.odin.threadId < 5 && fDisableThread[teb->o.odin.threadId-1] == 1)
    397420        {
     421            logMutex.leave();
     422            DosUnsetExceptionHandler(&RegRec);
    398423            SetFS(sel);
    399             logMutex.leave();
    400424            return 1;
    401425        }
     
    407431            fflush(flog);
    408432
     433        logMutex.leave();
     434        DosUnsetExceptionHandler(&RegRec);
    409435        SetFS(sel);
    410         logMutex.leave();
    411436        return 1;
    412437    }
     
    621646    }
    622647
     648    logMutex.leave();
     649    DosUnsetExceptionHandler(&RegRec);
    623650    SetFS(sel);
    624     logMutex.leave();
    625651    return 1;
    626652}
     
    631657    USHORT  sel = RestoreOS2FS();
    632658    va_list argptr;
     659
     660    EXCEPTIONREGISTRATIONRECORD RegRec = {0, WriteLogExcHandler};
     661    DosSetExceptionHandler(&RegRec);
    633662
    634663    logMutex.enter();
     
    673702    }
    674703
     704    logMutex.leave();
     705    DosUnsetExceptionHandler(&RegRec);
    675706    SetFS(sel);
    676     logMutex.leave();
    677707    return 1;
    678708}
Note: See TracChangeset for help on using the changeset viewer.