Changeset 37631 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jun 24, 2011 1:25:07 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 72480
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.cpp
r37609 r37631 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT Testcase - Core Dumper.3 * IPRT - Custom Core Dumper, Solaris. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 25 25 */ 26 26 27 27 28 /******************************************************************************* 28 29 * Header Files * 29 30 *******************************************************************************/ 30 #define LOG_GROUP LOG_GROUP_CORE_DUMPER 31 #include <VBox/log.h> 31 #define LOG_GROUP RTLOGGROUP_DEFAULT 32 32 #include <iprt/coredumper.h> 33 #include <iprt/types.h> 34 #include <iprt/file.h> 33 34 #include <iprt/asm.h> 35 #include <iprt/dir.h> 35 36 #include <iprt/err.h> 36 #include <iprt/dir.h> 37 #include <iprt/log.h> 38 #include <iprt/param.h> 37 39 #include <iprt/path.h> 40 #include <iprt/process.h> 38 41 #include <iprt/string.h> 39 42 #include <iprt/thread.h> 40 #include <iprt/param.h>41 #include <iprt/asm.h>42 43 #include "coredumper-solaris.h" 43 44 … … 62 63 #include "internal/ldrELF64.h" 63 64 65 64 66 /******************************************************************************* 65 67 * Globals * … … 127 129 * Reads from a file making sure an interruption doesn't cause a failure. 128 130 * 129 * @param hFileHandle to the file to read.131 * @param fd Handle to the file to read. 130 132 * @param pv Where to store the read data. 131 133 * @param cbToRead Size of data to read. … … 133 135 * @return IPRT status code. 134 136 */ 135 static int ReadFileNoIntr(RTFILE hFile, void *pv, size_t cbToRead) 136 { 137 int rc = VERR_READ_ERROR; 138 while (1) 139 { 140 rc = RTFileRead(hFile, pv, cbToRead, NULL /* Read all */); 141 if (rc == VERR_INTERRUPTED) 142 continue; 143 break; 144 } 145 return rc; 137 static int ReadFileNoIntr(int fd, void *pv, size_t cbToRead) 138 { 139 for (;;) 140 { 141 ssize_t cbRead = read(fd, pv, cbToRead); 142 if (cbRead < 0) 143 { 144 if (errno == EINTR) 145 continue; 146 return RTErrConvertFromErrno(errno); 147 } 148 if ((size_t)cbRead == cbToRead) 149 return VINF_SUCCESS; 150 if ((size_t)cbRead > cbToRead) 151 return VERR_INTERNAL_ERROR_3; 152 if (cbRead == 0) 153 return VERR_EOF; 154 pv = (uint8_t *)pv + cbRead; 155 cbToRead -= cbRead; 156 } 146 157 } 147 158 … … 150 161 * Writes to a file making sure an interruption doesn't cause a failure. 151 162 * 152 * @param hFile Handle to the file to write.163 * @param fd Handle to the file to write to. 153 164 * @param pv Pointer to what to write. 154 * @param cbTo ReadSize of data to write.165 * @param cbToWrite Size of data to write. 155 166 * 156 167 * @return IPRT status code. 157 168 */ 158 static int WriteFileNoIntr(RTFILE hFile, const void *pcv, size_t cbToRead) 159 { 160 int rc = VERR_READ_ERROR; 161 while (1) 162 { 163 rc = RTFileWrite(hFile, pcv, cbToRead, NULL /* Write all */); 164 if (rc == VERR_INTERRUPTED) 165 continue; 166 break; 167 } 168 return rc; 169 static int WriteFileNoIntr(int fd, const void *pv, size_t cbToWrite) 170 { 171 for (;;) 172 { 173 ssize_t cbWritten = write(fd, pv, cbToWrite); 174 if (cbWritten < 0) 175 { 176 if (errno == EINTR) 177 continue; 178 return RTErrConvertFromErrno(errno); 179 } 180 if ((size_t)cbWritten == cbToWrite) 181 return VINF_SUCCESS; 182 if ((size_t)cbWritten > cbToWrite) 183 return VERR_INTERNAL_ERROR_2; 184 pv = (uint8_t const *)pv + cbWritten; 185 cbToWrite -= cbWritten; 186 } 169 187 } 170 188 … … 173 191 * Read from a given offset in the process' address space. 174 192 * 175 * @param p VBoxProc Pointer to the VBoxprocess.193 * @param pSolProc Pointer to the solaris process. 176 194 * @param pv Where to read the data into. 177 195 * @param cb Size of the read buffer. … … 180 198 * @return VINF_SUCCESS, if all the given bytes was read in, otherwise VERR_READ_ERROR. 181 199 */ 182 static ssize_t ProcReadAddrSpace(PVBOXPROCESS pVBoxProc, RTFOFF off, void *pvBuf, size_t cbToRead) 183 { 184 while (1) 185 { 186 int rc = RTFileReadAt(pVBoxProc->hAs, off, pvBuf, cbToRead, NULL); 187 if (rc == VERR_INTERRUPTED) 188 continue; 189 return rc; 200 static ssize_t ProcReadAddrSpace(PRTSOLCOREPROCESS pSolProc, RTFOFF off, void *pvBuf, size_t cbToRead) 201 { 202 for (;;) 203 { 204 ssize_t cbRead = pread(pSolProc->fdAs, pvBuf, cbToRead, off); 205 if (cbRead < 0) 206 { 207 if (errno == EINTR) 208 continue; 209 return RTErrConvertFromErrno(errno); 210 } 211 if ((size_t)cbRead == cbToRead) 212 return VINF_SUCCESS; 213 if ((size_t)cbRead > cbToRead) 214 return VERR_INTERNAL_ERROR_4; 215 if (cbRead == 0) 216 return VERR_EOF; 217 218 pvBuf = (uint8_t *)pvBuf + cbRead; 219 cbToRead -= cbRead; 220 off += cbRead; 190 221 } 191 222 } … … 195 226 * Determines if the current process' architecture is suitable for dumping core. 196 227 * 197 * @param p VBoxProc Pointer to the VBoxprocess.228 * @param pSolProc Pointer to the solaris process. 198 229 * 199 230 * @return true if the architecture matches the current one. 200 231 */ 201 static inline bool IsProcessArchNative(PVBOXPROCESS pVBoxProc) 202 { 203 return pVBoxProc->ProcInfo.pr_dmodel == PR_MODEL_NATIVE; 204 } 205 206 207 /** 208 * Helper function to get the size of a file given it's path. 209 * 210 * @param pszPath Pointer to the full path of the file. 211 * 212 * @return The size of the file in bytes. 213 */ 214 static size_t GetFileSize(const char *pszPath) 215 { 216 uint64_t cb = 0; 232 static inline bool IsProcessArchNative(PRTSOLCOREPROCESS pSolProc) 233 { 234 return pSolProc->ProcInfo.pr_dmodel == PR_MODEL_NATIVE; 235 } 236 237 238 /** 239 * Helper function to get the size_t compatible file size from a file 240 * descriptor. 241 * 242 * @return The file size (in bytes). 243 * @param fd The file descriptor. 244 */ 245 static size_t GetFileSizeByFd(int fd) 246 { 247 struct stat st; 248 if (fstat(fd, &st) == 0) 249 return st.st_size < ~(size_t)0 ? (size_t)st.st_size : ~(size_t)0; 250 251 CORELOGRELSYS((CORELOG_NAME "GetFileSizeByFd: fstat failed rc=%Rrc\n", RTErrConvertFromErrno(errno))); 252 return 0; 253 } 254 255 256 /** 257 * Helper function to get the size_t compatible size of a file given its path. 258 * 259 * @return The file size (in bytes). 260 * @param pszPath Pointer to the full path of the file. 261 */ 262 static size_t GetFileSizeByName(const char *pszPath) 263 { 217 264 int fd = open(pszPath, O_RDONLY); 218 if (fd >=0)219 { 220 RTFILE hFile = (RTFILE)(uintptr_t)fd;221 RTFileGetSize(hFile, &cb);222 RTFileClose(hFile);223 } 224 else225 CORELOGRELSYS((CORELOG_NAME "GetFileSize: failed to open %s rc=%Rrc\n", pszPath, RTErrConvertFromErrno(fd)));226 return cb < ~(size_t)0 ? (size_t)cb : ~(size_t)0;265 if (fd < 0) 266 { 267 CORELOGRELSYS((CORELOG_NAME "GetFileSizeByName: failed to open %s rc=%Rrc\n", pszPath, RTErrConvertFromErrno(errno))); 268 return 0; 269 } 270 271 size_t cb = GetFileSizeByFd(fd); 272 close(fd); 273 return cb; 227 274 } 228 275 … … 233 280 * mapped memory area which will be used during the core dumping routines. 234 281 * 235 * @param p VBoxCorePointer to the core object.282 * @param pSolCore Pointer to the core object. 236 283 * 237 284 * @return IPRT status code. 238 285 */ 239 static int AllocMemoryArea(P VBOXCORE pVBoxCore)240 { 241 AssertReturn(p VBoxCore->pvCore == NULL, VERR_ALREADY_EXISTS);242 243 st ruct VBOXSOLPREALLOCTABLE286 static int AllocMemoryArea(PRTSOLCORE pSolCore) 287 { 288 AssertReturn(pSolCore->pvCore == NULL, VERR_ALREADY_EXISTS); 289 290 static struct 244 291 { 245 292 const char *pszFilePath; /* Proc based path */ … … 247 294 size_t cbEntry; /* Size of each entry in file */ 248 295 size_t cbAccounting; /* Size of each accounting entry per entry */ 249 } aPreAllocTable[] = { 250 { "/proc/%d/map", 0, sizeof(prmap_t), sizeof(VBOXSOLMAPINFO) }, 296 } const s_aPreAllocTable[] = 297 { 298 { "/proc/%d/map", 0, sizeof(prmap_t), sizeof(RTSOLCOREMAPINFO) }, 251 299 { "/proc/%d/auxv", 0, 0, 0 }, 252 { "/proc/%d/lpsinfo", sizeof(prheader_t), sizeof(lwpsinfo_t), sizeof( VBOXSOLTHREADINFO) },300 { "/proc/%d/lpsinfo", sizeof(prheader_t), sizeof(lwpsinfo_t), sizeof(RTSOLCORETHREADINFO) }, 253 301 { "/proc/%d/lstatus", 0, 0, 0 }, 254 302 { "/proc/%d/ldt", 0, 0, 0 }, … … 258 306 259 307 size_t cb = 0; 260 for ( int i = 0; i < (int)RT_ELEMENTS(aPreAllocTable); i++)308 for (unsigned i = 0; i < RT_ELEMENTS(s_aPreAllocTable); i++) 261 309 { 262 310 char szPath[PATH_MAX]; 263 RTStrPrintf(szPath, sizeof(szPath), aPreAllocTable[i].pszFilePath, (int)pVBoxCore->VBoxProc.Process);264 size_t cbFile = GetFileSize (szPath);311 RTStrPrintf(szPath, sizeof(szPath), s_aPreAllocTable[i].pszFilePath, (int)pSolCore->SolProc.Process); 312 size_t cbFile = GetFileSizeByName(szPath); 265 313 cb += cbFile; 266 314 if ( cbFile > 0 267 && aPreAllocTable[i].cbEntry > 0)268 { 269 cb += ((cbFile - aPreAllocTable[i].cbHeader) / aPreAllocTable[i].cbEntry) * (aPreAllocTable[i].cbAccounting > 0 ?270 271 cb += aPreAllocTable[i].cbHeader;315 && s_aPreAllocTable[i].cbEntry > 0) 316 { 317 cb += ((cbFile - s_aPreAllocTable[i].cbHeader) / s_aPreAllocTable[i].cbEntry) 318 * (s_aPreAllocTable[i].cbAccounting > 0 ? s_aPreAllocTable[i].cbAccounting : 1); 319 cb += s_aPreAllocTable[i].cbHeader; 272 320 } 273 321 } … … 276 324 * Make room for our own mapping accountant entry which will also be included in the core. 277 325 */ 278 cb += sizeof( VBOXSOLMAPINFO);326 cb += sizeof(RTSOLCOREMAPINFO); 279 327 280 328 /* … … 286 334 { 287 335 CORELOG((CORELOG_NAME "AllocMemoryArea: memory area of %u bytes allocated.\n", cb)); 288 p VBoxCore->pvCore = pv;289 p VBoxCore->pvFree = pv;290 p VBoxCore->cbCore = cb;336 pSolCore->pvCore = pv; 337 pSolCore->pvFree = pv; 338 pSolCore->cbCore = cb; 291 339 return VINF_SUCCESS; 292 340 } 293 else 294 { 295 CORELOGRELSYS((CORELOG_NAME "AllocMemoryArea: failed cb=%u\n", cb)); 296 return VERR_NO_MEMORY; 297 } 341 CORELOGRELSYS((CORELOG_NAME "AllocMemoryArea: failed cb=%u\n", cb)); 342 return VERR_NO_MEMORY; 298 343 } 299 344 … … 302 347 * Free memory area used by the core object. 303 348 * 304 * @param p VBoxCorePointer to the core object.305 */ 306 static void FreeMemoryArea(P VBOXCORE pVBoxCore)307 { 308 AssertReturnVoid(p VBoxCore);309 AssertReturnVoid(p VBoxCore->pvCore);310 AssertReturnVoid(p VBoxCore->cbCore > 0);311 312 munmap(p VBoxCore->pvCore, pVBoxCore->cbCore);313 CORELOG((CORELOG_NAME "FreeMemoryArea: memory area of %u bytes freed.\n", p VBoxCore->cbCore));314 315 p VBoxCore->pvCore = NULL;316 p VBoxCore->pvFree= NULL;317 p VBoxCore->cbCore = 0;349 * @param pSolCore Pointer to the core object. 350 */ 351 static void FreeMemoryArea(PRTSOLCORE pSolCore) 352 { 353 AssertReturnVoid(pSolCore); 354 AssertReturnVoid(pSolCore->pvCore); 355 AssertReturnVoid(pSolCore->cbCore > 0); 356 357 munmap(pSolCore->pvCore, pSolCore->cbCore); 358 CORELOG((CORELOG_NAME "FreeMemoryArea: memory area of %u bytes freed.\n", pSolCore->cbCore)); 359 360 pSolCore->pvCore = NULL; 361 pSolCore->pvFree= NULL; 362 pSolCore->cbCore = 0; 318 363 } 319 364 … … 322 367 * Get a chunk from the area of allocated memory. 323 368 * 324 * @param p VBoxCorePointer to the core object.369 * @param pSolCore Pointer to the core object. 325 370 * @param cb Size of requested chunk. 326 371 * 327 372 * @return Pointer to allocated memory, or NULL on failure. 328 373 */ 329 static void *GetMemoryChunk(P VBOXCORE pVBoxCore, size_t cb)330 { 331 AssertReturn(p VBoxCore, NULL);332 AssertReturn(p VBoxCore->pvCore, NULL);333 AssertReturn(p VBoxCore->pvFree, NULL);334 335 size_t cbAllocated = (char *)p VBoxCore->pvFree - (char *)pVBoxCore->pvCore;336 if (cbAllocated < p VBoxCore->cbCore)337 { 338 char *pb = (char *)p VBoxCore->pvFree;339 p VBoxCore->pvFree = pb + cb;374 static void *GetMemoryChunk(PRTSOLCORE pSolCore, size_t cb) 375 { 376 AssertReturn(pSolCore, NULL); 377 AssertReturn(pSolCore->pvCore, NULL); 378 AssertReturn(pSolCore->pvFree, NULL); 379 380 size_t cbAllocated = (char *)pSolCore->pvFree - (char *)pSolCore->pvCore; 381 if (cbAllocated < pSolCore->cbCore) 382 { 383 char *pb = (char *)pSolCore->pvFree; 384 pSolCore->pvFree = pb + cb; 340 385 return pb; 341 386 } … … 348 393 * Reads the proc file's content into a newly allocated buffer. 349 394 * 350 * @param p VBoxCorePointer to the core object.395 * @param pSolCore Pointer to the core object. 351 396 * @param pszFileFmt Only the name of the file to read from (/proc/<pid> will be prepended) 352 397 * @param ppv Where to store the allocated buffer. … … 357 402 * respectively. 358 403 */ 359 static int ProcReadFileInto(P VBOXCORE pVBoxCore, const char *pszProcFileName, void **ppv, size_t *pcb)360 { 361 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);404 static int ProcReadFileInto(PRTSOLCORE pSolCore, const char *pszProcFileName, void **ppv, size_t *pcb) 405 { 406 AssertReturn(pSolCore, VERR_INVALID_POINTER); 362 407 363 408 char szPath[PATH_MAX]; 364 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/%s", (int)p VBoxCore->VBoxProc.Process, pszProcFileName);409 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/%s", (int)pSolCore->SolProc.Process, pszProcFileName); 365 410 int rc = VINF_SUCCESS; 366 411 int fd = open(szPath, O_RDONLY); 367 412 if (fd >= 0) 368 413 { 369 RTFILE hFile = (RTFILE)(uintptr_t)fd; 370 uint64_t u64Size; 371 RTFileGetSize(hFile, &u64Size); 372 *pcb = u64Size < ~(size_t)0 ? u64Size : ~(size_t)0; 414 *pcb = GetFileSizeByFd(fd); 373 415 if (*pcb > 0) 374 416 { 375 *ppv = GetMemoryChunk(p VBoxCore, *pcb);417 *ppv = GetMemoryChunk(pSolCore, *pcb); 376 418 if (*ppv) 377 rc = ReadFileNoIntr( hFile, *ppv, *pcb);419 rc = ReadFileNoIntr(fd, *ppv, *pcb); 378 420 else 379 421 rc = VERR_NO_MEMORY; … … 385 427 rc = VINF_SUCCESS; 386 428 } 387 RTFileClose(hFile);429 close(fd); 388 430 } 389 431 else … … 399 441 * Read process information (format psinfo_t) from /proc. 400 442 * 401 * @param p VBoxCorePointer to the core object.443 * @param pSolCore Pointer to the core object. 402 444 * 403 445 * @return IPRT status code. 404 446 */ 405 static int ProcReadInfo(P VBOXCORE pVBoxCore)406 { 407 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);408 409 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;447 static int ProcReadInfo(PRTSOLCORE pSolCore) 448 { 449 AssertReturn(pSolCore, VERR_INVALID_POINTER); 450 451 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 410 452 char szPath[PATH_MAX]; 411 453 int rc = VINF_SUCCESS; 412 454 413 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/psinfo", (int)p VBoxProc->Process);455 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/psinfo", (int)pSolProc->Process); 414 456 int fd = open(szPath, O_RDONLY); 415 457 if (fd >= 0) 416 458 { 417 RTFILE hFile = (RTFILE)(uintptr_t)fd;418 459 size_t cbProcInfo = sizeof(psinfo_t); 419 rc = ReadFileNoIntr( hFile, &pVBoxProc->ProcInfo, cbProcInfo);420 RTFileClose(hFile);460 rc = ReadFileNoIntr(fd, &pSolProc->ProcInfo, cbProcInfo); 461 close(fd); 421 462 } 422 463 else … … 433 474 * Read process status (format pstatus_t) from /proc. 434 475 * 435 * @param p VBoxCorePointer to the core object.476 * @param pSolCore Pointer to the core object. 436 477 * 437 478 * @return IPRT status code. 438 479 */ 439 static int ProcReadStatus(P VBOXCORE pVBoxCore)440 { 441 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);442 443 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;480 static int ProcReadStatus(PRTSOLCORE pSolCore) 481 { 482 AssertReturn(pSolCore, VERR_INVALID_POINTER); 483 484 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 444 485 445 486 char szPath[PATH_MAX]; 446 487 int rc = VINF_SUCCESS; 447 488 448 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/status", (int)p VBoxProc->Process);489 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/status", (int)pSolProc->Process); 449 490 int fd = open(szPath, O_RDONLY); 450 491 if (fd >= 0) 451 492 { 452 RTFILE hFile = (RTFILE)(uintptr_t)fd;453 size_t cbRead;454 493 size_t cbProcStatus = sizeof(pstatus_t); 455 AssertCompile(sizeof(pstatus_t) == sizeof(p VBoxProc->ProcStatus));456 rc = ReadFileNoIntr( hFile, &pVBoxProc->ProcStatus, cbProcStatus);457 RTFileClose(hFile);494 AssertCompile(sizeof(pstatus_t) == sizeof(pSolProc->ProcStatus)); 495 rc = ReadFileNoIntr(fd, &pSolProc->ProcStatus, cbProcStatus); 496 close(fd); 458 497 } 459 498 else … … 469 508 * Read process credential information (format prcred_t + array of guid_t) 470 509 * 471 * @param p VBoxCorePointer to the core object.510 * @param pSolCore Pointer to the core object. 472 511 * 473 512 * @remarks Should not be called before successful call to @see AllocMemoryArea() 474 513 * @return IPRT status code. 475 514 */ 476 static int ProcReadCred(P VBOXCORE pVBoxCore)477 { 478 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);479 480 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;481 return ProcReadFileInto(p VBoxCore, "cred", &pVBoxProc->pvCred, &pVBoxProc->cbCred);515 static int ProcReadCred(PRTSOLCORE pSolCore) 516 { 517 AssertReturn(pSolCore, VERR_INVALID_POINTER); 518 519 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 520 return ProcReadFileInto(pSolCore, "cred", &pSolProc->pvCred, &pSolProc->cbCred); 482 521 } 483 522 … … 486 525 * Read process privilege information (format prpriv_t + array of priv_chunk_t) 487 526 * 488 * @param p VBoxCorePointer to the core object.527 * @param pSolCore Pointer to the core object. 489 528 * 490 529 * @remarks Should not be called before successful call to @see AllocMemoryArea() 491 530 * @return IPRT status code. 492 531 */ 493 static int ProcReadPriv(P VBOXCORE pVBoxCore)494 { 495 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);496 497 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;498 int rc = ProcReadFileInto(p VBoxCore, "priv", (void **)&pVBoxProc->pPriv, &pVBoxProc->cbPriv);532 static int ProcReadPriv(PRTSOLCORE pSolCore) 533 { 534 AssertReturn(pSolCore, VERR_INVALID_POINTER); 535 536 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 537 int rc = ProcReadFileInto(pSolCore, "priv", (void **)&pSolProc->pPriv, &pSolProc->cbPriv); 499 538 if (RT_FAILURE(rc)) 500 539 return rc; 501 p VBoxProc->pcPrivImpl = getprivimplinfo();502 if (!p VBoxProc->pcPrivImpl)540 pSolProc->pcPrivImpl = getprivimplinfo(); 541 if (!pSolProc->pcPrivImpl) 503 542 { 504 543 CORELOGRELSYS((CORELOG_NAME "ProcReadPriv: getprivimplinfo returned NULL.\n")); … … 512 551 * Read process LDT information (format array of struct ssd) from /proc. 513 552 * 514 * @param p VBoxProc Pointer to the core object.553 * @param pSolProc Pointer to the core object. 515 554 * 516 555 * @remarks Should not be called before successful call to @see AllocMemoryArea() 517 556 * @return IPRT status code. 518 557 */ 519 static int ProcReadLdt(P VBOXCORE pVBoxCore)520 { 521 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);522 523 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;524 return ProcReadFileInto(p VBoxCore, "ldt", &pVBoxProc->pvLdt, &pVBoxProc->cbLdt);558 static int ProcReadLdt(PRTSOLCORE pSolCore) 559 { 560 AssertReturn(pSolCore, VERR_INVALID_POINTER); 561 562 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 563 return ProcReadFileInto(pSolCore, "ldt", &pSolProc->pvLdt, &pSolProc->cbLdt); 525 564 } 526 565 … … 529 568 * Read process auxiliary vectors (format auxv_t) for the process. 530 569 * 531 * @param p VBoxCorePointer to the core object.570 * @param pSolCore Pointer to the core object. 532 571 * 533 572 * @remarks Should not be called before successful call to @see AllocMemoryArea() 534 573 * @return IPRT status code. 535 574 */ 536 static int ProcReadAuxVecs(P VBOXCORE pVBoxCore)537 { 538 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);539 540 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;575 static int ProcReadAuxVecs(PRTSOLCORE pSolCore) 576 { 577 AssertReturn(pSolCore, VERR_INVALID_POINTER); 578 579 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 541 580 char szPath[PATH_MAX]; 542 581 int rc = VINF_SUCCESS; 543 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/auxv", (int)p VBoxProc->Process);582 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/auxv", (int)pSolProc->Process); 544 583 int fd = open(szPath, O_RDONLY); 545 584 if (fd < 0) … … 550 589 } 551 590 552 RTFILE hFile = (RTFILE)(uintptr_t)fd; 553 uint64_t u64Size; 554 RTFileGetSize(hFile, &u64Size); 555 size_t cbAuxFile = u64Size < ~(size_t)0 ? u64Size : ~(size_t)0; 591 size_t cbAuxFile = GetFileSizeByFd(fd); 556 592 if (cbAuxFile >= sizeof(auxv_t)) 557 593 { 558 p VBoxProc->pAuxVecs = (auxv_t*)GetMemoryChunk(pVBoxCore, cbAuxFile + sizeof(auxv_t));559 if (p VBoxProc->pAuxVecs)560 { 561 rc = ReadFileNoIntr( hFile, pVBoxProc->pAuxVecs, cbAuxFile);594 pSolProc->pAuxVecs = (auxv_t*)GetMemoryChunk(pSolCore, cbAuxFile + sizeof(auxv_t)); 595 if (pSolProc->pAuxVecs) 596 { 597 rc = ReadFileNoIntr(fd, pSolProc->pAuxVecs, cbAuxFile); 562 598 if (RT_SUCCESS(rc)) 563 599 { 564 600 /* Terminate list of vectors */ 565 p VBoxProc->cAuxVecs = cbAuxFile / sizeof(auxv_t);601 pSolProc->cAuxVecs = cbAuxFile / sizeof(auxv_t); 566 602 CORELOG((CORELOG_NAME "ProcReadAuxVecs: cbAuxFile=%u auxv_t size %d cAuxVecs=%u\n", cbAuxFile, sizeof(auxv_t), 567 p VBoxProc->cAuxVecs));568 if (p VBoxProc->cAuxVecs > 0)603 pSolProc->cAuxVecs)); 604 if (pSolProc->cAuxVecs > 0) 569 605 { 570 p VBoxProc->pAuxVecs[pVBoxProc->cAuxVecs].a_type = AT_NULL;571 p VBoxProc->pAuxVecs[pVBoxProc->cAuxVecs].a_un.a_val = 0L;572 RTFileClose(hFile);606 pSolProc->pAuxVecs[pSolProc->cAuxVecs].a_type = AT_NULL; 607 pSolProc->pAuxVecs[pSolProc->cAuxVecs].a_un.a_val = 0L; 608 close(fd); 573 609 return VINF_SUCCESS; 574 610 } 575 else 576 { 577 CORELOGRELSYS((CORELOG_NAME "ProcReadAuxVecs: Invalid vector count %u\n", pVBoxProc->cAuxVecs)); 578 rc = VERR_READ_ERROR; 579 } 611 612 CORELOGRELSYS((CORELOG_NAME "ProcReadAuxVecs: Invalid vector count %u\n", pSolProc->cAuxVecs)); 613 rc = VERR_READ_ERROR; 580 614 } 581 615 else 582 616 CORELOGRELSYS((CORELOG_NAME "ProcReadAuxVecs: ReadFileNoIntr failed. rc=%Rrc cbAuxFile=%u\n", rc, cbAuxFile)); 583 617 584 p VBoxProc->pAuxVecs = NULL;585 p VBoxProc->cAuxVecs = 0;618 pSolProc->pAuxVecs = NULL; 619 pSolProc->cAuxVecs = 0; 586 620 } 587 621 else … … 597 631 } 598 632 599 RTFileClose(hFile);633 close(fd); 600 634 return rc; 601 635 } … … 605 639 * Find an element in the process' auxiliary vector. 606 640 */ 607 static long GetAuxVal(P VBOXPROCESS pVBoxProc, int Type)608 { 609 AssertReturn(p VBoxProc, -1);610 if (p VBoxProc->pAuxVecs)611 { 612 auxv_t *pAuxVec = p VBoxProc->pAuxVecs;641 static long GetAuxVal(PRTSOLCOREPROCESS pSolProc, int Type) 642 { 643 AssertReturn(pSolProc, -1); 644 if (pSolProc->pAuxVecs) 645 { 646 auxv_t *pAuxVec = pSolProc->pAuxVecs; 613 647 for (; pAuxVec->a_type != AT_NULL; pAuxVec++) 614 648 { … … 624 658 * Read the process mappings (format prmap_t array). 625 659 * 626 * @param p VBoxCorePointer to the core object.660 * @param pSolCore Pointer to the core object. 627 661 * 628 662 * @remarks Should not be called before successful call to @see AllocMemoryArea() 629 663 * @return IPRT status code. 630 664 */ 631 static int ProcReadMappings(P VBOXCORE pVBoxCore)632 { 633 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);634 635 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;665 static int ProcReadMappings(PRTSOLCORE pSolCore) 666 { 667 AssertReturn(pSolCore, VERR_INVALID_POINTER); 668 669 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 636 670 char szPath[PATH_MAX]; 637 671 int rc = VINF_SUCCESS; 638 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/map", (int)p VBoxProc->Process);639 int fd = open(szPath, O_RDONLY);640 if (fd < 0)641 { 642 rc = RTErrConvertFromErrno( fd);672 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/map", (int)pSolProc->Process); 673 int fdMap = open(szPath, O_RDONLY); 674 if (fdMap < 0) 675 { 676 rc = RTErrConvertFromErrno(errno); 643 677 CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: failed to open %s. rc=%Rrc\n", szPath, rc)); 644 678 return rc; 645 679 } 646 680 647 RTFILE hFile = (RTFILE)(uintptr_t)fd; 648 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/as", (int)pVBoxProc->Process); 649 fd = open(szPath, O_RDONLY); 650 if (fd >= 0) 651 { 652 pVBoxProc->hAs = (RTFILE)(uintptr_t)fd; 653 681 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/as", (int)pSolProc->Process); 682 pSolProc->fdAs = open(szPath, O_RDONLY); 683 if (pSolProc->fdAs >= 0) 684 { 654 685 /* 655 686 * Allocate and read all the prmap_t objects from proc. 656 687 */ 657 uint64_t u64Size; 658 RTFileGetSize(hFile, &u64Size); 659 size_t cbMapFile = u64Size < ~(size_t)0 ? u64Size : ~(size_t)0; 688 size_t cbMapFile = GetFileSizeByFd(fdMap); 660 689 if (cbMapFile >= sizeof(prmap_t)) 661 690 { 662 prmap_t *pMap = (prmap_t*)GetMemoryChunk(p VBoxCore, cbMapFile);691 prmap_t *pMap = (prmap_t*)GetMemoryChunk(pSolCore, cbMapFile); 663 692 if (pMap) 664 693 { 665 rc = ReadFileNoIntr( hFile, pMap, cbMapFile);694 rc = ReadFileNoIntr(fdMap, pMap, cbMapFile); 666 695 if (RT_SUCCESS(rc)) 667 696 { 668 p VBoxProc->cMappings = cbMapFile / sizeof(prmap_t);669 if (p VBoxProc->cMappings > 0)697 pSolProc->cMappings = cbMapFile / sizeof(prmap_t); 698 if (pSolProc->cMappings > 0) 670 699 { 671 700 /* 672 * Allocate for each prmap_t object, a corresponding VBOXSOLMAPINFO object.701 * Allocate for each prmap_t object, a corresponding RTSOLCOREMAPINFO object. 673 702 */ 674 p VBoxProc->pMapInfoHead = (PVBOXSOLMAPINFO)GetMemoryChunk(pVBoxCore, pVBoxProc->cMappings * sizeof(VBOXSOLMAPINFO));675 if (p VBoxProc->pMapInfoHead)703 pSolProc->pMapInfoHead = (PRTSOLCOREMAPINFO)GetMemoryChunk(pSolCore, pSolProc->cMappings * sizeof(RTSOLCOREMAPINFO)); 704 if (pSolProc->pMapInfoHead) 676 705 { 677 706 /* 678 707 * Associate the prmap_t with the mapping info object. 679 708 */ 680 Assert(pVBoxProc->pMapInfoHead == NULL);681 P VBOXSOLMAPINFO pCur = pVBoxProc->pMapInfoHead;682 P VBOXSOLMAPINFO pPrev = NULL;683 for (uint64_t i = 0; i < p VBoxProc->cMappings; i++, pMap++, pCur++)709 /*Assert(pSolProc->pMapInfoHead == NULL); - does not make sense */ 710 PRTSOLCOREMAPINFO pCur = pSolProc->pMapInfoHead; 711 PRTSOLCOREMAPINFO pPrev = NULL; 712 for (uint64_t i = 0; i < pSolProc->cMappings; i++, pMap++, pCur++) 684 713 { 685 714 memcpy(&pCur->pMap, pMap, sizeof(pCur->pMap)); … … 697 726 { 698 727 size_t cb = RT_MIN(sizeof(achBuf), pCur->pMap.pr_size - k); 699 int rc2 = ProcReadAddrSpace(p VBoxProc, pCur->pMap.pr_vaddr + k, &achBuf, cb);728 int rc2 = ProcReadAddrSpace(pSolProc, pCur->pMap.pr_vaddr + k, &achBuf, cb); 700 729 if (RT_FAILURE(rc2)) 701 730 { … … 722 751 pPrev->pNext = NULL; 723 752 724 RTFileClose(hFile);725 RTFileClose(pVBoxProc->hAs);726 p VBoxProc->hAs = NIL_RTFILE;727 CORELOG((CORELOG_NAME "ProcReadMappings: successfully read in %u mappings\n", p VBoxProc->cMappings));753 close(fdMap); 754 close(pSolProc->fdAs); 755 pSolProc->fdAs = -1; 756 CORELOG((CORELOG_NAME "ProcReadMappings: successfully read in %u mappings\n", pSolProc->cMappings)); 728 757 return VINF_SUCCESS; 729 758 } 730 else 731 { 732 CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: GetMemoryChunk failed %u\n", 733 pVBoxProc->cMappings * sizeof(VBOXSOLMAPINFO))); 734 rc = VERR_NO_MEMORY; 735 } 759 760 CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: GetMemoryChunk failed %u\n", 761 pSolProc->cMappings * sizeof(RTSOLCOREMAPINFO))); 762 rc = VERR_NO_MEMORY; 736 763 } 737 764 else 738 765 { 739 CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: Invalid mapping count %u\n", p VBoxProc->cMappings));766 CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: Invalid mapping count %u\n", pSolProc->cMappings)); 740 767 rc = VERR_READ_ERROR; 741 768 } … … 751 778 } 752 779 753 RTFileClose(pVBoxProc->hAs);754 p VBoxProc->hAs = NIL_RTFILE;780 close(pSolProc->fdAs); 781 pSolProc->fdAs = -1; 755 782 } 756 783 else 757 784 CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: failed to open %s. rc=%Rrc\n", szPath, rc)); 758 785 759 RTFileClose(hFile);786 close(fdMap); 760 787 return rc; 761 788 } … … 765 792 * Reads the thread information for all threads in the process. 766 793 * 767 * @param p VBoxCorePointer to the core object.794 * @param pSolCore Pointer to the core object. 768 795 * 769 796 * @remarks Should not be called before successful call to @see AllocMemoryArea() 770 797 * @return IPRT status code. 771 798 */ 772 static int ProcReadThreads(P VBOXCORE pVBoxCore)773 { 774 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);775 776 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;777 AssertReturn(p VBoxProc->pCurThreadCtx, VERR_NO_DATA);799 static int ProcReadThreads(PRTSOLCORE pSolCore) 800 { 801 AssertReturn(pSolCore, VERR_INVALID_POINTER); 802 803 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 804 AssertReturn(pSolProc->pCurThreadCtx, VERR_NO_DATA); 778 805 779 806 /* … … 783 810 size_t cbInfoHdrAndData; 784 811 void *pvInfoHdr = NULL; 785 int rc = ProcReadFileInto(p VBoxCore, "lpsinfo", &pvInfoHdr, &cbInfoHdrAndData);812 int rc = ProcReadFileInto(pSolCore, "lpsinfo", &pvInfoHdr, &cbInfoHdrAndData); 786 813 if (RT_SUCCESS(rc)) 787 814 { … … 792 819 void *pvStatusHdr = NULL; 793 820 size_t cbStatusHdrAndData; 794 rc = ProcReadFileInto(p VBoxCore, "lstatus", &pvStatusHdr, &cbStatusHdrAndData);821 rc = ProcReadFileInto(pSolCore, "lstatus", &pvStatusHdr, &cbStatusHdrAndData); 795 822 if (RT_SUCCESS(rc)) 796 823 { … … 844 871 cStatus = pInfoHdr->pr_nent; 845 872 846 size_t cbThreadInfo = RT_MAX(cStatus, cInfo) * sizeof( VBOXSOLTHREADINFO);847 p VBoxProc->pThreadInfoHead = (PVBOXSOLTHREADINFO)GetMemoryChunk(pVBoxCore, cbThreadInfo);848 if (p VBoxProc->pThreadInfoHead)873 size_t cbThreadInfo = RT_MAX(cStatus, cInfo) * sizeof(RTSOLCORETHREADINFO); 874 pSolProc->pThreadInfoHead = (PRTSOLCORETHREADINFO)GetMemoryChunk(pSolCore, cbThreadInfo); 875 if (pSolProc->pThreadInfoHead) 849 876 { 850 P VBOXSOLTHREADINFO pCur = pVBoxProc->pThreadInfoHead;851 P VBOXSOLTHREADINFO pPrev = NULL;877 PRTSOLCORETHREADINFO pCur = pSolProc->pThreadInfoHead; 878 PRTSOLCORETHREADINFO pPrev = NULL; 852 879 for (uint64_t i = 0; i < cInfo; i++, pCur++) 853 880 { … … 861 888 */ 862 889 if ( pStatus /* noid droid */ 863 && pStatus->pr_lwpid == (id_t)p VBoxProc->hCurThread)890 && pStatus->pr_lwpid == (id_t)pSolProc->hCurThread) 864 891 { 865 AssertCompile(sizeof(pStatus->pr_reg) == sizeof(p VBoxProc->pCurThreadCtx->uc_mcontext.gregs));866 AssertCompile(sizeof(pStatus->pr_fpreg) == sizeof(p VBoxProc->pCurThreadCtx->uc_mcontext.fpregs));867 memcpy(&pStatus->pr_reg, &p VBoxProc->pCurThreadCtx->uc_mcontext.gregs, sizeof(pStatus->pr_reg));868 memcpy(&pStatus->pr_fpreg, &p VBoxProc->pCurThreadCtx->uc_mcontext.fpregs, sizeof(pStatus->pr_fpreg));869 870 AssertCompile(sizeof(pStatus->pr_lwphold) == sizeof(p VBoxProc->pCurThreadCtx->uc_sigmask));871 memcpy(&pStatus->pr_lwphold, &p VBoxProc->pCurThreadCtx->uc_sigmask, sizeof(pStatus->pr_lwphold));872 pStatus->pr_ustack = (uintptr_t)&p VBoxProc->pCurThreadCtx->uc_stack;892 AssertCompile(sizeof(pStatus->pr_reg) == sizeof(pSolProc->pCurThreadCtx->uc_mcontext.gregs)); 893 AssertCompile(sizeof(pStatus->pr_fpreg) == sizeof(pSolProc->pCurThreadCtx->uc_mcontext.fpregs)); 894 memcpy(&pStatus->pr_reg, &pSolProc->pCurThreadCtx->uc_mcontext.gregs, sizeof(pStatus->pr_reg)); 895 memcpy(&pStatus->pr_fpreg, &pSolProc->pCurThreadCtx->uc_mcontext.fpregs, sizeof(pStatus->pr_fpreg)); 896 897 AssertCompile(sizeof(pStatus->pr_lwphold) == sizeof(pSolProc->pCurThreadCtx->uc_sigmask)); 898 memcpy(&pStatus->pr_lwphold, &pSolProc->pCurThreadCtx->uc_sigmask, sizeof(pStatus->pr_lwphold)); 899 pStatus->pr_ustack = (uintptr_t)&pSolProc->pCurThreadCtx->uc_stack; 873 900 874 901 CORELOG((CORELOG_NAME "ProcReadThreads: patched dumper thread context with pre-dump time context.\n")); … … 893 920 894 921 CORELOG((CORELOG_NAME "ProcReadThreads: successfully read %u threads.\n", cInfo)); 895 p VBoxProc->cThreads = cInfo;922 pSolProc->cThreads = cInfo; 896 923 return VINF_SUCCESS; 897 924 } … … 927 954 * This may include platform name, zone name and other OS-specific information. 928 955 * 929 * @param p VBoxCorePointer to the core object.956 * @param pSolCore Pointer to the core object. 930 957 * 931 958 * @return IPRT status code. 932 959 */ 933 static int ProcReadMiscInfo(P VBOXCORE pVBoxCore)934 { 935 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);936 937 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;960 static int ProcReadMiscInfo(PRTSOLCORE pSolCore) 961 { 962 AssertReturn(pSolCore, VERR_INVALID_POINTER); 963 964 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 938 965 939 966 #ifdef RT_OS_SOLARIS … … 941 968 * Read the platform name, uname string and zone name. 942 969 */ 943 int rc = sysinfo(SI_PLATFORM, p VBoxProc->szPlatform, sizeof(pVBoxProc->szPlatform));970 int rc = sysinfo(SI_PLATFORM, pSolProc->szPlatform, sizeof(pSolProc->szPlatform)); 944 971 if (rc == -1) 945 972 { … … 947 974 return VERR_GENERAL_FAILURE; 948 975 } 949 p VBoxProc->szPlatform[sizeof(pVBoxProc->szPlatform) - 1] = '\0';950 951 rc = uname(&p VBoxProc->UtsName);976 pSolProc->szPlatform[sizeof(pSolProc->szPlatform) - 1] = '\0'; 977 978 rc = uname(&pSolProc->UtsName); 952 979 if (rc == -1) 953 980 { … … 956 983 } 957 984 958 rc = getzonenamebyid(p VBoxProc->ProcInfo.pr_zoneid, pVBoxProc->szZoneName, sizeof(pVBoxProc->szZoneName));985 rc = getzonenamebyid(pSolProc->ProcInfo.pr_zoneid, pSolProc->szZoneName, sizeof(pSolProc->szZoneName)); 959 986 if (rc < 0) 960 987 { 961 988 CORELOGRELSYS((CORELOG_NAME "ProcReadMiscInfo: getzonenamebyid failed. rc=%d errno=%d zoneid=%d\n", rc, errno, 962 p VBoxProc->ProcInfo.pr_zoneid));989 pSolProc->ProcInfo.pr_zoneid)); 963 990 return VERR_GENERAL_FAILURE; 964 991 } 965 p VBoxProc->szZoneName[sizeof(pVBoxProc->szZoneName) - 1] = '\0';992 pSolProc->szZoneName[sizeof(pSolProc->szZoneName) - 1] = '\0'; 966 993 rc = VINF_SUCCESS; 967 994 … … 977 1004 * info. for backward and GDB compatibility, hence the need for this ugly function. 978 1005 * 979 * @param p VBoxCorePointer to the core object.1006 * @param pSolCore Pointer to the core object. 980 1007 * @param pInfo Pointer to the old prpsinfo_t structure to update. 981 1008 */ 982 static void GetOldProcessInfo(P VBOXCORE pVBoxCore, prpsinfo_t *pInfo)983 { 984 AssertReturnVoid(p VBoxCore);1009 static void GetOldProcessInfo(PRTSOLCORE pSolCore, prpsinfo_t *pInfo) 1010 { 1011 AssertReturnVoid(pSolCore); 985 1012 AssertReturnVoid(pInfo); 986 1013 987 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;988 psinfo_t *pSrc = &p VBoxProc->ProcInfo;1014 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1015 psinfo_t *pSrc = &pSolProc->ProcInfo; 989 1016 memset(pInfo, 0, sizeof(prpsinfo_t)); 990 1017 pInfo->pr_state = pSrc->pr_lwp.pr_state; … … 1033 1060 * info. for backward and GDB compatibility, hence the need for this ugly function. 1034 1061 * 1035 * @param p VBoxCorePointer to the core object.1062 * @param pSolCore Pointer to the core object. 1036 1063 * @param pInfo Pointer to the thread info. 1037 1064 * @param pStatus Pointer to the thread status. … … 1039 1066 * 1040 1067 */ 1041 static void GetOldProcessStatus(P VBOXCORE pVBoxCore, lwpsinfo_t *pInfo, lwpstatus_t *pStatus, prstatus_t *pDst)1042 { 1043 AssertReturnVoid(p VBoxCore);1068 static void GetOldProcessStatus(PRTSOLCORE pSolCore, lwpsinfo_t *pInfo, lwpstatus_t *pStatus, prstatus_t *pDst) 1069 { 1070 AssertReturnVoid(pSolCore); 1044 1071 AssertReturnVoid(pInfo); 1045 1072 AssertReturnVoid(pStatus); 1046 1073 AssertReturnVoid(pDst); 1047 1074 1048 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1075 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1049 1076 memset(pDst, 0, sizeof(prstatus_t)); 1050 1077 if (pStatus->pr_flags & PR_STOPPED) … … 1096 1123 RTStrCopy(pDst->pr_clname, sizeof(pDst->pr_clname), pStatus->pr_clname); 1097 1124 1098 pDst->pr_nlwp = p VBoxProc->ProcStatus.pr_nlwp;1099 pDst->pr_sigpend = p VBoxProc->ProcStatus.pr_sigpend;1100 pDst->pr_pid = p VBoxProc->ProcStatus.pr_pid;1101 pDst->pr_ppid = p VBoxProc->ProcStatus.pr_ppid;1102 pDst->pr_pgrp = p VBoxProc->ProcStatus.pr_pgid;1103 pDst->pr_sid = p VBoxProc->ProcStatus.pr_sid;1104 pDst->pr_utime = p VBoxProc->ProcStatus.pr_utime;1105 pDst->pr_stime = p VBoxProc->ProcStatus.pr_stime;1106 pDst->pr_cutime = p VBoxProc->ProcStatus.pr_cutime;1107 pDst->pr_cstime = p VBoxProc->ProcStatus.pr_cstime;1108 pDst->pr_brkbase = (caddr_t)p VBoxProc->ProcStatus.pr_brkbase;1109 pDst->pr_brksize = p VBoxProc->ProcStatus.pr_brksize;1110 pDst->pr_stkbase = (caddr_t)p VBoxProc->ProcStatus.pr_stkbase;1111 pDst->pr_stksize = p VBoxProc->ProcStatus.pr_stksize;1125 pDst->pr_nlwp = pSolProc->ProcStatus.pr_nlwp; 1126 pDst->pr_sigpend = pSolProc->ProcStatus.pr_sigpend; 1127 pDst->pr_pid = pSolProc->ProcStatus.pr_pid; 1128 pDst->pr_ppid = pSolProc->ProcStatus.pr_ppid; 1129 pDst->pr_pgrp = pSolProc->ProcStatus.pr_pgid; 1130 pDst->pr_sid = pSolProc->ProcStatus.pr_sid; 1131 pDst->pr_utime = pSolProc->ProcStatus.pr_utime; 1132 pDst->pr_stime = pSolProc->ProcStatus.pr_stime; 1133 pDst->pr_cutime = pSolProc->ProcStatus.pr_cutime; 1134 pDst->pr_cstime = pSolProc->ProcStatus.pr_cstime; 1135 pDst->pr_brkbase = (caddr_t)pSolProc->ProcStatus.pr_brkbase; 1136 pDst->pr_brksize = pSolProc->ProcStatus.pr_brksize; 1137 pDst->pr_stkbase = (caddr_t)pSolProc->ProcStatus.pr_stkbase; 1138 pDst->pr_stksize = pSolProc->ProcStatus.pr_stksize; 1112 1139 1113 1140 pDst->pr_processor = (short)pInfo->pr_onpro; … … 1120 1147 * Callback for rtCoreDumperForEachThread to suspend a thread. 1121 1148 * 1122 * @param p VBoxCorePointer to the core object.1149 * @param pSolCore Pointer to the core object. 1123 1150 * @param pvThreadInfo Opaque pointer to thread information. 1124 1151 * 1125 1152 * @return IPRT status code. 1126 1153 */ 1127 static int suspendThread(P VBOXCORE pVBoxCore, void *pvThreadInfo)1154 static int suspendThread(PRTSOLCORE pSolCore, void *pvThreadInfo) 1128 1155 { 1129 1156 AssertPtrReturn(pvThreadInfo, VERR_INVALID_POINTER); 1130 NOREF(p VBoxCore);1157 NOREF(pSolCore); 1131 1158 1132 1159 lwpsinfo_t *pThreadInfo = (lwpsinfo_t *)pvThreadInfo; 1133 1160 CORELOG((CORELOG_NAME ":suspendThread %d\n", (lwpid_t)pThreadInfo->pr_lwpid)); 1134 if ((lwpid_t)pThreadInfo->pr_lwpid != p VBoxCore->VBoxProc.hCurThread)1161 if ((lwpid_t)pThreadInfo->pr_lwpid != pSolCore->SolProc.hCurThread) 1135 1162 _lwp_suspend(pThreadInfo->pr_lwpid); 1136 1163 return VINF_SUCCESS; … … 1141 1168 * Callback for rtCoreDumperForEachThread to resume a thread. 1142 1169 * 1143 * @param p VBoxCorePointer to the core object.1170 * @param pSolCore Pointer to the core object. 1144 1171 * @param pvThreadInfo Opaque pointer to thread information. 1145 1172 * 1146 1173 * @return IPRT status code. 1147 1174 */ 1148 static int resumeThread(P VBOXCORE pVBoxCore, void *pvThreadInfo)1175 static int resumeThread(PRTSOLCORE pSolCore, void *pvThreadInfo) 1149 1176 { 1150 1177 AssertPtrReturn(pvThreadInfo, VERR_INVALID_POINTER); 1151 NOREF(p VBoxCore);1178 NOREF(pSolCore); 1152 1179 1153 1180 lwpsinfo_t *pThreadInfo = (lwpsinfo_t *)pvThreadInfo; 1154 1181 CORELOG((CORELOG_NAME ":resumeThread %d\n", (lwpid_t)pThreadInfo->pr_lwpid)); 1155 if ((lwpid_t)pThreadInfo->pr_lwpid != (lwpid_t)p VBoxCore->VBoxProc.hCurThread)1182 if ((lwpid_t)pThreadInfo->pr_lwpid != (lwpid_t)pSolCore->SolProc.hCurThread) 1156 1183 _lwp_continue(pThreadInfo->pr_lwpid); 1157 1184 return VINF_SUCCESS; … … 1162 1189 * Calls a thread worker function for all threads in the process as described by /proc 1163 1190 * 1164 * @param p VBoxCorePointer to the core object.1191 * @param pSolCore Pointer to the core object. 1165 1192 * @param pcThreads Number of threads read. 1166 1193 * @param pfnWorker Callback function for each thread. … … 1168 1195 * @return IPRT status code. 1169 1196 */ 1170 static int rtCoreDumperForEachThread(P VBOXCORE pVBoxCore, uint64_t *pcThreads, PFNCORETHREADWORKER pfnWorker)1171 { 1172 AssertPtrReturn(p VBoxCore, VERR_INVALID_POINTER);1173 1174 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1197 static int rtCoreDumperForEachThread(PRTSOLCORE pSolCore, uint64_t *pcThreads, PFNRTSOLCORETHREADWORKER pfnWorker) 1198 { 1199 AssertPtrReturn(pSolCore, VERR_INVALID_POINTER); 1200 1201 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1175 1202 1176 1203 /* … … 1179 1206 */ 1180 1207 char szLpsInfoPath[PATH_MAX]; 1181 RTStrPrintf(szLpsInfoPath, sizeof(szLpsInfoPath), "/proc/%d/lpsinfo", (int)p VBoxProc->Process);1208 RTStrPrintf(szLpsInfoPath, sizeof(szLpsInfoPath), "/proc/%d/lpsinfo", (int)pSolProc->Process); 1182 1209 1183 1210 int rc = VINF_SUCCESS; … … 1185 1212 if (fd >= 0) 1186 1213 { 1187 RTFILE hFile = (RTFILE)(uintptr_t)fd; 1188 uint64_t u64Size; 1189 RTFileGetSize(hFile, &u64Size); 1190 size_t cbInfoHdrAndData = u64Size < ~(size_t)0 ? u64Size : ~(size_t)0; 1191 void *pvInfoHdr = mmap(NULL, cbInfoHdrAndData, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1 /* fd */, 0 /* offset */); 1214 size_t cbInfoHdrAndData = GetFileSizeByFd(fd); 1215 void *pvInfoHdr = mmap(NULL, cbInfoHdrAndData, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 1216 -1 /* fd */, 0 /* offset */); 1192 1217 if (pvInfoHdr != MAP_FAILED) 1193 1218 { 1194 rc = R TFileRead(hFile, pvInfoHdr, cbInfoHdrAndData, NULL);1219 rc = ReadFileNoIntr(fd, pvInfoHdr, cbInfoHdrAndData); 1195 1220 if (RT_SUCCESS(rc)) 1196 1221 { … … 1199 1224 for (long i = 0; i < pHeader->pr_nent; i++) 1200 1225 { 1201 pfnWorker(p VBoxCore, pThreadInfo);1226 pfnWorker(pSolCore, pThreadInfo); 1202 1227 pThreadInfo = (lwpsinfo_t *)((uintptr_t)pThreadInfo + pHeader->pr_entsize); 1203 1228 } … … 1210 1235 else 1211 1236 rc = VERR_NO_MEMORY; 1212 RTFileClose(hFile);1237 close(fd); 1213 1238 } 1214 1239 else … … 1222 1247 * Resume all threads of this process. 1223 1248 * 1224 * @param p VBoxCorePointer to the core object.1249 * @param pSolCore Pointer to the core object. 1225 1250 * 1226 1251 * @return IPRT status code.. 1227 1252 */ 1228 static int rtCoreDumperResumeThreads(P VBOXCORE pVBoxCore)1229 { 1230 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);1253 static int rtCoreDumperResumeThreads(PRTSOLCORE pSolCore) 1254 { 1255 AssertReturn(pSolCore, VERR_INVALID_POINTER); 1231 1256 1232 1257 #if 1 1233 1258 uint64_t cThreads; 1234 return rtCoreDumperForEachThread(p VBoxCore, &cThreads, resumeThread);1259 return rtCoreDumperForEachThread(pSolCore, &cThreads, resumeThread); 1235 1260 #else 1236 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1261 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1237 1262 1238 1263 char szCurThread[128]; … … 1240 1265 PRTDIR pDir = NULL; 1241 1266 1242 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/lwp", (int)p VBoxProc->Process);1243 RTStrPrintf(szCurThread, sizeof(szCurThread), "%d", (int)p VBoxProc->hCurThread);1267 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/lwp", (int)pSolProc->Process); 1268 RTStrPrintf(szCurThread, sizeof(szCurThread), "%d", (int)pSolProc->hCurThread); 1244 1269 1245 1270 int32_t cRunningThreads = 0; … … 1281 1306 * Stop all running threads of this process except the current one. 1282 1307 * 1283 * @param p VBoxCorePointer to the core object.1308 * @param pSolCore Pointer to the core object. 1284 1309 * 1285 1310 * @return IPRT status code. 1286 1311 */ 1287 static int rtCoreDumperSuspendThreads(P VBOXCORE pVBoxCore)1288 { 1289 AssertPtrReturn(p VBoxCore, VERR_INVALID_POINTER);1312 static int rtCoreDumperSuspendThreads(PRTSOLCORE pSolCore) 1313 { 1314 AssertPtrReturn(pSolCore, VERR_INVALID_POINTER); 1290 1315 1291 1316 /* … … 1303 1328 for (cTries = 0; cTries < RT_ELEMENTS(aThreads); cTries++) 1304 1329 { 1305 rc = rtCoreDumperForEachThread(p VBoxCore, &aThreads[cTries], suspendThread);1330 rc = rtCoreDumperForEachThread(pSolCore, &aThreads[cTries], suspendThread); 1306 1331 if (RT_FAILURE(rc)) 1307 1332 break; … … 1315 1340 return rc; 1316 1341 #else 1317 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1342 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1318 1343 1319 1344 char szCurThread[128]; … … 1321 1346 PRTDIR pDir = NULL; 1322 1347 1323 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/lwp", (int)p VBoxProc->Process);1324 RTStrPrintf(szCurThread, sizeof(szCurThread), "%d", (int)p VBoxProc->hCurThread);1348 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/lwp", (int)pSolProc->Process); 1349 RTStrPrintf(szCurThread, sizeof(szCurThread), "%d", (int)pSolProc->hCurThread); 1325 1350 1326 1351 int rc = -1; … … 1391 1416 * Write an ELF NOTE header into the core file. 1392 1417 * 1393 * @param p VBoxCorePointer to the core object.1418 * @param pSolCore Pointer to the core object. 1394 1419 * @param Type Type of this NOTE section. 1395 1420 * @param pcv Opaque pointer to the data, if NULL only computes size. … … 1398 1423 * @return IPRT status code. 1399 1424 */ 1400 static int ElfWriteNoteHeader(P VBOXCORE pVBoxCore, uint_t Type, const void *pcv, size_t cb)1401 { 1402 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);1425 static int ElfWriteNoteHeader(PRTSOLCORE pSolCore, uint_t Type, const void *pcv, size_t cb) 1426 { 1427 AssertReturn(pSolCore, VERR_INVALID_POINTER); 1403 1428 AssertReturn(pcv, VERR_INVALID_POINTER); 1404 1429 AssertReturn(cb > 0, VERR_NO_DATA); 1405 AssertReturn(p VBoxCore->pfnWriter, VERR_WRITE_ERROR);1406 AssertReturn(p VBoxCore->hCoreFile, VERR_INVALID_HANDLE);1430 AssertReturn(pSolCore->pfnWriter, VERR_WRITE_ERROR); 1431 AssertReturn(pSolCore->fdCoreFile >= 0, VERR_INVALID_HANDLE); 1407 1432 1408 1433 int rc = VERR_GENERAL_FAILURE; … … 1428 1453 * Write note header and description. 1429 1454 */ 1430 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, &ElfNoteHdr, sizeof(ElfNoteHdr));1455 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ElfNoteHdr, sizeof(ElfNoteHdr)); 1431 1456 if (RT_SUCCESS(rc)) 1432 1457 { 1433 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, pcv, cb);1458 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, pcv, cb); 1434 1459 if (RT_SUCCESS(rc)) 1435 1460 { 1436 1461 if (cbAlign > cb) 1437 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, s_achPad, cbAlign - cb);1462 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, s_achPad, cbAlign - cb); 1438 1463 } 1439 1464 } … … 1452 1477 * Solaris has two types of program header information (new and old). 1453 1478 * 1454 * @param p VBoxCorePointer to the core object.1479 * @param pSolCore Pointer to the core object. 1455 1480 * @param enmType Type of core file information required. 1456 1481 * 1457 1482 * @return Size of NOTE section. 1458 1483 */ 1459 static size_t ElfNoteSectionSize(P VBOXCORE pVBoxCore, VBOXSOLCORETYPE enmType)1460 { 1461 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1484 static size_t ElfNoteSectionSize(PRTSOLCORE pSolCore, RTSOLCORETYPE enmType) 1485 { 1486 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1462 1487 size_t cb = 0; 1463 1488 switch (enmType) … … 1466 1491 { 1467 1492 cb += ElfNoteHeaderSize(sizeof(prpsinfo_t)); 1468 cb += ElfNoteHeaderSize(p VBoxProc->cAuxVecs * sizeof(auxv_t));1469 cb += ElfNoteHeaderSize(strlen(p VBoxProc->szPlatform));1470 1471 P VBOXSOLTHREADINFO pThreadInfo = pVBoxProc->pThreadInfoHead;1493 cb += ElfNoteHeaderSize(pSolProc->cAuxVecs * sizeof(auxv_t)); 1494 cb += ElfNoteHeaderSize(strlen(pSolProc->szPlatform)); 1495 1496 PRTSOLCORETHREADINFO pThreadInfo = pSolProc->pThreadInfoHead; 1472 1497 while (pThreadInfo) 1473 1498 { … … 1487 1512 cb += ElfNoteHeaderSize(sizeof(psinfo_t)); 1488 1513 cb += ElfNoteHeaderSize(sizeof(pstatus_t)); 1489 cb += ElfNoteHeaderSize(p VBoxProc->cAuxVecs * sizeof(auxv_t));1490 cb += ElfNoteHeaderSize(strlen(p VBoxProc->szPlatform) + 1);1514 cb += ElfNoteHeaderSize(pSolProc->cAuxVecs * sizeof(auxv_t)); 1515 cb += ElfNoteHeaderSize(strlen(pSolProc->szPlatform) + 1); 1491 1516 cb += ElfNoteHeaderSize(sizeof(struct utsname)); 1492 1517 cb += ElfNoteHeaderSize(sizeof(core_content_t)); 1493 cb += ElfNoteHeaderSize(p VBoxProc->cbCred);1494 1495 if (p VBoxProc->pPriv)1496 cb += ElfNoteHeaderSize(PRIV_PRPRIV_SIZE(p VBoxProc->pPriv)); /* Ought to be same as cbPriv!? */1497 1498 if (p VBoxProc->pcPrivImpl)1499 cb += ElfNoteHeaderSize(PRIV_IMPL_INFO_SIZE(p VBoxProc->pcPrivImpl));1500 1501 cb += ElfNoteHeaderSize(strlen(p VBoxProc->szZoneName) + 1);1502 if (p VBoxProc->cbLdt > 0)1503 cb += ElfNoteHeaderSize(p VBoxProc->cbLdt);1504 1505 P VBOXSOLTHREADINFO pThreadInfo = pVBoxProc->pThreadInfoHead;1518 cb += ElfNoteHeaderSize(pSolProc->cbCred); 1519 1520 if (pSolProc->pPriv) 1521 cb += ElfNoteHeaderSize(PRIV_PRPRIV_SIZE(pSolProc->pPriv)); /* Ought to be same as cbPriv!? */ 1522 1523 if (pSolProc->pcPrivImpl) 1524 cb += ElfNoteHeaderSize(PRIV_IMPL_INFO_SIZE(pSolProc->pcPrivImpl)); 1525 1526 cb += ElfNoteHeaderSize(strlen(pSolProc->szZoneName) + 1); 1527 if (pSolProc->cbLdt > 0) 1528 cb += ElfNoteHeaderSize(pSolProc->cbLdt); 1529 1530 PRTSOLCORETHREADINFO pThreadInfo = pSolProc->pThreadInfoHead; 1506 1531 while (pThreadInfo) 1507 1532 { … … 1531 1556 * Solaris has two types of program header information (new and old). 1532 1557 * 1533 * @param p VBoxCorePointer to the core object.1558 * @param pSolCore Pointer to the core object. 1534 1559 * @param enmType Type of core file information required. 1535 1560 * 1536 1561 * @return IPRT status code. 1537 1562 */ 1538 static int ElfWriteNoteSection(P VBOXCORE pVBoxCore, VBOXSOLCORETYPE enmType)1539 { 1540 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);1541 1542 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1563 static int ElfWriteNoteSection(PRTSOLCORE pSolCore, RTSOLCORETYPE enmType) 1564 { 1565 AssertReturn(pSolCore, VERR_INVALID_POINTER); 1566 1567 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1543 1568 int rc = VERR_GENERAL_FAILURE; 1544 1569 1545 1570 #ifdef RT_OS_SOLARIS 1546 typedef int (*PFNELFWRITENOTEHDR)(P VBOXCORE pVBoxCore, uint_t, const void *pcv, size_t cb);1571 typedef int (*PFNELFWRITENOTEHDR)(PRTSOLCORE pSolCore, uint_t, const void *pcv, size_t cb); 1547 1572 typedef struct ELFWRITENOTE 1548 1573 { … … 1559 1584 ELFWRITENOTE aElfNotes[] = 1560 1585 { 1561 { "NT_PRPSINFO", NT_PRPSINFO, &p VBoxProc->ProcInfoOld, sizeof(prpsinfo_t) },1562 { "NT_AUXV", NT_AUXV, p VBoxProc->pAuxVecs, pVBoxProc->cAuxVecs * sizeof(auxv_t) },1563 { "NT_PLATFORM", NT_PLATFORM, p VBoxProc->szPlatform, strlen(pVBoxProc->szPlatform) + 1 }1586 { "NT_PRPSINFO", NT_PRPSINFO, &pSolProc->ProcInfoOld, sizeof(prpsinfo_t) }, 1587 { "NT_AUXV", NT_AUXV, pSolProc->pAuxVecs, pSolProc->cAuxVecs * sizeof(auxv_t) }, 1588 { "NT_PLATFORM", NT_PLATFORM, pSolProc->szPlatform, strlen(pSolProc->szPlatform) + 1 } 1564 1589 }; 1565 1590 1566 1591 for (unsigned i = 0; i < RT_ELEMENTS(aElfNotes); i++) 1567 1592 { 1568 rc = ElfWriteNoteHeader(p VBoxCore, aElfNotes[i].Type, aElfNotes[i].pcv, aElfNotes[i].cb);1593 rc = ElfWriteNoteHeader(pSolCore, aElfNotes[i].Type, aElfNotes[i].pcv, aElfNotes[i].cb); 1569 1594 if (RT_FAILURE(rc)) 1570 1595 { … … 1578 1603 * so we just skip if there is no status information for them. 1579 1604 */ 1580 P VBOXSOLTHREADINFO pThreadInfo = pVBoxProc->pThreadInfoHead;1605 PRTSOLCORETHREADINFO pThreadInfo = pSolProc->pThreadInfoHead; 1581 1606 for (; pThreadInfo; pThreadInfo = pThreadInfo->pNext) 1582 1607 { … … 1585 1610 1586 1611 prstatus_t OldProcessStatus; 1587 GetOldProcessStatus(p VBoxCore, &pThreadInfo->Info, pThreadInfo->pStatus, &OldProcessStatus);1588 rc = ElfWriteNoteHeader(p VBoxCore, NT_PRSTATUS, &OldProcessStatus, sizeof(prstatus_t));1612 GetOldProcessStatus(pSolCore, &pThreadInfo->Info, pThreadInfo->pStatus, &OldProcessStatus); 1613 rc = ElfWriteNoteHeader(pSolCore, NT_PRSTATUS, &OldProcessStatus, sizeof(prstatus_t)); 1589 1614 if (RT_SUCCESS(rc)) 1590 1615 { 1591 rc = ElfWriteNoteHeader(p VBoxCore, NT_PRFPREG, &pThreadInfo->pStatus->pr_fpreg, sizeof(prfpregset_t));1616 rc = ElfWriteNoteHeader(pSolCore, NT_PRFPREG, &pThreadInfo->pStatus->pr_fpreg, sizeof(prfpregset_t)); 1592 1617 if (RT_FAILURE(rc)) 1593 1618 { … … 1609 1634 ELFWRITENOTE aElfNotes[] = 1610 1635 { 1611 { "NT_PSINFO", NT_PSINFO, &p VBoxProc->ProcInfo, sizeof(psinfo_t) },1612 { "NT_PSTATUS", NT_PSTATUS, &p VBoxProc->ProcStatus, sizeof(pstatus_t) },1613 { "NT_AUXV", NT_AUXV, p VBoxProc->pAuxVecs, pVBoxProc->cAuxVecs * sizeof(auxv_t) },1614 { "NT_PLATFORM", NT_PLATFORM, p VBoxProc->szPlatform, strlen(pVBoxProc->szPlatform) + 1 },1615 { "NT_UTSNAME", NT_UTSNAME, &p VBoxProc->UtsName, sizeof(struct utsname) },1616 { "NT_CONTENT", NT_CONTENT, &p VBoxProc->CoreContent, sizeof(core_content_t) },1617 { "NT_PRCRED", NT_PRCRED, p VBoxProc->pvCred, pVBoxProc->cbCred },1618 { "NT_PRPRIV", NT_PRPRIV, p VBoxProc->pPriv, PRIV_PRPRIV_SIZE(pVBoxProc->pPriv) },1619 { "NT_PRPRIVINFO", NT_PRPRIVINFO, p VBoxProc->pcPrivImpl, PRIV_IMPL_INFO_SIZE(pVBoxProc->pcPrivImpl) },1620 { "NT_ZONENAME", NT_ZONENAME, p VBoxProc->szZoneName, strlen(pVBoxProc->szZoneName) + 1 }1636 { "NT_PSINFO", NT_PSINFO, &pSolProc->ProcInfo, sizeof(psinfo_t) }, 1637 { "NT_PSTATUS", NT_PSTATUS, &pSolProc->ProcStatus, sizeof(pstatus_t) }, 1638 { "NT_AUXV", NT_AUXV, pSolProc->pAuxVecs, pSolProc->cAuxVecs * sizeof(auxv_t) }, 1639 { "NT_PLATFORM", NT_PLATFORM, pSolProc->szPlatform, strlen(pSolProc->szPlatform) + 1 }, 1640 { "NT_UTSNAME", NT_UTSNAME, &pSolProc->UtsName, sizeof(struct utsname) }, 1641 { "NT_CONTENT", NT_CONTENT, &pSolProc->CoreContent, sizeof(core_content_t) }, 1642 { "NT_PRCRED", NT_PRCRED, pSolProc->pvCred, pSolProc->cbCred }, 1643 { "NT_PRPRIV", NT_PRPRIV, pSolProc->pPriv, PRIV_PRPRIV_SIZE(pSolProc->pPriv) }, 1644 { "NT_PRPRIVINFO", NT_PRPRIVINFO, pSolProc->pcPrivImpl, PRIV_IMPL_INFO_SIZE(pSolProc->pcPrivImpl) }, 1645 { "NT_ZONENAME", NT_ZONENAME, pSolProc->szZoneName, strlen(pSolProc->szZoneName) + 1 } 1621 1646 }; 1622 1647 1623 1648 for (unsigned i = 0; i < RT_ELEMENTS(aElfNotes); i++) 1624 1649 { 1625 rc = ElfWriteNoteHeader(p VBoxCore, aElfNotes[i].Type, aElfNotes[i].pcv, aElfNotes[i].cb);1650 rc = ElfWriteNoteHeader(pSolCore, aElfNotes[i].Type, aElfNotes[i].pcv, aElfNotes[i].cb); 1626 1651 if (RT_FAILURE(rc)) 1627 1652 { … … 1635 1660 * we only dump the lwpsinfo_t in that case. 1636 1661 */ 1637 P VBOXSOLTHREADINFO pThreadInfo = pVBoxProc->pThreadInfoHead;1662 PRTSOLCORETHREADINFO pThreadInfo = pSolProc->pThreadInfoHead; 1638 1663 for (; pThreadInfo; pThreadInfo = pThreadInfo->pNext) 1639 1664 { 1640 rc = ElfWriteNoteHeader(p VBoxCore, NT_LWPSINFO, &pThreadInfo->Info, sizeof(lwpsinfo_t));1665 rc = ElfWriteNoteHeader(pSolCore, NT_LWPSINFO, &pThreadInfo->Info, sizeof(lwpsinfo_t)); 1641 1666 if (RT_FAILURE(rc)) 1642 1667 { … … 1647 1672 if (pThreadInfo->pStatus) 1648 1673 { 1649 rc = ElfWriteNoteHeader(p VBoxCore, NT_LWPSTATUS, pThreadInfo->pStatus, sizeof(lwpstatus_t));1674 rc = ElfWriteNoteHeader(pSolCore, NT_LWPSTATUS, pThreadInfo->pStatus, sizeof(lwpstatus_t)); 1650 1675 if (RT_FAILURE(rc)) 1651 1676 { … … 1675 1700 * Write mappings into the core file. 1676 1701 * 1677 * @param p VBoxCorePointer to the core object.1702 * @param pSolCore Pointer to the core object. 1678 1703 * 1679 1704 * @return IPRT status code. 1680 1705 */ 1681 static int ElfWriteMappings(P VBOXCORE pVBoxCore)1682 { 1683 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1706 static int ElfWriteMappings(PRTSOLCORE pSolCore) 1707 { 1708 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1684 1709 1685 1710 int rc = VERR_GENERAL_FAILURE; 1686 P VBOXSOLMAPINFO pMapInfo = pVBoxProc->pMapInfoHead;1711 PRTSOLCOREMAPINFO pMapInfo = pSolProc->pMapInfoHead; 1687 1712 while (pMapInfo) 1688 1713 { … … 1694 1719 { 1695 1720 size_t cb = RT_MIN(sizeof(achBuf), pMapInfo->pMap.pr_size - k); 1696 int rc2 = ProcReadAddrSpace(p VBoxProc, pMapInfo->pMap.pr_vaddr + k, &achBuf, cb);1721 int rc2 = ProcReadAddrSpace(pSolProc, pMapInfo->pMap.pr_vaddr + k, &achBuf, cb); 1697 1722 if (RT_FAILURE(rc2)) 1698 1723 { … … 1701 1726 } 1702 1727 1703 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, achBuf, sizeof(achBuf));1728 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, achBuf, sizeof(achBuf)); 1704 1729 if (RT_FAILURE(rc)) 1705 1730 { … … 1717 1742 if (sizeof(achBuf) != pMapInfo->pMap.pr_size) 1718 1743 CORELOGRELSYS((CORELOG_NAME "ElfWriteMappings: Huh!? something is wrong!\n")); 1719 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, &achBuf, sizeof(achBuf));1744 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &achBuf, sizeof(achBuf)); 1720 1745 if (RT_FAILURE(rc)) 1721 1746 { … … 1735 1760 * Write program headers for all mappings into the core file. 1736 1761 * 1737 * @param p VBoxCorePointer to the core object.1762 * @param pSolCore Pointer to the core object. 1738 1763 * 1739 1764 * @return IPRT status code. 1740 1765 */ 1741 static int ElfWriteMappingHeaders(P VBOXCORE pVBoxCore)1742 { 1743 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);1744 1745 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1766 static int ElfWriteMappingHeaders(PRTSOLCORE pSolCore) 1767 { 1768 AssertReturn(pSolCore, VERR_INVALID_POINTER); 1769 1770 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1746 1771 Elf_Phdr ProgHdr; 1747 1772 RT_ZERO(ProgHdr); … … 1749 1774 1750 1775 int rc = VERR_GENERAL_FAILURE; 1751 P VBOXSOLMAPINFO pMapInfo = pVBoxProc->pMapInfoHead;1776 PRTSOLCOREMAPINFO pMapInfo = pSolProc->pMapInfoHead; 1752 1777 while (pMapInfo) 1753 1778 { 1754 1779 ProgHdr.p_vaddr = pMapInfo->pMap.pr_vaddr; /* Virtual address of this mapping in the process address space */ 1755 ProgHdr.p_offset = p VBoxCore->offWrite; /* Where this mapping is located in the core file */1780 ProgHdr.p_offset = pSolCore->offWrite; /* Where this mapping is located in the core file */ 1756 1781 ProgHdr.p_memsz = pMapInfo->pMap.pr_size; /* Size of the memory image of the mapping */ 1757 1782 ProgHdr.p_filesz = pMapInfo->pMap.pr_size; /* Size of the file image of the mapping */ … … 1768 1793 ProgHdr.p_flags |= PF_SUNW_FAILURE; 1769 1794 1770 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, &ProgHdr, sizeof(ProgHdr));1795 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ProgHdr, sizeof(ProgHdr)); 1771 1796 if (RT_FAILURE(rc)) 1772 1797 { … … 1775 1800 } 1776 1801 1777 p VBoxCore->offWrite += ProgHdr.p_filesz;1802 pSolCore->offWrite += ProgHdr.p_filesz; 1778 1803 pMapInfo = pMapInfo->pNext; 1779 1804 } … … 1786 1811 * to be in suspended state (i.e. called after CreateCore). 1787 1812 * 1788 * @param p VBoxCorePointer to the core object.1813 * @param pSolCore Pointer to the core object. 1789 1814 * @param pfnWriter Pointer to the writer function to override default writer (NULL uses default). 1790 1815 * 1791 1816 * @remarks Resumes all suspended threads, unless it's an invalid core. This 1792 1817 * function must be called only -after- rtCoreDumperCreateCore(). 1793 * @return VBoxstatus.1794 */ 1795 static int rtCoreDumperWriteCore(P VBOXCORE pVBoxCore, PFNCOREWRITER pfnWriter)1796 { 1797 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);1798 1799 if (!p VBoxCore->fIsValid)1818 * @return IPRT status. 1819 */ 1820 static int rtCoreDumperWriteCore(PRTSOLCORE pSolCore, PFNRTCOREWRITER pfnWriter) 1821 { 1822 AssertReturn(pSolCore, VERR_INVALID_POINTER); 1823 1824 if (!pSolCore->fIsValid) 1800 1825 return VERR_INVALID_STATE; 1801 1826 1802 1827 if (pfnWriter) 1803 p VBoxCore->pfnWriter = pfnWriter;1804 1805 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1828 pSolCore->pfnWriter = pfnWriter; 1829 1830 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 1806 1831 char szPath[PATH_MAX]; 1807 1832 int rc = VINF_SUCCESS; … … 1810 1835 * Open the process address space file. 1811 1836 */ 1812 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/as", (int)p VBoxProc->Process);1837 RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/as", (int)pSolProc->Process); 1813 1838 int fd = open(szPath, O_RDONLY); 1814 1839 if (fd < 0) … … 1819 1844 } 1820 1845 1821 p VBoxProc->hAs = (RTFILE)(uintptr_t)fd;1846 pSolProc->fdAs = fd; 1822 1847 1823 1848 /* 1824 1849 * Create the core file. 1825 1850 */ 1826 fd = open(p VBoxCore->szCorePath, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR);1851 fd = open(pSolCore->szCorePath, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR); 1827 1852 if (fd < 0) 1828 1853 { 1829 1854 rc = RTErrConvertFromErrno(fd); 1830 CORELOGRELSYS((CORELOG_NAME "WriteCore: failed to open %s. rc=%Rrc\n", p VBoxCore->szCorePath, rc));1855 CORELOGRELSYS((CORELOG_NAME "WriteCore: failed to open %s. rc=%Rrc\n", pSolCore->szCorePath, rc)); 1831 1856 goto WriteCoreDone; 1832 1857 } 1833 1858 1834 p VBoxCore->hCoreFile = (RTFILE)(uintptr_t)fd;1835 1836 p VBoxCore->offWrite = 0;1837 uint32_t cProgHdrs = p VBoxProc->cMappings + 2; /* two PT_NOTE program headers (old, new style) */1859 pSolCore->fdCoreFile = fd; 1860 1861 pSolCore->offWrite = 0; 1862 uint32_t cProgHdrs = pSolProc->cMappings + 2; /* two PT_NOTE program headers (old, new style) */ 1838 1863 1839 1864 /* … … 1864 1889 ElfHdr.e_phentsize = sizeof(Elf_Phdr); 1865 1890 ElfHdr.e_shentsize = sizeof(Elf_Shdr); 1866 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, &ElfHdr, sizeof(ElfHdr));1891 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ElfHdr, sizeof(ElfHdr)); 1867 1892 if (RT_FAILURE(rc)) 1868 1893 { … … 1882 1907 * Write old-style NOTE program header. 1883 1908 */ 1884 p VBoxCore->offWrite += sizeof(ElfHdr) + cProgHdrs * sizeof(ProgHdr);1885 ProgHdr.p_offset = p VBoxCore->offWrite;1886 ProgHdr.p_filesz = ElfNoteSectionSize(p VBoxCore, enmOldEra);1887 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, &ProgHdr, sizeof(ProgHdr));1909 pSolCore->offWrite += sizeof(ElfHdr) + cProgHdrs * sizeof(ProgHdr); 1910 ProgHdr.p_offset = pSolCore->offWrite; 1911 ProgHdr.p_filesz = ElfNoteSectionSize(pSolCore, enmOldEra); 1912 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ProgHdr, sizeof(ProgHdr)); 1888 1913 if (RT_FAILURE(rc)) 1889 1914 { … … 1895 1920 * Write new-style NOTE program header. 1896 1921 */ 1897 p VBoxCore->offWrite += ProgHdr.p_filesz;1898 ProgHdr.p_offset = p VBoxCore->offWrite;1899 ProgHdr.p_filesz = ElfNoteSectionSize(p VBoxCore, enmNewEra);1900 rc = p VBoxCore->pfnWriter(pVBoxCore->hCoreFile, &ProgHdr, sizeof(ProgHdr));1922 pSolCore->offWrite += ProgHdr.p_filesz; 1923 ProgHdr.p_offset = pSolCore->offWrite; 1924 ProgHdr.p_filesz = ElfNoteSectionSize(pSolCore, enmNewEra); 1925 rc = pSolCore->pfnWriter(pSolCore->fdCoreFile, &ProgHdr, sizeof(ProgHdr)); 1901 1926 if (RT_FAILURE(rc)) 1902 1927 { … … 1908 1933 * Write program headers per mapping. 1909 1934 */ 1910 p VBoxCore->offWrite += ProgHdr.p_filesz;1911 rc = ElfWriteMappingHeaders(p VBoxCore);1935 pSolCore->offWrite += ProgHdr.p_filesz; 1936 rc = ElfWriteMappingHeaders(pSolCore); 1912 1937 if (RT_FAILURE(rc)) 1913 1938 { … … 1919 1944 * Write old-style note section. 1920 1945 */ 1921 rc = ElfWriteNoteSection(p VBoxCore, enmOldEra);1946 rc = ElfWriteNoteSection(pSolCore, enmOldEra); 1922 1947 if (RT_FAILURE(rc)) 1923 1948 { … … 1929 1954 * Write new-style section. 1930 1955 */ 1931 rc = ElfWriteNoteSection(p VBoxCore, enmNewEra);1956 rc = ElfWriteNoteSection(pSolCore, enmNewEra); 1932 1957 if (RT_FAILURE(rc)) 1933 1958 { … … 1939 1964 * Write all mappings. 1940 1965 */ 1941 rc = ElfWriteMappings(p VBoxCore);1966 rc = ElfWriteMappings(pSolCore); 1942 1967 if (RT_FAILURE(rc)) 1943 1968 { … … 1948 1973 1949 1974 WriteCoreDone: 1950 if (p VBoxCore->hCoreFile != NIL_RTFILE) /* Initialized in rtCoreDumperCreateCore() */1951 { 1952 RTFileClose(pVBoxCore->hCoreFile);1953 p VBoxCore->hCoreFile = NIL_RTFILE;1954 } 1955 1956 if (p VBoxProc->hAs != NIL_RTFILE) /* Initialized in rtCoreDumperCreateCore() */1957 { 1958 RTFileClose(pVBoxProc->hAs);1959 p VBoxProc->hAs = NIL_RTFILE;1960 } 1961 1962 rtCoreDumperResumeThreads(p VBoxCore);1975 if (pSolCore->fdCoreFile != -1) /* Initialized in rtCoreDumperCreateCore() */ 1976 { 1977 close(pSolCore->fdCoreFile); 1978 pSolCore->fdCoreFile = -1; 1979 } 1980 1981 if (pSolProc->fdAs != -1) /* Initialized in rtCoreDumperCreateCore() */ 1982 { 1983 close(pSolProc->fdAs); 1984 pSolProc->fdAs = -1; 1985 } 1986 1987 rtCoreDumperResumeThreads(pSolCore); 1963 1988 return rc; 1964 1989 } … … 1970 1995 * are ultimately resumed en-masse) already suspended while calling this function. 1971 1996 * 1972 * @param p VBoxCorePointer to a core object.1997 * @param pSolCore Pointer to a core object. 1973 1998 * @param pContext Pointer to the caller context thread. 1974 1999 * @param pszCoreFilePath Path to the core file. If NULL is passed, the global … … 1978 2003 * @return IPRT status code. 1979 2004 */ 1980 static int rtCoreDumperCreateCore(P VBOXCORE pVBoxCore, ucontext_t *pContext, const char *pszCoreFilePath)1981 { 1982 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);2005 static int rtCoreDumperCreateCore(PRTSOLCORE pSolCore, ucontext_t *pContext, const char *pszCoreFilePath) 2006 { 2007 AssertReturn(pSolCore, VERR_INVALID_POINTER); 1983 2008 AssertReturn(pContext, VERR_INVALID_POINTER); 1984 2009 … … 1986 2011 * Initialize core structures. 1987 2012 */ 1988 memset(p VBoxCore, 0, sizeof(VBOXCORE));1989 p VBoxCore->pfnReader = &ReadFileNoIntr;1990 p VBoxCore->pfnWriter = &WriteFileNoIntr;1991 p VBoxCore->fIsValid = false;1992 p VBoxCore->hCoreFile = NIL_RTFILE;1993 1994 P VBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;1995 p VBoxProc->Process = RTProcSelf();1996 p VBoxProc->hCurThread = _lwp_self(); /* thr_self() */1997 p VBoxProc->hAs = NIL_RTFILE;1998 p VBoxProc->pCurThreadCtx = pContext;1999 p VBoxProc->CoreContent = CC_CONTENT_DEFAULT;2000 2001 RTProcGetExecutablePath(p VBoxProc->szExecPath, sizeof(pVBoxProc->szExecPath)); /* this gets full path not just name */2002 p VBoxProc->pszExecName = RTPathFilename(pVBoxProc->szExecPath);2013 memset(pSolCore, 0, sizeof(RTSOLCORE)); 2014 pSolCore->pfnReader = &ReadFileNoIntr; 2015 pSolCore->pfnWriter = &WriteFileNoIntr; 2016 pSolCore->fIsValid = false; 2017 pSolCore->fdCoreFile = -1; 2018 2019 PRTSOLCOREPROCESS pSolProc = &pSolCore->SolProc; 2020 pSolProc->Process = RTProcSelf(); 2021 pSolProc->hCurThread = _lwp_self(); /* thr_self() */ 2022 pSolProc->fdAs = -1; 2023 pSolProc->pCurThreadCtx = pContext; 2024 pSolProc->CoreContent = CC_CONTENT_DEFAULT; 2025 2026 RTProcGetExecutablePath(pSolProc->szExecPath, sizeof(pSolProc->szExecPath)); /* this gets full path not just name */ 2027 pSolProc->pszExecName = RTPathFilename(pSolProc->szExecPath); 2003 2028 2004 2029 /* … … 2016 2041 { 2017 2042 /* We cannot call RTPathAbs*() as they call getcwd() which calls malloc. */ 2018 RTStrPrintf(p VBoxCore->szCorePath, sizeof(pVBoxCore->szCorePath), "%s/core.vb.%s.%d",2019 g_szCoreDumpDir, p VBoxProc->pszExecName, (int)pVBoxProc->Process);2043 RTStrPrintf(pSolCore->szCorePath, sizeof(pSolCore->szCorePath), "%s/core.vb.%s.%d", 2044 g_szCoreDumpDir, pSolProc->pszExecName, (int)pSolProc->Process); 2020 2045 } 2021 2046 else 2022 RTStrPrintf(p VBoxCore->szCorePath, sizeof(pVBoxCore->szCorePath), "%s/core.vb.%s", g_szCoreDumpDir, g_szCoreDumpFile);2047 RTStrPrintf(pSolCore->szCorePath, sizeof(pSolCore->szCorePath), "%s/core.vb.%s", g_szCoreDumpDir, g_szCoreDumpFile); 2023 2048 } 2024 2049 else 2025 RTStrCopy(p VBoxCore->szCorePath, sizeof(pVBoxCore->szCorePath), pszCoreFilePath);2026 2027 CORELOG((CORELOG_NAME "CreateCore: Taking Core %s from Thread %d\n", p VBoxCore->szCorePath, (int)pVBoxProc->hCurThread));2050 RTStrCopy(pSolCore->szCorePath, sizeof(pSolCore->szCorePath), pszCoreFilePath); 2051 2052 CORELOG((CORELOG_NAME "CreateCore: Taking Core %s from Thread %d\n", pSolCore->szCorePath, (int)pSolProc->hCurThread)); 2028 2053 2029 2054 /* 2030 2055 * Quiesce the process. 2031 2056 */ 2032 int rc = rtCoreDumperSuspendThreads(p VBoxCore);2057 int rc = rtCoreDumperSuspendThreads(pSolCore); 2033 2058 if (RT_SUCCESS(rc)) 2034 2059 { 2035 rc = ProcReadInfo(p VBoxCore);2060 rc = ProcReadInfo(pSolCore); 2036 2061 if (RT_SUCCESS(rc)) 2037 2062 { 2038 GetOldProcessInfo(p VBoxCore, &pVBoxProc->ProcInfoOld);2039 if (IsProcessArchNative(p VBoxProc))2063 GetOldProcessInfo(pSolCore, &pSolProc->ProcInfoOld); 2064 if (IsProcessArchNative(pSolProc)) 2040 2065 { 2041 2066 /* 2042 2067 * Read process status, information such as number of active LWPs will be invalid since we just quiesced the process. 2043 2068 */ 2044 rc = ProcReadStatus(p VBoxCore);2069 rc = ProcReadStatus(pSolCore); 2045 2070 if (RT_SUCCESS(rc)) 2046 2071 { 2047 rc = AllocMemoryArea(p VBoxCore);2072 rc = AllocMemoryArea(pSolCore); 2048 2073 if (RT_SUCCESS(rc)) 2049 2074 { … … 2051 2076 { 2052 2077 const char *pszName; 2053 PFN COREACCUMULATOR pfnAcc;2078 PFNRTSOLCOREACCUMULATOR pfnAcc; 2054 2079 bool fOptional; 2055 2080 } aAccumulators[] = … … 2066 2091 for (unsigned i = 0; i < RT_ELEMENTS(aAccumulators); i++) 2067 2092 { 2068 rc = aAccumulators[i].pfnAcc(p VBoxCore);2093 rc = aAccumulators[i].pfnAcc(pSolCore); 2069 2094 if (RT_FAILURE(rc)) 2070 2095 { … … 2077 2102 if (RT_SUCCESS(rc)) 2078 2103 { 2079 p VBoxCore->fIsValid = true;2104 pSolCore->fIsValid = true; 2080 2105 return VINF_SUCCESS; 2081 2106 } 2082 2107 2083 FreeMemoryArea(p VBoxCore);2108 FreeMemoryArea(pSolCore); 2084 2109 } 2085 2110 else … … 2101 2126 * Resume threads on failure. 2102 2127 */ 2103 rtCoreDumperResumeThreads(p VBoxCore);2128 rtCoreDumperResumeThreads(pSolCore); 2104 2129 } 2105 2130 else … … 2113 2138 * Destroy an existing core object. 2114 2139 * 2115 * @param p VBoxCorePointer to the core object.2140 * @param pSolCore Pointer to the core object. 2116 2141 * 2117 2142 * @return IPRT status code. 2118 2143 */ 2119 static int rtCoreDumperDestroyCore(P VBOXCORE pVBoxCore)2120 { 2121 AssertReturn(p VBoxCore, VERR_INVALID_POINTER);2122 if (!p VBoxCore->fIsValid)2144 static int rtCoreDumperDestroyCore(PRTSOLCORE pSolCore) 2145 { 2146 AssertReturn(pSolCore, VERR_INVALID_POINTER); 2147 if (!pSolCore->fIsValid) 2123 2148 return VERR_INVALID_STATE; 2124 2149 2125 FreeMemoryArea(p VBoxCore);2126 p VBoxCore->fIsValid = false;2150 FreeMemoryArea(pSolCore); 2151 pSolCore->fIsValid = false; 2127 2152 return VINF_SUCCESS; 2128 2153 } … … 2152 2177 * Any errors would resume all threads if they were halted. 2153 2178 */ 2154 VBOXCORE VBoxCore;2155 RT_ZERO( VBoxCore);2156 int rc = rtCoreDumperCreateCore(& VBoxCore, pContext, pszOutputFile);2179 RTSOLCORE SolCore; 2180 RT_ZERO(SolCore); 2181 int rc = rtCoreDumperCreateCore(&SolCore, pContext, pszOutputFile); 2157 2182 if (RT_SUCCESS(rc)) 2158 2183 { 2159 rc = rtCoreDumperWriteCore(& VBoxCore, &WriteFileNoIntr);2184 rc = rtCoreDumperWriteCore(&SolCore, &WriteFileNoIntr); 2160 2185 if (RT_SUCCESS(rc)) 2161 CORELOGRELSYS((CORELOG_NAME "Core dumped in %s\n", VBoxCore.szCorePath));2186 CORELOGRELSYS((CORELOG_NAME "Core dumped in %s\n", SolCore.szCorePath)); 2162 2187 else 2163 CORELOGRELSYS((CORELOG_NAME "TakeDump: WriteCore failed. szCorePath=%s rc=%Rrc\n", VBoxCore.szCorePath, rc));2164 2165 rtCoreDumperDestroyCore(& VBoxCore);2188 CORELOGRELSYS((CORELOG_NAME "TakeDump: WriteCore failed. szCorePath=%s rc=%Rrc\n", SolCore.szCorePath, rc)); 2189 2190 rtCoreDumperDestroyCore(&SolCore); 2166 2191 } 2167 2192 else -
trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.h
r31980 r37631 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT Testcase - Core dump, header.3 * IPRT - Custom Core Dumper, Solaris. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 25 25 */ 26 26 27 #include <iprt/process.h> 28 #include <iprt/file.h> 27 #include <iprt/types.h> 29 28 30 29 #ifdef RT_OS_SOLARIS … … 62 61 #ifdef RT_OS_SOLARIS 63 62 /** 64 * VBOXSOLMAPINFO: Memory mapping description.63 * Memory mapping descriptor employed by the solaris core dumper. 65 64 */ 66 typedef struct VBOXSOLMAPINFO65 typedef struct RTSOLCOREMAPINFO 67 66 { 68 prmap_t pMap; /* Proc description of this mapping */ 69 int fError; /* Any error reading this mapping (errno) */ 70 struct VBOXSOLMAPINFO *pNext; /* Pointer to the next mapping */ 71 } VBOXSOLMAPINFO; 72 typedef VBOXSOLMAPINFO *PVBOXSOLMAPINFO; 67 prmap_t pMap; /**< Proc description of this mapping */ 68 int fError; /**< Any error reading this mapping (errno) */ 69 struct RTSOLCOREMAPINFO *pNext; /**< Pointer to the next mapping */ 70 } RTSOLCOREMAPINFO; 71 /** Pointer to a solaris memory mapping descriptor. */ 72 typedef RTSOLCOREMAPINFO *PRTSOLCOREMAPINFO; 73 73 74 74 /** 75 * VBOXSOLCORETYPE: Whether this is an old or new stylecore.75 * Whether this is an old or new style solaris core. 76 76 */ 77 typedef enum VBOXSOLCORETYPE77 typedef enum RTSOLCORETYPE 78 78 { 79 enmOldEra = 0x01d, /*old */80 enmNewEra = 0x5c1f1 /*sci-fi */81 } VBOXSOLCORETYPE;79 enmOldEra = 0x01d, /**< old */ 80 enmNewEra = 0x5c1f1 /**< sci-fi */ 81 } RTSOLCORETYPE; 82 82 83 83 /** 84 * VBOXSOLTHREADINFO: Per-Thread information.84 * Per-Thread information employed by the solaris core dumper. 85 85 */ 86 typedef struct VBOXSOLTHREADINFO86 typedef struct RTSOLCORETHREADINFO 87 87 { 88 lwpsinfo_t Info; /* Proc description of this thread */89 lwpstatus_t *pStatus; /* Proc description of this thread's status (can be NULL, zombie lwp) */90 struct VBOXSOLTHREADINFO *pNext; /*Pointer to the next thread */91 } VBOXSOLTHREADINFO;92 typedef VBOXSOLTHREADINFO *PVBOXSOLTHREADINFO;88 lwpsinfo_t Info; /**< Proc description of this thread */ 89 lwpstatus_t *pStatus; /**< Proc description of this thread's status (can be NULL, zombie lwp) */ 90 struct RTSOLCORETHREADINFO *pNext; /**< Pointer to the next thread */ 91 } RTSOLCORETHREADINFO; 92 typedef RTSOLCORETHREADINFO *PRTSOLCORETHREADINFO; 93 93 #endif 94 94 95 95 96 96 /** 97 * VBOXPROCESS:Current (also the core target) process information.97 * Current (also the core target) process information. 98 98 */ 99 typedef struct VBOXPROCESS99 typedef struct RTSOLCOREPROCESS 100 100 { 101 RTPROCESS Process; /* The pid of the process */102 char szExecPath[PATH_MAX]; /* Path of the executable */103 char *pszExecName; /* Name of the executable file */101 RTPROCESS Process; /**< The pid of the process */ 102 char szExecPath[PATH_MAX]; /**< Path of the executable */ 103 char *pszExecName; /**< Name of the executable file */ 104 104 #ifdef RT_OS_SOLARIS 105 psinfo_t ProcInfo; /* Process info. */106 prpsinfo_t ProcInfoOld; /* Process info. Older version (for GDB compat.) */107 pstatus_t ProcStatus; /* Process status info. */108 thread_t hCurThread; /* The current thread */109 ucontext_t *pCurThreadCtx; /* Context info. of current thread before starting to dump */110 RTFILE hAs; /* proc/<pid/as file handle */111 auxv_t *pAuxVecs; /* Aux vector of process */112 int cAuxVecs; /* Number of aux vector entries */113 P VBOXSOLMAPINFO pMapInfoHead; /*Pointer to the head of list of mappings */114 uint32_t cMappings; /* Number of mappings (count of pMapInfoHead list) */115 P VBOXSOLTHREADINFO pThreadInfoHead; /*Pointer to the head of list of threads */116 uint64_t cThreads; /* Number of threads (count of pThreadInfoHead list) */117 char szPlatform[SYS_NMLN]; /* Platform name */118 char szZoneName[ZONENAME_MAX]; /* Zone name */119 struct utsname UtsName; /* UTS name */120 void *pvCred; /* Process credential info. */121 size_t cbCred; /* Size of process credential info. */122 void *pvLdt; /* Process LDT info. */123 size_t cbLdt; /* Size of the LDT info. */124 prpriv_t *pPriv; /* Process privilege info. */125 size_t cbPriv; /* Size of process privilege info. */126 const priv_impl_info_t *pcPrivImpl; /* Process privilege implementation info. (opaque handle) */127 core_content_t CoreContent; /* What information goes in the core */105 psinfo_t ProcInfo; /**< Process info. */ 106 prpsinfo_t ProcInfoOld; /**< Process info. Older version (for GDB compat.) */ 107 pstatus_t ProcStatus; /**< Process status info. */ 108 thread_t hCurThread; /**< The current thread */ 109 ucontext_t *pCurThreadCtx; /**< Context info. of current thread before starting to dump */ 110 int fdAs; /**< proc/pid/as file handle */ 111 auxv_t *pAuxVecs; /**< Aux vector of process */ 112 int cAuxVecs; /**< Number of aux vector entries */ 113 PRTSOLCOREMAPINFO pMapInfoHead; /**< Pointer to the head of list of mappings */ 114 uint32_t cMappings; /**< Number of mappings (count of pMapInfoHead list) */ 115 PRTSOLCORETHREADINFO pThreadInfoHead; /**< Pointer to the head of list of threads */ 116 uint64_t cThreads; /**< Number of threads (count of pThreadInfoHead list) */ 117 char szPlatform[SYS_NMLN]; /**< Platform name */ 118 char szZoneName[ZONENAME_MAX]; /**< Zone name */ 119 struct utsname UtsName; /**< UTS name */ 120 void *pvCred; /**< Process credential info. */ 121 size_t cbCred; /**< Size of process credential info. */ 122 void *pvLdt; /**< Process LDT info. */ 123 size_t cbLdt; /**< Size of the LDT info. */ 124 prpriv_t *pPriv; /**< Process privilege info. */ 125 size_t cbPriv; /**< Size of process privilege info. */ 126 const priv_impl_info_t *pcPrivImpl; /**< Process privilege implementation info. (opaque handle) */ 127 core_content_t CoreContent; /**< What information goes in the core */ 128 128 #else 129 129 # error Port Me! 130 130 #endif 131 131 132 } VBOXPROCESS;133 typedef VBOXPROCESS *PVBOXPROCESS;132 } RTSOLCOREPROCESS; 133 typedef RTSOLCOREPROCESS *PRTSOLCOREPROCESS; 134 134 135 typedef int (*PFN COREREADER)(RTFILE hFile, void *pv, size_t cb);136 typedef int (*PFN COREWRITER)(RTFILEhFile, const void *pcv, size_t cb);135 typedef int (*PFNRTCOREREADER)(int fdFile, void *pv, size_t cb); 136 typedef int (*PFNRTCOREWRITER)(int fdhFile, const void *pcv, size_t cb); 137 137 138 138 /** 139 * VBOXCORE: Core file object.139 * The solaris core file object. 140 140 */ 141 typedef struct VBOXCORE141 typedef struct RTSOLCORE 142 142 { 143 char szCorePath[PATH_MAX]; /* Path of the core file */144 VBOXPROCESS VBoxProc; /*Current process information */145 void *pvCore; /* Pointer to memory area during dumping */146 size_t cbCore; /* Size of memory area during dumping */147 void *pvFree; /* Pointer to base of free range in preallocated memory area */148 bool fIsValid; /* Whether core information has been fully collected */149 PFN COREREADER pfnReader; /*Reader function */150 PFN COREWRITER pfnWriter; /*Writer function */151 RTFILE hCoreFile; /*Core file (used only while writing the core) */152 RTFOFF offWrite; /* Segment/section offset (used only while writing the core) */153 } VBOXCORE;154 typedef VBOXCORE *PVBOXCORE;143 char szCorePath[PATH_MAX]; /**< Path of the core file */ 144 RTSOLCOREPROCESS SolProc; /**< Current process information */ 145 void *pvCore; /**< Pointer to memory area during dumping */ 146 size_t cbCore; /**< Size of memory area during dumping */ 147 void *pvFree; /**< Pointer to base of free range in preallocated memory area */ 148 bool fIsValid; /**< Whether core information has been fully collected */ 149 PFNRTCOREREADER pfnReader; /**< Reader function */ 150 PFNRTCOREWRITER pfnWriter; /**< Writer function */ 151 int fdCoreFile; /**< Core file (used only while writing the core) */ 152 RTFOFF offWrite; /**< Segment/section offset (used only while writing the core) */ 153 } RTSOLCORE; 154 typedef RTSOLCORE *PRTSOLCORE; 155 155 156 typedef int (*PFN COREACCUMULATOR)(PVBOXCORE pVBoxCore);157 typedef int (*PFN CORETHREADWORKER)(PVBOXCORE pVBoxCore, void *pvThreadInfo);156 typedef int (*PFNRTSOLCOREACCUMULATOR)(PRTSOLCORE pSolCore); 157 typedef int (*PFNRTSOLCORETHREADWORKER)(PRTSOLCORE pSolCore, void *pvThreadInfo); 158 158 -
trunk/src/VBox/Runtime/testcase/tstRTCoreDump.cpp
r32350 r37631 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 28 * Header Files * 29 29 *******************************************************************************/ 30 #include <iprt/types.h> 30 #include <iprt/coredumper.h> 31 32 #include <iprt/test.h> 31 33 #include <iprt/err.h> 32 34 #include <iprt/initterm.h> 33 35 #include <iprt/thread.h> 34 #include <iprt/stream.h>35 #include <iprt/coredumper.h>36 36 37 37 … … 39 39 * Globals * 40 40 *******************************************************************************/ 41 static unsigned volatile g_cErrors = 0; 42 43 static DECLCALLBACK(int) SleepyThread(RTTHREAD Thread, void *pvUser) 41 static DECLCALLBACK(int) SleepyThread(RTTHREAD hThread, void *pvUser) 44 42 { 45 43 NOREF(pvUser); 46 RTThread Sleep(90000000);44 RTThreadUserWait(hThread, 90000000); 47 45 return VINF_SUCCESS; 48 46 } … … 50 48 int main() 51 49 { 52 RTR3Init(); 53 RTPrintf("tstRTCoreDump: TESTING...\n"); 50 RTTEST hTest; 51 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTCoreDump", &hTest); 52 if (rcExit != RTEXITCODE_SUCCESS) 53 return rcExit; 54 RTTestBanner(hTest); 54 55 55 56 /* 56 57 * Setup core dumping. 57 58 */ 58 int rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | RTCOREDUMPER_FLAGS_LIVE_CORE); 59 int rc; 60 RTTESTI_CHECK_RC(rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | RTCOREDUMPER_FLAGS_LIVE_CORE), 61 VINF_SUCCESS); 59 62 if (RT_SUCCESS(rc)) 60 63 { … … 63 66 */ 64 67 RTTHREAD ahThreads[5]; 65 unsigned i = 0;66 for ( ; i < RT_ELEMENTS(ahThreads); i++)68 unsigned i; 69 for (i = 0; i < RT_ELEMENTS(ahThreads); i++) 67 70 { 68 rc = RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1"); 69 if (RT_FAILURE(rc)) 70 { 71 RTPrintf("tstRTCoreDump: FAILURE(%d) - %d RTThreadCreate failed, rc=%Rrc\n", __LINE__, i, rc); 72 g_cErrors++; 73 ahThreads[i] = NIL_RTTHREAD; 74 break; 75 } 71 RTTESTI_CHECK_RC_BREAK(RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, 72 RTTHREADFLAGS_WAITABLE, "TEST1"), 73 VINF_SUCCESS); 76 74 } 77 RT Printf("Spawned %d threads.\n", i);75 RTTestIPrintf(RTTESTLVL_ALWAYS, "Spawned %d threads.\n", i); 78 76 79 77 /* 80 78 * Write the core to disk. 81 79 */ 82 rc = RTCoreDumperTakeDump(NULL, false /* fLiveCore*/); 83 if (RT_FAILURE(rc)) 80 RTTESTI_CHECK_RC(RTCoreDumperTakeDump(NULL, true /* fLiveCore*/), VINF_SUCCESS); 81 82 /* 83 * Clean up. 84 */ 85 RTTESTI_CHECK_RC(RTCoreDumperDisable(), VINF_SUCCESS); 86 while (i-- > 0) 84 87 { 85 g_cErrors++;86 RT Printf("RTCoreDumperTakeDump failed. rc=%Rrc\n", rc);88 RTTESTI_CHECK_RC(RTThreadUserSignal(ahThreads[i]), VINF_SUCCESS); 89 RTTESTI_CHECK_RC(RTThreadWait(ahThreads[i], 60*1000, NULL), VINF_SUCCESS); 87 90 } 88 RTCoreDumperDisable();89 }90 else91 {92 g_cErrors++;93 RTPrintf("RTCoreDumperSetup failed. rc=%Rrc\n", rc);94 91 } 95 92 … … 97 94 * Summary. 98 95 */ 99 if (!g_cErrors) 100 RTPrintf("tstRTCoreDump: SUCCESS\n"); 101 else 102 RTPrintf("tstRTCoreDump: FAILURE - %d errors\n", g_cErrors); 103 104 return !!g_cErrors; 96 return RTTestSummaryAndDestroy(hTest); 105 97 } 106 98
Note:
See TracChangeset
for help on using the changeset viewer.