VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/ldr.h@ 103005

Last change on this file since 103005 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 25.6 KB
Line 
1/* $Id: ldr.h 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Loader Internals.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_INTERNAL_ldr_h
38#define IPRT_INCLUDED_INTERNAL_ldr_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/types.h>
44#include "internal/magics.h"
45
46RT_C_DECLS_BEGIN
47
48
49/*******************************************************************************
50* Defined Constants And Macros *
51*******************************************************************************/
52#ifdef DOXYGEN_RUNNING
53/** @def LDR_WITH_NATIVE
54 * Define this to get native support. */
55# define LDR_WITH_NATIVE
56
57/** @def LDR_WITH_ELF32
58 * Define this to get 32-bit ELF support. */
59# define LDR_WITH_ELF32
60
61/** @def LDR_WITH_ELF64
62 * Define this to get 64-bit ELF support. */
63# define LDR_WITH_ELF64
64
65/** @def LDR_WITH_PE
66 * Define this to get 32-bit and 64-bit PE support. */
67# define LDR_WITH_PE
68
69/** @def LDR_WITH_LX
70 * Define this to get LX support. */
71# define LDR_WITH_LX
72
73/** @def LDR_WITH_MACHO
74 * Define this to get mach-o support (not implemented yet). */
75# define LDR_WITH_MACHO
76#endif /* DOXYGEN_RUNNING */
77
78#if defined(LDR_WITH_ELF32) || defined(LDR_WITH_ELF64)
79/** @def LDR_WITH_ELF
80 * This is defined if any of the ELF versions is requested.
81 */
82# define LDR_WITH_ELF
83#endif
84
85/* These two may clash with winnt.h. */
86#undef IMAGE_DOS_SIGNATURE
87#undef IMAGE_NT_SIGNATURE
88#undef IMAGE_LX_SIGNATURE
89
90
91/** Little endian uint32_t ELF signature ("\x7fELF"). */
92#define IMAGE_ELF_SIGNATURE (0x7f | ('E' << 8) | ('L' << 16) | ('F' << 24))
93/** Little endian uint32_t PE signature ("PE\0\0"). */
94#define IMAGE_NT_SIGNATURE 0x00004550
95/** Little endian uint16_t LX signature ("LX") */
96#define IMAGE_LX_SIGNATURE ('L' | ('X' << 8))
97/** Little endian uint16_t LE signature ("LE") */
98#define IMAGE_LE_SIGNATURE ('L' | ('E' << 8))
99/** Little endian uint16_t NE signature ("NE") */
100#define IMAGE_NE_SIGNATURE ('N' | ('E' << 8))
101/** Little endian uint16_t MZ signature ("MZ"). */
102#define IMAGE_DOS_SIGNATURE ('M' | ('Z' << 8))
103
104
105/** Kind of missing flag. */
106#define RTMEM_PROT_WRITECOPY RTMEM_PROT_WRITE
107
108
109/** @name Load symbol kind flags (from kStuff, expose later).
110 * @{ */
111/** The bitness doesn't matter. */
112#define RTLDRSYMKIND_NO_BIT UINT32_C(0x00000000)
113/** 16-bit symbol. */
114#define RTLDRSYMKIND_16BIT UINT32_C(0x00000001)
115/** 32-bit symbol. */
116#define RTLDRSYMKIND_32BIT UINT32_C(0x00000002)
117/** 64-bit symbol. */
118#define RTLDRSYMKIND_64BIT UINT32_C(0x00000003)
119/** Mask out the bit.*/
120#define RTLDRSYMKIND_BIT_MASK UINT32_C(0x00000003)
121/** We don't know the type of symbol. */
122#define RTLDRSYMKIND_NO_TYPE UINT32_C(0x00000000)
123/** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
124#define RTLDRSYMKIND_CODE UINT32_C(0x00000010)
125/** The symbol is a data object. */
126#define RTLDRSYMKIND_DATA UINT32_C(0x00000020)
127/** Mask out the symbol type. */
128#define RTLDRSYMKIND_TYPE_MASK UINT32_C(0x00000030)
129/** Valid symbol kind mask. */
130#define RTLDRSYMKIND_MASK UINT32_C(0x00000033)
131/** Weak symbol. */
132#define RTLDRSYMKIND_WEAK UINT32_C(0x00000100)
133/** Forwarder symbol. */
134#define RTLDRSYMKIND_FORWARDER UINT32_C(0x00000200)
135/** Request a flat symbol address. */
136#define RTLDRSYMKIND_REQ_FLAT UINT32_C(0x00000000)
137/** Request a segmented symbol address. */
138#define RTLDRSYMKIND_REQ_SEGMENTED UINT32_C(0x40000000)
139/** Request type mask. */
140#define RTLDRSYMKIND_REQ_TYPE_MASK UINT32_C(0x40000000)
141/** @} */
142
143/** Align a RTLDRADDR value. */
144#define RTLDR_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(RTLDRADDR)((align) - 1) )
145
146/** Special base address value alias for the link address.
147 * Consider propagating... */
148#define RTLDR_BASEADDRESS_LINK (~(RTLDRADDR)1)
149
150
151
152/*******************************************************************************
153* Structures and Typedefs *
154*******************************************************************************/
155/**
156 * Loader state.
157 */
158typedef enum RTLDRSTATE
159{
160 /** Invalid. */
161 LDR_STATE_INVALID = 0,
162 /** Opened. */
163 LDR_STATE_OPENED,
164 /** The image can no longer be relocated. */
165 LDR_STATE_DONE,
166 /** The image was loaded, not opened. */
167 LDR_STATE_LOADED,
168 /** The usual 32-bit hack. */
169 LDR_STATE_32BIT_HACK = 0x7fffffff
170} RTLDRSTATE;
171
172
173/**
174 * CPU models (from kStuff, expose later some time).
175 */
176typedef enum RTLDRCPU
177{
178 /** The usual invalid cpu. */
179 RTLDRCPU_INVALID = 0,
180
181 /** @name K_ARCH_X86_16
182 * @{ */
183 RTLDRCPU_I8086,
184 RTLDRCPU_I8088,
185 RTLDRCPU_I80186,
186 RTLDRCPU_I80286,
187 RTLDRCPU_I386_16,
188 RTLDRCPU_I486_16,
189 RTLDRCPU_I486SX_16,
190 RTLDRCPU_I586_16,
191 RTLDRCPU_I686_16,
192 RTLDRCPU_P4_16,
193 RTLDRCPU_CORE2_16,
194 RTLDRCPU_K6_16,
195 RTLDRCPU_K7_16,
196 RTLDRCPU_K8_16,
197 RTLDRCPU_FIRST_X86_16 = RTLDRCPU_I8086,
198 RTLDRCPU_LAST_X86_16 = RTLDRCPU_K8_16,
199 /** @} */
200
201 /** @name K_ARCH_X86_32
202 * @{ */
203 RTLDRCPU_X86_32_BLEND,
204 RTLDRCPU_I386,
205 RTLDRCPU_I486,
206 RTLDRCPU_I486SX,
207 RTLDRCPU_I586,
208 RTLDRCPU_I686,
209 RTLDRCPU_P4,
210 RTLDRCPU_CORE2_32,
211 RTLDRCPU_K6,
212 RTLDRCPU_K7,
213 RTLDRCPU_K8_32,
214 RTLDRCPU_FIRST_X86_32 = RTLDRCPU_I386,
215 RTLDRCPU_LAST_X86_32 = RTLDRCPU_K8_32,
216 /** @} */
217
218 /** @name K_ARCH_AMD64
219 * @{ */
220 RTLDRCPU_AMD64_BLEND,
221 RTLDRCPU_K8,
222 RTLDRCPU_P4_64,
223 RTLDRCPU_CORE2,
224 RTLDRCPU_FIRST_AMD64 = RTLDRCPU_K8,
225 RTLDRCPU_LAST_AMD64 = RTLDRCPU_CORE2,
226 /** @} */
227
228 /** @name K_ARCH_ARM64
229 * @{ */
230 RTLDRCPU_ARM64_BLEND,
231 RTLDRCPU_ARM64_V8,
232 RTLDRCPU_ARM64E,
233 RTLDRCPU_FIRST_ARM64 = RTLDRCPU_ARM64_V8,
234 RTLDRCPU_LAST_ARM64 = RTLDRCPU_ARM64E,
235 /** @} */
236
237 /** The end of the valid cpu values (exclusive). */
238 RTLDRCPU_END,
239 /** Hack to blow the type up to 32-bit. */
240 RTLDRCPU_32BIT_HACK = 0x7fffffff
241} RTLDRCPU;
242
243
244/** Pointer to a loader item. */
245typedef struct RTLDRMODINTERNAL *PRTLDRMODINTERNAL;
246
247/**
248 * Loader module operations.
249 */
250typedef struct RTLDROPS
251{
252 /** The name of the executable format. */
253 const char *pszName;
254
255 /**
256 * Release any resources attached to the module.
257 * The caller will do RTMemFree on pMod on return.
258 *
259 * @returns iprt status code.
260 * @param pMod Pointer to the loader module structure.
261 * @remark Compulsory entry point.
262 */
263 DECLCALLBACKMEMBER(int, pfnClose,(PRTLDRMODINTERNAL pMod));
264
265 /**
266 * Gets a simple symbol.
267 * This entrypoint can be omitted if RTLDROPS::pfnGetSymbolEx() is provided.
268 *
269 * @returns iprt status code.
270 * @param pMod Pointer to the loader module structure.
271 * @param pszSymbol The symbol name.
272 * @param ppvValue Where to store the symbol value.
273 */
274 DECLCALLBACKMEMBER(int, pfnGetSymbol,(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue));
275
276 /**
277 * Called when we're done with getting bits and relocating them.
278 * This is used to release resources used by the loader to support those actions.
279 *
280 * After this call none of the extended loader functions can be called.
281 *
282 * @returns iprt status code.
283 * @param pMod Pointer to the loader module structure.
284 * @remark This is an optional entry point.
285 */
286 DECLCALLBACKMEMBER(int, pfnDone,(PRTLDRMODINTERNAL pMod));
287
288 /**
289 * Enumerates the symbols exported by the module.
290 *
291 * @returns iprt status code, which might have been returned by pfnCallback.
292 * @param pMod Pointer to the loader module structure.
293 * @param fFlags Flags indicating what to return and such.
294 * @param pvBits Pointer to the bits returned by RTLDROPS::pfnGetBits(), optional.
295 * @param BaseAddress The image base addressto use when calculating the symbol values.
296 * @param pfnCallback The callback function which each symbol is to be
297 * fed to.
298 * @param pvUser User argument to pass to the enumerator.
299 * @remark This is an optional entry point.
300 */
301 DECLCALLBACKMEMBER(int, pfnEnumSymbols,(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress,
302 PFNRTLDRENUMSYMS pfnCallback, void *pvUser));
303
304
305/* extended functions: */
306
307 /**
308 * Gets the size of the loaded image (i.e. in memory).
309 *
310 * @returns in memory size, in bytes.
311 * @returns ~(size_t)0 if it's not an extended image.
312 * @param pMod Pointer to the loader module structure.
313 * @remark Extended loader feature.
314 */
315 DECLCALLBACKMEMBER(size_t, pfnGetImageSize,(PRTLDRMODINTERNAL pMod));
316
317 /**
318 * Gets the image bits fixed up for a specified address.
319 *
320 * @returns iprt status code.
321 * @param pMod Pointer to the loader module structure.
322 * @param pvBits Where to store the bits. The size of this buffer is equal or
323 * larger to the value returned by pfnGetImageSize().
324 * @param BaseAddress The base address which the image should be fixed up to.
325 * @param pfnGetImport The callback function to use to resolve imports (aka unresolved externals).
326 * @param pvUser User argument to pass to the callback.
327 * @remark Extended loader feature.
328 */
329 DECLCALLBACKMEMBER(int, pfnGetBits,(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser));
330
331 /**
332 * Relocate bits obtained using pfnGetBits to a new address.
333 *
334 * @returns iprt status code.
335 * @param pMod Pointer to the loader module structure.
336 * @param pvBits Where to store the bits. The size of this buffer is equal or
337 * larger to the value returned by pfnGetImageSize().
338 * @param NewBaseAddress The base address which the image should be fixed up to.
339 * @param OldBaseAddress The base address which the image is currently fixed up to.
340 * @param pfnGetImport The callback function to use to resolve imports (aka unresolved externals).
341 * @param pvUser User argument to pass to the callback.
342 * @remark Extended loader feature.
343 */
344 DECLCALLBACKMEMBER(int, pfnRelocate,(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress, RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser));
345
346 /**
347 * Gets a symbol with special base address and stuff.
348 * This entrypoint can be omitted if RTLDROPS::pfnGetSymbolEx() is provided and the special BaseAddress feature isn't supported.
349 *
350 * @returns iprt status code.
351 * @retval VERR_LDR_FORWARDER forwarder, use pfnQueryForwarderInfo. Buffer size
352 * in @a pValue.
353 * @param pMod Pointer to the loader module structure.
354 * @param pvBits Pointer to bits returned by RTLDROPS::pfnGetBits(), optional.
355 * @param BaseAddress The image base address to use when calculating the symbol value.
356 * @param iOrdinal Symbol table ordinal, UINT32_MAX if the symbol name
357 * should be used.
358 * @param pszSymbol The symbol name.
359 * @param pValue Where to store the symbol value.
360 * @remark Extended loader feature.
361 */
362 DECLCALLBACKMEMBER(int, pfnGetSymbolEx,(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,
363 uint32_t iOrdinal, const char *pszSymbol, RTUINTPTR *pValue));
364
365 /**
366 * Query forwarder information on the specified symbol.
367 *
368 * This is an optional entrypoint.
369 *
370 * @returns iprt status code.
371 * @param pMod Pointer to the loader module structure.
372 * @param pvBits Pointer to bits returned by RTLDROPS::pfnGetBits(),
373 * optional.
374 * @param iOrdinal Symbol table ordinal of the forwarded symbol to query.
375 * UINT32_MAX if the symbol name should be used.
376 * @param pszSymbol The symbol name of the forwarded symbol to query.
377 * @param pInfo Where to return the forwarder information.
378 * @param cbInfo The size of the pInfo buffer. The pfnGetSymbolEx
379 * entrypoint returns the required size in @a pValue when
380 * the return code is VERR_LDR_FORWARDER.
381 * @remark Extended loader feature.
382 */
383 DECLCALLBACKMEMBER(int, pfnQueryForwarderInfo,(PRTLDRMODINTERNAL pMod, const void *pvBits, uint32_t iOrdinal,
384 const char *pszSymbol, PRTLDRIMPORTINFO pInfo, size_t cbInfo));
385
386 /**
387 * Enumerates the debug info contained in the module.
388 *
389 * @returns iprt status code, which might have been returned by pfnCallback.
390 * @param pMod Pointer to the loader module structure.
391 * @param pvBits Pointer to the bits returned by RTLDROPS::pfnGetBits(), optional.
392 * @param pfnCallback The callback function which each debug info part is
393 * to be fed to.
394 * @param pvUser User argument to pass to the enumerator.
395 * @remark This is an optional entry point that can be NULL.
396 */
397 DECLCALLBACKMEMBER(int, pfnEnumDbgInfo,(PRTLDRMODINTERNAL pMod, const void *pvBits,
398 PFNRTLDRENUMDBG pfnCallback, void *pvUser));
399
400 /**
401 * Enumerates the segments in the module.
402 *
403 * @returns iprt status code, which might have been returned by pfnCallback.
404 * @param pMod Pointer to the loader module structure.
405 * @param pfnCallback The callback function which each debug info part is
406 * to be fed to.
407 * @param pvUser User argument to pass to the enumerator.
408 * @remark This is an optional entry point that can be NULL.
409 */
410 DECLCALLBACKMEMBER(int, pfnEnumSegments,(PRTLDRMODINTERNAL pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser));
411
412 /**
413 * Converts a link address to a segment:offset address.
414 *
415 * @returns IPRT status code.
416 *
417 * @param pMod Pointer to the loader module structure.
418 * @param LinkAddress The link address to convert.
419 * @param piSeg Where to return the segment index.
420 * @param poffSeg Where to return the segment offset.
421 * @remark This is an optional entry point that can be NULL.
422 */
423 DECLCALLBACKMEMBER(int, pfnLinkAddressToSegOffset,(PRTLDRMODINTERNAL pMod, RTLDRADDR LinkAddress,
424 uint32_t *piSeg, PRTLDRADDR poffSeg));
425
426 /**
427 * Converts a link address to a RVA.
428 *
429 * @returns IPRT status code.
430 *
431 * @param pMod Pointer to the loader module structure.
432 * @param LinkAddress The link address to convert.
433 * @param pRva Where to return the RVA.
434 * @remark This is an optional entry point that can be NULL.
435 */
436 DECLCALLBACKMEMBER(int, pfnLinkAddressToRva,(PRTLDRMODINTERNAL pMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva));
437
438 /**
439 * Converts a segment:offset to a RVA.
440 *
441 * @returns IPRT status code.
442 *
443 * @param pMod Pointer to the loader module structure.
444 * @param iSeg The segment index.
445 * @param offSeg The segment offset.
446 * @param pRva Where to return the RVA.
447 * @remark This is an optional entry point that can be NULL.
448 */
449 DECLCALLBACKMEMBER(int, pfnSegOffsetToRva,(PRTLDRMODINTERNAL pMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva));
450
451 /**
452 * Converts a RVA to a segment:offset.
453 *
454 * @returns IPRT status code.
455 *
456 * @param pMod Pointer to the loader module structure.
457 * @param Rva The RVA to convert.
458 * @param piSeg Where to return the segment index.
459 * @param poffSeg Where to return the segment offset.
460 * @remark This is an optional entry point that can be NULL.
461 */
462 DECLCALLBACKMEMBER(int, pfnRvaToSegOffset,(PRTLDRMODINTERNAL pMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg));
463
464 /**
465 * Reads a debug info part (section) from the image.
466 *
467 * This is primarily needed for getting DWARF sections in ELF image with fixups
468 * applied and won't be required by most other loader backends.
469 *
470 * @returns IPRT status code.
471 *
472 * @param pMod Pointer to the loader module structure.
473 * @param pvBuf The buffer to read into.
474 * @param iDbgInfo The debug info ordinal number if the request
475 * corresponds exactly to a debug info part from
476 * pfnEnumDbgInfo. Otherwise, pass UINT32_MAX.
477 * @param off The offset into the image file.
478 * @param cb The number of bytes to read.
479 */
480 DECLCALLBACKMEMBER(int, pfnReadDbgInfo,(PRTLDRMODINTERNAL pMod, uint32_t iDbgInfo, RTFOFF off, size_t cb, void *pvBuf));
481
482 /**
483 * Generic method for querying image properties.
484 *
485 * @returns IPRT status code.
486 * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
487 * or that specific property).
488 * @retval VERR_NOT_FOUND the property was not found in the module.
489 *
490 * @param pMod Pointer to the loader module structure.
491 * @param enmProp The property to query (valid).
492 * @param pvBits Pointer to the bits returned by
493 * RTLDROPS::pfnGetBits(), optional.
494 * @param pvBuf Pointer to the input / output buffer. This is valid.
495 * Normally only used for returning data, but in some
496 * cases it also holds input.
497 * @param cbBuf The size of the buffer (valid as per
498 * property).
499 * @param pcbRet The number of bytes actually returned. If
500 * VERR_BUFFER_OVERFLOW is returned, this is set to the
501 * required buffer size.
502 */
503 DECLCALLBACKMEMBER(int, pfnQueryProp,(PRTLDRMODINTERNAL pMod, RTLDRPROP enmProp, void const *pvBits,
504 void *pvBuf, size_t cbBuf, size_t *pcbRet));
505
506 /**
507 * Verify the image signature.
508 *
509 * This may permform additional integrity checks on the image structures that
510 * was not done when opening the image.
511 *
512 * @returns IPRT status code.
513 * @retval VERR_LDRVI_NOT_SIGNED if not signed.
514 *
515 * @param pMod Pointer to the loader module structure.
516 * @param pfnCallback Callback that does the signature and certificate
517 * verification.
518 * @param pvUser User argument for the callback.
519 * @param pErrInfo Pointer to an error info buffer. Optional.
520 */
521 DECLCALLBACKMEMBER(int, pfnVerifySignature,(PRTLDRMODINTERNAL pMod, PFNRTLDRVALIDATESIGNEDDATA pfnCallback, void *pvUser,
522 PRTERRINFO pErrInfo));
523
524 /**
525 * Calculate the image hash according the image signing rules.
526 *
527 * @returns IPRT status code.
528 * @param pMod The module handle.
529 * @param enmDigest Which kind of digest.
530 * @param pabHash Where to store the image hash.
531 * @param cbHash Size of the buffer @a pabHash points at. This has
532 * been validated to be at least the required size.
533 */
534 DECLCALLBACKMEMBER(int, pfnHashImage,(PRTLDRMODINTERNAL pMod, RTDIGESTTYPE enmDigest, uint8_t *pabHash, size_t cbHash));
535
536 /**
537 * Try use unwind information to unwind one frame.
538 *
539 * @returns IPRT status code. Last informational status from stack reader callback.
540 * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
541 * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
542 * for the location given by iSeg:off.
543 *
544 * @param pMod Pointer to the module structure.
545 * @param pvBits Pointer to the bits returned by
546 * RTLDROPS::pfnGetBits(), optional.
547 * @param iSeg The segment number of the program counter. UINT32_MAX for RVA.
548 * @param off The offset into @a iSeg. Together with @a iSeg
549 * this corresponds to the RTDBGUNWINDSTATE::uPc
550 * value pointed to by @a pState.
551 * @param pState The unwind state to work.
552 *
553 * @sa RTLdrUnwindFrame, RTDbgModUnwindFrame
554 */
555 DECLCALLBACKMEMBER(int, pfnUnwindFrame,(PRTLDRMODINTERNAL pMod, void const *pvBits, uint32_t iSeg, RTUINTPTR off,
556 PRTDBGUNWINDSTATE pState));
557
558 /** Dummy entry to make sure we've initialized it all. */
559 RTUINT uDummy;
560} RTLDROPS;
561typedef RTLDROPS *PRTLDROPS;
562typedef const RTLDROPS *PCRTLDROPS;
563
564
565/**
566 * Loader module core.
567 */
568typedef struct RTLDRMODINTERNAL
569{
570 /** The loader magic value (RTLDRMOD_MAGIC). */
571 uint32_t u32Magic;
572 /** State. */
573 RTLDRSTATE eState;
574 /** Loader ops. */
575 PCRTLDROPS pOps;
576 /** Pointer to the reader instance. This is NULL for native image. */
577 PRTLDRREADER pReader;
578 /** Image format. */
579 RTLDRFMT enmFormat;
580 /** Image type. */
581 RTLDRTYPE enmType;
582 /** Image endianness. */
583 RTLDRENDIAN enmEndian;
584 /** Image target architecture. */
585 RTLDRARCH enmArch;
586} RTLDRMODINTERNAL;
587
588
589/**
590 * Validates that a loader module handle is valid.
591 *
592 * @returns true if valid.
593 * @returns false if invalid.
594 * @param hLdrMod The loader module handle.
595 */
596DECLINLINE(bool) rtldrIsValid(RTLDRMOD hLdrMod)
597{
598 return RT_VALID_PTR(hLdrMod)
599 && ((PRTLDRMODINTERNAL)hLdrMod)->u32Magic == RTLDRMOD_MAGIC;
600}
601
602
603/**
604 * Native loader module.
605 */
606typedef struct RTLDRMODNATIVE
607{
608 /** The core structure. */
609 RTLDRMODINTERNAL Core;
610 /** The native handle. */
611 uintptr_t hNative;
612 /** The load flags (RTLDRLOAD_FLAGS_XXX). */
613 uint32_t fFlags;
614} RTLDRMODNATIVE;
615/** Pointer to a native module. */
616typedef RTLDRMODNATIVE *PRTLDRMODNATIVE;
617
618/** @copydoc RTLDROPS::pfnGetSymbol */
619DECLCALLBACK(int) rtldrNativeGetSymbol(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue);
620/** @copydoc RTLDROPS::pfnClose */
621DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod);
622
623/**
624 * Load a native module using the native loader.
625 *
626 * @returns iprt status code.
627 * @param pszFilename The image filename.
628 * @param phHandle Where to store the module handle on success.
629 * @param fFlags RTLDRLOAD_FLAGS_XXX.
630 * @param pErrInfo Where to return extended error information. Optional.
631 */
632DECLHIDDEN(int) rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, uint32_t fFlags, PRTERRINFO pErrInfo);
633
634/**
635 * Load a system library.
636 *
637 * @returns iprt status code.
638 * @param pszFilename The image filename.
639 * @param pszExt Extension to add. NULL if none.
640 * @param fFlags RTLDRLOAD_FLAGS_XXX.
641 * @param phLdrMod Where to return the module handle on success.
642 */
643DECLHIDDEN(int) rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod);
644
645DECLHIDDEN(int) rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
646DECLHIDDEN(int) rtldrELFOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
647DECLHIDDEN(int) rtldrLXOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offLxHdr, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
648DECLHIDDEN(int) rtldrMachOOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offImage, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
649DECLHIDDEN(int) rtldrFatOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
650DECLHIDDEN(int) rtldrkLdrOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
651
652
653DECLHIDDEN(int) rtLdrReadAt(RTLDRMOD hLdrMod, void *pvBuf, uint32_t iDbgInfo, RTFOFF off, size_t cb);
654
655RT_C_DECLS_END
656
657#endif /* !IPRT_INCLUDED_INTERNAL_ldr_h */
658
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