VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/dbgkrnlinfo-r0drv-solaris.c@ 41946

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

r0drv/solaris/dbgkrnlinfo: initialize with NIL_RTDBGKRNLINFO.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/* $Id: dbgkrnlinfo-r0drv-solaris.c 41946 2012-06-28 04:49:50Z 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#include "internal/magics.h"
44
45
46/*******************************************************************************
47* Structures and Typedefs *
48*******************************************************************************/
49/**
50 * Solaris kernel debug info instance data.
51 */
52typedef struct RTDBGKRNLINFOINT
53{
54 /** Magic value (RTDBGKRNLINFO_MAGIC). */
55 uint32_t volatile u32Magic;
56 /** The number of threads referencing this object. */
57 uint32_t volatile cRefs;
58 /** Pointer to the genunix CTF handle. */
59 ctf_file_t *pGenUnixCTF;
60 /** Pointer to the genunix module handle. */
61 modctl_t *pGenUnixMod;
62} RTDBGKRNLINFOINT;
63/** Pointer to the solaris kernel debug info instance data. */
64typedef struct RTDBGKRNLINFOINT *PRTDBGKRNLINFOINT;
65
66
67/**
68 * Retains a kernel module and opens the CTF data associated with it.
69 *
70 * @param pszModule The name of the module to open.
71 * @param ppMod Where to store the module handle.
72 * @param ppCTF Where to store the module's CTF handle.
73 *
74 * @return IPRT status code.
75 */
76static int rtR0DbgKrnlInfoModRetain(char *pszModule, modctl_t **ppMod, ctf_file_t **ppCTF)
77{
78 AssertPtrReturn(pszModule, VERR_INVALID_PARAMETER);
79 AssertPtrReturn(ppMod, VERR_INVALID_PARAMETER);
80 AssertPtrReturn(ppCTF, VERR_INVALID_PARAMETER);
81
82 int rc = VINF_SUCCESS;
83 modid_t ModId = mod_name_to_modid(pszModule);
84 if (ModId != -1)
85 {
86 *ppMod = mod_hold_by_id(ModId);
87 if (*ppMod)
88 {
89 /*
90 * Hold mod_lock as ctf_modopen may update the module with uncompressed CTF data.
91 */
92 int err;
93 mutex_enter(&mod_lock);
94 *ppCTF = ctf_modopen(((modctl_t *)*ppMod)->mod_mp, &err);
95 mutex_exit(&mod_lock);
96 mod_release_mod(*ppMod);
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 else
107 {
108 LogRel(("rtR0DbgKrnlInfoModRetain: mod_hold_by_id failed for '%s'\n", pszModule));
109 rc = VERR_INTERNAL_ERROR_2;
110 }
111 }
112 else
113 {
114 LogRel(("rtR0DbgKrnlInfoModRetain: mod_name_to_modid failed for '%s'\n", pszModule));
115 rc = VERR_INTERNAL_ERROR;
116 }
117
118 return rc;
119}
120
121
122/**
123 * Releases the kernel module and closes its CTF data.
124 *
125 * @param pMod Pointer to the module handle.
126 * @param pCTF Pointer to the module's CTF handle.
127 */
128static void rtR0DbgKrnlInfoModRelease(modctl_t *pMod, ctf_file_t *pCTF)
129{
130 AssertPtrReturnVoid(pMod);
131 AssertPtrReturnVoid(pCTF);
132
133 ctf_close(pCTF);
134}
135
136
137RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags)
138{
139 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
140 AssertPtrReturn(phKrnlInfo, VERR_INVALID_POINTER);
141 RT_ASSERT_PREEMPTIBLE();
142
143 *phKrnlInfo = NIL_RTDBGKRNLINFO;
144 PRTDBGKRNLINFOINT pThis = (PRTDBGKRNLINFOINT)RTMemAllocZ(sizeof(*pThis));
145 if (!pThis)
146 return VERR_NO_MEMORY;
147
148 char szGenUnixModName[] = "genunix";
149 int rc = rtR0DbgKrnlInfoModRetain(szGenUnixModName, &pThis->pGenUnixMod, &pThis->pGenUnixCTF);
150 if (RT_SUCCESS(rc))
151 {
152 pThis->u32Magic = RTDBGKRNLINFO_MAGIC;
153 pThis->cRefs = 1;
154
155 *phKrnlInfo = pThis;
156 return VINF_SUCCESS;
157 }
158
159 LogRel(("RTR0DbgKrnlInfoOpen: rtR0DbgKrnlInfoModRetain failed rc=%d.\n", rc));
160 RTMemFree(pThis);
161 return rc;
162}
163
164
165RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo)
166{
167 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
168 AssertPtrReturn(pThis, UINT32_MAX);
169 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
170
171 uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
172 Assert(cRefs && cRefs < 100000);
173 return cRefs;
174}
175
176
177RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
178{
179 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
180 if (pThis == NIL_RTDBGKRNLINFO)
181 return 0;
182 AssertPtrReturn(pThis, UINT32_MAX);
183 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
184 RT_ASSERT_PREEMPTIBLE();
185
186 uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
187 if (cRefs == 0)
188 {
189 pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
190 rtR0DbgKrnlInfoModRelease(pThis->pGenUnixMod, pThis->pGenUnixCTF);
191 RTMemFree(pThis);
192 }
193 return cRefs;
194}
195
196
197RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
198 const char *pszMember, size_t *poffMember)
199{
200 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
201 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
202 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
203 AssertPtrReturn(pszMember, VERR_INVALID_PARAMETER);
204 AssertPtrReturn(pszStructure, VERR_INVALID_PARAMETER);
205 AssertPtrReturn(poffMember, VERR_INVALID_PARAMETER);
206 RT_ASSERT_PREEMPTIBLE();
207
208 int rc = VERR_NOT_FOUND;
209 ctf_id_t TypeIdent = ctf_lookup_by_name(pThis->pGenUnixCTF, pszStructure);
210 if (TypeIdent != CTF_ERR)
211 {
212 ctf_membinfo_t MemberInfo;
213 RT_ZERO(MemberInfo);
214 if (ctf_member_info(pThis->pGenUnixCTF, TypeIdent, pszMember, &MemberInfo) != CTF_ERR)
215 {
216 *poffMember = (MemberInfo.ctm_offset >> 3);
217 return VINF_SUCCESS;
218 }
219 }
220
221 return rc;
222}
223
224
225RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
226 const char *pszSymbol, void **ppvSymbol)
227{
228 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
229 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
230 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
231 AssertPtrReturn(pszSymbol, VERR_INVALID_PARAMETER);
232 AssertPtrNullReturn(ppvSymbol, VERR_INVALID_PARAMETER);
233 AssertReturn(!pszModule, VERR_MODULE_NOT_FOUND);
234 RT_ASSERT_PREEMPTIBLE();
235
236 uintptr_t uValue = kobj_getsymvalue((char *)pszSymbol, 1 /* only kernel */);
237 if (ppvSymbol)
238 *ppvSymbol = (void *)uValue;
239 if (uValue)
240 return VINF_SUCCESS;
241 return VERR_SYMBOL_NOT_FOUND;
242}
243
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