Lines Matching refs:pSolCore

287  * @param pSolCore          Pointer to the core object.
291 static int AllocMemoryArea(PRTSOLCORE pSolCore)
293 AssertReturn(pSolCore->pvCore == NULL, VERR_ALREADY_EXISTS);
316 RTStrPrintf(szPath, sizeof(szPath), s_aPreAllocTable[i].pszFilePath, (int)pSolCore->SolProc.Process);
341 pSolCore->pvCore = pv;
342 pSolCore->pvFree = pv;
343 pSolCore->cbCore = cb;
354 * @param pSolCore Pointer to the core object.
356 static void FreeMemoryArea(PRTSOLCORE pSolCore)
358 AssertReturnVoid(pSolCore);
359 AssertReturnVoid(pSolCore->pvCore);
360 AssertReturnVoid(pSolCore->cbCore > 0);
362 munmap(pSolCore->pvCore, pSolCore->cbCore);
363 CORELOG((CORELOG_NAME "FreeMemoryArea: memory area of %u bytes freed.\n", pSolCore->cbCore));
365 pSolCore->pvCore = NULL;
366 pSolCore->pvFree= NULL;
367 pSolCore->cbCore = 0;
374 * @param pSolCore Pointer to the core object.
379 static void *GetMemoryChunk(PRTSOLCORE pSolCore, size_t cb)
381 AssertReturn(pSolCore, NULL);
382 AssertReturn(pSolCore->pvCore, NULL);
383 AssertReturn(pSolCore->pvFree, NULL);
385 size_t cbAllocated = (char *)pSolCore->pvFree - (char *)pSolCore->pvCore;
386 if (cbAllocated < pSolCore->cbCore)
388 char *pb = (char *)pSolCore->pvFree;
389 pSolCore->pvFree = pb + cb;
400 * @param pSolCore Pointer to the core object.
409 static int ProcReadFileInto(PRTSOLCORE pSolCore, const char *pszProcFileName, void **ppv, size_t *pcb)
411 AssertReturn(pSolCore, VERR_INVALID_POINTER);
414 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/%s", (int)pSolCore->SolProc.Process, pszProcFileName);
422 *ppv = GetMemoryChunk(pSolCore, *pcb);
448 * @param pSolCore Pointer to the core object.
452 static int ProcReadInfo(PRTSOLCORE pSolCore)
454 AssertReturn(pSolCore, VERR_INVALID_POINTER);
456 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
481 * @param pSolCore Pointer to the core object.
485 static int ProcReadStatus(PRTSOLCORE pSolCore)
487 AssertReturn(pSolCore, VERR_INVALID_POINTER);
489 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
515 * @param pSolCore Pointer to the core object.
520 static int ProcReadCred(PRTSOLCORE pSolCore)
522 AssertReturn(pSolCore, VERR_INVALID_POINTER);
524 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
525 return ProcReadFileInto(pSolCore, "cred", &pSolProc->pvCred, &pSolProc->cbCred);
532 * @param pSolCore Pointer to the core object.
537 static int ProcReadPriv(PRTSOLCORE pSolCore)
539 AssertReturn(pSolCore, VERR_INVALID_POINTER);
541 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
542 int rc = ProcReadFileInto(pSolCore, "priv", (void **)&pSolProc->pPriv, &pSolProc->cbPriv);
563 static int ProcReadLdt(PRTSOLCORE pSolCore)
565 AssertReturn(pSolCore, VERR_INVALID_POINTER);
567 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
568 return ProcReadFileInto(pSolCore, "ldt", &pSolProc->pvLdt, &pSolProc->cbLdt);
575 * @param pSolCore Pointer to the core object.
580 static int ProcReadAuxVecs(PRTSOLCORE pSolCore)
582 AssertReturn(pSolCore, VERR_INVALID_POINTER);
584 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
599 pSolProc->pAuxVecs = (auxv_t*)GetMemoryChunk(pSolCore, cbAuxFile + sizeof(auxv_t));
665 * @param pSolCore Pointer to the core object.
670 static int ProcReadMappings(PRTSOLCORE pSolCore)
672 AssertReturn(pSolCore, VERR_INVALID_POINTER);
674 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
696 prmap_t *pMap = (prmap_t*)GetMemoryChunk(pSolCore, cbMapFile);
708 pSolProc->pMapInfoHead = (PRTSOLCOREMAPINFO)GetMemoryChunk(pSolCore,
803 * @param pSolCore Pointer to the core object.
808 static int ProcReadThreads(PRTSOLCORE pSolCore)
810 AssertReturn(pSolCore, VERR_INVALID_POINTER);
812 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
821 int rc = ProcReadFileInto(pSolCore, "lpsinfo", &pvInfoHdr, &cbInfoHdrAndData);
830 rc = ProcReadFileInto(pSolCore, "lstatus", &pvStatusHdr, &cbStatusHdrAndData);
883 pSolProc->pThreadInfoHead = (PRTSOLCORETHREADINFO)GetMemoryChunk(pSolCore, cbThreadInfo);
965 * @param pSolCore Pointer to the core object.
969 static int ProcReadMiscInfo(PRTSOLCORE pSolCore)
971 AssertReturn(pSolCore, VERR_INVALID_POINTER);
973 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1015 * @param pSolCore Pointer to the core object.
1018 static void GetOldProcessInfo(PRTSOLCORE pSolCore, prpsinfo_t *pInfo)
1020 AssertReturnVoid(pSolCore);
1023 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1071 * @param pSolCore Pointer to the core object.
1077 static void GetOldProcessStatus(PRTSOLCORE pSolCore, lwpsinfo_t *pInfo, lwpstatus_t *pStatus, prstatus_t *pDst)
1079 AssertReturnVoid(pSolCore);
1084 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1158 * @param pSolCore Pointer to the core object.
1163 static int suspendThread(PRTSOLCORE pSolCore, void *pvThreadInfo)
1166 NOREF(pSolCore);
1170 if ((lwpid_t)pThreadInfo->pr_lwpid != pSolCore->SolProc.hCurThread)
1179 * @param pSolCore Pointer to the core object.
1184 static int resumeThread(PRTSOLCORE pSolCore, void *pvThreadInfo)
1187 NOREF(pSolCore);
1191 if ((lwpid_t)pThreadInfo->pr_lwpid != (lwpid_t)pSolCore->SolProc.hCurThread)
1200 * @param pSolCore Pointer to the core object.
1206 static int rtCoreDumperForEachThread(PRTSOLCORE pSolCore, uint64_t *pcThreads, PFNRTSOLCORETHREADWORKER pfnWorker)
1208 AssertPtrReturn(pSolCore, VERR_INVALID_POINTER);
1210 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1235 pfnWorker(pSolCore, pThreadInfo);
1258 * @param pSolCore Pointer to the core object.
1262 static int rtCoreDumperResumeThreads(PRTSOLCORE pSolCore)
1264 AssertReturn(pSolCore, VERR_INVALID_POINTER);
1267 return rtCoreDumperForEachThread(pSolCore, &cThreads, resumeThread);
1274 * @param pSolCore Pointer to the core object.
1278 static int rtCoreDumperSuspendThreads(PRTSOLCORE pSolCore)
1280 AssertPtrReturn(pSolCore, VERR_INVALID_POINTER);
1295 rc = rtCoreDumperForEachThread(pSolCore, &aThreads[cTries], suspendThread);
1325 * @param pSolCore Pointer to the core object.
1332 static int ElfWriteNoteHeader(PRTSOLCORE pSolCore, uint_t Type, const void *pcv, size_t cb)
1334 AssertReturn(pSolCore, VERR_INVALID_POINTER);
1337 AssertReturn(pSolCore->pfnWriter, VERR_WRITE_ERROR);
1338 AssertReturn(pSolCore->fdCoreFile >= 0, VERR_INVALID_HANDLE);
1362 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ElfNoteHdr, sizeof(ElfNoteHdr));
1365 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, pcv, cb);
1369 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, s_achPad, cbAlign - cb);
1386 * @param pSolCore Pointer to the core object.
1391 static size_t ElfNoteSectionSize(PRTSOLCORE pSolCore, RTSOLCORETYPE enmType)
1393 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1465 * @param pSolCore Pointer to the core object.
1470 static int ElfWriteNoteSection(PRTSOLCORE pSolCore, RTSOLCORETYPE enmType)
1472 AssertReturn(pSolCore, VERR_INVALID_POINTER);
1474 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1478 typedef int (*PFNELFWRITENOTEHDR)(PRTSOLCORE pSolCore, uint_t, const void *pcv, size_t cb);
1500 rc = ElfWriteNoteHeader(pSolCore, aElfNotes[i].Type, aElfNotes[i].pcv, aElfNotes[i].cb);
1520 GetOldProcessStatus(pSolCore, &pThreadInfo->Info, pThreadInfo->pStatus, &OldProcessStatus);
1521 rc = ElfWriteNoteHeader(pSolCore, NT_PRSTATUS, &OldProcessStatus, sizeof(prstatus_t));
1524 rc = ElfWriteNoteHeader(pSolCore, NT_PRFPREG, &pThreadInfo->pStatus->pr_fpreg, sizeof(prfpregset_t));
1558 rc = ElfWriteNoteHeader(pSolCore, aElfNotes[i].Type, aElfNotes[i].pcv, aElfNotes[i].cb);
1574 rc = ElfWriteNoteHeader(pSolCore, NT_LWPSINFO, &pThreadInfo->Info, sizeof(lwpsinfo_t));
1583 rc = ElfWriteNoteHeader(pSolCore, NT_LWPSTATUS, pThreadInfo->pStatus, sizeof(lwpstatus_t));
1612 * @param pSolCore Pointer to the core object.
1616 static int ElfWriteMappings(PRTSOLCORE pSolCore)
1618 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1638 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, achBuf, sizeof(achBuf));
1654 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &achBuf, sizeof(achBuf));
1672 * @param pSolCore Pointer to the core object.
1676 static int ElfWriteMappingHeaders(PRTSOLCORE pSolCore)
1678 AssertReturn(pSolCore, VERR_INVALID_POINTER);
1680 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1690 ProgHdr.p_offset = pSolCore->offWrite; /* Where this mapping is located in the core file */
1705 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ProgHdr, sizeof(ProgHdr));
1712 pSolCore->offWrite += ProgHdr.p_filesz;
1722 static int rtCoreDumperWriteCoreDoIt(PRTSOLCORE pSolCore, PFNRTCOREWRITER pfnWriter,
1725 pSolCore->offWrite = 0;
1755 int rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ElfHdr, sizeof(ElfHdr));
1773 pSolCore->offWrite += sizeof(ElfHdr) + cProgHdrs * sizeof(ProgHdr);
1774 ProgHdr.p_offset = pSolCore->offWrite;
1775 ProgHdr.p_filesz = ElfNoteSectionSize(pSolCore, enmOldEra);
1776 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ProgHdr, sizeof(ProgHdr));
1786 pSolCore->offWrite += ProgHdr.p_filesz;
1787 ProgHdr.p_offset = pSolCore->offWrite;
1788 ProgHdr.p_filesz = ElfNoteSectionSize(pSolCore, enmNewEra);
1789 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ProgHdr, sizeof(ProgHdr));
1799 pSolCore->offWrite += ProgHdr.p_filesz;
1800 rc = ElfWriteMappingHeaders(pSolCore);
1810 rc = ElfWriteNoteSection(pSolCore, enmOldEra);
1820 rc = ElfWriteNoteSection(pSolCore, enmNewEra);
1830 rc = ElfWriteMappings(pSolCore);
1845 * @param pSolCore Pointer to the core object.
1852 static int rtCoreDumperWriteCore(PRTSOLCORE pSolCore, PFNRTCOREWRITER pfnWriter)
1854 AssertReturn(pSolCore, VERR_INVALID_POINTER);
1856 if (!pSolCore->fIsValid)
1860 pSolCore->pfnWriter = pfnWriter;
1862 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1878 fd = open(pSolCore->szCorePath, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR);
1881 pSolCore->fdCoreFile = fd;
1886 rc = rtCoreDumperWriteCoreDoIt(pSolCore, pfnWriter, pSolProc);
1888 close(pSolCore->fdCoreFile);
1889 pSolCore->fdCoreFile = -1;
1894 CORELOGRELSYS((CORELOG_NAME "WriteCore: failed to open %s. rc=%Rrc\n", pSolCore->szCorePath, rc));
1905 rtCoreDumperResumeThreads(pSolCore);
1915 * @param pSolCore Pointer to a core object.
1923 static int rtCoreDumperCreateCore(PRTSOLCORE pSolCore, ucontext_t *pContext, const char *pszCoreFilePath)
1925 AssertReturn(pSolCore, VERR_INVALID_POINTER);
1931 memset(pSolCore, 0, sizeof(RTSOLCORE));
1932 pSolCore->pfnReader = &ReadFileNoIntr;
1933 pSolCore->pfnWriter = &WriteFileNoIntr;
1934 pSolCore->fIsValid = false;
1935 pSolCore->fdCoreFile = -1;
1937 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc;
1961 RTStrPrintf(pSolCore->szCorePath, sizeof(pSolCore->szCorePath), "%s/core.vb.%s.%d",
1965 RTStrPrintf(pSolCore->szCorePath, sizeof(pSolCore->szCorePath), "%s/core.vb.%s", g_szCoreDumpDir, g_szCoreDumpFile);
1968 RTStrCopy(pSolCore->szCorePath, sizeof(pSolCore->szCorePath), pszCoreFilePath);
1970 CORELOG((CORELOG_NAME "CreateCore: Taking Core %s from Thread %d\n", pSolCore->szCorePath, (int)pSolProc->hCurThread));
1975 int rc = rtCoreDumperSuspendThreads(pSolCore);
1978 rc = ProcReadInfo(pSolCore);
1981 GetOldProcessInfo(pSolCore, &pSolProc->ProcInfoOld);
1988 rc = ProcReadStatus(pSolCore);
1991 rc = AllocMemoryArea(pSolCore);
2012 rc = aAccumulators[i].pfnAcc(pSolCore);
2023 pSolCore->fIsValid = true;
2027 FreeMemoryArea(pSolCore);
2047 rtCoreDumperResumeThreads(pSolCore);
2059 * @param pSolCore Pointer to the core object.
2063 static int rtCoreDumperDestroyCore(PRTSOLCORE pSolCore)
2065 AssertReturn(pSolCore, VERR_INVALID_POINTER);
2066 if (!pSolCore->fIsValid)
2069 FreeMemoryArea(pSolCore);
2070 pSolCore->fIsValid = false;