1 | /** @file
|
---|
2 | * IPRT - Loader.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef ___iprt_ldr_h
|
---|
27 | #define ___iprt_ldr_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | /** @defgroup grp_ldr RTLdr - Loader
|
---|
34 | * @ingroup grp_rt
|
---|
35 | * @{
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 | RT_C_DECLS_BEGIN
|
---|
40 |
|
---|
41 | /** Loader address (unsigned integer). */
|
---|
42 | typedef RTUINTPTR RTLDRADDR;
|
---|
43 | /** Pointer to a loader address. */
|
---|
44 | typedef RTLDRADDR *PRTLDRADDR;
|
---|
45 | /** Pointer to a const loader address. */
|
---|
46 | typedef RTLDRADDR const *PCRTLDRADDR;
|
---|
47 | /** The max loader address value. */
|
---|
48 | #define RTLDRADDR_MAX RTUINTPTR_MAX
|
---|
49 | /** NIL loader address value. */
|
---|
50 | #define NIL_RTLDRADDR RTLDRADDR_MAX
|
---|
51 |
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Gets the default file suffix for DLL/SO/DYLIB/whatever.
|
---|
55 | *
|
---|
56 | * @returns The stuff (readonly).
|
---|
57 | */
|
---|
58 | RTDECL(const char *) RTLdrGetSuff(void);
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Checks if a library is loadable or not.
|
---|
62 | *
|
---|
63 | * This may attempt load and unload the library.
|
---|
64 | *
|
---|
65 | * @returns true/false accordingly.
|
---|
66 | * @param pszFilename Image filename.
|
---|
67 | */
|
---|
68 | RTDECL(bool) RTLdrIsLoadable(const char *pszFilename);
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Loads a dynamic load library (/shared object) image file using native
|
---|
72 | * OS facilities.
|
---|
73 | *
|
---|
74 | * The filename will be appended the default DLL/SO extension of
|
---|
75 | * the platform if it have been omitted. This means that it's not
|
---|
76 | * possible to load DLLs/SOs with no extension using this interface,
|
---|
77 | * but that's not a bad tradeoff.
|
---|
78 | *
|
---|
79 | * If no path is specified in the filename, the OS will usually search it's library
|
---|
80 | * path to find the image file.
|
---|
81 | *
|
---|
82 | * @returns iprt status code.
|
---|
83 | * @param pszFilename Image filename.
|
---|
84 | * @param phLdrMod Where to store the handle to the loader module.
|
---|
85 | */
|
---|
86 | RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Loads a dynamic load library (/shared object) image file using native
|
---|
90 | * OS facilities.
|
---|
91 | *
|
---|
92 | * The filename will be appended the default DLL/SO extension of
|
---|
93 | * the platform if it have been omitted. This means that it's not
|
---|
94 | * possible to load DLLs/SOs with no extension using this interface,
|
---|
95 | * but that's not a bad tradeoff.
|
---|
96 | *
|
---|
97 | * If no path is specified in the filename, the OS will usually search it's library
|
---|
98 | * path to find the image file.
|
---|
99 | *
|
---|
100 | * @returns iprt status code.
|
---|
101 | * @param pszFilename Image filename.
|
---|
102 | * @param phLdrMod Where to store the handle to the loader module.
|
---|
103 | * @param fFlags See RTLDRLOAD_FLAGS_XXX.
|
---|
104 | * @param pErrInfo Where to return extended error information. Optional.
|
---|
105 | */
|
---|
106 | RTDECL(int) RTLdrLoadEx(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
107 |
|
---|
108 | /** @defgroup RTLDRLOAD_FLAGS_XXX RTLdrLoadEx flags.
|
---|
109 | * @{ */
|
---|
110 | /** Symbols defined in this library are not made available to resolve
|
---|
111 | * references in subsequently loaded libraries (default). */
|
---|
112 | #define RTLDRLOAD_FLAGS_LOCAL UINT32_C(0)
|
---|
113 | /** Symbols defined in this library will be made available for symbol
|
---|
114 | * resolution of subsequently loaded libraries. */
|
---|
115 | #define RTLDRLOAD_FLAGS_GLOBAL RT_BIT_32(0)
|
---|
116 | /** The mask of valid flag bits. */
|
---|
117 | #define RTLDRLOAD_FLAGS_VALID_MASK UINT32_C(0x00000001)
|
---|
118 | /** @} */
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Loads a dynamic load library (/shared object) image file residing in the
|
---|
122 | * RTPathAppPrivateArch() directory.
|
---|
123 | *
|
---|
124 | * Suffix is not required.
|
---|
125 | *
|
---|
126 | * @returns iprt status code.
|
---|
127 | * @param pszFilename Image filename. No path.
|
---|
128 | * @param phLdrMod Where to store the handle to the loaded module.
|
---|
129 | */
|
---|
130 | RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Image architecuture specifier for RTLdrOpenEx.
|
---|
134 | */
|
---|
135 | typedef enum RTLDRARCH
|
---|
136 | {
|
---|
137 | RTLDRARCH_INVALID = 0,
|
---|
138 | /** Whatever. */
|
---|
139 | RTLDRARCH_WHATEVER,
|
---|
140 | /** The host architecture. */
|
---|
141 | RTLDRARCH_HOST,
|
---|
142 | /** 32-bit x86. */
|
---|
143 | RTLDRARCH_X86_32,
|
---|
144 | /** AMD64 (64-bit x86 if you like). */
|
---|
145 | RTLDRARCH_AMD64,
|
---|
146 | /** End of the valid values. */
|
---|
147 | RTLDRARCH_END,
|
---|
148 | /** Make sure the type is a full 32-bit. */
|
---|
149 | RTLDRARCH_32BIT_HACK = 0x7fffffff
|
---|
150 | } RTLDRARCH;
|
---|
151 | /** Pointer to a RTLDRARCH. */
|
---|
152 | typedef RTLDRARCH *PRTLDRARCH;
|
---|
153 |
|
---|
154 | /** @name RTLDR_O_XXX - RTLdrOpen flags.
|
---|
155 | * @{ */
|
---|
156 | /** Open for debugging or introspection reasons.
|
---|
157 | * This will skip a few of the stricter validations when loading images. */
|
---|
158 | #define RTLDR_O_FOR_DEBUG RT_BIT_32(0)
|
---|
159 | /** Mask of valid flags. */
|
---|
160 | #define RTLDR_O_VALID_MASK UINT32_C(0x00000001)
|
---|
161 | /** @} */
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Open a binary image file, extended version.
|
---|
165 | *
|
---|
166 | * @returns iprt status code.
|
---|
167 | * @param pszFilename Image filename.
|
---|
168 | * @param fFlags Valid RTLDR_O_XXX combination.
|
---|
169 | * @param enmArch CPU architecture specifier for the image to be loaded.
|
---|
170 | * @param phLdrMod Where to store the handle to the loader module.
|
---|
171 | */
|
---|
172 | RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Opens a binary image file using kLdr.
|
---|
176 | *
|
---|
177 | * @returns iprt status code.
|
---|
178 | * @param pszFilename Image filename.
|
---|
179 | * @param phLdrMod Where to store the handle to the loaded module.
|
---|
180 | * @param fFlags Valid RTLDR_O_XXX combination.
|
---|
181 | * @param enmArch CPU architecture specifier for the image to be loaded.
|
---|
182 | * @remark Primarily for testing the loader.
|
---|
183 | */
|
---|
184 | RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
|
---|
185 |
|
---|
186 |
|
---|
187 | /**
|
---|
188 | * Called to read @a cb bytes at @a off into @a pvBuf.
|
---|
189 | *
|
---|
190 | * @returns IPRT status code
|
---|
191 | * @param pvBuf The output buffer.
|
---|
192 | * @param cb The number of bytes to read.
|
---|
193 | * @param off Where to start reading.
|
---|
194 | * @param pvUser The user parameter.
|
---|
195 | */
|
---|
196 | typedef DECLCALLBACK(int) FNRTLDRRDRMEMREAD(void *pvBuf, size_t cb, size_t off, void *pvUser);
|
---|
197 | /** Pointer to a RTLdrOpenInMemory reader callback. */
|
---|
198 | typedef FNRTLDRRDRMEMREAD *PFNRTLDRRDRMEMREAD;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Called to when the module is unloaded (or done loading) to release resources
|
---|
202 | * associated with it (@a pvUser).
|
---|
203 | *
|
---|
204 | * @returns IPRT status code
|
---|
205 | * @param pvUser The user parameter.
|
---|
206 | */
|
---|
207 | typedef DECLCALLBACK(void) FNRTLDRRDRMEMDTOR(void *pvUser);
|
---|
208 | /** Pointer to a RTLdrOpenInMemory destructor callback. */
|
---|
209 | typedef FNRTLDRRDRMEMDTOR *PFNRTLDRRDRMEMDTOR;
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Open a in-memory image or an image with a custom reader callback.
|
---|
213 | *
|
---|
214 | * @returns IPRT status code.
|
---|
215 | * @param pszName The image name.
|
---|
216 | * @param fFlags Valid RTLDR_O_XXX combination.
|
---|
217 | * @param enmArch CPU architecture specifier for the image to be loaded.
|
---|
218 | * @param cbImage The size of the image (fake file).
|
---|
219 | * @param pfnRead The read function. If NULL is passed in, a default
|
---|
220 | * reader function is provided that assumes @a pvUser
|
---|
221 | * points to the raw image bits, at least @a cbImage of
|
---|
222 | * valid memory.
|
---|
223 | * @param pfnDtor The destructor function. If NULL is passed, a default
|
---|
224 | * destructor will be provided that passes @a pvUser to
|
---|
225 | * RTMemFree.
|
---|
226 | * @param pvUser The user argument or, if any of the callbacks are NULL,
|
---|
227 | * a pointer to a memory block.
|
---|
228 | * @param phLdrMod Where to return the module handle.
|
---|
229 | */
|
---|
230 | RTDECL(int) RTLdrOpenInMemory(const char *pszName, uint32_t fFlags, RTLDRARCH enmArch, size_t cbImage,
|
---|
231 | PFNRTLDRRDRMEMREAD pfnRead, PFNRTLDRRDRMEMDTOR pfnDtor, void *pvUser,
|
---|
232 | PRTLDRMOD phLdrMod);
|
---|
233 |
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Closes a loader module handle.
|
---|
237 | *
|
---|
238 | * The handle can be obtained using any of the RTLdrLoad(), RTLdrOpen()
|
---|
239 | * and RTLdrOpenInMemory() functions.
|
---|
240 | *
|
---|
241 | * @returns iprt status code.
|
---|
242 | * @param hLdrMod The loader module handle.
|
---|
243 | */
|
---|
244 | RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod);
|
---|
245 |
|
---|
246 | /**
|
---|
247 | * Gets the address of a named exported symbol.
|
---|
248 | *
|
---|
249 | * @returns iprt status code.
|
---|
250 | * @param hLdrMod The loader module handle.
|
---|
251 | * @param pszSymbol Symbol name.
|
---|
252 | * @param ppvValue Where to store the symbol value. Note that this is restricted to the
|
---|
253 | * pointer size used on the host!
|
---|
254 | */
|
---|
255 | RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);
|
---|
256 |
|
---|
257 | /**
|
---|
258 | * Gets the address of a named exported symbol.
|
---|
259 | *
|
---|
260 | * This function differs from the plain one in that it can deal with
|
---|
261 | * both GC and HC address sizes, and that it can calculate the symbol
|
---|
262 | * value relative to any given base address.
|
---|
263 | *
|
---|
264 | * @returns iprt status code.
|
---|
265 | * @param hLdrMod The loader module handle.
|
---|
266 | * @param pvBits Optional pointer to the loaded image.
|
---|
267 | * Set this to NULL if no RTLdrGetBits() processed image bits are available.
|
---|
268 | * Not supported for RTLdrLoad() images.
|
---|
269 | * @param BaseAddress Image load address.
|
---|
270 | * Not supported for RTLdrLoad() images.
|
---|
271 | * @param pszSymbol Symbol name.
|
---|
272 | * @param pValue Where to store the symbol value.
|
---|
273 | */
|
---|
274 | RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTLDRADDR BaseAddress, const char *pszSymbol,
|
---|
275 | PRTLDRADDR pValue);
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Gets the size of the loaded image.
|
---|
279 | *
|
---|
280 | * This is not necessarily available for images that has been loaded using
|
---|
281 | * RTLdrLoad().
|
---|
282 | *
|
---|
283 | * @returns image size (in bytes).
|
---|
284 | * @returns ~(size_t)0 on if not available.
|
---|
285 | * @param hLdrMod Handle to the loader module.
|
---|
286 | */
|
---|
287 | RTDECL(size_t) RTLdrSize(RTLDRMOD hLdrMod);
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Resolve an external symbol during RTLdrGetBits().
|
---|
291 | *
|
---|
292 | * @returns iprt status code.
|
---|
293 | * @param hLdrMod The loader module handle.
|
---|
294 | * @param pszModule Module name.
|
---|
295 | * @param pszSymbol Symbol name, NULL if uSymbol should be used.
|
---|
296 | * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
|
---|
297 | * @param pValue Where to store the symbol value (address).
|
---|
298 | * @param pvUser User argument.
|
---|
299 | */
|
---|
300 | typedef DECLCALLBACK(int) RTLDRIMPORT(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol,
|
---|
301 | PRTLDRADDR pValue, void *pvUser);
|
---|
302 | /** Pointer to a FNRTLDRIMPORT() callback function. */
|
---|
303 | typedef RTLDRIMPORT *PFNRTLDRIMPORT;
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Loads the image into a buffer provided by the user and applies fixups
|
---|
307 | * for the given base address.
|
---|
308 | *
|
---|
309 | * @returns iprt status code.
|
---|
310 | * @param hLdrMod The load module handle.
|
---|
311 | * @param pvBits Where to put the bits.
|
---|
312 | * Must be as large as RTLdrSize() suggests.
|
---|
313 | * @param BaseAddress The base address.
|
---|
314 | * @param pfnGetImport Callback function for resolving imports one by one.
|
---|
315 | * @param pvUser User argument for the callback.
|
---|
316 | * @remark Not supported for RTLdrLoad() images.
|
---|
317 | */
|
---|
318 | RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Relocates bits after getting them.
|
---|
322 | * Useful for code which moves around a bit.
|
---|
323 | *
|
---|
324 | * @returns iprt status code.
|
---|
325 | * @param hLdrMod The loader module handle.
|
---|
326 | * @param pvBits Where the image bits are.
|
---|
327 | * Must have been passed to RTLdrGetBits().
|
---|
328 | * @param NewBaseAddress The new base address.
|
---|
329 | * @param OldBaseAddress The old base address.
|
---|
330 | * @param pfnGetImport Callback function for resolving imports one by one.
|
---|
331 | * @param pvUser User argument for the callback.
|
---|
332 | * @remark Not supported for RTLdrLoad() images.
|
---|
333 | */
|
---|
334 | RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR NewBaseAddress, RTLDRADDR OldBaseAddress,
|
---|
335 | PFNRTLDRIMPORT pfnGetImport, void *pvUser);
|
---|
336 |
|
---|
337 | /**
|
---|
338 | * Enumeration callback function used by RTLdrEnumSymbols().
|
---|
339 | *
|
---|
340 | * @returns iprt status code. Failure will stop the enumeration.
|
---|
341 | * @param hLdrMod The loader module handle.
|
---|
342 | * @param pszSymbol Symbol name. NULL if ordinal only.
|
---|
343 | * @param uSymbol Symbol ordinal, ~0 if not used.
|
---|
344 | * @param Value Symbol value.
|
---|
345 | * @param pvUser The user argument specified to RTLdrEnumSymbols().
|
---|
346 | */
|
---|
347 | typedef DECLCALLBACK(int) RTLDRENUMSYMS(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTLDRADDR Value, void *pvUser);
|
---|
348 | /** Pointer to a RTLDRENUMSYMS() callback function. */
|
---|
349 | typedef RTLDRENUMSYMS *PFNRTLDRENUMSYMS;
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * Enumerates all symbols in a module.
|
---|
353 | *
|
---|
354 | * @returns iprt status code.
|
---|
355 | * @param hLdrMod The loader module handle.
|
---|
356 | * @param fFlags Flags indicating what to return and such.
|
---|
357 | * @param pvBits Optional pointer to the loaded image. (RTLDR_ENUM_SYMBOL_FLAGS_*)
|
---|
358 | * Set this to NULL if no RTLdrGetBits() processed image bits are available.
|
---|
359 | * @param BaseAddress Image load address.
|
---|
360 | * @param pfnCallback Callback function.
|
---|
361 | * @param pvUser User argument for the callback.
|
---|
362 | * @remark Not supported for RTLdrLoad() images.
|
---|
363 | */
|
---|
364 | RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTLDRADDR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
|
---|
365 |
|
---|
366 | /** @name RTLdrEnumSymbols flags.
|
---|
367 | * @{ */
|
---|
368 | /** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
|
---|
369 | #define RTLDR_ENUM_SYMBOL_FLAGS_ALL RT_BIT(1)
|
---|
370 | /** @} */
|
---|
371 |
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Debug info type (as far the loader can tell).
|
---|
375 | */
|
---|
376 | typedef enum RTLDRDBGINFOTYPE
|
---|
377 | {
|
---|
378 | /** The invalid 0 value. */
|
---|
379 | RTLDRDBGINFOTYPE_INVALID = 0,
|
---|
380 | /** Unknown debug info format. */
|
---|
381 | RTLDRDBGINFOTYPE_UNKNOWN,
|
---|
382 | /** Stabs. */
|
---|
383 | RTLDRDBGINFOTYPE_STABS,
|
---|
384 | /** Debug With Arbitrary Record Format (DWARF). */
|
---|
385 | RTLDRDBGINFOTYPE_DWARF,
|
---|
386 | /** Debug With Arbitrary Record Format (DWARF), in external file (DWO). */
|
---|
387 | RTLDRDBGINFOTYPE_DWARF_DWO,
|
---|
388 | /** Microsoft Codeview debug info. */
|
---|
389 | RTLDRDBGINFOTYPE_CODEVIEW,
|
---|
390 | /** Microsoft Codeview debug info, in external v2.0+ program database (PDB). */
|
---|
391 | RTLDRDBGINFOTYPE_CODEVIEW_PDB20,
|
---|
392 | /** Microsoft Codeview debug info, in external v7.0+ program database (PDB). */
|
---|
393 | RTLDRDBGINFOTYPE_CODEVIEW_PDB70,
|
---|
394 | /** Microsoft Codeview debug info, in external file (DBG). */
|
---|
395 | RTLDRDBGINFOTYPE_CODEVIEW_DBG,
|
---|
396 | /** Watcom debug info. */
|
---|
397 | RTLDRDBGINFOTYPE_WATCOM,
|
---|
398 | /** IBM High Level Language debug info.. */
|
---|
399 | RTLDRDBGINFOTYPE_HLL,
|
---|
400 | /** The end of the valid debug info values (exclusive). */
|
---|
401 | RTLDRDBGINFOTYPE_END,
|
---|
402 | /** Blow the type up to 32-bits. */
|
---|
403 | RTLDRDBGINFOTYPE_32BIT_HACK = 0x7fffffff
|
---|
404 | } RTLDRDBGINFOTYPE;
|
---|
405 |
|
---|
406 |
|
---|
407 | /**
|
---|
408 | * Debug info details for the enumeration callback.
|
---|
409 | */
|
---|
410 | typedef struct RTLDRDBGINFO
|
---|
411 | {
|
---|
412 | /** The kind of debug info. */
|
---|
413 | RTLDRDBGINFOTYPE enmType;
|
---|
414 | /** The debug info ordinal number / id. */
|
---|
415 | uint32_t iDbgInfo;
|
---|
416 | /** The file offset *if* this type has one specific location in the executable
|
---|
417 | * image file. This is -1 if there isn't any specific file location. */
|
---|
418 | RTFOFF offFile;
|
---|
419 | /** The link address of the debug info if it's loadable. NIL_RTLDRADDR if not
|
---|
420 | * loadable*/
|
---|
421 | RTLDRADDR LinkAddress;
|
---|
422 | /** The size of the debug information. -1 is used if this isn't applicable.*/
|
---|
423 | RTLDRADDR cb;
|
---|
424 | /** This is set if the debug information is found in an external file. NULL
|
---|
425 | * if no external file involved.
|
---|
426 | * @note Putting it outside the union to allow lazy callback implementation. */
|
---|
427 | const char *pszExtFile;
|
---|
428 | /** Type (enmType) specific information. */
|
---|
429 | union
|
---|
430 | {
|
---|
431 | /** RTLDRDBGINFOTYPE_DWARF */
|
---|
432 | struct
|
---|
433 | {
|
---|
434 | /** The section name. */
|
---|
435 | const char *pszSection;
|
---|
436 | } Dwarf;
|
---|
437 |
|
---|
438 | /** RTLDRDBGINFOTYPE_DWARF_DWO */
|
---|
439 | struct
|
---|
440 | {
|
---|
441 | /** The CRC32 of the external file. */
|
---|
442 | uint32_t uCrc32;
|
---|
443 | } Dwo;
|
---|
444 |
|
---|
445 | /** RTLDRDBGINFOTYPE_CODEVIEW_PDB20, RTLDRDBGINFOTYPE_CODEVIEW_DBG */
|
---|
446 | struct
|
---|
447 | {
|
---|
448 | /** The PE image size. */
|
---|
449 | uint32_t cbImage;
|
---|
450 | /** The timestamp. */
|
---|
451 | uint32_t uTimestamp;
|
---|
452 | /** The major version from the entry. */
|
---|
453 | uint32_t uMajorVer;
|
---|
454 | /** The minor version from the entry. */
|
---|
455 | uint32_t uMinorVer;
|
---|
456 | } Cv;
|
---|
457 |
|
---|
458 | /** RTLDRDBGINFOTYPE_CODEVIEW_DBG */
|
---|
459 | struct
|
---|
460 | {
|
---|
461 | /** The PE image size. */
|
---|
462 | uint32_t cbImage;
|
---|
463 | /** The timestamp. */
|
---|
464 | uint32_t uTimestamp;
|
---|
465 | } Dbg;
|
---|
466 |
|
---|
467 | /** RTLDRDBGINFOTYPE_CODEVIEW_PDB20*/
|
---|
468 | struct
|
---|
469 | {
|
---|
470 | /** The PE image size. */
|
---|
471 | uint32_t cbImage;
|
---|
472 | /** The timestamp. */
|
---|
473 | uint32_t uTimestamp;
|
---|
474 | /** The PDB age. */
|
---|
475 | uint32_t uAge;
|
---|
476 | } Pdb20;
|
---|
477 |
|
---|
478 | /** RTLDRDBGINFOTYPE_CODEVIEW_PDB70 */
|
---|
479 | struct
|
---|
480 | {
|
---|
481 | /** The PE image size. */
|
---|
482 | uint32_t cbImage;
|
---|
483 | /** The PDB age. */
|
---|
484 | uint32_t uAge;
|
---|
485 | /** The UUID. */
|
---|
486 | RTUUID Uuid;
|
---|
487 | } Pdb70;
|
---|
488 | } u;
|
---|
489 | } RTLDRDBGINFO;
|
---|
490 | /** Pointer to debug info details. */
|
---|
491 | typedef RTLDRDBGINFO *PRTLDRDBGINFO;
|
---|
492 | /** Pointer to read only debug info details. */
|
---|
493 | typedef RTLDRDBGINFO const *PCRTLDRDBGINFO;
|
---|
494 |
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * Debug info enumerator callback.
|
---|
498 | *
|
---|
499 | * @returns VINF_SUCCESS to continue the enumeration. Any other status code
|
---|
500 | * will cause RTLdrEnumDbgInfo to immediately return with that status.
|
---|
501 | *
|
---|
502 | * @param hLdrMod The module handle.
|
---|
503 | * @param pDbgInfo Pointer to a read only structure with the details.
|
---|
504 | * @param pvUser The user parameter specified to RTLdrEnumDbgInfo.
|
---|
505 | */
|
---|
506 | typedef DECLCALLBACK(int) FNRTLDRENUMDBG(RTLDRMOD hLdrMod, PCRTLDRDBGINFO pDbgInfo, void *pvUser);
|
---|
507 | /** Pointer to a debug info enumerator callback. */
|
---|
508 | typedef FNRTLDRENUMDBG *PFNRTLDRENUMDBG;
|
---|
509 |
|
---|
510 | /**
|
---|
511 | * Enumerate the debug info contained in the executable image.
|
---|
512 | *
|
---|
513 | * @returns IPRT status code or whatever pfnCallback returns.
|
---|
514 | *
|
---|
515 | * @param hLdrMod The module handle.
|
---|
516 | * @param pvBits Optional pointer to bits returned by
|
---|
517 | * RTLdrGetBits(). This can be used by some module
|
---|
518 | * interpreters to reduce memory consumption.
|
---|
519 | * @param pfnCallback The callback function.
|
---|
520 | * @param pvUser The user argument.
|
---|
521 | */
|
---|
522 | RTDECL(int) RTLdrEnumDbgInfo(RTLDRMOD hLdrMod, const void *pvBits, PFNRTLDRENUMDBG pfnCallback, void *pvUser);
|
---|
523 |
|
---|
524 |
|
---|
525 | /**
|
---|
526 | * Loader segment.
|
---|
527 | */
|
---|
528 | typedef struct RTLDRSEG
|
---|
529 | {
|
---|
530 | /** The segment name. (Might not be zero terminated!) */
|
---|
531 | const char *pchName;
|
---|
532 | /** The length of the segment name. */
|
---|
533 | uint32_t cchName;
|
---|
534 | /** The flat selector to use for the segment (i.e. data/code).
|
---|
535 | * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
|
---|
536 | uint16_t SelFlat;
|
---|
537 | /** The 16-bit selector to use for the segment.
|
---|
538 | * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
|
---|
539 | uint16_t Sel16bit;
|
---|
540 | /** Segment flags. */
|
---|
541 | uint32_t fFlags;
|
---|
542 | /** The segment protection (RTMEM_PROT_XXX). */
|
---|
543 | uint32_t fProt;
|
---|
544 | /** The size of the segment. */
|
---|
545 | RTLDRADDR cb;
|
---|
546 | /** The required segment alignment.
|
---|
547 | * The to 0 if the segment isn't supposed to be mapped. */
|
---|
548 | RTLDRADDR Alignment;
|
---|
549 | /** The link address.
|
---|
550 | * Set to NIL_RTLDRADDR if the segment isn't supposed to be mapped or if
|
---|
551 | * the image doesn't have link addresses. */
|
---|
552 | RTLDRADDR LinkAddress;
|
---|
553 | /** File offset of the segment.
|
---|
554 | * Set to -1 if no file backing (like BSS). */
|
---|
555 | RTFOFF offFile;
|
---|
556 | /** Size of the file bits of the segment.
|
---|
557 | * Set to -1 if no file backing (like BSS). */
|
---|
558 | RTFOFF cbFile;
|
---|
559 | /** The relative virtual address when mapped.
|
---|
560 | * Set to NIL_RTLDRADDR if the segment isn't supposed to be mapped. */
|
---|
561 | RTLDRADDR RVA;
|
---|
562 | /** The size of the segment including the alignment gap up to the next segment when mapped.
|
---|
563 | * This is set to NIL_RTLDRADDR if not implemented. */
|
---|
564 | RTLDRADDR cbMapped;
|
---|
565 | } RTLDRSEG;
|
---|
566 | /** Pointer to a loader segment. */
|
---|
567 | typedef RTLDRSEG *PRTLDRSEG;
|
---|
568 | /** Pointer to a read only loader segment. */
|
---|
569 | typedef RTLDRSEG const *PCRTLDRSEG;
|
---|
570 |
|
---|
571 |
|
---|
572 | /** @name Segment flags
|
---|
573 | * @{ */
|
---|
574 | /** The segment is 16-bit. When not set the default of the target architecture is assumed. */
|
---|
575 | #define RTLDRSEG_FLAG_16BIT UINT32_C(1)
|
---|
576 | /** The segment requires a 16-bit selector alias. (OS/2) */
|
---|
577 | #define RTLDRSEG_FLAG_OS2_ALIAS16 UINT32_C(2)
|
---|
578 | /** Conforming segment (x86 weirdness). (OS/2) */
|
---|
579 | #define RTLDRSEG_FLAG_OS2_CONFORM UINT32_C(4)
|
---|
580 | /** IOPL (ring-2) segment. (OS/2) */
|
---|
581 | #define RTLDRSEG_FLAG_OS2_IOPL UINT32_C(8)
|
---|
582 | /** @} */
|
---|
583 |
|
---|
584 | /**
|
---|
585 | * Segment enumerator callback.
|
---|
586 | *
|
---|
587 | * @returns VINF_SUCCESS to continue the enumeration. Any other status code
|
---|
588 | * will cause RTLdrEnumSegments to immediately return with that
|
---|
589 | * status.
|
---|
590 | *
|
---|
591 | * @param hLdrMod The module handle.
|
---|
592 | * @param pSeg The segment information.
|
---|
593 | * @param pvUser The user parameter specified to RTLdrEnumSegments.
|
---|
594 | */
|
---|
595 | typedef DECLCALLBACK(int) FNRTLDRENUMSEGS(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser);
|
---|
596 | /** Pointer to a segment enumerator callback. */
|
---|
597 | typedef FNRTLDRENUMSEGS *PFNRTLDRENUMSEGS;
|
---|
598 |
|
---|
599 | /**
|
---|
600 | * Enumerate the debug info contained in the executable image.
|
---|
601 | *
|
---|
602 | * @returns IPRT status code or whatever pfnCallback returns.
|
---|
603 | *
|
---|
604 | * @param hLdrMod The module handle.
|
---|
605 | * @param pfnCallback The callback function.
|
---|
606 | * @param pvUser The user argument.
|
---|
607 | */
|
---|
608 | RTDECL(int) RTLdrEnumSegments(RTLDRMOD hLdrMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser);
|
---|
609 |
|
---|
610 | /**
|
---|
611 | * Converts a link address to a segment:offset address.
|
---|
612 | *
|
---|
613 | * @returns IPRT status code.
|
---|
614 | *
|
---|
615 | * @param hLdrMod The module handle.
|
---|
616 | * @param LinkAddress The link address to convert.
|
---|
617 | * @param piSeg Where to return the segment index.
|
---|
618 | * @param poffSeg Where to return the segment offset.
|
---|
619 | */
|
---|
620 | RTDECL(int) RTLdrLinkAddressToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, uint32_t *piSeg, PRTLDRADDR poffSeg);
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Converts a link address to an image relative virtual address (RVA).
|
---|
624 | *
|
---|
625 | * @returns IPRT status code.
|
---|
626 | *
|
---|
627 | * @param hLdrMod The module handle.
|
---|
628 | * @param LinkAddress The link address to convert.
|
---|
629 | * @param pRva Where to return the RVA.
|
---|
630 | */
|
---|
631 | RTDECL(int) RTLdrLinkAddressToRva(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva);
|
---|
632 |
|
---|
633 | /**
|
---|
634 | * Converts an image relative virtual address (RVA) to a segment:offset.
|
---|
635 | *
|
---|
636 | * @returns IPRT status code.
|
---|
637 | *
|
---|
638 | * @param hLdrMod The module handle.
|
---|
639 | * @param Rva The link address to convert.
|
---|
640 | * @param piSeg Where to return the segment index.
|
---|
641 | * @param poffSeg Where to return the segment offset.
|
---|
642 | */
|
---|
643 | RTDECL(int) RTLdrSegOffsetToRva(RTLDRMOD hLdrMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva);
|
---|
644 |
|
---|
645 | /**
|
---|
646 | * Converts a segment:offset into an image relative virtual address (RVA).
|
---|
647 | *
|
---|
648 | * @returns IPRT status code.
|
---|
649 | *
|
---|
650 | * @param hLdrMod The module handle.
|
---|
651 | * @param iSeg The segment index.
|
---|
652 | * @param offSeg The segment offset.
|
---|
653 | * @param pRva Where to return the RVA.
|
---|
654 | */
|
---|
655 | RTDECL(int) RTLdrRvaToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg);
|
---|
656 |
|
---|
657 | RT_C_DECLS_END
|
---|
658 |
|
---|
659 | /** @} */
|
---|
660 |
|
---|
661 | #endif
|
---|
662 |
|
---|