Changeset 2727


Ignore:
Timestamp:
Jul 18, 2006, 1:26:14 AM (19 years ago)
Author:
bird
Message:

Nt panic.

Location:
trunk/libc
Files:
1 added
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/libc/Makefile.kmk

    r2718 r2727  
    5656        $(TARGET_libc_libsyslog) \
    5757        $(TARGET_libc_libc_sys)
     58libc_SOURCES.win32 = $(TARGET_kNIX.nt)
    5859
    5960ifdef CFG_LIBC_LOGSTRICT_LIBS
     
    6970        $(TARGET_libc_libsyslog_l) \
    7071        $(TARGET_libc_libc_sys_l)
     72libc_SOURCES.win32 = $(TARGET_kNIX.nt_l)
    7173endif
    7274
     
    8385        $(TARGET_libc_libsyslog_p)
    8486        $(TARGET_libc_libc_p)
     87libc_SOURCES.win32 = $(TARGET_kNIX.nt_p)
    8588endif
    8689
  • trunk/libc/include/klibc/nt/fib.h

    r2726 r2727  
    132132    } u1;                                                           /*  10   20  */
    133133    void                               *ArbitraryUserPointer;       /*  14   28  */
    134     struct _NT_TIB                     *Self;                       /*  18   30  */
     134    struct __LIBC_TEB                  *Self;                       /*  18   30  */
    135135    void                               *EnvironmentPointer;         /*  1c   38  */
    136136    struct
     
    323323
    324324/**
     325 * Gets the pointer to the thread information block.
     326 */
     327#define fibGetTEB()                 ((__LIBC_PTEB)__libc_fibGetTEB_PV(Self))
     328
     329/**
    325330 * Gets the pointer to the process information block.
    326331 */
     
    390395}
    391396
     397/**
     398 * Checks if we're being debugged.
     399 */
     400#define fibIsBeingDebugged()    (fibGetPEB()->BeingDebugged)
    392401
    393402__END_DECLS
  • trunk/libc/include/klibc/nt/nt.h

    r2723 r2727  
    3333#undef PAGE_SHIFT
    3434
     35NTOSAPI
     36NTSTATUS NTAPI RtlQueryEnvironmentVariable_U(
     37    IN PVOID Environment OPTIONAL,
     38    IN PUNICODE_STRING VariableName,
     39    OUT PUNICODE_STRING VariableValue);
     40
    3541#endif
    3642
  • trunk/libc/src/kNIX.nt/b_panic.c

    r2722 r2727  
    44 * LIBC SYS Backend - panic.
    55 *
    6  * Copyright (c) 2005 knut st. osmundsen <bird@anduin.net>
    7  *
    8  *
    9  * This file is part of InnoTek LIBC.
    10  *
    11  * InnoTek LIBC is free software; you can redistribute it and/or modify
     6 * Copyright (c) 2005-2006 knut st. osmundsen <bird@anduin.net>
     7 *
     8 *
     9 * This file is part of kLIBC.
     10 *
     11 * kLIBC is free software; you can redistribute it and/or modify
    1212 * it under the terms of the GNU General Public License as published by
    1313 * the Free Software Foundation; either version 2 of the License, or
    1414 * (at your option) any later version.
    1515 *
    16  * InnoTek LIBC is distributed in the hope that it will be useful,
     16 * kLIBC is distributed in the hope that it will be useful,
    1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     
    2020 *
    2121 * You should have received a copy of the GNU General Public License
    22  * along with InnoTek LIBC; if not, write to the Free Software
     22 * along with kLIBC; if not, write to the Free Software
    2323 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2424 *
     
    3131*******************************************************************************/
    3232#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_NOGROUP
    33 #define INCL_BASE
    34 #define INCL_ERRORS
    35 #define INCL_FSMACROS
    36 #define INCL_DOSUNDOCUEMENTED
    3733#define _GNU_SOURCE
     34#include <klibc/nt/nt.h>
     35#include <klibc/fib.h>
    3836#include <string.h>
    3937#include <InnotekLIBC/backend.h>
    4038#include <InnotekLIBC/sharedpm.h>
    4139#include <InnotekLIBC/logstrict.h>
    42 #include <os2emx.h>
    43 
    44 
    45 /*******************************************************************************
    46 *   Defined Constants And Macros                                               *
    47 *******************************************************************************/
    48 /** OS/2 default standard error handle. */
    49 #define HFILE_STDERR    ((HFILE)2)
    5040
    5141
     
    6353}
    6454
     55
     56
    6557/**
    6658 * Compare and advance if found.
     
    6961 * @returns 0 if no match.
    7062 */
    71 static int panicStrICmp(const char **ppsz, const char *pszLower, const char *pszUpper)
    72 {
    73     const char *psz = *ppsz;
    74     while (*psz == *pszLower || *psz == *pszUpper)
    75     {
    76         psz++;
     63static int panicStrICmp(const WCHAR **ppwsz, const char *pszLower, const char *pszUpper)
     64{
     65    const WCHAR *pwsz = *ppwsz;
     66    while (*pwsz == *pszLower || *pwsz == *pszUpper)
     67    {
     68        pwsz++;
    7769        pszUpper++;
    7870        if (!*pszUpper)
    7971        {
    80             *ppsz = psz;
     72            *ppwsz = pwsz;
    8173            return 1;
    8274        }
     
    137129
    138130/**
     131 * Write panic text to the panic message / log.
     132 *
     133 * @param   psz     The text.
     134 * @param   cch     The length.
     135 */
     136static void panicWrite(const char *psz, unsigned cch)
     137{
     138    /** @todo find somewhere to write the panic! */
     139}
     140
     141
     142/**
    139143 * Print a panic message and dump/kill the process.
    140144 *
     
    168172     * First, terminate the exception handler chain to avoid recursive trouble.
    169173     */
    170     FS_VAR();
    171     FS_SAVE_LOAD();
    172     PTIB pTib;
    173     PPIB pPib;
    174     DosGetInfoBlocks(&pTib, &pPib);
    175     pTib->tib_pexchain = END_OF_CHAIN;
     174    __LIBC_PTEB pTeb = fibGetTEB();
     175    pTeb->ExceptionList = (void *)-1;
    176176
    177177    /*
    178178     * Set the exit reason in SPM.
    179179     */
    180     if (!(fFlags & __LIBC_PANIC_NO_SPM_TERM))
    181         __libc_spmTerm(__LIBC_EXIT_REASON_KILL, 127);
     180//later    if (!(fFlags & __LIBC_PANIC_NO_SPM_TERM))
     181//later        __libc_spmTerm(__LIBC_EXIT_REASON_KILL, 127);
    182182
    183183    /*
     
    186186    BOOL fQuiet = FALSE;
    187187    BOOL fVerbose = TRUE;
    188     BOOL fBreakpoint = DosSysCtl(DOSSYSCTL_AM_I_DEBUGGED, NULL) == TRUE;
     188    BOOL fBreakpoint = fibIsBeingDebugged();
    189189    BOOL fDumpProcess = TRUE;
    190     const char *pszPanicCfg = NULL;
    191     int rc = DosScanEnv((PCSZ)"LIBC_PANIC", (PSZ *)(void *)&pszPanicCfg);
    192     if (!rc && pszPanicCfg && strnlen(pszPanicCfg, 512) < 512)
    193     {
    194         int c = 512;
    195         while (c-- > 0 && *pszPanicCfg)
     190    /* the variable name */
     191    static WCHAR s_wszEnvVar[] = { 'L','I','B','C','_','P','A','N','I','C','\0' };
     192    UNICODE_STRING s_EnvVar =
     193    {
     194        .Length = sizeof(s_wszEnvVar) - 2,
     195        .MaximumLength = sizeof(s_wszEnvVar),
     196        .Buffer = (PWSTR)&s_wszEnvVar[0]
     197    };
     198    /* the value buffer. */
     199    static WCHAR s_wszEnvValue[512];
     200    UNICODE_STRING EnvValue;
     201    EnvValue.Length = EnvValue.MaximumLength = sizeof(s_wszEnvValue);
     202    EnvValue.Buffer = &s_wszEnvValue[0];
     203    /* do the query. */
     204    NTSTATUS rc = RtlQueryEnvironmentVariable_U(NULL, &s_EnvVar, &EnvValue);
     205    if (NT_SUCCESS(rc))
     206    {
     207        int c = EnvValue.Length;
     208        const WCHAR *pwszPanicCfg = EnvValue.Buffer;
     209        while (c-- > 0)
    196210        {
    197             if (panicStrICmp(&pszPanicCfg, "quiet", "QUIET"))
     211            if (panicStrICmp(&pwszPanicCfg, "quiet", "QUIET"))
    198212                fQuiet = TRUE;
    199             //else if (panicStrICmp(&pszPanicCfg, "noquiet", "NOQUIET"))
     213            //else if (panicStrICmp(&pwszPanicCfg, "noquiet", "NOQUIET"))
    200214            //    fQuiet = FALSE;
    201             else if (panicStrICmp(&pszPanicCfg, "terse", "TERSE"))
     215            else if (panicStrICmp(&pwszPanicCfg, "terse", "TERSE"))
    202216                fVerbose = FALSE;
    203             //else if (panicStrICmp(&pszPanicCfg, "verbose", "VERBOSE"))
     217            //else if (panicStrICmp(&pwszPanicCfg, "verbose", "VERBOSE"))
    204218            //    fVerbose = TRUE;
    205             else if (panicStrICmp(&pszPanicCfg, "breakpoint", "BREAKPOINT"))
     219            else if (panicStrICmp(&pwszPanicCfg, "breakpoint", "BREAKPOINT"))
    206220                fBreakpoint = TRUE;
    207             else if (panicStrICmp(&pszPanicCfg, "nobreakpoint", "NOBREAKPOINT"))
     221            else if (panicStrICmp(&pwszPanicCfg, "nobreakpoint", "NOBREAKPOINT"))
    208222                fBreakpoint = FALSE;
    209             //else if (panicStrICmp(&pszPanicCfg, "dump", "DUMP"))
     223            //else if (panicStrICmp(&pwszPanicCfg, "dump", "DUMP"))
    210224            //    fDumpProcess = TRUE;
    211             else if (panicStrICmp(&pszPanicCfg, "nodump", "NODUMP"))
     225            else if (panicStrICmp(&pwszPanicCfg, "nodump", "NODUMP"))
    212226                fDumpProcess = FALSE;
    213227            else
    214                 pszPanicCfg++;
     228                pwszPanicCfg++;
    215229        }
    216230    }
     
    223237         * Write user message to stderr.
    224238         */
    225 #define PRINT_CHAR(ch)  DosWrite(HFILE_STDERR, &ch,      1,                                    &cb)
    226 #define PRINT_C(msg)    DosWrite(HFILE_STDERR, msg,      sizeof(msg) - 1,                      &cb)
    227 #define PRINT_P(msg)    DosWrite(HFILE_STDERR, msg,      panicStrLen(msg),           &cb)
    228 #define PRINT_H(hex)    DosWrite(HFILE_STDERR, szHexNum, panicHex(szHexNum, hex, 0), &cb)
    229 #define PRINT_H16(hex)  DosWrite(HFILE_STDERR, szHexNum, panicHex(szHexNum, hex, 4), &cb)
    230 #define PRINT_H32(hex)  DosWrite(HFILE_STDERR, szHexNum, panicHex(szHexNum, hex, 8), &cb)
     239#define PRINT_CHAR(ch)  panicWrite(&ch,      1)
     240#define PRINT_C(msg)    panicWrite(msg,      sizeof(msg) - 1)
     241#define PRINT_P(msg)    panicWrite(msg,      panicStrLen(msg))
     242#define PRINT_H(hex)    panicWrite(szHexNum, panicHex(szHexNum, hex, 0))
     243#define PRINT_H16(hex)  panicWrite(szHexNum, panicHex(szHexNum, hex, 4))
     244#define PRINT_H32(hex)  panicWrite(szHexNum, panicHex(szHexNum, hex, 8))
    231245        if (!(fFlags & __LIBC_PANIC_SIGNAL) && fVerbose)
    232246            PRINT_C("\r\nLIBC PANIC!!\r\n");
     
    312326
    313327            /* pid, tid and stuff */
    314             PRINT_C("pid=0x");   PRINT_H16(pPib->pib_ulpid);
    315             PRINT_C(" ppid=0x"); PRINT_H16(pPib->pib_ulppid);
    316             PRINT_C(" tid=0x");  PRINT_H16(pTib->tib_ptib2->tib2_ultid);
    317             PRINT_C(" slot=0x"); PRINT_H16(pTib->tib_ordinal);
    318             PRINT_C(" pri=0x");  PRINT_H16(pTib->tib_ptib2->tib2_ulpri);
    319             PRINT_C(" mc=0x");   PRINT_H16(pTib->tib_ptib2->tib2_usMCCount);
    320 
     328            PRINT_C("pid=0x");   PRINT_H16((uintptr_t)pTeb->ClientId.UniqueProcess);
     329            PRINT_C(" tid=0x");  PRINT_H16((uintptr_t)pTeb->ClientId.UniqueThread);
     330
     331#if 0
    321332            /* executable name. */
    322333            static char szExeName[CCHMAXPATH];
     
    327338                PRINT_P(szExeName);
    328339            }
     340#endif
    329341
    330342            /*
     
    333345            if (pvCtx)
    334346            {
    335                 PCONTEXTRECORD pCtx = (PCONTEXTRECORD)pvCtx;
    336 
     347                PCONTEXT pCtx = (PCONTEXT)pvCtx;
     348
     349#if 0
    337350                /* the module name */
    338                 if (pCtx->ctx_RegEip >= 0x10000)
     351                if (pCtx->Eip >= 0x10000)
    339352                {
    340353                    HMODULE hmod;
    341354                    ULONG iObj = 0;
    342355                    ULONG offObj = 0;
    343                     if (!DosQueryModFromEIP(&hmod, &iObj, sizeof(szExeName), szExeName, &offObj, pCtx->ctx_RegEip))
     356                    if (!DosQueryModFromEIP(&hmod, &iObj, sizeof(szExeName), szExeName, &offObj, pCtx->Eip))
    344357                    {
    345358                        PRINT_C("\r\n");
     
    352365                    }
    353366                }
     367#endif
    354368
    355369                /* registers */
    356370                PRINT_C("\r\ncs:eip=");
    357                 PRINT_H16(pCtx->ctx_SegCs);
     371                PRINT_H16(pCtx->SegCs);
    358372                PRINT_C(":");
    359                 PRINT_H32(pCtx->ctx_RegEip);
     373                PRINT_H32(pCtx->Eip);
    360374
    361375                PRINT_C("      ss:esp=");
    362                 PRINT_H16(pCtx->ctx_SegSs);
     376                PRINT_H16(pCtx->SegSs);
    363377                PRINT_C(":");
    364                 PRINT_H32(pCtx->ctx_RegEsp);
     378                PRINT_H32(pCtx->Esp);
    365379
    366380                PRINT_C("      ebp=");
    367                 PRINT_H32(pCtx->ctx_RegEbp);
     381                PRINT_H32(pCtx->Ebp);
    368382
    369383                PRINT_C("\r\n ds=");
    370                 PRINT_H16(pCtx->ctx_SegDs);
     384                PRINT_H16(pCtx->SegDs);
    371385                PRINT_C("      es=");
    372                 PRINT_H16(pCtx->ctx_SegEs);
     386                PRINT_H16(pCtx->SegEs);
    373387                PRINT_C("      fs=");
    374                 PRINT_H16(pCtx->ctx_SegFs);
     388                PRINT_H16(pCtx->SegFs);
    375389                PRINT_C("      gs=");
    376                 PRINT_H16(pCtx->ctx_SegGs);
     390                PRINT_H16(pCtx->SegGs);
    377391                PRINT_C("     efl=");
    378                 PRINT_H32(pCtx->ctx_EFlags);
     392                PRINT_H32(pCtx->EFlags);
    379393
    380394                PRINT_C("\r\neax=");
    381                 PRINT_H32(pCtx->ctx_RegEax);
     395                PRINT_H32(pCtx->Eax);
    382396                PRINT_C(" ebx=");
    383                 PRINT_H32(pCtx->ctx_RegEbx);
     397                PRINT_H32(pCtx->Ebx);
    384398                PRINT_C(" ecx=");
    385                 PRINT_H32(pCtx->ctx_RegEcx);
     399                PRINT_H32(pCtx->Ecx);
    386400                PRINT_C(" edx=");
    387                 PRINT_H32(pCtx->ctx_RegEdx);
     401                PRINT_H32(pCtx->Edx);
    388402                PRINT_C(" edi=");
    389                 PRINT_H32(pCtx->ctx_RegEdi);
     403                PRINT_H32(pCtx->Edi);
    390404                PRINT_C(" esi=");
    391                 PRINT_H32(pCtx->ctx_RegEsi);
     405                PRINT_H32(pCtx->Esi);
    392406                /** @todo fpu */
    393407            }
     
    408422    }
    409423
     424#if 0
    410425    /*
    411426     * Attempt dumping the process.
     
    413428    if (fDumpProcess)
    414429    {
     430        /// @todo Use MiniDumpWriteDump() if we're in a process which support dbghelp and such.
    415431        LIBCLOG_MSG("Calling DosDumpProcess()\n");
    416432        rc = DosDumpProcess(DDP_PERFORMPROCDUMP, 0, 0);
     
    429445        }
    430446    }
     447#endif
    431448
    432449    /*
    433450     * Terminate the process.
    434451     */
    435     LIBCLOG_MSG("Calling DosKillProcess()\n");
     452    LIBCLOG_MSG("Calling ZwTerminateProcess()\n");
    436453    for (;;)
    437454    {
    438         DosKillProcess(DKP_PROCESS, pPib->pib_ulpid);
    439         DosExit(EXIT_PROCESS, 127);
    440     }
    441 }
    442 
     455        ZwTerminateProcess(NtCurrentProcess(), 127);
     456        ZwYieldExecution();
     457    }
     458}
     459
Note: See TracChangeset for help on using the changeset viewer.