1 | /* $Id: dbg-r0drv-solaris.c 40670 2012-03-27 17:35:04Z 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 |
|
---|
41 | #include <sys/kobj.h>
|
---|
42 | #include <sys/thread.h>
|
---|
43 | #include <sys/ctf_api.h>
|
---|
44 | #include <sys/modctl.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | /*******************************************************************************
|
---|
48 | * Structures and Typedefs *
|
---|
49 | *******************************************************************************/
|
---|
50 | typedef struct RTDBGKRNLINFOINT
|
---|
51 | {
|
---|
52 | /** Magic value (). */
|
---|
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 | typedef struct RTDBGKRNLINFOINT *PRTDBGKRNLINFOINT;
|
---|
62 | /** Magic value for RTDBGKRNLINFOINT::u32Magic. (John Carmack) */
|
---|
63 | #define RTDBGKRNLINFO_MAGIC UINT32_C(0x19700820)
|
---|
64 |
|
---|
65 |
|
---|
66 | RTR0DECL(int) RTR0DbgKrnlInfoOpen(PRTDBGKRNLINFO phKrnlInfo, uint32_t fFlags)
|
---|
67 | {
|
---|
68 | AssertReturn(fFlags == 0, VERR_INVALID_PARAMETER);
|
---|
69 | AssertPtrReturn(phKrnlInfo, VERR_INVALID_POINTER);
|
---|
70 | RT_ASSERT_PREEMPTIBLE();
|
---|
71 |
|
---|
72 | PRTDBGKRNLINFOINT pThis = (PRTDBGKRNLINFOINT)RTMemAllocZ(sizeof(*pThis));
|
---|
73 | if (!pThis)
|
---|
74 | return VERR_NO_MEMORY;
|
---|
75 |
|
---|
76 | int rc = VINF_SUCCESS;
|
---|
77 | pThis->pGenUnixMod = mod_hold_by_name("genunix");
|
---|
78 | if (RT_LIKELY(pThis->pGenUnixMod))
|
---|
79 | {
|
---|
80 | /*
|
---|
81 | * Hold mod_lock as ctf_modopen may update the module with uncompressed CTF data.
|
---|
82 | */
|
---|
83 | int err;
|
---|
84 | mutex_enter(&mod_lock);
|
---|
85 | pThis->pGenUnixCTF = ctf_modopen(pThis->pGenUnixMod->mod_mp, &err);
|
---|
86 | mutex_exit(&mod_lock);
|
---|
87 |
|
---|
88 | if (RT_LIKELY(pThis->pGenUnixCTF))
|
---|
89 | {
|
---|
90 | pThis->u32Magic = RTDBGKRNLINFO_MAGIC;
|
---|
91 | pThis->cRefs = 1;
|
---|
92 |
|
---|
93 | *phKrnlInfo = pThis;
|
---|
94 | return VINF_SUCCESS;
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | LogRel(("RTR0DbgKrnlInfoOpen: ctf_modopen failed. err=%d\n", err));
|
---|
99 | rc = VERR_INTERNAL_ERROR_2;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | else
|
---|
103 | {
|
---|
104 | LogRel(("RTR0DbgKrnlInfoOpen: mod_hold_by_name failed for genunix.\n"));
|
---|
105 | rc = VERR_INTERNAL_ERROR;
|
---|
106 | }
|
---|
107 |
|
---|
108 | return rc;
|
---|
109 | }
|
---|
110 |
|
---|
111 |
|
---|
112 | RTR0DECL(uint32_t) RTR0DbgKrnlInfoRetain(RTDBGKRNLINFO hKrnlInfo)
|
---|
113 | {
|
---|
114 | PRTDBGKRNLINFOINT pThis = hKrnlInfo;
|
---|
115 | uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
|
---|
116 | Assert(cRefs && cRefs < 100000);
|
---|
117 | NOREF(cRefs);
|
---|
118 | }
|
---|
119 |
|
---|
120 | static void rtR0DbgKrnlInfoDestroy(RTDBGKRNLINFO hKrnlInfo)
|
---|
121 | {
|
---|
122 | PRTDBGKRNLINFOINT pThis = hKrnlInfo;
|
---|
123 | AssertPtrReturnVoid(pThis);
|
---|
124 | AssertPtrReturnVoid(pThis->u32Magic == RTDBGKRNLINFO_MAGIC);
|
---|
125 | RT_ASSERT_PREEMPTIBLE();
|
---|
126 |
|
---|
127 | ctf_close(pThis->pGenUnixCTF);
|
---|
128 | mod_release_mod(pThis->pGenUnixMod);
|
---|
129 | RTMemFree(pThis);
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | RTR0DECL(uint32_t) RTR0DbgKrnlInfoRelease(RTDBGKRNLINFO hKrnlInfo)
|
---|
134 | {
|
---|
135 | PRTDBGKRNLINFOINT pThis = hKrnlInfo;
|
---|
136 | AssertPtrReturn(pThis, UINT32_MAX);
|
---|
137 | AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), UINT32_MAX);
|
---|
138 | RT_ASSERT_PREEMPTIBLE();
|
---|
139 |
|
---|
140 | if (ASMAtomicDecU32(&pThis->cRefs) == 0)
|
---|
141 | rtR0DbgKrnlInfoDestroy(pThis);
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | RTR0DECL(int) RTR0DbgKrnlInfoQueryMember(RTDBGKRNLINFO hKrnlInfo, const char *pszStructure,
|
---|
146 | const char *pszMember, size_t *poffMember)
|
---|
147 | {
|
---|
148 | PRTDBGKRNLINFOINT pThis = hKrnlInfo;
|
---|
149 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
150 | AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
|
---|
151 | AssertPtrReturn(pszMember, VERR_INVALID_PARAMETER);
|
---|
152 | AssertPtrReturn(pszStructure, VERR_INVALID_PARAMETER);
|
---|
153 | AssertPtrReturn(poffMember, VERR_INVALID_PARAMETER);
|
---|
154 | RT_ASSERT_PREEMPTIBLE();
|
---|
155 |
|
---|
156 | int rc = VERR_NOT_FOUND;
|
---|
157 | ctf_id_t TypeIdent = ctf_lookup_by_name(pThis->pGenUnixCTF, pszStructure);
|
---|
158 | if (TypeIdent != CTF_ERR)
|
---|
159 | {
|
---|
160 | ctf_membinfo_t MemberInfo;
|
---|
161 | RT_ZERO(MemberInfo);
|
---|
162 | if (ctf_member_info(pThis->pGenUnixCTF, TypeIdent, pszMember, &MemberInfo) != CTF_ERR)
|
---|
163 | {
|
---|
164 | *poffMember = (MemberInfo.ctm_offset >> 3);
|
---|
165 | return VINF_SUCCESS;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | return rc;
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | RTR0DECL(int) RTR0DbgKrnlInfoQuerySymbol(RTDBGKRNLINFO hKrnlInfo, const char *pszModule,
|
---|
174 | const char *pszSymbol, void **ppvSymbol)
|
---|
175 | {
|
---|
176 | PRTDBGKRNLINFOINT pThis = hKrnlInfo;
|
---|
177 | AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
|
---|
178 | AssertMsgReturn(pThis->u32Magic == RTDBGKRNLINFO_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
|
---|
179 | AssertPtrReturn(pszSymbol, VERR_INVALID_PARAMETER);
|
---|
180 | AssertPtrReturn(ppvSymbol, VERR_INVALID_PARAMETER);
|
---|
181 | RT_ASSERT_PREEMPTIBLE();
|
---|
182 |
|
---|
183 | NOREF(pszModule);
|
---|
184 | *ppvSymbol = kobj_getsymvalue(pszSymbol, 1 /* only kernel */);
|
---|
185 | if (*ppvSymbol)
|
---|
186 | return VINF_SUCCESS;
|
---|
187 |
|
---|
188 | return VERR_SYMBOL_NOT_FOUND;
|
---|
189 | }
|
---|
190 |
|
---|