VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGPlugInLinuxModuleCodeTmpl.cpp.h@ 88956

Last change on this file since 88956 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 KB
Line 
1/* $Id: DBGPlugInLinuxModuleCodeTmpl.cpp.h 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * DBGPlugInLinux - Code template for struct module processing.
4 */
5
6/*
7 * Copyright (C) 2019-2020 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
18
19/*********************************************************************************************************************************
20* Defined Constants And Macros *
21*********************************************************************************************************************************/
22#ifndef LNX_MK_VER
23# define LNX_MK_VER(major, minor, build) (((major) << 22) | ((minor) << 12) | (build))
24#endif
25#if LNX_64BIT
26# define LNX_ULONG_T uint64_t
27#else
28# define LNX_ULONG_T uint32_t
29#endif
30#if LNX_64BIT
31# define PAD32ON64(seq) uint32_t RT_CONCAT(u32Padding,seq);
32#else
33# define PAD32ON64(seq)
34#endif
35
36
37/*********************************************************************************************************************************
38* Structures and Typedefs *
39*********************************************************************************************************************************/
40#if LNX_VER >= LNX_MK_VER(2,6,11)
41typedef struct RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX)
42{
43 LNX_PTR_T uPtrKName;
44# if LNX_VER < LNX_MK_VER(2,6,24)
45 char name[20];
46# endif
47# if LNX_VER < LNX_MK_VER(2,6,27)
48 int32_t cRefs;
49# if LNX_VER >= LNX_MK_VER(2,6,24)
50 PAD32ON64(0)
51# endif
52# endif
53 LNX_PTR_T uPtrNext;
54 LNX_PTR_T uPtrPrev;
55 LNX_PTR_T uPtrParent; /**< struct kobject pointer */
56 LNX_PTR_T uPtrKset; /**< struct kset pointer */
57 LNX_PTR_T uPtrKtype; /**< struct kobj_type pointer */
58 LNX_PTR_T uPtrDirEntry; /**< struct dentry pointer; 2.6.23+ sysfs_dirent. */
59# if LNX_VER >= LNX_MK_VER(2,6,17) && LNX_VER < LNX_MK_VER(2,6,24)
60 LNX_PTR_T aPtrWaitQueueHead[3];
61# endif
62# if LNX_VER >= LNX_MK_VER(2,6,27)
63 int32_t cRefs;
64 uint32_t uStateStuff;
65# elif LNX_VER >= LNX_MK_VER(2,6,25)
66 LNX_ULONG_T uStateStuff;
67# endif
68 /* non-kobject: */
69 LNX_PTR_T uPtrModule; /**< struct module pointer. */
70# if LNX_VER >= LNX_MK_VER(2,6,21)
71 LNX_PTR_T uPtrDriverDir; /**< Points to struct kobject. */
72# endif
73} RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX);
74#endif
75#if LNX_VER == LNX_MK_VER(2,6,24) && LNX_64BIT
76AssertCompileMemberOffset(RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX), uPtrParent, 32);
77AssertCompileMemberOffset(RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX), uPtrParent, 32);
78AssertCompileSize(RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX), 80);
79#endif
80
81
82
83/**
84 * Maps to the start of struct module in include/linux/module.h.
85 */
86typedef struct RT_CONCAT(LNXKMODULE,LNX_SUFFIX)
87{
88#if LNX_VER >= LNX_MK_VER(2,5,48)
89 /*
90 * This first part is mostly always the same.
91 */
92 int32_t state;
93 PAD32ON64(0)
94 LNX_PTR_T uPtrNext;
95 LNX_PTR_T uPtrPrev;
96 char name[64 - sizeof(LNX_PTR_T)];
97
98 /*
99 * Here be spaghetti dragons.
100 */
101# if LNX_VER >= LNX_MK_VER(2,6,11)
102 RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX) mkobj; /**< Was just kobj for a while. */
103 LNX_PTR_T uPtrParamAttrs; /**< Points to struct module_param_attrs. */
104# if LNX_VER >= LNX_MK_VER(2,6,17)
105 LNX_PTR_T uPtrModInfoAttrs; /**< Points to struct module_attribute. */
106# endif
107# if LNX_VER == LNX_MK_VER(2,6,20)
108 LNX_PTR_T uPtrDriverDir; /**< Points to struct kobject. */
109# elif LNX_VER >= LNX_MK_VER(2,6,21)
110 LNX_PTR_T uPtrHolderDir; /**< Points to struct kobject. */
111# endif
112# if LNX_VER >= LNX_MK_VER(2,6,13)
113 LNX_PTR_T uPtrVersion; /**< String pointers. */
114 LNX_PTR_T uPtrSrcVersion; /**< String pointers. */
115# endif
116# else
117# if LNX_VER >= LNX_MK_VER(2,6,7)
118 LNX_PTR_T uPtrMkObj;
119# endif
120# if LNX_VER >= LNX_MK_VER(2,6,10)
121 LNX_PTR_T uPtrParamsKobject;
122# endif
123# endif
124
125 /** @name Exported Symbols
126 * @{ */
127# if LNX_VER < LNX_MK_VER(2,5,67)
128 LNX_PTR_T uPtrSymsNext, uPtrSymsPrev, uPtrSymsOwner;
129# if LNX_VER >= LNX_MK_VER(2,5,55)
130 int32_t syms_gplonly;
131 uint32_t num_syms;
132# else
133 uint32_t num_syms;
134 PAD32ON64(1)
135# endif
136# endif
137 LNX_PTR_T uPtrSyms; /**< Array of struct kernel_symbol. */
138# if LNX_VER >= LNX_MK_VER(2,5,67)
139 uint32_t num_syms;
140 PAD32ON64(1)
141# endif
142# if LNX_VER >= LNX_MK_VER(2,5,60)
143 LNX_PTR_T uPtrCrcs; /**< unsigned long array */
144# endif
145 /** @} */
146
147 /** @name GPL Symbols
148 * @since 2.5.55
149 * @{ */
150# if LNX_VER >= LNX_MK_VER(2,5,55)
151# if LNX_VER < LNX_MK_VER(2,5,67)
152 LNX_PTR_T uPtrGplSymsNext, uPtrGplSymsPrev, uPtrGplSymsOwner;
153# if LNX_VER >= LNX_MK_VER(2,5,55)
154 int32_t gpl_syms_gplonly;
155 uint32_t num_gpl_syms;
156# else
157 uint32_t num_gpl_syms;
158 PAD32ON64(2)
159# endif
160# endif
161 LNX_PTR_T uPtrGplSyms; /**< Array of struct kernel_symbol. */
162# if LNX_VER >= LNX_MK_VER(2,5,67)
163 uint32_t num_gpl_syms;
164 PAD32ON64(2)
165# endif
166# if LNX_VER >= LNX_MK_VER(2,5,60)
167 LNX_PTR_T uPtrGplCrcs; /**< unsigned long array */
168# endif
169# endif /* > 2.5.55 */
170 /** @} */
171
172 /** @name Unused Exported Symbols
173 * @since 2.6.18
174 * @{ */
175# if LNX_VER >= LNX_MK_VER(2,6,18)
176 LNX_PTR_T uPtrUnusedSyms; /**< Array of struct kernel_symbol. */
177 uint32_t num_unused_syms;
178 PAD32ON64(4)
179 LNX_PTR_T uPtrUnusedCrcs; /**< unsigned long array */
180# endif
181 /** @} */
182
183 /** @name Unused GPL Symbols
184 * @since 2.6.18
185 * @{ */
186# if LNX_VER >= LNX_MK_VER(2,6,18)
187 LNX_PTR_T uPtrUnusedGplSyms; /**< Array of struct kernel_symbol. */
188 uint32_t num_unused_gpl_syms;
189 PAD32ON64(5)
190 LNX_PTR_T uPtrUnusedGplCrcs; /**< unsigned long array */
191# endif
192 /** @} */
193
194 /** @name Future GPL Symbols
195 * @since 2.6.17
196 * @{ */
197# if LNX_VER >= LNX_MK_VER(2,6,17)
198 LNX_PTR_T uPtrGplFutureSyms; /**< Array of struct kernel_symbol. */
199 uint32_t num_gpl_future_syms;
200 PAD32ON64(3)
201 LNX_PTR_T uPtrGplFutureCrcs; /**< unsigned long array */
202# endif
203 /** @} */
204
205 /** @name Exception table.
206 * @{ */
207# if LNX_VER < LNX_MK_VER(2,5,67)
208 LNX_PTR_T uPtrXcptTabNext, uPtrXcptTabPrev;
209# endif
210 uint32_t num_exentries;
211 PAD32ON64(6)
212 LNX_PTR_T uPtrEntries; /**< struct exception_table_entry array. */
213 /** @} */
214
215 /*
216 * Hopefully less spaghetti from here on...
217 */
218 LNX_PTR_T pfnInit;
219 LNX_PTR_T uPtrModuleInit;
220 LNX_PTR_T uPtrModuleCore;
221 LNX_ULONG_T cbInit;
222 LNX_ULONG_T cbCore;
223# if LNX_VER >= LNX_MK_VER(2,5,74)
224 LNX_ULONG_T cbInitText;
225 LNX_ULONG_T cbCoreText;
226# endif
227
228# if LNX_VER >= LNX_MK_VER(2,6,18)
229 LNX_PTR_T uPtrUnwindInfo;
230# endif
231#else
232 uint32_t structure_size;
233
234#endif
235} RT_CONCAT(LNXKMODULE,LNX_SUFFIX);
236
237# if LNX_VER == LNX_MK_VER(2,6,24) && LNX_64BIT
238AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrParamAttrs, 160);
239AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_syms, 208);
240AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_gpl_syms, 232);
241AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_unused_syms, 256);
242AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_unused_gpl_syms, 280);
243AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_gpl_future_syms, 304);
244AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_exentries, 320);
245AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrModuleCore, 352);
246AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrUnwindInfo, 392);
247#endif
248
249
250
251/**
252 * Version specific module processing code.
253 */
254static uint64_t RT_CONCAT(dbgDiggerLinuxLoadModule,LNX_SUFFIX)(PDBGDIGGERLINUX pThis, PUVM pUVM, PDBGFADDRESS pAddrModule)
255{
256 RT_CONCAT(LNXKMODULE,LNX_SUFFIX) Module;
257
258 int rc = DBGFR3MemRead(pUVM, 0, DBGFR3AddrSub(pAddrModule, RT_UOFFSETOF(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrNext)),
259 &Module, sizeof(Module));
260 if (RT_FAILURE(rc))
261 {
262 LogRelFunc(("Failed to read module structure at %#RX64: %Rrc\n", pAddrModule->FlatPtr, rc));
263 return 0;
264 }
265
266 /*
267 * Check the module name.
268 */
269#if LNX_VER >= LNX_MK_VER(2,5,48)
270 const char *pszName = Module.name;
271 size_t const cbName = sizeof(Module.name);
272#else
273
274#endif
275 if ( RTStrNLen(pszName, cbName) >= cbName
276 || RT_FAILURE(RTStrValidateEncoding(pszName))
277 || *pszName == '\0')
278 {
279 LogRelFunc(("%#RX64: Bad name: %.*Rhxs\n", pAddrModule->FlatPtr, (int)cbName, pszName));
280 return 0;
281 }
282
283 /*
284 * Create a simple module for it.
285 */
286 LogRelFunc((" %#RX64: %#RX64 LB %#RX64 %s\n", pAddrModule->FlatPtr, Module.uPtrModuleCore, Module.cbCore, pszName));
287
288 RTDBGMOD hDbgMod;
289 rc = RTDbgModCreate(&hDbgMod, pszName, Module.cbCore, 0 /*fFlags*/);
290 if (RT_SUCCESS(rc))
291 {
292 rc = RTDbgModSetTag(hDbgMod, DIG_LNX_MOD_TAG);
293 if (RT_SUCCESS(rc))
294 {
295 RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
296 rc = RTDbgAsModuleLink(hAs, hDbgMod, Module.uPtrModuleCore, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
297 RTDbgAsRelease(hAs);
298 }
299 else
300 LogRel(("DbgDiggerOs2: RTDbgModSetTag failed: %Rrc\n", rc));
301 RTDbgModRelease(hDbgMod);
302 }
303
304 RT_NOREF(pThis);
305 return Module.uPtrNext;
306}
307
308#undef LNX_VER
309#undef LNX_SUFFIX
310#undef LNX_ULONG_T
311#undef PAD32ON64
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