source: trunk/kLdr/kLdr.h@ 2868

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

Did the remaining search bit (I hope).

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