source: trunk/kLdr/kLdr.h@ 2879

Last change on this file since 2879 was 2879, checked in by bird, 19 years ago

started coding on the LX module interpreter.

  • Property svn:keywords set to Id
File size: 43.1 KB
RevLine 
[2826]1/* $Id: kLdr.h 2879 2006-11-12 17:21:16Z bird $ */
[2821]2/** @file
3 *
4 * kLdr - The Dynamic Loader.
5 *
6 * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>
7 *
8 *
9 * This file is part of kLdr.
10 *
11 * kLdr is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * kLdr is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with kLdr; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#ifndef __kLdr_h__
28#define __kLdr_h__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
[2824]34/* kLdr depend on size_t, [u]intNN_t, [u]intptr_t and some related constants. */
[2821]35#include <sys/types.h>
[2825]36#include <stddef.h>
37#ifdef _MSC_VER
38typedef signed char int8_t;
39typedef unsigned char uint8_t;
40typedef signed short int16_t;
41typedef unsigned short uint16_t;
42typedef signed int int32_t;
43typedef unsigned int uint32_t;
44typedef signed __int64 int64_t;
45typedef unsigned __int64 uint64_t;
[2836]46typedef int64_t intmax_t;
[2825]47typedef uint64_t uintmax_t;
[2879]48#define UINT32_C(c) (c##U)
[2825]49#else
50# include <stdint.h>
51#endif
[2821]52
[2824]53
[2825]54/** @defgroup grp_kLdrRdr kLdrRdr - The file provider
55 * @{ */
[2821]56
[2848]57/** The kLdr address type. */
58typedef uint64_t KLDRADDR;
59/** Pointer to a kLdr address. */
60typedef KLDRADDR *PKLDRADDR;
61/** Pointer to a const kLdr address. */
62typedef const KLDRADDR *PCKLDRADDR;
63
64/** NIL address. */
65#define NIL_KLDRADDR (~(uint64_t)0)
66
[2859]67/** @def PRI_KLDRADDR
68 * printf format type. */
69#ifdef _MSC_VER
70# define PRI_KLDRADDR "I64x"
71#else
72# define PRI_KLDRADDR "llx"
73#endif
74
75
[2848]76/** The kLdr size type. */
77typedef uint64_t KLDRSIZE;
78/** Pointer to a kLdr size. */
79typedef KLDRSIZE *PKLDRSIZE;
80/** Pointer to a const kLdr size. */
81typedef const KLDRSIZE *PCKLDRSIZE;
82
[2859]83/** @def PRI_KLDRSIZE
84 * printf format type. */
85#ifdef _MSC_VER
86# define PRI_KLDRSIZE "I64x"
87#else
88# define PRI_KLDRSIZE "llx"
89#endif
[2848]90
[2861]91/** Pointer to a loader segment. */
92typedef struct KLDRSEG *PKLDRSEG;
93/** Pointer to a loader segment. */
94typedef const struct KLDRSEG *PCKLDRSEG;
[2848]95
[2859]96
[2861]97
98
[2840]99/**
100 * Memory Mapping Protections.
101 *
102 * @remark Shared segments can be mapped using the non copy-on-write variant.
103 * (Normally the copy-on-write variant is used because changes must
104 * be private and not shared with other processes mapping the file.)
105 */
[2829]106typedef enum KLDRPROT
107{
108 /** The usual invalid 0. */
109 KLDRPROT_INVALID = 0,
110 /** No access (page not present). */
111 KLDRPROT_NOACCESS,
112 /** Read only. */
113 KLDRPROT_READONLY,
114 /** Read & write. */
115 KLDRPROT_READWRITE,
116 /** Read & copy on write. */
117 KLDRPROT_WRITECOPY,
118 /** Execute only. */
119 KLDRPROT_EXECUTE,
120 /** Execute & read. */
[2830]121 KLDRPROT_EXECUTE_READ,
[2829]122 /** Execute, read & write. */
123 KLDRPROT_EXECUTE_READWRITE,
124 /** Execute, read & copy on write. */
125 KLDRPROT_EXECUTE_WRITECOPY,
126 /** The usual end value. (exclusive) */
127 KLDRPROT_END,
128 /** Blow the type up to 32-bits. */
129 KLDRPROT_32BIT_HACK = 0x7fffffff
130} KLDRPROT;
131
132
[2825]133/** Pointer to a file provider instance core. */
134typedef struct KLDRRDR *PKLDRRDR;
135/** Pointer to a file provider instance core pointer. */
136typedef struct KLDRRDR **PPKLDRRDR;
137
[2821]138/**
[2825]139 * File provider instance operations.
140 */
141typedef struct KLDRRDROPS
142{
143 /** The name of this file provider. */
144 const char *pszName;
145 /** Pointer to the next file provider. */
146 const struct KLDRRDROPS *pNext;
147
148 /** Try create a new file provider instance.
149 *
150 * @returns 0 on success, OS specific error code on failure.
151 * @param ppRdr Where to store the file provider instance.
152 * @param pszFilename The filename to open.
153 */
154 int (* pfnCreate)( PPKLDRRDR ppRdr, const char *pszFilename);
155 /** Destroy the file provider instance.
156 *
157 * @returns 0 on success, OS specific error code on failure.
158 * On failure, the file provider instance will be in an indeterminate state - don't touch it!
159 * @param pRdr The file provider instance.
160 */
161 int (* pfnDestroy)( PKLDRRDR pRdr);
[2856]162 /** @copydoc kLdrRdrRead */
[2825]163 int (* pfnRead)( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
[2856]164 /** @copydoc kLdrRdrAllMap */
[2825]165 int (* pfnAllMap)( PKLDRRDR pRdr, const void **ppvBits);
[2856]166 /** @copydoc kLdrRdrAllUnmap */
[2825]167 int (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits);
[2856]168 /** @copydoc kLdrRdrSize */
[2825]169 off_t (* pfnSize)( PKLDRRDR pRdr);
[2856]170 /** @copydoc kLdrRdrTell */
[2825]171 off_t (* pfnTell)( PKLDRRDR pRdr);
[2856]172 /** @copydoc kLdrRdrName */
[2825]173 const char * (* pfnName)(PKLDRRDR pRdr);
[2856]174 /** @copydoc kLdrRdrPageSize */
175 size_t (* pfnPageSize)(PKLDRRDR pRdr);
176 /** @copydoc kLdrRdrMap */
[2861]177 int (* pfnMap)( PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed);
178 /** @copydoc kLdrRdrRefresh */
179 int (* pfnRefresh)( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
[2856]180 /** @copydoc kLdrRdrProtect */
[2861]181 int (* pfnProtect)( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
[2856]182 /** @copydoc kLdrRdrUnmap */
[2861]183 int (* pfnUnmap)( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
[2856]184 /** @copydoc kLdrRdrDone */
[2861]185 void (* pfnDone)( PKLDRRDR pRdr);
[2829]186 /** The usual non-zero dummy that makes sure we've initialized all members. */
187 uint32_t u32Dummy;
[2825]188} KLDRRDROPS;
189/** Pointer to file provider operations. */
190typedef KLDRRDROPS *PKLDRRDROPS;
191/** Pointer to const file provider operations. */
192typedef const KLDRRDROPS *PCKLDRRDROPS;
193
194
195/**
196 * File provider instance core.
197 */
198typedef struct KLDRRDR
199{
[2856]200 /** Magic number (KLDRRDR_MAGIC). */
201 uint32_t u32Magic;
[2825]202 /** Pointer to the file provider operations. */
203 PCKLDRRDROPS pOps;
204} KLDRRDR;
205
[2856]206/** The magic for KLDRRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */
207#define KLDRRDR_MAGIC 0x19610919
208
[2825]209void kLdrRdrAddProvider(PKLDRRDROPS pAdd);
210
211int kLdrRdrOpen( PPKLDRRDR ppRdr, const char *pszFilename);
212int kLdrRdrClose( PKLDRRDR pRdr);
213int kLdrRdrRead( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
214int kLdrRdrAllMap( PKLDRRDR pRdr, const void **ppvBits);
215int kLdrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits);
216off_t kLdrRdrSize( PKLDRRDR pRdr);
217off_t kLdrRdrTell( PKLDRRDR pRdr);
218const char *kLdrRdrName(PKLDRRDR pRdr);
[2856]219size_t kLdrRdrPageSize(PKLDRRDR pRdr);
[2861]220int kLdrRdrMap( PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed);
221int kLdrRdrRefresh( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
222int kLdrRdrProtect( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
223int kLdrRdrUnmap( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
[2856]224void kLdrRdrDone( PKLDRRDR pRdr);
[2825]225
226/** @} */
227
228
229
230/** @defgroup grp_kLdrMod kLdrMod - The executable image intepreter
231 * @{ */
232
[2855]233/**
234 * CPU Architecture.
235 * @todo Double check the non intel architectures.
236 */
237typedef enum KLDRARCH
238{
239 /** The usual invalid one. */
240 KLDRARCH_INVALID = 0,
241 /** Clone or Intel 16-bit x86. */
242 KLDRARCH_X86_16,
243 /** Clone or Intel 32-bit x86. */
244 KLDRARCH_X86_32,
245 /** AMD64 (including clones). */
246 KLDRARCH_AMD64,
247 /** Itanic (64-bit). */
248 KLDRARCH_IA64,
249 /** ALPHA (64-bit). */
250 KLDRARCH_ALPHA,
251 /** ALPHA limited to 32-bit. */
252 KLDRARCH_ALPHA_32,
253 /** 32-bit ARM. */
254 KLDRARCH_ARM_32,
255 /** 64-bit ARM. */
256 KLDRARCH_ARM_64,
257 /** 32-bit MIPS. */
258 KLDRARCH_MIPS_32,
259 /** 64-bit MIPS. */
260 KLDRARCH_MIPS_64,
261 /** 32-bit PowerPC. */
262 KLDRARCH_POWERPC_32,
263 /** 64-bit PowerPC. */
264 KLDRARCH_POWERPC_64,
265 /** 32-bit SPARC. */
266 KLDRARCH_SPARC_32,
267 /** 64-bit SPARC. */
268 KLDRARCH_SPARC_64,
269 /** The end of the valid architecture values (exclusive). */
270 KLDRARCH_END,
271 /** Hack to blow the type up to 32-bit. */
272 KLDRARCH_32BIT_HACK = 0x7fffffff
273} KLDRARCH;
274/** Pointer to a CPU architecture type. */
275typedef KLDRARCH *PKLDRARCH;
[2849]276
[2825]277/**
[2855]278 * CPU models.
279 */
280typedef enum KLDRCPU
281{
282 /** The usual invalid cpu. */
283 KLDRCPU_INVALID = 0,
284 /** @name KLDRARCH_X86_16
285 * @{ */
286 KLDRCPU_I8086,
287 KLDRCPU_I8088,
288 KLDRCPU_I80186,
289 KLDRCPU_I80286,
290 KLDRCPU_I386_16,
291 KLDRCPU_I486_16,
292 KLDRCPU_I486SX_16,
293 KLDRCPU_I586_16,
294 KLDRCPU_I686_16,
295 KLDRCPU_P4_16,
296 KLDRCPU_CORE2_16,
297 KLDRCPU_K6_16,
298 KLDRCPU_K7_16,
299 KLDRCPU_K8_16,
300 KLDRCPU_FIRST_X86_16 = KLDRCPU_I8086,
301 KLDRCPU_LAST_X86_16 = KLDRCPU_K8_16,
302 /** @} */
303
304 /** @name KLDRARCH_X86_32
305 * @{ */
306 KLDRCPU_X86_32_BLEND,
307 KLDRCPU_I386,
308 KLDRCPU_I486,
309 KLDRCPU_I486SX,
310 KLDRCPU_I586,
311 KLDRCPU_I686,
312 KLDRCPU_P4,
313 KLDRCPU_CORE2_32,
314 KLDRCPU_K6,
315 KLDRCPU_K7,
316 KLDRCPU_K8_32,
317 KLDRCPU_FIRST_X86_32 = KLDRCPU_I386,
318 KLDRCPU_LAST_X86_32 = KLDRCPU_K8_32,
319 /** @} */
320
321 /** @name KLDRARCH_AMD64
322 * @{ */
323 KLDRCPU_AMD64_BLEND,
324 KLDRCPU_K8,
325 KLDRCPU_P4_64,
326 KLDRCPU_CORE2,
327 KLDRCPU_FIRST_AMD64 = KLDRCPU_K8,
328 KLDRCPU_LAST_AMD64 = KLDRCPU_CORE2,
329 /** @} */
330
331 /** The end of the valid cpu values (exclusive). */
332 KLDRCPU_END,
333 /** Hack to blow the type up to 32-bit. */
334 KLDRCPU_32BIT_HACK = 0x7fffffff
335} KLDRCPU;
336/** Pointer to a CPU type. */
337typedef KLDRCPU *PKLDRCPU;
338
339void kLdrGetArchCpu(PKLDRARCH penmArch, PKLDRCPU penmCpu);
340int kLdrCompareCpus(KLDRARCH enmCodeArch, KLDRCPU enmCodeCpu, KLDRARCH enmArch, KLDRCPU enmCpu);
341
342
343/**
[2849]344 * Debug info type (from the loader point of view).
345 */
346typedef enum KLDRDBGINFOTYPE
347{
348 /** The usual invalid enum value. */
349 KLDRDBGINFOTYPE_INVALID = 0,
[2856]350 /** Unknown debug info format. */
351 KLDRDBGINFOTYPE_UNKNOWN,
[2849]352 /** Stabs. */
353 KLDRDBGINFOTYPE_STABS,
354 /** Debug With Arbitrary Record Format (DWARF). */
355 KLDRDBGINFOTYPE_DWARF,
356 /** Microsoft Codeview debug info. */
357 KLDRDBGINFOTYPE_CODEVIEW,
358 /** Watcom debug info. */
359 KLDRDBGINFOTYPE_WATCOM,
360 /** IBM High Level Language debug info.. */
361 KLDRDBGINFOTYPE_HLL,
362 /** The end of the valid debug info values (exclusive). */
363 KLDRDBGINFOTYPE_END,
364 /** Blow the type up to 32-bit. */
365 KLDRDBGINFOTYPE_32BIT_HACK = 0x7fffffff
366} KLDRDBGINFOTYPE;
367/** Pointer to a kLdr debug info type. */
368typedef KLDRDBGINFOTYPE *PKLDRDBGINFOTYPE;
369
370
371/**
[2835]372 * Stack information.
373 */
374typedef struct KLDRSTACKINFO
375{
[2848]376 /** The base address of the stack (sub) segment.
377 * Set this to NIL_KLDRADDR if the module doesn't include any stack segment. */
378 KLDRADDR Address;
[2835]379 /** The base address of the stack (sub) segment, link address.
[2848]380 * Set this to NIL_KLDRADDR if the module doesn't include any stack (sub)segment. */
381 KLDRADDR LinkAddress;
[2835]382 /** The stack size of the main thread.
383 * If no stack (sub)segment in the module, this is the stack size of the main thread.
384 * If the module doesn't contain this kind of information this field will be set to 0. */
[2848]385 KLDRSIZE cbStack;
[2835]386 /** The stack size of non-main threads.
387 * If the module doesn't contain this kind of information this field will be set to 0. */
[2848]388 KLDRSIZE cbStackThread;
389} KLDRSTACKINFO;
390/** Pointer to stack information. */
391typedef KLDRSTACKINFO *PKLDRSTACKINFO;
392/** Pointer to const stack information. */
393typedef const KLDRSTACKINFO *PCKLDRSTACKINFO;
[2835]394
395
396/**
[2821]397 * Loader segment.
398 */
399typedef struct KLDRSEG
400{
[2832]401 /** Variable free to use for the kLdr user. */
402 void *pvUser;
[2854]403 /** The segment name. (Might not be zero terminated!) */
404 const char *pchName;
405 /** The length of the segment name. */
406 uint32_t cchName;
[2857]407 /** The segment protection. */
408 KLDRPROT enmProt;
[2821]409 /** The size of the segment. */
[2848]410 KLDRSIZE cb;
[2856]411 /** The required segment alignment.
412 * The to 0 if the segment isn't supposed to be mapped. */
[2854]413 KLDRADDR Alignment;
414 /** The link address.
[2856]415 * Set to NIL_KLDRADDR if the segment isn't supposed to be
416 * mapped or if the image doesn't have link addresses. */
[2848]417 KLDRADDR LinkAddress;
[2856]418 /** File offset of the segment.
419 * Set to -1 if no file backing (like BSS). */
420 off_t offFile;
421 /** Size of the file bits of the segment.
422 * Set to -1 if no file backing (like BSS). */
423 off_t cbFile;
[2859]424 /** The relative virtual address when mapped.
425 * Set to NIL_KLDRADDR if the segment isn't supposed to be mapped. */
426 KLDRADDR RVA;
427 /** The size of the segment including the alignment gap up to the next segment when mapped. */
428 size_t cbMapped;
[2857]429 /** The address the segment was mapped at by kLdrModMap().
430 * Set to 0 if not mapped. */
431 uintptr_t MapAddress;
[2848]432} KLDRSEG;
[2821]433
434
435/**
[2832]436 * Loader module format.
437 */
438typedef enum KLDRFMT
439{
440 /** The usual invalid 0 format. */
441 KLDRFMT_INVALID = 0,
442 /** The native OS loader. */
443 KLDRFMT_NATIVE,
444 /** The AOUT loader. */
445 KLDRFMT_AOUT,
446 /** The ELF loader. */
447 KLDRFMT_ELF,
448 /** The LX loader. */
449 KLDRFMT_LX,
450 /** The mach-o loader. */
451 KLDRFMT_MACHO,
452 /** The LX loader. */
453 KLDRFMT_PE,
454 /** The end of the valid format values (exclusive). */
455 KLDRFMT_END,
456 /** Hack to blow the type up to 32-bit. */
457 KLDRFMT_32BIT_HACK = 0x7fffffff
458} KLDRFMT;
459
460
461/**
[2821]462 * Loader module type.
463 */
464typedef enum KLDRTYPE
465{
466 /** The usual invalid 0 type. */
467 KLDRTYPE_INVALID = 0,
[2832]468 /** Object file. */
469 KLDRTYPE_OBJECT,
470 /** Executable module, fixed load address. */
471 KLDRTYPE_EXECUTABLE_FIXED,
472 /** Executable module, relocatable, non-fixed load address. */
473 KLDRTYPE_EXECUTABLE_RELOCATABLE,
474 /** Executable module, position independent code, non-fixed load address. */
475 KLDRTYPE_EXECUTABLE_PIC,
476 /** Shared library, fixed load address.
477 * Typically a system library. */
478 KLDRTYPE_SHARED_LIBRARY_FIXED,
479 /** Shared library, relocatable, non-fixed load address. */
480 KLDRTYPE_SHARED_LIBRARY_RELOCATABLE,
481 /** Shared library, position independent code, non-fixed load address. */
482 KLDRTYPE_SHARED_LIBRARY_PIC,
483 /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */
484 KLDRTYPE_FORWARDER_DLL,
485 /** Core or dump. */
486 KLDRTYPE_CORE,
487 /** The end of the valid types values (exclusive). */
[2821]488 KLDRTYPE_END,
489 /** Hack to blow the type up to 32-bit. */
490 KLDRTYPE_32BIT_HACK = 0x7fffffff
491} KLDRTYPE;
492
493
494/**
[2832]495 * Loader endian indicator.
496 */
497typedef enum KLDRENDIAN
498{
499 /** The usual invalid endian. */
500 KLDRENDIAN_INVALID,
501 /** Little endian. */
502 KLDRENDIAN_LITTLE,
503 /** Bit endian. */
504 KLDRENDIAN_BIG,
505 /** Endianness doesn't have a meaning in the context. */
506 KLDRENDIAN_NA,
507 /** The end of the valid endian values (exclusive). */
508 KLDRENDIAN_END,
509 /** Hack to blow the type up to 32-bit. */
510 KLDRENDIAN_32BIT_HACK = 0x7fffffff
511} KLDRENDIAN;
512
513
[2851]514/** Pointer to a module interpreter method table. */
515typedef struct KLDRMODOPS *PKLDRMODOPS;
516/** Pointer to const module interpreter methods table. */
517typedef const struct KLDRMODOPS *PCKLDRMODOPS;
518
[2832]519/**
[2851]520 * Module interpreter instance.
521 * All members are read only unless you're kLdrMod or the module interpreter.
[2821]522 */
523typedef struct KLDRMOD
524{
[2856]525 /** Magic number (KLDRMOD_MAGIC). */
[2825]526 uint32_t u32Magic;
[2832]527 /** The format of this module. */
528 KLDRFMT enmFmt;
529 /** The type of module. */
[2825]530 KLDRTYPE enmType;
[2832]531 /** The architecture this module was built for. */
532 KLDRARCH enmArch;
533 /** The minium cpu this module was built for.
534 * This might not be accurate, so use kLdrModCanExecuteOn() to check. */
535 KLDRARCH enmCpu;
536 /** The endian used by the module. */
537 KLDRENDIAN enmEndian;
[2821]538 /** The filename length (bytes). */
539 uint32_t cchFilename;
540 /** The filename. */
541 const char *pszFilename;
542 /** The module name. */
543 const char *pszName;
544 /** The module name length (bytes). */
545 uint32_t cchName;
546 /** The number of segments in the module. */
547 uint32_t cSegments;
[2851]548 /** Pointer to the loader methods.
549 * Not meant for calling directly thru! */
550 PCKLDRMODOPS pOps;
[2854]551 /** Pointer to the read instance. (Can be NULL after kLdrModDone().)*/
552 PKLDRRDR pRdr;
[2832]553 /** The module data. */
554 void *pvData;
[2821]555 /** Segments. (variable size, can be zero) */
556 KLDRSEG aSegments[1];
557} KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
558
[2851]559/** The magic for KLDRMOD::u32Magic. (Kosuke Fujishima) */
560#define KLDRMOD_MAGIC 0x19640707
[2821]561
[2851]562
[2832]563/** Special base address value alias for the link address. */
[2848]564#define KLDRMOD_BASEADDRESS_LINK (~(KLDRADDR)1)
[2832]565/** Special base address value alias for the actual load address (must be mapped). */
[2848]566#define KLDRMOD_BASEADDRESS_MAP (~(KLDRADDR)2)
[2825]567
[2848]568/** Special import module ordinal value used to indicate that there is no
569 * specific module associated with the requested symbol. */
[2859]570#define NIL_KLDRMOD_IMPORT (~(uint32_t)0)
[2848]571
572/** Special symbol ordinal value used to indicate that the symbol
573 * only has a string name. */
[2859]574#define NIL_KLDRMOD_SYM_ORDINAL (~(uint32_t)0)
[2848]575
576
[2832]577/** @name Load symbol kind flags.
578 * @{ */
579/** The bitness doesn't matter. */
[2848]580#define KLDRSYMKIND_NO_BIT 0x00000000
[2832]581/** 16-bit symbol. */
[2848]582#define KLDRSYMKIND_16BIT 0x00000001
[2832]583/** 32-bit symbol. */
[2848]584#define KLDRSYMKIND_32BIT 0x00000002
[2832]585/** 64-bit symbol. */
[2848]586#define KLDRSYMKIND_64BIT 0x00000003
[2832]587/** Mask out the bit.*/
[2848]588#define KLDRSYMKIND_BIT_MASK 0x00000003
[2832]589/** We don't know the type of symbol. */
[2848]590#define KLDRSYMKIND_NO_TYPE 0x00000000
[2832]591/** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
[2848]592#define KLDRSYMKIND_CODE 0x00000010
[2832]593/** The symbol is a data object. */
[2848]594#define KLDRSYMKIND_DATA 0x00000020
[2832]595/** Mask out the symbol type. */
[2848]596#define KLDRSYMKIND_TYPE_MASK 0x00000030
[2832]597/** Valid symbol kind mask. */
[2848]598#define KLDRSYMKIND_MASK 0x00000033
[2850]599/** Weak symbol. */
600#define KLDRSYMKIND_WEAK 0x00000100
[2854]601/** Forwarder symbol. */
602#define KLDRSYMKIND_FORWARDER 0x00000200
[2832]603/** @} */
[2825]604
605/** @name kLdrModEnumSymbols flags.
606 * @{ */
607/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
[2848]608#define KLDRMOD_ENUM_SYMS_FLAGS_ALL 0x00000001
[2825]609/** @} */
610
[2832]611
[2848]612/**
613 * Callback for resolving imported symbols when applying fixups.
614 *
615 * @returns 0 on success and *pValue and *pfKind filled.
616 * @returns Non-zero OS specific or kLdr status code on failure.
617 *
618 * @param pMod The module which fixups are begin applied.
619 * @param iImport The import module ordinal number or NIL_KLDRMOD_IMPORT.
[2859]620 * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
621 * @param pszSymbol The symbol name. Can be NULL if iSymbol isn't nil.
[2848]622 * @param puValue Where to store the symbol value.
623 * @param pfKind Where to store the symbol kind flags.
624 * @param pvUser The user parameter specified to the relocation function.
625 */
[2859]626typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pszSymbol,
[2848]627 PKLDRADDR puValue, uint32_t *pfKind, void *pvUser);
628/** Pointer to a import callback. */
[2832]629typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
[2848]630
631/**
632 * Symbol enumerator callback.
633 *
634 * @returns 0 if enumeration should continue.
[2849]635 * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumSymbols().
[2848]636 *
637 * @param pMod The module which symbols are being enumerated.s
[2859]638 * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
[2848]639 * @param pszSymbol The symbol name. This can be NULL if there is a symbol ordinal.
640 * This can also be an empty string if the symbol doesn't have a name
641 * or it's name has been stripped.
642 * @param uValue The symbol value.
643 * @param fKind The symbol kind flags.
644 * @param pvUser The user parameter specified to kLdrModEnumSymbols().
645 */
[2859]646typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, uint32_t iSymbol, const char *pszSymbol,
[2848]647 KLDRADDR uValue, uint32_t fKind, void *pvUser);
648/** Pointer to a symbol enumerator callback. */
[2832]649typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
650
[2849]651/**
652 * Debug info enumerator callback.
653 *
654 * @returns 0 to continue the enumeration.
655 * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumDbgInfo().
656 *
657 * @param pMod The module.
[2856]658 * @param iDbgInfo The debug info ordinal number / id.
[2849]659 * @param enmType The debug info type.
[2856]660 * @param iMajorVer The major version number of the debug info format. -1 if unknow - implies invalid iMinorVer.
661 * @param iMinorVer The minor version number of the debug info format. -1 when iMajorVer is -1.
[2849]662 * @param offFile The file offset *if* this type has one specific location in the executable image file.
663 * This is -1 if there isn't any specific file location.
[2856]664 * @param LinkAddress The link address of the debug info if it's loadable. NIL_KLDRADDR if not loadable.
665 * @param cb The size of the debug information. -1 is used if this isn't applicable.
[2849]666 * @param pszExtFile This points to the name of an external file containing the debug info.
667 * This is NULL if there isn't any external file.
668 * @param pvUser The user parameter specified to kLdrModEnumDbgInfo.
669 */
[2856]670typedef int FNKLDRENUMDBG(PKLDRMOD pMod, uint32_t iDbgInfo, KLDRDBGINFOTYPE enmType, int16_t iMajorVer, int16_t iMinorVer,
[2859]671 off_t offFile, KLDRADDR LinkAddress, KLDRSIZE cb, const char *pszExtFile, void *pvUser);
[2856]672/** Pointer to a debug info enumberator callback. */
673typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;
[2849]674
[2832]675int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod);
[2845]676int kLdrModOpenFromRdr(PKLDRRDR pRdr, PPKLDRMOD ppMod);
677int kLdrModOpenNative(const char *pszFilename, PPKLDRMOD ppMod);
[2877]678int kLdrModOpenNativeByHandle(uintptr_t uHandle, PPKLDRMOD ppMod);
[2832]679int kLdrModClose(PKLDRMOD pMod);
[2848]680
[2859]681int kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t iSymbol,
[2854]682 const char *pszSymbol, PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser,
683 PKLDRADDR puValue, uint32_t *pfKind);
684int kLdrModEnumSymbols(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress,
685 uint32_t fFlags, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
[2855]686int kLdrModGetImport(PKLDRMOD pMod, const void *pvBits, uint32_t iImport, char *pszName, size_t cchName);
687int32_t kLdrModNumberOfImports(PKLDRMOD pMod, const void *pvBits);
688int kLdrModCanExecuteOn(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
689int kLdrModGetStackInfo(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
690int kLdrModQueryMainEntrypoint(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
691int kLdrModEnumDbgInfo(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
692int kLdrModHasDbgInfo(PKLDRMOD pMod, const void *pvBits);
[2848]693
694/** @name Operations On The Internally Managed Mapping
695 * @{ */
[2832]696int kLdrModMap(PKLDRMOD pMod);
697int kLdrModUnmap(PKLDRMOD pMod);
[2846]698int kLdrModAllocTLS(PKLDRMOD pMod);
[2847]699void kLdrModFreeTLS(PKLDRMOD pMod);
[2846]700int kLdrModReload(PKLDRMOD pMod);
[2848]701int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
[2856]702int kLdrModCallInit(PKLDRMOD pMod, uintptr_t uHandle);
703int kLdrModCallTerm(PKLDRMOD pMod, uintptr_t uHandle);
704int kLdrModCallThread(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching);
[2848]705/** @} */
[2832]706
[2848]707/** @name Operations On The Externally Managed Mappings
708 * @{ */
[2856]709KLDRADDR kLdrModSize(PKLDRMOD pMod);
[2848]710int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
711int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
712 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
[2825]713/** @} */
714
[2849]715
[2851]716/**
717 * The loader module operation.
718 */
719typedef struct KLDRMODOPS
720{
721 /** The name of this module interpreter. */
722 const char *pszName;
723 /** Pointer to the next module interpreter. */
724 PCKLDRMODOPS pNext;
725
726 /**
727 * Create a loader module instance interpreting the executable image found
728 * in the specified file provider instance.
729 *
730 * @returns 0 on success and *ppMod pointing to a module instance.
731 * On failure, a non-zero OS specific error code is returned.
732 * @param pOps Pointer to the registered method table.
733 * @param pRdr The file provider instance to use.
734 * @param offNewHdr The offset of the new header in MZ files. -1 if not found.
735 * @param ppMod Where to store the module instance pointer.
736 */
737 int (* pfnCreate)(PCKLDRMODOPS pOps, PKLDRRDR pRdr, off_t offNewHdr, PPKLDRMOD ppMod);
738 /**
739 * Destroys an loader module instance.
740 *
741 * The caller is responsible for calling kLdrModUnmap() and kLdrFreeTLS() first.
742 *
743 * @returns 0 on success, non-zero on failure. The module instance state
744 * is unknown on failure, it's best not to touch it.
745 * @param pMod The module.
746 */
747 int (* pfnDestroy)(PKLDRMOD pMod);
748
749 /** @copydoc kLdrModQuerySymbol */
[2859]750 int (* pfnQuerySymbol)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t iSymbol,
[2854]751 const char *pszSymbol, PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser,
752 PKLDRADDR puValue, uint32_t *pfKind);
[2851]753 /** @copydoc kLdrModEnumSymbols */
[2854]754 int (* pfnEnumSymbols)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t fFlags,
[2851]755 PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
756 /** @copydoc kLdrModGetImport */
[2855]757 int (* pfnGetImport)(PKLDRMOD pMod, const void *pvBits, uint32_t iImport, char *pszName, size_t cchName);
[2851]758 /** @copydoc kLdrModNumberOfImports */
[2855]759 int32_t (* pfnNumberOfImports)(PKLDRMOD pMod, const void *pvBits);
[2851]760 /** @copydoc kLdrModCanExecuteOn */
[2855]761 int (* pfnCanExecuteOn)(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
[2851]762 /** @copydoc kLdrModGetStackInfo */
[2855]763 int (* pfnGetStackInfo)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
[2851]764 /** @copydoc kLdrModQueryMainEntrypoint */
[2855]765 int (* pfnQueryMainEntrypoint)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
[2851]766 /** @copydoc kLdrModEnumDbgInfo */
[2855]767 int (* pfnEnumDbgInfo)(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
[2851]768 /** @copydoc kLdrModHasDbgInfo */
[2855]769 int (* pfnHasDbgInfo)(PKLDRMOD pMod, const void *pvBits);
[2851]770 /** @copydoc kLdrModMap */
771 int (* pfnMap)(PKLDRMOD pMod);
772 /** @copydoc kLdrModUnmap */
773 int (* pfnUnmap)(PKLDRMOD pMod);
774 /** @copydoc kLdrModAllocTLS */
775 int (* pfnAllocTLS)(PKLDRMOD pMod);
776 /** @copydoc kLdrModFreeTLS */
777 void (* pfnFreeTLS)(PKLDRMOD pMod);
778 /** @copydoc kLdrModReload */
779 int (* pfnReload)(PKLDRMOD pMod);
780 /** @copydoc kLdrModFixupMapping */
781 int (* pfnFixupMapping)(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
782 /** @copydoc kLdrModCallInit */
[2856]783 int (* pfnCallInit)(PKLDRMOD pMod, uintptr_t uHandle);
[2851]784 /** @copydoc kLdrModCallTerm */
[2856]785 int (* pfnCallTerm)(PKLDRMOD pMod, uintptr_t uHandle);
[2851]786 /** @copydoc kLdrModCallThread */
[2856]787 int (* pfnCallThread)(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching);
[2851]788 /** @copydoc kLdrModSize */
[2856]789 KLDRADDR (* pfnSize)(PKLDRMOD pMod);
[2851]790 /** @copydoc kLdrModGetBits */
791 int (* pfnGetBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
792 /** @copydoc kLdrModRelocateBits */
793 int (* pfnRelocateBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
794 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
795 /** Dummy which should be assigned a non-zero value. */
796 uint32_t uEndOfStructure;
797} KLDRMODOPS;
798
799
[2848]800/** @} */
[2825]801
802
803
[2848]804
[2832]805/** @defgroup grp_kLdrDyld kLdrDyld - The dynamic loader
[2825]806 * @{ */
807
[2832]808/** The handle to a dynamic loader module. */
[2833]809typedef struct KLDRDYLDMOD *HKLDRMOD;
[2832]810/** Pointer to the handle to a dynamic loader module. */
811typedef HKLDRMOD *PHKLDRMOD;
[2833]812/** NIL handle value. */
813#define NIL_HKLDRMOD ((HKLDRMOD)0)
[2825]814
815
[2832]816/**
817 * File search method.
818 *
819 * In addition to it's own way of finding files, kLdr emulates
820 * the methods employed by the most popular systems.
821 */
822typedef enum KLDRDYLDSEARCH
823{
824 /** The usual invalid file search method. */
825 KLDRDYLD_SEARCH_INVALID = 0,
826 /** Uses the kLdr file search method.
827 * @todo invent me. */
828 KLDRDYLD_SEARCH_KLDR,
829 /** Use the emulation closest to the host system. */
830 KLDRDYLD_SEARCH_HOST,
831 /** Emulate the OS/2 file search method.
832 * On non-OS/2 systems, BEGINLIBPATH, LIBPATH, ENDLIBPATH and LIBPATHSTRICT are
833 * taken form the environment. */
834 KLDRDYLD_SEARCH_OS2,
835 /** Emulate the standard window file search method. */
836 KLDRDYLD_SEARCH_WINDOWS,
837 /** Emulate the alternative window file search method. */
838 KLDRDYLD_SEARCH_WINDOWS_ALTERED,
839 /** Emulate the most common UNIX file search method. */
840 KLDRDYLD_SEARCH_UNIX_COMMON,
[2833]841 /** End of the valid file search method values. */
842 KLDRDYLD_SEARCH_END,
843 /** Hack to blow the type up to 32-bit. */
844 KLDRDYLD_SEARCH_32BIT_HACK = 0x7fffffff
[2832]845} KLDRDYLDSEARCH;
846
[2836]847/** @name kLdrDyldLoad and kLdrDyldFindByName flags.
[2832]848 * @{ */
849/** The symbols in the module should be loaded into the global unix namespace.
850 * If not specified, the symbols are local and can only be referenced directly. */
851#define KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS 0x00000001
[2870]852/** The symbols in the module should be loaded into the global unix namespace and
853 * it's symbols should take precedence over all currently loaded modules.
854 * This implies KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS. */
855#define KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS 0x00000002
[2832]856/** The module shouldn't be found by a global module search.
857 * If not specified, the module can be found by unspecified module searches,
858 * typical used when loading import/dep modules. */
[2870]859#define KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE 0x00000004
[2843]860/** Do a recursive initialization calls instead of defering them to the outermost call. */
[2870]861#define KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT 0x00000008
[2843]862/** We're loading the executable module.
[2867]863 * @internal */
[2843]864#define KLDRDYLD_LOAD_FLAGS_EXECUTABLE 0x40000000
[2832]865/** @} */
866
867
[2843]868int kLdrDyldLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
[2833]869 unsigned fFlags, PHKLDRMOD phMod, char *pszErr, size_t cchErr);
[2832]870int kLdrDyldUnload(HKLDRMOD hMod);
[2843]871int kLdrDyldFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
[2836]872 unsigned fFlags, PHKLDRMOD phMod);
[2833]873int kLdrDyldFindByAddress(uintptr_t Address, PHKLDRMOD phMod, uint32_t *piSegment, uintptr_t *poffSegment);
[2832]874int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, size_t cchName);
[2835]875int kLdrDyldGetFilename(HKLDRMOD hMod, char *pszFilename, size_t cchFilename);
[2832]876int kLdrDyldQuerySymbol(HKLDRMOD hMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind);
877
878/** @name OS/2 like API
879 * @{ */
880int kLdrDosLoadModule(char *pszObject, size_t cbObject, const char *pszModule, PHKLDRMOD phMod);
881int kLdrDosFreeModule(HKLDRMOD hMod);
882int kLdrDosQueryModuleHandle(const char *pszModname, PHKLDRMOD phMod);
883int kLdrDosQueryModuleName(HKLDRMOD hMod, size_t cchName, char *pszName);
884int kLdrDosQueryProcAddr(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, void **ppvProcAddr);
885int kLdrDosQueryProcType(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, uint32_t *pfProcType);
886int kLdrDosQueryModFromEIP(PHKLDRMOD phMod, uint32_t *piObject, size_t cbName, char *pszName, uintptr_t *poffObject, uintptr_t ulEIP);
887int kLdrDosReplaceModule(const char *pszOldModule, const char *pszNewModule, const char *pszBackupModule);
888int kLdrDosGetResource(HKLDRMOD hMod, uint32_t idType, uint32_t idName, void **pvResAddr);
889int kLdrDosQueryResourceSize(HKLDRMOD hMod, uint32_t idTypeID, uint32_t idName, uint32_t *pcb);
890int kLdrDosFreeResource(void *pvResAddr);
891/** @} */
892
893/** @name POSIX like API
894 * @{ */
895HKLDRMOD kLdrDlOpen(const char *pszLibrary, int fFlags);
896const char *kLdrDlError(void);
897void * kLdrDlSym(HKLDRMOD hMod, const char *pszSymbol);
898int kLdrDlClose(HKLDRMOD hMod);
899/** @} */
900
901/** @name Win32 like API
902 * @{ */
903HKLDRMOD kLdrWLoadLibrary(const char *pszFilename);
904HKLDRMOD kLdrWLoadLibraryEx(const char *pszFilename, void *hFileReserved, uint32_t fFlags);
905uint32_t kLdrWGetModuleFileName(HKLDRMOD hMod, char *pszModName, size_t cchModName);
906HKLDRMOD kLdrWGetModuleHandle(const char *pszFilename);
907int kLdrWGetModuleHandleEx(uint32_t fFlags, const char *pszFilename, HKLDRMOD hMod);
908void * kLdrWGetProcAddress(HKLDRMOD hMod, const char *pszProcName);
909uint32_t kLdrWGetDllDirectory(size_t cchDir, char *pszDir);
910int kLdrWSetDllDirectory(const char *pszDir);
911int kLdrWFreeLibrary(HKLDRMOD hMod);
912int kLdrWDisableThreadLibraryCalls(HKLDRMOD hMod);
913
914/** @} */
915
916
[2821]917/** @name Process Bootstrapping
918 * @{ */
919
920/**
921 * Argument package from the stub.
922 */
923typedef struct KLDREXEARGS
924{
[2875]925 /** Load & search flags, some which will become defaults. */
[2821]926 uint32_t fFlags;
[2875]927 /** The default search method. */
[2843]928 KLDRDYLDSEARCH enmSearch;
[2821]929 /** The executable file that the stub is supposed to load. */
930 char szExecutable[260];
[2843]931 /** The default prefix used when searching for DLLs. */
932 char szDefPrefix[16];
933 /** The default suffix used when searching for DLLs. */
934 char szDefSuffix[16];
[2821]935 /** The LD_LIBRARY_PATH prefix for the process.. */
[2843]936 char szLibPath[4096 - sizeof(uint32_t) - sizeof(KLDRDYLDSEARCH) - 16 - 16 - 260];
[2821]937} KLDREXEARGS, *PKLDREXEARGS;
[2874]938/** Pointer to a const argument package from the stub. */
939typedef const KLDREXEARGS *PCKLDREXEARGS;
[2821]940
[2875]941void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS);
[2832]942
[2821]943/** @} */
944
945/** @} */
946
[2827]947
948/** @defgroup grp_kLdrErr kLdr Status Codes
949 * kLdr uses a mix of native status codes and it's own status codes.
950 * A status code of 0 means success, all other status codes means failure.
951 * @{
952 */
953#ifdef __OS2__
[2858]954# define KLDR_ERR_BASE 420000
[2827]955#elif defined(__WIN__)
[2858]956# define KLDR_ERR_BASE 420000
[2827]957#else
958# error "port me"
959#endif
960/** The image format is unknown. */
961#define KLDR_ERR_UNKNOWN_FORMAT (KLDR_ERR_BASE + 0)
962/** The MZ image format isn't supported by this kLdr build. */
963#define KLDR_ERR_MZ_NOT_SUPPORTED (KLDR_ERR_BASE + 1)
964/** The NE image format isn't supported by this kLdr build. */
965#define KLDR_ERR_NE_NOT_SUPPORTED (KLDR_ERR_BASE + 2)
966/** The LX image format isn't supported by this kLdr build. */
967#define KLDR_ERR_LX_NOT_SUPPORTED (KLDR_ERR_BASE + 3)
968/** The LE image format isn't supported by this kLdr build. */
969#define KLDR_ERR_LE_NOT_SUPPORTED (KLDR_ERR_BASE + 4)
970/** The PE image format isn't supported by this kLdr build. */
971#define KLDR_ERR_PE_NOT_SUPPORTED (KLDR_ERR_BASE + 5)
972/** The ELF image format isn't supported by this kLdr build. */
973#define KLDR_ERR_ELF_NOT_SUPPORTED (KLDR_ERR_BASE + 6)
974/** The mach-o image format isn't supported by this kLdr build. */
975#define KLDR_ERR_MACHO_NOT_SUPPORTED (KLDR_ERR_BASE + 7)
976/** The mach-o image format isn't supported by this kLdr build. */
977#define KLDR_ERR_AOUT_NOT_SUPPORTED (KLDR_ERR_BASE + 8)
978
[2833]979/** Invalid parameter to a kLdr API. */
[2842]980#define KLDR_ERR_INVALID_PARAMETER (KLDR_ERR_BASE + 32)
[2833]981/** Invalid handle parameter to a kLdr API. */
[2842]982#define KLDR_ERR_INVALID_HANDLE (KLDR_ERR_BASE + 33)
983/** The module wasn't loaded dynamically. */
984#define KLDR_ERR_NOT_LOADED_DYNAMICALLY (KLDR_ERR_BASE + 34)
[2836]985/** The module wasn't found. */
[2842]986#define KLDR_ERR_MODULE_NOT_FOUND (KLDR_ERR_BASE + 35)
[2837]987/** A prerequisit module wasn't found. */
[2842]988#define KLDR_ERR_PREREQUISITE_MODULE_NOT_FOUND (KLDR_ERR_BASE + 36)
[2837]989/** The module is being terminated and can therefore not be loaded. */
[2842]990#define KLDR_ERR_MODULE_TERMINATING (KLDR_ERR_BASE + 37)
[2837]991/** A prerequisit module is being terminated and can therefore not be loaded. */
[2842]992#define KLDR_ERR_PREREQUISITE_MODULE_TERMINATING (KLDR_ERR_BASE + 38)
993/** The module initialization failed. */
994#define KLDR_ERR_MODULE_INIT_FAILED (KLDR_ERR_BASE + 39)
995/** The initialization of a prerequisite module failed. */
996#define KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED (KLDR_ERR_BASE + 40)
997/** The module has already failed initialization and can't be attempted reloaded until
998 * after we've finished garbage collection. */
999#define KLDR_ERR_MODULE_INIT_FAILED_ALREADY (KLDR_ERR_BASE + 41)
1000/** A prerequisite module has already failed initialization and can't be attempted
1001 * reloaded until after we've finished garbage collection. */
1002#define KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED_ALREADY (KLDR_ERR_BASE + 42)
1003/** Prerequisite recursed too deeply. */
1004#define KLDR_ERR_PREREQUISITE_RECURSED_TOO_DEEPLY (KLDR_ERR_BASE + 43)
[2846]1005/** Failed to allocate the main stack. */
1006#define KLDR_ERR_MAIN_STACK_ALLOC_FAILED (KLDR_ERR_BASE + 44)
1007/** Buffer overflow. */
1008#define KLDR_ERR_BUFFER_OVERFLOW (KLDR_ERR_BASE + 45)
[2848]1009/** The specified ARCH+CPU isn't compatible with image. */
1010#define KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE (KLDR_ERR_BASE + 45)
[2850]1011/** Symbol not found. */
1012#define KLDR_ERR_SYMBOL_NOT_FOUND (KLDR_ERR_BASE + 46)
[2854]1013/** A forward symbol was encountered but the caller didn't provide any means to resolve it. */
1014#define KLDR_ERR_FORWARDER_SYMBOL (KLDR_ERR_BASE + 47)
[2833]1015/** Encountered a bad fixup. */
[2842]1016#define KLDR_ERR_BAD_FIXUP (KLDR_ERR_BASE + 48)
1017/** A memory allocation failed. */
[2854]1018#define KLDR_ERR_NO_MEMORY (KLDR_ERR_BASE + 49)
[2855]1019/** The import ordinal was out of bounds. */
1020#define KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS (KLDR_ERR_BASE + 50)
1021/** A forwarder chain was too long. */
1022#define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN (KLDR_ERR_BASE + 51)
[2856]1023/** The module has no debug info. */
1024#define KLDR_ERR_NO_DEBUG_INFO (KLDR_ERR_BASE + 52)
1025/** The module is already mapped.
1026 * kLdrModMap() can only be called once (without kLdrModUnmap() in between). */
1027#define KLDR_ERR_ALREADY_MAPPED (KLDR_ERR_BASE + 53)
1028/** The module was not mapped.
1029 * kLdrModUnmap() should not called without being preceeded by a kLdrModMap(). */
1030#define KLDR_ERR_NOT_MAPPED (KLDR_ERR_BASE + 54)
[2857]1031/** Couldn't fit the address value into the field. Typically a relocation kind of error. */
1032#define KLDR_ERR_ADDRESS_OVERFLOW (KLDR_ERR_BASE + 55)
1033/** Thread attach failed. */
1034#define KLDR_ERR_THREAD_ATTACH_FAILED (KLDR_ERR_BASE + 57)
[2861]1035/** The file reader can't take more concurrent mappings. */
1036#define KLDR_ERR_TOO_MANY_MAPPINGS (KLDR_ERR_BASE + 58)
[2870]1037/** The module wasn't a DLL or object file. */
1038#define KLDR_ERR_NOT_DLL (KLDR_ERR_BASE + 59)
1039/** The module wasn't an EXE. */
1040#define KLDR_ERR_NOT_EXE (KLDR_ERR_BASE + 60)
[2842]1041
[2857]1042
[2854]1043/** @name kLdrModPE status codes
1044 * @{ */
[2879]1045#define KLDR_ERR_PE_BASE (KLDR_ERR_BASE + 61)
[2854]1046/** The machine isn't supported by the interpreter. */
[2879]1047#define KLDR_ERR_PE_UNSUPPORTED_MACHINE (KLDR_ERR_PE_BASE + 0)
[2854]1048/** The file handler isn't valid. */
[2879]1049#define KLDR_ERR_PE_BAD_FILE_HEADER (KLDR_ERR_PE_BASE + 1)
[2854]1050/** The the optional headers isn't valid. */
[2879]1051#define KLDR_ERR_PE_BAD_OPTIONAL_HEADER (KLDR_ERR_PE_BASE + 2)
[2854]1052/** One of the section headers aren't valid. */
[2879]1053#define KLDR_ERR_PE_BAD_SECTION_HEADER (KLDR_ERR_PE_BASE + 3)
[2854]1054/** Bad forwarder entry. */
[2879]1055#define KLDR_ERR_PE_BAD_FORWARDER (KLDR_ERR_PE_BASE + 4)
[2854]1056/** Forwarder module not found in the import descriptor table. */
[2879]1057#define KLDR_ERR_PE_FORWARDER_IMPORT_NOT_FOUND (KLDR_ERR_PE_BASE + 5)
[2857]1058/** Bad PE fixups. */
[2879]1059#define KLDR_ERR_PE_BAD_FIXUP (KLDR_ERR_PE_BASE + 6)
[2857]1060/** Bad PE import (thunk). */
[2879]1061#define KLDR_ERR_PE_BAD_IMPORT (KLDR_ERR_PE_BASE + 7)
[2827]1062/** @} */
1063
[2879]1064/** @name kLdrModLX status codes
1065 * @{ */
1066#define KLDR_ERR_LX_BASE (KLDR_ERR_PE_BASE + 8)
1067/** validation of LX header failed. */
1068#define KLDR_ERR_LX_BAD_HEADER (KLDR_ERR_LX_BASE + 0)
1069/** validation of the loader section (in the LX header) failed. */
1070#define KLDR_ERR_LX_BAD_LOADER_SECTION (KLDR_ERR_LX_BASE + 1)
1071/** validation of the fixup section (in the LX header) failed. */
1072#define KLDR_ERR_LX_BAD_FIXUP_SECTION (KLDR_ERR_LX_BASE + 2)
1073/** validation of the LX object table failed. */
1074#define KLDR_ERR_LX_BAD_OBJECT_TABLE (KLDR_ERR_LX_BASE + 3)
1075/** @} */
1076
[2868]1077/** End of the valid kLdr status codes. */
[2879]1078#define KLDR_ERR_END (KLDR_ERR_LX_BASE + 4)
[2827]1079
[2854]1080/** @} */
1081
1082
[2821]1083#ifdef __cplusplus
1084}
1085#endif
1086
1087#endif
1088
Note: See TracBrowser for help on using the repository browser.