source: trunk/kStuff/include/k/kLdr.h@ 3578

Last change on this file since 3578 was 3578, checked in by bird, 18 years ago

kLdrRdr cleanup.

  • Property svn:keywords set to Id
File size: 52.1 KB
Line 
1/* $Id: kLdr.h 3578 2007-09-02 20:55:51Z 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 ___k_kLdr_h___
28#define ___k_kLdr_h___
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/*
35 * Include the base typedefs and macros.
36 */
37#include <k/kDefs.h>
38#include <k/kTypes.h>
39
40
41/** @defgroup grp_kLdrBasic kLdr Basic Types
42 * @{ */
43
44/** The kLdr address type. */
45typedef KU64 KLDRADDR;
46/** Pointer to a kLdr address. */
47typedef KLDRADDR *PKLDRADDR;
48/** Pointer to a const kLdr address. */
49typedef const KLDRADDR *PCKLDRADDR;
50
51/** NIL address. */
52#define NIL_KLDRADDR (~(KU64)0)
53
54/** @def PRI_KLDRADDR
55 * printf format type. */
56#ifdef _MSC_VER
57# define PRI_KLDRADDR "I64x"
58#else
59# define PRI_KLDRADDR "llx"
60#endif
61
62/** Align a KSIZE value. */
63#define KLDR_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KLDRADDR)((align) - 1) )
64
65
66/** The kLdr size type. */
67typedef KU64 KLDRSIZE;
68/** Pointer to a kLdr size. */
69typedef KLDRSIZE *PKLDRSIZE;
70/** Pointer to a const kLdr size. */
71typedef const KLDRSIZE *PCKLDRSIZE;
72
73/** @def PRI_KLDRSIZE
74 * printf format type. */
75#ifdef _MSC_VER
76# define PRI_KLDRSIZE "I64x"
77#else
78# define PRI_KLDRSIZE "llx"
79#endif
80
81
82/** The kLdr file offset type. */
83typedef long KLDRFOFF;
84/** Pointer to a kLdr file offset type. */
85typedef KLDRFOFF *PKLDRFOFF;
86/** Pointer to a const kLdr file offset type. */
87typedef const KLDRFOFF *PCKLDRFOFF;
88
89/** @def PRI_KLDRFOFF
90 * printf format type. */
91#define PRI_KLDRFOFF "lx"
92
93
94/**
95 * Union of all the integer types.
96 */
97typedef union KLDRU
98{
99 KI8 i8; /**< KI8 view. */
100 KU8 u8; /**< KU8 view. */
101 KI16 i16; /**< KI16 view. */
102 KU16 u16; /**< KU16 view. */
103 KI32 i32; /**< KI32 view. */
104 KU32 u32; /**< KU32 view. */
105 KI64 i64; /**< KI64 view. */
106 KU64 u64; /**< KU64 view. */
107
108 KI8 ai8[8]; /**< KI8 array view . */
109 KU8 au8[8]; /**< KU8 array view. */
110 KI16 ai16[4];/**< KI16 array view . */
111 KU16 au16[4];/**< KU16 array view. */
112 KI32 ai32[2];/**< KI32 array view . */
113 KU32 au32[2];/**< KU32 array view. */
114
115 signed char ch; /**< signed char view. */
116 unsigned char uch; /**< unsigned char view. */
117 signed short s; /**< signed short view. */
118 unsigned short us; /**< unsigned short view. */
119 signed int i; /**< signed int view. */
120 unsigned int u; /**< unsigned int view. */
121 signed long l; /**< signed long view. */
122 unsigned long ul; /**< unsigned long view. */
123 void *pv; /**< void pointer view. */
124
125 KLDRADDR Addr; /**< kLdr address view. */
126 KLDRSIZE Size; /**< kLdr size view. */
127} KLDRU;
128/** Pointer to an integer union. */
129typedef KLDRU *PKLDRU;
130/** Pointer to a const integer union. */
131typedef const KLDRU *PCKLDRU;
132
133
134/**
135 * Union of pointers to all the integer types.
136 */
137typedef union KLDRPU
138{
139 KI8 *pi8; /**< KI8 view. */
140 KU8 *pu8; /**< KU8 view. */
141 KI16 *pi16; /**< KI16 view. */
142 KU16 *pu16; /**< KU16 view. */
143 KI32 *pi32; /**< KI32 view. */
144 KU32 *pu32; /**< KU32 view. */
145 KI64 *pi64; /**< KI64 view. */
146 KU64 *pu64; /**< KU64 view. */
147
148 signed char *pch; /**< signed char view. */
149 unsigned char *puch; /**< unsigned char view. */
150 signed short *ps; /**< signed short view. */
151 unsigned short *pus; /**< unsigned short view. */
152 signed int *pi; /**< signed int view. */
153 unsigned int *pu; /**< unsigned int view. */
154 signed long *pl; /**< signed long view. */
155 unsigned long *pul; /**< unsigned long view. */
156 void *pv; /**< void pointer view. */
157} KLDRPU;
158/** Pointer to an integer pointer union. */
159typedef KLDRPU *PKLDRPU;
160/** Pointer to a const integer pointer union. */
161typedef const KLDRPU *PCKLDRPU;
162
163/** @} */
164
165
166/** @defgroup grp_kLdrMod kLdrMod - The executable image intepreter
167 * @{ */
168
169/**
170 * CPU Architecture.
171 * @todo Double check the non intel architectures.
172 */
173typedef enum KLDRARCH
174{
175 /** The usual invalid one. */
176 KLDRARCH_INVALID = 0,
177 /** Clone or Intel 16-bit x86. */
178 KLDRARCH_X86_16,
179 /** Clone or Intel 32-bit x86. */
180 KLDRARCH_X86_32,
181 /** AMD64 (including clones). */
182 KLDRARCH_AMD64,
183 /** Itanic (64-bit). */
184 KLDRARCH_IA64,
185 /** ALPHA (64-bit). */
186 KLDRARCH_ALPHA,
187 /** ALPHA limited to 32-bit. */
188 KLDRARCH_ALPHA_32,
189 /** 32-bit ARM. */
190 KLDRARCH_ARM_32,
191 /** 64-bit ARM. */
192 KLDRARCH_ARM_64,
193 /** 32-bit MIPS. */
194 KLDRARCH_MIPS_32,
195 /** 64-bit MIPS. */
196 KLDRARCH_MIPS_64,
197 /** 32-bit PowerPC. */
198 KLDRARCH_POWERPC_32,
199 /** 64-bit PowerPC. */
200 KLDRARCH_POWERPC_64,
201 /** 32-bit SPARC. */
202 KLDRARCH_SPARC_32,
203 /** 64-bit SPARC. */
204 KLDRARCH_SPARC_64,
205 /** The end of the valid architecture values (exclusive). */
206 KLDRARCH_END,
207 /** Hack to blow the type up to 32-bit. */
208 KLDRARCH_32BIT_HACK = 0x7fffffff
209} KLDRARCH;
210/** Pointer to a CPU architecture type. */
211typedef KLDRARCH *PKLDRARCH;
212
213/**
214 * CPU models.
215 */
216typedef enum KLDRCPU
217{
218 /** The usual invalid cpu. */
219 KLDRCPU_INVALID = 0,
220 /** @name KLDRARCH_X86_16
221 * @{ */
222 KLDRCPU_I8086,
223 KLDRCPU_I8088,
224 KLDRCPU_I80186,
225 KLDRCPU_I80286,
226 KLDRCPU_I386_16,
227 KLDRCPU_I486_16,
228 KLDRCPU_I486SX_16,
229 KLDRCPU_I586_16,
230 KLDRCPU_I686_16,
231 KLDRCPU_P4_16,
232 KLDRCPU_CORE2_16,
233 KLDRCPU_K6_16,
234 KLDRCPU_K7_16,
235 KLDRCPU_K8_16,
236 KLDRCPU_FIRST_X86_16 = KLDRCPU_I8086,
237 KLDRCPU_LAST_X86_16 = KLDRCPU_K8_16,
238 /** @} */
239
240 /** @name KLDRARCH_X86_32
241 * @{ */
242 KLDRCPU_X86_32_BLEND,
243 KLDRCPU_I386,
244 KLDRCPU_I486,
245 KLDRCPU_I486SX,
246 KLDRCPU_I586,
247 KLDRCPU_I686,
248 KLDRCPU_P4,
249 KLDRCPU_CORE2_32,
250 KLDRCPU_K6,
251 KLDRCPU_K7,
252 KLDRCPU_K8_32,
253 KLDRCPU_FIRST_X86_32 = KLDRCPU_I386,
254 KLDRCPU_LAST_X86_32 = KLDRCPU_K8_32,
255 /** @} */
256
257 /** @name KLDRARCH_AMD64
258 * @{ */
259 KLDRCPU_AMD64_BLEND,
260 KLDRCPU_K8,
261 KLDRCPU_P4_64,
262 KLDRCPU_CORE2,
263 KLDRCPU_FIRST_AMD64 = KLDRCPU_K8,
264 KLDRCPU_LAST_AMD64 = KLDRCPU_CORE2,
265 /** @} */
266
267 /** The end of the valid cpu values (exclusive). */
268 KLDRCPU_END,
269 /** Hack to blow the type up to 32-bit. */
270 KLDRCPU_32BIT_HACK = 0x7fffffff
271} KLDRCPU;
272/** Pointer to a CPU type. */
273typedef KLDRCPU *PKLDRCPU;
274
275void kLdrGetArchCpu(PKLDRARCH penmArch, PKLDRCPU penmCpu);
276int kLdrCompareCpus(KLDRARCH enmCodeArch, KLDRCPU enmCodeCpu, KLDRARCH enmArch, KLDRCPU enmCpu);
277
278
279/**
280 * Debug info type (from the loader point of view).
281 */
282typedef enum KLDRDBGINFOTYPE
283{
284 /** The usual invalid enum value. */
285 KLDRDBGINFOTYPE_INVALID = 0,
286 /** Unknown debug info format. */
287 KLDRDBGINFOTYPE_UNKNOWN,
288 /** Stabs. */
289 KLDRDBGINFOTYPE_STABS,
290 /** Debug With Arbitrary Record Format (DWARF). */
291 KLDRDBGINFOTYPE_DWARF,
292 /** Microsoft Codeview debug info. */
293 KLDRDBGINFOTYPE_CODEVIEW,
294 /** Watcom debug info. */
295 KLDRDBGINFOTYPE_WATCOM,
296 /** IBM High Level Language debug info.. */
297 KLDRDBGINFOTYPE_HLL,
298 /** The end of the valid debug info values (exclusive). */
299 KLDRDBGINFOTYPE_END,
300 /** Blow the type up to 32-bit. */
301 KLDRDBGINFOTYPE_32BIT_HACK = 0x7fffffff
302} KLDRDBGINFOTYPE;
303/** Pointer to a kLdr debug info type. */
304typedef KLDRDBGINFOTYPE *PKLDRDBGINFOTYPE;
305
306
307/**
308 * Stack information.
309 */
310typedef struct KLDRSTACKINFO
311{
312 /** The base address of the stack (sub) segment.
313 * Set this to NIL_KLDRADDR if the module doesn't include any stack segment. */
314 KLDRADDR Address;
315 /** The base address of the stack (sub) segment, link address.
316 * Set this to NIL_KLDRADDR if the module doesn't include any stack (sub)segment. */
317 KLDRADDR LinkAddress;
318 /** The stack size of the main thread.
319 * If no stack (sub)segment in the module, this is the stack size of the main thread.
320 * If the module doesn't contain this kind of information this field will be set to 0. */
321 KLDRSIZE cbStack;
322 /** The stack size of non-main threads.
323 * If the module doesn't contain this kind of information this field will be set to 0. */
324 KLDRSIZE cbStackThread;
325} KLDRSTACKINFO;
326/** Pointer to stack information. */
327typedef KLDRSTACKINFO *PKLDRSTACKINFO;
328/** Pointer to const stack information. */
329typedef const KLDRSTACKINFO *PCKLDRSTACKINFO;
330
331
332/**
333 * Loader segment.
334 */
335typedef struct KLDRSEG
336{
337 /** Variable free to use for the kLdr user. */
338 void *pvUser;
339 /** The segment name. (Might not be zero terminated!) */
340 const char *pchName;
341 /** The length of the segment name. */
342 KU32 cchName;
343 /** The flat selector to use for the segment (i.e. data/code).
344 * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
345 KU16 SelFlat;
346 /** The 16-bit selector to use for the segment.
347 * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
348 KU16 Sel16bit;
349 /** Segment flags. */
350 KU32 fFlags;
351 /** The segment protection. */
352 KPROT enmProt;
353 /** The size of the segment. */
354 KLDRSIZE cb;
355 /** The required segment alignment.
356 * The to 0 if the segment isn't supposed to be mapped. */
357 KLDRADDR Alignment;
358 /** The link address.
359 * Set to NIL_KLDRADDR if the segment isn't supposed to be
360 * mapped or if the image doesn't have link addresses. */
361 KLDRADDR LinkAddress;
362 /** File offset of the segment.
363 * Set to -1 if no file backing (like BSS). */
364 KLDRFOFF offFile;
365 /** Size of the file bits of the segment.
366 * Set to -1 if no file backing (like BSS). */
367 KLDRFOFF cbFile;
368 /** The relative virtual address when mapped.
369 * Set to NIL_KLDRADDR if the segment isn't supposed to be mapped. */
370 KLDRADDR RVA;
371 /** The size of the segment including the alignment gap up to the next segment when mapped. */
372 KSIZE cbMapped;
373 /** The address the segment was mapped at by kLdrModMap().
374 * Set to 0 if not mapped. */
375 KUPTR MapAddress;
376} KLDRSEG;
377
378
379/** @name Segment flags
380 * @{ */
381/** The segment is 16-bit. When not set the default of the target architecture is assumed. */
382#define KLDRSEG_FLAG_16BIT 1
383/** The segment requires a 16-bit selector alias. (OS/2) */
384#define KLDRSEG_FLAG_OS2_ALIAS16 2
385/** Conforming segment (x86 weirdness). (OS/2) */
386#define KLDRSEG_FLAG_OS2_CONFORM 4
387/** IOPL (ring-2) segment. (OS/2) */
388#define KLDRSEG_FLAG_OS2_IOPL 8
389/** @} */
390
391
392/**
393 * Loader module format.
394 */
395typedef enum KLDRFMT
396{
397 /** The usual invalid 0 format. */
398 KLDRFMT_INVALID = 0,
399 /** The native OS loader. */
400 KLDRFMT_NATIVE,
401 /** The AOUT loader. */
402 KLDRFMT_AOUT,
403 /** The ELF loader. */
404 KLDRFMT_ELF,
405 /** The LX loader. */
406 KLDRFMT_LX,
407 /** The Mach-O loader. */
408 KLDRFMT_MACHO,
409 /** The PE loader. */
410 KLDRFMT_PE,
411 /** The end of the valid format values (exclusive). */
412 KLDRFMT_END,
413 /** Hack to blow the type up to 32-bit. */
414 KLDRFMT_32BIT_HACK = 0x7fffffff
415} KLDRFMT;
416
417
418/**
419 * Loader module type.
420 */
421typedef enum KLDRTYPE
422{
423 /** The usual invalid 0 type. */
424 KLDRTYPE_INVALID = 0,
425 /** Object file. */
426 KLDRTYPE_OBJECT,
427 /** Executable module, fixed load address. */
428 KLDRTYPE_EXECUTABLE_FIXED,
429 /** Executable module, relocatable, non-fixed load address. */
430 KLDRTYPE_EXECUTABLE_RELOCATABLE,
431 /** Executable module, position independent code, non-fixed load address. */
432 KLDRTYPE_EXECUTABLE_PIC,
433 /** Shared library, fixed load address.
434 * Typically a system library. */
435 KLDRTYPE_SHARED_LIBRARY_FIXED,
436 /** Shared library, relocatable, non-fixed load address. */
437 KLDRTYPE_SHARED_LIBRARY_RELOCATABLE,
438 /** Shared library, position independent code, non-fixed load address. */
439 KLDRTYPE_SHARED_LIBRARY_PIC,
440 /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */
441 KLDRTYPE_FORWARDER_DLL,
442 /** Core or dump. */
443 KLDRTYPE_CORE,
444 /** The end of the valid types values (exclusive). */
445 KLDRTYPE_END,
446 /** Hack to blow the type up to 32-bit. */
447 KLDRTYPE_32BIT_HACK = 0x7fffffff
448} KLDRTYPE;
449
450
451/**
452 * Loader endian indicator.
453 */
454typedef enum KLDRENDIAN
455{
456 /** The usual invalid endian. */
457 KLDRENDIAN_INVALID,
458 /** Little endian. */
459 KLDRENDIAN_LITTLE,
460 /** Bit endian. */
461 KLDRENDIAN_BIG,
462 /** Endianness doesn't have a meaning in the context. */
463 KLDRENDIAN_NA,
464 /** The end of the valid endian values (exclusive). */
465 KLDRENDIAN_END,
466 /** Hack to blow the type up to 32-bit. */
467 KLDRENDIAN_32BIT_HACK = 0x7fffffff
468} KLDRENDIAN;
469
470
471/** Pointer to a module interpreter method table. */
472typedef struct KLDRMODOPS *PKLDRMODOPS;
473/** Pointer to const module interpreter methods table. */
474typedef const struct KLDRMODOPS *PCKLDRMODOPS;
475
476/**
477 * Module interpreter instance.
478 * All members are read only unless you're kLdrMod or the module interpreter.
479 */
480typedef struct KLDRMOD
481{
482 /** Magic number (KLDRMOD_MAGIC). */
483 KU32 u32Magic;
484 /** The format of this module. */
485 KLDRFMT enmFmt;
486 /** The type of module. */
487 KLDRTYPE enmType;
488 /** The architecture this module was built for. */
489 KLDRARCH enmArch;
490 /** The minium cpu this module was built for.
491 * This might not be accurate, so use kLdrModCanExecuteOn() to check. */
492 KLDRARCH enmCpu;
493 /** The endian used by the module. */
494 KLDRENDIAN enmEndian;
495 /** The filename length (bytes). */
496 KU32 cchFilename;
497 /** The filename. */
498 const char *pszFilename;
499 /** The module name. */
500 const char *pszName;
501 /** The module name length (bytes). */
502 KU32 cchName;
503 /** The number of segments in the module. */
504 KU32 cSegments;
505 /** Pointer to the loader methods.
506 * Not meant for calling directly thru! */
507 PCKLDRMODOPS pOps;
508 /** Pointer to the read instance. (Can be NULL after kLdrModDone().)*/
509 PKRDR pRdr;
510 /** The module data. */
511 void *pvData;
512 /** Segments. (variable size, can be zero) */
513 KLDRSEG aSegments[1];
514} KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
515
516/** The magic for KLDRMOD::u32Magic. (Kosuke Fujishima) */
517#define KLDRMOD_MAGIC 0x19640707
518
519
520/** Special base address value alias for the link address. */
521#define KLDRMOD_BASEADDRESS_LINK (~(KLDRADDR)1)
522/** Special base address value alias for the actual load address (must be mapped). */
523#define KLDRMOD_BASEADDRESS_MAP (~(KLDRADDR)2)
524
525/** Special import module ordinal value used to indicate that there is no
526 * specific module associated with the requested symbol. */
527#define NIL_KLDRMOD_IMPORT (~(KU32)0)
528
529/** Special symbol ordinal value used to indicate that the symbol
530 * only has a string name. */
531#define NIL_KLDRMOD_SYM_ORDINAL (~(KU32)0)
532
533
534/** @name Load symbol kind flags.
535 * @{ */
536/** The bitness doesn't matter. */
537#define KLDRSYMKIND_NO_BIT 0x00000000
538/** 16-bit symbol. */
539#define KLDRSYMKIND_16BIT 0x00000001
540/** 32-bit symbol. */
541#define KLDRSYMKIND_32BIT 0x00000002
542/** 64-bit symbol. */
543#define KLDRSYMKIND_64BIT 0x00000003
544/** Mask out the bit.*/
545#define KLDRSYMKIND_BIT_MASK 0x00000003
546/** We don't know the type of symbol. */
547#define KLDRSYMKIND_NO_TYPE 0x00000000
548/** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
549#define KLDRSYMKIND_CODE 0x00000010
550/** The symbol is a data object. */
551#define KLDRSYMKIND_DATA 0x00000020
552/** Mask out the symbol type. */
553#define KLDRSYMKIND_TYPE_MASK 0x00000030
554/** Valid symbol kind mask. */
555#define KLDRSYMKIND_MASK 0x00000033
556/** Weak symbol. */
557#define KLDRSYMKIND_WEAK 0x00000100
558/** Forwarder symbol. */
559#define KLDRSYMKIND_FORWARDER 0x00000200
560/** Request a flat symbol address. */
561#define KLDRSYMKIND_REQ_FLAT 0x00000000
562/** Request a segmented symbol address. */
563#define KLDRSYMKIND_REQ_SEGMENTED 0x40000000
564/** Request type mask. */
565#define KLDRSYMKIND_REQ_TYPE_MASK 0x40000000
566/** @} */
567
568/** @name kLdrModEnumSymbols flags.
569 * @{ */
570/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
571#define KLDRMOD_ENUM_SYMS_FLAGS_ALL 0x00000001
572/** @} */
573
574
575/**
576 * Callback for resolving imported symbols when applying fixups.
577 *
578 * @returns 0 on success and *pValue and *pfKind filled.
579 * @returns Non-zero OS specific or kLdr status code on failure.
580 *
581 * @param pMod The module which fixups are begin applied.
582 * @param iImport The import module ordinal number or NIL_KLDRMOD_IMPORT.
583 * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
584 * @param pchSymbol The symbol name. Can be NULL if iSymbol isn't nil. Doesn't have to be null-terminated.
585 * @param cchSymbol The length of the symbol.
586 * @param pszVersion The symbol version. NULL if not versioned.
587 * @param puValue Where to store the symbol value.
588 * @param pfKind Where to store the symbol kind flags.
589 * @param pvUser The user parameter specified to the relocation function.
590 */
591typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, KU32 iImport, KU32 iSymbol, const char *pchSymbol, KSIZE cchSymbol,
592 const char *pszVersion, PKLDRADDR puValue, KU32 *pfKind, void *pvUser);
593/** Pointer to a import callback. */
594typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
595
596/**
597 * Symbol enumerator callback.
598 *
599 * @returns 0 if enumeration should continue.
600 * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumSymbols().
601 *
602 * @param pMod The module which symbols are being enumerated.s
603 * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
604 * @param pchSymbol The symbol name. This can be NULL if there is a symbol ordinal.
605 * This can also be an empty string if the symbol doesn't have a name
606 * or it's name has been stripped.
607 * Important, this doesn't have to be a null-terminated string.
608 * @param cchSymbol The length of the symbol.
609 * @param pszVersion The symbol version. NULL if not versioned.
610 * @param uValue The symbol value.
611 * @param fKind The symbol kind flags.
612 * @param pvUser The user parameter specified to kLdrModEnumSymbols().
613 */
614typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, KU32 iSymbol, const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
615 KLDRADDR uValue, KU32 fKind, void *pvUser);
616/** Pointer to a symbol enumerator callback. */
617typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
618
619/**
620 * Debug info enumerator callback.
621 *
622 * @returns 0 to continue the enumeration.
623 * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumDbgInfo().
624 *
625 * @param pMod The module.
626 * @param iDbgInfo The debug info ordinal number / id.
627 * @param enmType The debug info type.
628 * @param iMajorVer The major version number of the debug info format. -1 if unknow - implies invalid iMinorVer.
629 * @param iMinorVer The minor version number of the debug info format. -1 when iMajorVer is -1.
630 * @param offFile The file offset *if* this type has one specific location in the executable image file.
631 * This is -1 if there isn't any specific file location.
632 * @param LinkAddress The link address of the debug info if it's loadable. NIL_KLDRADDR if not loadable.
633 * @param cb The size of the debug information. -1 is used if this isn't applicable.
634 * @param pszExtFile This points to the name of an external file containing the debug info.
635 * This is NULL if there isn't any external file.
636 * @param pvUser The user parameter specified to kLdrModEnumDbgInfo.
637 */
638typedef int FNKLDRENUMDBG(PKLDRMOD pMod, KU32 iDbgInfo, KLDRDBGINFOTYPE enmType, KI16 iMajorVer, KI16 iMinorVer,
639 KLDRFOFF offFile, KLDRADDR LinkAddress, KLDRSIZE cb, const char *pszExtFile, void *pvUser);
640/** Pointer to a debug info enumerator callback. */
641typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;
642
643/**
644 * Resource enumerator callback.
645 *
646 * @returns 0 to continue the enumeration.
647 * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumResources().
648 *
649 * @param pMod The module.
650 * @param idType The resource type id. NIL_KLDRMOD_RSRC_TYPE_ID if no type id.
651 * @param pszType The resource type name. NULL if no type name.
652 * @param idName The resource id. NIL_KLDRMOD_RSRC_NAME_ID if no id.
653 * @param pszName The resource name. NULL if no name.
654 * @param idLang The language id.
655 * @param AddrRsrc The address value for the resource.
656 * @param cbRsrc The size of the resource.
657 * @param pvUser The user parameter specified to kLdrModEnumDbgInfo.
658 */
659typedef int FNKLDRENUMRSRC(PKLDRMOD pMod, KU32 idType, const char *pszType, KU32 idName, const char *pszName,
660 KU32 idLang, KLDRADDR AddrRsrc, KLDRSIZE cbRsrc, void *pvUser);
661/** Pointer to a resource enumerator callback. */
662typedef FNKLDRENUMRSRC *PFNKLDRENUMRSRC;
663
664/** NIL resource name ID. */
665#define NIL_KLDRMOD_RSRC_NAME_ID ( ~(KU32)0 )
666/** NIL resource type ID. */
667#define NIL_KLDRMOD_RSRC_TYPE_ID ( ~(KU32)0 )
668/** @name Language ID
669 *
670 * Except for the special IDs #defined here, the values are considered
671 * format specific for now since it's only used by the PE resources.
672 *
673 * @{ */
674/** NIL language ID. */
675#define NIL_KLDR_LANG_ID ( ~(KU32)0 )
676/** Special language id value for matching any language. */
677#define KLDR_LANG_ID_ANY ( ~(KU32)1 )
678/** Special language id value indicating language neutral. */
679#define KLDR_LANG_ID_NEUTRAL ( ~(KU32)2 )
680/** Special language id value indicating user default language. */
681#define KLDR_LANG_ID_USER_DEFAULT ( ~(KU32)3 )
682/** Special language id value indicating system default language. */
683#define KLDR_LANG_ID_SYS_DEFAULT ( ~(KU32)4 )
684/** Special language id value indicating default custom locale. */
685#define KLDR_LANG_ID_CUSTOM_DEFAULT ( ~(KU32)5 )
686/** Special language id value indicating unspecified custom locale. */
687#define KLDR_LANG_ID_CUSTOM_UNSPECIFIED ( ~(KU32)6 )
688/** Special language id value indicating default custom MUI locale. */
689#define KLDR_LANG_ID_UI_CUSTOM_DEFAULT ( ~(KU32)7 )
690/** @} */
691
692
693int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod);
694int kLdrModOpenFromRdr(PKRDR pRdr, PPKLDRMOD ppMod);
695int kLdrModOpenNative(const char *pszFilename, PPKLDRMOD ppMod);
696int kLdrModOpenNativeByHandle(KUPTR uHandle, PPKLDRMOD ppMod);
697int kLdrModClose(PKLDRMOD pMod);
698
699int kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 iSymbol,
700 const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
701 PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, PKLDRADDR puValue, KU32 *pfKind);
702int kLdrModEnumSymbols(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress,
703 KU32 fFlags, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
704int kLdrModGetImport(PKLDRMOD pMod, const void *pvBits, KU32 iImport, char *pszName, KSIZE cchName);
705KI32 kLdrModNumberOfImports(PKLDRMOD pMod, const void *pvBits);
706int kLdrModCanExecuteOn(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
707int kLdrModGetStackInfo(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
708int kLdrModQueryMainEntrypoint(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
709int kLdrModQueryResource(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
710 KU32 idName, const char *pszName, KU32 idLang, PKLDRADDR pAddrRsrc, KSIZE *pcbRsrc);
711int kLdrModEnumResources(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
712 KU32 idName, const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
713int kLdrModEnumDbgInfo(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
714int kLdrModHasDbgInfo(PKLDRMOD pMod, const void *pvBits);
715int kLdrModMostlyDone(PKLDRMOD pMod);
716
717
718/** @name Operations On The Internally Managed Mapping
719 * @{ */
720int kLdrModMap(PKLDRMOD pMod);
721int kLdrModUnmap(PKLDRMOD pMod);
722int kLdrModAllocTLS(PKLDRMOD pMod);
723void kLdrModFreeTLS(PKLDRMOD pMod);
724int kLdrModReload(PKLDRMOD pMod);
725int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
726int kLdrModCallInit(PKLDRMOD pMod, KUPTR uHandle);
727int kLdrModCallTerm(PKLDRMOD pMod, KUPTR uHandle);
728int kLdrModCallThread(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching);
729/** @} */
730
731/** @name Operations On The Externally Managed Mappings
732 * @{ */
733KLDRADDR kLdrModSize(PKLDRMOD pMod);
734int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
735int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
736 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
737/** @} */
738
739
740/**
741 * The loader module operation.
742 */
743typedef struct KLDRMODOPS
744{
745 /** The name of this module interpreter. */
746 const char *pszName;
747 /** Pointer to the next module interpreter. */
748 PCKLDRMODOPS pNext;
749
750 /**
751 * Create a loader module instance interpreting the executable image found
752 * in the specified file provider instance.
753 *
754 * @returns 0 on success and *ppMod pointing to a module instance.
755 * On failure, a non-zero OS specific error code is returned.
756 * @param pOps Pointer to the registered method table.
757 * @param pRdr The file provider instance to use.
758 * @param offNewHdr The offset of the new header in MZ files. -1 if not found.
759 * @param ppMod Where to store the module instance pointer.
760 */
761 int (* pfnCreate)(PCKLDRMODOPS pOps, PKRDR pRdr, KLDRFOFF offNewHdr, PPKLDRMOD ppMod);
762 /**
763 * Destroys an loader module instance.
764 *
765 * The caller is responsible for calling kLdrModUnmap() and kLdrFreeTLS() first.
766 *
767 * @returns 0 on success, non-zero on failure. The module instance state
768 * is unknown on failure, it's best not to touch it.
769 * @param pMod The module.
770 */
771 int (* pfnDestroy)(PKLDRMOD pMod);
772
773 /** @copydoc kLdrModQuerySymbol */
774 int (* pfnQuerySymbol)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 iSymbol,
775 const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
776 PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, PKLDRADDR puValue, KU32 *pfKind);
777 /** @copydoc kLdrModEnumSymbols */
778 int (* pfnEnumSymbols)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 fFlags,
779 PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
780 /** @copydoc kLdrModGetImport */
781 int (* pfnGetImport)(PKLDRMOD pMod, const void *pvBits, KU32 iImport, char *pszName, KSIZE cchName);
782 /** @copydoc kLdrModNumberOfImports */
783 KI32 (* pfnNumberOfImports)(PKLDRMOD pMod, const void *pvBits);
784 /** @copydoc kLdrModCanExecuteOn */
785 int (* pfnCanExecuteOn)(PKLDRMOD pMod, const void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
786 /** @copydoc kLdrModGetStackInfo */
787 int (* pfnGetStackInfo)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
788 /** @copydoc kLdrModQueryMainEntrypoint */
789 int (* pfnQueryMainEntrypoint)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
790 /** @copydoc kLdrModQueryResource */
791 int (* pfnQueryResource)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
792 KU32 idName, const char *pszName, KU32 idLang, PKLDRADDR pAddrRsrc, KSIZE *pcbRsrc);
793 /** @copydoc kLdrModEnumResources */
794 int (* pfnEnumResources)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
795 KU32 idName, const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
796 /** @copydoc kLdrModEnumDbgInfo */
797 int (* pfnEnumDbgInfo)(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
798 /** @copydoc kLdrModHasDbgInfo */
799 int (* pfnHasDbgInfo)(PKLDRMOD pMod, const void *pvBits);
800 /** @copydoc kLdrModMap */
801 int (* pfnMap)(PKLDRMOD pMod);
802 /** @copydoc kLdrModUnmap */
803 int (* pfnUnmap)(PKLDRMOD pMod);
804 /** @copydoc kLdrModAllocTLS */
805 int (* pfnAllocTLS)(PKLDRMOD pMod);
806 /** @copydoc kLdrModFreeTLS */
807 void (*pfnFreeTLS)(PKLDRMOD pMod);
808 /** @copydoc kLdrModReload */
809 int (* pfnReload)(PKLDRMOD pMod);
810 /** @copydoc kLdrModFixupMapping */
811 int (* pfnFixupMapping)(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
812 /** @copydoc kLdrModCallInit */
813 int (* pfnCallInit)(PKLDRMOD pMod, KUPTR uHandle);
814 /** @copydoc kLdrModCallTerm */
815 int (* pfnCallTerm)(PKLDRMOD pMod, KUPTR uHandle);
816 /** @copydoc kLdrModCallThread */
817 int (* pfnCallThread)(PKLDRMOD pMod, KUPTR uHandle, unsigned fAttachingOrDetaching);
818 /** @copydoc kLdrModSize */
819 KLDRADDR (* pfnSize)(PKLDRMOD pMod);
820 /** @copydoc kLdrModGetBits */
821 int (* pfnGetBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
822 /** @copydoc kLdrModRelocateBits */
823 int (* pfnRelocateBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
824 PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
825 /** @copydoc kLdrModMostlyDone */
826 int (* pfnMostlyDone)(PKLDRMOD pMod);
827 /** Dummy which should be assigned a non-zero value. */
828 KU32 uEndOfStructure;
829} KLDRMODOPS;
830
831
832/** @} */
833
834
835
836
837/** @defgroup grp_kLdrDyld kLdrDyld - The dynamic loader
838 * @{ */
839
840/** The handle to a dynamic loader module. */
841typedef struct KLDRDYLDMOD *HKLDRMOD;
842/** Pointer to the handle to a dynamic loader module. */
843typedef HKLDRMOD *PHKLDRMOD;
844/** NIL handle value. */
845#define NIL_HKLDRMOD ((HKLDRMOD)0)
846
847
848/**
849 * File search method.
850 *
851 * In addition to it's own way of finding files, kLdr emulates
852 * the methods employed by the most popular systems.
853 */
854typedef enum KLDRDYLDSEARCH
855{
856 /** The usual invalid file search method. */
857 KLDRDYLD_SEARCH_INVALID = 0,
858 /** Uses the kLdr file search method.
859 * @todo invent me. */
860 KLDRDYLD_SEARCH_KLDR,
861 /** Use the emulation closest to the host system. */
862 KLDRDYLD_SEARCH_HOST,
863 /** Emulate the OS/2 file search method.
864 * On non-OS/2 systems, BEGINLIBPATH, LIBPATH, ENDLIBPATH and LIBPATHSTRICT are
865 * taken form the environment. */
866 KLDRDYLD_SEARCH_OS2,
867 /** Emulate the standard window file search method. */
868 KLDRDYLD_SEARCH_WINDOWS,
869 /** Emulate the alternative window file search method. */
870 KLDRDYLD_SEARCH_WINDOWS_ALTERED,
871 /** Emulate the most common UNIX file search method. */
872 KLDRDYLD_SEARCH_UNIX_COMMON,
873 /** End of the valid file search method values. */
874 KLDRDYLD_SEARCH_END,
875 /** Hack to blow the type up to 32-bit. */
876 KLDRDYLD_SEARCH_32BIT_HACK = 0x7fffffff
877} KLDRDYLDSEARCH;
878
879/** @name kLdrDyldLoad and kLdrDyldFindByName flags.
880 * @{ */
881/** The symbols in the module should be loaded into the global unix namespace.
882 * If not specified, the symbols are local and can only be referenced directly. */
883#define KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS 0x00000001
884/** The symbols in the module should be loaded into the global unix namespace and
885 * it's symbols should take precedence over all currently loaded modules.
886 * This implies KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS. */
887#define KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS 0x00000002
888/** The module shouldn't be found by a global module search.
889 * If not specified, the module can be found by unspecified module searches,
890 * typical used when loading import/dep modules. */
891#define KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE 0x00000004
892/** Do a recursive initialization calls instead of defering them to the outermost call. */
893#define KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT 0x00000008
894/** We're loading the executable module.
895 * @internal */
896#define KLDRDYLD_LOAD_FLAGS_EXECUTABLE 0x40000000
897/** @} */
898
899
900int kLdrDyldLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
901 unsigned fFlags, PHKLDRMOD phMod, char *pszErr, KSIZE cchErr);
902int kLdrDyldUnload(HKLDRMOD hMod);
903int kLdrDyldFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
904 unsigned fFlags, PHKLDRMOD phMod);
905int kLdrDyldFindByAddress(KUPTR Address, PHKLDRMOD phMod, KU32 *piSegment, KUPTR *poffSegment);
906int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, KSIZE cchName);
907int kLdrDyldGetFilename(HKLDRMOD hMod, char *pszFilename, KSIZE cchFilename);
908int kLdrDyldQuerySymbol(HKLDRMOD hMod, KU32 uSymbolOrdinal, const char *pszSymbolName,
909 const char *pszSymbolVersion, KUPTR *pValue, KU32 *pfKind);
910int kLdrDyldQueryResource(HKLDRMOD hMod, KU32 idType, const char *pszType, KU32 idName,
911 const char *pszName, KU32 idLang, void **pvRsrc, KSIZE *pcbRsrc);
912int kLdrDyldEnumResources(HKLDRMOD hMod, KU32 idType, const char *pszType, KU32 idName,
913 const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
914
915
916/** @name OS/2 like API
917 * @{ */
918#if defined(__OS2__)
919# define KLDROS2API _System
920#else
921# define KLDROS2API
922#endif
923int kLdrDosLoadModule(char *pszObject, KSIZE cbObject, const char *pszModule, PHKLDRMOD phMod);
924int kLdrDosFreeModule(HKLDRMOD hMod);
925int kLdrDosQueryModuleHandle(const char *pszModname, PHKLDRMOD phMod);
926int kLdrDosQueryModuleName(HKLDRMOD hMod, KSIZE cchName, char *pszName);
927int kLdrDosQueryProcAddr(HKLDRMOD hMod, KU32 iOrdinal, const char *pszProcName, void **ppvProcAddr);
928int kLdrDosQueryProcType(HKLDRMOD hMod, KU32 iOrdinal, const char *pszProcName, KU32 *pfProcType);
929int kLdrDosQueryModFromEIP(PHKLDRMOD phMod, KU32 *piObject, KSIZE cbName, char *pszName, KUPTR *poffObject, KUPTR ulEIP);
930int kLdrDosReplaceModule(const char *pszOldModule, const char *pszNewModule, const char *pszBackupModule);
931int kLdrDosGetResource(HKLDRMOD hMod, KU32 idType, KU32 idName, void **pvResAddr);
932int kLdrDosQueryResourceSize(HKLDRMOD hMod, KU32 idType, KU32 idName, KU32 *pcb);
933int kLdrDosFreeResource(void *pvResAddr);
934/** @} */
935
936/** @name POSIX like API
937 * @{ */
938HKLDRMOD kLdrDlOpen(const char *pszLibrary, int fFlags);
939const char *kLdrDlError(void);
940void * kLdrDlSym(HKLDRMOD hMod, const char *pszSymbol);
941int kLdrDlClose(HKLDRMOD hMod);
942/** @todo GNU extensions */
943/** @} */
944
945/** @name Win32 like API
946 * @{ */
947#if defined(_MSC_VER)
948# define KLDRWINAPI __stdcall
949#else
950# define KLDRWINAPI
951#endif
952HKLDRMOD KLDRWINAPI kLdrWLoadLibrary(const char *pszFilename);
953HKLDRMOD KLDRWINAPI kLdrWLoadLibraryEx(const char *pszFilename, void *hFileReserved, KU32 fFlags);
954KU32 KLDRWINAPI kLdrWGetModuleFileName(HKLDRMOD hMod, char *pszModName, KSIZE cchModName);
955HKLDRMOD KLDRWINAPI kLdrWGetModuleHandle(const char *pszFilename);
956int KLDRWINAPI kLdrWGetModuleHandleEx(KU32 fFlags, const char *pszFilename, HKLDRMOD hMod);
957void * KLDRWINAPI kLdrWGetProcAddress(HKLDRMOD hMod, const char *pszProcName);
958KU32 KLDRWINAPI kLdrWGetDllDirectory(KSIZE cchDir, char *pszDir);
959int KLDRWINAPI kLdrWSetDllDirectory(const char *pszDir);
960int KLDRWINAPI kLdrWFreeLibrary(HKLDRMOD hMod);
961int KLDRWINAPI kLdrWDisableThreadLibraryCalls(HKLDRMOD hMod);
962
963/** The handle to a resource that's been found. */
964typedef struct KLDRWRSRCFOUND *HKLDRWRSRCFOUND;
965/** The handle to a loaded resource. */
966typedef struct KLDRWRSRCLOADED *HKLDRWRSRCLOADED;
967HKLDRWRSRCFOUND KLDRWINAPI kLdrWFindResource(HKLDRMOD hMod, const char *pszType, const char *pszName);
968HKLDRWRSRCFOUND KLDRWINAPI kLdrWFindResourceEx(HKLDRMOD hMod, const char *pszType, const char *pszName, KU16 idLang);
969KU32 KLDRWINAPI kLdrWSizeofResource(HKLDRMOD hMod, HKLDRWRSRCFOUND hFoundRsrc);
970HKLDRWRSRCLOADED KLDRWINAPI kLdrWLoadResource(HKLDRMOD hMod, HKLDRWRSRCFOUND hFoundRsrc);
971void *KLDRWINAPI kLdrWLockResource(HKLDRMOD hMod, HKLDRWRSRCLOADED hLoadedRsrc);
972int KLDRWINAPI kLdrWFreeResource(HKLDRMOD hMod, HKLDRWRSRCLOADED hLoadedRsrc);
973
974typedef int (KLDRWINAPI *PFNKLDRWENUMRESTYPE)(HKLDRMOD hMod, const char *pszType, KUPTR uUser);
975int KLDRWINAPI kLdrWEnumResourceTypes(HKLDRMOD hMod, PFNKLDRWENUMRESTYPE pfnEnum, KUPTR uUser);
976int KLDRWINAPI kLdrWEnumResourceTypesEx(HKLDRMOD hMod, PFNKLDRWENUMRESTYPE pfnEnum, KUPTR uUser, KU32 fFlags, KU16 idLang);
977
978typedef int (KLDRWINAPI *PFNKLDRWENUMRESNAME)(HKLDRMOD hMod, const char *pszType, char *pszName, KUPTR uUser);
979int KLDRWINAPI kLdrWEnumResourceNames(HKLDRMOD hMod, const char *pszType, PFNKLDRWENUMRESNAME pfnEnum, KUPTR uUser);
980int KLDRWINAPI kLdrWEnumResourceNamesEx(HKLDRMOD hMod, const char *pszType, PFNKLDRWENUMRESNAME pfnEnum, KUPTR uUser, KU32 fFlags, KU16 idLang);
981
982typedef int (KLDRWINAPI *PFNKLDRWENUMRESLANG)(HKLDRMOD hMod, const char *pszType, const char *pszName, KU16 idLang, KUPTR uUser);
983int KLDRWINAPI kLdrWEnumResourceLanguages(HKLDRMOD hMod, const char *pszType, const char *pszName, PFNKLDRWENUMRESLANG pfnEnum, KUPTR uUser);
984int KLDRWINAPI kLdrWEnumResourceLanguagesEx(HKLDRMOD hMod, const char *pszType, const char *pszName,
985 PFNKLDRWENUMRESLANG pfnEnum, KUPTR uUser, KU32 fFlags, KU16 idLang);
986/** @} */
987
988
989/** @name Process Bootstrapping
990 * @{ */
991
992/**
993 * Argument package from the stub.
994 */
995typedef struct KLDREXEARGS
996{
997 /** Load & search flags, some which will become defaults. */
998 KU32 fFlags;
999 /** The default search method. */
1000 KLDRDYLDSEARCH enmSearch;
1001 /** The executable file that the stub is supposed to load. */
1002 char szExecutable[260];
1003 /** The default prefix used when searching for DLLs. */
1004 char szDefPrefix[16];
1005 /** The default suffix used when searching for DLLs. */
1006 char szDefSuffix[16];
1007 /** The LD_LIBRARY_PATH prefix for the process.. */
1008 char szLibPath[4096 - sizeof(KU32) - sizeof(KLDRDYLDSEARCH) - 16 - 16 - 260];
1009} KLDREXEARGS, *PKLDREXEARGS;
1010/** Pointer to a const argument package from the stub. */
1011typedef const KLDREXEARGS *PCKLDREXEARGS;
1012
1013void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS); /** @todo fix this mess... */
1014void kLdrDyldLoadExe(PCKLDREXEARGS pArgs, void *pvOS);
1015
1016/** @} */
1017
1018/** @} */
1019
1020
1021/** @defgroup grp_kLdrErr kLdr Status Codes
1022 * kLdr uses a mix of native status codes and it's own status codes.
1023 * A status code of 0 means success, all other status codes means failure.
1024 * @{
1025 */
1026
1027#define KLDR_ERR_BASE 420000
1028
1029/** The image format is unknown. */
1030#define KLDR_ERR_UNKNOWN_FORMAT (KLDR_ERR_BASE + 0)
1031/** The MZ image format isn't supported by this kLdr build. */
1032#define KLDR_ERR_MZ_NOT_SUPPORTED (KLDR_ERR_BASE + 1)
1033/** The NE image format isn't supported by this kLdr build. */
1034#define KLDR_ERR_NE_NOT_SUPPORTED (KLDR_ERR_BASE + 2)
1035/** The LX image format isn't supported by this kLdr build. */
1036#define KLDR_ERR_LX_NOT_SUPPORTED (KLDR_ERR_BASE + 3)
1037/** The LE image format isn't supported by this kLdr build. */
1038#define KLDR_ERR_LE_NOT_SUPPORTED (KLDR_ERR_BASE + 4)
1039/** The PE image format isn't supported by this kLdr build. */
1040#define KLDR_ERR_PE_NOT_SUPPORTED (KLDR_ERR_BASE + 5)
1041/** The ELF image format isn't supported by this kLdr build. */
1042#define KLDR_ERR_ELF_NOT_SUPPORTED (KLDR_ERR_BASE + 6)
1043/** The mach-o image format isn't supported by this kLdr build. */
1044#define KLDR_ERR_MACHO_NOT_SUPPORTED (KLDR_ERR_BASE + 7)
1045/** The FAT image format isn't supported by this kLdr build or
1046 * a direct open was attempt without going thru the FAT file provider.
1047 * FAT images are also known as Universal Binaries. */
1048#define KLDR_ERR_FAT_NOT_SUPPORTED (KLDR_ERR_BASE + 8)
1049/** The a.out image format isn't supported by this kLdr build. */
1050#define KLDR_ERR_AOUT_NOT_SUPPORTED (KLDR_ERR_BASE + 9)
1051
1052/** Invalid parameter to a kLdr API. */
1053#define KLDR_ERR_INVALID_PARAMETER (KLDR_ERR_BASE + 32)
1054/** Invalid handle parameter to a kLdr API. */
1055#define KLDR_ERR_INVALID_HANDLE (KLDR_ERR_BASE + 33)
1056/** The module wasn't loaded dynamically. */
1057#define KLDR_ERR_NOT_LOADED_DYNAMICALLY (KLDR_ERR_BASE + 34)
1058/** The module wasn't found. */
1059#define KLDR_ERR_MODULE_NOT_FOUND (KLDR_ERR_BASE + 35)
1060/** A prerequisit module wasn't found. */
1061#define KLDR_ERR_PREREQUISITE_MODULE_NOT_FOUND (KLDR_ERR_BASE + 36)
1062/** The module is being terminated and can therefore not be loaded. */
1063#define KLDR_ERR_MODULE_TERMINATING (KLDR_ERR_BASE + 37)
1064/** A prerequisit module is being terminated and can therefore not be loaded. */
1065#define KLDR_ERR_PREREQUISITE_MODULE_TERMINATING (KLDR_ERR_BASE + 38)
1066/** The module initialization failed. */
1067#define KLDR_ERR_MODULE_INIT_FAILED (KLDR_ERR_BASE + 39)
1068/** The initialization of a prerequisite module failed. */
1069#define KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED (KLDR_ERR_BASE + 40)
1070/** The module has already failed initialization and can't be attempted reloaded until
1071 * after we've finished garbage collection. */
1072#define KLDR_ERR_MODULE_INIT_FAILED_ALREADY (KLDR_ERR_BASE + 41)
1073/** A prerequisite module has already failed initialization and can't be attempted
1074 * reloaded until after we've finished garbage collection. */
1075#define KLDR_ERR_PREREQUISITE_MODULE_INIT_FAILED_ALREADY (KLDR_ERR_BASE + 42)
1076/** Prerequisite recursed too deeply. */
1077#define KLDR_ERR_PREREQUISITE_RECURSED_TOO_DEEPLY (KLDR_ERR_BASE + 43)
1078/** Failed to allocate the main stack. */
1079#define KLDR_ERR_MAIN_STACK_ALLOC_FAILED (KLDR_ERR_BASE + 44)
1080/** Buffer overflow. */
1081#define KLDR_ERR_BUFFER_OVERFLOW (KLDR_ERR_BASE + 45)
1082/** The specified ARCH+CPU isn't compatible with image. */
1083#define KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE (KLDR_ERR_BASE + 46)
1084/** Symbol not found. */
1085#define KLDR_ERR_SYMBOL_NOT_FOUND (KLDR_ERR_BASE + 47)
1086/** A forward symbol was encountered but the caller didn't provide any means to resolve it. */
1087#define KLDR_ERR_FORWARDER_SYMBOL (KLDR_ERR_BASE + 48)
1088/** Encountered a bad fixup. */
1089#define KLDR_ERR_BAD_FIXUP (KLDR_ERR_BASE + 49)
1090/** A memory allocation failed. */
1091#define KLDR_ERR_NO_MEMORY (KLDR_ERR_BASE + 50)
1092/** The import ordinal was out of bounds. */
1093#define KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS (KLDR_ERR_BASE + 51)
1094/** A forwarder chain was too long. */
1095#define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN (KLDR_ERR_BASE + 52)
1096/** The module has no debug info. */
1097#define KLDR_ERR_NO_DEBUG_INFO (KLDR_ERR_BASE + 53)
1098/** The module is already mapped.
1099 * kLdrModMap() can only be called once (without kLdrModUnmap() in between). */
1100#define KLDR_ERR_ALREADY_MAPPED (KLDR_ERR_BASE + 54)
1101/** The module was not mapped.
1102 * kLdrModUnmap() should not called without being preceeded by a kLdrModMap(). */
1103#define KLDR_ERR_NOT_MAPPED (KLDR_ERR_BASE + 55)
1104/** Couldn't fit the address value into the field. Typically a relocation kind of error. */
1105#define KLDR_ERR_ADDRESS_OVERFLOW (KLDR_ERR_BASE + 56)
1106/** Couldn't fit a calculated size value into the native size type of the host. */
1107#define KLDR_ERR_SIZE_OVERFLOW (KLDR_ERR_BASE + 57)
1108/** Thread attach failed. */
1109#define KLDR_ERR_THREAD_ATTACH_FAILED (KLDR_ERR_BASE + 58)
1110/** The file reader can't take more concurrent mappings. */
1111#define KLDR_ERR_TOO_MANY_MAPPINGS (KLDR_ERR_BASE + 59)
1112/** The module wasn't a DLL or object file. */
1113#define KLDR_ERR_NOT_DLL (KLDR_ERR_BASE + 60)
1114/** The module wasn't an EXE. */
1115#define KLDR_ERR_NOT_EXE (KLDR_ERR_BASE + 61)
1116/** Not implemented yet. */
1117#define KLDR_ERR_TODO (KLDR_ERR_BASE + 62)
1118
1119
1120/** @name kLdrModPE status codes
1121 * @{ */
1122#define KLDR_ERR_PE_BASE (KLDR_ERR_BASE + 63)
1123/** The machine isn't supported by the interpreter. */
1124#define KLDR_ERR_PE_UNSUPPORTED_MACHINE (KLDR_ERR_PE_BASE + 0)
1125/** The file handler isn't valid. */
1126#define KLDR_ERR_PE_BAD_FILE_HEADER (KLDR_ERR_PE_BASE + 1)
1127/** The the optional headers isn't valid. */
1128#define KLDR_ERR_PE_BAD_OPTIONAL_HEADER (KLDR_ERR_PE_BASE + 2)
1129/** One of the section headers aren't valid. */
1130#define KLDR_ERR_PE_BAD_SECTION_HEADER (KLDR_ERR_PE_BASE + 3)
1131/** Bad forwarder entry. */
1132#define KLDR_ERR_PE_BAD_FORWARDER (KLDR_ERR_PE_BASE + 4)
1133/** Forwarder module not found in the import descriptor table. */
1134#define KLDR_ERR_PE_FORWARDER_IMPORT_NOT_FOUND (KLDR_ERR_PE_BASE + 5)
1135/** Bad PE fixups. */
1136#define KLDR_ERR_PE_BAD_FIXUP (KLDR_ERR_PE_BASE + 6)
1137/** Bad PE import (thunk). */
1138#define KLDR_ERR_PE_BAD_IMPORT (KLDR_ERR_PE_BASE + 7)
1139/** @} */
1140
1141/** @name kLdrModLX status codes
1142 * @{ */
1143#define KLDR_ERR_LX_BASE (KLDR_ERR_PE_BASE + 8)
1144/** validation of LX header failed. */
1145#define KLDR_ERR_LX_BAD_HEADER (KLDR_ERR_LX_BASE + 0)
1146/** validation of the loader section (in the LX header) failed. */
1147#define KLDR_ERR_LX_BAD_LOADER_SECTION (KLDR_ERR_LX_BASE + 1)
1148/** validation of the fixup section (in the LX header) failed. */
1149#define KLDR_ERR_LX_BAD_FIXUP_SECTION (KLDR_ERR_LX_BASE + 2)
1150/** validation of the LX object table failed. */
1151#define KLDR_ERR_LX_BAD_OBJECT_TABLE (KLDR_ERR_LX_BASE + 3)
1152/** A bad page map entry was encountered. */
1153#define KLDR_ERR_LX_BAD_PAGE_MAP (KLDR_ERR_LX_BASE + 4)
1154/** Bad iterdata (EXEPACK) data. */
1155#define KLDR_ERR_LX_BAD_ITERDATA (KLDR_ERR_LX_BASE + 5)
1156/** Bad iterdata2 (EXEPACK2) data. */
1157#define KLDR_ERR_LX_BAD_ITERDATA2 (KLDR_ERR_LX_BASE + 6)
1158/** Bad bundle data. */
1159#define KLDR_ERR_LX_BAD_BUNDLE (KLDR_ERR_LX_BASE + 7)
1160/** No soname. */
1161#define KLDR_ERR_LX_NO_SONAME (KLDR_ERR_LX_BASE + 8)
1162/** Bad soname. */
1163#define KLDR_ERR_LX_BAD_SONAME (KLDR_ERR_LX_BASE + 9)
1164/** Bad forwarder entry. */
1165#define KLDR_ERR_LX_BAD_FORWARDER (KLDR_ERR_LX_BASE + 10)
1166/** internal fixup chain isn't implemented yet. */
1167#define KLDR_ERR_LX_NRICHAIN_NOT_SUPPORTED (KLDR_ERR_LX_BASE + 11)
1168/** @} */
1169
1170/** @name
1171 * @{ */
1172#define KLDR_ERR_MACHO_BASE (KLDR_ERR_LX_BASE + 12)
1173/** Only native endian Mach-O files are supported. */
1174#define KLDR_ERR_MACHO_OTHER_ENDIAN_NOT_SUPPORTED (KLDR_ERR_MACHO_BASE + 0)
1175/** 64-bit Mach-O files aren't supported yet. */
1176#define KLDR_ERR_MACHO_64BIT_NOT_SUPPORTED (KLDR_ERR_MACHO_BASE + 1)
1177/** The Mach-O header is bad or contains new and unsupported features. */
1178#define KLDR_ERR_MACHO_BAD_HEADER (KLDR_ERR_MACHO_BASE + 2)
1179/** The file type isn't supported. */
1180#define KLDR_ERR_MACHO_UNSUPPORTED_FILE_TYPE (KLDR_ERR_MACHO_BASE + 3)
1181/** The machine (cputype / cpusubtype combination) isn't supported. */
1182#define KLDR_ERR_MACHO_UNSUPPORTED_MACHINE (KLDR_ERR_MACHO_BASE + 4)
1183/** Bad load command(s). */
1184#define KLDR_ERR_MACHO_BAD_LOAD_COMMAND (KLDR_ERR_MACHO_BASE + 5)
1185/** Encountered an unknown load command.*/
1186#define KLDR_ERR_MACHO_UNKNOWN_LOAD_COMMAND (KLDR_ERR_MACHO_BASE + 6)
1187/** Encountered a load command that's not implemented.*/
1188#define KLDR_ERR_MACHO_UNSUPPORTED_LOAD_COMMAND (KLDR_ERR_MACHO_BASE + 7)
1189/** Bad section. */
1190#define KLDR_ERR_MACHO_BAD_SECTION (KLDR_ERR_MACHO_BASE + 8)
1191/** Encountered a section type that's not implemented.*/
1192#define KLDR_ERR_MACHO_UNSUPPORTED_SECTION (KLDR_ERR_MACHO_BASE + 9)
1193/** Encountered a section type that's not known to the loader. (probably invalid) */
1194#define KLDR_ERR_MACHO_UNKNOWN_SECTION (KLDR_ERR_MACHO_BASE + 10)
1195/** The sections aren't ordered by segment as expected by the loader. */
1196#define KLDR_ERR_MACHO_BAD_SECTION_ORDER (KLDR_ERR_MACHO_BASE + 11)
1197/** The image is 32-bit and contains 64-bit load commands or vise versa. */
1198#define KLDR_ERR_MACHO_BIT_MIX (KLDR_ERR_MACHO_BASE + 12)
1199/** Bad MH_OBJECT file. */
1200#define KLDR_ERR_MACHO_BAD_OBJECT_FILE (KLDR_ERR_MACHO_BASE + 13)
1201/** Bad symbol table entry. */
1202#define KLDR_ERR_MACHO_BAD_SYMBOL (KLDR_ERR_MACHO_BASE + 14)
1203/** Unsupported fixup type. */
1204#define KLDR_ERR_MACHO_UNSUPPORTED_FIXUP_TYPE (KLDR_ERR_MACHO_BASE + 15)
1205/** @} */
1206
1207/** End of the valid kLdr status codes. */
1208#define KLDR_ERR_END (KLDR_ERR_MACHO_BASE + 16)
1209
1210const char *kLdrErrStr(int rc);
1211
1212/** @} */
1213
1214
1215#ifdef __cplusplus
1216}
1217#endif
1218
1219#endif
1220
Note: See TracBrowser for help on using the repository browser.