- Timestamp:
- Apr 10, 2012 3:11:16 PM (13 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r40805 r40856 1771 1771 r0drv/darwin/assert-r0drv-darwin.cpp \ 1772 1772 r0drv/darwin/initterm-r0drv-darwin.cpp \ 1773 r0drv/darwin/ mach_kernel-r0drv-darwin.cpp \1773 r0drv/darwin/dbgkrnlinfo-r0drv-darwin.cpp \ 1774 1774 r0drv/darwin/memobj-r0drv-darwin.cpp \ 1775 1775 r0drv/darwin/mp-r0drv-darwin.cpp \ -
trunk/src/VBox/Runtime/r0drv/darwin/dbgkrnlinfo-r0drv-darwin.cpp
r40852 r40856 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - mach_kernel symbol resolving hack, R0 Driver, Darwin.3 * IPRT - Kernel Debug Information, R0 Driver, Darwin. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2011 Oracle Corporation7 * Copyright (C) 2011-2012 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 48 48 49 49 #include "internal/iprt.h" 50 #include <iprt/d arwin/machkernel.h>50 #include <iprt/dbg.h> 51 51 52 52 #include <iprt/asm.h> … … 59 59 #include <iprt/string.h> 60 60 #include "internal/ldrMach-O.h" 61 #include "internal/magics.h" 61 62 62 63 /** @def MY_CPU_TYPE … … 123 124 * and successfully resolving their addresses. 124 125 */ 125 typedef struct RTR0MACHKERNELINT 126 { 126 typedef struct RTDBGKRNLINFOINT 127 { 128 /** Magic value (RTDBGKRNLINFO_MAGIC). */ 129 uint32_t u32Magic; 130 /** Reference counter. */ 131 uint32_t volatile cRefs; 132 127 133 /** @name Result. 128 134 * @{ */ … … 163 169 /** Buffer space. */ 164 170 char abBuf[_4K]; 165 } RT R0MACHKERNELINT;171 } RTDBGKRNLINFOINT; 166 172 167 173 … … 339 345 * @param pThis The internal scratch data. 340 346 */ 341 static void rtR0 MachKernelLoadDone(RTR0MACHKERNELINT *pThis)347 static void rtR0DbgKrnlDarwinLoadDone(RTDBGKRNLINFOINT *pThis) 342 348 { 343 349 RTFileClose(pThis->hFile); … … 359 365 * with an underscore. 360 366 */ 361 static uintptr_t rtR0 MachKernelLookup(RTR0MACHKERNELINT *pThis, const char *pszSymbol)367 static uintptr_t rtR0DbgKrnlDarwinLookup(RTDBGKRNLINFOINT *pThis, const char *pszSymbol) 362 368 { 363 369 uint32_t const cSyms = pThis->cSyms; … … 403 409 * @param pThis The internal scratch data. 404 410 */ 405 static int rtR0 MachKernelCheckStandardSymbols(RTR0MACHKERNELINT *pThis)411 static int rtR0DbgKrnlDarwinCheckStandardSymbols(RTDBGKRNLINFOINT *pThis) 406 412 { 407 413 static struct … … 522 528 for (unsigned i = 0; i < RT_ELEMENTS(s_aStandardCandles); i++) 523 529 { 524 uintptr_t uAddr = rtR0 MachKernelLookup(pThis, s_aStandardCandles[i].pszName);530 uintptr_t uAddr = rtR0DbgKrnlDarwinLookup(pThis, s_aStandardCandles[i].pszName); 525 531 #ifdef IN_RING0 526 532 if (uAddr != s_aStandardCandles[i].uAddr) … … 543 549 * @param pThis The internal scratch data. 544 550 */ 545 static int rtR0 MachKernelLoadSymTab(RTR0MACHKERNELINT *pThis)551 static int rtR0DbgKrnlDarwinLoadSymTab(RTDBGKRNLINFOINT *pThis) 546 552 { 547 553 /* … … 648 654 * @param pThis The internal scratch data. 649 655 */ 650 static int rtR0 MachKernelLoadCommands(RTR0MACHKERNELINT *pThis)656 static int rtR0DbgKrnlDarwinLoadCommands(RTDBGKRNLINFOINT *pThis) 651 657 { 652 658 pThis->offStrTab = 0; … … 874 880 * @param pThis The internal scratch data. 875 881 */ 876 static int rtR0 MachKernelLoadFileHeaders(RTR0MACHKERNELINT *pThis)882 static int rtR0DbgKrnlDarwinLoadFileHeaders(RTDBGKRNLINFOINT *pThis) 877 883 { 878 884 uint32_t i; … … 973 979 974 980 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 */ 986 static 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 1000 RTR0DECL(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)); 980 1007 if (!pThis) 981 1008 return VERR_NO_MEMORY; 982 1009 pThis->hFile = NIL_RTFILE; 983 1010 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); 985 1012 if (RT_SUCCESS(rc)) 986 rc = rtR0 MachKernelLoadFileHeaders(pThis);1013 rc = rtR0DbgKrnlDarwinLoadFileHeaders(pThis); 987 1014 if (RT_SUCCESS(rc)) 988 rc = rtR0 MachKernelLoadCommands(pThis);1015 rc = rtR0DbgKrnlDarwinLoadCommands(pThis); 989 1016 if (RT_SUCCESS(rc)) 990 rc = rtR0 MachKernelLoadSymTab(pThis);1017 rc = rtR0DbgKrnlDarwinLoadSymTab(pThis); 991 1018 if (RT_SUCCESS(rc)) 992 rc = rtR0 MachKernelCheckStandardSymbols(pThis);993 994 rtR0 MachKernelLoadDone(pThis);1019 rc = rtR0DbgKrnlDarwinCheckStandardSymbols(pThis); 1020 1021 rtR0DbgKrnlDarwinLoadDone(pThis); 995 1022 if (RT_SUCCESS(rc)) 996 *phKernel = pThis; 1023 { 1024 pThis->u32Magic = RTDBGKRNLINFO_MAGIC; 1025 pThis->cRefs = 1; 1026 *phKrnlInfo = pThis; 1027 } 997 1028 else 998 RTR0MachKernelClose(pThis);1029 rtR0DbgKrnlDarwinDtor(pThis); 999 1030 return rc; 1000 1031 } 1001 1032 1002 1033 1003 RTR0DECL(int) RTR0MachKernelGetSymbol(RTR0MACHKERNEL hKernel, const char *pszSymbol, void **ppvValue) 1004 { 1005 RTR0MACHKERNELINT *pThis = hKernel; 1034 RTR0DECL(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 1046 RTR0DECL(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 1061 RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure, 1062 const char *pszMember, size_t *poffMember) 1063 { 1064 RTDBGKRNLINFOINT *pThis = hKrnlInfo; 1006 1065 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 1074 RTR0DECL(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) 1020 1088 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 34 34 #include <iprt/err.h> 35 35 #include <iprt/assert.h> 36 #include <iprt/d arwin/machkernel.h>36 #include <iprt/dbg.h> 37 37 #include "internal/initterm.h" 38 38 … … 67 67 * Try resolve kernel symbols we need but apple don't wish to give us. 68 68 */ 69 RT R0MACHKERNEL hKernel;70 rc = RTR0 MachKernelOpen("/mach_kernel", &hKernel);69 RTDBGKRNLINFO hKrnlInfo; 70 rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/); 71 71 if (RT_SUCCESS(rc)) 72 72 { 73 RTR0 MachKernelGetSymbol(hKernel, "ast_pending", (void **)&g_pfnR0DarwinAstPending);73 RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "ast_pending", (void **)&g_pfnR0DarwinAstPending); 74 74 printf("ast_pending=%p\n", g_pfnR0DarwinAstPending); 75 RTR0 MachKernelGetSymbol(hKernel, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt);75 RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt); 76 76 printf("cpu_interrupt=%p\n", g_pfnR0DarwinCpuInterrupt); 77 RTR0 MachKernelClose(hKernel);77 RTR0DbgKrnlInfoRelease(hKrnlInfo); 78 78 } 79 79 if (RT_FAILURE(rc)) -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r40365 r40856 650 650 tstRTDarwinMachKernel_SOURCES = \ 651 651 tstRTDarwinMachKernel.cpp \ 652 ../r0drv/darwin/ mach_kernel-r0drv-darwin.cpp652 ../r0drv/darwin/dbgkrnlinfo-r0drv-darwin.cpp 653 653 654 654 ntGetTimerResolution_SOURCES = ntGetTimerResolution.cpp -
trunk/src/VBox/Runtime/testcase/tstRTDarwinMachKernel.cpp
r37573 r40856 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #include <iprt/d arwin/machkernel.h>31 #include <iprt/dbg.h> 32 32 #include <iprt/err.h> 33 33 #include <iprt/string.h> … … 36 36 37 37 38 static void dotest( const char *pszMachKernel)38 static void dotest(void) 39 39 { 40 RT R0MACHKERNEL hKernel;41 RTTESTI_CHECK_RC_RETV(RTR0 MachKernelOpen(pszMachKernel, &hKernel), VINF_SUCCESS);40 RTDBGKRNLINFO hKrnlInfo; 41 RTTESTI_CHECK_RC_RETV(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS); 42 42 static const char * const s_apszSyms[] = 43 43 { … … 50 50 { 51 51 void *pvValue = NULL; 52 int rc = RTR0 MachKernelGetSymbol(hKernel, s_apszSyms[i], &pvValue);52 int rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], &pvValue); 53 53 RTTestIPrintf(RTTESTLVL_ALWAYS, "%Rrc %p %s\n", rc, pvValue, s_apszSyms[i]); 54 54 RTTESTI_CHECK_RC(rc, VINF_SUCCESS); 55 55 if (RT_SUCCESS(rc)) 56 RTTESTI_CHECK_RC(RTR0 MachKernelGetSymbol(hKernel, s_apszSyms[i], NULL), VINF_SUCCESS);56 RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], NULL), VINF_SUCCESS); 57 57 } 58 58 59 RTTESTI_CHECK_RC(RTR0 MachKernelGetSymbol(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); 62 62 } 63 63 … … 66 66 { 67 67 RTTEST hTest; 68 RTEXITCODE rcExit = RTTestInitAndCreate("tstRT MachKernel", &hTest);68 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTDarwinMachKernel", &hTest); 69 69 if (rcExit != RTEXITCODE_SUCCESS) 70 70 return rcExit; 71 71 RTTestBanner(hTest); 72 72 73 dotest( "/mach_kernel");73 dotest(); 74 74 75 75 return RTTestSummaryAndDestroy(hTest);
Note:
See TracChangeset
for help on using the changeset viewer.