coredumper-solaris.cpp revision e68a03ea87defe18d436b00e60a8594f30e7f473
/* $Id$ */
/** @file
* IPRT Testcase - Core Dumper.
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
#include "tstRTCoreDump.h"
#ifdef RT_OS_SOLARIS
# include <signal.h>
# include <unistd.h>
# include <errno.h>
# include <zone.h>
# include <sys/sysmacros.h>
# include <sys/systeminfo.h>
#endif /* RT_OS_SOLARIS */
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
#define CORELOGREL(a) RTPrintf a
/**
* VBOXSOLCORETYPE: Whether this is an old or new style core.
*/
typedef enum VBOXSOLCORETYPE
{
static unsigned volatile g_cErrors = 0;
volatile bool g_fCoreDumpInProgress = false;
/**
* Determines endianness of the system. Just for completeness.
*
* @return Will return false if system is little endian, true otherwise.
*/
static bool IsBigEndian()
{
const int i = 1;
char *p = (char *)&i;
if (p[0] == 1)
return false;
return true;
}
/**
* Reads from a file making sure an interruption doesn't cause a failure.
*
* @param hFile Handle to the file to read.
* @param pv Where to store the read data.
* @param cbToRead Size of data to read.
*
* @return VBox status code.
*/
{
int rc = VERR_READ_ERROR;
while (1)
{
if (rc == VERR_INTERRUPTED)
continue;
break;
}
return rc;
}
/**
* Writes to a file making sure an interruption doesn't cause a failure.
*
* @param hFile Handle to the file to write.
* @param pv Pointer to what to write.
* @param cbToRead Size of data to write.
*
* @return VBox status code.
*/
{
int rc = VERR_READ_ERROR;
while (1)
{
if (rc == VERR_INTERRUPTED)
continue;
break;
}
return rc;
}
/**
* Read from a given offet in the process' address space.
*
* @param pVBoxProc Pointer to the VBox process.
* @param pv Where to read the data into.
* @param cb Size of the read buffer.
* @param off Offset to read from.
*
* @return VINF_SUCCESS, if all the given bytes was read in, otherwise VERR_READ_ERROR.
*/
{
while (1)
{
if (rc == VERR_INTERRUPTED)
continue;
return rc;
}
}
/**
* Determines if the current process' architecture is suitable for dumping core.
*
* @param pVBoxProc Pointer to the VBox process.
*
* @return true if the architecture matches the current one.
*/
{
}
/**
* Helper function to get the size of a file given it's path.
*
* @param pszPath Pointer to the full path of the file.
*
* @return The size of the file in bytes.
*/
{
if (RT_SUCCESS(rc))
{
}
else
return cb;
}
/**
* Pre-compute and pre-allocate sufficient memory for dumping core.
* This is meant to be called once, as a single-large anonymously
* mapped memory area which will be used during the core dumping routines.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
struct VBOXSOLPREALLOCTABLE
{
const char *pszFilePath; /* Proc based path */
} aPreAllocTable[] = {
};
for (int i = 0; i < (int)RT_ELEMENTS(aPreAllocTable); i++)
{
RTStrPrintf(szPath, sizeof(szPath), aPreAllocTable[i].pszFilePath, (int)pVBoxCore->VBoxProc.Process);
if ( cbFile > 0
&& aPreAllocTable[i].cbEntry > 0
&& aPreAllocTable[i].cbAccounting > 0)
{
cb += ((cbFile - aPreAllocTable[i].cbHeader) / aPreAllocTable[i].cbEntry) * aPreAllocTable[i].cbAccounting;
}
}
/*
* Make Room for our own mapping accountant entry which will also be included in the core.
*/
cb += sizeof(VBOXSOLMAPINFO);
/*
* Allocate the required space, plus some extra room.
*/
void *pv = mmap(NULL, cb, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 /* fd */, 0 /* offset */);
if (pv)
{
return VINF_SUCCESS;
}
else
{
return VERR_NO_MEMORY;
}
}
/**
* Free memory area used by the core object.
*
* @param pVBoxCore Pointer to the core object.
*/
{
}
/**
* Get a chunk from the area of allocated memory.
*
* @param pVBoxCore Pointer to the core object.
* @param cb Size of requested chunk.
*
* @return Pointer to allocated memory, or NULL on failure.
*/
{
{
return pb;
}
return NULL;
}
/**
* Reads the proc file's content into a newly allocated buffer.
*
* @param pVBoxCore Pointer to the core object.
* @param pszFileFmt Only the name of the file to read from (/proc/<pid> will be prepended)
* @param ppv Where to store the allocated buffer.
* @param pcb Where to store size of the buffer.
*
* @return VBox status code.
*/
{
RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/%s", (int)pVBoxCore->VBoxProc.Process, pszProcFileName);
if (RT_SUCCESS(rc))
{
if (*pcb > 0)
{
if (*ppv)
else
rc = VERR_NO_MEMORY;
}
else
{
*pcb = 0;
}
}
else
return rc;
}
/**
* Read process information (format psinfo_t) from /proc.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Read process status (format pstatus_t) from /proc.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Read process credential information (format prcred_t + array of guid_t)
*
* @param pVBoxCore Pointer to the core object.
*
* @remarks Should not be called before successful call to @see AllocMemoryArea()
* @return VBox status code.
*/
{
}
/**
* Read process privilege information (format prpriv_t + array of priv_chunk_t)
*
* @param pVBoxCore Pointer to the core object.
*
* @remarks Should not be called before successful call to @see AllocMemoryArea()
* @return VBox status code.
*/
{
if (RT_FAILURE(rc))
return rc;
if (!pVBoxProc->pcPrivImpl)
{
CORELOGREL(("ReadProcPriv: getprivimplinfo returned NULL.\n"));
return VERR_INVALID_STATE;
}
return rc;
}
/**
* Read process LDT information (format array of struct ssd) from /proc.
*
* @param pVBoxProc Pointer to the core object.
*
* @remarks Should not be called before successful call to @see AllocMemoryArea()
* @return VBox status code.
*/
{
}
/**
* Read process auxiliary vectors (format auxv_t) for the process.
*
* @param pVBoxCore Pointer to the core object.
*
* @remarks Should not be called before successful call to @see AllocMemoryArea()
* @return VBox status code.
*/
{
if (RT_FAILURE(rc))
{
return rc;
}
{
{
if (RT_SUCCESS(rc))
{
/* Terminate list of vectors */
CORELOG(("ReadProcAuxVecs: cbAuxFile=%u auxv_t size %d cAuxVecs=%u\n", cbAuxFile, sizeof(auxv_t), pVBoxProc->cAuxVecs));
{
return VINF_SUCCESS;
}
else
{
}
}
else
}
else
{
rc = VERR_NO_MEMORY;
}
}
else
CORELOGREL(("ReadProcAuxVecs: aux file too small %u, expecting %u or more\n", cbAuxFile, sizeof(auxv_t)));
return rc;
}
/*
* Find an element in the process' auxiliary vector.
*/
{
{
{
}
}
return -1;
}
/**
* Read the process mappings (format prmap_t array).
*
* @param pVBoxCore Pointer to the core object.
*
* @remarks Should not be called before successful call to @see AllocMemoryArea()
* @return VBox status code.
*/
{
if (RT_FAILURE(rc))
return rc;
if (RT_SUCCESS(rc))
{
/*
* Allocate and read all the prmap_t objects from proc.
*/
{
if (pMap)
{
if (RT_SUCCESS(rc))
{
{
/*
* Allocate for each prmap_t object, a corresponding VBOXSOLMAPINFO object.
*/
pVBoxProc->pMapInfoHead = (PVBOXSOLMAPINFO)GetMemoryChunk(pVBoxCore, pVBoxProc->cMappings * sizeof(VBOXSOLMAPINFO));
if (pVBoxProc->pMapInfoHead)
{
/*
* Associate the prmap_t with the mapping info object.
*/
{
if (pPrev)
/*
* Make sure we can read the mapping, otherwise mark them to be skipped.
*/
uint64_t k = 0;
{
if (RT_FAILURE(rc2))
{
/*
* Instead of storing the actual mapping data which we failed to read, the core
* will contain an errno in place. So we adjust the prmap_t's size field too
* so the program header offsets match.
*/
break;
}
k += cb;
}
}
if (pPrev)
return VINF_SUCCESS;
}
else
{
CORELOGREL(("ReadProcMappings: GetMemoryChunk failed %u\n", pVBoxProc->cMappings * sizeof(VBOXSOLMAPINFO)));
rc = VERR_NO_MEMORY;
}
}
else
{
}
}
else
}
else
{
rc = VERR_NO_MEMORY;
}
}
}
else
return rc;
}
/**
* Reads the thread information for all threads in the process.
*
* @param pVBoxCore Pointer to the core object.
*
* @remarks Should not be called before successful call to @see AllocMemoryArea()
* @return VBox status code.
*/
{
/*
* Read the information for threads.
* Format: prheader_t + array of lwpsinfo_t's.
*/
if (RT_SUCCESS(rc))
{
/*
* Read the status of threads.
* Format: prheader_t + array of lwpstatus_t's.
*/
void *pvStatusHdr = NULL;
if (RT_SUCCESS(rc))
{
CORELOG(("ReadProcThreads: read info(%u) status(%u), threads:cInfo=%u cStatus=%u\n", cbInfoHdrAndData, cbStatusHdrAndData, cInfo, cStatus));
/*
* Minor sanity size check (remember sizeof lwpstatus_t & lwpsinfo_t is <= size in file per entry).
*/
{
/*
* Make sure we have a matching lstatus entry for an lpsinfo entry unless
* it is a zombie thread, in which case we will not have a matching lstatus entry.
*/
{
{
if ( cStatus == 0
{
CORELOGREL(("ReadProcThreads: cStatus = %u pStatuslwpid=%d infolwpid=%d\n", cStatus, pStatus->pr_lwpid, pInfo->pr_lwpid));
break;
}
cStatus--;
}
}
if (RT_SUCCESS(rc))
{
/*
* Threre can still be more lwpsinfo_t's than lwpstatus_t's, build the
* lists accordingly.
*/
if (pVBoxProc->pThreadInfoHead)
{
{
{
/*
* Adjust the context of the dumping thread to reflect the context
* when the core dump got initiated before whatever signal caused it.
*/
if ( pStatus /* noid droid */
{
memcpy(&pStatus->pr_fpreg, &pVBoxProc->pCurThreadCtx->uc_mcontext.fpregs, sizeof(pStatus->pr_fpreg));
CORELOG(("ReadProcThreads: patched dumper thread context with pre-dump time context.\n"));
}
}
else
{
}
if (pPrev)
}
if (pPrev)
return VINF_SUCCESS;
}
else
{
rc = VERR_NO_MEMORY;
}
}
else
}
else
{
CORELOGREL(("ReadProcThreads: huh!? cbStatusHdrAndData=%u prheader_t=%u entsize=%u\n", cbStatusHdrAndData,
CORELOGREL(("ReadProcThreads: huh!? cbInfoHdrAndData=%u entsize=%u\n", cbInfoHdrAndData, pStatusHdr->pr_entsize));
}
}
else
}
else
return rc;
}
/**
* Reads miscellaneous information that is collected as part of a core file.
* This may include platform name, zone name and other OS-specific information.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
#ifdef RT_OS_SOLARIS
/*
* Read the platform name, uname string and zone name.
*/
if (rc == -1)
{
return VERR_GENERAL_FAILURE;
}
if (rc == -1)
{
return VERR_GENERAL_FAILURE;
}
rc = getzonenamebyid(pVBoxProc->ProcInfo.pr_zoneid, pVBoxProc->szZoneName, sizeof(pVBoxProc->szZoneName));
if (rc < 0)
{
CORELOGREL(("ReadProcMiscInfo: getzonenamebyid failed. rc=%d errno=%d zoneid=%d\n", rc, errno, pVBoxProc->ProcInfo.pr_zoneid));
return VERR_GENERAL_FAILURE;
}
rc = VINF_SUCCESS;
#else
#endif
return rc;
}
/**
* On Solaris use the old-style procfs interfaces but the core file still should have this
* info. for backward and GDB compatibility, hence the need for this ugly function.
*
* @param pVBoxCore Pointer to the core object.
* @param pInfo Pointer to the old prpsinfo_t structure to update.
*/
{
pInfo->pr_aslwpid = 0;
}
/**
* On Solaris use the old-style procfs interfaces but the core file still should have this
* info. for backward and GDB compatibility, hence the need for this ugly function.
*
* @param pVBoxCore Pointer to the core object.
* @param pInfo Pointer to the thread info.
* @param pStatus Pointer to the thread status.
* @param pDst Pointer to the old-style status structure to update.
*
*/
void GetOldProcessStatus(PVBOXCORE pVBoxCore, lwpsinfo_t *pInfo, lwpstatus_t *pStatus, prstatus_t *pDst)
{
/* PR_PTRACE is never set */
}
/**
* Count the number of sections which will be dumped into the core file.
*
* @param pVBoxCore Pointer to the core object.
*
* @return Number of sections for the core file.
*/
{
/* @todo sections */
return 0;
}
/**
* Resume all threads of this process.
*
* @param pVBoxProc Pointer to the VBox process.
*
* @return VBox error code.
*/
{
char szCurThread[128];
int32_t cRunningThreads = 0;
if (RT_SUCCESS(rc))
{
/*
* Loop through all our threads & resume them.
*/
{
continue;
continue;
}
}
else
{
}
return rc;
}
/**
* Stop all running threads of this process. Before dumping any
* core we need to make sure the process is quiesced.
*
* @param pVBoxProc Pointer to the VBox process.
*
* @return VBox error code.
*/
{
char szCurThread[128];
int rc = -1;
{
uint32_t cRunningThreads = 0;
if (RT_SUCCESS(rc))
{
/*
* Loop through all our threads & suspend them, multiple calls to _lwp_suspend() are okay.
*/
{
continue;
continue;
}
{
rc = VINF_SUCCESS;
break;
}
}
else
{
break;
}
}
if (RT_SUCCESS(rc))
return rc;
}
/**
* Returns size of an ELF NOTE header given the size of data the NOTE section will contain.
*
* @param cb Size of the data.
*
* @return Size of data actually used for NOTE header and section.
*/
{
}
/**
* Write an ELF NOTE header into the core file.
*
* @param pVBoxCore Pointer to the core object.
* @param Type Type of this NOTE section.
* @param pcv Opaque pointer to the data, if NULL only computes size.
* @param cb Size of the data.
*
* @return VBox status code.
*/
{
int rc = VERR_GENERAL_FAILURE;
#ifdef RT_OS_SOLARIS
/*
* Write note header and description.
*/
if (RT_SUCCESS(rc))
if (RT_FAILURE(rc))
#else
#endif
return rc;
}
/**
* Computes the size of NOTE section for the given core type.
* Solaris has two types of program header information (new and old).
*
* @param pVBoxCore Pointer to the core object.
* @param enmType Type of core file information required.
*
* @return Size of NOTE section.
*/
{
switch (enmType)
{
case enmOldEra:
{
while (pThreadInfo)
{
if (pThreadInfo->pStatus)
{
}
}
break;
}
case enmNewEra:
{
if (pVBoxProc->pcPrivImpl)
while (pThreadInfo)
{
if (pThreadInfo->pStatus)
}
break;
}
default:
{
break;
}
}
return cb;
}
/**
* Write the note section for the given era into the core file.
* Solaris has two types of program header information (new and old).
*
* @param pVBoxCore Pointer to the core object.
* @param enmType Type of core file information required.
*
* @return VBox status code.
*/
{
int rc = VERR_GENERAL_FAILURE;
#ifdef RT_OS_SOLARIS
typedef struct ELFWRITENOTE
{
const char *pszType;
const void *pcv;
} ELFWRITENOTE;
switch (enmType)
{
case enmOldEra:
{
{
};
for (unsigned i = 0; i < RT_ELEMENTS(aElfNotes); i++)
{
if (RT_FAILURE(rc))
{
CORELOGREL(("ElfWriteNoteSection: ElfWriteNoteHeader failed for %s. rc=%Rrc\n", aElfNotes[i].pszType, rc));
break;
}
}
/*
* Write old-style thread info., they contain nothing about zombies,
* so we just skip if there is no status information for them.
*/
{
if (!pThreadInfo->pStatus)
continue;
if (RT_SUCCESS(rc))
{
rc = ElfWriteNoteHeader(pVBoxCore, NT_PRFPREG, &pThreadInfo->pStatus->pr_fpreg, sizeof(prfpregset_t));
if (RT_FAILURE(rc))
{
break;
}
}
else
{
break;
}
}
break;
}
case enmNewEra:
{
{
{ "NT_PRPRIVINFO", NT_PRPRIVINFO, pVBoxProc->pcPrivImpl, PRIV_IMPL_INFO_SIZE(pVBoxProc->pcPrivImpl) },
};
for (unsigned i = 0; i < RT_ELEMENTS(aElfNotes); i++)
{
if (RT_FAILURE(rc))
{
CORELOGREL(("ElfWriteNoteSection: ElfWriteNoteHeader failed for %s. rc=%Rrc\n", aElfNotes[i].pszType, rc));
break;
}
}
/*
* Write new-style thread info., missing lwpstatus_t indicates it's a zombie thread
* we only dump the lwpsinfo_t in that case.
*/
{
if (RT_FAILURE(rc))
{
break;
}
if (pThreadInfo->pStatus)
{
if (RT_FAILURE(rc))
{
break;
}
}
}
break;
}
default:
{
break;
}
}
#else
#endif
return rc;
}
/**
* Write mappings into the core file.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
int rc = VERR_GENERAL_FAILURE;
while (pMapInfo)
{
{
uint64_t k = 0;
{
if (RT_FAILURE(rc2))
{
return VERR_INVALID_STATE;
}
if (RT_FAILURE(rc))
{
return rc;
}
k += cb;
}
}
else
{
CORELOGREL(("ElfWriteMappings: Huh!? something is wrong!\n"));
if (RT_FAILURE(rc))
{
return rc;
}
}
}
return VINF_SUCCESS;
}
/**
* Write program headers for all mappings into the core file.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
int rc = VERR_GENERAL_FAILURE;
while (pMapInfo)
{
ProgHdr.p_vaddr = pMapInfo->pMap.pr_vaddr; /* Virtual address of this mapping in the process address space */
if (RT_FAILURE(rc))
{
return rc;
}
}
return rc;
}
/**
* Write a prepared core file using a user-passed in writer function, requires all threads
* to be in suspended state (i.e. called after CreateCore).
*
* @param pVBoxCore Pointer to the core object.
* @param pfnWriter Pointer to the writer function to override default writer (NULL uses default).
*
* @remarks Resumes all suspended threads, unless it's an invalid core.
* @return VBox status.
*/
{
return VERR_INVALID_STATE;
if (pfnWriter)
/*
* Open the process address space file.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Create the core file.
*/
RTStrPrintf(szPath, sizeof(szPath), "/export/home/ram/vbox/out/solaris.amd64/release/bin/%s", pVBoxCore->szCorePath, pVBoxCore->VBoxProc.Process); /* @todo fix this */
rc = RTFileOpen(&pVBoxCore->hCoreFile, szPath, RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE | RTFILE_O_READWRITE | RTFILE_O_DENY_ALL);
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Write the ELF header.
*/
#ifdef RT_ARCH_AMD64
#else
#endif
else
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Setup program header.
*/
/*
* Write old-style NOTE program header.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Write new-style NOTE program header.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Write program headers per mapping.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Write old-style note section.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Write new-style section.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
/*
* Write all mappings.
*/
if (RT_FAILURE(rc))
{
goto WriteCoreDone;
}
{
}
{
}
return rc;
}
/**
* Takes a process snapshot into a passed-in core object. It has the side-effect of halting
* all threads which can lead to things like spurious wakeups of threads (if and when threads
* are ultimately resumed en-masse) already suspended while calling this function.
*
* @param pVBoxCore Pointer to a core object.
* @param pContext Pointer to the caller context thread.
*
* @remarks Halts all threads.
* @return VBox status code.
*/
{
/*
* Initialize core structures.
*/
RTProcGetExecutableName(pVBoxProc->szExecPath, sizeof(pVBoxProc->szExecPath)); /* this gets full path not just name */
RTStrPrintf(pVBoxCore->szCorePath, sizeof(pVBoxCore->szCorePath), "core.vb.%s.%d", pVBoxProc->pszExecName, (int)pVBoxProc->Process);
CORELOG(("tstRTCoreDump: Taking Core %s from Thread %d\n", pVBoxCore->szCorePath, (int)pVBoxProc->hCurThread));
/*
* Quiesce the process.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (IsProcArchNative(pVBoxProc))
{
/*
* Read process status, information such as number of active LWPs will be invalid since we just quiesced the process.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
struct COREACCUMULATOR
{
const char *pszName;
bool fOptional;
} aAccumulators[] =
{
{ "ReadProcLdt", &ReadProcLdt, false },
{ "ReadProcCred", &ReadProcCred, false },
{ "ReadProcPriv", &ReadProcPriv, false },
{ "ReadProcAuxVecs", &ReadProcAuxVecs, false },
{ "ReadProcMappings", &ReadProcMappings, false },
{ "ReadProcThreads", &ReadProcThreads, false },
{ "ReadProcMiscInfo", &ReadProcMiscInfo, false }
};
for (unsigned i = 0; i < RT_ELEMENTS(aAccumulators); i++)
{
if (RT_FAILURE(rc))
{
if (!aAccumulators[i].fOptional)
break;
}
}
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
else
}
else
}
else
{
CORELOGREL(("DumpCore: IsProcArchNative failed.\n"));
}
}
else
/*
* Resume threads on failure.
*/
}
else
return rc;
}
/**
* Destroy an existing core object.
*
* @param pVBoxCore Pointer to the core object.
*
* @return VBox status code.
*/
{
return VERR_INVALID_STATE;
return VINF_SUCCESS;
}
{
if (!pContext)
CORELOGREL(("CoreSigHandler: Missing context.\n"));
else
{
{
ASMAtomicWriteBool(&g_fCoreDumpInProgress, true);
/*
* Take a snapshot, then dump core to disk, all threads except this one are halted
* from before taking the snapshot until writing the core is completely finished.
* Any errors would resume all threads if they were halted.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
CORELOG(("CoreSigHandler: Successfully wrote core file to disk.\n"));
else
}
else
ASMAtomicWriteBool(&g_fCoreDumpInProgress, false);
}
else
{
/* @todo detect if we are awaiting for ourselves, if so don't. */
CORELOGREL(("CoreSigHandler: Core dump already in progress! Waiting before signalling Sig=%d.\n", Sig));
while (!ASMAtomicUoReadBool(&g_fCoreDumpInProgress))
{
RTThreadSleep(200);
iTimeout -= 200;
if (iTimeout <= 0)
break;
}
if (iTimeout <= 0)
}
}
}
{
sleep(10000);
return VINF_SUCCESS;
}
int main()
{
RTR3Init();
/*
* Install core dump signal handler.
*/
/*
* Spawn a few threads.
*/
for (unsigned i = 0; i < RT_ELEMENTS(ahThreads); i++)
{
int rc = RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1");
if (RT_FAILURE(rc))
{
g_cErrors++;
ahThreads[i] = NIL_RTTHREAD;
break;
}
}
/*
* Send signal to dump core.
*/
g_cErrors++;
sleep(10);
/*
* Summary.
*/
if (!g_cErrors)
CORELOG(("tstRTCoreDump: SUCCESS\n"));
else
return !!g_cErrors;
}