VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/dbg-r0drv-solaris.c@ 40701

Last change on this file since 40701 was 40701, checked in by vboxsync, 13 years ago

Runtime/r0drv/solaris: dbg-r0drv fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: dbg-r0drv-solaris.c 40701 2012-03-28 16:58:05Z vboxsync $ */
2/** @file
3 * IPRT - Kernel debug information, Ring-0 Driver, Solaris Code.
4 */
5
6/*
7 * Copyright (C) 2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "the-solaris-kernel.h"
32#include "internal/iprt.h"
33
34#include <iprt/dbg.h>
35#include <iprt/asm.h>
36#include <iprt/assert.h>
37#include <iprt/err.h>
38#include <iprt/log.h>
39#include <iprt/mem.h>
40#include <iprt/string.h>
41#include <iprt/thread.h>
42
43
44/*******************************************************************************
45* Structures and Typedefs *
46*******************************************************************************/
47/**
48 * Solaris kernel debug info instance data.
49 */
50typedef struct RTDBGKRNLINFOINT
51{
52 /** Magic value (RTDBGKRNLINFO_MAGIC). */
53 uint32_t volatile u32Magic;
54 /** The number of threads referencing this object. */
55 uint32_t volatile cRefs;
56 /** Pointer to the genunix CTF handle. */
57 ctf_file_t *pGenUnixCTF;
58 /** Pointer to the genunix module handle. */
59 modctl_t *pGenUnixMod;
60} RTDBGKRNLINFOINT;
61/** Pointer to the solaris kernel debug info instance data. */
62typedef struct RTDBGKRNLINFOINT *PRTDBGKRNLINFOINT;
63
64/** Magic value for RTDBGKRNLINFOINT::u32Magic. (John Carmack) */
65#define RTDBGKRNLINFO_MAGIC UINT32_C(0x19700820)
66
67
68/**
69 * Retains a kernel module and opens the CTF data associated with it.
70 *
71 * @param pszModule The name of the module to open.
72 * @param ppMod Where to store the module handle.
73 * @param ppCTF Where to store the module's CTF handle.
74 *
75 * @return IPRT status code.
76 */
77static int rtR0DbgKrnlInfoModRetain(char *pszModule, modctl_t **ppMod, ctf_file_t **ppCTF)
78{
79 AssertPtrReturn(pszModule, VERR_INVALID_PARAMETER);
80 AssertPtrReturn(ppMod, VERR_INVALID_PARAMETER);
81 AssertPtrReturn(ppCTF, VERR_INVALID_PARAMETER);
82
83 int rc = VINF_SUCCESS;
84 modid_t ModId = mod_name_to_modid(pszModule);
85 if (ModId != -1)
86 {
87 *ppMod = mod_hold_by_id(ModId);
88 if (*ppMod)
89 {
90 /*
91 * Hold mod_lock as ctf_modopen may update the module with uncompressed CTF data.
92 */
93 int err;
94 mutex_enter(&mod_lock);
95 *ppCTF = ctf_modopen(((modctl_t *)*ppMod)->mod_mp, &err);
96 mutex_exit(&mod_lock);
97
98 if (*ppCTF)
99 return VINF_SUCCESS;
100 else
101 {
102 LogRel(("rtR0DbgKrnlInfoModRetain: ctf_modopen failed for '%s' err=%d\n", pszModule, err));
103 rc = VERR_INTERNAL_ERROR_3;
104 }
105
106 mod_release_mod(*ppMod);
107 }
108 else
109 {
110 LogRel(("rtR0DbgKrnlInfoModRetain: mod_hold_by_id failed for '%s'\n" pszModule));
111 rc = VERR_INTERNAL_ERROR_2;
112 }
113 }
114 else
115 {
116 LogRel(("rtR0DbgKrnlInfoModRetain: mod_name_to_modid failed for '%s'\n", pszModule));
117 rc = VERR_INTERNAL_ERROR;
118 }
119
120 return rc;
121}
122
123
124/**
125 * Releases the kernel module and closes its CTF data.
126 *
127 * @param pMod Pointer to the module handle.
128 * @param pCTF Pointer to the module's CTF handle.
129 */
130static void rtR0DbgKrnlInfoModRelease(modctl_t *pMod, ctf_file_t *pCTF)
131{
132 AssertPtrReturnVoid(pMod);
133 AssertPtrReturnVoid(pCTF);
134
135 ctf_close(pCTF);
136 mod_release_mod(pMod);
137}
138
139
140RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags)
141{
142 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
143 AssertPtrReturn(phKrnlInfo, VERR_INVALID_POINTER);
144 RT_ASSERT_PREEMPTIBLE();
145
146 PRTDBGKRNLINFOINT pThis = (PRTDBGKRNLINFOINT)RTMemAllocZ(sizeof(*pThis));
147 if (!pThis)
148 return VERR_NO_MEMORY;
149
150 char szGenUnixModName[] = "genunix";
151 int rc = rtR0DbgKrnlInfoModRetain(szGenUnixModName, &pThis->pGenUnixMod, &pThis->pGenUnixCTF);
152 if (RT_SUCCESS(rc))
153 {
154 pThis->u32Magic = RTDBGKRNLINFO_MAGIC;
155 pThis->cRefs = 1;
156
157 *phKrnlInfo = pThis;
158 return VINF_SUCCESS;
159 }
160
161 LogRel(("RTR0DbgKrnlInfoOpen: rtR0DbgKrnlInfoModRetain failed rc=%d.\n", rc));
162 RTMemFree(pThis);
163 return rc;
164}
165
166
167RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo)
168{
169 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
170 uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
171 Assert(cRefs && cRefs < 100000);
172 NOREF(cRefs);
173 return cRefs;
174}
175
176
177RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
178{
179 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
180 AssertPtrReturn(pThis, UINT32_MAX);
181 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
182 RT_ASSERT_PREEMPTIBLE();
183
184 uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
185 if (cRefs == 0)
186 {
187 pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
188 rtR0DbgKrnlInfoModRelease(pThis->pGenUnixMod, pThis->pGenUnixCTF);
189 RTMemFree(pThis);
190 }
191 return cRefs;
192}
193
194
195RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
196 const char *pszMember, size_t *poffMember)
197{
198 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
199 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
200 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
201 AssertPtrReturn(pszMember, VERR_INVALID_PARAMETER);
202 AssertPtrReturn(pszStructure, VERR_INVALID_PARAMETER);
203 AssertPtrReturn(poffMember, VERR_INVALID_PARAMETER);
204 RT_ASSERT_PREEMPTIBLE();
205
206 int rc = VERR_NOT_FOUND;
207 ctf_id_t TypeIdent = ctf_lookup_by_name(pThis->pGenUnixCTF, pszStructure);
208 if (TypeIdent != CTF_ERR)
209 {
210 ctf_membinfo_t MemberInfo;
211 RT_ZERO(MemberInfo);
212 if (ctf_member_info(pThis->pGenUnixCTF, TypeIdent, pszMember, &MemberInfo) != CTF_ERR)
213 {
214 *poffMember = (MemberInfo.ctm_offset >> 3);
215 return VINF_SUCCESS;
216 }
217 }
218
219 return rc;
220}
221
222
223RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
224 const char *pszSymbol, void **ppvSymbol)
225{
226 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
227 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
228 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
229 AssertPtrReturn(pszSymbol, VERR_INVALID_PARAMETER);
230 AssertPtrReturn(ppvSymbol, VERR_INVALID_PARAMETER);
231 AssertReturn(!pszModule, VERR_MODULE_NOT_FOUND);
232 RT_ASSERT_PREEMPTIBLE();
233
234 *ppvSymbol = (void *)kobj_getsymvalue((char *)pszSymbol, 1 /* only kernel */);
235 if (*ppvSymbol)
236 return VINF_SUCCESS;
237
238 return VERR_SYMBOL_NOT_FOUND;
239}
240
Note: See TracBrowser for help on using the repository browser.

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