source: trunk/kLdr/kLdr.h@ 2836

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

more prototyping. (And avoid 64-bit div/rem)

  • Property svn:keywords set to Id
File size: 26.4 KB
Line 
1/* $Id: kLdr.h 2836 2006-10-26 03:58:53Z 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
56typedef enum KLDRPROT
57{
58 /** The usual invalid 0. */
59 KLDRPROT_INVALID = 0,
60 /** No access (page not present). */
61 KLDRPROT_NOACCESS,
62 /** Read only. */
63 KLDRPROT_READONLY,
64 /** Read & write. */
65 KLDRPROT_READWRITE,
66 /** Read & copy on write. */
67 KLDRPROT_WRITECOPY,
68 /** Execute only. */
69 KLDRPROT_EXECUTE,
70 /** Execute & read. */
71 KLDRPROT_EXECUTE_READ,
72 /** Execute, read & write. */
73 KLDRPROT_EXECUTE_READWRITE,
74 /** Execute, read & copy on write. */
75 KLDRPROT_EXECUTE_WRITECOPY,
76 /** The usual end value. (exclusive) */
77 KLDRPROT_END,
78 /** Blow the type up to 32-bits. */
79 KLDRPROT_32BIT_HACK = 0x7fffffff
80} KLDRPROT;
81
82
83/** Pointer to a file provider instance core. */
84typedef struct KLDRRDR *PKLDRRDR;
85/** Pointer to a file provider instance core pointer. */
86typedef struct KLDRRDR **PPKLDRRDR;
87
88/**
89 * File provider instance operations.
90 */
91typedef struct KLDRRDROPS
92{
93 /** The name of this file provider. */
94 const char *pszName;
95 /** Pointer to the next file provider. */
96 const struct KLDRRDROPS *pNext;
97
98 /** Try create a new file provider instance.
99 *
100 * @returns 0 on success, OS specific error code on failure.
101 * @param ppRdr Where to store the file provider instance.
102 * @param pszFilename The filename to open.
103 */
104 int (* pfnCreate)( PPKLDRRDR ppRdr, const char *pszFilename);
105 /** Destroy the file provider instance.
106 *
107 * @returns 0 on success, OS specific error code on failure.
108 * On failure, the file provider instance will be in an indeterminate state - don't touch it!
109 * @param pRdr The file provider instance.
110 */
111 int (* pfnDestroy)( PKLDRRDR pRdr);
112 /** Read bits from the file.
113 *
114 * @returns 0 on success, OS specific error code on failure.
115 * @param pRdr The file provider instance.
116 * @param pvBuf Where to put the bits.
117 * @param cb The number of bytes to read.
118 * @param off Where to start reading.
119 */
120 int (* pfnRead)( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
121 /** Map all the file bits into memory (read only).
122 *
123 * @returns 0 on success, OS specific error code on failure.
124 * @param pRdr The file provider instance.
125 * @param ppvBits Where to store the address of the mapping.
126 * The size can be obtained using pfnSize.
127 */
128 int (* pfnAllMap)( PKLDRRDR pRdr, const void **ppvBits);
129 /** Unmap a file bits mapping obtained by KLDRRDROPS::pfnAllMap.
130 *
131 * @returns 0 on success, OS specific error code on failure.
132 * @param pRdr The file provider instance.
133 * @param pvBits The mapping address.
134 */
135 int (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits);
136 /** Get the file size.
137 *
138 * @returns The file size. Returns -1 on failure.
139 * @param pRdr The file provider instance.
140 */
141 off_t (* pfnSize)( PKLDRRDR pRdr);
142 /** Get the file pointer offset.
143 *
144 * @returns The file pointer offset. Returns -1 on failure.
145 * @param pRdr The file provider instance.
146 */
147 off_t (* pfnTell)( PKLDRRDR pRdr);
148 /** Get the file name.
149 *
150 * @returns The file size. Returns -1 on failure.
151 * @param pRdr The file provider instance.
152 */
153 const char * (* pfnName)(PKLDRRDR pRdr);
154 /**
155 * Prepares a memory region to map file sections into.
156 *
157 * @returns 0 on success, OS specific error code on failure.
158 * @param pRdr The file provider instance.
159 * @param ppv If fFixed is set, *ppv contains the memory location which
160 * the region should be based at. If fFixed is clear the OS
161 * is free to choose the location.
162 * On successful return *ppv contains address of the prepared
163 * memory region.
164 * @param cb The size of the memory region to prepare.
165 * @param fFixed When set *ppv will contain the desired region address.
166 *
167 */
168 int (* pfnPrepare)(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed);
169 /**
170 * Maps a section of the file into the memory region reserved by pfnPrepare.
171 *
172 * @returns 0 on success, OS specific error code on failure.
173 * @param pRdr The file provider instance.
174 * @param pv The address in the prepared region.
175 * @param cb The size of the memory mapping.
176 * @param enmProt The desired memory protection.
177 * @param offFile The start of the raw file bytes.
178 * @param cbFile The number of raw file bytes. This must be less or equal to cb.
179 */
180 int (* pfnMap)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile);
181 /**
182 * Changes the page protection of a section mapped using pfnMap.
183 *
184 * This is typically used for applying fixups and similar.
185 *
186 * @returns 0 on success, OS specific error code on failure.
187 * @param pRdr The file provider instance.
188 * @param pv The address passed to pfnMap.
189 * @param cb The size passed to pfnMap.
190 * @param enmProt The desired memory protection.
191 */
192 int (* pfnProtect)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt);
193 /**
194 * Unmaps a section of the file previously mapped using pfnMap.
195 *
196 * @returns 0 on success, OS specific error code on failure.
197 * @param pRdr The file provider instance.
198 * @param pv The address passed to pfnMap.
199 * @param cb The size passed to pfnMap.
200 */
201 int (* pfnUnmap)(PKLDRRDR pRdr, void *pv, size_t cb);
202 /**
203 * Releases the memory region prepared by pfnPrepare().
204 *
205 * Before calling this function, all sections mapped by pfnMap must first be unmapped by calling pfnUnmap.
206 *
207 * @returns 0 on success, OS specific error code on failure.
208 * @param pRdr The file provider instance.
209 * @param pv The address of the prepared region.
210 * @param cb The size of the prepared region.
211 */
212 int (* pfnUnprepare)(PKLDRRDR pRdr, void *pv, size_t cb);
213 /**
214 * We're done reading from the file but would like to keep file mappings.
215 *
216 * If the OS support closing the file handle while the file is mapped,
217 * the reader should do so.
218 *
219 * @param pRdr The file provider instance.
220 */
221 void (* pfnDone)(PKLDRRDR pRdr);
222 /** The usual non-zero dummy that makes sure we've initialized all members. */
223 uint32_t u32Dummy;
224} KLDRRDROPS;
225/** Pointer to file provider operations. */
226typedef KLDRRDROPS *PKLDRRDROPS;
227/** Pointer to const file provider operations. */
228typedef const KLDRRDROPS *PCKLDRRDROPS;
229
230
231/**
232 * File provider instance core.
233 */
234typedef struct KLDRRDR
235{
236 /** Pointer to the file provider operations. */
237 PCKLDRRDROPS pOps;
238} KLDRRDR;
239
240void kLdrRdrAddProvider(PKLDRRDROPS pAdd);
241
242int kLdrRdrOpen( PPKLDRRDR ppRdr, const char *pszFilename);
243int kLdrRdrClose( PKLDRRDR pRdr);
244int kLdrRdrRead( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
245int kLdrRdrAllMap( PKLDRRDR pRdr, const void **ppvBits);
246int kLdrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits);
247off_t kLdrRdrSize( PKLDRRDR pRdr);
248off_t kLdrRdrTell( PKLDRRDR pRdr);
249const char *kLdrRdrName(PKLDRRDR pRdr);
250
251/** @} */
252
253
254
255/** @defgroup grp_kLdrMod kLdrMod - The executable image intepreter
256 * @{ */
257
258/**
259 * Stack information.
260 */
261typedef struct KLDRSTACKINFO
262{
263 /** The base address of the stack (sub) segment, link address.
264 * Set this to ~(uintptr_t)0 if the module doesn't include any stack (sub)segment. */
265 uintmax_t uLinkAddress;
266 /** The base address of the stack (sub) segment, actual load address.
267 * Set this to ~(uintptr_t)0 if the module doesn't include any stack (sub)segment or if
268 * the module isn't mapped (loaded) yet. */
269 uintmax_t uLoadAddress;
270 /** The stack size of the main thread.
271 * If no stack (sub)segment in the module, this is the stack size of the main thread.
272 * If the module doesn't contain this kind of information this field will be set to 0. */
273 uintmax_t cbStack;
274 /** The stack size of non-main threads.
275 * If the module doesn't contain this kind of information this field will be set to 0. */
276 uintmax_t cbStackThread;
277} KLDRSTACKINFO, *PKLDRSTACKINFO;
278
279
280/**
281 * Loader segment.
282 */
283typedef struct KLDRSEG
284{
285 /** Variable free to use for the kLdr user. */
286 void *pvUser;
287 /** The segment name. */
288 const char *pszName;
289 /** The size of the segment. */
290 uintmax_t cb;
291 /** The link time load address. */
292 uintmax_t LinkAddress;
293 /** The actual load address (if loaded). */
294 uintmax_t LoadAddress;
295 /** The segment protection. */
296 KLDRPROT enmProt;
297} KLDRSEG, *PKLDRSEG;
298
299
300/**
301 * Loader module format.
302 */
303typedef enum KLDRFMT
304{
305 /** The usual invalid 0 format. */
306 KLDRFMT_INVALID = 0,
307 /** The native OS loader. */
308 KLDRFMT_NATIVE,
309 /** The AOUT loader. */
310 KLDRFMT_AOUT,
311 /** The ELF loader. */
312 KLDRFMT_ELF,
313 /** The LX loader. */
314 KLDRFMT_LX,
315 /** The mach-o loader. */
316 KLDRFMT_MACHO,
317 /** The LX loader. */
318 KLDRFMT_PE,
319 /** The end of the valid format values (exclusive). */
320 KLDRFMT_END,
321 /** Hack to blow the type up to 32-bit. */
322 KLDRFMT_32BIT_HACK = 0x7fffffff
323} KLDRFMT;
324
325
326/**
327 * Loader module type.
328 */
329typedef enum KLDRTYPE
330{
331 /** The usual invalid 0 type. */
332 KLDRTYPE_INVALID = 0,
333 /** Object file. */
334 KLDRTYPE_OBJECT,
335 /** Executable module, fixed load address. */
336 KLDRTYPE_EXECUTABLE_FIXED,
337 /** Executable module, relocatable, non-fixed load address. */
338 KLDRTYPE_EXECUTABLE_RELOCATABLE,
339 /** Executable module, position independent code, non-fixed load address. */
340 KLDRTYPE_EXECUTABLE_PIC,
341 /** Shared library, fixed load address.
342 * Typically a system library. */
343 KLDRTYPE_SHARED_LIBRARY_FIXED,
344 /** Shared library, relocatable, non-fixed load address. */
345 KLDRTYPE_SHARED_LIBRARY_RELOCATABLE,
346 /** Shared library, position independent code, non-fixed load address. */
347 KLDRTYPE_SHARED_LIBRARY_PIC,
348 /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */
349 KLDRTYPE_FORWARDER_DLL,
350 /** Core or dump. */
351 KLDRTYPE_CORE,
352 /** The end of the valid types values (exclusive). */
353 KLDRTYPE_END,
354 /** Hack to blow the type up to 32-bit. */
355 KLDRTYPE_32BIT_HACK = 0x7fffffff
356} KLDRTYPE;
357
358
359/**
360 * CPU Architecture.
361 * @todo Double check the non intel architectures.
362 */
363typedef enum KLDRARCH
364{
365 /** The usual invalid one. */
366 KLDRARCH_INVALID = 0,
367 /** Clone or Intel 16-bit x86. */
368 KLDRARCH_X86_16,
369 /** Clone or Intel 32-bit x86. */
370 KLDRARCH_X86_32,
371 /** AMD64 (including clones). */
372 KLDRARCH_AMD64,
373 /** Itanic (64-bit). */
374 KLDRARCH_IA64,
375 /** ALPHA (64-bit). */
376 KLDRARCH_ALPHA,
377 /** ALPHA limited to 32-bit. */
378 KLDRARCH_ALPHA_32,
379 /** 32-bit ARM. */
380 KLDRARCH_ARM_32,
381 /** 64-bit ARM. */
382 KLDRARCH_ARM_64,
383 /** 32-bit MIPS. */
384 KLDRARCH_MIPS_32,
385 /** 64-bit MIPS. */
386 KLDRARCH_MIPS_64,
387 /** 32-bit PowerPC. */
388 KLDRARCH_POWERPC_32,
389 /** 64-bit PowerPC. */
390 KLDRARCH_POWERPC_64,
391 /** 32-bit SPARC. */
392 KLDRARCH_SPARC_32,
393 /** 64-bit SPARC. */
394 KLDRARCH_SPARC_64,
395 /** The end of the valid architecture values (exclusive). */
396 KLDRARCH_END,
397 /** Hack to blow the type up to 32-bit. */
398 KLDRARCH_32BIT_HACK = 0x7fffffff
399} KLDRARCH;
400
401/**
402 * CPU models.
403 */
404typedef enum KLDRCPU
405{
406 /** The usual invalid cpu. */
407 KLDRCPU_INVALID = 0,
408 /** @name KLDRARCH_X86_16
409 * @{ */
410 KLDRCPU_I8086,
411 KLDRCPU_I8088,
412 KLDRCPU_I80186,
413 KLDRCPU_I80286,
414 KLDRCPU_I386_16,
415 KLDRCPU_I486_16,
416 KLDRCPU_I486SX_16,
417 KLDRCPU_I586_16,
418 KLDRCPU_I686_16,
419 KLDRCPU_K6_16,
420 KLDRCPU_K7_16,
421 KLDRCPU_K8_16,
422 /** @} */
423
424 /** @name KLDRARCH_X86_32
425 * @{ */
426 KLDRCPU_I386,
427 KLDRCPU_I486,
428 KLDRCPU_I486SX,
429 KLDRCPU_I586,
430 KLDRCPU_I686,
431 KLDRCPU_P4,
432 KLDRCPU_CORE2_32,
433 KLDRCPU_K6,
434 KLDRCPU_K7,
435 KLDRCPU_K8_32,
436 /** @} */
437
438 /** @name KLDRARCH_AMD64
439 * @{ */
440 KLDRCPU_K8,
441 KLDRCPU_P4_64,
442 KLDRCPU_CORE2,
443 /** @} */
444
445 /** The end of the valid cpu values (exclusive). */
446 KLDRCPU_END,
447 /** Hack to blow the type up to 32-bit. */
448 KLDRCPU_32BIT_HACK = 0x7fffffff
449} KLDRCPU;
450
451
452/**
453 * Loader endian indicator.
454 */
455typedef enum KLDRENDIAN
456{
457 /** The usual invalid endian. */
458 KLDRENDIAN_INVALID,
459 /** Little endian. */
460 KLDRENDIAN_LITTLE,
461 /** Bit endian. */
462 KLDRENDIAN_BIG,
463 /** Endianness doesn't have a meaning in the context. */
464 KLDRENDIAN_NA,
465 /** The end of the valid endian values (exclusive). */
466 KLDRENDIAN_END,
467 /** Hack to blow the type up to 32-bit. */
468 KLDRENDIAN_32BIT_HACK = 0x7fffffff
469} KLDRENDIAN;
470
471
472/**
473 * Loader module.
474 */
475typedef struct KLDRMOD
476{
477 /** Magic number. */
478 uint32_t u32Magic;
479 /** The format of this module. */
480 KLDRFMT enmFmt;
481 /** The type of module. */
482 KLDRTYPE enmType;
483 /** The architecture this module was built for. */
484 KLDRARCH enmArch;
485 /** The minium cpu this module was built for.
486 * This might not be accurate, so use kLdrModCanExecuteOn() to check. */
487 KLDRARCH enmCpu;
488 /** The endian used by the module. */
489 KLDRENDIAN enmEndian;
490 /** The filename length (bytes). */
491 uint32_t cchFilename;
492 /** The filename. */
493 const char *pszFilename;
494 /** The module name. */
495 const char *pszName;
496 /** The module name length (bytes). */
497 uint32_t cchName;
498 /** The number of segments in the module. */
499 uint32_t cSegments;
500 /** The module data. */
501 void *pvData;
502 /** Segments. (variable size, can be zero) */
503 KLDRSEG aSegments[1];
504} KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
505
506
507/** Special base address value alias for the link address. */
508#define KLDRMOD_BASEADDRESS_LINK (~(uintmax_t)1)
509/** Special base address value alias for the actual load address (must be mapped). */
510#define KLDRMOD_BASEADDRESS_MAP (~(uintmax_t)2)
511
512/** @name Load symbol kind flags.
513 * @{ */
514/** The bitness doesn't matter. */
515#define KLDRSYMKIND_NO_BIT 0x00000000
516/** 16-bit symbol. */
517#define KLDRSYMKIND_16BIT 0x00000001
518/** 32-bit symbol. */
519#define KLDRSYMKIND_32BIT 0x00000002
520/** 64-bit symbol. */
521#define KLDRSYMKIND_64BIT 0x00000003
522/** Mask out the bit.*/
523#define KLDRSYMKIND_BIT_MASK 0x00000003
524/** We don't know the type of symbol. */
525#define KLDRSYMKIND_NO_TYPE 0x00000000
526/** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
527#define KLDRSYMKIND_CODE 0x00000010
528/** The symbol is a data object. */
529#define KLDRSYMKIND_DATA 0x00000020
530/** Mask out the symbol type. */
531#define KLDRSYMKIND_TYPE_MASK 0x00000030
532/** Valid symbol kind mask. */
533#define KLDRSYMKIND_MASK 0x00000033
534/** @} */
535
536/** @name kLdrModEnumSymbols flags.
537 * @{ */
538/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
539#define KLDRMOD_ENUM_SYMBOL_FLAGS_ALL 0x00000001
540/** @} */
541
542
543typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, const char *pszModule, const char *pszSymbol, uint32_t uSymbol,
544 uintmax_t *pValue, uint32_t *pfKind, void *pvModuleUser, void *pvUser);
545typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
546typedef int FNKLDRMODENUMIMPMODS(PKLDRMOD pMod, const char *pszImpMod, unsigned fFlags, void *pvUser);
547typedef FNKLDRMODENUMIMPMODS *PFNKLDRMODENUMIMPMODS;
548typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, const char *pszSymbol, unsigned uSymbol, uintmax_t Value, uint32_t fKind, void *pvUser);
549typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
550
551int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod);
552int kLdrModClose(PKLDRMOD pMod);
553int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, uint32_t *pfKind);
554int kLdrModEnumSymbols(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, uintmax_t BaseAddress, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
555int kLdrModEnumImportModules(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, FNKLDRMODENUMIMPMODS pfnCallback, void *pvUser);
556int kLdrModMap(PKLDRMOD pMod);
557int kLdrModUnmap(PKLDRMOD pMod);
558int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
559size_t kLdrModSize(PKLDRMOD pMod);
560int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, uintmax_t BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
561int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, uintmax_t NewBaseAddress, uintmax_t OldBaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
562int kLdrModCanExecuteOn(PKLDRMOD pMod, KLDRARCH enmArch, KLDRCPU enmCpu);
563int kLdrModGetStackInfo(PKLDRMOD pMod, PKLDRSTACKINFO pStackInfo);
564
565/** @} */
566
567
568
569
570/** @defgroup grp_kLdrDyld kLdrDyld - The dynamic loader
571 * @{ */
572
573/** The handle to a dynamic loader module. */
574typedef struct KLDRDYLDMOD *HKLDRMOD;
575/** Pointer to the handle to a dynamic loader module. */
576typedef HKLDRMOD *PHKLDRMOD;
577/** NIL handle value. */
578#define NIL_HKLDRMOD ((HKLDRMOD)0)
579
580
581/**
582 * File search method.
583 *
584 * In addition to it's own way of finding files, kLdr emulates
585 * the methods employed by the most popular systems.
586 */
587typedef enum KLDRDYLDSEARCH
588{
589 /** The usual invalid file search method. */
590 KLDRDYLD_SEARCH_INVALID = 0,
591 /** Uses the kLdr file search method.
592 * @todo invent me. */
593 KLDRDYLD_SEARCH_KLDR,
594 /** Use the emulation closest to the host system. */
595 KLDRDYLD_SEARCH_HOST,
596 /** Emulate the OS/2 file search method.
597 * On non-OS/2 systems, BEGINLIBPATH, LIBPATH, ENDLIBPATH and LIBPATHSTRICT are
598 * taken form the environment. */
599 KLDRDYLD_SEARCH_OS2,
600 /** Emulate the standard window file search method. */
601 KLDRDYLD_SEARCH_WINDOWS,
602 /** Emulate the alternative window file search method. */
603 KLDRDYLD_SEARCH_WINDOWS_ALTERED,
604 /** Emulate the most common UNIX file search method. */
605 KLDRDYLD_SEARCH_UNIX_COMMON,
606 /** End of the valid file search method values. */
607 KLDRDYLD_SEARCH_END,
608 /** Hack to blow the type up to 32-bit. */
609 KLDRDYLD_SEARCH_32BIT_HACK = 0x7fffffff
610} KLDRDYLDSEARCH;
611
612/** @name kLdrDyldLoad and kLdrDyldFindByName flags.
613 * @{ */
614/** The symbols in the module should be loaded into the global unix namespace.
615 * If not specified, the symbols are local and can only be referenced directly. */
616#define KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS 0x00000001
617/** The module shouldn't be found by a global module search.
618 * If not specified, the module can be found by unspecified module searches,
619 * typical used when loading import/dep modules. */
620#define KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE 0x00000002
621/** @todo more to come. */
622/** @} */
623
624
625int kLdrDyldLoad(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
626 unsigned fFlags, PHKLDRMOD phMod, char *pszErr, size_t cchErr);
627int kLdrDyldUnload(HKLDRMOD hMod);
628int kLdrDyldFindByName(const char *pszDll, const char *pszDefPrefix, const char *pszDefSuffix, KLDRDYLDSEARCH enmSearch,
629 unsigned fFlags, PHKLDRMOD phMod);
630int kLdrDyldFindByAddress(uintptr_t Address, PHKLDRMOD phMod, uint32_t *piSegment, uintptr_t *poffSegment);
631int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, size_t cchName);
632int kLdrDyldGetFilename(HKLDRMOD hMod, char *pszFilename, size_t cchFilename);
633int kLdrDyldQuerySymbol(HKLDRMOD hMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind);
634
635/** @name OS/2 like API
636 * @{ */
637int kLdrDosLoadModule(char *pszObject, size_t cbObject, const char *pszModule, PHKLDRMOD phMod);
638int kLdrDosFreeModule(HKLDRMOD hMod);
639int kLdrDosQueryModuleHandle(const char *pszModname, PHKLDRMOD phMod);
640int kLdrDosQueryModuleName(HKLDRMOD hMod, size_t cchName, char *pszName);
641int kLdrDosQueryProcAddr(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, void **ppvProcAddr);
642int kLdrDosQueryProcType(HKLDRMOD hMod, uint32_t iOrdinal, const char *pszProcName, uint32_t *pfProcType);
643int kLdrDosQueryModFromEIP(PHKLDRMOD phMod, uint32_t *piObject, size_t cbName, char *pszName, uintptr_t *poffObject, uintptr_t ulEIP);
644int kLdrDosReplaceModule(const char *pszOldModule, const char *pszNewModule, const char *pszBackupModule);
645int kLdrDosGetResource(HKLDRMOD hMod, uint32_t idType, uint32_t idName, void **pvResAddr);
646int kLdrDosQueryResourceSize(HKLDRMOD hMod, uint32_t idTypeID, uint32_t idName, uint32_t *pcb);
647int kLdrDosFreeResource(void *pvResAddr);
648/** @} */
649
650/** @name POSIX like API
651 * @{ */
652HKLDRMOD kLdrDlOpen(const char *pszLibrary, int fFlags);
653const char *kLdrDlError(void);
654void * kLdrDlSym(HKLDRMOD hMod, const char *pszSymbol);
655int kLdrDlClose(HKLDRMOD hMod);
656/** @} */
657
658/** @name Win32 like API
659 * @{ */
660HKLDRMOD kLdrWLoadLibrary(const char *pszFilename);
661HKLDRMOD kLdrWLoadLibraryEx(const char *pszFilename, void *hFileReserved, uint32_t fFlags);
662uint32_t kLdrWGetModuleFileName(HKLDRMOD hMod, char *pszModName, size_t cchModName);
663HKLDRMOD kLdrWGetModuleHandle(const char *pszFilename);
664int kLdrWGetModuleHandleEx(uint32_t fFlags, const char *pszFilename, HKLDRMOD hMod);
665void * kLdrWGetProcAddress(HKLDRMOD hMod, const char *pszProcName);
666uint32_t kLdrWGetDllDirectory(size_t cchDir, char *pszDir);
667int kLdrWSetDllDirectory(const char *pszDir);
668int kLdrWFreeLibrary(HKLDRMOD hMod);
669int kLdrWDisableThreadLibraryCalls(HKLDRMOD hMod);
670
671/** @} */
672
673
674/** @name Process Bootstrapping
675 * @{ */
676
677/**
678 * Argument package from the stub.
679 */
680typedef struct KLDREXEARGS
681{
682 /** Flags. (Currently unused, MBZ.) */
683 uint32_t fFlags;
684 /** The executable file that the stub is supposed to load. */
685 char szExecutable[260];
686 /** The LD_LIBRARY_PATH prefix for the process.. */
687 char szLibPath[4096 - 260 - sizeof(uint32_t)];
688} KLDREXEARGS, *PKLDREXEARGS;
689
690void kLdrLoadExe(PKLDREXEARGS pArgs, void *pvOS);
691
692/** @} */
693
694/** @} */
695
696
697/** @defgroup grp_kLdrErr kLdr Status Codes
698 * kLdr uses a mix of native status codes and it's own status codes.
699 * A status code of 0 means success, all other status codes means failure.
700 * @{
701 */
702#ifdef __OS2__
703# define KLDR_ERR_BASE 0x7face000
704#elif defined(__WIN__)
705# define KLDR_ERR_BASE 0x7face000
706#else
707# error "port me"
708#endif
709/** The image format is unknown. */
710#define KLDR_ERR_UNKNOWN_FORMAT (KLDR_ERR_BASE + 0)
711/** The MZ image format isn't supported by this kLdr build. */
712#define KLDR_ERR_MZ_NOT_SUPPORTED (KLDR_ERR_BASE + 1)
713/** The NE image format isn't supported by this kLdr build. */
714#define KLDR_ERR_NE_NOT_SUPPORTED (KLDR_ERR_BASE + 2)
715/** The LX image format isn't supported by this kLdr build. */
716#define KLDR_ERR_LX_NOT_SUPPORTED (KLDR_ERR_BASE + 3)
717/** The LE image format isn't supported by this kLdr build. */
718#define KLDR_ERR_LE_NOT_SUPPORTED (KLDR_ERR_BASE + 4)
719/** The PE image format isn't supported by this kLdr build. */
720#define KLDR_ERR_PE_NOT_SUPPORTED (KLDR_ERR_BASE + 5)
721/** The ELF image format isn't supported by this kLdr build. */
722#define KLDR_ERR_ELF_NOT_SUPPORTED (KLDR_ERR_BASE + 6)
723/** The mach-o image format isn't supported by this kLdr build. */
724#define KLDR_ERR_MACHO_NOT_SUPPORTED (KLDR_ERR_BASE + 7)
725/** The mach-o image format isn't supported by this kLdr build. */
726#define KLDR_ERR_AOUT_NOT_SUPPORTED (KLDR_ERR_BASE + 8)
727
728/** Invalid parameter to a kLdr API. */
729#define KLDR_ERR_INVALID_PARAMETER (KLDR_ERR_BASE + 32)
730/** Invalid handle parameter to a kLdr API. */
731#define KLDR_ERR_INVALID_HANDLE (KLDR_ERR_BASE + 33)
732/** The module wasn't found. */
733#define KLDR_ERR_MODULE_NOT_FOUND (KLDR_ERR_BASE + 34)
734
735/** Encountered a bad fixup. */
736#define KLDR_ERR_BAD_FIXUP (KLDR_ERR_BASE + 48)
737
738/** @} */
739
740
741#ifdef __cplusplus
742}
743#endif
744
745#endif
746
Note: See TracBrowser for help on using the repository browser.