Changeset 1881 for trunk


Ignore:
Timestamp:
Apr 24, 2005, 1:06:47 AM (20 years ago)
Author:
bird
Message:

Display cs:eip and module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/lib/sys/signals.c

    • Property cvs2svn:cvs-rev changed from 1.24 to 1.25
    r1880 r1881  
    206206    __LIBC_PTHREAD  pThrd;
    207207} SIGSCHEDENUMPARAM, *PSIGSCHEDENUMPARAM;
     208
     209
     210/**
     211 * Exception handler argument list.
     212 */
     213typedef struct XcptParams
     214{
     215    PEXCEPTIONREPORTRECORD       pXcptRepRec;
     216    PEXCEPTIONREGISTRATIONRECORD pXcptRegRec;
     217    PCONTEXTRECORD               pCtx;
     218    PVOID                        pvWhatEver;
     219} XCPTPARAMS, *PEXCPTPARAMS;
    208220
    209221
     
    555567static int              signalDeliver(__LIBC_PTHREAD pThrd, int iSignalNo, void *pvXcptParams);
    556568static void             signalTerminate(int iSignalNo) __dead2;
    557 static void             signalTerminateAbnormal(int iSignalNo) __dead2;
    558 static int              signalTerminateHex(char *pszBuf, unsigned u);
     569static void             signalTerminateAbnormal(int iSignalNo, void *pvXcptParams) __dead2;
    559570static int              signalJobStop(int iSignalNo);
    560571static int              signalJobResume(void);
     
    10121023        LIBCLOG_MSG("we're toast!\n");
    10131024        DosWrite(HFILE_STDERR, szMsg, sizeof(szMsg) - 1, &cb);
    1014         signalTerminateAbnormal(iSignalNo);
     1025        signalTerminateAbnormal(iSignalNo, fFlags & __LIBC_BSRF_QUEUED ? NULL : pvXcptOrQueued);
    10151026    }
    10161027
     
    17781789 * @param   iSignalNo           Deliver the first signal of this type no matter if it's
    17791790 *                              blocked or not. This is for use with hardware signals only!
    1780  * @param   pvXcptParams        sPointer to exception parameter list is any.
     1791 * @param   pvXcptParams        Pointer to exception parameter list is any.
    17811792 */
    17821793static int signalDeliver(__LIBC_PTHREAD pThrd, int iSignalNo, void *pvXcptParams)
     
    18831894                case SPA_CORE:
    18841895                case SPA_NEXT_CORE:
    1885                     signalTerminateAbnormal(iSignalNo);
     1896                    signalTerminateAbnormal(iSignalNo, pvXcptParams);
    18861897                    break;
    18871898
     
    20372048}
    20382049
     2050
    20392051/**
    20402052 * Cause immediate process termination because of the given signal.
     
    20502062     */
    20512063    __libc_spmTerm(__LIBC_EXIT_REASON_SIGNAL_BASE + iSignalNo, 127);
    2052     LIBCLOG_MSG("Calling DosExit(,127)\n");
     2064    LIBCLOG_MSG("Calling DosKillProcess()\n");
    20532065    for (;;)
    20542066    {
    20552067        DosKillProcess(DKP_PROCESS, 0);
    2056         DosExit(EXIT_THREAD, 127);
    2057     }
    2058 }
    2059 
    2060 /**
    2061  * Cause immediate process termination because of the given signal.
    2062  *
    2063  * @param   iSignalNo   Signal causing the termination.
    2064  */
    2065 static void signalTerminateAbnormal(int iSignalNo)
    2066 {
    2067     LIBCLOG_ENTER("iSignalNo=%d\n", iSignalNo);
    2068     /*
    2069      * Set the exit reason in SPM.
    2070      */
    2071     __libc_spmTerm(__LIBC_EXIT_REASON_SIGNAL_BASE + iSignalNo, 127);
    2072 
    2073     /*
    2074      * Before we go crazy here, let's release the semaphore.
    2075      *
    2076      * If possible we'll stay in the must complete section to
    2077      * be sure we get to the exit. If not we'll have to mess with
    2078      * exception handlers and such now.
    2079      */
    2080     //if (__libc_back_signalSemIsOwner())
    2081     //    DosReleaseMutexSem(ghmtxSignals);
    2082 
    2083     /*
    2084      * Terminate the exception handler chain to avoid recursive trouble.
    2085      */
    2086     FS_VAR();
    2087     FS_SAVE_LOAD();
    2088     PTIB pTib;
    2089     PPIB pPib;
    2090     DosGetInfoBlocks(&pTib, &pPib);
    2091     pTib->tib_pexchain = END_OF_CHAIN;
    2092 
    2093     /*
    2094      * Write message to stderr.
    2095      */
    2096     ULONG   cb;
    2097     if (iSignalNo == SIGABRT)
    2098     {
    2099         static const char szMsg[] = "\n\rAbnormal program termination";
    2100         DosWrite(HFILE_STDERR, szMsg, sizeof(szMsg) - 1, &cb);
    2101     }
    2102     else
    2103     {
    2104         static const char szMsg[] = "\n\rProcess terminated by ";
    2105         DosWrite(HFILE_STDERR, szMsg, sizeof(szMsg) - 1, &cb);
    2106 
    2107         const char *psz = "unknown signal";
    2108         if (iSignalNo < sizeof(gaszSignalNames) / sizeof(gaszSignalNames[0]))
    2109             psz = gaszSignalNames[iSignalNo];
    2110         for (cb = 0; psz[cb];)
    2111             cb++;
    2112         DosWrite(HFILE_STDERR, psz, cb, &cb);
    2113     }
    2114 
    2115     /* pid */
    2116     static const char szMsgPid[] = " - pid=0x";
    2117     DosWrite(HFILE_STDERR, szMsgPid, sizeof(szMsgPid) - 1, &cb);
    2118     char szHexNum[12];
    2119     cb = signalTerminateHex(szHexNum, pPib->pib_ulpid);
    2120     DosWrite(HFILE_STDERR, szHexNum, cb, &cb);
    2121 
    2122     /* tid */
    2123     static const char szMsgTid[] = " - tid=0x";
    2124     DosWrite(HFILE_STDERR, szMsgTid, sizeof(szMsgTid) - 1, &cb);
    2125     cb = signalTerminateHex(szHexNum, pTib->tib_ptib2->tib2_ultid);
    2126     DosWrite(HFILE_STDERR, szHexNum, cb, &cb);
    2127 
    2128     /* executable name. */
    2129     static char szExeName[CCHMAXPATH];
    2130     if (!DosQueryModuleName(pPib->pib_hmte, sizeof(szExeName), &szExeName[0]))
    2131     {
    2132         static const char szHypen[] = " - ";
    2133         DosWrite(HFILE_STDERR, szHypen, sizeof(szHypen) - 1, &cb);
    2134 
    2135         for (cb = 0; szExeName[cb];)
    2136             cb++;
    2137         DosWrite(HFILE_STDERR, szExeName, cb, &cb);
    2138     }
    2139 
    2140     /* final newline */
    2141     static const char szNewLine[] = "\r\n";
    2142     DosWrite(HFILE_STDERR, szNewLine, sizeof(szNewLine) - 1, &cb);
    2143 
    2144     /*
    2145      * Terminate the process.
    2146      */
    2147     LIBCLOG_MSG("Calling DosExit(,127)\n");
    2148     for (;;)
    2149     {
    2150         DosKillProcess(DKP_PROCESS, 0);
    2151         DosExit(EXIT_THREAD, 127);
    2152     }
    2153 }
     2068        DosExit(EXIT_PROCESS, 127);
     2069    }
     2070}
     2071
     2072
     2073/**
     2074 * Calculates the length of a string.
     2075 * @returns String length in bytes.
     2076 * @param   psz     Pointer to the string.
     2077 */
     2078static size_t signalTerminateStrLen(const char *psz)
     2079{
     2080    const char *pszEnd = psz;
     2081    while (*pszEnd)
     2082        pszEnd++;
     2083    return pszEnd - psz;
     2084}
     2085
    21542086
    21552087/**
     
    21592091 * @param   pszBuf  Where to store the formatted number.
    21602092 * @param   u       Number to format.
    2161  */
    2162 static int signalTerminateHex(char *pszBuf, unsigned u)
     2093 * @param   cDigits Minimum number of digits in the output. Use 0 for whatever fits.
     2094 */
     2095static int signalTerminateHex(char *pszBuf, unsigned u, unsigned cDigits)
    21632096{
    21642097    static const char szHex[17] = "0123456789abcdef";
    2165     if (u <= 0xff)
     2098    if (u <= 0xf && cDigits <= 1)
     2099    {
     2100        pszBuf[0] = szHex[u & 0xf];
     2101        pszBuf[1] = '\0';
     2102        return 1;
     2103    }
     2104    if (u <= 0xff && cDigits <= 2)
    21662105    {
    21672106        pszBuf[0] = szHex[u >> 4];
     
    21702109        return 2;
    21712110    }
    2172     else if (u <= 0xffff)
     2111    else if (u <= 0xffff && cDigits <= 4)
    21732112    {
    21742113        pszBuf[0] = szHex[u >> 12];
     
    21942133}
    21952134
     2135
     2136/**
     2137 * Cause immediate process termination because of the given signal.
     2138 *
     2139 * @param   iSignalNo       Signal causing the termination.
     2140 * @param   pvXcptParams    Pointer to the argument list of the OS/2 exception handler.
     2141 *                          NULL if not available.
     2142 */
     2143static void signalTerminateAbnormal(int iSignalNo, void *pvXcptParams)
     2144{
     2145    LIBCLOG_ENTER("iSignalNo=%d\n", iSignalNo);
     2146    /*
     2147     * Set the exit reason in SPM.
     2148     */
     2149    __libc_spmTerm(__LIBC_EXIT_REASON_SIGNAL_BASE + iSignalNo, 127);
     2150
     2151    /*
     2152     * Before we go crazy here, let's release the semaphore.
     2153     *
     2154     * If possible we'll stay in the must complete section to
     2155     * be sure we get to the exit. If not we'll have to mess with
     2156     * exception handlers and such now.
     2157     */
     2158    //if (__libc_back_signalSemIsOwner())
     2159    //    DosReleaseMutexSem(ghmtxSignals);
     2160
     2161    /*
     2162     * Terminate the exception handler chain to avoid recursive trouble.
     2163     */
     2164    FS_VAR();
     2165    FS_SAVE_LOAD();
     2166    PTIB pTib;
     2167    PPIB pPib;
     2168    DosGetInfoBlocks(&pTib, &pPib);
     2169    pTib->tib_pexchain = END_OF_CHAIN;
     2170
     2171    /*
     2172     * Write message to stderr.
     2173     */
     2174    ULONG   cb;
     2175    char szHexNum[12];
     2176#define SIG_PRINT_C(msg)  DosWrite(HFILE_STDERR, msg, sizeof(msg) - 1, &cb)
     2177#define SIG_PRINT_P(msg)  DosWrite(HFILE_STDERR, msg, signalTerminateStrLen(msg), &cb)
     2178#define SIG_PRINT_H(hex)  DosWrite(HFILE_STDERR, szHexNum, signalTerminateHex(szHexNum, hex, 0), &cb)
     2179#define SIG_PRINT_H16(hex)  DosWrite(HFILE_STDERR, szHexNum, signalTerminateHex(szHexNum, hex, 4), &cb)
     2180#define SIG_PRINT_H32(hex)  DosWrite(HFILE_STDERR, szHexNum, signalTerminateHex(szHexNum, hex, 8), &cb)
     2181    if (iSignalNo == SIGABRT)
     2182        SIG_PRINT_C("\n\rAbnormal program termination");
     2183    else
     2184    {
     2185        SIG_PRINT_C("\n\rProcess terminated by ");
     2186
     2187        if (iSignalNo < sizeof(gaszSignalNames) / sizeof(gaszSignalNames[0]))
     2188            SIG_PRINT_P(gaszSignalNames[iSignalNo]);
     2189        else
     2190        {
     2191            SIG_PRINT_C("unknown signal ");
     2192            SIG_PRINT_H(iSignalNo);
     2193        }
     2194    }
     2195
     2196    /* pid */
     2197    SIG_PRINT_C(" - pid=0x"); SIG_PRINT_H16(pPib->pib_ulpid);
     2198
     2199    /* tid */
     2200    SIG_PRINT_C(" - tid=0x"); SIG_PRINT_H16(pTib->tib_ptib2->tib2_ultid);
     2201
     2202    /* executable name. */
     2203    static char szExeName[CCHMAXPATH];
     2204    if (!DosQueryModuleName(pPib->pib_hmte, sizeof(szExeName), &szExeName[0]))
     2205    {
     2206        static const char szHypen[] = " - ";
     2207        DosWrite(HFILE_STDERR, szHypen, sizeof(szHypen) - 1, &cb);
     2208
     2209        for (cb = 0; szExeName[cb];)
     2210            cb++;
     2211        DosWrite(HFILE_STDERR, szExeName, cb, &cb);
     2212    }
     2213
     2214    /* eip */
     2215    PCONTEXTRECORD pCtx;
     2216    if (    pvXcptParams
     2217        &&  (pCtx = ((PEXCPTPARAMS)pvXcptParams)->pCtx))
     2218    {
     2219        SIG_PRINT_C("\r\ncs:eip=");
     2220        SIG_PRINT_H16(pCtx->ctx_SegCs);
     2221        SIG_PRINT_C(":");
     2222        SIG_PRINT_H32(pCtx->ctx_RegEip);
     2223        if (pCtx->ctx_RegEip >= 0x10000)
     2224        {
     2225            HMODULE hmod;
     2226            ULONG iObj = 0;
     2227            ULONG offObj = 0;
     2228            if (!DosQueryModFromEIP(&hmod, &iObj, sizeof(szExeName), szExeName, &offObj, pCtx->ctx_RegEip))
     2229            {
     2230                SIG_PRINT_C(" - ");
     2231                SIG_PRINT_H(iObj);
     2232                SIG_PRINT_C(":");
     2233                SIG_PRINT_H32(offObj);
     2234                SIG_PRINT_C(" ");
     2235                SIG_PRINT_P(szExeName);
     2236            }
     2237        }
     2238    }
     2239
     2240    /* final newline */
     2241    SIG_PRINT_C("\r\n");
     2242
     2243    /*
     2244     * Terminate the process.
     2245     */
     2246    LIBCLOG_MSG("Calling DosKillProcess()\n");
     2247    for (;;)
     2248    {
     2249        DosKillProcess(DKP_PROCESS, 0);
     2250        DosExit(EXIT_PROCESS, 127);
     2251    }
     2252}
     2253
     2254
    21962255/**
    21972256 * Stop the process (job control emulation).
     
    22222281    return __libc_back_signalSemRequest();
    22232282}
     2283
    22242284
    22252285/**
Note: See TracChangeset for help on using the changeset viewer.