VirtualBox

Changeset 32219 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 2, 2010 6:26:21 PM (14 years ago)
Author:
vboxsync
Message:

VMM/DBGFCoreWrite: bits.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/include/internal/ldrELFCommon.h

    r31980 r32219  
    307307#endif
    308308
     309/* VirtualBox specific NOTE sections (added by Ramshankar */
     310#ifdef VBOX
     311#define NT_VBOXCPU  0xace
     312#endif
     313
    309314/* Symbol Binding - ELFNN_ST_BIND - st_info */
    310315#define STB_LOCAL       0       /* Local symbol */
  • trunk/src/VBox/VMM/DBGFCoreWrite.cpp

    r32218 r32219  
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
    17 
    18 
    19 /*******************************************************************************
    20 *   Header Files                                                               *
    21 *******************************************************************************/
    22 #define LOG_GROUP LOG_GROUP_DBGF
    23 #include <iprt/param.h>
    24 #include <iprt/file.h>
    25 #include <VBox/dbgf.h>
    26 #include "DBGFInternal.h"
    27 #include <VBox/vm.h>
    28 #include <VBox/pgm.h>
    29 #include <VBox/err.h>
    30 #include <VBox/log.h>
    31 #include <VBox/mm.h>
    32 
    33 #include "../Runtime/include/internal/ldrELF64.h"
    34 
    35 /*******************************************************************************
    36 *   Defined Constants And Macros                                               *
    37 *******************************************************************************/
    38 #ifdef DEBUG_ramshankar
    39 # undef Log
    40 # define Log LogRel
    41 #endif
    42 #define DBGFLOG_NAME           "DGBFCoreWrite"
    43 
    44 /**
    45  * DBGFCOREDATA: Core data.
    46  */
    47 typedef struct
    48 {
    49     const char *pszDumpPath;    /* File path to dump the core into. */
    50 } DBGFCOREDATA, *PDBGFCOREDATA;
    51 
    5217
    5318/*
     
    7540 */
    7641
     42/*******************************************************************************
     43*   Header Files                                                               *
     44*******************************************************************************/
     45#define LOG_GROUP LOG_GROUP_DBGF
     46#include <iprt/param.h>
     47#include <iprt/file.h>
     48
     49#include "DBGFInternal.h"
     50
     51#include <VBox/cpum.h>
     52#include "CPUMInternal.h"
     53#include <VBox/dbgf.h>
     54#include <VBox/vm.h>
     55#include <VBox/pgm.h>
     56#include <VBox/err.h>
     57#include <VBox/log.h>
     58#include <VBox/mm.h>
     59
     60#include "../Runtime/include/internal/ldrELF64.h"
     61
     62/*******************************************************************************
     63*   Defined Constants And Macros                                               *
     64*******************************************************************************/
     65#ifdef DEBUG_ramshankar
     66# undef Log
     67# define Log LogRel
     68#endif
     69#define DBGFLOG_NAME           "DGBFCoreWrite"
     70
     71static const int s_NoteAlign = 4;
     72
     73/**
     74 * DBGFCOREDATA: Core data.
     75 */
     76typedef struct
     77{
     78    const char *pszDumpPath;    /* File path to dump the core into. */
     79} DBGFCOREDATA, *PDBGFCOREDATA;
     80
     81typedef struct
     82{
     83    Elf64_Nhdr  Hdr;            /* 64-bit NOTE Header */
     84    char        achName[8];    /* Name of NOTE section */
     85} ELFNOTEHDR;
     86
     87
    7788/**
    7889 * ELF function to write 64-bit ELF header.
     
    8899static int Elf64WriteElfHdr(RTFILE hFile, uint16_t cProgHdrs, uint16_t cSecHdrs, uint64_t *pcbElfHdr)
    89100{
    90 AssertCompile(sizeof(uint32_t) == 4);
    91 
    92101    Elf64_Ehdr ElfHdr;
    93102    RT_ZERO(ElfHdr);
     
    155164
    156165/**
     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.
     169 *
     170 * @return The size of the NOTE section as rounded to the file alignment.
     171 */
     172static inline int Elf64NoteSectionSize(uint64_t cb)
     173{
     174    return sizeof(ELFNOTEHDR) + RT_ALIGN_64(cb, s_NoteAlign);
     175}
     176
     177
     178/**
    157179 * Elf function to write 64-bit note header.
    158180 *
    159181 * @param hFile             The file to write to.
    160182 * @param Type              Type of this section.
    161  * @param pszName           Name of this section, will be limited to 8 bytes.
     183 * @param pszName           Name of this section, will be limited to 16 bytes.
    162184 * @param pcv               Opaque pointer to the data, if NULL only computes size.
    163185 * @param cb                Size of the data.
     
    167189 * @return IPRT status code.
    168190 */
    169 static int Elf64WriteNoteHeader(RTFILE hFile, uint16_t Type, const char *pszName, const void *pcv, uint64_t cb, uint64_t *pcbNoteHdr)
     191static int Elf64WriteNoteHdr(RTFILE hFile, uint16_t Type, const char *pszName, const void *pcv, uint64_t cb, uint64_t *pcbNoteHdr)
    170192{
    171193    AssertReturn(pcv, VERR_INVALID_POINTER);
    172194    AssertReturn(cb > 0, VERR_NO_DATA);
    173195
    174     typedef struct
    175     {
    176         Elf64_Nhdr  Hdr;            /* 64-bit NOTE Header */
    177         char        achName[8];     /* Name of NOTE section */
    178     } ELFNOTEHDR;
    179 
    180196    ELFNOTEHDR ElfNoteHdr;
    181197    RT_ZERO(ElfNoteHdr);
    182     RTStrCopy(ElfNoteHdr.achName, sizeof(ElfNoteHdr.achName) - 1, pszName);
    183     ElfNoteHdr.Hdr.n_namesz = (Elf64_Word)strlen(ElfNoteHdr.achName) + 1;
     198    RTStrCopy(ElfNoteHdr.achName, sizeof(ElfNoteHdr.achName), pszName);
     199    ElfNoteHdr.Hdr.n_namesz = (Elf64_Word)strlen(ElfNoteHdr.achName);
    184200    ElfNoteHdr.Hdr.n_type   = Type;
    185 
    186     static const char s_achPad[3] = { 0, 0, 0 };
    187     uint64_t cbAlign = RT_ALIGN_64(cb, 4);
    188     ElfNoteHdr.Hdr.n_descsz = cbAlign;
     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;
    189206
    190207    /*
     
    194211    if (RT_SUCCESS(rc))
    195212    {
     213        if (cbNameAlign > ElfNoteHdr.Hdr.n_namesz)
     214            rc = RTFileWrite(hFile, s_achPad, cbNameAlign - ElfNoteHdr.Hdr.n_namesz, NULL);
     215
    196216        rc = RTFileWrite(hFile, pcv, cb, NULL /* full write */);
    197217        if (RT_SUCCESS(rc))
     
    236256 *
    237257 * @return VBox status code.
    238  * @remarks The VM must be suspended before calling this function.
    239258 */
    240259static DECLCALLBACK(VBOXSTRICTRC) dbgfR3CoreWrite(PVM pVM, PVMCPU pVCpu, void *pvData)
     
    259278     * Compute size of the note section.
    260279     */
    261     uint64_t cbNoteSection = pVM->cCpus * sizeof(CPUMCTX);
     280    uint64_t cbNoteSection = Elf64NoteSectionSize(pVM->cCpus * sizeof(CPUMCTX));
    262281    uint64_t off = 0;
    263282
     
    336355                if (RT_SUCCESS(rc))
    337356                {
    338                     for (uint32_t iCpu = 0; iCpu < pVM->cCpus; iCpu++)
     357                    for (uint32_t i = 0; i < pVM->cCpus; i++)
    339358                    {
    340                         /** @todo -XXX- cpus */
     359                        PCPUMCTX pCpuCtx = &pVM->aCpus[i].cpum.s.Guest;
     360                        rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, "VBOXCPU", pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */);
     361                        if (RT_FAILURE(rc))
     362                        {
     363                            LogRel((DBGFLOG_NAME ":Elf64WriteNoteHdr failed for vCPU[%u] rc=%Rrc\n", i, rc));
     364                            break;
     365                        }
    341366                    }
    342367                }
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