VirtualBox

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

Last change on this file since 107044 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 46.7 KB
Line 
1/* $Id: DBGPlugInSolaris.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * DBGPlugInSolaris - Debugger and Guest OS Digger Plugin For Solaris.
4 */
5
6/*
7 * Copyright (C) 2008-2024 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 /* Basic validations of the rest of the stuff. */
532 if ( !SOL32_VALID_ADDRESS(Module.shdrs)
533 || !SOL32_VALID_ADDRESS(Module.symhdr)
534 || !SOL32_VALID_ADDRESS(Module.strhdr)
535 || (!SOL32_VALID_ADDRESS(Module.symspace) && Module.symspace)
536 || !SOL32_VALID_ADDRESS(Module.text)
537 || !SOL32_VALID_ADDRESS(Module.data)
538 || (!SOL32_VALID_ADDRESS(Module.symtbl) && Module.symtbl)
539 || (!SOL32_VALID_ADDRESS(Module.strings) && Module.strings)
540 || (!SOL32_VALID_ADDRESS(Module.head) && Module.head)
541 || (!SOL32_VALID_ADDRESS(Module.tail) && Module.tail)
542 || !SOL32_VALID_ADDRESS(Module.filename))
543 return;
544 if ( Module.symsize > _4M
545 || Module.hdr.e_shnum > 4096
546 || Module.nsyms > _256K)
547 return;
548
549 /* Ignore modules without symbols. */
550 if (!Module.symtbl || !Module.strings || !Module.symspace || !Module.symsize)
551 return;
552
553 /* Check that the symtbl and strings points inside the symspace. */
554 if (Module.strings - Module.symspace >= Module.symsize)
555 return;
556 if (Module.symtbl - Module.symspace >= Module.symsize)
557 return;
558
559 /*
560 * Read the section headers, symbol table and string tables.
561 */
562 size_t cb = Module.hdr.e_shnum * sizeof(Elf32_Shdr);
563 Elf32_Shdr *paShdrs = (Elf32_Shdr *)RTMemTmpAlloc(cb);
564 if (!paShdrs)
565 return;
566 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.shdrs), paShdrs, cb);
567 if (RT_SUCCESS(rc))
568 {
569 void *pvSymSpace = RTMemTmpAlloc(Module.symsize + 1);
570 if (pvSymSpace)
571 {
572 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.symspace),
573 pvSymSpace, Module.symsize);
574 if (RT_SUCCESS(rc))
575 {
576 ((uint8_t *)pvSymSpace)[Module.symsize] = 0;
577
578 /*
579 * Hand it over to the common ELF32 module parser.
580 */
581 char const *pbStrings = (char const *)pvSymSpace + (Module.strings - Module.symspace);
582 size_t cbMaxStrings = Module.symsize - (Module.strings - Module.symspace);
583
584 Elf32_Sym const *paSyms = (Elf32_Sym const *)((uintptr_t)pvSymSpace + (Module.symtbl - Module.symspace));
585 size_t cMaxSyms = (Module.symsize - (Module.symtbl - Module.symspace)) / sizeof(Elf32_Sym);
586 cMaxSyms = RT_MIN(cMaxSyms, Module.nsyms);
587
588 DBGDiggerCommonParseElf32Mod(pUVM, pVMM, szModName, szFilename, DBG_DIGGER_ELF_FUNNY_SHDRS,
589 &Module.hdr, paShdrs, paSyms, cMaxSyms, pbStrings, cbMaxStrings,
590 SOL32_MIN_KRNL_ADDR, SOL32_MAX_KRNL_ADDR - 1, DIG_SOL_MOD_TAG);
591 }
592 RTMemTmpFree(pvSymSpace);
593 }
594 }
595
596 RTMemTmpFree(paShdrs);
597 return;
598}
599
600
601/**
602 * Processes a modctl_t.
603 *
604 * @param pUVM The user mode VM handle.
605 * @param pVMM The VMM function table.
606 * @param pThis Our instance data.
607 * @param pModCtl Pointer to the modctl structure.
608 */
609static void dbgDiggerSolarisProcessModCtl64(PUVM pUVM, PCVMMR3VTABLE pVMM, PDBGDIGGERSOLARIS pThis, SOL_modctl_t const *pModCtl)
610{
611 RT_NOREF1(pThis);
612
613 /* skip it if it's not loaded and installed */
614 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_loaded, v9_64.mod_loaded);
615 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_installed, v9_64.mod_installed);
616 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_id, v9_64.mod_id);
617 if ( ( !pModCtl->v9_64.mod_loaded
618 || !pModCtl->v9_64.mod_installed)
619 && pModCtl->v9_64.mod_id > 3)
620 return;
621
622 /*
623 * Read the module and file names first
624 */
625 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_modname, v9_64.mod_modname);
626 char szModName[64];
627 DBGFADDRESS Addr;
628 int rc = pVMM->pfnDBGFR3MemReadString(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_64.mod_modname),
629 szModName, sizeof(szModName));
630 if (RT_FAILURE(rc))
631 return;
632 if (!RTStrEnd(szModName, sizeof(szModName)))
633 szModName[sizeof(szModName) - 1] = '\0';
634
635 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_filename, v9_64.mod_filename);
636 char szFilename[256];
637 rc = pVMM->pfnDBGFR3MemReadString(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_64.mod_filename),
638 szFilename, sizeof(szFilename));
639 if (RT_FAILURE(rc))
640 strcpy(szFilename, szModName);
641 else if (!RTStrEnd(szFilename, sizeof(szFilename)))
642 szFilename[sizeof(szFilename) - 1] = '\0';
643
644 /*
645 * Then read the module struct and validate it.
646 */
647 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_mp, v9_64.mod_mp);
648 struct SOL64_module Module;
649 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, pModCtl->v9_64.mod_mp), &Module, sizeof(Module));
650 if (RT_FAILURE(rc))
651 return;
652
653 /* Basic validations of the elf header. */
654 if ( Module.hdr.e_ident[EI_MAG0] != ELFMAG0
655 || Module.hdr.e_ident[EI_MAG1] != ELFMAG1
656 || Module.hdr.e_ident[EI_MAG2] != ELFMAG2
657 || Module.hdr.e_ident[EI_MAG3] != ELFMAG3
658 || Module.hdr.e_ident[EI_CLASS] != ELFCLASS64
659 || Module.hdr.e_ident[EI_DATA] != ELFDATA2LSB
660 || Module.hdr.e_ident[EI_VERSION] != EV_CURRENT
661 || !ASMMemIsZero(&Module.hdr.e_ident[EI_PAD], EI_NIDENT - EI_PAD)
662 )
663 return;
664 if (Module.hdr.e_version != EV_CURRENT)
665 return;
666 if (Module.hdr.e_ehsize != sizeof(Module.hdr))
667 return;
668 if ( Module.hdr.e_type != ET_DYN
669 && Module.hdr.e_type != ET_REL
670 && Module.hdr.e_type != ET_EXEC) //??
671 return;
672 if (Module.hdr.e_machine != EM_X86_64)
673 return;
674 if ( Module.hdr.e_phentsize != sizeof(Elf64_Phdr)
675 && Module.hdr.e_phentsize) //??
676 return;
677 if (Module.hdr.e_shentsize != sizeof(Elf64_Shdr))
678 return;
679
680 /* Basic validations of the rest of the stuff. */
681 if ( !SOL64_VALID_ADDRESS(Module.shdrs)
682 || !SOL64_VALID_ADDRESS(Module.symhdr)
683 || !SOL64_VALID_ADDRESS(Module.strhdr)
684 || (!SOL64_VALID_ADDRESS(Module.symspace) && Module.symspace)
685 || !SOL64_VALID_ADDRESS(Module.text)
686 || !SOL64_VALID_ADDRESS(Module.data)
687 || (!SOL64_VALID_ADDRESS(Module.symtbl) && Module.symtbl)
688 || (!SOL64_VALID_ADDRESS(Module.strings) && Module.strings)
689 || (!SOL64_VALID_ADDRESS(Module.head) && Module.head)
690 || (!SOL64_VALID_ADDRESS(Module.tail) && Module.tail)
691 || !SOL64_VALID_ADDRESS(Module.filename))
692 return;
693 if ( Module.symsize > _4M
694 || Module.hdr.e_shnum > 4096
695 || Module.nsyms > _256K)
696 return;
697
698 /* Ignore modules without symbols. */
699 if (!Module.symtbl || !Module.strings || !Module.symspace || !Module.symsize)
700 return;
701
702 /* Check that the symtbl and strings points inside the symspace. */
703 if (Module.strings - Module.symspace >= Module.symsize)
704 return;
705 if (Module.symtbl - Module.symspace >= Module.symsize)
706 return;
707
708 /*
709 * Read the section headers, symbol table and string tables.
710 */
711 size_t cb = Module.hdr.e_shnum * sizeof(Elf64_Shdr);
712 Elf64_Shdr *paShdrs = (Elf64_Shdr *)RTMemTmpAlloc(cb);
713 if (!paShdrs)
714 return;
715 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.shdrs), paShdrs, cb);
716 if (RT_SUCCESS(rc))
717 {
718 void *pvSymSpace = RTMemTmpAlloc(Module.symsize + 1);
719 if (pvSymSpace)
720 {
721 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, Module.symspace),
722 pvSymSpace, Module.symsize);
723 if (RT_SUCCESS(rc))
724 {
725 ((uint8_t *)pvSymSpace)[Module.symsize] = 0;
726
727 /*
728 * Hand it over to the common ELF64 module parser.
729 */
730 char const *pbStrings = (char const *)pvSymSpace + (Module.strings - Module.symspace);
731 size_t cbMaxStrings = Module.symsize - (Module.strings - Module.symspace);
732
733 Elf64_Sym const *paSyms = (Elf64_Sym const *)((uintptr_t)pvSymSpace + (uintptr_t)(Module.symtbl - Module.symspace));
734 size_t cMaxSyms = (Module.symsize - (Module.symtbl - Module.symspace)) / sizeof(Elf32_Sym);
735 cMaxSyms = RT_MIN(cMaxSyms, Module.nsyms);
736
737 DBGDiggerCommonParseElf64Mod(pUVM, pVMM, szModName, szFilename, DBG_DIGGER_ELF_FUNNY_SHDRS,
738 &Module.hdr, paShdrs, paSyms, cMaxSyms, pbStrings, cbMaxStrings,
739 SOL64_MIN_KRNL_ADDR, SOL64_MAX_KRNL_ADDR - 1, DIG_SOL_MOD_TAG);
740 }
741 RTMemTmpFree(pvSymSpace);
742 }
743 }
744
745 RTMemTmpFree(paShdrs);
746 return;
747}
748
749
750/**
751 * @copydoc DBGFOSREG::pfnTerm
752 */
753static DECLCALLBACK(void) dbgDiggerSolarisTerm(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
754{
755 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
756 RT_NOREF(pUVM, pVMM);
757 Assert(pThis->fValid);
758
759 pThis->fValid = false;
760}
761
762
763/**
764 * @copydoc DBGFOSREG::pfnRefresh
765 */
766static DECLCALLBACK(int) dbgDiggerSolarisRefresh(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
767{
768 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
769 RT_NOREF(pThis);
770 Assert(pThis->fValid);
771
772 /*
773 * For now we'll flush and reload everything.
774 */
775 RTDBGAS hDbgAs = pVMM->pfnDBGFR3AsResolveAndRetain(pUVM, DBGF_AS_KERNEL);
776 if (hDbgAs != NIL_RTDBGAS)
777 {
778 uint32_t iMod = RTDbgAsModuleCount(hDbgAs);
779 while (iMod-- > 0)
780 {
781 RTDBGMOD hMod = RTDbgAsModuleByIndex(hDbgAs, iMod);
782 if (hMod != NIL_RTDBGMOD)
783 {
784 if (RTDbgModGetTag(hMod) == DIG_SOL_MOD_TAG)
785 {
786 int rc = RTDbgAsModuleUnlink(hDbgAs, hMod);
787 AssertRC(rc);
788 }
789 RTDbgModRelease(hMod);
790 }
791 }
792 RTDbgAsRelease(hDbgAs);
793 }
794
795 dbgDiggerSolarisTerm(pUVM, pVMM, pvData);
796 return dbgDiggerSolarisInit(pUVM, pVMM, pvData);
797}
798
799
800/**
801 * @copydoc DBGFOSREG::pfnInit
802 */
803static DECLCALLBACK(int) dbgDiggerSolarisInit(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
804{
805 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
806 Assert(!pThis->fValid);
807 int rc;
808 size_t cbModCtl = 0;
809
810 /*
811 * On Solaris the kernel and is the global address space.
812 */
813 pVMM->pfnDBGFR3AsSetAlias(pUVM, DBGF_AS_KERNEL, DBGF_AS_GLOBAL);
814
815/** @todo Use debug_info, build 7x / S10U6. */
816
817 /*
818 * Find the 'unix' modctl_t structure (aka modules).
819 * We know it resides in the unix data segment.
820 */
821 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &pThis->AddrUnixModCtl, 0);
822
823 DBGFADDRESS CurAddr = pThis->AddrUnixData;
824 DBGFADDRESS MaxAddr;
825 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &MaxAddr, CurAddr.FlatPtr + SOL_UNIX_MAX_DATA_SEG_SIZE);
826 const uint8_t *pbExpr = (const uint8_t *)&pThis->AddrUnixText.FlatPtr;
827 const uint32_t cbExpr = pThis->f64Bit ? sizeof(uint64_t) : sizeof(uint32_t);
828 while ( CurAddr.FlatPtr < MaxAddr.FlatPtr
829 && CurAddr.FlatPtr >= pThis->AddrUnixData.FlatPtr)
830 {
831 DBGFADDRESS HitAddr;
832 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &CurAddr, MaxAddr.FlatPtr - CurAddr.FlatPtr, 1, pbExpr, cbExpr, &HitAddr);
833 if (RT_FAILURE(rc))
834 break;
835
836 /*
837 * Read out the modctl_t structure.
838 */
839 DBGFADDRESS ModCtlAddr;
840
841 /* v11 */
842 if (pThis->f64Bit)
843 {
844 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32v11_modctl_t, mod_text));
845 SOL64v11_modctl_t ModCtlv11;
846 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv11, sizeof(ModCtlv11));
847 if (RT_SUCCESS(rc))
848 {
849 if ( SOL64_VALID_ADDRESS(ModCtlv11.mod_next)
850 && SOL64_VALID_ADDRESS(ModCtlv11.mod_prev)
851 && ModCtlv11.mod_id == 0
852 && SOL64_VALID_ADDRESS(ModCtlv11.mod_mp)
853 && SOL64_VALID_ADDRESS(ModCtlv11.mod_filename)
854 && SOL64_VALID_ADDRESS(ModCtlv11.mod_modname)
855 && ModCtlv11.mod_prim == 1
856 && ModCtlv11.mod_loaded == 1
857 && ModCtlv11.mod_installed == 1
858 && ModCtlv11.mod_requisites == 0
859 && ModCtlv11.mod_loadcnt == 1
860 /*&& ModCtlv11.mod_text == pThis->AddrUnixText.FlatPtr*/
861 && ModCtlv11.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE
862 && ModCtlv11.mod_text_size >= _128K)
863 {
864 char szUnix[5];
865 DBGFADDRESS NameAddr;
866 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv11.mod_modname);
867 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
868 if (RT_SUCCESS(rc))
869 {
870 if (!strcmp(szUnix, "unix"))
871 {
872 pThis->AddrUnixModCtl = ModCtlAddr;
873 pThis->iModCtlVer = 11;
874 cbModCtl = sizeof(ModCtlv11);
875 break;
876 }
877 Log(("sol64 mod_name=%.*s v11\n", sizeof(szUnix), szUnix));
878 }
879 }
880 }
881 }
882 else
883 {
884 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32v11_modctl_t, mod_text));
885 SOL32v11_modctl_t ModCtlv11;
886 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv11, sizeof(ModCtlv11));
887 if (RT_SUCCESS(rc))
888 {
889 if ( SOL32_VALID_ADDRESS(ModCtlv11.mod_next)
890 && SOL32_VALID_ADDRESS(ModCtlv11.mod_prev)
891 && ModCtlv11.mod_id == 0
892 && SOL32_VALID_ADDRESS(ModCtlv11.mod_mp)
893 && SOL32_VALID_ADDRESS(ModCtlv11.mod_filename)
894 && SOL32_VALID_ADDRESS(ModCtlv11.mod_modname)
895 && ModCtlv11.mod_prim == 1
896 && ModCtlv11.mod_loaded == 1
897 && ModCtlv11.mod_installed == 1
898 && ModCtlv11.mod_requisites == 0
899 && ModCtlv11.mod_loadcnt == 1
900 /*&& ModCtlv11.mod_text == pThis->AddrUnixText.FlatPtr*/
901 && ModCtlv11.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE
902 && ModCtlv11.mod_text_size >= _128K)
903 {
904 char szUnix[5];
905 DBGFADDRESS NameAddr;
906 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv11.mod_modname);
907 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
908 if (RT_SUCCESS(rc))
909 {
910 if (!strcmp(szUnix, "unix"))
911 {
912 pThis->AddrUnixModCtl = ModCtlAddr;
913 pThis->iModCtlVer = 11;
914 cbModCtl = sizeof(ModCtlv11);
915 break;
916 }
917 Log(("sol32 mod_name=%.*s v11\n", sizeof(szUnix), szUnix));
918 }
919 }
920 }
921 }
922
923 /* v9 */
924 if (pThis->f64Bit)
925 {
926 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL64v9_modctl_t, mod_text));
927 SOL64v9_modctl_t ModCtlv9;
928 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv9, sizeof(ModCtlv9));
929 if (RT_SUCCESS(rc))
930 {
931 if ( SOL64_VALID_ADDRESS(ModCtlv9.mod_next)
932 && SOL64_VALID_ADDRESS(ModCtlv9.mod_prev)
933 && ModCtlv9.mod_id == 0
934 && SOL64_VALID_ADDRESS(ModCtlv9.mod_mp)
935 && SOL64_VALID_ADDRESS(ModCtlv9.mod_filename)
936 && SOL64_VALID_ADDRESS(ModCtlv9.mod_modname)
937 && (ModCtlv9.mod_loaded == 1 || ModCtlv9.mod_loaded == 0)
938 && (ModCtlv9.mod_installed == 1 || ModCtlv9.mod_installed == 0)
939 && ModCtlv9.mod_requisites == 0
940 && (ModCtlv9.mod_loadcnt == 1 || ModCtlv9.mod_loadcnt == 0)
941 /*&& ModCtlv9.mod_text == pThis->AddrUnixText.FlatPtr*/
942 && ModCtlv9.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE)
943 {
944 char szUnix[5];
945 DBGFADDRESS NameAddr;
946 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv9.mod_modname);
947 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
948 if (RT_SUCCESS(rc))
949 {
950 if (!strcmp(szUnix, "unix"))
951 {
952 pThis->AddrUnixModCtl = ModCtlAddr;
953 pThis->iModCtlVer = 9;
954 cbModCtl = sizeof(ModCtlv9);
955 break;
956 }
957 Log(("sol64 mod_name=%.*s v9\n", sizeof(szUnix), szUnix));
958 }
959 }
960 }
961 }
962 else
963 {
964 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32v9_modctl_t, mod_text));
965 SOL32v9_modctl_t ModCtlv9;
966 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &ModCtlAddr, &ModCtlv9, sizeof(ModCtlv9));
967 if (RT_SUCCESS(rc))
968 {
969 if ( SOL32_VALID_ADDRESS(ModCtlv9.mod_next)
970 && SOL32_VALID_ADDRESS(ModCtlv9.mod_prev)
971 && ModCtlv9.mod_id == 0
972 && SOL32_VALID_ADDRESS(ModCtlv9.mod_mp)
973 && SOL32_VALID_ADDRESS(ModCtlv9.mod_filename)
974 && SOL32_VALID_ADDRESS(ModCtlv9.mod_modname)
975 && (ModCtlv9.mod_loaded == 1 || ModCtlv9.mod_loaded == 0)
976 && (ModCtlv9.mod_installed == 1 || ModCtlv9.mod_installed == 0)
977 && ModCtlv9.mod_requisites == 0
978 && (ModCtlv9.mod_loadcnt == 1 || ModCtlv9.mod_loadcnt == 0)
979 /*&& ModCtlv9.mod_text == pThis->AddrUnixText.FlatPtr*/
980 && ModCtlv9.mod_text_size < SOL_UNIX_MAX_CODE_SEG_SIZE )
981 {
982 char szUnix[5];
983 DBGFADDRESS NameAddr;
984 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &NameAddr, ModCtlv9.mod_modname);
985 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &NameAddr, &szUnix, sizeof(szUnix));
986 if (RT_SUCCESS(rc))
987 {
988 if (!strcmp(szUnix, "unix"))
989 {
990 pThis->AddrUnixModCtl = ModCtlAddr;
991 pThis->iModCtlVer = 9;
992 cbModCtl = sizeof(ModCtlv9);
993 break;
994 }
995 Log(("sol32 mod_name=%.*s v9\n", sizeof(szUnix), szUnix));
996 }
997 }
998 }
999 }
1000
1001 /* next */
1002 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &CurAddr, HitAddr.FlatPtr + cbExpr);
1003 }
1004
1005 /*
1006 * Walk the module chain and add the modules and their symbols.
1007 */
1008 if (pThis->AddrUnixModCtl.FlatPtr)
1009 {
1010 int iMod = 0;
1011 CurAddr = pThis->AddrUnixModCtl;
1012 do
1013 {
1014 /* read it */
1015 SOL_modctl_t ModCtl;
1016 rc = pVMM->pfnDBGFR3MemRead(pUVM, 0, &CurAddr, &ModCtl, cbModCtl);
1017 if (RT_FAILURE(rc))
1018 {
1019 LogRel(("sol: bad modctl_t chain for module %d: %RGv - %Rrc\n", iMod, CurAddr.FlatPtr, rc));
1020 break;
1021 }
1022
1023 /* process it. */
1024 if (pThis->f64Bit)
1025 dbgDiggerSolarisProcessModCtl64(pUVM, pVMM, pThis, &ModCtl);
1026 else
1027 dbgDiggerSolarisProcessModCtl32(pUVM, pVMM, pThis, &ModCtl);
1028
1029 /* next */
1030 if (pThis->f64Bit)
1031 {
1032 AssertCompile2MemberOffsets(SOL_modctl_t, v11_64.mod_next, v9_64.mod_next);
1033 if (!SOL64_VALID_ADDRESS(ModCtl.v9_64.mod_next))
1034 {
1035 LogRel(("sol64: bad modctl_t chain for module %d at %RGv: %RGv\n", iMod, CurAddr.FlatPtr, (RTGCUINTPTR)ModCtl.v9_64.mod_next));
1036 break;
1037 }
1038 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &CurAddr, ModCtl.v9_64.mod_next);
1039 }
1040 else
1041 {
1042 AssertCompile2MemberOffsets(SOL_modctl_t, v11_32.mod_next, v9_32.mod_next);
1043 if (!SOL32_VALID_ADDRESS(ModCtl.v9_32.mod_next))
1044 {
1045 LogRel(("sol32: bad modctl_t chain for module %d at %RGv: %RGv\n", iMod, CurAddr.FlatPtr, (RTGCUINTPTR)ModCtl.v9_32.mod_next));
1046 break;
1047 }
1048 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &CurAddr, ModCtl.v9_32.mod_next);
1049 }
1050 if (++iMod >= 1024)
1051 {
1052 LogRel(("sol32: too many modules (%d)\n", iMod));
1053 break;
1054 }
1055 } while (CurAddr.FlatPtr != pThis->AddrUnixModCtl.FlatPtr);
1056 }
1057
1058 pThis->fValid = true;
1059 return VINF_SUCCESS;
1060}
1061
1062
1063/**
1064 * @copydoc DBGFOSREG::pfnProbe
1065 */
1066static DECLCALLBACK(bool) dbgDiggerSolarisProbe(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1067{
1068 PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
1069
1070 /*
1071 * Look for "SunOS Release" in the text segment.
1072 */
1073 DBGFADDRESS Addr;
1074 bool f64Bit = false;
1075
1076 /* 32-bit search range. */
1077 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, 0xfe800000);
1078 RTGCUINTPTR cbRange = 0xfec00000 - 0xfe800000;
1079
1080 DBGFADDRESS HitAddr;
1081 static const uint8_t s_abSunRelease[] = "SunOS Release ";
1082 int rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abSunRelease, sizeof(s_abSunRelease) - 1, &HitAddr);
1083 if (RT_FAILURE(rc))
1084 {
1085 /* 64-bit.... */
1086 pVMM->pfnDBGFR3AddrFromFlat(pUVM, &Addr, UINT64_C(0xfffffffffb800000));
1087 cbRange = UINT64_C(0xfffffffffbd00000) - UINT64_C(0xfffffffffb800000);
1088 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abSunRelease, sizeof(s_abSunRelease) - 1, &HitAddr);
1089 if (RT_FAILURE(rc))
1090 return false;
1091 f64Bit = true;
1092 }
1093
1094 /*
1095 * Look for the copyright string too, just to be sure.
1096 */
1097 static const uint8_t s_abSMI[] = "Sun Microsystems, Inc.";
1098 static const uint8_t s_abORCL[] = "Oracle and/or its affiliates.";
1099 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abSMI, sizeof(s_abSMI) - 1, &HitAddr);
1100 if (RT_FAILURE(rc))
1101 {
1102 /* Try the alternate copyright string. */
1103 rc = pVMM->pfnDBGFR3MemScan(pUVM, 0, &Addr, cbRange, 1, s_abORCL, sizeof(s_abORCL) - 1, &HitAddr);
1104 if (RT_FAILURE(rc))
1105 return false;
1106 }
1107
1108 /*
1109 * Remember the unix text and data addresses and bitness.
1110 */
1111 pThis->AddrUnixText = Addr;
1112 pVMM->pfnDBGFR3AddrAdd(&Addr, SOL_UNIX_MAX_CODE_SEG_SIZE);
1113 pThis->AddrUnixData = Addr;
1114 pThis->f64Bit = f64Bit;
1115
1116 return true;
1117}
1118
1119
1120/**
1121 * @copydoc DBGFOSREG::pfnDestruct
1122 */
1123static DECLCALLBACK(void) dbgDiggerSolarisDestruct(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1124{
1125 RT_NOREF(pUVM, pVMM, pvData);
1126}
1127
1128
1129/**
1130 * @copydoc DBGFOSREG::pfnConstruct
1131 */
1132static DECLCALLBACK(int) dbgDiggerSolarisConstruct(PUVM pUVM, PCVMMR3VTABLE pVMM, void *pvData)
1133{
1134 RT_NOREF(pUVM, pVMM, pvData);
1135 return VINF_SUCCESS;
1136}
1137
1138
1139const DBGFOSREG g_DBGDiggerSolaris =
1140{
1141 /* .u32Magic = */ DBGFOSREG_MAGIC,
1142 /* .fFlags = */ 0,
1143 /* .cbData = */ sizeof(DBGDIGGERSOLARIS),
1144 /* .szName = */ "Solaris",
1145 /* .pfnConstruct = */ dbgDiggerSolarisConstruct,
1146 /* .pfnDestruct = */ dbgDiggerSolarisDestruct,
1147 /* .pfnProbe = */ dbgDiggerSolarisProbe,
1148 /* .pfnInit = */ dbgDiggerSolarisInit,
1149 /* .pfnRefresh = */ dbgDiggerSolarisRefresh,
1150 /* .pfnTerm = */ dbgDiggerSolarisTerm,
1151 /* .pfnQueryVersion = */ dbgDiggerSolarisQueryVersion,
1152 /* .pfnQueryInterface = */ dbgDiggerSolarisQueryInterface,
1153 /* .pfnStackUnwindAssist = */ dbgDiggerSolarisStackUnwindAssist,
1154 /* .u32EndMagic = */ DBGFOSREG_MAGIC
1155};
1156
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