VirtualBox

Changeset 36465 in vbox


Ignore:
Timestamp:
Mar 29, 2011 4:22:33 PM (14 years ago)
Author:
vboxsync
Message:

Runtime/r3/solaris/coredumper: replace RTFileOpen() with open() syscalls to avoid touching the heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/solaris/coredumper-solaris.cpp

    r36210 r36465  
    5353# include <sys/systeminfo.h>
    5454# include <sys/mman.h>
     55# include <sys/types.h>
     56# include <sys/stat.h>
     57# include <fcntl.h>
    5558# include <ucontext.h>
    5659#endif  /* RT_OS_SOLARIS */
     
    212215{
    213216    uint64_t cb = 0;
    214     RTFILE hFile;
    215     int rc = RTFileOpen(&hFile, pszPath, RTFILE_O_OPEN | RTFILE_O_READ);
    216     if (RT_SUCCESS(rc))
    217     {
     217    int fd = open(pszPath, O_RDONLY);
     218    if (fd >= 0)
     219    {
     220        RTFILE hFile = fd;
    218221        RTFileGetSize(hFile, &cb);
    219222        RTFileClose(hFile);
    220223    }
    221224    else
    222         CORELOGRELSYS((CORELOG_NAME "GetFileSize failed to open %s rc=%Rrc\n", pszPath, rc));
     225        CORELOGRELSYS((CORELOG_NAME "GetFileSize: failed to open %s rc=%Rrc\n", pszPath, RTErrConvertFromErrno(fd)));
    223226    return cb < ~(size_t)0 ? (size_t)cb : ~(size_t)0;
    224227}
     
    350353 * @param pcb               Where to store size of the buffer.
    351354 *
    352  * @return IPRT status code.
     355 * @return IPRT status code. If the proc file is 0 bytes, VINF_SUCCESS is
     356 *          returned with pointed to values of @c ppv, @c pcb set to NULL and 0
     357 *          respectively.
    353358 */
    354359static int ProcReadFileInto(PVBOXCORE pVBoxCore, const char *pszProcFileName, void **ppv, size_t *pcb)
     
    358363    char szPath[PATH_MAX];
    359364    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/%s", (int)pVBoxCore->VBoxProc.Process, pszProcFileName);
    360     RTFILE hFile;
    361     int rc = RTFileOpen(&hFile, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    362     if (RT_SUCCESS(rc))
    363     {
     365    int rc = VINF_SUCCESS;
     366    int fd = open(szPath, O_RDONLY);
     367    if (fd >= 0)
     368    {
     369        RTFILE hFile = fd;
    364370        uint64_t u64Size;
    365371        RTFileGetSize(hFile, &u64Size);
     
    377383            *pcb =  0;
    378384            *ppv = NULL;
     385            rc = VINF_SUCCESS;
    379386        }
    380387        RTFileClose(hFile);
    381388    }
    382389    else
     390    {
     391        rc = RTErrConvertFromErrno(fd);
    383392        CORELOGRELSYS((CORELOG_NAME "ProcReadFileInto: failed to open %s. rc=%Rrc\n", szPath, rc));
     393    }
    384394    return rc;
    385395}
     
    399409    PVBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;
    400410    char szPath[PATH_MAX];
    401     RTFILE hFile;
     411    int rc = VINF_SUCCESS;
    402412
    403413    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/psinfo", (int)pVBoxProc->Process);
    404     int rc = RTFileOpen(&hFile, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    405     if (RT_SUCCESS(rc))
    406     {
     414    int fd = open(szPath, O_RDONLY);
     415    if (fd >= 0)
     416    {
     417        RTFILE hFile = fd;
    407418        size_t cbProcInfo = sizeof(psinfo_t);
    408419        rc = ReadFileNoIntr(hFile, &pVBoxProc->ProcInfo, cbProcInfo);
    409     }
    410 
    411     RTFileClose(hFile);
     420        RTFileClose(hFile);
     421    }
     422    else
     423    {
     424        rc = RTErrConvertFromErrno(fd);
     425        CORELOGRELSYS((CORELOG_NAME "ProcReadInfo: failed to open %s. rc=%Rrc\n", szPath, rc));
     426    }
     427
    412428    return rc;
    413429}
     
    428444
    429445    char szPath[PATH_MAX];
    430     RTFILE hFile;
     446    int rc = VINF_SUCCESS;
    431447
    432448    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/status", (int)pVBoxProc->Process);
    433     int rc = RTFileOpen(&hFile, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    434     if (RT_SUCCESS(rc))
    435     {
     449    int fd = open(szPath, O_RDONLY);
     450    if (fd >= 0)
     451    {
     452        RTFILE hFile = fd;
    436453        size_t cbRead;
    437454        size_t cbProcStatus = sizeof(pstatus_t);
    438455        AssertCompile(sizeof(pstatus_t) == sizeof(pVBoxProc->ProcStatus));
    439456        rc = ReadFileNoIntr(hFile, &pVBoxProc->ProcStatus, cbProcStatus);
    440     }
    441     RTFileClose(hFile);
     457        RTFileClose(hFile);
     458    }
     459    else
     460    {
     461        rc = RTErrConvertFromErrno(fd);
     462        CORELOGRELSYS((CORELOG_NAME "ProcReadStatus: failed to open %s. rc=%Rrc\n", szPath, rc));
     463    }
    442464    return rc;
    443465}
     
    518540    PVBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;
    519541    char szPath[PATH_MAX];
    520     RTFILE hFile = NIL_RTFILE;
     542    int rc = VINF_SUCCESS;
    521543    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/auxv", (int)pVBoxProc->Process);
    522     int rc = RTFileOpen(&hFile, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    523     if (RT_FAILURE(rc))
    524     {
    525         CORELOGRELSYS((CORELOG_NAME "ProcReadAuxVecs: RTFileOpen %s failed rc=%Rrc\n", szPath, rc));
     544    int fd = open(szPath, O_RDONLY);
     545    if (fd < 0)
     546    {
     547        rc = RTErrConvertFromErrno(fd);
     548        CORELOGRELSYS((CORELOG_NAME "ProcReadAuxVecs: failed to open %s rc=%Rrc\n", szPath, rc));
    526549        return rc;
    527550    }
    528551
     552    RTFILE hFile = fd;
    529553    uint64_t u64Size;
    530554    RTFileGetSize(hFile, &u64Size);
     
    568592    }
    569593    else
     594    {
    570595        CORELOGRELSYS((CORELOG_NAME "ProcReadAuxVecs: aux file too small %u, expecting %u or more\n", cbAuxFile, sizeof(auxv_t)));
     596        rc = VERR_READ_ERROR;
     597    }
    571598
    572599    RTFileClose(hFile);
     
    608635    PVBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;
    609636    char szPath[PATH_MAX];
    610     RTFILE hFile = NIL_RTFILE;
     637    int rc = VINF_SUCCESS;
    611638    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/map", (int)pVBoxProc->Process);
    612     int rc = RTFileOpen(&hFile, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    613     if (RT_FAILURE(rc))
     639    int fd = open(szPath, O_RDONLY);
     640    if (fd < 0)
     641    {
     642        rc = RTErrConvertFromErrno(fd);
     643        CORELOGRELSYS((CORELOG_NAME "ProcReadMappings: failed to open %s. rc=%Rrc\n", szPath, rc));
    614644        return rc;
    615 
     645    }
     646
     647    RTFILE hFile = fd;
    616648    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/as", (int)pVBoxProc->Process);
    617     rc = RTFileOpen(&pVBoxProc->hAs, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    618     if (RT_SUCCESS(rc))
    619     {
     649    fd = open(szPath, O_RDONLY);
     650    if (fd >= 0)
     651    {
     652        pVBoxProc->hAs = fd;
     653
    620654        /*
    621655         * Allocate and read all the prmap_t objects from proc.
     
    11471181    RTStrPrintf(szLpsInfoPath, sizeof(szLpsInfoPath), "/proc/%d/lpsinfo", (int)pVBoxProc->Process);
    11481182
    1149     RTFILE hFile = NIL_RTFILE;
    1150     int rc = RTFileOpen(&hFile, szLpsInfoPath, RTFILE_O_READ);
    1151     if (RT_SUCCESS(rc))
    1152     {
     1183    int rc = VINF_SUCCESS;
     1184    int fd = open(szLpsInfoPath, O_RDONLY);
     1185    if (fd >= 0)
     1186    {
     1187        RTFILE hFile = fd;
    11531188        uint64_t u64Size;
    11541189        RTFileGetSize(hFile, &u64Size);
     
    11771212        RTFileClose(hFile);
    11781213    }
     1214    else
     1215        rc = RTErrConvertFromErrno(rc);
    11791216
    11801217    return rc;
     
    17521789 * @param pfnWriter         Pointer to the writer function to override default writer (NULL uses default).
    17531790 *
    1754  * @remarks Resumes all suspended threads, unless it's an invalid core.
     1791 * @remarks Resumes all suspended threads, unless it's an invalid core. This
     1792 *          function must be called only -after- rtCoreDumperCreateCore().
    17551793 * @return VBox status.
    17561794 */
     
    17671805    PVBOXPROCESS pVBoxProc = &pVBoxCore->VBoxProc;
    17681806    char szPath[PATH_MAX];
     1807    int rc = VINF_SUCCESS;
    17691808
    17701809    /*
     
    17721811     */
    17731812    RTStrPrintf(szPath, sizeof(szPath), "/proc/%d/as", (int)pVBoxProc->Process);
    1774     int rc = RTFileOpen(&pVBoxProc->hAs, szPath, RTFILE_O_OPEN | RTFILE_O_READ);
    1775     if (RT_FAILURE(rc))
    1776     {
     1813    int fd = open(szPath, O_RDONLY);
     1814    if (fd < 0)
     1815    {
     1816        rc = RTErrConvertFromErrno(fd);
    17771817        CORELOGRELSYS((CORELOG_NAME "WriteCore: Failed to open address space, %s. rc=%Rrc\n", szPath, rc));
    17781818        goto WriteCoreDone;
    17791819    }
    17801820
     1821    pVBoxProc->hAs = fd;
     1822
    17811823    /*
    17821824     * Create the core file.
    17831825     */
    1784     rc = RTFileOpen(&pVBoxCore->hCoreFile, pVBoxCore->szCorePath,
    1785                     RTFILE_O_OPEN_CREATE | RTFILE_O_TRUNCATE | RTFILE_O_READWRITE | RTFILE_O_DENY_ALL);
    1786     if (RT_FAILURE(rc))
    1787     {
     1826    fd = open(pVBoxCore->szCorePath, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR);
     1827    if (fd < 0)
     1828    {
     1829        rc = RTErrConvertFromErrno(fd);
    17881830        CORELOGRELSYS((CORELOG_NAME "WriteCore: failed to open %s. rc=%Rrc\n", pVBoxCore->szCorePath, rc));
    17891831        goto WriteCoreDone;
    17901832    }
     1833
     1834    pVBoxCore->hCoreFile = fd;
    17911835
    17921836    pVBoxCore->offWrite = 0;
     
    19041948
    19051949WriteCoreDone:
    1906     if (pVBoxCore->hCoreFile != NIL_RTFILE)
     1950    if (pVBoxCore->hCoreFile != NIL_RTFILE)     /* Initialized in rtCoreDumperCreateCore() */
    19071951    {
    19081952        RTFileClose(pVBoxCore->hCoreFile);
     
    19101954    }
    19111955
    1912     if (pVBoxProc->hAs != NIL_RTFILE)
     1956    if (pVBoxProc->hAs != NIL_RTFILE)           /* Initialized in rtCoreDumperCreateCore() */
    19131957    {
    19141958        RTFileClose(pVBoxProc->hAs);
Note: See TracChangeset for help on using the changeset viewer.

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