[77874] | 1 | /* $Id: DBGPlugInLinuxModuleCodeTmpl.cpp.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * DBGPlugInLinux - Code template for struct module processing.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2019-2023 Oracle and/or its affiliates.
|
---|
[77874] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[77874] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Defined Constants And Macros *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
| 32 | #ifndef LNX_MK_VER
|
---|
| 33 | # define LNX_MK_VER(major, minor, build) (((major) << 22) | ((minor) << 12) | (build))
|
---|
| 34 | #endif
|
---|
| 35 | #if LNX_64BIT
|
---|
| 36 | # define LNX_ULONG_T uint64_t
|
---|
| 37 | #else
|
---|
| 38 | # define LNX_ULONG_T uint32_t
|
---|
| 39 | #endif
|
---|
| 40 | #if LNX_64BIT
|
---|
| 41 | # define PAD32ON64(seq) uint32_t RT_CONCAT(u32Padding,seq);
|
---|
| 42 | #else
|
---|
| 43 | # define PAD32ON64(seq)
|
---|
| 44 | #endif
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | /*********************************************************************************************************************************
|
---|
| 48 | * Structures and Typedefs *
|
---|
| 49 | *********************************************************************************************************************************/
|
---|
[90432] | 50 | /**
|
---|
| 51 | * Kernel module symbol (hasn't changed in ages).
|
---|
| 52 | */
|
---|
| 53 | typedef struct RT_CONCAT(LNXMODKSYM,LNX_SUFFIX)
|
---|
| 54 | {
|
---|
| 55 | LNX_ULONG_T uValue;
|
---|
| 56 | LNX_PTR_T uPtrSymName;
|
---|
| 57 | } RT_CONCAT(LNXMODKSYM,LNX_SUFFIX);
|
---|
| 58 |
|
---|
| 59 |
|
---|
[77874] | 60 | #if LNX_VER >= LNX_MK_VER(2,6,11)
|
---|
| 61 | typedef struct RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX)
|
---|
| 62 | {
|
---|
| 63 | LNX_PTR_T uPtrKName;
|
---|
| 64 | # if LNX_VER < LNX_MK_VER(2,6,24)
|
---|
| 65 | char name[20];
|
---|
| 66 | # endif
|
---|
| 67 | # if LNX_VER < LNX_MK_VER(2,6,27)
|
---|
| 68 | int32_t cRefs;
|
---|
| 69 | # if LNX_VER >= LNX_MK_VER(2,6,24)
|
---|
| 70 | PAD32ON64(0)
|
---|
| 71 | # endif
|
---|
| 72 | # endif
|
---|
| 73 | LNX_PTR_T uPtrNext;
|
---|
| 74 | LNX_PTR_T uPtrPrev;
|
---|
| 75 | LNX_PTR_T uPtrParent; /**< struct kobject pointer */
|
---|
| 76 | LNX_PTR_T uPtrKset; /**< struct kset pointer */
|
---|
| 77 | LNX_PTR_T uPtrKtype; /**< struct kobj_type pointer */
|
---|
| 78 | LNX_PTR_T uPtrDirEntry; /**< struct dentry pointer; 2.6.23+ sysfs_dirent. */
|
---|
| 79 | # if LNX_VER >= LNX_MK_VER(2,6,17) && LNX_VER < LNX_MK_VER(2,6,24)
|
---|
| 80 | LNX_PTR_T aPtrWaitQueueHead[3];
|
---|
| 81 | # endif
|
---|
| 82 | # if LNX_VER >= LNX_MK_VER(2,6,27)
|
---|
| 83 | int32_t cRefs;
|
---|
| 84 | uint32_t uStateStuff;
|
---|
| 85 | # elif LNX_VER >= LNX_MK_VER(2,6,25)
|
---|
| 86 | LNX_ULONG_T uStateStuff;
|
---|
| 87 | # endif
|
---|
| 88 | /* non-kobject: */
|
---|
| 89 | LNX_PTR_T uPtrModule; /**< struct module pointer. */
|
---|
| 90 | # if LNX_VER >= LNX_MK_VER(2,6,21)
|
---|
| 91 | LNX_PTR_T uPtrDriverDir; /**< Points to struct kobject. */
|
---|
| 92 | # endif
|
---|
[90408] | 93 | # if LNX_VER >= LNX_MK_VER(4,5,0)
|
---|
| 94 | LNX_PTR_T uPtrMp;
|
---|
| 95 | LNX_PTR_T uPtrCompletion; /**< Points to struct completion. */
|
---|
| 96 | # endif
|
---|
[77874] | 97 | } RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX);
|
---|
| 98 | #endif
|
---|
| 99 | #if LNX_VER == LNX_MK_VER(2,6,24) && LNX_64BIT
|
---|
| 100 | AssertCompileMemberOffset(RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX), uPtrParent, 32);
|
---|
| 101 | AssertCompileMemberOffset(RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX), uPtrParent, 32);
|
---|
| 102 | AssertCompileSize(RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX), 80);
|
---|
| 103 | #endif
|
---|
| 104 |
|
---|
| 105 |
|
---|
[90408] | 106 | #if LNX_VER >= LNX_MK_VER(4,5,0)
|
---|
| 107 | /**
|
---|
| 108 | * Red black tree node.
|
---|
| 109 | */
|
---|
| 110 | typedef struct RT_CONCAT(LNXRBNODE,LNX_SUFFIX)
|
---|
| 111 | {
|
---|
| 112 | LNX_ULONG_T uRbParentColor;
|
---|
| 113 | LNX_PTR_T uPtrRbRight;
|
---|
| 114 | LNX_PTR_T uPtrRbLeft;
|
---|
| 115 | } RT_CONCAT(LNXRBNODE,LNX_SUFFIX);
|
---|
[77874] | 116 |
|
---|
[90408] | 117 |
|
---|
[77874] | 118 | /**
|
---|
[90408] | 119 | * Latch tree node.
|
---|
| 120 | */
|
---|
| 121 | typedef struct RT_CONCAT(LNXLATCHTREENODE,LNX_SUFFIX)
|
---|
| 122 | {
|
---|
| 123 | RT_CONCAT(LNXRBNODE,LNX_SUFFIX) aNode[2];
|
---|
| 124 | } RT_CONCAT(LNXLATCHTREENODE,LNX_SUFFIX);
|
---|
| 125 |
|
---|
| 126 |
|
---|
| 127 | /**
|
---|
| 128 | * Module tree node.
|
---|
| 129 | */
|
---|
| 130 | typedef struct RT_CONCAT(LNXMODTREENODE,LNX_SUFFIX)
|
---|
| 131 | {
|
---|
| 132 | LNX_PTR_T uPtrKMod;
|
---|
| 133 | RT_CONCAT(LNXLATCHTREENODE,LNX_SUFFIX) Node;
|
---|
| 134 | } RT_CONCAT(LNXMODTREENODE,LNX_SUFFIX);
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | /**
|
---|
| 138 | * Module layout.
|
---|
| 139 | */
|
---|
| 140 | typedef struct RT_CONCAT(LNXKMODLAYOUT,LNX_SUFFIX)
|
---|
| 141 | {
|
---|
| 142 | LNX_PTR_T uPtrBase; /**< Base pointer to text and data. */
|
---|
| 143 | uint32_t cb; /**< Size of the module. */
|
---|
| 144 | uint32_t cbText; /**< Size of the text section. */
|
---|
| 145 | uint32_t cbRo; /**< Size of the readonly portion (text + ro data). */
|
---|
| 146 | RT_CONCAT(LNXMODTREENODE,LNX_SUFFIX) ModTreeNd; /**< Only available when CONFIG_MODULES_TREE_LOOKUP is set (default). */
|
---|
| 147 | } RT_CONCAT(LNXKMODLAYOUT,LNX_SUFFIX);
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | /**
|
---|
| 151 | * Mutex.
|
---|
| 152 | */
|
---|
| 153 | typedef struct RT_CONCAT(LNXMUTEX,LNX_SUFFIX)
|
---|
| 154 | {
|
---|
| 155 | LNX_ULONG_T uOwner;
|
---|
| 156 | uint32_t wait_lock; /**< Actually spinlock_t */
|
---|
| 157 | PAD32ON64(0)
|
---|
| 158 | LNX_PTR_T uWaitLstPtrNext;
|
---|
| 159 | LNX_PTR_T uWaitLstPtrPrev;
|
---|
| 160 | } RT_CONCAT(LNXMUTEX,LNX_SUFFIX);
|
---|
| 161 | #endif
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | /**
|
---|
[77874] | 165 | * Maps to the start of struct module in include/linux/module.h.
|
---|
| 166 | */
|
---|
| 167 | typedef struct RT_CONCAT(LNXKMODULE,LNX_SUFFIX)
|
---|
| 168 | {
|
---|
[90408] | 169 | #if LNX_VER >= LNX_MK_VER(4,5,0)
|
---|
| 170 | /* Completely new layout to not feed the spaghetti dragons further. */
|
---|
| 171 | int32_t state;
|
---|
| 172 | PAD32ON64(0)
|
---|
| 173 | LNX_PTR_T uPtrNext;
|
---|
| 174 | LNX_PTR_T uPtrPrev;
|
---|
| 175 | char name[64 - sizeof(LNX_PTR_T)];
|
---|
| 176 |
|
---|
| 177 | RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX) mkobj;
|
---|
| 178 | LNX_PTR_T uPtrModInfoAttrs; /**< Points to struct module_attribute. */
|
---|
| 179 | LNX_PTR_T uPtrVersion; /**< String pointers. */
|
---|
| 180 | LNX_PTR_T uPtrSrcVersion; /**< String pointers. */
|
---|
| 181 | LNX_PTR_T uPtrHolderDir; /**< Points to struct kobject. */
|
---|
| 182 |
|
---|
| 183 | /** @name Exported Symbols
|
---|
| 184 | * @{ */
|
---|
| 185 | LNX_PTR_T uPtrSyms; /**< Array of struct kernel_symbol. */
|
---|
| 186 | LNX_PTR_T uPtrCrcs; /**< unsigned long array */
|
---|
| 187 | uint32_t num_syms;
|
---|
| 188 | /** @} */
|
---|
| 189 |
|
---|
| 190 | /** @name Kernel parameters
|
---|
| 191 | * @{ */
|
---|
| 192 | RT_CONCAT(LNXMUTEX,LNX_SUFFIX) Mtx; /**< Mutex. */
|
---|
| 193 | LNX_PTR_T uPtrKp; /**< Points to struct kernel_param */
|
---|
| 194 | uint32_t num_kp;
|
---|
| 195 | /** @} */
|
---|
| 196 |
|
---|
| 197 | /** @name GPL Symbols
|
---|
| 198 | * @{ */
|
---|
| 199 | uint32_t num_gpl_syms;
|
---|
| 200 | LNX_PTR_T uPtrGplSyms; /**< Array of struct kernel_symbol. */
|
---|
| 201 | LNX_PTR_T uPtrGplCrcs; /**< unsigned long array */
|
---|
| 202 | /** @} */
|
---|
| 203 |
|
---|
| 204 | /** @name Unused symbols
|
---|
| 205 | * @{ */
|
---|
| 206 | LNX_PTR_T uPtrUnusedSyms; /**< Array of struct kernel_symbol. */
|
---|
| 207 | LNX_PTR_T uPtrUnusedCrcs; /**< unsigned long array */
|
---|
| 208 | uint32_t num_unused_syms;
|
---|
| 209 | uint32_t num_unused_gpl_syms;
|
---|
| 210 | LNX_PTR_T uPtrUnusedGplSyms; /**< Array of struct kernel_symbol. */
|
---|
| 211 | LNX_PTR_T uPtrUnusedGplCrcs; /**< unsigned long array */
|
---|
| 212 | /** @} */
|
---|
| 213 |
|
---|
| 214 | uint8_t sig_ok;
|
---|
| 215 | uint8_t async_probe_requested;
|
---|
| 216 |
|
---|
| 217 | /** @name Future GPL Symbols
|
---|
| 218 | * @{ */
|
---|
| 219 | LNX_PTR_T uPtrGplFutureSyms; /**< Array of struct kernel_symbol. */
|
---|
| 220 | LNX_PTR_T uPtrGplFutureCrcs; /**< unsigned long array */
|
---|
| 221 | uint32_t num_gpl_future_syms;
|
---|
| 222 | /** @} */
|
---|
| 223 |
|
---|
| 224 | /** @name Exception table.
|
---|
| 225 | * @{ */
|
---|
| 226 | uint32_t num_exentries;
|
---|
| 227 | LNX_PTR_T uPtrEntries; /**< struct exception_table_entry array. */
|
---|
| 228 | /** @} */
|
---|
| 229 |
|
---|
| 230 | LNX_PTR_T pfnInit;
|
---|
| 231 | RT_CONCAT(LNXKMODLAYOUT,LNX_SUFFIX) CoreLayout; /**< Should be aligned on a cache line. */
|
---|
| 232 | RT_CONCAT(LNXKMODLAYOUT,LNX_SUFFIX) InitLayout;
|
---|
| 233 |
|
---|
| 234 | #elif LNX_VER >= LNX_MK_VER(2,5,48)
|
---|
[77874] | 235 | /*
|
---|
| 236 | * This first part is mostly always the same.
|
---|
| 237 | */
|
---|
| 238 | int32_t state;
|
---|
| 239 | PAD32ON64(0)
|
---|
| 240 | LNX_PTR_T uPtrNext;
|
---|
| 241 | LNX_PTR_T uPtrPrev;
|
---|
| 242 | char name[64 - sizeof(LNX_PTR_T)];
|
---|
| 243 |
|
---|
| 244 | /*
|
---|
| 245 | * Here be spaghetti dragons.
|
---|
| 246 | */
|
---|
| 247 | # if LNX_VER >= LNX_MK_VER(2,6,11)
|
---|
| 248 | RT_CONCAT(LNXMODKOBJECT,LNX_SUFFIX) mkobj; /**< Was just kobj for a while. */
|
---|
| 249 | LNX_PTR_T uPtrParamAttrs; /**< Points to struct module_param_attrs. */
|
---|
| 250 | # if LNX_VER >= LNX_MK_VER(2,6,17)
|
---|
| 251 | LNX_PTR_T uPtrModInfoAttrs; /**< Points to struct module_attribute. */
|
---|
| 252 | # endif
|
---|
| 253 | # if LNX_VER == LNX_MK_VER(2,6,20)
|
---|
| 254 | LNX_PTR_T uPtrDriverDir; /**< Points to struct kobject. */
|
---|
| 255 | # elif LNX_VER >= LNX_MK_VER(2,6,21)
|
---|
| 256 | LNX_PTR_T uPtrHolderDir; /**< Points to struct kobject. */
|
---|
| 257 | # endif
|
---|
| 258 | # if LNX_VER >= LNX_MK_VER(2,6,13)
|
---|
| 259 | LNX_PTR_T uPtrVersion; /**< String pointers. */
|
---|
| 260 | LNX_PTR_T uPtrSrcVersion; /**< String pointers. */
|
---|
| 261 | # endif
|
---|
| 262 | # else
|
---|
| 263 | # if LNX_VER >= LNX_MK_VER(2,6,7)
|
---|
| 264 | LNX_PTR_T uPtrMkObj;
|
---|
| 265 | # endif
|
---|
| 266 | # if LNX_VER >= LNX_MK_VER(2,6,10)
|
---|
| 267 | LNX_PTR_T uPtrParamsKobject;
|
---|
| 268 | # endif
|
---|
| 269 | # endif
|
---|
| 270 |
|
---|
| 271 | /** @name Exported Symbols
|
---|
| 272 | * @{ */
|
---|
| 273 | # if LNX_VER < LNX_MK_VER(2,5,67)
|
---|
| 274 | LNX_PTR_T uPtrSymsNext, uPtrSymsPrev, uPtrSymsOwner;
|
---|
| 275 | # if LNX_VER >= LNX_MK_VER(2,5,55)
|
---|
| 276 | int32_t syms_gplonly;
|
---|
| 277 | uint32_t num_syms;
|
---|
| 278 | # else
|
---|
| 279 | uint32_t num_syms;
|
---|
| 280 | PAD32ON64(1)
|
---|
| 281 | # endif
|
---|
| 282 | # endif
|
---|
| 283 | LNX_PTR_T uPtrSyms; /**< Array of struct kernel_symbol. */
|
---|
| 284 | # if LNX_VER >= LNX_MK_VER(2,5,67)
|
---|
| 285 | uint32_t num_syms;
|
---|
| 286 | PAD32ON64(1)
|
---|
| 287 | # endif
|
---|
| 288 | # if LNX_VER >= LNX_MK_VER(2,5,60)
|
---|
| 289 | LNX_PTR_T uPtrCrcs; /**< unsigned long array */
|
---|
| 290 | # endif
|
---|
| 291 | /** @} */
|
---|
| 292 |
|
---|
| 293 | /** @name GPL Symbols
|
---|
| 294 | * @since 2.5.55
|
---|
| 295 | * @{ */
|
---|
| 296 | # if LNX_VER >= LNX_MK_VER(2,5,55)
|
---|
| 297 | # if LNX_VER < LNX_MK_VER(2,5,67)
|
---|
| 298 | LNX_PTR_T uPtrGplSymsNext, uPtrGplSymsPrev, uPtrGplSymsOwner;
|
---|
| 299 | # if LNX_VER >= LNX_MK_VER(2,5,55)
|
---|
| 300 | int32_t gpl_syms_gplonly;
|
---|
| 301 | uint32_t num_gpl_syms;
|
---|
| 302 | # else
|
---|
| 303 | uint32_t num_gpl_syms;
|
---|
| 304 | PAD32ON64(2)
|
---|
| 305 | # endif
|
---|
| 306 | # endif
|
---|
| 307 | LNX_PTR_T uPtrGplSyms; /**< Array of struct kernel_symbol. */
|
---|
| 308 | # if LNX_VER >= LNX_MK_VER(2,5,67)
|
---|
| 309 | uint32_t num_gpl_syms;
|
---|
| 310 | PAD32ON64(2)
|
---|
| 311 | # endif
|
---|
| 312 | # if LNX_VER >= LNX_MK_VER(2,5,60)
|
---|
| 313 | LNX_PTR_T uPtrGplCrcs; /**< unsigned long array */
|
---|
| 314 | # endif
|
---|
| 315 | # endif /* > 2.5.55 */
|
---|
| 316 | /** @} */
|
---|
| 317 |
|
---|
| 318 | /** @name Unused Exported Symbols
|
---|
| 319 | * @since 2.6.18
|
---|
| 320 | * @{ */
|
---|
| 321 | # if LNX_VER >= LNX_MK_VER(2,6,18)
|
---|
| 322 | LNX_PTR_T uPtrUnusedSyms; /**< Array of struct kernel_symbol. */
|
---|
| 323 | uint32_t num_unused_syms;
|
---|
| 324 | PAD32ON64(4)
|
---|
| 325 | LNX_PTR_T uPtrUnusedCrcs; /**< unsigned long array */
|
---|
| 326 | # endif
|
---|
| 327 | /** @} */
|
---|
| 328 |
|
---|
| 329 | /** @name Unused GPL Symbols
|
---|
| 330 | * @since 2.6.18
|
---|
| 331 | * @{ */
|
---|
| 332 | # if LNX_VER >= LNX_MK_VER(2,6,18)
|
---|
| 333 | LNX_PTR_T uPtrUnusedGplSyms; /**< Array of struct kernel_symbol. */
|
---|
| 334 | uint32_t num_unused_gpl_syms;
|
---|
| 335 | PAD32ON64(5)
|
---|
| 336 | LNX_PTR_T uPtrUnusedGplCrcs; /**< unsigned long array */
|
---|
| 337 | # endif
|
---|
| 338 | /** @} */
|
---|
| 339 |
|
---|
| 340 | /** @name Future GPL Symbols
|
---|
| 341 | * @since 2.6.17
|
---|
| 342 | * @{ */
|
---|
| 343 | # if LNX_VER >= LNX_MK_VER(2,6,17)
|
---|
| 344 | LNX_PTR_T uPtrGplFutureSyms; /**< Array of struct kernel_symbol. */
|
---|
| 345 | uint32_t num_gpl_future_syms;
|
---|
| 346 | PAD32ON64(3)
|
---|
| 347 | LNX_PTR_T uPtrGplFutureCrcs; /**< unsigned long array */
|
---|
| 348 | # endif
|
---|
| 349 | /** @} */
|
---|
| 350 |
|
---|
| 351 | /** @name Exception table.
|
---|
| 352 | * @{ */
|
---|
| 353 | # if LNX_VER < LNX_MK_VER(2,5,67)
|
---|
| 354 | LNX_PTR_T uPtrXcptTabNext, uPtrXcptTabPrev;
|
---|
| 355 | # endif
|
---|
| 356 | uint32_t num_exentries;
|
---|
| 357 | PAD32ON64(6)
|
---|
| 358 | LNX_PTR_T uPtrEntries; /**< struct exception_table_entry array. */
|
---|
| 359 | /** @} */
|
---|
| 360 |
|
---|
| 361 | /*
|
---|
| 362 | * Hopefully less spaghetti from here on...
|
---|
| 363 | */
|
---|
| 364 | LNX_PTR_T pfnInit;
|
---|
| 365 | LNX_PTR_T uPtrModuleInit;
|
---|
| 366 | LNX_PTR_T uPtrModuleCore;
|
---|
| 367 | LNX_ULONG_T cbInit;
|
---|
| 368 | LNX_ULONG_T cbCore;
|
---|
| 369 | # if LNX_VER >= LNX_MK_VER(2,5,74)
|
---|
| 370 | LNX_ULONG_T cbInitText;
|
---|
| 371 | LNX_ULONG_T cbCoreText;
|
---|
| 372 | # endif
|
---|
| 373 |
|
---|
| 374 | # if LNX_VER >= LNX_MK_VER(2,6,18)
|
---|
| 375 | LNX_PTR_T uPtrUnwindInfo;
|
---|
| 376 | # endif
|
---|
| 377 | #else
|
---|
| 378 | uint32_t structure_size;
|
---|
| 379 |
|
---|
| 380 | #endif
|
---|
| 381 | } RT_CONCAT(LNXKMODULE,LNX_SUFFIX);
|
---|
| 382 |
|
---|
| 383 | # if LNX_VER == LNX_MK_VER(2,6,24) && LNX_64BIT
|
---|
| 384 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrParamAttrs, 160);
|
---|
| 385 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_syms, 208);
|
---|
| 386 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_gpl_syms, 232);
|
---|
| 387 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_unused_syms, 256);
|
---|
| 388 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_unused_gpl_syms, 280);
|
---|
| 389 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_gpl_future_syms, 304);
|
---|
| 390 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), num_exentries, 320);
|
---|
| 391 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrModuleCore, 352);
|
---|
| 392 | AssertCompileMemberOffset(RT_CONCAT(LNXKMODULE,LNX_SUFFIX), uPtrUnwindInfo, 392);
|
---|
| 393 | #endif
|
---|
| 394 |
|
---|
| 395 |
|
---|
| 396 |
|
---|
| 397 | /**
|
---|
[90432] | 398 | * Loads the kernel symbols at the given start address.
|
---|
| 399 | *
|
---|
| 400 | * @returns VBox status code.
|
---|
[90473] | 401 | * @param pUVM Pointer to the user-mode VM instance.
|
---|
[90432] | 402 | * @param hDbgMod The module handle to add the loaded symbols to.
|
---|
[90473] | 403 | * @param uPtrModuleStart The virtual address where the kernel module starts we want to extract symbols from.
|
---|
[90432] | 404 | * @param uPtrSymStart The start address of the array of symbols.
|
---|
| 405 | * @param cSyms Number of symbols in the array.
|
---|
| 406 | */
|
---|
[93470] | 407 | static int RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(PUVM pUVM, PCVMMR3VTABLE pVMM, RTDBGMOD hDbgMod,
|
---|
| 408 | LNX_PTR_T uPtrModuleStart, LNX_PTR_T uPtrSymStart, uint32_t cSyms)
|
---|
[90432] | 409 | {
|
---|
| 410 | int rc = VINF_SUCCESS;
|
---|
| 411 | DBGFADDRESS AddrSym;
|
---|
[93470] | 412 | pVMM->pfnDBGFR3AddrFromFlat(pUVM, &AddrSym, uPtrSymStart);
|
---|
[90432] | 413 |
|
---|
| 414 | while ( cSyms
|
---|
| 415 | && RT_SUCCESS(rc))
|
---|
| 416 | {
|
---|
| 417 | RT_CONCAT(LNXMODKSYM,LNX_SUFFIX) aSyms[64];
|
---|
| 418 | uint32_t cThisLoad = RT_MIN(cSyms, RT_ELEMENTS(aSyms));
|
---|
| 419 |
|
---|
[93470] | 420 | rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &AddrSym, &aSyms[0], cThisLoad * sizeof(aSyms[0]));
|
---|
[90432] | 421 | if (RT_SUCCESS(rc))
|
---|
| 422 | {
|
---|
| 423 | cSyms -= cThisLoad;
|
---|
[93470] | 424 | pVMM->pfnDBGFR3AddrAdd(&AddrSym, cThisLoad * sizeof(aSyms[0]));
|
---|
[90432] | 425 |
|
---|
| 426 | for (uint32_t i = 0; i < cThisLoad; i++)
|
---|
| 427 | {
|
---|
| 428 | char szSymName[128];
|
---|
| 429 | DBGFADDRESS AddrSymName;
|
---|
[93470] | 430 | rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &AddrSymName, aSyms[i].uPtrSymName),
|
---|
| 431 | &szSymName[0], sizeof(szSymName));
|
---|
[90432] | 432 | if (RT_FAILURE(rc))
|
---|
| 433 | break;
|
---|
| 434 |
|
---|
| 435 | /* Verify string encoding - ignore the symbol if it fails. */
|
---|
| 436 | rc = RTStrValidateEncodingEx(&szSymName[0], sizeof(szSymName), RTSTR_VALIDATE_ENCODING_ZERO_TERMINATED);
|
---|
| 437 | if (RT_FAILURE(rc))
|
---|
| 438 | continue;
|
---|
| 439 |
|
---|
| 440 | Assert(aSyms[i].uValue >= uPtrModuleStart);
|
---|
[93470] | 441 | rc = RTDbgModSymbolAdd(hDbgMod, szSymName, RTDBGSEGIDX_RVA, aSyms[i].uValue - uPtrModuleStart,
|
---|
| 442 | 0 /*cb*/, 0 /*fFlags*/, NULL);
|
---|
[90432] | 443 | if (RT_SUCCESS(rc))
|
---|
| 444 | LogFlowFunc(("Added symbol '%s' successfully\n", szSymName));
|
---|
| 445 | else
|
---|
| 446 | {
|
---|
| 447 | LogFlowFunc(("Adding symbol '%s' failed with: %Rrc\n", szSymName, rc));
|
---|
| 448 | rc = VINF_SUCCESS;
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 | }
|
---|
| 453 |
|
---|
| 454 | return rc;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 |
|
---|
| 458 | /**
|
---|
[77874] | 459 | * Version specific module processing code.
|
---|
| 460 | */
|
---|
[93470] | 461 | static uint64_t RT_CONCAT(dbgDiggerLinuxLoadModule,LNX_SUFFIX)(PDBGDIGGERLINUX pThis, PUVM pUVM,
|
---|
| 462 | PCVMMR3VTABLE pVMM, PDBGFADDRESS pAddrModule)
|
---|
[77874] | 463 | {
|
---|
| 464 | RT_CONCAT(LNXKMODULE,LNX_SUFFIX) Module;
|
---|
| 465 |
|
---|
[93470] | 466 | int rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrSub(pAddrModule, RT_UOFFSETOF(RT_CONCAT(LNXKMODULE,LNX_SUFFIX),
|
---|
| 467 | uPtrNext)),
|
---|
| 468 | &Module, sizeof(Module));
|
---|
[77874] | 469 | if (RT_FAILURE(rc))
|
---|
| 470 | {
|
---|
| 471 | LogRelFunc(("Failed to read module structure at %#RX64: %Rrc\n", pAddrModule->FlatPtr, rc));
|
---|
| 472 | return 0;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | /*
|
---|
| 476 | * Check the module name.
|
---|
| 477 | */
|
---|
| 478 | #if LNX_VER >= LNX_MK_VER(2,5,48)
|
---|
| 479 | const char *pszName = Module.name;
|
---|
| 480 | size_t const cbName = sizeof(Module.name);
|
---|
| 481 | #else
|
---|
| 482 |
|
---|
| 483 | #endif
|
---|
| 484 | if ( RTStrNLen(pszName, cbName) >= cbName
|
---|
| 485 | || RT_FAILURE(RTStrValidateEncoding(pszName))
|
---|
| 486 | || *pszName == '\0')
|
---|
| 487 | {
|
---|
| 488 | LogRelFunc(("%#RX64: Bad name: %.*Rhxs\n", pAddrModule->FlatPtr, (int)cbName, pszName));
|
---|
| 489 | return 0;
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | /*
|
---|
| 493 | * Create a simple module for it.
|
---|
| 494 | */
|
---|
[90408] | 495 | #if LNX_VER >= LNX_MK_VER(4,5,0)
|
---|
| 496 | LNX_PTR_T uPtrModuleCore = Module.CoreLayout.uPtrBase;
|
---|
| 497 | uint32_t cbCore = Module.CoreLayout.cb;
|
---|
| 498 | #else
|
---|
| 499 | LNX_PTR_T uPtrModuleCore = Module.uPtrModuleCore;
|
---|
| 500 | uint32_t cbCore = (uint32_t)Module.cbCore;
|
---|
| 501 | #endif
|
---|
| 502 | LogRelFunc((" %#RX64: %#RX64 LB %#RX32 %s\n", pAddrModule->FlatPtr, uPtrModuleCore, cbCore, pszName));
|
---|
[77874] | 503 |
|
---|
| 504 | RTDBGMOD hDbgMod;
|
---|
[90408] | 505 | rc = RTDbgModCreate(&hDbgMod, pszName, cbCore, 0 /*fFlags*/);
|
---|
[77874] | 506 | if (RT_SUCCESS(rc))
|
---|
| 507 | {
|
---|
| 508 | rc = RTDbgModSetTag(hDbgMod, DIG_LNX_MOD_TAG);
|
---|
| 509 | if (RT_SUCCESS(rc))
|
---|
| 510 | {
|
---|
[93470] | 511 | RTDBGAS hAs = pVMM->pfnDBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
|
---|
[90408] | 512 | rc = RTDbgAsModuleLink(hAs, hDbgMod, uPtrModuleCore, RTDBGASLINK_FLAGS_REPLACE /*fFlags*/);
|
---|
[77874] | 513 | RTDbgAsRelease(hAs);
|
---|
[90432] | 514 | if (RT_SUCCESS(rc))
|
---|
| 515 | {
|
---|
[93470] | 516 | rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, pVMM, hDbgMod, uPtrModuleCore,
|
---|
[90432] | 517 | Module.uPtrSyms, Module.num_syms);
|
---|
| 518 | if (RT_FAILURE(rc))
|
---|
| 519 | LogRelFunc((" Faild to load symbols: %Rrc\n", rc));
|
---|
| 520 |
|
---|
| 521 | #if LNX_VER >= LNX_MK_VER(2,5,55)
|
---|
[93470] | 522 | rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, pVMM, hDbgMod, uPtrModuleCore,
|
---|
[90432] | 523 | Module.uPtrGplSyms, Module.num_gpl_syms);
|
---|
| 524 | if (RT_FAILURE(rc))
|
---|
| 525 | LogRelFunc((" Faild to load GPL symbols: %Rrc\n", rc));
|
---|
| 526 | #endif
|
---|
| 527 |
|
---|
| 528 | #if LNX_VER >= LNX_MK_VER(2,6,17)
|
---|
[93470] | 529 | rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, pVMM, hDbgMod, uPtrModuleCore,
|
---|
[90432] | 530 | Module.uPtrGplFutureSyms, Module.num_gpl_future_syms);
|
---|
| 531 | if (RT_FAILURE(rc))
|
---|
| 532 | LogRelFunc((" Faild to load future GPL symbols: %Rrc\n", rc));
|
---|
| 533 | #endif
|
---|
| 534 |
|
---|
| 535 | #if LNX_VER >= LNX_MK_VER(2,6,18)
|
---|
[93470] | 536 | rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, pVMM, hDbgMod, uPtrModuleCore,
|
---|
[90432] | 537 | Module.uPtrUnusedSyms, Module.num_unused_syms);
|
---|
| 538 | if (RT_FAILURE(rc))
|
---|
| 539 | LogRelFunc((" Faild to load unused symbols: %Rrc\n", rc));
|
---|
| 540 |
|
---|
[93470] | 541 | rc = RT_CONCAT(dbgDiggerLinuxLoadModuleSymbols,LNX_SUFFIX)(pUVM, pVMM, hDbgMod, uPtrModuleCore,
|
---|
[90432] | 542 | Module.uPtrUnusedGplSyms, Module.num_unused_gpl_syms);
|
---|
| 543 | if (RT_FAILURE(rc))
|
---|
| 544 | LogRelFunc((" Faild to load unused GPL symbols: %Rrc\n", rc));
|
---|
| 545 | #endif
|
---|
| 546 | }
|
---|
[77874] | 547 | }
|
---|
| 548 | else
|
---|
| 549 | LogRel(("DbgDiggerOs2: RTDbgModSetTag failed: %Rrc\n", rc));
|
---|
| 550 | RTDbgModRelease(hDbgMod);
|
---|
| 551 | }
|
---|
| 552 |
|
---|
| 553 | RT_NOREF(pThis);
|
---|
| 554 | return Module.uPtrNext;
|
---|
| 555 | }
|
---|
| 556 |
|
---|
| 557 | #undef LNX_VER
|
---|
| 558 | #undef LNX_SUFFIX
|
---|
| 559 | #undef LNX_ULONG_T
|
---|
| 560 | #undef PAD32ON64
|
---|