VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGPlugInSolaris.cpp@ 99806

Last change on this file since 99806 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 46.8 KB
Line 
1/* $Id: DBGPlugInSolaris.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * DBGPlugInSolaris - Debugger and Guest OS Digger Plugin For Solaris.
4 */
5
6/*
7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
8 *
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
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DBGF /// @todo add new log group.
33#include "DBGPlugIns.h"
34#include "DBGPlugInCommonELF.h"
35#include <VBox/vmm/dbgf.h>
36#include <VBox/vmm/vmmr3vtable.h>
37#include <iprt/asm.h>
38#include <iprt/err.h>
39#include <iprt/mem.h>
40#include <iprt/stream.h>
41#include <iprt/string.h>
42
43
44/*********************************************************************************************************************************
45* Defined Constants And Macros *
46*********************************************************************************************************************************/
47/** Solaris on little endian ASCII systems. */
48#define DIG_SOL_MOD_TAG UINT64_C(0x00736972616c6f53)
49
50
51/*********************************************************************************************************************************
52* Structures and Typedefs *
53*********************************************************************************************************************************/
54
55/** @name InternalSolaris structures
56 * @{ */
57
58/** sys/modctl.h */
59typedef struct SOL32v11_modctl
60{
61 uint32_t mod_next; /**< 0 */
62 uint32_t mod_prev; /**< 4 */
63 int32_t mod_id; /**< 8 */
64 uint32_t mod_mp; /**< c Pointer to the kernel runtime loader bits. */
65 uint32_t mod_inprogress_thread; /**< 10 */
66 uint32_t mod_modinfo; /**< 14 */
67 uint32_t mod_linkage; /**< 18 */
68 uint32_t mod_filename; /**< 1c */
69 uint32_t mod_modname; /**< 20 */
70 int8_t mod_busy; /**< 24 */
71 int8_t mod_want; /**< 25 */
72 int8_t mod_prim; /**< 26 this is 1 for 'unix' and a few others. */
73 int8_t mod_unused_padding; /**< 27 */
74 int32_t mod_ref; /**< 28 */
75 int8_t mod_loaded; /**< 2c */
76 int8_t mod_installed; /**< 2d */
77 int8_t mod_loadflags; /**< 2e */
78 int8_t mod_delay_unload; /**< 2f */
79 uint32_t mod_requisites; /**< 30 */
80 uint32_t mod___unused; /**< 34 */
81 int32_t mod_loadcnt; /**< 38 */
82 int32_t mod_nenabled; /**< 3c */
83 uint32_t mod_text; /**< 40 */
84 uint32_t mod_text_size; /**< 44 */
85 int32_t mod_gencount; /**< 48 */
86 uint32_t mod_requisite_loading; /**< 4c */
87} SOL32v11_modctl_t;
88AssertCompileSize(SOL32v11_modctl_t, 0x50);
89
90typedef struct SOL64v11_modctl
91{
92 uint64_t mod_next; /**< 0 */
93 uint64_t mod_prev; /**< 8 */
94 int32_t mod_id; /**< 10 */
95 int32_t mod_padding0;
96 uint64_t mod_mp; /**< 18 Pointer to the kernel runtime loader bits. */
97 uint64_t mod_inprogress_thread; /**< 20 */
98 uint64_t mod_modinfo; /**< 28 */
99 uint64_t mod_linkage; /**< 30 */
100 uint64_t mod_filename; /**< 38 */
101 uint64_t mod_modname; /**< 40 */
102 int8_t mod_busy; /**< 48 */
103 int8_t mod_want; /**< 49 */
104 int8_t mod_prim; /**< 4a this is 1 for 'unix' and a few others. */
105 int8_t mod_unused_padding; /**< 4b */
106 int32_t mod_ref; /**< 4c */
107 int8_t mod_loaded; /**< 50 */
108 int8_t mod_installed; /**< 51 */
109 int8_t mod_loadflags; /**< 52 */
110 int8_t mod_delay_unload; /**< 53 */
111 int32_t mod_padding1;
112 uint64_t mod_requisites; /**< 58 */
113 uint64_t mod___unused; /**< 60 */
114 int32_t mod_loadcnt; /**< 68 */
115 int32_t mod_nenabled; /**< 6c */
116 uint64_t mod_text; /**< 70 */
117 uint64_t mod_text_size; /**< 78 */
118 int32_t mod_gencount; /**< 80 */
119 int32_t mod_padding2;
120 uint64_t mod_requisite_loading; /**< 88 */
121} SOL64v11_modctl_t;
122AssertCompileSize(SOL64v11_modctl_t, 0x90);
123
124typedef struct SOL32v9_modctl
125{
126 uint32_t mod_next; /**< 0 */
127 uint32_t mod_prev; /**< 4 */
128 int32_t mod_id; /**< 8 */
129 uint32_t mod_mp; /**< c Pointer to the kernel runtime loader bits. */
130 uint32_t mod_inprogress_thread; /**< 10 */
131 uint32_t mod_modinfo; /**< 14 */
132 uint32_t mod_linkage; /**< 18 */
133 uint32_t mod_filename; /**< 1c */
134 uint32_t mod_modname; /**< 20 */
135 int32_t mod_busy; /**< 24 */
136 int32_t mod_stub; /**< 28 DIFF 1 */
137 int8_t mod_loaded; /**< 2c */
138 int8_t mod_installed; /**< 2d */
139 int8_t mod_loadflags; /**< 2e */
140 int8_t mod_want; /**< 2f DIFF 2 */
141 uint32_t mod_requisites; /**< 30 */
142 uint32_t mod_dependents; /**< 34 DIFF 3 */
143 int32_t mod_loadcnt; /**< 38 */
144 /* DIFF 4: 4 bytes added in v11 */
145 uint32_t mod_text; /**< 3c */
146 uint32_t mod_text_size; /**< 40 */
147 /* DIFF 5: 8 bytes added in v11 */
148} SOL32v9_modctl_t;
149AssertCompileSize(SOL32v9_modctl_t, 0x44);
150
151typedef struct SOL64v9_modctl
152{
153 uint64_t mod_next; /**< 0 */
154 uint64_t mod_prev; /**< 8 */
155 int32_t mod_id; /**< 10 */
156 int32_t mod_padding0;
157 uint64_t mod_mp; /**< 18 Pointer to the kernel runtime loader bits. */
158 uint64_t mod_inprogress_thread; /**< 20 */
159 uint64_t mod_modinfo; /**< 28 */
160 uint64_t mod_linkage; /**< 30 */
161 uint64_t mod_filename; /**< 38 */
162 uint64_t mod_modname; /**< 40 */
163 int32_t mod_busy; /**< 48 */
164 int32_t mod_stub; /**< 4c DIFF 1 - is this a pointer? */
165 int8_t mod_loaded; /**< 50 */
166 int8_t mod_installed; /**< 51 */
167 int8_t mod_loadflags; /**< 52 */
168 int8_t mod_want; /**< 53 DIFF 2 */
169 int32_t mod_padding1;
170 uint64_t mod_requisites; /**< 58 */
171 uint64_t mod_dependencies; /**< 60 DIFF 3 */
172 int32_t mod_loadcnt; /**< 68 */
173 int32_t mod_padding3; /**< 6c DIFF 4 */
174 uint64_t mod_text; /**< 70 */
175 uint64_t mod_text_size; /**< 78 */
176 /* DIFF 5: 8 bytes added in v11 */
177} SOL64v9_modctl_t;
178AssertCompileSize(SOL64v9_modctl_t, 0x80);
179
180typedef union SOL_modctl
181{
182 SOL32v9_modctl_t v9_32;
183 SOL32v11_modctl_t v11_32;
184 SOL64v9_modctl_t v9_64;
185 SOL64v11_modctl_t v11_64;
186} SOL_modctl_t;
187
188/** sys/kobj.h */
189typedef struct SOL32_module
190{
191 int32_t total_allocated; /**< 0 */
192 Elf32_Ehdr hdr; /**< 4 Easy to validate */
193 uint32_t shdrs; /**< 38 */
194 uint32_t symhdr; /**< 3c */
195 uint32_t strhdr; /**< 40 */
196 uint32_t depends_on; /**< 44 */
197 uint32_t symsize; /**< 48 */
198 uint32_t symspace; /**< 4c */
199 int32_t flags; /**< 50 */
200 uint32_t text_size; /**< 54 */
201 uint32_t data_size; /**< 58 */
202 uint32_t text; /**< 5c */
203 uint32_t data; /**< 60 */
204 uint32_t symtbl_section; /**< 64 */
205 uint32_t symtbl; /**< 68 */
206 uint32_t strings; /**< 6c */
207 uint32_t hashsize; /**< 70 */
208 uint32_t buckets; /**< 74 */
209 uint32_t chains; /**< 78 */
210 uint32_t nsyms; /**< 7c */
211 uint32_t bss_align; /**< 80 */
212 uint32_t bss_size; /**< 84 */
213 uint32_t bss; /**< 88 */
214 uint32_t filename; /**< 8c */
215 uint32_t head; /**< 90 */
216 uint32_t tail; /**< 94 */
217 uint32_t destination; /**< 98 */
218 uint32_t machdata; /**< 9c */
219 uint32_t ctfdata; /**< a0 */
220 uint32_t ctfsize; /**< a4 */
221 uint32_t fbt_tab; /**< a8 */
222 uint32_t fbt_size; /**< ac */
223 uint32_t fbt_nentries; /**< b0 */
224 uint32_t textwin; /**< b4 */
225 uint32_t textwin_base; /**< b8 */
226 uint32_t sdt_probes; /**< bc */
227 uint32_t sdt_nprobes; /**< c0 */
228 uint32_t sdt_tab; /**< c4 */
229 uint32_t sdt_size; /**< c8 */
230 uint32_t sigdata; /**< cc */
231 uint32_t sigsize; /**< d0 */
232} SOL32_module_t;
233AssertCompileSize(Elf32_Ehdr, 0x34);
234AssertCompileSize(SOL32_module_t, 0xd4);
235
236typedef struct SOL64_module
237{
238 int32_t total_allocated; /**< 0 */
239 int32_t padding0;
240 Elf64_Ehdr hdr; /**< 8 Easy to validate */
241 uint64_t shdrs; /**< 48 */
242 uint64_t symhdr; /**< 50 */
243 uint64_t strhdr; /**< 58 */
244 uint64_t depends_on; /**< 60 */
245 uint64_t symsize; /**< 68 */
246 uint64_t symspace; /**< 70 */
247 int32_t flags; /**< 78 */
248 int32_t padding1;
249 uint64_t text_size; /**< 80 */
250 uint64_t data_size; /**< 88 */
251 uint64_t text; /**< 90 */
252 uint64_t data; /**< 98 */
253 uint32_t symtbl_section; /**< a0 */
254 int32_t padding2;
255 uint64_t symtbl; /**< a8 */
256 uint64_t strings; /**< b0 */
257 uint32_t hashsize; /**< b8 */
258 int32_t padding3;
259 uint64_t buckets; /**< c0 */
260 uint64_t chains; /**< c8 */
261 uint32_t nsyms; /**< d0 */
262 uint32_t bss_align; /**< d4 */
263 uint64_t bss_size; /**< d8 */
264 uint64_t bss; /**< e0 */
265 uint64_t filename; /**< e8 */
266 uint64_t head; /**< f0 */
267 uint64_t tail; /**< f8 */
268 uint64_t destination; /**< 100 */
269 uint64_t machdata; /**< 108 */
270 uint64_t ctfdata; /**< 110 */
271 uint64_t ctfsize; /**< 118 */
272 uint64_t fbt_tab; /**< 120 */
273 uint64_t fbt_size; /**< 128 */
274 uint64_t fbt_nentries; /**< 130 */
275 uint64_t textwin; /**< 138 */
276 uint64_t textwin_base; /**< 140 */
277 uint64_t sdt_probes; /**< 148 */
278 uint64_t sdt_nprobes; /**< 150 */
279 uint64_t sdt_tab; /**< 158 */
280 uint64_t sdt_size; /**< 160 */
281 uint64_t sigdata; /**< 168 */
282 uint64_t sigsize; /**< 170 */
283} SOL64_module_t;
284AssertCompileSize(Elf64_Ehdr, 0x40);
285AssertCompileSize(SOL64_module_t, 0x178);
286
287typedef struct SOL_utsname
288{
289 char sysname[257];
290 char nodename[257];
291 char release[257];
292 char version[257];
293 char machine[257];
294} SOL_utsname_t;
295AssertCompileSize(SOL_utsname_t, 5 * 257);
296
297/** @} */
298
299
300/**
301 * Solaris guest OS digger instance data.
302 */
303typedef struct DBGDIGGERSOLARIS
304{
305 /** Whether the information is valid or not.
306 * (For fending off illegal interface method calls.) */
307 bool fValid;
308
309 /** Address of the 'unix' text segment.
310 * This is set during probing. */
311 DBGFADDRESS AddrUnixText;
312 /** Address of the 'unix' text segment.
313 * This is set during probing. */
314 DBGFADDRESS AddrUnixData;
315 /** Address of the 'unix' modctl_t (aka modules). */
316 DBGFADDRESS AddrUnixModCtl;
317 /** modctl_t version number. */
318 int iModCtlVer;
319 /** 64-bit/32-bit indicator. */
320 bool f64Bit;
321
322} DBGDIGGERSOLARIS;
323/** Pointer to the solaris guest OS digger instance data. */
324typedef DBGDIGGERSOLARIS *PDBGDIGGERSOLARIS;
325
326
327/*********************************************************************************************************************************
328* Defined Constants And Macros *
329*********************************************************************************************************************************/
330/** Min kernel address. */
331#define SOL32_MIN_KRNL_ADDR UINT32_C(0x80000000)
332/** Max kernel address. */
333#define SOL32_MAX_KRNL_ADDR UINT32_C(0xfffff000)
334
335/** Min kernel address. */
336#define SOL64_MIN_KRNL_ADDR UINT64_C(0xFFFFC00000000000)
337/** Max kernel address. */
338#define SOL64_MAX_KRNL_ADDR UINT64_C(0xFFFFFFFFFFF00000)
339
340
341/** Validates a 32-bit solaris kernel address */
342#if 0 /* OpenSolaris, early boot have symspace at 0x27a2000 */
343# define SOL32_VALID_ADDRESS(Addr) ((Addr) > SOL32_MIN_KRNL_ADDR && (Addr) < SOL32_MAX_KRNL_ADDR)
344#else
345# define SOL32_VALID_ADDRESS(Addr) ( ((Addr) > SOL32_MIN_KRNL_ADDR && (Addr) < SOL32_MAX_KRNL_ADDR) \
346 || ((Addr) > UINT32_C(0x02000000) && (Addr) < UINT32_C(0x04000000)) /* boot */ )
347#endif
348
349/** Validates a 64-bit solaris kernel address */
350#define SOL64_VALID_ADDRESS(Addr) ( (Addr) > SOL64_MIN_KRNL_ADDR \
351 && (Addr) < SOL64_MAX_KRNL_ADDR)
352
353/** The max data segment size of the 'unix' module. */
354#define SOL_UNIX_MAX_DATA_SEG_SIZE 0x01000000
355
356/** The max code segment size of the 'unix' module.
357 * This is the same for both 64-bit and 32-bit. */
358#define SOL_UNIX_MAX_CODE_SEG_SIZE 0x00400000
359
360
361/*********************************************************************************************************************************
362* Internal Functions *
363*********************************************************************************************************************************/
364static DECLCALLBACK(int) dbgDiggerSolarisInit(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData);
365
366
367
368/**
369 * @copydoc DBGFOSREG::pfnStackUnwindAssist
370 */
371static DECLCALLBACK(int) dbgDiggerSolarisStackUnwindAssist(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData, VMCPUID idCpu,
372 PDBGFSTACKFRAME pFrame, PRTDBGUNWINDSTATE pState,
373 PCCPUMCTX pInitialCtx, RTDBGAS hAs, uint64_t *puScratch)
374{
375 RT_NOREF(pUVM, pVMM, pvData, idCpu, pFrame, pState, pInitialCtx, hAs, puScratch);
376 return VINF_SUCCESS;
377}
378
379
380/**
381 * @copydoc DBGFOSREG::pfnQueryInterface
382 */
383static DECLCALLBACK(void *) dbgDiggerSolarisQueryInterface(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData, DBGFOSINTERFACE enmIf)
384{
385 RT_NOREF(pUVM, pVMM, pvData, enmIf);
386 return NULL;
387}
388
389
390/**
391 * @copydoc DBGFOSREG::pfnQueryVersion
392 */
393static DECLCALLBACK(int) dbgDiggerSolarisQueryVersion(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData,
394 char *pszVersion, size_t cchVersion)
395{
396 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
397 Assert(pThis->fValid);
398
399 /*
400 * It's all in the utsname symbol...
401 */
402 SOL_utsname_t UtsName;
403 RT_ZERO(UtsName); /* Make MSC happy. */
404 DBGFADDRESS Addr;
405 RTDBGSYMBOL SymUtsName;
406 int rc = pVMM->pfnDBGFR3AsSymbolByName(pUVM, DBGF_AS_KERNEL, "utsname", &SymUtsName, NULL);
407 if (RT_SUCCESS(rc))
408 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, SymUtsName.Value),
409 &UtsName, sizeof(UtsName));
410 if (RT_FAILURE(rc))
411 {
412 /*
413 * Try searching by the name...
414 */
415 memset(&UtsName, '\0', sizeof(UtsName));
416 strcpy(&UtsName.sysname[0], "SunOS");
417 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &pThis->AddrUnixData, SOL_UNIX_MAX_DATA_SEG_SIZE, 1,
418 &UtsName.sysname[0], sizeof(UtsName.sysname), &Addr);
419 if (RT_SUCCESS(rc))
420 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr,
421 Addr.FlatPtr - RT_OFFSETOF(SOL_utsname_t, sysname)),
422 &UtsName, sizeof(UtsName));
423 }
424
425 /*
426 * Copy out the result (if any).
427 */
428 if (RT_SUCCESS(rc))
429 {
430 if ( UtsName.sysname[sizeof(UtsName.sysname) - 1] != '\0'
431 || UtsName.nodename[sizeof(UtsName.nodename) - 1] != '\0'
432 || UtsName.release[sizeof(UtsName.release) - 1] != '\0'
433 || UtsName.version[sizeof(UtsName.version) - 1] != '\0'
434 || UtsName.machine[sizeof(UtsName.machine) - 1] != '\0')
435 {
436 //rc = VERR_DBGF_UNEXPECTED_OS_DATA;
437 rc = VERR_GENERAL_FAILURE;
438 RTStrPrintf(pszVersion, cchVersion, "failed - bogus utsname");
439 }
440 else
441 RTStrPrintf(pszVersion, cchVersion, "%s %s", UtsName.version, UtsName.release);
442 }
443 else
444 RTStrPrintf(pszVersion, cchVersion, "failed - %Rrc", rc);
445
446 return rc;
447}
448
449
450
451/**
452 * Processes a modctl_t.
453 *
454 * @param pUVM The user mode VM handle.
455 * @param pVMM The VMM function table.
456 * @param pThis Our instance data.
457 * @param pModCtl Pointer to the modctl structure.
458 */
459static void dbgDiggerSolarisProcessModCtl32(PUVM pUVM, PCVMMR3VTABLE pVMM, PDBGDIGGERSOLARIS pThis, SOL_modctl_t const *pModCtl)
460{
461 RT_NOREF1(pThis);
462
463 /* skip it if it's not loaded and installed */
464 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_loaded, v9_32.mod_loaded);
465 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_installed, v9_32.mod_installed);
466 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_id, v9_32.mod_id);
467 if ( ( !pModCtl->v9_32.mod_loaded
468 || !pModCtl->v9_32.mod_installed)
469 && pModCtl->v9_32.mod_id > 3)
470 return;
471
472 /*
473 * Read the module and file names first
474 */
475 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_modname, v9_32.mod_modname);
476 char szModName[64];
477 DBGFADDRESS Addr;
478 int rc = pVMM->pfnDBGFR3MemReadString(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_32.mod_modname),
479 szModName, sizeof(szModName));
480 if (RT_FAILURE(rc))
481 return;
482 if (!RTStrEnd(szModName, sizeof(szModName)))
483 szModName[sizeof(szModName) - 1] = '\0';
484
485 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_filename, v9_32.mod_filename);
486 char szFilename[256];
487 rc = pVMM->pfnDBGFR3MemReadString(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_32.mod_filename),
488 szFilename, sizeof(szFilename));
489 if (RT_FAILURE(rc))
490 strcpy(szFilename, szModName);
491 else if (!RTStrEnd(szFilename, sizeof(szFilename)))
492 szFilename[sizeof(szFilename) - 1] = '\0';
493
494 /*
495 * Then read the module struct and validate it.
496 */
497 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_mp, v9_32.mod_mp);
498 struct SOL32_module Module;
499 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_32.mod_mp), &Module, sizeof(Module));
500 if (RT_FAILURE(rc))
501 return;
502
503 /* Basic validations of the elf header. */
504 if ( Module.hdr.e_ident[EI_MAG0] != ELFMAG0
505 || Module.hdr.e_ident[EI_MAG1] != ELFMAG1
506 || Module.hdr.e_ident[EI_MAG2] != ELFMAG2
507 || Module.hdr.e_ident[EI_MAG3] != ELFMAG3
508 || Module.hdr.e_ident[EI_CLASS] != ELFCLASS32
509 || Module.hdr.e_ident[EI_DATA] != ELFDATA2LSB
510 || Module.hdr.e_ident[EI_VERSION] != EV_CURRENT
511 || !ASMMemIsZero(&Module.hdr.e_ident[EI_PAD], EI_NIDENT - EI_PAD)
512 )
513 return;
514 if (Module.hdr.e_version != EV_CURRENT)
515 return;
516 if (Module.hdr.e_ehsize != sizeof(Module.hdr))
517 return;
518 if ( Module.hdr.e_type != ET_DYN
519 && Module.hdr.e_type != ET_REL
520 && Module.hdr.e_type != ET_EXEC) //??
521 return;
522 if ( Module.hdr.e_machine != EM_386
523 && Module.hdr.e_machine != EM_486)
524 return;
525 if ( Module.hdr.e_phentsize != sizeof(Elf32_Phdr)
526 && Module.hdr.e_phentsize) //??
527 return;
528 if (Module.hdr.e_shentsize != sizeof(Elf32_Shdr))
529 return;
530
531 if (Module.hdr.e_shentsize != sizeof(Elf32_Shdr))
532 return;
533
534 /* Basic validations of the rest of the stuff. */
535 if ( !SOL32_VALID_ADDRESS(Module.shdrs)
536 || !SOL32_VALID_ADDRESS(Module.symhdr)
537 || !SOL32_VALID_ADDRESS(Module.strhdr)
538 || (!SOL32_VALID_ADDRESS(Module.symspace) && Module.symspace)
539 || !SOL32_VALID_ADDRESS(Module.text)
540 || !SOL32_VALID_ADDRESS(Module.data)
541 || (!SOL32_VALID_ADDRESS(Module.symtbl) && Module.symtbl)
542 || (!SOL32_VALID_ADDRESS(Module.strings) && Module.strings)
543 || (!SOL32_VALID_ADDRESS(Module.head) && Module.head)
544 || (!SOL32_VALID_ADDRESS(Module.tail) && Module.tail)
545 || !SOL32_VALID_ADDRESS(Module.filename))
546 return;
547 if ( Module.symsize > _4M
548 || Module.hdr.e_shnum > 4096
549 || Module.nsyms > _256K)
550 return;
551
552 /* Ignore modules without symbols. */
553 if (!Module.symtbl || !Module.strings || !Module.symspace || !Module.symsize)
554 return;
555
556 /* Check that the symtbl and strings points inside the symspace. */
557 if (Module.strings - Module.symspace >= Module.symsize)
558 return;
559 if (Module.symtbl - Module.symspace >= Module.symsize)
560 return;
561
562 /*
563 * Read the section headers, symbol table and string tables.
564 */
565 size_t cb = Module.hdr.e_shnum * sizeof(Elf32_Shdr);
566 Elf32_Shdr *paShdrs = (Elf32_Shdr *)RTMemTmpAlloc(cb);
567 if (!paShdrs)
568 return;
569 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.shdrs), paShdrs, cb);
570 if (RT_SUCCESS(rc))
571 {
572 void *pvSymSpace = RTMemTmpAlloc(Module.symsize + 1);
573 if (pvSymSpace)
574 {
575 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.symspace),
576 pvSymSpace, Module.symsize);
577 if (RT_SUCCESS(rc))
578 {
579 ((uint8_t *)pvSymSpace)[Module.symsize] = 0;
580
581 /*
582 * Hand it over to the common ELF32 module parser.
583 */
584 char const *pbStrings = (char const *)pvSymSpace + (Module.strings - Module.symspace);
585 size_t cbMaxStrings = Module.symsize - (Module.strings - Module.symspace);
586
587 Elf32_Sym const *paSyms = (Elf32_Sym const *)((uintptr_t)pvSymSpace + (Module.symtbl - Module.symspace));
588 size_t cMaxSyms = (Module.symsize - (Module.symtbl - Module.symspace)) / sizeof(Elf32_Sym);
589 cMaxSyms = RT_MIN(cMaxSyms, Module.nsyms);
590
591 DBGDiggerCommonParseElf32Mod(pUVM, pVMM, szModName, szFilename, DBG_DIGGER_ELF_FUNNY_SHDRS,
592 &Module.hdr, paShdrs, paSyms, cMaxSyms, pbStrings, cbMaxStrings,
593 SOL32_MIN_KRNL_ADDR, SOL32_MAX_KRNL_ADDR - 1, DIG_SOL_MOD_TAG);
594 }
595 RTMemTmpFree(pvSymSpace);
596 }
597 }
598
599 RTMemTmpFree(paShdrs);
600 return;
601}
602
603
604/**
605 * Processes a modctl_t.
606 *
607 * @param pUVM The user mode VM handle.
608 * @param pVMM The VMM function table.
609 * @param pThis Our instance data.
610 * @param pModCtl Pointer to the modctl structure.
611 */
612static void dbgDiggerSolarisProcessModCtl64(PUVM pUVM, PCVMMR3VTABLE pVMM, PDBGDIGGERSOLARIS pThis, SOL_modctl_t const *pModCtl)
613{
614 RT_NOREF1(pThis);
615
616 /* skip it if it's not loaded and installed */
617 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_loaded, v9_64.mod_loaded);
618 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_installed, v9_64.mod_installed);
619 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_id, v9_64.mod_id);
620 if ( ( !pModCtl->v9_64.mod_loaded
621 || !pModCtl->v9_64.mod_installed)
622 && pModCtl->v9_64.mod_id > 3)
623 return;
624
625 /*
626 * Read the module and file names first
627 */
628 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_modname, v9_64.mod_modname);
629 char szModName[64];
630 DBGFADDRESS Addr;
631 int rc = pVMM->pfnDBGFR3MemReadString(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_64.mod_modname),
632 szModName, sizeof(szModName));
633 if (RT_FAILURE(rc))
634 return;
635 if (!RTStrEnd(szModName, sizeof(szModName)))
636 szModName[sizeof(szModName) - 1] = '\0';
637
638 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_filename, v9_64.mod_filename);
639 char szFilename[256];
640 rc = pVMM->pfnDBGFR3MemReadString(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_64.mod_filename),
641 szFilename, sizeof(szFilename));
642 if (RT_FAILURE(rc))
643 strcpy(szFilename, szModName);
644 else if (!RTStrEnd(szFilename, sizeof(szFilename)))
645 szFilename[sizeof(szFilename) - 1] = '\0';
646
647 /*
648 * Then read the module struct and validate it.
649 */
650 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_mp, v9_64.mod_mp);
651 struct SOL64_module Module;
652 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_64.mod_mp), &Module, sizeof(Module));
653 if (RT_FAILURE(rc))
654 return;
655
656 /* Basic validations of the elf header. */
657 if ( Module.hdr.e_ident[EI_MAG0] != ELFMAG0
658 || Module.hdr.e_ident[EI_MAG1] != ELFMAG1
659 || Module.hdr.e_ident[EI_MAG2] != ELFMAG2
660 || Module.hdr.e_ident[EI_MAG3] != ELFMAG3
661 || Module.hdr.e_ident[EI_CLASS] != ELFCLASS64
662 || Module.hdr.e_ident[EI_DATA] != ELFDATA2LSB
663 || Module.hdr.e_ident[EI_VERSION] != EV_CURRENT
664 || !ASMMemIsZero(&Module.hdr.e_ident[EI_PAD], EI_NIDENT - EI_PAD)
665 )
666 return;
667 if (Module.hdr.e_version != EV_CURRENT)
668 return;
669 if (Module.hdr.e_ehsize != sizeof(Module.hdr))
670 return;
671 if ( Module.hdr.e_type != ET_DYN
672 && Module.hdr.e_type != ET_REL
673 && Module.hdr.e_type != ET_EXEC) //??
674 return;
675 if (Module.hdr.e_machine != EM_X86_64)
676 return;
677 if ( Module.hdr.e_phentsize != sizeof(Elf64_Phdr)
678 && Module.hdr.e_phentsize) //??
679 return;
680 if (Module.hdr.e_shentsize != sizeof(Elf64_Shdr))
681 return;
682
683 if (Module.hdr.e_shentsize != sizeof(Elf64_Shdr))
684 return;
685
686 /* Basic validations of the rest of the stuff. */
687 if ( !SOL64_VALID_ADDRESS(Module.shdrs)
688 || !SOL64_VALID_ADDRESS(Module.symhdr)
689 || !SOL64_VALID_ADDRESS(Module.strhdr)
690 || (!SOL64_VALID_ADDRESS(Module.symspace) && Module.symspace)
691 || !SOL64_VALID_ADDRESS(Module.text)
692 || !SOL64_VALID_ADDRESS(Module.data)
693 || (!SOL64_VALID_ADDRESS(Module.symtbl) && Module.symtbl)
694 || (!SOL64_VALID_ADDRESS(Module.strings) && Module.strings)
695 || (!SOL64_VALID_ADDRESS(Module.head) && Module.head)
696 || (!SOL64_VALID_ADDRESS(Module.tail) && Module.tail)
697 || !SOL64_VALID_ADDRESS(Module.filename))
698 return;
699 if ( Module.symsize > _4M
700 || Module.hdr.e_shnum > 4096
701 || Module.nsyms > _256K)
702 return;
703
704 /* Ignore modules without symbols. */
705 if (!Module.symtbl || !Module.strings || !Module.symspace || !Module.symsize)
706 return;
707
708 /* Check that the symtbl and strings points inside the symspace. */
709 if (Module.strings - Module.symspace >= Module.symsize)
710 return;
711 if (Module.symtbl - Module.symspace >= Module.symsize)
712 return;
713
714 /*
715 * Read the section headers, symbol table and string tables.
716 */
717 size_t cb = Module.hdr.e_shnum * sizeof(Elf64_Shdr);
718 Elf64_Shdr *paShdrs = (Elf64_Shdr *)RTMemTmpAlloc(cb);
719 if (!paShdrs)
720 return;
721 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.shdrs), paShdrs, cb);
722 if (RT_SUCCESS(rc))
723 {
724 void *pvSymSpace = RTMemTmpAlloc(Module.symsize + 1);
725 if (pvSymSpace)
726 {
727 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.symspace),
728 pvSymSpace, Module.symsize);
729 if (RT_SUCCESS(rc))
730 {
731 ((uint8_t *)pvSymSpace)[Module.symsize] = 0;
732
733 /*
734 * Hand it over to the common ELF64 module parser.
735 */
736 char const *pbStrings = (char const *)pvSymSpace + (Module.strings - Module.symspace);
737 size_t cbMaxStrings = Module.symsize - (Module.strings - Module.symspace);
738
739 Elf64_Sym const *paSyms = (Elf64_Sym const *)((uintptr_t)pvSymSpace + (uintptr_t)(Module.symtbl - Module.symspace));
740 size_t cMaxSyms = (Module.symsize - (Module.symtbl - Module.symspace)) / sizeof(Elf32_Sym);
741 cMaxSyms = RT_MIN(cMaxSyms, Module.nsyms);
742
743 DBGDiggerCommonParseElf64Mod(pUVM, pVMM, szModName, szFilename, DBG_DIGGER_ELF_FUNNY_SHDRS,
744 &Module.hdr, paShdrs, paSyms, cMaxSyms, pbStrings, cbMaxStrings,
745 SOL64_MIN_KRNL_ADDR, SOL64_MAX_KRNL_ADDR - 1, DIG_SOL_MOD_TAG);
746 }
747 RTMemTmpFree(pvSymSpace);
748 }
749 }
750
751 RTMemTmpFree(paShdrs);
752 return;
753}
754
755
756/**
757 * @copydoc DBGFOSREG::pfnTerm
758 */
759static DECLCALLBACK(void) dbgDiggerSolarisTerm(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
760{
761 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
762 RT_NOREF(pUVM, pVMM);
763 Assert(pThis->fValid);
764
765 pThis->fValid = false;
766}
767
768
769/**
770 * @copydoc DBGFOSREG::pfnRefresh
771 */
772static DECLCALLBACK(int) dbgDiggerSolarisRefresh(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
773{
774 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
775 RT_NOREF(pThis);
776 Assert(pThis->fValid);
777
778 /*
779 * For now we'll flush and reload everything.
780 */
781 RTDBGAS hDbgAs = pVMM->pfnDBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
782 if (hDbgAs != NIL_RTDBGAS)
783 {
784 uint32_t iMod = RTDbgAsModuleCount(hDbgAs);
785 while (iMod-- > 0)
786 {
787 RTDBGMOD hMod = RTDbgAsModuleByIndex(hDbgAs, iMod);
788 if (hMod != NIL_RTDBGMOD)
789 {
790 if (RTDbgModGetTag(hMod) == DIG_SOL_MOD_TAG)
791 {
792 int rc = RTDbgAsModuleUnlink(hDbgAs, hMod);
793 AssertRC(rc);
794 }
795 RTDbgModRelease(hMod);
796 }
797 }
798 RTDbgAsRelease(hDbgAs);
799 }
800
801 dbgDiggerSolarisTerm(pUVM, pVMM, pvData);
802 return dbgDiggerSolarisInit(pUVM, pVMM, pvData);
803}
804
805
806/**
807 * @copydoc DBGFOSREG::pfnInit
808 */
809static DECLCALLBACK(int) dbgDiggerSolarisInit(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
810{
811 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
812 Assert(!pThis->fValid);
813 int rc;
814 size_t cbModCtl = 0;
815
816 /*
817 * On Solaris the kernel and is the global address space.
818 */
819 pVMM->pfnDBGFR3AsSetAlias(pUVM, DBGF_AS_KERNEL, DBGF_AS_GLOBAL);
820
821/** @todo Use debug_info, build 7x / S10U6. */
822
823 /*
824 * Find the 'unix' modctl_t structure (aka modules).
825 * We know it resides in the unix data segment.
826 */
827 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &pThis->AddrUnixModCtl, 0);
828
829 DBGFADDRESS CurAddr = pThis->AddrUnixData;
830 DBGFADDRESS MaxAddr;
831 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &MaxAddr, CurAddr.FlatPtr + SOL_UNIX_MAX_DATA_SEG_SIZE);
832 const uint8_t *pbExpr = (const uint8_t *)&pThis->AddrUnixText.FlatPtr;
833 const uint32_t cbExpr = pThis->f64Bit ? sizeof(uint64_t) : sizeof(uint32_t);
834 while ( CurAddr.FlatPtr < MaxAddr.FlatPtr
835 && CurAddr.FlatPtr >= pThis->AddrUnixData.FlatPtr)
836 {
837 DBGFADDRESS HitAddr;
838 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &CurAddr, MaxAddr.FlatPtr - CurAddr.FlatPtr, 1, pbExpr, cbExpr, &HitAddr);
839 if (RT_FAILURE(rc))
840 break;
841
842 /*
843 * Read out the modctl_t structure.
844 */
845 DBGFADDRESS ModCtlAddr;
846
847 /* v11 */
848 if (pThis->f64Bit)
849 {
850 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32v11_modctl_t, mod_text));
851 SOL64v11_modctl_t ModCtlv11;
852 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv11, sizeof(ModCtlv11));
853 if (RT_SUCCESS(rc))
854 {
855 if ( SOL64_VALID_ADDRESS(ModCtlv11.mod_next)
856 && SOL64_VALID_ADDRESS(ModCtlv11.mod_prev)
857 && ModCtlv11.mod_id == 0
858 && SOL64_VALID_ADDRESS(ModCtlv11.mod_mp)
859 && SOL64_VALID_ADDRESS(ModCtlv11.mod_filename)
860 && SOL64_VALID_ADDRESS(ModCtlv11.mod_modname)
861 && ModCtlv11.mod_prim == 1
862 && ModCtlv11.mod_loaded == 1
863 && ModCtlv11.mod_installed == 1
864 && ModCtlv11.mod_requisites == 0
865 && ModCtlv11.mod_loadcnt == 1
866 /*&& ModCtlv11.mod_text == pThis->AddrUnixText.FlatPtr*/
867 && ModCtlv11.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE
868 && ModCtlv11.mod_text_size >= _128K)
869 {
870 char szUnix[5];
871 DBGFADDRESS NameAddr;
872 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv11.mod_modname);
873 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
874 if (RT_SUCCESS(rc))
875 {
876 if (!strcmp(szUnix, "unix"))
877 {
878 pThis->AddrUnixModCtl = ModCtlAddr;
879 pThis->iModCtlVer = 11;
880 cbModCtl = sizeof(ModCtlv11);
881 break;
882 }
883 Log(("sol64 mod_name=%.*s v11\n", sizeof(szUnix), szUnix));
884 }
885 }
886 }
887 }
888 else
889 {
890 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32v11_modctl_t, mod_text));
891 SOL32v11_modctl_t ModCtlv11;
892 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv11, sizeof(ModCtlv11));
893 if (RT_SUCCESS(rc))
894 {
895 if ( SOL32_VALID_ADDRESS(ModCtlv11.mod_next)
896 && SOL32_VALID_ADDRESS(ModCtlv11.mod_prev)
897 && ModCtlv11.mod_id == 0
898 && SOL32_VALID_ADDRESS(ModCtlv11.mod_mp)
899 && SOL32_VALID_ADDRESS(ModCtlv11.mod_filename)
900 && SOL32_VALID_ADDRESS(ModCtlv11.mod_modname)
901 && ModCtlv11.mod_prim == 1
902 && ModCtlv11.mod_loaded == 1
903 && ModCtlv11.mod_installed == 1
904 && ModCtlv11.mod_requisites == 0
905 && ModCtlv11.mod_loadcnt == 1
906 /*&& ModCtlv11.mod_text == pThis->AddrUnixText.FlatPtr*/
907 && ModCtlv11.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE
908 && ModCtlv11.mod_text_size >= _128K)
909 {
910 char szUnix[5];
911 DBGFADDRESS NameAddr;
912 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv11.mod_modname);
913 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
914 if (RT_SUCCESS(rc))
915 {
916 if (!strcmp(szUnix, "unix"))
917 {
918 pThis->AddrUnixModCtl = ModCtlAddr;
919 pThis->iModCtlVer = 11;
920 cbModCtl = sizeof(ModCtlv11);
921 break;
922 }
923 Log(("sol32 mod_name=%.*s v11\n", sizeof(szUnix), szUnix));
924 }
925 }
926 }
927 }
928
929 /* v9 */
930 if (pThis->f64Bit)
931 {
932 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL64v9_modctl_t, mod_text));
933 SOL64v9_modctl_t ModCtlv9;
934 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv9, sizeof(ModCtlv9));
935 if (RT_SUCCESS(rc))
936 {
937 if ( SOL64_VALID_ADDRESS(ModCtlv9.mod_next)
938 && SOL64_VALID_ADDRESS(ModCtlv9.mod_prev)
939 && ModCtlv9.mod_id == 0
940 && SOL64_VALID_ADDRESS(ModCtlv9.mod_mp)
941 && SOL64_VALID_ADDRESS(ModCtlv9.mod_filename)
942 && SOL64_VALID_ADDRESS(ModCtlv9.mod_modname)
943 && (ModCtlv9.mod_loaded == 1 || ModCtlv9.mod_loaded == 0)
944 && (ModCtlv9.mod_installed == 1 || ModCtlv9.mod_installed == 0)
945 && ModCtlv9.mod_requisites == 0
946 && (ModCtlv9.mod_loadcnt == 1 || ModCtlv9.mod_loadcnt == 0)
947 /*&& ModCtlv9.mod_text == pThis->AddrUnixText.FlatPtr*/
948 && ModCtlv9.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE)
949 {
950 char szUnix[5];
951 DBGFADDRESS NameAddr;
952 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv9.mod_modname);
953 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
954 if (RT_SUCCESS(rc))
955 {
956 if (!strcmp(szUnix, "unix"))
957 {
958 pThis->AddrUnixModCtl = ModCtlAddr;
959 pThis->iModCtlVer = 9;
960 cbModCtl = sizeof(ModCtlv9);
961 break;
962 }
963 Log(("sol64 mod_name=%.*s v9\n", sizeof(szUnix), szUnix));
964 }
965 }
966 }
967 }
968 else
969 {
970 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32v9_modctl_t, mod_text));
971 SOL32v9_modctl_t ModCtlv9;
972 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv9, sizeof(ModCtlv9));
973 if (RT_SUCCESS(rc))
974 {
975 if ( SOL32_VALID_ADDRESS(ModCtlv9.mod_next)
976 && SOL32_VALID_ADDRESS(ModCtlv9.mod_prev)
977 && ModCtlv9.mod_id == 0
978 && SOL32_VALID_ADDRESS(ModCtlv9.mod_mp)
979 && SOL32_VALID_ADDRESS(ModCtlv9.mod_filename)
980 && SOL32_VALID_ADDRESS(ModCtlv9.mod_modname)
981 && (ModCtlv9.mod_loaded == 1 || ModCtlv9.mod_loaded == 0)
982 && (ModCtlv9.mod_installed == 1 || ModCtlv9.mod_installed == 0)
983 && ModCtlv9.mod_requisites == 0
984 && (ModCtlv9.mod_loadcnt == 1 || ModCtlv9.mod_loadcnt == 0)
985 /*&& ModCtlv9.mod_text == pThis->AddrUnixText.FlatPtr*/
986 && ModCtlv9.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE )
987 {
988 char szUnix[5];
989 DBGFADDRESS NameAddr;
990 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv9.mod_modname);
991 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
992 if (RT_SUCCESS(rc))
993 {
994 if (!strcmp(szUnix, "unix"))
995 {
996 pThis->AddrUnixModCtl = ModCtlAddr;
997 pThis->iModCtlVer = 9;
998 cbModCtl = sizeof(ModCtlv9);
999 break;
1000 }
1001 Log(("sol32 mod_name=%.*s v9\n", sizeof(szUnix), szUnix));
1002 }
1003 }
1004 }
1005 }
1006
1007 /* next */
1008 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &CurAddr, HitAddr.FlatPtr + cbExpr);
1009 }
1010
1011 /*
1012 * Walk the module chain and add the modules and their symbols.
1013 */
1014 if (pThis->AddrUnixModCtl.FlatPtr)
1015 {
1016 int iMod = 0;
1017 CurAddr = pThis->AddrUnixModCtl;
1018 do
1019 {
1020 /* read it */
1021 SOL_modctl_t ModCtl;
1022 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &CurAddr, &ModCtl, cbModCtl);
1023 if (RT_FAILURE(rc))
1024 {
1025 LogRel(("sol: bad modctl_t chain for module %d: %RGv - %Rrc\n", iMod, CurAddr.FlatPtr, rc));
1026 break;
1027 }
1028
1029 /* process it. */
1030 if (pThis->f64Bit)
1031 dbgDiggerSolarisProcessModCtl64(pUVM, pVMM, pThis, &ModCtl);
1032 else
1033 dbgDiggerSolarisProcessModCtl32(pUVM, pVMM, pThis, &ModCtl);
1034
1035 /* next */
1036 if (pThis->f64Bit)
1037 {
1038 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_next, v9_64.mod_next);
1039 if (!SOL64_VALID_ADDRESS(ModCtl.v9_64.mod_next))
1040 {
1041 LogRel(("sol64: bad modctl_t chain for module %d at %RGv: %RGv\n", iMod, CurAddr.FlatPtr, (RTGCUINTPTR)ModCtl.v9_64.mod_next));
1042 break;
1043 }
1044 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &CurAddr, ModCtl.v9_64.mod_next);
1045 }
1046 else
1047 {
1048 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_next, v9_32.mod_next);
1049 if (!SOL32_VALID_ADDRESS(ModCtl.v9_32.mod_next))
1050 {
1051 LogRel(("sol32: bad modctl_t chain for module %d at %RGv: %RGv\n", iMod, CurAddr.FlatPtr, (RTGCUINTPTR)ModCtl.v9_32.mod_next));
1052 break;
1053 }
1054 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &CurAddr, ModCtl.v9_32.mod_next);
1055 }
1056 if (++iMod >= 1024)
1057 {
1058 LogRel(("sol32: too many modules (%d)\n", iMod));
1059 break;
1060 }
1061 } while (CurAddr.FlatPtr != pThis->AddrUnixModCtl.FlatPtr);
1062 }
1063
1064 pThis->fValid = true;
1065 return VINF_SUCCESS;
1066}
1067
1068
1069/**
1070 * @copydoc DBGFOSREG::pfnProbe
1071 */
1072static DECLCALLBACK(bool) dbgDiggerSolarisProbe(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1073{
1074 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
1075
1076 /*
1077 * Look for "SunOS Release" in the text segment.
1078 */
1079 DBGFADDRESS Addr;
1080 bool f64Bit = false;
1081
1082 /* 32-bit search range. */
1083 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, 0xfe800000);
1084 RTGCUINTPTR cbRange = 0xfec00000 - 0xfe800000;
1085
1086 DBGFADDRESS HitAddr;
1087 static const uint8_t s_abSunRelease[] = "SunOS Release ";
1088 int rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abSunRelease, sizeof(s_abSunRelease) - 1, &HitAddr);
1089 if (RT_FAILURE(rc))
1090 {
1091 /* 64-bit.... */
1092 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, UINT64_C(0xfffffffffb800000));
1093 cbRange = UINT64_C(0xfffffffffbd00000) - UINT64_C(0xfffffffffb800000);
1094 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abSunRelease, sizeof(s_abSunRelease) - 1, &HitAddr);
1095 if (RT_FAILURE(rc))
1096 return false;
1097 f64Bit = true;
1098 }
1099
1100 /*
1101 * Look for the copyright string too, just to be sure.
1102 */
1103 static const uint8_t s_abSMI[] = "Sun Microsystems, Inc.";
1104 static const uint8_t s_abORCL[] = "Oracle and/or its affiliates.";
1105 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abSMI, sizeof(s_abSMI) - 1, &HitAddr);
1106 if (RT_FAILURE(rc))
1107 {
1108 /* Try the alternate copyright string. */
1109 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abORCL, sizeof(s_abORCL) - 1, &HitAddr);
1110 if (RT_FAILURE(rc))
1111 return false;
1112 }
1113
1114 /*
1115 * Remember the unix text and data addresses and bitness.
1116 */
1117 pThis->AddrUnixText = Addr;
1118 pVMM->pfnDBGFR3AddrAdd(&Addr, SOL_UNIX_MAX_CODE_SEG_SIZE);
1119 pThis->AddrUnixData = Addr;
1120 pThis->f64Bit = f64Bit;
1121
1122 return true;
1123}
1124
1125
1126/**
1127 * @copydoc DBGFOSREG::pfnDestruct
1128 */
1129static DECLCALLBACK(void) dbgDiggerSolarisDestruct(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1130{
1131 RT_NOREF(pUVM, pVMM, pvData);
1132}
1133
1134
1135/**
1136 * @copydoc DBGFOSREG::pfnConstruct
1137 */
1138static DECLCALLBACK(int) dbgDiggerSolarisConstruct(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1139{
1140 RT_NOREF(pUVM, pVMM, pvData);
1141 return VINF_SUCCESS;
1142}
1143
1144
1145const DBGFOSREG g_DBGDiggerSolaris =
1146{
1147 /* .u32Magic = */ DBGFOSREG_MAGIC,
1148 /* .fFlags = */ 0,
1149 /* .cbData = */ sizeof(DBGDIGGERSOLARIS),
1150 /* .szName = */ "Solaris",
1151 /* .pfnConstruct = */ dbgDiggerSolarisConstruct,
1152 /* .pfnDestruct = */ dbgDiggerSolarisDestruct,
1153 /* .pfnProbe = */ dbgDiggerSolarisProbe,
1154 /* .pfnInit = */ dbgDiggerSolarisInit,
1155 /* .pfnRefresh = */ dbgDiggerSolarisRefresh,
1156 /* .pfnTerm = */ dbgDiggerSolarisTerm,
1157 /* .pfnQueryVersion = */ dbgDiggerSolarisQueryVersion,
1158 /* .pfnQueryInterface = */ dbgDiggerSolarisQueryInterface,
1159 /* .pfnStackUnwindAssist = */ dbgDiggerSolarisStackUnwindAssist,
1160 /* .u32EndMagic = */ DBGFOSREG_MAGIC
1161};
1162
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