1 | /* $Id: DBGPlugInSolaris.cpp 8928 2008-05-19 18:26:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGPlugInSolaris - Debugger and Guest OS Digger Plugin For Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
19 | * additional information or have any questions.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_DBGF ///@todo add new log group.
|
---|
27 | #include "DBGPlugIns.h"
|
---|
28 | #include "DBGPlugInCommonELF.h"
|
---|
29 | #include <VBox/dbgf.h>
|
---|
30 | #include <iprt/string.h>
|
---|
31 | #include <iprt/mem.h>
|
---|
32 | #include <iprt/stream.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*******************************************************************************
|
---|
36 | * Structures and Typedefs *
|
---|
37 | *******************************************************************************/
|
---|
38 |
|
---|
39 | /** @name InternalSolaris structures
|
---|
40 | * @{ */
|
---|
41 |
|
---|
42 | typedef struct SOL32_modctl
|
---|
43 | {
|
---|
44 | uint32_t mod_next; /**< 0 */
|
---|
45 | uint32_t mod_prev; /**< 4 */
|
---|
46 | int32_t mod_id; /**< 8 */
|
---|
47 | uint32_t mod_mp; /**< c Pointer to the kernel runtime loader bits. */
|
---|
48 | uint32_t mod_inprogress_thread; /**< 10 */
|
---|
49 | uint32_t mod_modinfo; /**< 14 */
|
---|
50 | uint32_t mod_linkage; /**< 18 */
|
---|
51 | uint32_t mod_filename; /**< 1c */
|
---|
52 | uint32_t mod_modname; /**< 20 */
|
---|
53 | int8_t mod_busy; /**< 24 */
|
---|
54 | int8_t mod_want; /**< 25 */
|
---|
55 | int8_t mod_prim; /**< 26 this is 1 for 'unix' and a few others. */
|
---|
56 | int8_t mod_unused_padding; /**< 27 */
|
---|
57 | int32_t mod_ref; /**< 28 */
|
---|
58 | int8_t mod_loaded; /**< 2c */
|
---|
59 | int8_t mod_installed; /**< 2d */
|
---|
60 | int8_t mod_loadflags; /**< 2e */
|
---|
61 | int8_t mod_delay_unload; /**< 2f */
|
---|
62 | uint32_t mod_requisites; /**< 30 */
|
---|
63 | uint32_t mod___unused; /**< 34 */
|
---|
64 | int32_t mod_loadcnt; /**< 38 */
|
---|
65 | int32_t mod_nenabled; /**< 3c */
|
---|
66 | uint32_t mod_text; /**< 40 */
|
---|
67 | uint32_t mod_text_size; /**< 44 */
|
---|
68 | int32_t mod_gencount; /**< 48 */
|
---|
69 | uint32_t mod_requisite_loading; /**< 4c */
|
---|
70 | } SOL32_modctl_t;
|
---|
71 | AssertCompileSize(SOL32_modctl_t, 0x50);
|
---|
72 |
|
---|
73 | typedef struct SOL32_module
|
---|
74 | {
|
---|
75 | int32_t total_allocated; /**< 0 */
|
---|
76 | Elf32_Ehdr hdr; /**< 4 Easy to validate */
|
---|
77 | uint32_t shdrs; /**< 38 */
|
---|
78 | uint32_t symhdr; /**< 3c */
|
---|
79 | uint32_t strhdr; /**< 40 */
|
---|
80 | uint32_t depends_on; /**< 44 */
|
---|
81 | uint32_t symsize; /**< 48 */
|
---|
82 | uint32_t symspace; /**< 4c */
|
---|
83 | int32_t flags; /**< 50 */
|
---|
84 | uint32_t text_size; /**< 54 */
|
---|
85 | uint32_t data_size; /**< 58 */
|
---|
86 | uint32_t text; /**< 5c */
|
---|
87 | uint32_t data; /**< 60 */
|
---|
88 | uint32_t symtbl_section; /**< 64 */
|
---|
89 | uint32_t symtbl; /**< 68 */
|
---|
90 | uint32_t strings; /**< 6c */
|
---|
91 | uint32_t hashsize; /**< 70 */
|
---|
92 | uint32_t buckets; /**< 74 */
|
---|
93 | uint32_t chains; /**< 78 */
|
---|
94 | uint32_t nsyms; /**< 7c */
|
---|
95 | uint32_t bss_align; /**< 80 */
|
---|
96 | uint32_t bss_size; /**< 84 */
|
---|
97 | uint32_t bss; /**< 88 */
|
---|
98 | uint32_t filename; /**< 8c */
|
---|
99 | uint32_t head; /**< 90 */
|
---|
100 | uint32_t tail; /**< 94 */
|
---|
101 | uint32_t destination; /**< 98 */
|
---|
102 | uint32_t machdata; /**< 9c */
|
---|
103 | uint32_t ctfdata; /**< a0 */
|
---|
104 | uint32_t ctfsize; /**< a4 */
|
---|
105 | uint32_t fbt_tab; /**< a8 */
|
---|
106 | uint32_t fbt_size; /**< ac */
|
---|
107 | uint32_t fbt_nentries; /**< b0 */
|
---|
108 | uint32_t textwin; /**< b4 */
|
---|
109 | uint32_t textwin_base; /**< b8 */
|
---|
110 | uint32_t sdt_probes; /**< bc */
|
---|
111 | uint32_t sdt_nprobes; /**< c0 */
|
---|
112 | uint32_t sdt_tab; /**< c4 */
|
---|
113 | uint32_t sdt_size; /**< c8 */
|
---|
114 | uint32_t sigdata; /**< cc */
|
---|
115 | uint32_t sigsize; /**< d0 */
|
---|
116 | } SOL32_module_t;
|
---|
117 | AssertCompileSize(Elf32_Ehdr, 0x34);
|
---|
118 | AssertCompileSize(SOL32_module_t, 0xd4);
|
---|
119 |
|
---|
120 | typedef struct SOL_utsname
|
---|
121 | {
|
---|
122 | char sysname[257];
|
---|
123 | char nodename[257];
|
---|
124 | char release[257];
|
---|
125 | char version[257];
|
---|
126 | char machine[257];
|
---|
127 | } SOL_utsname_t;
|
---|
128 | AssertCompileSize(SOL_utsname_t, 5 * 257);
|
---|
129 |
|
---|
130 | /** @} */
|
---|
131 |
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Solaris guest OS digger instance data.
|
---|
135 | */
|
---|
136 | typedef struct DBGDIGGERSOLARIS
|
---|
137 | {
|
---|
138 | /** Whether the information is valid or not.
|
---|
139 | * (For fending off illegal interface method calls.) */
|
---|
140 | bool fValid;
|
---|
141 |
|
---|
142 | /** Address of the 'unix' text segment.
|
---|
143 | * This is set during probing. */
|
---|
144 | DBGFADDRESS AddrUnixText;
|
---|
145 | /** Address of the 'unix' text segment.
|
---|
146 | * This is set during probing. */
|
---|
147 | DBGFADDRESS AddrUnixData;
|
---|
148 | /** Address of the 'unix' modctl_t (aka modules). */
|
---|
149 | DBGFADDRESS AddrUnixModCtl;
|
---|
150 |
|
---|
151 | } DBGDIGGERSOLARIS;
|
---|
152 | /** Pointer to the solaris guest OS digger instance data. */
|
---|
153 | typedef DBGDIGGERSOLARIS *PDBGDIGGERSOLARIS;
|
---|
154 |
|
---|
155 |
|
---|
156 | /*******************************************************************************
|
---|
157 | * Defined Constants And Macros *
|
---|
158 | *******************************************************************************/
|
---|
159 | /** Validates a 32-bit solaris kernel address */
|
---|
160 | #define SOL32_VALID_ADDRESS(Addr) ((Addr) > UINT32_C(0x80000000) && (Addr) < UINT32_C(0xfffff000))
|
---|
161 |
|
---|
162 | /** The max data segment size of the 'unix' module. */
|
---|
163 | #define SOL_UNIX_MAX_DATA_SEG_SIZE 0x01000000
|
---|
164 |
|
---|
165 |
|
---|
166 | /*******************************************************************************
|
---|
167 | * Internal Functions *
|
---|
168 | *******************************************************************************/
|
---|
169 | static DECLCALLBACK(int) dbgDiggerSolarisInit(PVM pVM, void *pvData);
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * @copydoc DBGFOSREG::pfnQueryInterface
|
---|
175 | */
|
---|
176 | static DECLCALLBACK(void *) dbgDiggerSolarisQueryInterface(PVM pVM, void *pvData, DBGFOSINTERFACE enmIf)
|
---|
177 | {
|
---|
178 | return NULL;
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * @copydoc DBGFOSREG::pfnQueryVersion
|
---|
184 | */
|
---|
185 | static DECLCALLBACK(int) dbgDiggerSolarisQueryVersion(PVM pVM, void *pvData, char *pszVersion, size_t cchVersion)
|
---|
186 | {
|
---|
187 | PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
|
---|
188 | Assert(pThis->fValid);
|
---|
189 |
|
---|
190 | /*
|
---|
191 | * It's all in the utsname symbol...
|
---|
192 | */
|
---|
193 | DBGFADDRESS Addr;
|
---|
194 | SOL_utsname_t UtsName;
|
---|
195 | DBGFSYMBOL SymUtsName;
|
---|
196 | int rc = DBGFR3SymbolByName(pVM, "utsname", &SymUtsName);
|
---|
197 | if (RT_SUCCESS(rc))
|
---|
198 | rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, SymUtsName.Value), &UtsName, sizeof(UtsName));
|
---|
199 | if (RT_FAILURE(rc))
|
---|
200 | {
|
---|
201 | /*
|
---|
202 | * Try searching by the name...
|
---|
203 | */
|
---|
204 | memset(&UtsName, '\0', sizeof(UtsName));
|
---|
205 | strcpy(&UtsName.sysname[0], "SunOS");
|
---|
206 | rc = DBGFR3MemScan(pVM, &pThis->AddrUnixData, SOL_UNIX_MAX_DATA_SEG_SIZE,
|
---|
207 | (uint8_t *)&UtsName.sysname[0], sizeof(UtsName.sysname), &Addr);
|
---|
208 | if (RT_SUCCESS(rc))
|
---|
209 | rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, Addr.FlatPtr - RT_OFFSETOF(SOL_utsname_t, sysname)),
|
---|
210 | &UtsName, sizeof(UtsName));
|
---|
211 | }
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * Copy out the result (if any).
|
---|
215 | */
|
---|
216 | if (RT_SUCCESS(rc))
|
---|
217 | {
|
---|
218 | if ( UtsName.nodename[-1] != '\0'
|
---|
219 | || UtsName.release[-1] != '\0'
|
---|
220 | || UtsName.version[-1] != '\0'
|
---|
221 | || UtsName.machine[-1] != '\0'
|
---|
222 | || UtsName.machine[sizeof(UtsName.machine) - 1] != '\0')
|
---|
223 | {
|
---|
224 | //rc = VERR_DBGF_UNEXPECTED_OS_DATA;
|
---|
225 | rc = VERR_GENERAL_FAILURE;
|
---|
226 | RTStrPrintf(pszVersion, cchVersion, "failed - bogus utsname");
|
---|
227 | }
|
---|
228 | else
|
---|
229 | RTStrPrintf(pszVersion, cchVersion, "%s %s", UtsName.version, UtsName.release);
|
---|
230 | }
|
---|
231 | else
|
---|
232 | RTStrPrintf(pszVersion, cchVersion, "failed - %Rrc", rc);
|
---|
233 |
|
---|
234 | return rc;
|
---|
235 | }
|
---|
236 |
|
---|
237 |
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Processes a modctl_t.
|
---|
241 | *
|
---|
242 | * @param pVM The VM handle.
|
---|
243 | * @param pThis Our instance data.
|
---|
244 | * @param pModCtl Pointer to the modctl structure.
|
---|
245 | */
|
---|
246 | static void dbgDiggerSolarisProcessModCtl(PVM pVM, PDBGDIGGERSOLARIS pThis, SOL32_modctl_t const *pModCtl)
|
---|
247 | {
|
---|
248 | /* skip it if it's not loaded and installed */
|
---|
249 | if ( !pModCtl->mod_loaded
|
---|
250 | || !pModCtl->mod_installed)
|
---|
251 | return;
|
---|
252 |
|
---|
253 | /*
|
---|
254 | * Read the module and file names first
|
---|
255 | */
|
---|
256 | char szModName[64];
|
---|
257 | DBGFADDRESS Addr;
|
---|
258 | int rc = DBGFR3MemReadString(pVM, DBGFR3AddrFromFlat(pVM, &Addr, pModCtl->mod_modname), szModName, sizeof(szModName));
|
---|
259 | if (RT_FAILURE(rc))
|
---|
260 | return;
|
---|
261 | if (!memchr(szModName, '\0', sizeof(szModName)))
|
---|
262 | szModName[sizeof(szModName) - 1] = '\0';
|
---|
263 |
|
---|
264 | char szFilename[256];
|
---|
265 | rc = DBGFR3MemReadString(pVM, DBGFR3AddrFromFlat(pVM, &Addr, pModCtl->mod_filename), szFilename, sizeof(szFilename));
|
---|
266 | if (RT_FAILURE(rc))
|
---|
267 | strcpy(szFilename, szModName);
|
---|
268 | else if (!memchr(szFilename, '\0', sizeof(szFilename)))
|
---|
269 | szFilename[sizeof(szFilename) - 1] = '\0';
|
---|
270 |
|
---|
271 | /*
|
---|
272 | * Then read the module struct and validate it.
|
---|
273 | */
|
---|
274 | struct SOL32_module Module;
|
---|
275 | rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, pModCtl->mod_mp), &Module, sizeof(Module));
|
---|
276 | if (RT_FAILURE(rc))
|
---|
277 | return;
|
---|
278 |
|
---|
279 | /* Basic validations of the elf header. */
|
---|
280 | if ( Module.hdr.e_ident[EI_MAG0] != ELFMAG0
|
---|
281 | || Module.hdr.e_ident[EI_MAG1] != ELFMAG1
|
---|
282 | || Module.hdr.e_ident[EI_MAG2] != ELFMAG2
|
---|
283 | || Module.hdr.e_ident[EI_MAG3] != ELFMAG3
|
---|
284 | || Module.hdr.e_ident[EI_CLASS] != ELFCLASS32
|
---|
285 | || Module.hdr.e_ident[EI_DATA] != ELFDATA2LSB
|
---|
286 | || Module.hdr.e_ident[EI_VERSION] != EV_CURRENT
|
---|
287 | || ASMMemIsAll8(&Module.hdr.e_ident[EI_PAD], EI_NIDENT - EI_PAD, 0) != NULL
|
---|
288 | )
|
---|
289 | return;
|
---|
290 | if (Module.hdr.e_version != EV_CURRENT)
|
---|
291 | return;
|
---|
292 | if (Module.hdr.e_ehsize != sizeof(Module.hdr))
|
---|
293 | return;
|
---|
294 | if ( Module.hdr.e_type != ET_DYN
|
---|
295 | && Module.hdr.e_type != ET_REL
|
---|
296 | && Module.hdr.e_type != ET_EXEC) //??
|
---|
297 | return;
|
---|
298 | if ( Module.hdr.e_machine != EM_386
|
---|
299 | && Module.hdr.e_machine != EM_486)
|
---|
300 | return;
|
---|
301 | if ( Module.hdr.e_phentsize != sizeof(Elf32_Phdr)
|
---|
302 | && Module.hdr.e_phentsize) //??
|
---|
303 | return;
|
---|
304 | if (Module.hdr.e_shentsize != sizeof(Elf32_Shdr))
|
---|
305 | return;
|
---|
306 |
|
---|
307 | if (Module.hdr.e_shentsize != sizeof(Elf32_Shdr))
|
---|
308 | return;
|
---|
309 |
|
---|
310 | /* Basic validations of the rest of the stuff. */
|
---|
311 | if ( !SOL32_VALID_ADDRESS(Module.shdrs)
|
---|
312 | || !SOL32_VALID_ADDRESS(Module.symhdr)
|
---|
313 | || !SOL32_VALID_ADDRESS(Module.strhdr)
|
---|
314 | || (!SOL32_VALID_ADDRESS(Module.symspace) && Module.symspace)
|
---|
315 | || !SOL32_VALID_ADDRESS(Module.text)
|
---|
316 | || !SOL32_VALID_ADDRESS(Module.data)
|
---|
317 | || (!SOL32_VALID_ADDRESS(Module.symtbl) && Module.symtbl)
|
---|
318 | || (!SOL32_VALID_ADDRESS(Module.strings) && Module.strings)
|
---|
319 | || (!SOL32_VALID_ADDRESS(Module.head) && Module.head)
|
---|
320 | || (!SOL32_VALID_ADDRESS(Module.tail) && Module.tail)
|
---|
321 | || !SOL32_VALID_ADDRESS(Module.filename))
|
---|
322 | return;
|
---|
323 | if ( Module.symsize > _4M
|
---|
324 | || Module.hdr.e_shnum > 4096
|
---|
325 | || Module.nsyms > _256K)
|
---|
326 | return;
|
---|
327 |
|
---|
328 | /* Ignore modules without symbols. */
|
---|
329 | if (!Module.symtbl || !Module.strings || !Module.symspace || !Module.symspace)
|
---|
330 | return;
|
---|
331 |
|
---|
332 | /* Check that the symtbl and strings points inside the symspace. */
|
---|
333 | if (Module.strings - Module.symspace >= Module.symsize)
|
---|
334 | return;
|
---|
335 | if (Module.symtbl - Module.symspace >= Module.symsize)
|
---|
336 | return;
|
---|
337 |
|
---|
338 | /*
|
---|
339 | * Read the section headers, symbol table and string tables.
|
---|
340 | */
|
---|
341 | size_t cb = Module.hdr.e_shnum * sizeof(Elf32_Shdr);
|
---|
342 | Elf32_Shdr *paShdrs = (Elf32_Shdr *)RTMemTmpAlloc(cb);
|
---|
343 | if (!paShdrs)
|
---|
344 | return;
|
---|
345 | rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, Module.shdrs), paShdrs, cb);
|
---|
346 | if (RT_SUCCESS(rc))
|
---|
347 | {
|
---|
348 | void *pvSymSpace = RTMemTmpAlloc(Module.symsize + 1);
|
---|
349 | if (pvSymSpace)
|
---|
350 | {
|
---|
351 | rc = DBGFR3MemRead(pVM, DBGFR3AddrFromFlat(pVM, &Addr, Module.shdrs), pvSymSpace, Module.symsize);
|
---|
352 | if (RT_SUCCESS(rc))
|
---|
353 | {
|
---|
354 | ((uint8_t *)pvSymSpace)[Module.symsize] = 0;
|
---|
355 |
|
---|
356 | /*
|
---|
357 | * Hand it over to the common ELF32 module parser.
|
---|
358 | */
|
---|
359 | char const *pbStrings = (char const *)pvSymSpace + (Module.strings - Module.symspace);
|
---|
360 | size_t cbMaxStrings = Module.symsize - (Module.strings - Module.symspace);
|
---|
361 |
|
---|
362 | Elf32_Sym const *paSyms = (Elf32_Sym const *)((uintptr_t)pvSymSpace + (Module.symtbl - Module.symspace));
|
---|
363 | size_t cMaxSyms = (Module.symsize - (Module.symtbl - Module.symspace)) / sizeof(Elf32_Sym);
|
---|
364 | cMaxSyms = RT_MIN(cMaxSyms, Module.nsyms);
|
---|
365 |
|
---|
366 | DBGDiggerCommonParseElf32Mod(pVM, szModName, szFilename, DBG_DIGGER_ELF_FUNNY_SHDRS,
|
---|
367 | &Module.hdr, paShdrs, paSyms, cMaxSyms, pbStrings, cbMaxStrings);
|
---|
368 | }
|
---|
369 | RTMemTmpFree(pvSymSpace);
|
---|
370 | }
|
---|
371 | }
|
---|
372 |
|
---|
373 | RTMemTmpFree(paShdrs);
|
---|
374 | return;
|
---|
375 | }
|
---|
376 |
|
---|
377 |
|
---|
378 | /**
|
---|
379 | * @copydoc DBGFOSREG::pfnTerm
|
---|
380 | */
|
---|
381 | static DECLCALLBACK(void) dbgDiggerSolarisTerm(PVM pVM, void *pvData)
|
---|
382 | {
|
---|
383 | PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
|
---|
384 | Assert(pThis->fValid);
|
---|
385 |
|
---|
386 | pThis->fValid = false;
|
---|
387 | }
|
---|
388 |
|
---|
389 |
|
---|
390 | /**
|
---|
391 | * @copydoc DBGFOSREG::pfnRefresh
|
---|
392 | */
|
---|
393 | static DECLCALLBACK(int) dbgDiggerSolarisRefresh(PVM pVM, void *pvData)
|
---|
394 | {
|
---|
395 | PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
|
---|
396 | NOREF(pThis);
|
---|
397 | Assert(pThis->fValid);
|
---|
398 |
|
---|
399 | /*
|
---|
400 | * For now we'll flush and reload everything.
|
---|
401 | */
|
---|
402 | dbgDiggerSolarisTerm(pVM, pvData);
|
---|
403 | return dbgDiggerSolarisInit(pVM, pvData);
|
---|
404 | }
|
---|
405 |
|
---|
406 |
|
---|
407 | /**
|
---|
408 | * @copydoc DBGFOSREG::pfnInit
|
---|
409 | */
|
---|
410 | static DECLCALLBACK(int) dbgDiggerSolarisInit(PVM pVM, void *pvData)
|
---|
411 | {
|
---|
412 | PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
|
---|
413 | Assert(!pThis->fValid);
|
---|
414 | int rc;
|
---|
415 |
|
---|
416 | /*
|
---|
417 | * Find the 'unix' modctl_t structure (aka modules).
|
---|
418 | * We know it resides in the unix data segment.
|
---|
419 | */
|
---|
420 | DBGFR3AddrFromFlat(pVM, &pThis->AddrUnixModCtl, 0);
|
---|
421 |
|
---|
422 | DBGFADDRESS CurAddr = pThis->AddrUnixData;
|
---|
423 | DBGFADDRESS MaxAddr;
|
---|
424 | DBGFR3AddrFromFlat(pVM, &MaxAddr, CurAddr.FlatPtr + SOL_UNIX_MAX_DATA_SEG_SIZE);
|
---|
425 | const uint8_t *pbExpr = (const uint8_t *)&pThis->AddrUnixText.FlatPtr;
|
---|
426 | const uint32_t cbExpr = sizeof(uint32_t);//pThis->AddrUnixText.FlatPtr < _4G ? sizeof(uint32_t) : sizeof(uint64_t)
|
---|
427 | while ( CurAddr.FlatPtr < MaxAddr.FlatPtr
|
---|
428 | && CurAddr.FlatPtr >= pThis->AddrUnixData.FlatPtr)
|
---|
429 | {
|
---|
430 | DBGFADDRESS HitAddr;
|
---|
431 | rc = DBGFR3MemScan(pVM, &CurAddr, MaxAddr.FlatPtr - CurAddr.FlatPtr, pbExpr, cbExpr, &HitAddr);
|
---|
432 | if (RT_FAILURE(rc))
|
---|
433 | break;
|
---|
434 |
|
---|
435 | /*
|
---|
436 | * Read out the modctl_t structure.
|
---|
437 | */
|
---|
438 | DBGFADDRESS ModCtlAddr;
|
---|
439 | DBGFR3AddrFromFlat(pVM, &ModCtlAddr, HitAddr.FlatPtr - RT_OFFSETOF(SOL32_modctl_t, mod_text));
|
---|
440 | SOL32_modctl_t ModCtl;
|
---|
441 | rc = DBGFR3MemRead(pVM, &ModCtlAddr, &ModCtl, sizeof(ModCtl));
|
---|
442 | if (RT_SUCCESS(rc))
|
---|
443 | {
|
---|
444 | if ( SOL32_VALID_ADDRESS(ModCtl.mod_next)
|
---|
445 | && SOL32_VALID_ADDRESS(ModCtl.mod_prev)
|
---|
446 | && ModCtl.mod_id == 0
|
---|
447 | && SOL32_VALID_ADDRESS(ModCtl.mod_mp)
|
---|
448 | && SOL32_VALID_ADDRESS(ModCtl.mod_filename)
|
---|
449 | && SOL32_VALID_ADDRESS(ModCtl.mod_modname)
|
---|
450 | && ModCtl.mod_prim == 1
|
---|
451 | && ModCtl.mod_loaded == 1
|
---|
452 | && ModCtl.mod_installed == 1
|
---|
453 | && ModCtl.mod_requisites == 0
|
---|
454 | && ModCtl.mod_loadcnt == 1
|
---|
455 | /*&& ModCtl.mod_text == pThis->AddrUnixText.FlatPtr*/
|
---|
456 | && ModCtl.mod_text_size < UINT32_C(0xfec00000) - UINT32_C(0xfe800000) )
|
---|
457 | {
|
---|
458 | char szUnix[5];
|
---|
459 | DBGFADDRESS NameAddr;
|
---|
460 | DBGFR3AddrFromFlat(pVM, &NameAddr, ModCtl.mod_modname);
|
---|
461 | rc = DBGFR3MemRead(pVM, &NameAddr, &szUnix, sizeof(szUnix));
|
---|
462 | if (RT_SUCCESS(rc))
|
---|
463 | {
|
---|
464 | if (!strcmp(szUnix, "unix"))
|
---|
465 | {
|
---|
466 | pThis->AddrUnixModCtl = ModCtlAddr;
|
---|
467 | break;
|
---|
468 | }
|
---|
469 | Log(("sol32 mod_name=%.*s\n", sizeof(szUnix), szUnix));
|
---|
470 | }
|
---|
471 | }
|
---|
472 | }
|
---|
473 |
|
---|
474 | /* next */
|
---|
475 | DBGFR3AddrFromFlat(pVM, &CurAddr, HitAddr.FlatPtr + cbExpr);
|
---|
476 | }
|
---|
477 |
|
---|
478 | /*
|
---|
479 | * Walk the module chain and add the modules and their symbols.
|
---|
480 | */
|
---|
481 | if (pThis->AddrUnixModCtl.FlatPtr)
|
---|
482 | {
|
---|
483 | int iMod = 0;
|
---|
484 | CurAddr = pThis->AddrUnixModCtl;
|
---|
485 | do
|
---|
486 | {
|
---|
487 | /* read it */
|
---|
488 | SOL32_modctl_t ModCtl;
|
---|
489 | rc = DBGFR3MemRead(pVM, &CurAddr, &ModCtl, sizeof(ModCtl));
|
---|
490 | if (RT_FAILURE(rc))
|
---|
491 | {
|
---|
492 | LogRel(("sol32: bad modctl_t chain: %RGv - %Rrc\n", iMod, CurAddr.FlatPtr, rc));
|
---|
493 | break;
|
---|
494 | }
|
---|
495 |
|
---|
496 | /* process it. */
|
---|
497 | dbgDiggerSolarisProcessModCtl(pVM, pThis, &ModCtl);
|
---|
498 |
|
---|
499 | /* next */
|
---|
500 | if (!SOL32_VALID_ADDRESS(ModCtl.mod_next))
|
---|
501 | {
|
---|
502 | LogRel(("sol32: bad modctl_t chain at %RGv: %RGv\n", iMod, CurAddr.FlatPtr, (RTGCUINTPTR)ModCtl.mod_next));
|
---|
503 | break;
|
---|
504 | }
|
---|
505 | if (++iMod >= 1024)
|
---|
506 | {
|
---|
507 | LogRel(("sol32: too many modules (%d)\n", iMod));
|
---|
508 | break;
|
---|
509 | }
|
---|
510 | DBGFR3AddrFromFlat(pVM, &CurAddr, ModCtl.mod_next);
|
---|
511 | } while (CurAddr.FlatPtr != pThis->AddrUnixModCtl.FlatPtr);
|
---|
512 | }
|
---|
513 |
|
---|
514 | pThis->fValid = true;
|
---|
515 | return VINF_SUCCESS;
|
---|
516 | }
|
---|
517 |
|
---|
518 |
|
---|
519 | /**
|
---|
520 | * @copydoc DBGFOSREG::pfnProbe
|
---|
521 | */
|
---|
522 | static DECLCALLBACK(bool) dbgDiggerSolarisProbe(PVM pVM, void *pvData)
|
---|
523 | {
|
---|
524 | PDBGDIGGERSOLARIS pThis = (PDBGDIGGERSOLARIS)pvData;
|
---|
525 |
|
---|
526 | /*
|
---|
527 | * Look for "SunOS Release" in the text segment.
|
---|
528 | */
|
---|
529 | DBGFADDRESS Addr;
|
---|
530 | DBGFR3AddrFromFlat(pVM, &Addr, 0xfe800000);
|
---|
531 | RTGCUINTPTR cbRange = 0xfec00000 - 0xfe800000;
|
---|
532 |
|
---|
533 | DBGFADDRESS HitAddr;
|
---|
534 | static const uint8_t s_abSunRelease[] = "SunOS Release ";
|
---|
535 | int rc = DBGFR3MemScan(pVM, &Addr, cbRange, s_abSunRelease, sizeof(s_abSunRelease) - 1, &HitAddr);
|
---|
536 | if (RT_FAILURE(rc))
|
---|
537 | return false;
|
---|
538 |
|
---|
539 | /*
|
---|
540 | * Look for the copy right string too, just to be sure.
|
---|
541 | */
|
---|
542 | static const uint8_t s_abSMI[] = "Sun Microsystems, Inc.";
|
---|
543 | rc = DBGFR3MemScan(pVM, &Addr, cbRange, s_abSMI, sizeof(s_abSMI) - 1, &HitAddr);
|
---|
544 | if (RT_FAILURE(rc))
|
---|
545 | return false;
|
---|
546 |
|
---|
547 | /*
|
---|
548 | * Remember the unix text and data addresses (32-bit vs 64-bit).
|
---|
549 | */
|
---|
550 | pThis->AddrUnixText = Addr;
|
---|
551 | // if (pThis->AddrUnixText.FlatPtr == 0xfe800000)
|
---|
552 | {
|
---|
553 | DBGFR3AddrFromFlat(pVM, &Addr, 0xfec00000);
|
---|
554 | pThis->AddrUnixData = Addr;
|
---|
555 | }
|
---|
556 | // else
|
---|
557 | // {
|
---|
558 | // DBGFR3AddrFromFlat(pVM, &Addr, UINT64_C(0xwhateveritis));
|
---|
559 | // pThis->AddrUnixData = Addr;
|
---|
560 | // }
|
---|
561 |
|
---|
562 | return true;
|
---|
563 | }
|
---|
564 |
|
---|
565 |
|
---|
566 | /**
|
---|
567 | * @copydoc DBGFOSREG::pfnDestruct
|
---|
568 | */
|
---|
569 | static DECLCALLBACK(void) dbgDiggerSolarisDestruct(PVM pVM, void *pvData)
|
---|
570 | {
|
---|
571 |
|
---|
572 | }
|
---|
573 |
|
---|
574 |
|
---|
575 | /**
|
---|
576 | * @copydoc DBGFOSREG::pfnConstruct
|
---|
577 | */
|
---|
578 | static DECLCALLBACK(int) dbgDiggerSolarisConstruct(PVM pVM, void *pvData)
|
---|
579 | {
|
---|
580 | return VINF_SUCCESS;
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | const DBGFOSREG g_DBGDiggerSolaris =
|
---|
585 | {
|
---|
586 | /* .u32Magic = */ DBGFOSREG_MAGIC,
|
---|
587 | /* .fFlags = */ 0,
|
---|
588 | /* .cbData = */ sizeof(DBGDIGGERSOLARIS),
|
---|
589 | /* .szName = */ "Solaris",
|
---|
590 | /* .pfnConstruct = */ dbgDiggerSolarisConstruct,
|
---|
591 | /* .pfnDestruct = */ dbgDiggerSolarisDestruct,
|
---|
592 | /* .pfnProbe = */ dbgDiggerSolarisProbe,
|
---|
593 | /* .pfnInit = */ dbgDiggerSolarisInit,
|
---|
594 | /* .pfnRefresh = */ dbgDiggerSolarisRefresh,
|
---|
595 | /* .pfnTerm = */ dbgDiggerSolarisTerm,
|
---|
596 | /* .pfnQueryVersion = */ dbgDiggerSolarisQueryVersion,
|
---|
597 | /* .pfnQueryInterface = */ dbgDiggerSolarisQueryInterface,
|
---|
598 | /* .u32EndMagic = */ DBGFOSREG_MAGIC
|
---|
599 | };
|
---|
600 |
|
---|