VirtualBox

Changeset 32403 in vbox


Ignore:
Timestamp:
Sep 10, 2010 1:09:44 PM (14 years ago)
Author:
vboxsync
Message:

r=bird: Quick glance at the solaris core dumper.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r32360 r32403  
    54125412            pszDumpDir = NULL;
    54135413
    5414         int vrc = VERR_GENERAL_FAILURE;
     5414        int vrc;
    54155415        if (   pszDumpDir
    54165416            && !RTDirExists(pszDumpDir))
  • trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.cpp

    r32377 r32403  
    6161*   Globals                                                                    *
    6262*******************************************************************************/
    63 volatile static uint64_t   g_CoreDumpThread = NIL_RTTHREAD;
    64 volatile static bool       g_fCoreDumpSignalSetup = false;
    65 volatile static bool       g_fCoreDumpDeliberate = false;
    66 volatile static bool       g_fCoreDumpInProgress = false;
    67 volatile static uint32_t   g_fCoreDumpFlags = 0;
    68 static char                g_szCoreDumpDir[PATH_MAX] = { 0 };
    69 static char                g_szCoreDumpFile[PATH_MAX] = { 0 };
     63volatile static RTNATIVETHREAD volatile g_CoreDumpThread = NIL_RTNATIVETHREAD;
     64volatile static bool volatile      g_fCoreDumpSignalSetup       = false;
     65volatile static bool volatile      g_fCoreDumpDeliberate        = false;
     66volatile static uint32_t volatile  g_fCoreDumpFlags             = 0;
     67static char                        g_szCoreDumpDir[PATH_MAX]    = { 0 };
     68static char                        g_szCoreDumpFile[PATH_MAX]   = { 0 };
    7069
    7170
     
    282281    cb += _128K;
    283282    void *pv = mmap(NULL, cb, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 /* fd */, 0 /* offset */);
    284     if (pv)
     283    if (pv != MAP_FAILED)
    285284    {
    286285        CORELOG((CORELOG_NAME "AllocMemoryArea: memory area of %u bytes allocated.\n", cb));
     
    11521151        size_t cbInfoHdrAndData = u64Size < ~(size_t)0 ? u64Size : ~(size_t)0;
    11531152        void *pvInfoHdr = mmap(NULL, cbInfoHdrAndData, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 /* fd */, 0 /* offset */);
    1154         if (pvInfoHdr)
     1153        if (pvInfoHdr != MAP_FAILED)
    11551154        {
    11561155            rc = RTFileRead(hFile, pvInfoHdr, cbInfoHdrAndData, NULL);
     
    21232122    CORELOG((CORELOG_NAME "SignalHandler Sig=%d pvArg=%p\n", Sig, pvArg));
    21242123
    2125     int rc = VERR_GENERAL_FAILURE;
    2126     bool fCallSystemDump = false;
    2127     if (ASMAtomicUoReadBool(&g_fCoreDumpInProgress) == false)
    2128     {
    2129         ASMAtomicWriteBool(&g_fCoreDumpInProgress, true);
    2130         ASMAtomicWriteU64(&g_CoreDumpThread, (uint64_t)RTThreadSelf());
    2131 
     2124    RTNATIVETHREAD  hCurNativeThread = RTThreadNativeSelf();
     2125    int             rc               = VERR_GENERAL_FAILURE;
     2126    bool            fCallSystemDump  = false;
     2127    bool            fRc;
     2128    ASMAtomicCmpXchgHandle(&g_CoreDumpThread, hCurNativeThread, NIL_RTNATIVETHREAD, fRc);
     2129    if (fRc)
     2130    {
    21322131        rc = rtCoreDumperTakeDump((ucontext_t *)pvArg);
    2133 
    2134         ASMAtomicWriteU64(&g_CoreDumpThread, NIL_RTTHREAD);
    2135         ASMAtomicWriteBool(&g_fCoreDumpInProgress, false);
     2132        ASMAtomicWriteHandle(&g_CoreDumpThread, NIL_RTNATIVETHREAD);
    21362133
    21372134        if (RT_FAILURE(rc))
     
    21502147         * Wait only when the dumping thread is not the one generating this signal.
    21512148         */
    2152         if (ASMAtomicReadU64(&g_CoreDumpThread) == (uint64_t)RTThreadSelf())
     2149        RTNATIVETHREAD hNativeDumperThread;
     2150        ASMAtomicReadHandle(&g_CoreDumpThread, &hNativeDumperThread);
     2151        if (hNativeDumperThread == RTThreadNativeSelf())
    21532152        {
    21542153            CORELOGRELSYS((CORELOG_NAME "SignalHandler: Core dumper (thread %u) crashed Sig=%d. Triggering system dump\n",
     
    21642163            CORELOGRELSYS((CORELOG_NAME "SignalHandler: Core dump already in progress! Waiting a while for completion Sig=%d.\n", Sig));
    21652164            int64_t iTimeout = 16000;  /* timeout (ms) */
    2166             while (ASMAtomicReadBool(&g_fCoreDumpInProgress) == true)
     2165            for (;;)
    21672166            {
     2167                ASMAtomicReadHandle(&g_CoreDumpThread, &hNativeDumperThread);
     2168                if (hNativeDumperThread == NIL_RTNATIVETHREAD)
     2169                    break;
    21682170                RTThreadSleep(200);
    21692171                iTimeout -= 200;
     
    22042206
    22052207
    2206 /**
    2207  * Take a core dump of the current process without terminating it.
    2208  *
    2209  * @returns IPRT status code.
    2210  * @param   pszOutputFile       Name of the core file.  If NULL use the
    2211  *                              default naming scheme.
    2212  * @param   fLiveCore           When true, the process is not killed after
    2213  *                              taking a core. Otherwise it will be killed. This
    2214  *                              works in conjuction with the flags set during
    2215  *                              RTCoreDumperSetup().
    2216  */
    22172208RTDECL(int) RTCoreDumperTakeDump(const char *pszOutputFile, bool fLiveCore)
    22182209{
     2210    /** @todo r=bird: No setup should be required for this call and it
     2211     * shouldn't change the globals.
     2212     *
     2213     * Would probably be best to serialize RTCoreDumperTakeDump callers using a
     2214     * lazily initialized critsect (see RTOnce) and use different globals to
     2215     * communicate with the signal handlers.
     2216     *
     2217     * Another improvement is to use getcontext() to get the thread context and
     2218     * call rtCoreDumperTakeDump directly.  Extend rtCoreDumperTakeDump so that
     2219     * it takes pszOutputFile as an optional argument.  Mask the other fatal +
     2220     * SIGUSR2 while doing this.
     2221     */
     2222
    22192223    /*
    22202224     * Validate input.
     
    22462250
    22472251
    2248 /**
    2249  * Sets up and enables the core dumper.
    2250  *
    2251  * Installs signal / unhandled exception handlers for catching fatal errors
    2252  * that should result in a core dump.  If you wish to install your own handlers
    2253  * you should do that after calling this function and make sure you pass on
    2254  * events you don't handle.
    2255  *
    2256  * This can be called multiple times to change the settings without needing to
    2257  * call RTCoreDumperDisable in between.
    2258  *
    2259  * @param   pszOutputDir        The directory to store the cores in.  If NULL
    2260  *                              the current directory will be used.
    2261  * @param   pszBaseName         Base file name, no directory.  If NULL the
    2262  *                              dumper will generate an appropriate name.
    2263  * @param   fFlags              Setup flags, see RTCOREDUMPER_FLAGS_*.
    2264  */
    22652252RTDECL(int) RTCoreDumperSetup(const char *pszOutputDir, uint32_t fFlags)
    22662253{
     
    22682255     * Validate flags.
    22692256     */
    2270     AssertReturn(fFlags, VERR_INVALID_PARAMETER);
     2257    AssertReturn(fFlags, VERR_INVALID_PARAMETER); /** @todo r=bird: Update the function docs to reflect this.  It currently reads
     2258                                                   * as if RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP was standard behavior.
     2259                                                   * The SIGUSR2/RTCOREDUMPER_FLAGS_LIVE_CORE behavior isn't mentioned at all. */
    22712260    AssertReturn(!(fFlags & ~(  RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP
    22722261                              | RTCOREDUMPER_FLAGS_LIVE_CORE)),
    22732262                 VERR_INVALID_PARAMETER);
    22742263
     2264/** @todo r=bird: The idea here was that we shouldn't register the handler
     2265 *        more than once.  I.e. skip it if g_fCoreDumpSignalSetup and the
     2266 *        flags didn't change in any way.  The rational/usecase is that that
     2267 *        allows the user to chain handlers before our SIGSEGV/SIGBUS/SIGTRAP
     2268 *        core dumping + crashing handler.  Since we're registering our stuff
     2269 *        in Main somewhere it's important that only the first call messes with
     2270 *        the signal handlers.  The front end could for instance do a
     2271 *        RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP |
     2272 *        RTCOREDUMPER_FLAGS_LIVE_CORE) call in it's main() before setting up
     2273 *        it's own SIGBUS/SIGSEGV/SIGTRAP handlers.
     2274 *
     2275 *        Adding the conditional registration via the two flags complicates
     2276 *        the implementation of this use case. */
    22752277    /*
    22762278     * Install core dump signal handler.
     
    22792281    RT_ZERO(sigAct);
    22802282    sigAct.sa_sigaction = &rtCoreDumperSignalHandler;
    2281     sigemptyset(&sigAct.sa_mask);
    2282     sigAct.sa_flags = SA_RESTART | SA_SIGINFO | SA_NODEFER;
     2283    sigemptyset(&sigAct.sa_mask); /** @todo r=bird: We're probably better off blocking all signals here. */
     2284    sigAct.sa_flags = SA_RESTART | SA_SIGINFO | SA_NODEFER; /** @todo r=bird: SA_NODEFER doesn't make sense for SIGUSR2. For the hardware triggered ones, I don't think you can efficiently mask them, but it doesn't hurt playing safe ofc. */
    22832285
    22842286    if (fFlags & RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP)
     
    22862288        sigaction(SIGSEGV, &sigAct, NULL);
    22872289        sigaction(SIGBUS, &sigAct, NULL);
     2290/** @todo Add SIGTRAP or release+fatal assertions. */
    22882291    }
    22892292
     
    23032306
    23042307
    2305 /**
    2306  * Disables the core dumper, i.e. undoes what RTCoreDumperSetup did.
    2307  *
    2308  * @returns IPRT status code.
    2309  */
    23102308RTDECL(int) RTCoreDumperDisable(void)
    23112309{
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette