VirtualBox

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

Last change on this file since 52553 was 52553, checked in by vboxsync, 10 years ago

HostDrivers/solaris, Runtime/r0drv: Fix calling RTThreadPreemptIs* too early on Solaris.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/* $Id: dbgkrnlinfo-r0drv-solaris.c 52553 2014-09-01 14:48:33Z 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 /* This can be called as part of IPRT init, in which case we have no thread preempt information yet. */
142 if (g_frtSolInitDone)
143 RT_ASSERT_PREEMPTIBLE();
144
145 *phKrnlInfo = NIL_RTDBGKRNLINFO;
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 AssertPtrReturn(pThis, UINT32_MAX);
171 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
172
173 uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
174 Assert(cRefs && cRefs < 100000);
175 return cRefs;
176}
177
178
179RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
180{
181 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
182 if (pThis == NIL_RTDBGKRNLINFO)
183 return 0;
184 AssertPtrReturn(pThis, UINT32_MAX);
185 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
186 if (g_frtSolInitDone)
187 RT_ASSERT_PREEMPTIBLE();
188
189 uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
190 if (cRefs == 0)
191 {
192 pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
193 rtR0DbgKrnlInfoModRelease(pThis->pGenUnixMod, pThis->pGenUnixCTF);
194 RTMemFree(pThis);
195 }
196 return cRefs;
197}
198
199
200RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
201 const char *pszMember, size_t *poffMember)
202{
203 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
204 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
205 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
206 AssertPtrReturn(pszMember, VERR_INVALID_PARAMETER);
207 AssertPtrReturn(pszStructure, VERR_INVALID_PARAMETER);
208 AssertPtrReturn(poffMember, VERR_INVALID_PARAMETER);
209 if (g_frtSolInitDone)
210 RT_ASSERT_PREEMPTIBLE();
211
212 int rc = VERR_NOT_FOUND;
213 ctf_id_t TypeIdent = ctf_lookup_by_name(pThis->pGenUnixCTF, pszStructure);
214 if (TypeIdent != CTF_ERR)
215 {
216 ctf_membinfo_t MemberInfo;
217 RT_ZERO(MemberInfo);
218 if (ctf_member_info(pThis->pGenUnixCTF, TypeIdent, pszMember, &MemberInfo) != CTF_ERR)
219 {
220 *poffMember = (MemberInfo.ctm_offset >> 3);
221 return VINF_SUCCESS;
222 }
223 }
224
225 return rc;
226}
227
228
229RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
230 const char *pszSymbol, void **ppvSymbol)
231{
232 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
233 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
234 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
235 AssertPtrReturn(pszSymbol, VERR_INVALID_PARAMETER);
236 AssertPtrNullReturn(ppvSymbol, VERR_INVALID_PARAMETER);
237 AssertReturn(!pszModule, VERR_MODULE_NOT_FOUND);
238 if (g_frtSolInitDone)
239 RT_ASSERT_PREEMPTIBLE();
240
241 uintptr_t uValue = kobj_getsymvalue((char *)pszSymbol, 1 /* only kernel */);
242 if (ppvSymbol)
243 *ppvSymbol = (void *)uValue;
244 if (uValue)
245 return VINF_SUCCESS;
246 return VERR_SYMBOL_NOT_FOUND;
247}
248
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