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