VirtualBox

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

Last change on this file since 85877 was 85626, checked in by vboxsync, 4 years ago

IPRT/ldr: comment typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 25.1 KB
Line 
1/* $Id: ldr.h 85626 2020-08-06 00:42:43Z vboxsync $ */
2/** @file
3 * IPRT - Loader Internals.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * 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 /** The end of the valid cpu values (exclusive). */
219 RTLDRCPU_END,
220 /** Hack to blow the type up to 32-bit. */
221 RTLDRCPU_32BIT_HACK = 0x7fffffff
222} RTLDRCPU;
223
224
225/** Pointer to a loader item. */
226typedef struct RTLDRMODINTERNAL *PRTLDRMODINTERNAL;
227
228/**
229 * Loader module operations.
230 */
231typedef struct RTLDROPS
232{
233 /** The name of the executable format. */
234 const char *pszName;
235
236 /**
237 * Release any resources attached to the module.
238 * The caller will do RTMemFree on pMod on return.
239 *
240 * @returns iprt status code.
241 * @param pMod Pointer to the loader module structure.
242 * @remark Compulsory entry point.
243 */
244 DECLCALLBACKMEMBER(int, pfnClose,(PRTLDRMODINTERNAL pMod));
245
246 /**
247 * Gets a simple symbol.
248 * This entrypoint can be omitted if RTLDROPS::pfnGetSymbolEx() is provided.
249 *
250 * @returns iprt status code.
251 * @param pMod Pointer to the loader module structure.
252 * @param pszSymbol The symbol name.
253 * @param ppvValue Where to store the symbol value.
254 */
255 DECLCALLBACKMEMBER(int, pfnGetSymbol,(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue));
256
257 /**
258 * Called when we're done with getting bits and relocating them.
259 * This is used to release resources used by the loader to support those actions.
260 *
261 * After this call none of the extended loader functions can be called.
262 *
263 * @returns iprt status code.
264 * @param pMod Pointer to the loader module structure.
265 * @remark This is an optional entry point.
266 */
267 DECLCALLBACKMEMBER(int, pfnDone,(PRTLDRMODINTERNAL pMod));
268
269 /**
270 * Enumerates the symbols exported by the module.
271 *
272 * @returns iprt status code, which might have been returned by pfnCallback.
273 * @param pMod Pointer to the loader module structure.
274 * @param fFlags Flags indicating what to return and such.
275 * @param pvBits Pointer to the bits returned by RTLDROPS::pfnGetBits(), optional.
276 * @param BaseAddress The image base addressto use when calculating the symbol values.
277 * @param pfnCallback The callback function which each symbol is to be
278 * fed to.
279 * @param pvUser User argument to pass to the enumerator.
280 * @remark This is an optional entry point.
281 */
282 DECLCALLBACKMEMBER(int, pfnEnumSymbols,(PRTLDRMODINTERNAL pMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress,
283 PFNRTLDRENUMSYMS pfnCallback, void *pvUser));
284
285
286/* extended functions: */
287
288 /**
289 * Gets the size of the loaded image (i.e. in memory).
290 *
291 * @returns in memory size, in bytes.
292 * @returns ~(size_t)0 if it's not an extended image.
293 * @param pMod Pointer to the loader module structure.
294 * @remark Extended loader feature.
295 */
296 DECLCALLBACKMEMBER(size_t, pfnGetImageSize,(PRTLDRMODINTERNAL pMod));
297
298 /**
299 * Gets the image bits fixed up for a specified address.
300 *
301 * @returns iprt status code.
302 * @param pMod Pointer to the loader module structure.
303 * @param pvBits Where to store the bits. The size of this buffer is equal or
304 * larger to the value returned by pfnGetImageSize().
305 * @param BaseAddress The base address which the image should be fixed up to.
306 * @param pfnGetImport The callback function to use to resolve imports (aka unresolved externals).
307 * @param pvUser User argument to pass to the callback.
308 * @remark Extended loader feature.
309 */
310 DECLCALLBACKMEMBER(int, pfnGetBits,(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser));
311
312 /**
313 * Relocate bits obtained using pfnGetBits to a new address.
314 *
315 * @returns iprt status code.
316 * @param pMod Pointer to the loader module structure.
317 * @param pvBits Where to store the bits. The size of this buffer is equal or
318 * larger to the value returned by pfnGetImageSize().
319 * @param NewBaseAddress The base address which the image should be fixed up to.
320 * @param OldBaseAddress The base address which the image is currently fixed up to.
321 * @param pfnGetImport The callback function to use to resolve imports (aka unresolved externals).
322 * @param pvUser User argument to pass to the callback.
323 * @remark Extended loader feature.
324 */
325 DECLCALLBACKMEMBER(int, pfnRelocate,(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress, RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser));
326
327 /**
328 * Gets a symbol with special base address and stuff.
329 * This entrypoint can be omitted if RTLDROPS::pfnGetSymbolEx() is provided and the special BaseAddress feature isn't supported.
330 *
331 * @returns iprt status code.
332 * @retval VERR_LDR_FORWARDER forwarder, use pfnQueryForwarderInfo. Buffer size
333 * in @a pValue.
334 * @param pMod Pointer to the loader module structure.
335 * @param pvBits Pointer to bits returned by RTLDROPS::pfnGetBits(), optional.
336 * @param BaseAddress The image base address to use when calculating the symbol value.
337 * @param iOrdinal Symbol table ordinal, UINT32_MAX if the symbol name
338 * should be used.
339 * @param pszSymbol The symbol name.
340 * @param pValue Where to store the symbol value.
341 * @remark Extended loader feature.
342 */
343 DECLCALLBACKMEMBER(int, pfnGetSymbolEx,(PRTLDRMODINTERNAL pMod, const void *pvBits, RTUINTPTR BaseAddress,
344 uint32_t iOrdinal, const char *pszSymbol, RTUINTPTR *pValue));
345
346 /**
347 * Query forwarder information on the specified symbol.
348 *
349 * This is an optional entrypoint.
350 *
351 * @returns iprt status code.
352 * @param pMod Pointer to the loader module structure.
353 * @param pvBits Pointer to bits returned by RTLDROPS::pfnGetBits(),
354 * optional.
355 * @param iOrdinal Symbol table ordinal of the forwarded symbol to query.
356 * UINT32_MAX if the symbol name should be used.
357 * @param pszSymbol The symbol name of the forwarded symbol to query.
358 * @param pInfo Where to return the forwarder information.
359 * @param cbInfo The size of the pInfo buffer. The pfnGetSymbolEx
360 * entrypoint returns the required size in @a pValue when
361 * the return code is VERR_LDR_FORWARDER.
362 * @remark Extended loader feature.
363 */
364 DECLCALLBACKMEMBER(int, pfnQueryForwarderInfo,(PRTLDRMODINTERNAL pMod, const void *pvBits, uint32_t iOrdinal,
365 const char *pszSymbol, PRTLDRIMPORTINFO pInfo, size_t cbInfo));
366
367 /**
368 * Enumerates the debug info contained in the module.
369 *
370 * @returns iprt status code, which might have been returned by pfnCallback.
371 * @param pMod Pointer to the loader module structure.
372 * @param pvBits Pointer to the bits returned by RTLDROPS::pfnGetBits(), optional.
373 * @param pfnCallback The callback function which each debug info part is
374 * to be fed to.
375 * @param pvUser User argument to pass to the enumerator.
376 * @remark This is an optional entry point that can be NULL.
377 */
378 DECLCALLBACKMEMBER(int, pfnEnumDbgInfo,(PRTLDRMODINTERNAL pMod, const void *pvBits,
379 PFNRTLDRENUMDBG pfnCallback, void *pvUser));
380
381 /**
382 * Enumerates the segments in the module.
383 *
384 * @returns iprt status code, which might have been returned by pfnCallback.
385 * @param pMod Pointer to the loader module structure.
386 * @param pfnCallback The callback function which each debug info part is
387 * to be fed to.
388 * @param pvUser User argument to pass to the enumerator.
389 * @remark This is an optional entry point that can be NULL.
390 */
391 DECLCALLBACKMEMBER(int, pfnEnumSegments,(PRTLDRMODINTERNAL pMod, PFNRTLDRENUMSEGS pfnCallback, void *pvUser));
392
393 /**
394 * Converts a link address to a segment:offset address.
395 *
396 * @returns IPRT status code.
397 *
398 * @param pMod Pointer to the loader module structure.
399 * @param LinkAddress The link address to convert.
400 * @param piSeg Where to return the segment index.
401 * @param poffSeg Where to return the segment offset.
402 * @remark This is an optional entry point that can be NULL.
403 */
404 DECLCALLBACKMEMBER(int, pfnLinkAddressToSegOffset,(PRTLDRMODINTERNAL pMod, RTLDRADDR LinkAddress,
405 uint32_t *piSeg, PRTLDRADDR poffSeg));
406
407 /**
408 * Converts a link address to a RVA.
409 *
410 * @returns IPRT status code.
411 *
412 * @param pMod Pointer to the loader module structure.
413 * @param LinkAddress The link address to convert.
414 * @param pRva Where to return the RVA.
415 * @remark This is an optional entry point that can be NULL.
416 */
417 DECLCALLBACKMEMBER(int, pfnLinkAddressToRva,(PRTLDRMODINTERNAL pMod, RTLDRADDR LinkAddress, PRTLDRADDR pRva));
418
419 /**
420 * Converts a segment:offset to a RVA.
421 *
422 * @returns IPRT status code.
423 *
424 * @param pMod Pointer to the loader module structure.
425 * @param iSeg The segment index.
426 * @param offSeg The segment offset.
427 * @param pRva Where to return the RVA.
428 * @remark This is an optional entry point that can be NULL.
429 */
430 DECLCALLBACKMEMBER(int, pfnSegOffsetToRva,(PRTLDRMODINTERNAL pMod, uint32_t iSeg, RTLDRADDR offSeg, PRTLDRADDR pRva));
431
432 /**
433 * Converts a RVA to a segment:offset.
434 *
435 * @returns IPRT status code.
436 *
437 * @param pMod Pointer to the loader module structure.
438 * @param Rva The RVA to convert.
439 * @param piSeg Where to return the segment index.
440 * @param poffSeg Where to return the segment offset.
441 * @remark This is an optional entry point that can be NULL.
442 */
443 DECLCALLBACKMEMBER(int, pfnRvaToSegOffset,(PRTLDRMODINTERNAL pMod, RTLDRADDR Rva, uint32_t *piSeg, PRTLDRADDR poffSeg));
444
445 /**
446 * Reads a debug info part (section) from the image.
447 *
448 * This is primarily needed for getting DWARF sections in ELF image with fixups
449 * applied and won't be required by most other loader backends.
450 *
451 * @returns IPRT status code.
452 *
453 * @param pMod Pointer to the loader module structure.
454 * @param pvBuf The buffer to read into.
455 * @param iDbgInfo The debug info ordinal number if the request
456 * corresponds exactly to a debug info part from
457 * pfnEnumDbgInfo. Otherwise, pass UINT32_MAX.
458 * @param off The offset into the image file.
459 * @param cb The number of bytes to read.
460 * @param pMod Pointer to the loader module structure.
461 */
462 DECLCALLBACKMEMBER(int, pfnReadDbgInfo,(PRTLDRMODINTERNAL pMod, uint32_t iDbgInfo, RTFOFF off, size_t cb, void *pvBuf));
463
464 /**
465 * Generic method for querying image properties.
466 *
467 * @returns IPRT status code.
468 * @retval VERR_NOT_SUPPORTED if the property query isn't supported (either all
469 * or that specific property).
470 * @retval VERR_NOT_FOUND the property was not found in the module.
471 *
472 * @param pMod Pointer to the loader module structure.
473 * @param enmProp The property to query (valid).
474 * @param pvBits Pointer to the bits returned by
475 * RTLDROPS::pfnGetBits(), optional.
476 * @param pvBuf Pointer to the input / output buffer. This is valid.
477 * Normally only used for returning data, but in some
478 * cases it also holds input.
479 * @param cbBuf The size of the buffer (valid as per
480 * property).
481 * @param pcbRet The number of bytes actually returned. If
482 * VERR_BUFFER_OVERFLOW is returned, this is set to the
483 * required buffer size.
484 */
485 DECLCALLBACKMEMBER(int, pfnQueryProp,(PRTLDRMODINTERNAL pMod, RTLDRPROP enmProp, void const *pvBits,
486 void *pvBuf, size_t cbBuf, size_t *pcbRet));
487
488 /**
489 * Verify the image signature.
490 *
491 * This may permform additional integrity checks on the image structures that
492 * was not done when opening the image.
493 *
494 * @returns IPRT status code.
495 * @retval VERR_LDRVI_NOT_SIGNED if not signed.
496 *
497 * @param pMod Pointer to the loader module structure.
498 * @param pfnCallback Callback that does the signature and certificate
499 * verification.
500 * @param pvUser User argument for the callback.
501 * @param pErrInfo Pointer to an error info buffer. Optional.
502 */
503 DECLCALLBACKMEMBER(int, pfnVerifySignature,(PRTLDRMODINTERNAL pMod, PFNRTLDRVALIDATESIGNEDDATA pfnCallback, void *pvUser,
504 PRTERRINFO pErrInfo));
505
506 /**
507 * Calculate the image hash according the image signing rules.
508 *
509 * @returns IPRT status code.
510 * @param pMod The module handle.
511 * @param enmDigest Which kind of digest.
512 * @param pszDigest Where to store the image digest.
513 * @param cbDigest Size of the buffer @a pszDigest points at.
514 */
515 DECLCALLBACKMEMBER(int, pfnHashImage,(PRTLDRMODINTERNAL pMod, RTDIGESTTYPE enmDigest, char *pszDigest, size_t cbDigest));
516
517 /**
518 * Try use unwind information to unwind one frame.
519 *
520 * @returns IPRT status code. Last informational status from stack reader callback.
521 * @retval VERR_DBG_NO_UNWIND_INFO if the module contains no unwind information.
522 * @retval VERR_DBG_UNWIND_INFO_NOT_FOUND if no unwind information was found
523 * for the location given by iSeg:off.
524 *
525 * @param pMod Pointer to the module structure.
526 * @param pvBits Pointer to the bits returned by
527 * RTLDROPS::pfnGetBits(), optional.
528 * @param iSeg The segment number of the program counter. UINT32_MAX for RVA.
529 * @param off The offset into @a iSeg. Together with @a iSeg
530 * this corresponds to the RTDBGUNWINDSTATE::uPc
531 * value pointed to by @a pState.
532 * @param pState The unwind state to work.
533 *
534 * @sa RTLdrUnwindFrame, RTDbgModUnwindFrame
535 */
536 DECLCALLBACKMEMBER(int, pfnUnwindFrame,(PRTLDRMODINTERNAL pMod, void const *pvBits, uint32_t iSeg, RTUINTPTR off,
537 PRTDBGUNWINDSTATE pState));
538
539 /** Dummy entry to make sure we've initialized it all. */
540 RTUINT uDummy;
541} RTLDROPS;
542typedef RTLDROPS *PRTLDROPS;
543typedef const RTLDROPS *PCRTLDROPS;
544
545
546/**
547 * Loader module core.
548 */
549typedef struct RTLDRMODINTERNAL
550{
551 /** The loader magic value (RTLDRMOD_MAGIC). */
552 uint32_t u32Magic;
553 /** State. */
554 RTLDRSTATE eState;
555 /** Loader ops. */
556 PCRTLDROPS pOps;
557 /** Pointer to the reader instance. This is NULL for native image. */
558 PRTLDRREADER pReader;
559 /** Image format. */
560 RTLDRFMT enmFormat;
561 /** Image type. */
562 RTLDRTYPE enmType;
563 /** Image endianness. */
564 RTLDRENDIAN enmEndian;
565 /** Image target architecture. */
566 RTLDRARCH enmArch;
567} RTLDRMODINTERNAL;
568
569
570/**
571 * Validates that a loader module handle is valid.
572 *
573 * @returns true if valid.
574 * @returns false if invalid.
575 * @param hLdrMod The loader module handle.
576 */
577DECLINLINE(bool) rtldrIsValid(RTLDRMOD hLdrMod)
578{
579 return VALID_PTR(hLdrMod)
580 && ((PRTLDRMODINTERNAL)hLdrMod)->u32Magic == RTLDRMOD_MAGIC;
581}
582
583
584/**
585 * Native loader module.
586 */
587typedef struct RTLDRMODNATIVE
588{
589 /** The core structure. */
590 RTLDRMODINTERNAL Core;
591 /** The native handle. */
592 uintptr_t hNative;
593 /** The load flags (RTLDRLOAD_FLAGS_XXX). */
594 uint32_t fFlags;
595} RTLDRMODNATIVE;
596/** Pointer to a native module. */
597typedef RTLDRMODNATIVE *PRTLDRMODNATIVE;
598
599/** @copydoc RTLDROPS::pfnGetSymbol */
600DECLCALLBACK(int) rtldrNativeGetSymbol(PRTLDRMODINTERNAL pMod, const char *pszSymbol, void **ppvValue);
601/** @copydoc RTLDROPS::pfnClose */
602DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod);
603
604/**
605 * Load a native module using the native loader.
606 *
607 * @returns iprt status code.
608 * @param pszFilename The image filename.
609 * @param phHandle Where to store the module handle on success.
610 * @param fFlags RTLDRLOAD_FLAGS_XXX.
611 * @param pErrInfo Where to return extended error information. Optional.
612 */
613DECLHIDDEN(int) rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, uint32_t fFlags, PRTERRINFO pErrInfo);
614
615/**
616 * Load a system library.
617 *
618 * @returns iprt status code.
619 * @param pszFilename The image filename.
620 * @param pszExt Extension to add. NULL if none.
621 * @param fFlags RTLDRLOAD_FLAGS_XXX.
622 * @param phLdrMod Where to return the module handle on success.
623 */
624DECLHIDDEN(int) rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod);
625
626DECLHIDDEN(int) rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offNtHdrs, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
627DECLHIDDEN(int) rtldrELFOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
628DECLHIDDEN(int) rtldrLXOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offLxHdr, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
629DECLHIDDEN(int) rtldrMachOOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF offImage, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
630DECLHIDDEN(int) rtldrFatOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
631DECLHIDDEN(int) rtldrkLdrOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phLdrMod, PRTERRINFO pErrInfo);
632
633
634DECLHIDDEN(int) rtLdrReadAt(RTLDRMOD hLdrMod, void *pvBuf, uint32_t iDbgInfo, RTFOFF off, size_t cb);
635
636RT_C_DECLS_END
637
638#endif /* !IPRT_INCLUDED_INTERNAL_ldr_h */
639
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