VirtualBox

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

Last change on this file since 74962 was 74638, checked in by vboxsync, 6 years ago

IPRT: Initial adaption of the kstuff loader code. bugref:9232

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