VirtualBox

source: vbox/trunk/include/iprt/ldr.h@ 46252

Last change on this file since 46252 was 46164, checked in by vboxsync, 12 years ago

More exteran .dSYM and .dwo bundles/files changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.3 KB
Line 
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
39RT_C_DECLS_BEGIN
40
41/** Loader address (unsigned integer). */
42typedef RTUINTPTR RTLDRADDR;
43/** Pointer to a loader address. */
44typedef RTLDRADDR *PRTLDRADDR;
45/** Pointer to a const loader address. */
46typedef 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 * Loader module format.
55 */
56typedef enum RTLDRFMT
57{
58 /** The usual invalid 0 format. */
59 RTLDRFMT_INVALID = 0,
60 /** The native OS loader. */
61 RTLDRFMT_NATIVE,
62 /** The AOUT loader. */
63 RTLDRFMT_AOUT,
64 /** The ELF loader. */
65 RTLDRFMT_ELF,
66 /** The LX loader. */
67 RTLDRFMT_LX,
68 /** The Mach-O loader. */
69 RTLDRFMT_MACHO,
70 /** The PE loader. */
71 RTLDRFMT_PE,
72 /** The end of the valid format values (exclusive). */
73 RTLDRFMT_END,
74 /** Hack to blow the type up to 32-bit. */
75 RTLDRFMT_32BIT_HACK = 0x7fffffff
76} RTLDRFMT;
77
78
79/**
80 * Loader module type.
81 */
82typedef enum RTLDRTYPE
83{
84 /** The usual invalid 0 type. */
85 RTLDRTYPE_INVALID = 0,
86 /** Object file. */
87 RTLDRTYPE_OBJECT,
88 /** Executable module, fixed load address. */
89 RTLDRTYPE_EXECUTABLE_FIXED,
90 /** Executable module, relocatable, non-fixed load address. */
91 RTLDRTYPE_EXECUTABLE_RELOCATABLE,
92 /** Executable module, position independent code, non-fixed load address. */
93 RTLDRTYPE_EXECUTABLE_PIC,
94 /** Shared library, fixed load address.
95 * Typically a system library. */
96 RTLDRTYPE_SHARED_LIBRARY_FIXED,
97 /** Shared library, relocatable, non-fixed load address. */
98 RTLDRTYPE_SHARED_LIBRARY_RELOCATABLE,
99 /** Shared library, position independent code, non-fixed load address. */
100 RTLDRTYPE_SHARED_LIBRARY_PIC,
101 /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */
102 RTLDRTYPE_FORWARDER_DLL,
103 /** Core or dump. */
104 RTLDRTYPE_CORE,
105 /** Debug module (debug info with empty code & data segments). */
106 RTLDRTYPE_DEBUG_INFO,
107 /** The end of the valid types values (exclusive). */
108 RTLDRTYPE_END,
109 /** Hack to blow the type up to 32-bit. */
110 RTLDRTYPE_32BIT_HACK = 0x7fffffff
111} RTLDRTYPE;
112
113
114/**
115 * Loader endian indicator.
116 */
117typedef enum RTLDRENDIAN
118{
119 /** The usual invalid endian. */
120 RTLDRENDIAN_INVALID,
121 /** Little endian. */
122 RTLDRENDIAN_LITTLE,
123 /** Bit endian. */
124 RTLDRENDIAN_BIG,
125 /** Endianness doesn't have a meaning in the context. */
126 RTLDRENDIAN_NA,
127 /** The end of the valid endian values (exclusive). */
128 RTLDRENDIAN_END,
129 /** Hack to blow the type up to 32-bit. */
130 RTLDRENDIAN_32BIT_HACK = 0x7fffffff
131} RTLDRENDIAN;
132
133
134/**
135 * Gets the default file suffix for DLL/SO/DYLIB/whatever.
136 *
137 * @returns The stuff (readonly).
138 */
139RTDECL(const char *) RTLdrGetSuff(void);
140
141/**
142 * Checks if a library is loadable or not.
143 *
144 * This may attempt load and unload the library.
145 *
146 * @returns true/false accordingly.
147 * @param pszFilename Image filename.
148 */
149RTDECL(bool) RTLdrIsLoadable(const char *pszFilename);
150
151/**
152 * Loads a dynamic load library (/shared object) image file using native
153 * OS facilities.
154 *
155 * The filename will be appended the default DLL/SO extension of
156 * the platform if it have been omitted. This means that it's not
157 * possible to load DLLs/SOs with no extension using this interface,
158 * but that's not a bad tradeoff.
159 *
160 * If no path is specified in the filename, the OS will usually search it's library
161 * path to find the image file.
162 *
163 * @returns iprt status code.
164 * @param pszFilename Image filename.
165 * @param phLdrMod Where to store the handle to the loader module.
166 */
167RTDECL(int) RTLdrLoad(const char *pszFilename, PRTLDRMOD phLdrMod);
168
169/**
170 * Loads a dynamic load library (/shared object) image file using native
171 * OS facilities.
172 *
173 * The filename will be appended the default DLL/SO extension of
174 * the platform if it have been omitted. This means that it's not
175 * possible to load DLLs/SOs with no extension using this interface,
176 * but that's not a bad tradeoff.
177 *
178 * If no path is specified in the filename, the OS will usually search it's library
179 * path to find the image file.
180 *
181 * @returns iprt status code.
182 * @param pszFilename Image filename.
183 * @param phLdrMod Where to store the handle to the loader module.
184 * @param fFlags See RTLDRLOAD_FLAGS_XXX.
185 * @param pErrInfo Where to return extended error information. Optional.
186 */
187RTDECL(int) RTLdrLoadEx(const char *pszFilename, PRTLDRMOD phLdrMod, uint32_t fFlags, PRTERRINFO pErrInfo);
188
189/** @defgroup RTLDRLOAD_FLAGS_XXX RTLdrLoadEx flags.
190 * @{ */
191/** Symbols defined in this library are not made available to resolve
192 * references in subsequently loaded libraries (default). */
193#define RTLDRLOAD_FLAGS_LOCAL UINT32_C(0)
194/** Symbols defined in this library will be made available for symbol
195 * resolution of subsequently loaded libraries. */
196#define RTLDRLOAD_FLAGS_GLOBAL RT_BIT_32(0)
197/** The mask of valid flag bits. */
198#define RTLDRLOAD_FLAGS_VALID_MASK UINT32_C(0x00000001)
199/** @} */
200
201/**
202 * Loads a dynamic load library (/shared object) image file residing in the
203 * RTPathAppPrivateArch() directory.
204 *
205 * Suffix is not required.
206 *
207 * @returns iprt status code.
208 * @param pszFilename Image filename. No path.
209 * @param phLdrMod Where to store the handle to the loaded module.
210 */
211RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod);
212
213/**
214 * Image architecuture specifier for RTLdrOpenEx.
215 */
216typedef enum RTLDRARCH
217{
218 RTLDRARCH_INVALID = 0,
219 /** Whatever. */
220 RTLDRARCH_WHATEVER,
221 /** The host architecture. */
222 RTLDRARCH_HOST,
223 /** 32-bit x86. */
224 RTLDRARCH_X86_32,
225 /** AMD64 (64-bit x86 if you like). */
226 RTLDRARCH_AMD64,
227 /** End of the valid values. */
228 RTLDRARCH_END,
229 /** Make sure the type is a full 32-bit. */
230 RTLDRARCH_32BIT_HACK = 0x7fffffff
231} RTLDRARCH;
232/** Pointer to a RTLDRARCH. */
233typedef RTLDRARCH *PRTLDRARCH;
234
235/** @name RTLDR_O_XXX - RTLdrOpen flags.
236 * @{ */
237/** Open for debugging or introspection reasons.
238 * This will skip a few of the stricter validations when loading images. */
239#define RTLDR_O_FOR_DEBUG RT_BIT_32(0)
240/** Mask of valid flags. */
241#define RTLDR_O_VALID_MASK UINT32_C(0x00000001)
242/** @} */
243
244/**
245 * Open a binary image file, extended version.
246 *
247 * @returns iprt status code.
248 * @param pszFilename Image filename.
249 * @param fFlags Valid RTLDR_O_XXX combination.
250 * @param enmArch CPU architecture specifier for the image to be loaded.
251 * @param phLdrMod Where to store the handle to the loader module.
252 */
253RTDECL(int) RTLdrOpen(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
254
255/**
256 * Opens a binary image file using kLdr.
257 *
258 * @returns iprt status code.
259 * @param pszFilename Image filename.
260 * @param phLdrMod Where to store the handle to the loaded module.
261 * @param fFlags Valid RTLDR_O_XXX combination.
262 * @param enmArch CPU architecture specifier for the image to be loaded.
263 * @remark Primarily for testing the loader.
264 */
265RTDECL(int) RTLdrOpenkLdr(const char *pszFilename, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod);
266
267
268/**
269 * Called to read @a cb bytes at @a off into @a pvBuf.
270 *
271 * @returns IPRT status code
272 * @param pvBuf The output buffer.
273 * @param cb The number of bytes to read.
274 * @param off Where to start reading.
275 * @param pvUser The user parameter.
276 */
277typedef DECLCALLBACK(int) FNRTLDRRDRMEMREAD(void *pvBuf, size_t cb, size_t off, void *pvUser);
278/** Pointer to a RTLdrOpenInMemory reader callback. */
279typedef FNRTLDRRDRMEMREAD *PFNRTLDRRDRMEMREAD;
280
281/**
282 * Called to when the module is unloaded (or done loading) to release resources
283 * associated with it (@a pvUser).
284 *
285 * @returns IPRT status code
286 * @param pvUser The user parameter.
287 */
288typedef DECLCALLBACK(void) FNRTLDRRDRMEMDTOR(void *pvUser);
289/** Pointer to a RTLdrOpenInMemory destructor callback. */
290typedef FNRTLDRRDRMEMDTOR *PFNRTLDRRDRMEMDTOR;
291
292/**
293 * Open a in-memory image or an image with a custom reader callback.
294 *
295 * @returns IPRT status code.
296 * @param pszName The image name.
297 * @param fFlags Valid RTLDR_O_XXX combination.
298 * @param enmArch CPU architecture specifier for the image to be loaded.
299 * @param cbImage The size of the image (fake file).
300 * @param pfnRead The read function. If NULL is passed in, a default
301 * reader function is provided that assumes @a pvUser
302 * points to the raw image bits, at least @a cbImage of
303 * valid memory.
304 * @param pfnDtor The destructor function. If NULL is passed, a default
305 * destructor will be provided that passes @a pvUser to
306 * RTMemFree.
307 * @param pvUser The user argument or, if any of the callbacks are NULL,
308 * a pointer to a memory block.
309 * @param phLdrMod Where to return the module handle.
310 *
311 * @remarks With the exception of invalid @a pfnDtor and/or @a pvUser
312 * parameters, the pfnDtor methods (or the default one if NULL) will
313 * always be invoked. The destruction of pvUser is entirely in the
314 * hands of this method once it's called.
315 */
316RTDECL(int) RTLdrOpenInMemory(const char *pszName, uint32_t fFlags, RTLDRARCH enmArch, size_t cbImage,
317 PFNRTLDRRDRMEMREAD pfnRead, PFNRTLDRRDRMEMDTOR pfnDtor, void *pvUser,
318 PRTLDRMOD phLdrMod);
319
320/**
321 * Closes a loader module handle.
322 *
323 * The handle can be obtained using any of the RTLdrLoad(), RTLdrOpen()
324 * and RTLdrOpenInMemory() functions.
325 *
326 * @returns iprt status code.
327 * @param hLdrMod The loader module handle.
328 */
329RTDECL(int) RTLdrClose(RTLDRMOD hLdrMod);
330
331/**
332 * Gets the address of a named exported symbol.
333 *
334 * @returns iprt status code.
335 * @param hLdrMod The loader module handle.
336 * @param pszSymbol Symbol name.
337 * @param ppvValue Where to store the symbol value. Note that this is restricted to the
338 * pointer size used on the host!
339 */
340RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);
341
342/**
343 * Gets the address of a named exported symbol.
344 *
345 * This function differs from the plain one in that it can deal with
346 * both GC and HC address sizes, and that it can calculate the symbol
347 * value relative to any given base address.
348 *
349 * @returns iprt status code.
350 * @param hLdrMod The loader module handle.
351 * @param pvBits Optional pointer to the loaded image.
352 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
353 * Not supported for RTLdrLoad() images.
354 * @param BaseAddress Image load address.
355 * Not supported for RTLdrLoad() images.
356 * @param pszSymbol Symbol name.
357 * @param pValue Where to store the symbol value.
358 */
359RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTLDRADDR BaseAddress, const char *pszSymbol,
360 PRTLDRADDR pValue);
361
362/**
363 * Gets the size of the loaded image.
364 *
365 * This is not necessarily available for images that has been loaded using
366 * RTLdrLoad().
367 *
368 * @returns image size (in bytes).
369 * @returns ~(size_t)0 on if not available.
370 * @param hLdrMod Handle to the loader module.
371 */
372RTDECL(size_t) RTLdrSize(RTLDRMOD hLdrMod);
373
374/**
375 * Resolve an external symbol during RTLdrGetBits().
376 *
377 * @returns iprt status code.
378 * @param hLdrMod The loader module handle.
379 * @param pszModule Module name.
380 * @param pszSymbol Symbol name, NULL if uSymbol should be used.
381 * @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
382 * @param pValue Where to store the symbol value (address).
383 * @param pvUser User argument.
384 */
385typedef DECLCALLBACK(int) RTLDRIMPORT(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol,
386 PRTLDRADDR pValue, void *pvUser);
387/** Pointer to a FNRTLDRIMPORT() callback function. */
388typedef RTLDRIMPORT *PFNRTLDRIMPORT;
389
390/**
391 * Loads the image into a buffer provided by the user and applies fixups
392 * for the given base address.
393 *
394 * @returns iprt status code.
395 * @param hLdrMod The load module handle.
396 * @param pvBits Where to put the bits.
397 * Must be as large as RTLdrSize() suggests.
398 * @param BaseAddress The base address.
399 * @param pfnGetImport Callback function for resolving imports one by one.
400 * @param pvUser User argument for the callback.
401 * @remark Not supported for RTLdrLoad() images.
402 */
403RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
404
405/**
406 * Relocates bits after getting them.
407 * Useful for code which moves around a bit.
408 *
409 * @returns iprt status code.
410 * @param hLdrMod The loader module handle.
411 * @param pvBits Where the image bits are.
412 * Must have been passed to RTLdrGetBits().
413 * @param NewBaseAddress The new base address.
414 * @param OldBaseAddress The old base address.
415 * @param pfnGetImport Callback function for resolving imports one by one.
416 * @param pvUser User argument for the callback.
417 * @remark Not supported for RTLdrLoad() images.
418 */
419RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTLDRADDR NewBaseAddress, RTLDRADDR OldBaseAddress,
420 PFNRTLDRIMPORT pfnGetImport, void *pvUser);
421
422/**
423 * Enumeration callback function used by RTLdrEnumSymbols().
424 *
425 * @returns iprt status code. Failure will stop the enumeration.
426 * @param hLdrMod The loader module handle.
427 * @param pszSymbol Symbol name. NULL if ordinal only.
428 * @param uSymbol Symbol ordinal, ~0 if not used.
429 * @param Value Symbol value.
430 * @param pvUser The user argument specified to RTLdrEnumSymbols().
431 */
432typedef DECLCALLBACK(int) RTLDRENUMSYMS(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTLDRADDR Value, void *pvUser);
433/** Pointer to a RTLDRENUMSYMS() callback function. */
434typedef RTLDRENUMSYMS *PFNRTLDRENUMSYMS;
435
436/**
437 * Enumerates all symbols in a module.
438 *
439 * @returns iprt status code.
440 * @param hLdrMod The loader module handle.
441 * @param fFlags Flags indicating what to return and such.
442 * @param pvBits Optional pointer to the loaded image. (RTLDR_ENUM_SYMBOL_FLAGS_*)
443 * Set this to NULL if no RTLdrGetBits() processed image bits are available.
444 * @param BaseAddress Image load address.
445 * @param pfnCallback Callback function.
446 * @param pvUser User argument for the callback.
447 * @remark Not supported for RTLdrLoad() images.
448 */
449RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTLDRADDR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
450
451/** @name RTLdrEnumSymbols flags.
452 * @{ */
453/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
454#define RTLDR_ENUM_SYMBOL_FLAGS_ALL RT_BIT(1)
455/** Ignore forwarders (for use with RTLDR_ENUM_SYMBOL_FLAGS_ALL). */
456#define RTLDR_ENUM_SYMBOL_FLAGS_NO_FWD RT_BIT(2)
457/** @} */
458
459
460/**
461 * Debug info type (as far the loader can tell).
462 */
463typedef enum RTLDRDBGINFOTYPE
464{
465 /** The invalid 0 value. */
466 RTLDRDBGINFOTYPE_INVALID = 0,
467 /** Unknown debug info format. */
468 RTLDRDBGINFOTYPE_UNKNOWN,
469 /** Stabs. */
470 RTLDRDBGINFOTYPE_STABS,
471 /** Debug With Arbitrary Record Format (DWARF). */
472 RTLDRDBGINFOTYPE_DWARF,
473 /** Debug With Arbitrary Record Format (DWARF), in external file (DWO). */
474 RTLDRDBGINFOTYPE_DWARF_DWO,
475 /** Microsoft Codeview debug info. */
476 RTLDRDBGINFOTYPE_CODEVIEW,
477 /** Microsoft Codeview debug info, in external v2.0+ program database (PDB). */
478 RTLDRDBGINFOTYPE_CODEVIEW_PDB20,
479 /** Microsoft Codeview debug info, in external v7.0+ program database (PDB). */
480 RTLDRDBGINFOTYPE_CODEVIEW_PDB70,
481 /** Microsoft Codeview debug info, in external file (DBG). */
482 RTLDRDBGINFOTYPE_CODEVIEW_DBG,
483 /** Watcom debug info. */
484 RTLDRDBGINFOTYPE_WATCOM,
485 /** IBM High Level Language debug info.. */
486 RTLDRDBGINFOTYPE_HLL,
487 /** The end of the valid debug info values (exclusive). */
488 RTLDRDBGINFOTYPE_END,
489 /** Blow the type up to 32-bits. */
490 RTLDRDBGINFOTYPE_32BIT_HACK = 0x7fffffff
491} RTLDRDBGINFOTYPE;
492
493
494/**
495 * Debug info details for the enumeration callback.
496 */
497typedef struct RTLDRDBGINFO
498{
499 /** The kind of debug info. */
500 RTLDRDBGINFOTYPE enmType;
501 /** The debug info ordinal number / id. */
502 uint32_t iDbgInfo;
503 /** The file offset *if* this type has one specific location in the executable
504 * image file. This is -1 if there isn't any specific file location. */
505 RTFOFF offFile;
506 /** The link address of the debug info if it's loadable. NIL_RTLDRADDR if not
507 * loadable*/
508 RTLDRADDR LinkAddress;
509 /** The size of the debug information. -1 is used if this isn't applicable.*/
510 RTLDRADDR cb;
511 /** This is set if the debug information is found in an external file. NULL
512 * if no external file involved.
513 * @note Putting it outside the union to allow lazy callback implementation. */
514 const char *pszExtFile;
515 /** Type (enmType) specific information. */
516 union
517 {
518 /** RTLDRDBGINFOTYPE_DWARF */
519 struct
520 {
521 /** The section name. */
522 const char *pszSection;
523 } Dwarf;
524
525 /** RTLDRDBGINFOTYPE_DWARF_DWO */
526 struct
527 {
528 /** The CRC32 of the external file. */
529 uint32_t uCrc32;
530 } Dwo;
531
532 /** RTLDRDBGINFOTYPE_CODEVIEW_PDB20, RTLDRDBGINFOTYPE_CODEVIEW_DBG */
533 struct
534 {
535 /** The PE image size. */
536 uint32_t cbImage;
537 /** The timestamp. */
538 uint32_t uTimestamp;
539 /** The major version from the entry. */
540 uint32_t uMajorVer;
541 /** The minor version from the entry. */
542 uint32_t uMinorVer;
543 } Cv;
544
545 /** RTLDRDBGINFOTYPE_CODEVIEW_DBG */
546 struct
547 {
548 /** The PE image size. */
549 uint32_t cbImage;
550 /** The timestamp. */
551 uint32_t uTimestamp;
552 } Dbg;
553
554 /** RTLDRDBGINFOTYPE_CODEVIEW_PDB20*/
555 struct
556 {
557 /** The PE image size. */
558 uint32_t cbImage;
559 /** The timestamp. */
560 uint32_t uTimestamp;
561 /** The PDB age. */
562 uint32_t uAge;
563 } Pdb20;
564
565 /** RTLDRDBGINFOTYPE_CODEVIEW_PDB70 */
566 struct
567 {
568 /** The PE image size. */
569 uint32_t cbImage;
570 /** The PDB age. */
571 uint32_t uAge;
572 /** The UUID. */
573 RTUUID Uuid;
574 } Pdb70;
575 } u;
576} RTLDRDBGINFO;
577/** Pointer to debug info details. */
578typedef RTLDRDBGINFO *PRTLDRDBGINFO;
579/** Pointer to read only debug info details. */
580typedef RTLDRDBGINFO const *PCRTLDRDBGINFO;
581
582
583/**
584 * Debug info enumerator callback.
585 *
586 * @returns VINF_SUCCESS to continue the enumeration. Any other status code
587 * will cause RTLdrEnumDbgInfo to immediately return with that status.
588 *
589 * @param hLdrMod The module handle.
590 * @param pDbgInfo Pointer to a read only structure with the details.
591 * @param pvUser The user parameter specified to RTLdrEnumDbgInfo.
592 */
593typedef DECLCALLBACK(int) FNRTLDRENUMDBG(RTLDRMOD hLdrMod, PCRTLDRDBGINFO pDbgInfo, void *pvUser);
594/** Pointer to a debug info enumerator callback. */
595typedef FNRTLDRENUMDBG *PFNRTLDRENUMDBG;
596
597/**
598 * Enumerate the debug info contained in the executable image.
599 *
600 * @returns IPRT status code or whatever pfnCallback returns.
601 *
602 * @param hLdrMod The module handle.
603 * @param pvBits Optional pointer to bits returned by
604 * RTLdrGetBits(). This can be used by some module
605 * interpreters to reduce memory consumption.
606 * @param pfnCallback The callback function.
607 * @param pvUser The user argument.
608 */
609RTDECL(int) RTLdrEnumDbgInfo(RTLDRMOD hLdrMod, const void *pvBits, PFNRTLDRENUMDBG pfnCallback, void *pvUser);
610
611
612/**
613 * Loader segment.
614 */
615typedef struct RTLDRSEG
616{
617 /** The segment name. (Might not be zero terminated!) */
618 const char *pchName;
619 /** The length of the segment name. */
620 uint32_t cchName;
621 /** The flat selector to use for the segment (i.e. data/code).
622 * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
623 uint16_t SelFlat;
624 /** The 16-bit selector to use for the segment.
625 * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
626 uint16_t Sel16bit;
627 /** Segment flags. */
628 uint32_t fFlags;
629 /** The segment protection (RTMEM_PROT_XXX). */
630 uint32_t fProt;
631 /** The size of the segment. */
632 RTLDRADDR cb;
633 /** The required segment alignment.
634 * The to 0 if the segment isn't supposed to be mapped. */
635 RTLDRADDR Alignment;
636 /** The link address.
637 * Set to NIL_RTLDRADDR if the segment isn't supposed to be mapped or if
638 * the image doesn't have link addresses. */
639 RTLDRADDR LinkAddress;
640 /** File offset of the segment.
641 * Set to -1 if no file backing (like BSS). */
642 RTFOFF offFile;
643 /** Size of the file bits of the segment.
644 * Set to -1 if no file backing (like BSS). */
645 RTFOFF cbFile;
646 /** The relative virtual address when mapped.
647 * Set to NIL_RTLDRADDR if the segment isn't supposed to be mapped. */
648 RTLDRADDR RVA;
649 /** The size of the segment including the alignment gap up to the next segment when mapped.
650 * This is set to NIL_RTLDRADDR if not implemented. */
651 RTLDRADDR cbMapped;
652} RTLDRSEG;
653/** Pointer to a loader segment. */
654typedef RTLDRSEG *PRTLDRSEG;
655/** Pointer to a read only loader segment. */
656typedef RTLDRSEG const *PCRTLDRSEG;
657
658
659/** @name Segment flags
660 * @{ */
661/** The segment is 16-bit. When not set the default of the target architecture is assumed. */
662#define RTLDRSEG_FLAG_16BIT UINT32_C(1)
663/** The segment requires a 16-bit selector alias. (OS/2) */
664#define RTLDRSEG_FLAG_OS2_ALIAS16 UINT32_C(2)
665/** Conforming segment (x86 weirdness). (OS/2) */
666#define RTLDRSEG_FLAG_OS2_CONFORM UINT32_C(4)
667/** IOPL (ring-2) segment. (OS/2) */
668#define RTLDRSEG_FLAG_OS2_IOPL UINT32_C(8)
669/** @} */
670
671/**
672 * Segment enumerator callback.
673 *
674 * @returns VINF_SUCCESS to continue the enumeration. Any other status code
675 * will cause RTLdrEnumSegments to immediately return with that
676 * status.
677 *
678 * @param hLdrMod The module handle.
679 * @param pSeg The segment information.
680 * @param pvUser The user parameter specified to RTLdrEnumSegments.
681 */
682typedef DECLCALLBACK(int) FNRTLDRENUMSEGS(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser);
683/** Pointer to a segment enumerator callback. */
684typedef FNRTLDRENUMSEGS *PFNRTLDRENUMSEGS;
685
686/**
687 * Enumerate the debug info contained in the executable image.
688 *
689 * @returns IPRT status code or whatever pfnCallback returns.
690 *
691 * @param hLdrMod The module handle.
692 * @param pfnCallback The callback function.
693 * @param pvUser The user argument.
694 */
695RTDECL(int) RTLdrEnumSegments(RTLDRMOD hLdrMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser);
696
697/**
698 * Converts a link address to a segment:offset address.
699 *
700 * @returns IPRT status code.
701 *
702 * @param hLdrMod The module handle.
703 * @param LinkAddress The link address to convert.
704 * @param piSeg Where to return the segment index.
705 * @param poffSeg Where to return the segment offset.
706 */
707RTDECL(int) RTLdrLinkAddressToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, uint32_t *piSeg, PRTLDRADDR poffSeg);
708
709/**
710 * Converts a link address to an image relative virtual address (RVA).
711 *
712 * @returns IPRT status code.
713 *
714 * @param hLdrMod The module handle.
715 * @param LinkAddress The link address to convert.
716 * @param pRva Where to return the RVA.
717 */
718RTDECL(int) RTLdrLinkAddressToRva(RTLDRMOD hLdrMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva);
719
720/**
721 * Converts an image relative virtual address (RVA) to a segment:offset.
722 *
723 * @returns IPRT status code.
724 *
725 * @param hLdrMod The module handle.
726 * @param Rva The link address to convert.
727 * @param piSeg Where to return the segment index.
728 * @param poffSeg Where to return the segment offset.
729 */
730RTDECL(int) RTLdrSegOffsetToRva(RTLDRMOD hLdrMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva);
731
732/**
733 * Converts a segment:offset into an image relative virtual address (RVA).
734 *
735 * @returns IPRT status code.
736 *
737 * @param hLdrMod The module handle.
738 * @param iSeg The segment index.
739 * @param offSeg The segment offset.
740 * @param pRva Where to return the RVA.
741 */
742RTDECL(int) RTLdrRvaToSegOffset(RTLDRMOD hLdrMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg);
743
744/**
745 * Gets the image format.
746 *
747 * @returns Valid image format on success. RTLDRFMT_INVALID on invalid handle or
748 * other errors.
749 * @param hLdrMod The module handle.
750 */
751RTDECL(RTLDRFMT) RTLdrGetFormat(RTLDRMOD hLdrMod);
752
753/**
754 * Gets the image type.
755 *
756 * @returns Valid image type value on success. RTLDRTYPE_INVALID on
757 * invalid handle or other errors.
758 * @param hLdrMod The module handle.
759 */
760RTDECL(RTLDRTYPE) RTLdrGetType(RTLDRMOD hLdrMod);
761
762/**
763 * Gets the image endian-ness.
764 *
765 * @returns Valid image endian value on success. RTLDRENDIAN_INVALID on invalid
766 * handle or other errors.
767 * @param hLdrMod The module handle.
768 */
769RTDECL(RTLDRENDIAN) RTLdrGetEndian(RTLDRMOD hLdrMod);
770
771/**
772 * Gets the image endian-ness.
773 *
774 * @returns Valid image architecture value on success.
775 * RTLDRARCH_INVALID on invalid handle or other errors.
776 * @param hLdrMod The module handle.
777 */
778RTDECL(RTLDRARCH) RTLdrGetArch(RTLDRMOD hLdrMod);
779
780
781RT_C_DECLS_END
782
783/** @} */
784
785#endif
786
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