VirtualBox

Changeset 32236 in vbox for trunk/src


Ignore:
Timestamp:
Sep 3, 2010 1:42:19 PM (14 years ago)
Author:
vboxsync
Message:

VMM/DBGFCoreWrite: bits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/DBGFCoreWrite.cpp

    r32222 r32236  
    6969#define DBGFLOG_NAME           "DGBFCoreWrite"
    7070
    71 static const int s_NoteAlign = 4;
     71/*
     72 * For now use Solaris-specific padding and namesz length (i.e. includes NULL terminator)
     73 */
     74static const int s_NoteAlign  = 4;      /* @todo see #5211 comment 3 */
     75static const int s_cbNoteName = 16;
     76static const char *s_pcszCoreVBoxCpu = "VBOXCPU";
    7277
    7378/**
     
    7883    const char *pszDumpPath;    /* File path to dump the core into. */
    7984} DBGFCOREDATA, *PDBGFCOREDATA;
    80 
    81 typedef struct
    82 {
    83     Elf64_Nhdr  Hdr;            /* 64-bit NOTE Header */
    84     char        achName[8];     /* Name of NOTE section */
    85 } ELFNOTEHDR;
    8685
    8786
     
    164163
    165164/**
    166  * Returns the size of the NOTE section given the size of the data.
    167  *
    168  * @param cb                Size of the data part of the NOTE.
     165 * Returns the size of the NOTE section given the name and size of the data.
     166 *
     167 * @param pszName           Name of the note section.
     168 * @param cb                Size of the data portion of the note section.
    169169 *
    170170 * @return The size of the NOTE section as rounded to the file alignment.
    171171 */
    172 static inline uint64_t Elf64NoteSectionSize(uint64_t cb)
    173 {
    174     return sizeof(ELFNOTEHDR) + RT_ALIGN_64(cb, s_NoteAlign);
     172static inline uint64_t Elf64NoteSectionSize(const char *pszName, uint64_t cbData)
     173{
     174    uint64_t cbNote = sizeof(Elf64_Nhdr);
     175
     176    size_t cbName = strlen(pszName) + 1;
     177    size_t cbNameAlign = RT_ALIGN_Z(cbName, s_NoteAlign);
     178
     179    cbNote += cbNameAlign;
     180    cbNote += RT_ALIGN_64(cbData, s_NoteAlign);
     181    return cbNote;
    175182}
    176183
     
    181188 * @param hFile             The file to write to.
    182189 * @param Type              Type of this section.
    183  * @param pszName           Name of this section, will be limited to 16 bytes.
     190 * @param pszName           Name of this section.
    184191 * @param pcv               Opaque pointer to the data, if NULL only computes size.
    185  * @param cb                Size of the data.
     192 * @param cbData            Size of the data.
    186193 * @param pcbNoteHdr        Where to store the size of written header to file,
    187194 *                          can be NULL.
     
    189196 * @return IPRT status code.
    190197 */
    191 static int Elf64WriteNoteHdr(RTFILE hFile, uint16_t Type, const char *pszName, const void *pcv, uint64_t cb, uint64_t *pcbNoteHdr)
    192 {
    193     AssertReturn(pcv, VERR_INVALID_POINTER);
    194     AssertReturn(cb > 0, VERR_NO_DATA);
    195 
    196     ELFNOTEHDR ElfNoteHdr;
     198static int Elf64WriteNoteHdr(RTFILE hFile, uint16_t Type, const char *pszName, const void *pcvData, uint64_t cbData, uint64_t *pcbNoteHdr)
     199{
     200    AssertReturn(pcvData, VERR_INVALID_POINTER);
     201    AssertReturn(cbData > 0, VERR_NO_DATA);
     202
     203    char szNoteName[s_cbNoteName];
     204    RT_ZERO(szNoteName);
     205    RTStrCopy(szNoteName, sizeof(szNoteName), pszName);
     206
     207    size_t cbName        = strlen(szNoteName) + 1;
     208    size_t cbNameAlign   = RT_ALIGN_Z(cbName, s_NoteAlign);
     209    uint64_t cbDataAlign = RT_ALIGN_64(cbData, s_NoteAlign);
     210
     211    static const char s_achPad[7] = { 0, 0, 0, 0, 0, 0, 0 };
     212    AssertCompile(sizeof(s_achPad) >= s_NoteAlign - 1);
     213
     214    Elf64_Nhdr ElfNoteHdr;
    197215    RT_ZERO(ElfNoteHdr);
    198     RTStrCopy(ElfNoteHdr.achName, sizeof(ElfNoteHdr.achName), pszName);
    199     ElfNoteHdr.Hdr.n_namesz = (Elf64_Word)strlen(ElfNoteHdr.achName);
    200     ElfNoteHdr.Hdr.n_type   = Type;
    201     size_t cbNameAlign = RT_ALIGN_Z(ElfNoteHdr.Hdr.n_namesz, 8);
    202 
    203     static const char s_achPad[7] = { 0, 0, 0, 0, 0, 0, 0 };
    204     uint64_t cbAlign = RT_ALIGN_64(cb, s_NoteAlign);
    205     ElfNoteHdr.Hdr.n_descsz = (Elf64_Word)cbAlign;
    206 
    207     /*
    208      * Write note header and description.
     216    ElfNoteHdr.n_namesz = (Elf64_Word)cbName;   /* @todo fix this later to NOT include NULL terminator */
     217    ElfNoteHdr.n_type   = Type;
     218    ElfNoteHdr.n_descsz = (Elf64_Word)cbDataAlign;
     219
     220    /*
     221     * Write note header.
    209222     */
    210223    int rc = RTFileWrite(hFile, &ElfNoteHdr, sizeof(ElfNoteHdr), NULL /* full write */);
    211224    if (RT_SUCCESS(rc))
    212225    {
    213         if (cbNameAlign > ElfNoteHdr.Hdr.n_namesz)
    214             rc = RTFileWrite(hFile, s_achPad, cbNameAlign - ElfNoteHdr.Hdr.n_namesz, NULL);
    215 
    216         rc = RTFileWrite(hFile, pcv, cb, NULL /* full write */);
     226        /*
     227         * Write note name.
     228         */
     229        rc = RTFileWrite(hFile, szNoteName, cbName, NULL /* full write */);
    217230        if (RT_SUCCESS(rc))
    218231        {
    219             if (cbAlign > cb)
    220                 rc = RTFileWrite(hFile, s_achPad, cbAlign - cb, NULL /* full write*/);
     232            /*
     233             * Write note name padding if required.
     234             */
     235            if (cbNameAlign > cbName)
     236                rc = RTFileWrite(hFile, s_achPad, cbNameAlign - cbName, NULL);
     237
     238            if (RT_SUCCESS(rc))
     239            {
     240                /*
     241                 * Write note data.
     242                 */
     243                rc = RTFileWrite(hFile, pcvData, cbData, NULL /* full write */);
     244                if (RT_SUCCESS(rc))
     245                {
     246                    /*
     247                     * Write note data padding if required.
     248                     */
     249                    if (cbDataAlign > cbData)
     250                        rc = RTFileWrite(hFile, s_achPad, cbDataAlign - cbData, NULL /* full write*/);
     251                }
     252            }
    221253        }
    222254    }
    223255
    224256    if (RT_FAILURE(rc))
    225         LogRel((DBGFLOG_NAME ":RTFileWrite failed. rc=%Rrc pszName=%s cb=%u cbAlign=%u\n", rc, pszName, cb, cbAlign));
     257        LogRel((DBGFLOG_NAME ":RTFileWrite failed. rc=%Rrc pszName=%s cbData=%u cbDataAlign=%u\n", rc, pszName, cbData, cbDataAlign));
    226258
    227259    return rc;
     
    278310     * Compute size of the note section.
    279311     */
    280     uint64_t cbNoteSection = Elf64NoteSectionSize(pVM->cCpus * sizeof(CPUMCTX));
     312    uint64_t cbNoteSection = pVM->cCpus * Elf64NoteSectionSize(s_pcszCoreVBoxCpu, sizeof(CPUMCTX));
    281313    uint64_t off = 0;
    282314
     
    358390                    {
    359391                        PCPUMCTX pCpuCtx = &pVM->aCpus[i].cpum.s.Guest;
    360                         rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, "VBOXCPU", pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */);
     392                        rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, s_pcszCoreVBoxCpu, pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */);
    361393                        if (RT_FAILURE(rc))
    362394                        {
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