VirtualBox

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

最後變更 在這個檔案從95043是 94869,由 vboxsync 提交於 3 年 前

IPRT/ldr: Minimal MachO/ARM64 read support to make RTSignTool work. bugref:9898

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette