source: trunk/kLdr/kLdr.h@ 2875

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

Got the stub loader working (but without stack allocation/switching).

  • Property svn:keywords set to Id
File size: 42.3 KB
Line 
1/* $Id: kLdr.h 2875 2006-11-12 08:59:45Z 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/** @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
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
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
89
90/** Pointer to a loader segment. */
91typedef struct KLDRSEG *PKLDRSEG;
92/** Pointer to a loader segment. */
93typedef const struct KLDRSEG *PCKLDRSEG;
94
95
96
97
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 */
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. */
120 KLDRPROT_EXECUTE_READ,
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
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
137/**
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);
161 /** @copydoc kLdrRdrRead */
162 int (* pfnRead)( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
163 /** @copydoc kLdrRdrAllMap */
164 int (* pfnAllMap)( PKLDRRDR pRdr, const void **ppvBits);
165 /** @copydoc kLdrRdrAllUnmap */
166 int (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits);
167 /** @copydoc kLdrRdrSize */
168 off_t (* pfnSize)( PKLDRRDR pRdr);
169 /** @copydoc kLdrRdrTell */
170 off_t (* pfnTell)( PKLDRRDR pRdr);
171 /** @copydoc kLdrRdrName */
172 const char * (* pfnName)(PKLDRRDR pRdr);
173 /** @copydoc kLdrRdrPageSize */
174 size_t (* pfnPageSize)(PKLDRRDR pRdr);
175 /** @copydoc kLdrRdrMap */
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);
179 /** @copydoc kLdrRdrProtect */
180 int (* pfnProtect)( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
181 /** @copydoc kLdrRdrUnmap */
182 int (* pfnUnmap)( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
183 /** @copydoc kLdrRdrDone */
184 void (* pfnDone)( PKLDRRDR pRdr);
185 /** The usual non-zero dummy that makes sure we've initialized all members. */
186 uint32_t u32Dummy;
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{
199 /** Magic number (KLDRRDR_MAGIC). */
200 uint32_t u32Magic;
201 /** Pointer to the file provider operations. */
202 PCKLDRRDROPS pOps;
203} KLDRRDR;
204
205/** The magic for KLDRRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */
206#define KLDRRDR_MAGIC 0x19610919
207
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);
218size_t kLdrRdrPageSize(PKLDRRDR pRdr);
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);
223void kLdrRdrDone( PKLDRRDR pRdr);
224
225/** @} */
226
227
228
229/** @defgroup grp_kLdrMod kLdrMod - The executable image intepreter
230 * @{ */
231
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;
275
276/**
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/**
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,
349 /** Unknown debug info format. */
350 KLDRDBGINFOTYPE_UNKNOWN,
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/**
371 * Stack information.
372 */
373typedef struct KLDRSTACKINFO
374{
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;
378 /** The base address of the stack (sub) segment, link address.
379 * Set this to NIL_KLDRADDR if the module doesn't include any stack (sub)segment. */
380 KLDRADDR LinkAddress;
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. */
384 KLDRSIZE cbStack;
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. */
387 KLDRSIZE cbStackThread;
388} KLDRSTACKINFO;
389/** Pointer to stack information. */
390typedef KLDRSTACKINFO *PKLDRSTACKINFO;
391/** Pointer to const stack information. */
392typedef const KLDRSTACKINFO *PCKLDRSTACKINFO;
393
394
395/**
396 * Loader segment.
397 */
398typedef struct KLDRSEG
399{
400 /** Variable free to use for the kLdr user. */
401 void *pvUser;
402 /** The segment name. (Might not be zero terminated!) */
403 const char *pchName;
404 /** The length of the segment name. */
405 uint32_t cchName;
406 /** The segment protection. */
407 KLDRPROT enmProt;
408 /** The size of the segment. */
409 KLDRSIZE cb;
410 /** The required segment alignment.
411 * The to 0 if the segment isn't supposed to be mapped. */
412 KLDRADDR Alignment;
413 /** The link address.
414 * Set to NIL_KLDRADDR if the segment isn't supposed to be
415 * mapped or if the image doesn't have link addresses. */
416 KLDRADDR LinkAddress;
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;
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;
428 /** The address the segment was mapped at by kLdrModMap().
429 * Set to 0 if not mapped. */
430 uintptr_t MapAddress;
431} KLDRSEG;
432
433
434/**
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/**
461 * Loader module type.
462 */
463typedef enum KLDRTYPE
464{
465 /** The usual invalid 0 type. */
466 KLDRTYPE_INVALID = 0,
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). */
487 KLDRTYPE_END,
488 /** Hack to blow the type up to 32-bit. */
489 KLDRTYPE_32BIT_HACK = 0x7fffffff
490} KLDRTYPE;
491
492
493/**
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
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
518/**
519 * Module interpreter instance.
520 * All members are read only unless you're kLdrMod or the module interpreter.
521 */
522typedef struct KLDRMOD
523{
524 /** Magic number (KLDRMOD_MAGIC). */
525 uint32_t u32Magic;
526 /** The format of this module. */
527 KLDRFMT enmFmt;
528 /** The type of module. */
529 KLDRTYPE enmType;
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;
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;
547 /** Pointer to the loader methods.
548 * Not meant for calling directly thru! */
549 PCKLDRMODOPS pOps;
550 /** Pointer to the read instance. (Can be NULL after kLdrModDone().)*/
551 PKLDRRDR pRdr;
552 /** The module data. */
553 void *pvData;
554 /** Segments. (variable size, can be zero) */
555 KLDRSEG aSegments[1];
556} KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
557
558/** The magic for KLDRMOD::u32Magic. (Kosuke Fujishima) */
559#define KLDRMOD_MAGIC 0x19640707
560
561
562/** Special base address value alias for the link address. */
563#define KLDRMOD_BASEADDRESS_LINK (~(KLDRADDR)1)
564/** Special base address value alias for the actual load address (must be mapped). */
565#define KLDRMOD_BASEADDRESS_MAP (~(KLDRADDR)2)
566
567/** Special import module ordinal value used to indicate that there is no
568 * specific module associated with the requested symbol. */
569#define NIL_KLDRMOD_IMPORT (~(uint32_t)0)
570
571/** Special symbol ordinal value used to indicate that the symbol
572 * only has a string name. */
573#define NIL_KLDRMOD_SYM_ORDINAL (~(uint32_t)0)
574
575
576/** @name Load symbol kind flags.
577 * @{ */
578/** The bitness doesn't matter. */
579#define KLDRSYMKIND_NO_BIT 0x00000000
580/** 16-bit symbol. */
581#define KLDRSYMKIND_16BIT 0x00000001
582/** 32-bit symbol. */
583#define KLDRSYMKIND_32BIT 0x00000002
584/** 64-bit symbol. */
585#define KLDRSYMKIND_64BIT 0x00000003
586/** Mask out the bit.*/
587#define KLDRSYMKIND_BIT_MASK 0x00000003
588/** We don't know the type of symbol. */
589#define KLDRSYMKIND_NO_TYPE 0x00000000
590/** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
591#define KLDRSYMKIND_CODE 0x00000010
592/** The symbol is a data object. */
593#define KLDRSYMKIND_DATA 0x00000020
594/** Mask out the symbol type. */
595#define KLDRSYMKIND_TYPE_MASK 0x00000030
596/** Valid symbol kind mask. */
597#define KLDRSYMKIND_MASK 0x00000033
598/** Weak symbol. */
599#define KLDRSYMKIND_WEAK 0x00000100
600/** Forwarder symbol. */
601#define KLDRSYMKIND_FORWARDER 0x00000200
602/** @} */
603
604/** @name kLdrModEnumSymbols flags.
605 * @{ */
606/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
607#define KLDRMOD_ENUM_SYMS_FLAGS_ALL 0x00000001
608/** @} */
609
610
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.
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.
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 */
625typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pszSymbol,
626 PKLDRADDR puValue, uint32_t *pfKind, void *pvUser);
627/** Pointer to a import callback. */
628typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
629
630/**
631 * Symbol enumerator callback.
632 *
633 * @returns 0 if enumeration should continue.
634 * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumSymbols().
635 *
636 * @param pMod The module which symbols are being enumerated.s
637 * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
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 */
645typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, uint32_t iSymbol, const char *pszSymbol,
646 KLDRADDR uValue, uint32_t fKind, void *pvUser);
647/** Pointer to a symbol enumerator callback. */
648typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
649
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.
657 * @param iDbgInfo The debug info ordinal number / id.
658 * @param enmType The debug info type.
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.
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.
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.
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 */
669typedef int FNKLDRENUMDBG(PKLDRMOD pMod, uint32_t iDbgInfo, KLDRDBGINFOTYPE enmType, int16_t iMajorVer, int16_t iMinorVer,
670 off_t offFile, KLDRADDR LinkAddress, KLDRSIZE cb, const char *pszExtFile, void *pvUser);
671/** Pointer to a debug info enumberator callback. */
672typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;
673
674int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod);
675int kLdrModOpenFromRdr(PKLDRRDR pRdr, PPKLDRMOD ppMod);
676int kLdrModOpenNative(const char *pszFilename, PPKLDRMOD ppMod);
677int kLdrModClose(PKLDRMOD pMod);
678
679int kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t iSymbol,
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);
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);
691
692/** @name Operations On The Internally Managed Mapping
693 * @{ */
694int kLdrModMap(PKLDRMOD pMod);
695int kLdrModUnmap(PKLDRMOD pMod);
696int kLdrModAllocTLS(PKLDRMOD pMod);
697void kLdrModFreeTLS(PKLDRMOD pMod);
698int kLdrModReload(PKLDRMOD pMod);
699int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
700int kLdrModCallInit(PKLDRMOD pMod, uintptr_t uHandle);
701int kLdrModCallTerm(PKLDRMOD pMod, uintptr_t uHandle);
702int kLdrModCallThread(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching);
703/** @} */
704
705/** @name Operations On The Externally Managed Mappings
706 * @{ */
707KLDRADDR kLdrModSize(PKLDRMOD pMod);
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);
711/** @} */
712
713
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 */
748 int (* pfnQuerySymbol)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t iSymbol,
749 const char *pszSymbol, PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser,
750 PKLDRADDR puValue, uint32_t *pfKind);
751 /** @copydoc kLdrModEnumSymbols */
752 int (* pfnEnumSymbols)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t fFlags,
753 PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
754 /** @copydoc kLdrModGetImport */
755 int (* pfnGetImport)(PKLDRMOD pMod, const void *pvBits, uint32_t iImport, char *pszName, size_t cchName);
756 /** @copydoc kLdrModNumberOfImports */
757 int32_t (* pfnNumberOfImports)(PKLDRMOD pMod, const void *pvBits);
758 /** @copydoc kLdrModCanExecuteOn */
759 int (* pfnCanExecuteOn)(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
760 /** @copydoc kLdrModGetStackInfo */
761 int (* pfnGetStackInfo)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
762 /** @copydoc kLdrModQueryMainEntrypoint */
763 int (* pfnQueryMainEntrypoint)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
764 /** @copydoc kLdrModEnumDbgInfo */
765 int (* pfnEnumDbgInfo)(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
766 /** @copydoc kLdrModHasDbgInfo */
767 int (* pfnHasDbgInfo)(PKLDRMOD pMod, const void *pvBits);
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 */
781 int (* pfnCallInit)(PKLDRMOD pMod, uintptr_t uHandle);
782 /** @copydoc kLdrModCallTerm */
783 int (* pfnCallTerm)(PKLDRMOD pMod, uintptr_t uHandle);
784 /** @copydoc kLdrModCallThread */
785 int (* pfnCallThread)(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching);
786 /** @copydoc kLdrModSize */
787 KLDRADDR (* pfnSize)(PKLDRMOD pMod);
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
798/** @} */
799
800
801
802
803/** @defgroup grp_kLdrDyld kLdrDyld - The dynamic loader
804 * @{ */
805
806/** The handle to a dynamic loader module. */
807typedef struct KLDRDYLDMOD *HKLDRMOD;
808/** Pointer to the handle to a dynamic loader module. */
809typedef HKLDRMOD *PHKLDRMOD;
810/** NIL handle value. */
811#define NIL_HKLDRMOD ((HKLDRMOD)0)
812
813
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,
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
843} KLDRDYLDSEARCH;
844
845/** @name kLdrDyldLoad and kLdrDyldFindByName flags.
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 symbols in the module should be loaded into the global unix namespace and
851 * it's symbols should take precedence over all currently loaded modules.
852 * This implies KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS. */
853#define KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS 0x00000002
854/** The module shouldn't be found by a global module search.
855 * If not specified, the module can be found by unspecified module searches,
856 * typical used when loading import/dep modules. */
857#define KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE 0x00000004
858/** Do a recursive initialization calls instead of defering them to the outermost call. */
859#define KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT 0x00000008
860/** We're loading the executable module.
861 * @internal */
862#define KLDRDYLD_LOAD_FLAGS_EXECUTABLE 0x40000000
863/** @} */
864
865
866int kLdrDyldLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
867 unsigned fFlags, PHKLDRMOD phMod, char *pszErr, size_t cchErr);
868int kLdrDyldUnload(HKLDRMOD hMod);
869int kLdrDyldFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
870 unsigned fFlags, PHKLDRMOD phMod);
871int kLdrDyldFindByAddress(uintptr_t Address, PHKLDRMOD phMod, uint32_t *piSegment, uintptr_t *poffSegment);
872int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, size_t cchName);
873int kLdrDyldGetFilename(HKLDRMOD hMod, char *pszFilename, size_t cchFilename);
874int kLdrDyldQuerySymbol(HKLDRMOD hMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind);
875
876/** @name OS/2 like API
877 * @{ */
878int kLdrDosLoadModule(char *pszObject, size_t cbObject, const char *pszModule, PHKLDRMOD phMod);
879int kLdrDosFreeModule(HKLDRMOD hMod);
880int kLdrDosQueryModuleHandle(const char *pszModname, PHKLDRMOD phMod);
881int kLdrDosQueryModuleName(HKLDRMOD hMod, size_t cchName, char *pszName);
882int kLdrDosQueryProcAddr(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, void **ppvProcAddr);
883int kLdrDosQueryProcType(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, uint32_t *pfProcType);
884int kLdrDosQueryModFromEIP(PHKLDRMOD phMod, uint32_t *piObject, size_t cbName, char *pszName, uintptr_t *poffObject, uintptr_t ulEIP);
885int kLdrDosReplaceModule(const char *pszOldModule, const char *pszNewModule, const char *pszBackupModule);
886int kLdrDosGetResource(HKLDRMOD hMod, uint32_t idType, uint32_t idName, void **pvResAddr);
887int kLdrDosQueryResourceSize(HKLDRMOD hMod, uint32_t idTypeID, uint32_t idName, uint32_t *pcb);
888int kLdrDosFreeResource(void *pvResAddr);
889/** @} */
890
891/** @name POSIX like API
892 * @{ */
893HKLDRMOD kLdrDlOpen(const char *pszLibrary, int fFlags);
894const char *kLdrDlError(void);
895void * kLdrDlSym(HKLDRMOD hMod, const char *pszSymbol);
896int kLdrDlClose(HKLDRMOD hMod);
897/** @} */
898
899/** @name Win32 like API
900 * @{ */
901HKLDRMOD kLdrWLoadLibrary(const char *pszFilename);
902HKLDRMOD kLdrWLoadLibraryEx(const char *pszFilename, void *hFileReserved, uint32_t fFlags);
903uint32_t kLdrWGetModuleFileName(HKLDRMOD hMod, char *pszModName, size_t cchModName);
904HKLDRMOD kLdrWGetModuleHandle(const char *pszFilename);
905int kLdrWGetModuleHandleEx(uint32_t fFlags, const char *pszFilename, HKLDRMOD hMod);
906void * kLdrWGetProcAddress(HKLDRMOD hMod, const char *pszProcName);
907uint32_t kLdrWGetDllDirectory(size_t cchDir, char *pszDir);
908int kLdrWSetDllDirectory(const char *pszDir);
909int kLdrWFreeLibrary(HKLDRMOD hMod);
910int kLdrWDisableThreadLibraryCalls(HKLDRMOD hMod);
911
912/** @} */
913
914
915/** @name Process Bootstrapping
916 * @{ */
917
918/**
919 * Argument package from the stub.
920 */
921typedef struct KLDREXEARGS
922{
923 /** Load & search flags, some which will become defaults. */
924 uint32_t fFlags;
925 /** The default search method. */
926 KLDRDYLDSEARCH enmSearch;
927 /** The executable file that the stub is supposed to load. */
928 char szExecutable[260];
929 /** The default prefix used when searching for DLLs. */
930 char szDefPrefix[16];
931 /** The default suffix used when searching for DLLs. */
932 char szDefSuffix[16];
933 /** The LD_LIBRARY_PATH prefix for the process.. */
934 char szLibPath[4096 - sizeof(uint32_t) - sizeof(KLDRDYLDSEARCH) - 16 - 16 - 260];
935} KLDREXEARGS, *PKLDREXEARGS;
936/** Pointer to a const argument package from the stub. */
937typedef const KLDREXEARGS *PCKLDREXEARGS;
938
939void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS);
940
941/** @} */
942
943/** @} */
944
945
946/** @defgroup grp_kLdrErr kLdr Status Codes
947 * kLdr uses a mix of native status codes and it's own status codes.
948 * A status code of 0 means success, all other status codes means failure.
949 * @{
950 */
951#ifdef __OS2__
952# define KLDR_ERR_BASE 420000
953#elif defined(__WIN__)
954# define KLDR_ERR_BASE 420000
955#else
956# error "port me"
957#endif
958/** The image format is unknown. */
959#define KLDR_ERR_UNKNOWN_FORMAT (KLDR_ERR_BASE + 0)
960/** The MZ image format isn't supported by this kLdr build. */
961#define KLDR_ERR_MZ_NOT_SUPPORTED (KLDR_ERR_BASE + 1)
962/** The NE image format isn't supported by this kLdr build. */
963#define KLDR_ERR_NE_NOT_SUPPORTED (KLDR_ERR_BASE + 2)
964/** The LX image format isn't supported by this kLdr build. */
965#define KLDR_ERR_LX_NOT_SUPPORTED (KLDR_ERR_BASE + 3)
966/** The LE image format isn't supported by this kLdr build. */
967#define KLDR_ERR_LE_NOT_SUPPORTED (KLDR_ERR_BASE + 4)
968/** The PE image format isn't supported by this kLdr build. */
969#define KLDR_ERR_PE_NOT_SUPPORTED (KLDR_ERR_BASE + 5)
970/** The ELF image format isn't supported by this kLdr build. */
971#define KLDR_ERR_ELF_NOT_SUPPORTED (KLDR_ERR_BASE + 6)
972/** The mach-o image format isn't supported by this kLdr build. */
973#define KLDR_ERR_MACHO_NOT_SUPPORTED (KLDR_ERR_BASE + 7)
974/** The mach-o image format isn't supported by this kLdr build. */
975#define KLDR_ERR_AOUT_NOT_SUPPORTED (KLDR_ERR_BASE + 8)
976
977/** Invalid parameter to a kLdr API. */
978#define KLDR_ERR_INVALID_PARAMETER (KLDR_ERR_BASE + 32)
979/** Invalid handle parameter to a kLdr API. */
980#define KLDR_ERR_INVALID_HANDLE (KLDR_ERR_BASE + 33)
981/** The module wasn't loaded dynamically. */
982#define KLDR_ERR_NOT_LOADED_DYNAMICALLY (KLDR_ERR_BASE + 34)
983/** The module wasn't found. */
984#define KLDR_ERR_MODULE_NOT_FOUND (KLDR_ERR_BASE + 35)
985/** A prerequisit module wasn't found. */
986#define KLDR_ERR_PREREQUISITE_MODULE_NOT_FOUND (KLDR_ERR_BASE + 36)
987/** The module is being terminated and can therefore not be loaded. */
988#define KLDR_ERR_MODULE_TERMINATING (KLDR_ERR_BASE + 37)
989/** A prerequisit module is being terminated and can therefore not be loaded. */
990#define KLDR_ERR_PREREQUISITE_MODULE_TERMINATING (KLDR_ERR_BASE + 38)
991/** The module initialization failed. */
992#define KLDR_ERR_MODULE_INIT_FAILED (KLDR_ERR_BASE + 39)
993/** The initialization of a prerequisite module failed. */
994#define KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED (KLDR_ERR_BASE + 40)
995/** The module has already failed initialization and can't be attempted reloaded until
996 * after we've finished garbage collection. */
997#define KLDR_ERR_MODULE_INIT_FAILED_ALREADY (KLDR_ERR_BASE + 41)
998/** A prerequisite module has already failed initialization and can't be attempted
999 * reloaded until after we've finished garbage collection. */
1000#define KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED_ALREADY (KLDR_ERR_BASE + 42)
1001/** Prerequisite recursed too deeply. */
1002#define KLDR_ERR_PREREQUISITE_RECURSED_TOO_DEEPLY (KLDR_ERR_BASE + 43)
1003/** Failed to allocate the main stack. */
1004#define KLDR_ERR_MAIN_STACK_ALLOC_FAILED (KLDR_ERR_BASE + 44)
1005/** Buffer overflow. */
1006#define KLDR_ERR_BUFFER_OVERFLOW (KLDR_ERR_BASE + 45)
1007/** The specified ARCH+CPU isn't compatible with image. */
1008#define KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE (KLDR_ERR_BASE + 45)
1009/** Symbol not found. */
1010#define KLDR_ERR_SYMBOL_NOT_FOUND (KLDR_ERR_BASE + 46)
1011/** A forward symbol was encountered but the caller didn't provide any means to resolve it. */
1012#define KLDR_ERR_FORWARDER_SYMBOL (KLDR_ERR_BASE + 47)
1013/** Encountered a bad fixup. */
1014#define KLDR_ERR_BAD_FIXUP (KLDR_ERR_BASE + 48)
1015/** A memory allocation failed. */
1016#define KLDR_ERR_NO_MEMORY (KLDR_ERR_BASE + 49)
1017/** The import ordinal was out of bounds. */
1018#define KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS (KLDR_ERR_BASE + 50)
1019/** A forwarder chain was too long. */
1020#define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN (KLDR_ERR_BASE + 51)
1021/** The module has no debug info. */
1022#define KLDR_ERR_NO_DEBUG_INFO (KLDR_ERR_BASE + 52)
1023/** The module is already mapped.
1024 * kLdrModMap() can only be called once (without kLdrModUnmap() in between). */
1025#define KLDR_ERR_ALREADY_MAPPED (KLDR_ERR_BASE + 53)
1026/** The module was not mapped.
1027 * kLdrModUnmap() should not called without being preceeded by a kLdrModMap(). */
1028#define KLDR_ERR_NOT_MAPPED (KLDR_ERR_BASE + 54)
1029/** Couldn't fit the address value into the field. Typically a relocation kind of error. */
1030#define KLDR_ERR_ADDRESS_OVERFLOW (KLDR_ERR_BASE + 55)
1031/** Thread attach failed. */
1032#define KLDR_ERR_THREAD_ATTACH_FAILED (KLDR_ERR_BASE + 57)
1033/** The file reader can't take more concurrent mappings. */
1034#define KLDR_ERR_TOO_MANY_MAPPINGS (KLDR_ERR_BASE + 58)
1035/** The module wasn't a DLL or object file. */
1036#define KLDR_ERR_NOT_DLL (KLDR_ERR_BASE + 59)
1037/** The module wasn't an EXE. */
1038#define KLDR_ERR_NOT_EXE (KLDR_ERR_BASE + 60)
1039
1040
1041/** @name kLdrModPE status codes
1042 * @{ */
1043#define KLDR_ERR_BASE_PE (KLDR_ERR_BASE + 61)
1044/** The machine isn't supported by the interpreter. */
1045#define KLDR_ERR_PE_UNSUPPORTED_MACHINE (KLDR_ERR_BASE_PE + 0)
1046/** The file handler isn't valid. */
1047#define KLDR_ERR_PE_BAD_FILE_HEADER (KLDR_ERR_BASE_PE + 1)
1048/** The the optional headers isn't valid. */
1049#define KLDR_ERR_PE_BAD_OPTIONAL_HEADER (KLDR_ERR_BASE_PE + 2)
1050/** One of the section headers aren't valid. */
1051#define KLDR_ERR_PE_BAD_SECTION_HEADER (KLDR_ERR_BASE_PE + 3)
1052/** Bad forwarder entry. */
1053#define KLDR_ERR_PE_BAD_FORWARDER (KLDR_ERR_BASE_PE + 4)
1054/** Forwarder module not found in the import descriptor table. */
1055#define KLDR_ERR_PE_FORWARDER_IMPORT_NOT_FOUND (KLDR_ERR_BASE_PE + 5)
1056/** Bad PE fixups. */
1057#define KLDR_ERR_PE_BAD_FIXUP (KLDR_ERR_BASE_PE + 6)
1058/** Bad PE import (thunk). */
1059#define KLDR_ERR_PE_BAD_IMPORT (KLDR_ERR_BASE_PE + 7)
1060/** @} */
1061
1062/** End of the valid kLdr status codes. */
1063#define KLDR_ERR_END (KLDR_ERR_BASE_PE + 8)
1064
1065/** @} */
1066
1067
1068#ifdef __cplusplus
1069}
1070#endif
1071
1072#endif
1073
Note: See TracBrowser for help on using the repository browser.