VirtualBox

Changeset 40856 in vbox for trunk/src


Ignore:
Timestamp:
Apr 10, 2012 3:11:16 PM (13 years ago)
Author:
vboxsync
Message:

IPRT: Transformed the RTR0MachKernel API into RTR0DbgKrnlInfo.

Location:
trunk/src/VBox/Runtime
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r40805 r40856  
    17711771        r0drv/darwin/assert-r0drv-darwin.cpp \
    17721772        r0drv/darwin/initterm-r0drv-darwin.cpp \
    1773         r0drv/darwin/mach_kernel-r0drv-darwin.cpp \
     1773        r0drv/darwin/dbgkrnlinfo-r0drv-darwin.cpp \
    17741774        r0drv/darwin/memobj-r0drv-darwin.cpp \
    17751775        r0drv/darwin/mp-r0drv-darwin.cpp \
  • trunk/src/VBox/Runtime/r0drv/darwin/dbgkrnlinfo-r0drv-darwin.cpp

    r40852 r40856  
    11/* $Id$ */
    22/** @file
    3  * IPRT - mach_kernel symbol resolving hack, R0 Driver, Darwin.
     3 * IPRT - Kernel Debug Information, R0 Driver, Darwin.
    44 */
    55
    66/*
    7  * Copyright (C) 2011 Oracle Corporation
     7 * Copyright (C) 2011-2012 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4848
    4949#include "internal/iprt.h"
    50 #include <iprt/darwin/machkernel.h>
     50#include <iprt/dbg.h>
    5151
    5252#include <iprt/asm.h>
     
    5959#include <iprt/string.h>
    6060#include "internal/ldrMach-O.h"
     61#include "internal/magics.h"
    6162
    6263/** @def MY_CPU_TYPE
     
    123124 * and successfully resolving their addresses.
    124125 */
    125 typedef struct RTR0MACHKERNELINT
    126 {
     126typedef struct RTDBGKRNLINFOINT
     127{
     128    /** Magic value (RTDBGKRNLINFO_MAGIC). */
     129    uint32_t            u32Magic;
     130    /** Reference counter.  */
     131    uint32_t volatile   cRefs;
     132
    127133    /** @name Result.
    128134     * @{ */
     
    163169    /** Buffer space. */
    164170    char                abBuf[_4K];
    165 } RTR0MACHKERNELINT;
     171} RTDBGKRNLINFOINT;
    166172
    167173
     
    339345 * @param   pThis               The internal scratch data.
    340346 */
    341 static void rtR0MachKernelLoadDone(RTR0MACHKERNELINT *pThis)
     347static void rtR0DbgKrnlDarwinLoadDone(RTDBGKRNLINFOINT *pThis)
    342348{
    343349    RTFileClose(pThis->hFile);
     
    359365 *                              with an underscore.
    360366 */
    361 static uintptr_t rtR0MachKernelLookup(RTR0MACHKERNELINT *pThis, const char *pszSymbol)
     367static uintptr_t rtR0DbgKrnlDarwinLookup(RTDBGKRNLINFOINT *pThis, const char *pszSymbol)
    362368{
    363369    uint32_t const  cSyms = pThis->cSyms;
     
    403409 * @param   pThis               The internal scratch data.
    404410 */
    405 static int rtR0MachKernelCheckStandardSymbols(RTR0MACHKERNELINT *pThis)
     411static int rtR0DbgKrnlDarwinCheckStandardSymbols(RTDBGKRNLINFOINT *pThis)
    406412{
    407413    static struct
     
    522528    for (unsigned i = 0; i < RT_ELEMENTS(s_aStandardCandles); i++)
    523529    {
    524         uintptr_t uAddr = rtR0MachKernelLookup(pThis, s_aStandardCandles[i].pszName);
     530        uintptr_t uAddr = rtR0DbgKrnlDarwinLookup(pThis, s_aStandardCandles[i].pszName);
    525531#ifdef IN_RING0
    526532        if (uAddr != s_aStandardCandles[i].uAddr)
     
    543549 * @param   pThis               The internal scratch data.
    544550 */
    545 static int rtR0MachKernelLoadSymTab(RTR0MACHKERNELINT *pThis)
     551static int rtR0DbgKrnlDarwinLoadSymTab(RTDBGKRNLINFOINT *pThis)
    546552{
    547553    /*
     
    648654 * @param   pThis               The internal scratch data.
    649655 */
    650 static int rtR0MachKernelLoadCommands(RTR0MACHKERNELINT *pThis)
     656static int rtR0DbgKrnlDarwinLoadCommands(RTDBGKRNLINFOINT *pThis)
    651657{
    652658    pThis->offStrTab = 0;
     
    874880 * @param   pThis               The internal scratch data.
    875881 */
    876 static int rtR0MachKernelLoadFileHeaders(RTR0MACHKERNELINT *pThis)
     882static int rtR0DbgKrnlDarwinLoadFileHeaders(RTDBGKRNLINFOINT *pThis)
    877883{
    878884    uint32_t i;
     
    973979
    974980
    975 RTDECL(int) RTR0MachKernelOpen(const char *pszMachKernel, PRTR0MACHKERNEL phKernel)
    976 {
    977     *phKernel = NIL_RTR0MACHKERNEL;
    978 
    979     RTR0MACHKERNELINT *pThis = (RTR0MACHKERNELINT *)RTMemAllocZ(sizeof(*pThis));
     981/**
     982 * Destructor.
     983 *
     984 * @param   pThis               The instance to destroy.
     985 */
     986static void rtR0DbgKrnlDarwinDtor(RTDBGKRNLINFOINT *pThis)
     987{
     988    pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
     989
     990    RTMemFree(pThis->pachStrTab);
     991    pThis->pachStrTab = NULL;
     992
     993    RTMemFree(pThis->paSyms);
     994    pThis->paSyms = NULL;
     995
     996    RTMemFree(pThis);
     997}
     998
     999
     1000RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags)
     1001{
     1002    AssertPtrReturn(phKrnlInfo, VERR_INVALID_POINTER);
     1003    *phKrnlInfo = NIL_RTDBGKRNLINFO;
     1004    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
     1005
     1006    RTDBGKRNLINFOINT *pThis = (RTDBGKRNLINFOINT *)RTMemAllocZ(sizeof(*pThis));
    9801007    if (!pThis)
    9811008        return VERR_NO_MEMORY;
    9821009    pThis->hFile = NIL_RTFILE;
    9831010
    984     int rc = RTFileOpen(&pThis->hFile, pszMachKernel, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
     1011    int rc = RTFileOpen(&pThis->hFile, "/mach_kernel", RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
    9851012    if (RT_SUCCESS(rc))
    986         rc = rtR0MachKernelLoadFileHeaders(pThis);
     1013        rc = rtR0DbgKrnlDarwinLoadFileHeaders(pThis);
    9871014    if (RT_SUCCESS(rc))
    988         rc = rtR0MachKernelLoadCommands(pThis);
     1015        rc = rtR0DbgKrnlDarwinLoadCommands(pThis);
    9891016    if (RT_SUCCESS(rc))
    990         rc = rtR0MachKernelLoadSymTab(pThis);
     1017        rc = rtR0DbgKrnlDarwinLoadSymTab(pThis);
    9911018    if (RT_SUCCESS(rc))
    992         rc = rtR0MachKernelCheckStandardSymbols(pThis);
    993 
    994     rtR0MachKernelLoadDone(pThis);
     1019        rc = rtR0DbgKrnlDarwinCheckStandardSymbols(pThis);
     1020
     1021    rtR0DbgKrnlDarwinLoadDone(pThis);
    9951022    if (RT_SUCCESS(rc))
    996         *phKernel = pThis;
     1023    {
     1024        pThis->u32Magic = RTDBGKRNLINFO_MAGIC;
     1025        pThis->cRefs    = 1;
     1026        *phKrnlInfo = pThis;
     1027    }
    9971028    else
    998         RTR0MachKernelClose(pThis);
     1029        rtR0DbgKrnlDarwinDtor(pThis);
    9991030    return rc;
    10001031}
    10011032
    10021033
    1003 RTR0DECL(int) RTR0MachKernelGetSymbol(RTR0MACHKERNEL hKernel, const char *pszSymbol, void **ppvValue)
    1004 {
    1005     RTR0MACHKERNELINT *pThis = hKernel;
     1034RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo)
     1035{
     1036    RTDBGKRNLINFOINT *pThis = hKrnlInfo;
     1037    AssertPtrReturn(pThis, UINT32_MAX);
     1038    AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
     1039
     1040    uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
     1041    Assert(cRefs && cRefs < 100000);
     1042    return cRefs;
     1043}
     1044
     1045
     1046RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
     1047{
     1048    RTDBGKRNLINFOINT *pThis = hKrnlInfo;
     1049    if (pThis == NIL_RTDBGKRNLINFO)
     1050        return 0;
     1051    AssertPtrReturn(pThis, UINT32_MAX);
     1052    AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
     1053
     1054    uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
     1055    if (cRefs == 0)
     1056        rtR0DbgKrnlDarwinDtor(pThis);
     1057    return cRefs;
     1058}
     1059
     1060
     1061RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
     1062                                         const char *pszMember, size_t *poffMember)
     1063{
     1064    RTDBGKRNLINFOINT *pThis = hKrnlInfo;
    10061065    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    1007 
    1008     uintptr_t uValue = rtR0MachKernelLookup(pThis, pszSymbol);
    1009     if (ppvValue)
    1010         *ppvValue = (void *)uValue;
    1011     if (!uValue)
    1012         return VERR_SYMBOL_NOT_FOUND;
    1013     return VINF_SUCCESS;
    1014 }
    1015 
    1016 
    1017 RTR0DECL(int) RTR0MachKernelClose(RTR0MACHKERNEL hKernel)
    1018 {
    1019     if (hKernel == NIL_RTR0MACHKERNEL)
     1066    AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     1067    AssertPtrReturn(pszMember, VERR_INVALID_PARAMETER);
     1068    AssertPtrReturn(pszStructure, VERR_INVALID_PARAMETER);
     1069    AssertPtrReturn(poffMember, VERR_INVALID_PARAMETER);
     1070    return VERR_NOT_FOUND;
     1071}
     1072
     1073
     1074RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
     1075                                         const char *pszSymbol, void **ppvSymbol)
     1076{
     1077    RTDBGKRNLINFOINT *pThis = hKrnlInfo;
     1078    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
     1079    AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
     1080    AssertPtrReturn(pszSymbol, VERR_INVALID_PARAMETER);
     1081    AssertPtrNullReturn(ppvSymbol, VERR_INVALID_PARAMETER);
     1082    AssertReturn(!pszModule, VERR_MODULE_NOT_FOUND);
     1083
     1084    uintptr_t uValue = rtR0DbgKrnlDarwinLookup(pThis, pszSymbol);
     1085    if (ppvSymbol)
     1086        *ppvSymbol = (void *)uValue;
     1087    if (uValue)
    10201088        return VINF_SUCCESS;
    1021 
    1022     RTR0MACHKERNELINT *pThis = hKernel;
    1023     AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    1024 
    1025     RTMemFree(pThis->pachStrTab);
    1026     pThis->pachStrTab = NULL;
    1027 
    1028     RTMemFree(pThis->paSyms);
    1029     pThis->paSyms = NULL;
    1030 
    1031     RTMemFree(pThis);
    1032     return VINF_SUCCESS;
    1033 }
    1034 
     1089    return VERR_SYMBOL_NOT_FOUND;
     1090}
     1091
  • trunk/src/VBox/Runtime/r0drv/darwin/initterm-r0drv-darwin.cpp

    r37575 r40856  
    3434#include <iprt/err.h>
    3535#include <iprt/assert.h>
    36 #include <iprt/darwin/machkernel.h>
     36#include <iprt/dbg.h>
    3737#include "internal/initterm.h"
    3838
     
    6767         * Try resolve kernel symbols we need but apple don't wish to give us.
    6868         */
    69         RTR0MACHKERNEL hKernel;
    70         rc = RTR0MachKernelOpen("/mach_kernel", &hKernel);
     69        RTDBGKRNLINFO hKrnlInfo;
     70        rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/);
    7171        if (RT_SUCCESS(rc))
    7272        {
    73             RTR0MachKernelGetSymbol(hKernel, "ast_pending",   (void **)&g_pfnR0DarwinAstPending);
     73            RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "ast_pending",   (void **)&g_pfnR0DarwinAstPending);
    7474            printf("ast_pending=%p\n", g_pfnR0DarwinAstPending);
    75             RTR0MachKernelGetSymbol(hKernel, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt);
     75            RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt);
    7676            printf("cpu_interrupt=%p\n", g_pfnR0DarwinCpuInterrupt);
    77             RTR0MachKernelClose(hKernel);
     77            RTR0DbgKrnlInfoRelease(hKrnlInfo);
    7878        }
    7979        if (RT_FAILURE(rc))
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r40365 r40856  
    650650tstRTDarwinMachKernel_SOURCES  = \
    651651        tstRTDarwinMachKernel.cpp \
    652         ../r0drv/darwin/mach_kernel-r0drv-darwin.cpp
     652        ../r0drv/darwin/dbgkrnlinfo-r0drv-darwin.cpp
    653653
    654654ntGetTimerResolution_SOURCES = ntGetTimerResolution.cpp
  • trunk/src/VBox/Runtime/testcase/tstRTDarwinMachKernel.cpp

    r37573 r40856  
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    31 #include <iprt/darwin/machkernel.h>
     31#include <iprt/dbg.h>
    3232#include <iprt/err.h>
    3333#include <iprt/string.h>
     
    3636
    3737
    38 static void dotest(const char *pszMachKernel)
     38static void dotest(void)
    3939{
    40     RTR0MACHKERNEL hKernel;
    41     RTTESTI_CHECK_RC_RETV(RTR0MachKernelOpen(pszMachKernel, &hKernel), VINF_SUCCESS);
     40    RTDBGKRNLINFO hKrnlInfo;
     41    RTTESTI_CHECK_RC_RETV(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS);
    4242    static const char * const s_apszSyms[] =
    4343    {
     
    5050    {
    5151        void *pvValue = NULL;
    52         int rc = RTR0MachKernelGetSymbol(hKernel, s_apszSyms[i], &pvValue);
     52        int rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], &pvValue);
    5353        RTTestIPrintf(RTTESTLVL_ALWAYS, "%Rrc %p %s\n", rc, pvValue, s_apszSyms[i]);
    5454        RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    5555        if (RT_SUCCESS(rc))
    56             RTTESTI_CHECK_RC(RTR0MachKernelGetSymbol(hKernel, s_apszSyms[i], NULL), VINF_SUCCESS);
     56            RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], NULL), VINF_SUCCESS);
    5757    }
    5858
    59     RTTESTI_CHECK_RC(RTR0MachKernelGetSymbol(hKernel, "no_such_symbol_name_really", NULL), VERR_SYMBOL_NOT_FOUND);
    60     RTTESTI_CHECK_RC(RTR0MachKernelClose(hKernel), VINF_SUCCESS);
    61     RTTESTI_CHECK_RC(RTR0MachKernelClose(NIL_RTR0MACHKERNEL), VINF_SUCCESS);
     59    RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "no_such_symbol_name_really", NULL), VERR_SYMBOL_NOT_FOUND);
     60    RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(hKrnlInfo) == 0);
     61    RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(NIL_RTDBGKRNLINFO) == 0);
    6262}
    6363
     
    6666{
    6767    RTTEST hTest;
    68     RTEXITCODE rcExit = RTTestInitAndCreate("tstRTMachKernel", &hTest);
     68    RTEXITCODE rcExit = RTTestInitAndCreate("tstRTDarwinMachKernel", &hTest);
    6969    if (rcExit != RTEXITCODE_SUCCESS)
    7070        return rcExit;
    7171    RTTestBanner(hTest);
    7272
    73     dotest("/mach_kernel");
     73    dotest();
    7474
    7575    return RTTestSummaryAndDestroy(hTest);
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