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