source: trunk/kLdr/kLdr.h@ 2857

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

Only the mapping left now.

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