VirtualBox

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

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

dbg-r0drv-solaris.c: gcc 4.5.2 build fixes and a todo.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1/* $Id: dbg-r0drv-solaris.c 40689 2012-03-28 15:06: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 <iprt/dbg.h>
32#include "internal/iprt.h"
33
34#include <iprt/asm.h>
35#include <iprt/assert.h>
36#include <iprt/err.h>
37#include <iprt/log.h>
38#include <iprt/mem.h>
39#include <iprt/string.h>
40#include <iprt/thread.h>
41
42#include <sys/kobj.h>
43#include <sys/thread.h>
44#include <sys/ctf_api.h>
45#include <sys/modctl.h>
46
47
48/*******************************************************************************
49* Structures and Typedefs *
50*******************************************************************************/
51/**
52 * Solaris kernel debug info instance data.
53 */
54typedef struct RTDBGKRNLINFOINT
55{
56 /** Magic value (RTDBGKRNLINFO_MAGIC). */
57 uint32_t volatile u32Magic;
58 /** The number of threads referencing this object. */
59 uint32_t volatile cRefs;
60 /** Pointer to the genunix CTF handle. */
61 ctf_file_t *pGenUnixCTF;
62 /** Pointer to the genunix module handle. */
63 modctl_t *pGenUnixMod;
64} RTDBGKRNLINFOINT;
65/** Pointer to the solaris kernel debug info instance data. */
66typedef struct RTDBGKRNLINFOINT *PRTDBGKRNLINFOINT;
67
68/** Magic value for RTDBGKRNLINFOINT::u32Magic. (John Carmack) */
69#define RTDBGKRNLINFO_MAGIC UINT32_C(0x19700820)
70
71
72RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags)
73{
74 AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
75 AssertPtrReturn(phKrnlInfo, VERR_INVALID_POINTER);
76 RT_ASSERT_PREEMPTIBLE();
77
78 PRTDBGKRNLINFOINT pThis = (PRTDBGKRNLINFOINT)RTMemAllocZ(sizeof(*pThis));
79 if (!pThis)
80 return VERR_NO_MEMORY;
81
82 int rc;
83 /** @todo r=bird: Where do we release this module? I see other users (crypto) of
84 * this API mod_release_mod(). Not sure if this is a real issue with a primary
85 * module like genunix, though. Another thing, I noticed that mod_hold_by_name
86 * will (a) allocated a module if not found and (b) replace the filename with
87 * what you hand in under certain conditions. These issues doesn't apply with
88 * genunix, but is worth keeping in mind if other modules needs to be held. A
89 * safer alternative would probably be mod_name_to_modid + mod_hold_by_id. */
90 pThis->pGenUnixMod = mod_hold_by_name("genunix");
91 if (RT_LIKELY(pThis->pGenUnixMod))
92 {
93 /*
94 * Hold mod_lock as ctf_modopen may update the module with uncompressed CTF data.
95 */
96 int err;
97 mutex_enter(&mod_lock);
98 pThis->pGenUnixCTF = ctf_modopen(pThis->pGenUnixMod->mod_mp, &err);
99 mutex_exit(&mod_lock);
100
101 if (RT_LIKELY(pThis->pGenUnixCTF))
102 {
103 pThis->u32Magic = RTDBGKRNLINFO_MAGIC;
104 pThis->cRefs = 1;
105
106 *phKrnlInfo = pThis;
107 return VINF_SUCCESS;
108 }
109
110 LogRel(("RTR0DbgKrnlInfoOpen: ctf_modopen failed. err=%d\n", err));
111 rc = VERR_INTERNAL_ERROR_2;
112 }
113 else
114 {
115 LogRel(("RTR0DbgKrnlInfoOpen: mod_hold_by_name failed for genunix.\n"));
116 rc = VERR_INTERNAL_ERROR;
117 }
118
119 return rc;
120}
121
122
123RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo)
124{
125 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
126 uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
127 Assert(cRefs && cRefs < 100000);
128 NOREF(cRefs);
129 return cRefs;
130}
131
132
133static void rtR0DbgKrnlInfoDestroy(PRTDBGKRNLINFOINT pThis)
134{
135 pThis->u32Magic = ~RTDBGKRNLINFO_MAGIC;
136 ctf_close(pThis->pGenUnixCTF);
137 mod_release_mod(pThis->pGenUnixMod);
138 RTMemFree(pThis);
139}
140
141
142RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
143{
144 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
145 AssertPtrReturn(pThis, UINT32_MAX);
146 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
147 RT_ASSERT_PREEMPTIBLE();
148
149 uint32_t cRefs = ASMAtomicDecU32(&pThis->cRefs);
150 if (cRefs == 0)
151 rtR0DbgKrnlInfoDestroy(pThis);
152 return cRefs;
153}
154
155
156RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
157 const char *pszMember, size_t *poffMember)
158{
159 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
160 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
161 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
162 AssertPtrReturn(pszMember, VERR_INVALID_PARAMETER);
163 AssertPtrReturn(pszStructure, VERR_INVALID_PARAMETER);
164 AssertPtrReturn(poffMember, VERR_INVALID_PARAMETER);
165 RT_ASSERT_PREEMPTIBLE();
166
167 int rc = VERR_NOT_FOUND;
168 ctf_id_t TypeIdent = ctf_lookup_by_name(pThis->pGenUnixCTF, pszStructure);
169 if (TypeIdent != CTF_ERR)
170 {
171 ctf_membinfo_t MemberInfo;
172 RT_ZERO(MemberInfo);
173 if (ctf_member_info(pThis->pGenUnixCTF, TypeIdent, pszMember, &MemberInfo) != CTF_ERR)
174 {
175 *poffMember = (MemberInfo.ctm_offset >> 3);
176 return VINF_SUCCESS;
177 }
178 }
179
180 return rc;
181}
182
183
184RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
185 const char *pszSymbol, void **ppvSymbol)
186{
187 PRTDBGKRNLINFOINT pThis = hKrnlInfo;
188 AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
189 AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
190 AssertPtrReturn(pszSymbol, VERR_INVALID_PARAMETER);
191 AssertPtrReturn(ppvSymbol, VERR_INVALID_PARAMETER);
192 AssertReturn(!pszModule, VERR_MODULE_NOT_FOUND);
193 RT_ASSERT_PREEMPTIBLE();
194
195 *ppvSymbol = (void *)kobj_getsymvalue((char *)pszSymbol, 1 /* only kernel */);
196 if (*ppvSymbol)
197 return VINF_SUCCESS;
198
199 return VERR_SYMBOL_NOT_FOUND;
200}
201
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