[2] | 1 | /* $Id: kLdr.h 117 2020-03-15 15:23:36Z bird $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * kLdr - The Dynamic Loader.
|
---|
[29] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
|
---|
[2] | 8 | *
|
---|
[29] | 9 | * Permission is hereby granted, free of charge, to any person
|
---|
| 10 | * obtaining a copy of this software and associated documentation
|
---|
| 11 | * files (the "Software"), to deal in the Software without
|
---|
| 12 | * restriction, including without limitation the rights to use,
|
---|
| 13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
| 14 | * copies of the Software, and to permit persons to whom the
|
---|
| 15 | * Software is furnished to do so, subject to the following
|
---|
| 16 | * conditions:
|
---|
[2] | 17 | *
|
---|
[29] | 18 | * The above copyright notice and this permission notice shall be
|
---|
| 19 | * included in all copies or substantial portions of the Software.
|
---|
[2] | 20 | *
|
---|
[29] | 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
---|
| 22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
---|
| 23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
---|
| 24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
---|
| 25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
| 26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
| 27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
| 28 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
[2] | 29 | */
|
---|
| 30 |
|
---|
| 31 | #ifndef ___k_kLdr_h___
|
---|
| 32 | #define ___k_kLdr_h___
|
---|
| 33 |
|
---|
| 34 | #ifdef __cplusplus
|
---|
| 35 | extern "C" {
|
---|
| 36 | #endif
|
---|
| 37 |
|
---|
| 38 | /*
|
---|
| 39 | * Include the base typedefs and macros.
|
---|
| 40 | */
|
---|
| 41 | #include <k/kDefs.h>
|
---|
| 42 | #include <k/kTypes.h>
|
---|
| 43 | #include <k/kCpus.h>
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | /** @defgroup grp_kLdrBasic kLdr Basic Types
|
---|
| 47 | * @{ */
|
---|
| 48 |
|
---|
| 49 | /** The kLdr address type. */
|
---|
| 50 | typedef KU64 KLDRADDR;
|
---|
| 51 | /** Pointer to a kLdr address. */
|
---|
| 52 | typedef KLDRADDR *PKLDRADDR;
|
---|
| 53 | /** Pointer to a const kLdr address. */
|
---|
| 54 | typedef const KLDRADDR *PCKLDRADDR;
|
---|
| 55 |
|
---|
| 56 | /** NIL address. */
|
---|
| 57 | #define NIL_KLDRADDR (~(KU64)0)
|
---|
| 58 |
|
---|
| 59 | /** @def PRI_KLDRADDR
|
---|
| 60 | * printf format type. */
|
---|
| 61 | #ifdef _MSC_VER
|
---|
| 62 | # define PRI_KLDRADDR "I64x"
|
---|
| 63 | #else
|
---|
| 64 | # define PRI_KLDRADDR "llx"
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | /** Align a KSIZE value. */
|
---|
| 68 | #define KLDR_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KLDRADDR)((align) - 1) )
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | /** The kLdr size type. */
|
---|
| 72 | typedef KU64 KLDRSIZE;
|
---|
| 73 | /** Pointer to a kLdr size. */
|
---|
| 74 | typedef KLDRSIZE *PKLDRSIZE;
|
---|
| 75 | /** Pointer to a const kLdr size. */
|
---|
| 76 | typedef const KLDRSIZE *PCKLDRSIZE;
|
---|
| 77 |
|
---|
| 78 | /** @def PRI_KLDRSIZE
|
---|
| 79 | * printf format type. */
|
---|
| 80 | #ifdef _MSC_VER
|
---|
| 81 | # define PRI_KLDRSIZE "I64x"
|
---|
| 82 | #else
|
---|
| 83 | # define PRI_KLDRSIZE "llx"
|
---|
| 84 | #endif
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | /** The kLdr file offset type. */
|
---|
| 88 | typedef long KLDRFOFF;
|
---|
| 89 | /** Pointer to a kLdr file offset type. */
|
---|
| 90 | typedef KLDRFOFF *PKLDRFOFF;
|
---|
| 91 | /** Pointer to a const kLdr file offset type. */
|
---|
| 92 | typedef const KLDRFOFF *PCKLDRFOFF;
|
---|
| 93 |
|
---|
| 94 | /** @def PRI_KLDRFOFF
|
---|
| 95 | * printf format type. */
|
---|
| 96 | #define PRI_KLDRFOFF "lx"
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * Union of all the integer types.
|
---|
| 101 | */
|
---|
| 102 | typedef union KLDRU
|
---|
| 103 | {
|
---|
| 104 | KI8 i8; /**< KI8 view. */
|
---|
| 105 | KU8 u8; /**< KU8 view. */
|
---|
| 106 | KI16 i16; /**< KI16 view. */
|
---|
| 107 | KU16 u16; /**< KU16 view. */
|
---|
| 108 | KI32 i32; /**< KI32 view. */
|
---|
| 109 | KU32 u32; /**< KU32 view. */
|
---|
| 110 | KI64 i64; /**< KI64 view. */
|
---|
| 111 | KU64 u64; /**< KU64 view. */
|
---|
| 112 |
|
---|
| 113 | KI8 ai8[8]; /**< KI8 array view . */
|
---|
| 114 | KU8 au8[8]; /**< KU8 array view. */
|
---|
| 115 | KI16 ai16[4];/**< KI16 array view . */
|
---|
| 116 | KU16 au16[4];/**< KU16 array view. */
|
---|
| 117 | KI32 ai32[2];/**< KI32 array view . */
|
---|
| 118 | KU32 au32[2];/**< KU32 array view. */
|
---|
| 119 |
|
---|
| 120 | signed char ch; /**< signed char view. */
|
---|
| 121 | unsigned char uch; /**< unsigned char view. */
|
---|
| 122 | signed short s; /**< signed short view. */
|
---|
| 123 | unsigned short us; /**< unsigned short view. */
|
---|
| 124 | signed int i; /**< signed int view. */
|
---|
| 125 | unsigned int u; /**< unsigned int view. */
|
---|
| 126 | signed long l; /**< signed long view. */
|
---|
| 127 | unsigned long ul; /**< unsigned long view. */
|
---|
| 128 | void *pv; /**< void pointer view. */
|
---|
| 129 |
|
---|
| 130 | KLDRADDR Addr; /**< kLdr address view. */
|
---|
| 131 | KLDRSIZE Size; /**< kLdr size view. */
|
---|
| 132 | } KLDRU;
|
---|
| 133 | /** Pointer to an integer union. */
|
---|
| 134 | typedef KLDRU *PKLDRU;
|
---|
| 135 | /** Pointer to a const integer union. */
|
---|
| 136 | typedef const KLDRU *PCKLDRU;
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
| 140 | * Union of pointers to all the integer types.
|
---|
| 141 | */
|
---|
| 142 | typedef union KLDRPU
|
---|
| 143 | {
|
---|
| 144 | KI8 *pi8; /**< KI8 view. */
|
---|
| 145 | KU8 *pu8; /**< KU8 view. */
|
---|
| 146 | KI16 *pi16; /**< KI16 view. */
|
---|
| 147 | KU16 *pu16; /**< KU16 view. */
|
---|
| 148 | KI32 *pi32; /**< KI32 view. */
|
---|
| 149 | KU32 *pu32; /**< KU32 view. */
|
---|
| 150 | KI64 *pi64; /**< KI64 view. */
|
---|
| 151 | KU64 *pu64; /**< KU64 view. */
|
---|
| 152 |
|
---|
| 153 | signed char *pch; /**< signed char view. */
|
---|
| 154 | unsigned char *puch; /**< unsigned char view. */
|
---|
| 155 | signed short *ps; /**< signed short view. */
|
---|
| 156 | unsigned short *pus; /**< unsigned short view. */
|
---|
| 157 | signed int *pi; /**< signed int view. */
|
---|
| 158 | unsigned int *pu; /**< unsigned int view. */
|
---|
| 159 | signed long *pl; /**< signed long view. */
|
---|
| 160 | unsigned long *pul; /**< unsigned long view. */
|
---|
| 161 | void *pv; /**< void pointer view. */
|
---|
| 162 | } KLDRPU;
|
---|
| 163 | /** Pointer to an integer pointer union. */
|
---|
| 164 | typedef KLDRPU *PKLDRPU;
|
---|
| 165 | /** Pointer to a const integer pointer union. */
|
---|
| 166 | typedef const KLDRPU *PCKLDRPU;
|
---|
| 167 |
|
---|
| 168 | /** @} */
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 | /** @defgroup grp_kLdrMod kLdrMod - The executable image intepreter
|
---|
| 172 | * @{ */
|
---|
| 173 |
|
---|
| 174 | /**
|
---|
| 175 | * Debug info type (from the loader point of view).
|
---|
| 176 | */
|
---|
| 177 | typedef enum KLDRDBGINFOTYPE
|
---|
| 178 | {
|
---|
| 179 | /** The usual invalid enum value. */
|
---|
| 180 | KLDRDBGINFOTYPE_INVALID = 0,
|
---|
| 181 | /** Unknown debug info format. */
|
---|
| 182 | KLDRDBGINFOTYPE_UNKNOWN,
|
---|
| 183 | /** Stabs. */
|
---|
| 184 | KLDRDBGINFOTYPE_STABS,
|
---|
| 185 | /** Debug With Arbitrary Record Format (DWARF). */
|
---|
| 186 | KLDRDBGINFOTYPE_DWARF,
|
---|
| 187 | /** Microsoft Codeview debug info. */
|
---|
| 188 | KLDRDBGINFOTYPE_CODEVIEW,
|
---|
| 189 | /** Watcom debug info. */
|
---|
| 190 | KLDRDBGINFOTYPE_WATCOM,
|
---|
| 191 | /** IBM High Level Language debug info.. */
|
---|
| 192 | KLDRDBGINFOTYPE_HLL,
|
---|
| 193 | /** The end of the valid debug info values (exclusive). */
|
---|
| 194 | KLDRDBGINFOTYPE_END,
|
---|
| 195 | /** Blow the type up to 32-bit. */
|
---|
| 196 | KLDRDBGINFOTYPE_32BIT_HACK = 0x7fffffff
|
---|
| 197 | } KLDRDBGINFOTYPE;
|
---|
| 198 | /** Pointer to a kLdr debug info type. */
|
---|
| 199 | typedef KLDRDBGINFOTYPE *PKLDRDBGINFOTYPE;
|
---|
| 200 |
|
---|
| 201 |
|
---|
| 202 | /**
|
---|
| 203 | * Stack information.
|
---|
| 204 | */
|
---|
| 205 | typedef struct KLDRSTACKINFO
|
---|
| 206 | {
|
---|
| 207 | /** The base address of the stack (sub) segment.
|
---|
| 208 | * Set this to NIL_KLDRADDR if the module doesn't include any stack segment. */
|
---|
| 209 | KLDRADDR Address;
|
---|
| 210 | /** The base address of the stack (sub) segment, link address.
|
---|
| 211 | * Set this to NIL_KLDRADDR if the module doesn't include any stack (sub)segment. */
|
---|
| 212 | KLDRADDR LinkAddress;
|
---|
| 213 | /** The stack size of the main thread.
|
---|
| 214 | * If no stack (sub)segment in the module, this is the stack size of the main thread.
|
---|
| 215 | * If the module doesn't contain this kind of information this field will be set to 0. */
|
---|
| 216 | KLDRSIZE cbStack;
|
---|
| 217 | /** The stack size of non-main threads.
|
---|
| 218 | * If the module doesn't contain this kind of information this field will be set to 0. */
|
---|
| 219 | KLDRSIZE cbStackThread;
|
---|
| 220 | } KLDRSTACKINFO;
|
---|
| 221 | /** Pointer to stack information. */
|
---|
| 222 | typedef KLDRSTACKINFO *PKLDRSTACKINFO;
|
---|
| 223 | /** Pointer to const stack information. */
|
---|
| 224 | typedef const KLDRSTACKINFO *PCKLDRSTACKINFO;
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 | /**
|
---|
| 228 | * Loader segment.
|
---|
| 229 | */
|
---|
| 230 | typedef struct KLDRSEG
|
---|
| 231 | {
|
---|
| 232 | /** Variable free to use for the kLdr user. */
|
---|
| 233 | void *pvUser;
|
---|
| 234 | /** The segment name. (Might not be zero terminated!) */
|
---|
| 235 | const char *pchName;
|
---|
| 236 | /** The length of the segment name. */
|
---|
| 237 | KU32 cchName;
|
---|
| 238 | /** The flat selector to use for the segment (i.e. data/code).
|
---|
| 239 | * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
|
---|
| 240 | KU16 SelFlat;
|
---|
| 241 | /** The 16-bit selector to use for the segment.
|
---|
| 242 | * Primarily a way for the user to specify selectors for the LX/LE and NE interpreters. */
|
---|
| 243 | KU16 Sel16bit;
|
---|
| 244 | /** Segment flags. */
|
---|
| 245 | KU32 fFlags;
|
---|
| 246 | /** The segment protection. */
|
---|
[19] | 247 | KPROT enmProt;
|
---|
[2] | 248 | /** The size of the segment. */
|
---|
| 249 | KLDRSIZE cb;
|
---|
| 250 | /** The required segment alignment.
|
---|
| 251 | * The to 0 if the segment isn't supposed to be mapped. */
|
---|
| 252 | KLDRADDR Alignment;
|
---|
| 253 | /** The link address.
|
---|
| 254 | * Set to NIL_KLDRADDR if the segment isn't supposed to be
|
---|
| 255 | * mapped or if the image doesn't have link addresses. */
|
---|
| 256 | KLDRADDR LinkAddress;
|
---|
| 257 | /** File offset of the segment.
|
---|
| 258 | * Set to -1 if no file backing (like BSS). */
|
---|
| 259 | KLDRFOFF offFile;
|
---|
| 260 | /** Size of the file bits of the segment.
|
---|
| 261 | * Set to -1 if no file backing (like BSS). */
|
---|
| 262 | KLDRFOFF cbFile;
|
---|
| 263 | /** The relative virtual address when mapped.
|
---|
| 264 | * Set to NIL_KLDRADDR if the segment isn't supposed to be mapped. */
|
---|
| 265 | KLDRADDR RVA;
|
---|
| 266 | /** The size of the segment including the alignment gap up to the next segment when mapped. */
|
---|
| 267 | KSIZE cbMapped;
|
---|
| 268 | /** The address the segment was mapped at by kLdrModMap().
|
---|
| 269 | * Set to 0 if not mapped. */
|
---|
| 270 | KUPTR MapAddress;
|
---|
| 271 | } KLDRSEG;
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 | /** @name Segment flags
|
---|
| 275 | * @{ */
|
---|
| 276 | /** The segment is 16-bit. When not set the default of the target architecture is assumed. */
|
---|
| 277 | #define KLDRSEG_FLAG_16BIT 1
|
---|
| 278 | /** The segment requires a 16-bit selector alias. (OS/2) */
|
---|
| 279 | #define KLDRSEG_FLAG_OS2_ALIAS16 2
|
---|
| 280 | /** Conforming segment (x86 weirdness). (OS/2) */
|
---|
| 281 | #define KLDRSEG_FLAG_OS2_CONFORM 4
|
---|
| 282 | /** IOPL (ring-2) segment. (OS/2) */
|
---|
| 283 | #define KLDRSEG_FLAG_OS2_IOPL 8
|
---|
| 284 | /** @} */
|
---|
| 285 |
|
---|
| 286 |
|
---|
| 287 | /**
|
---|
| 288 | * Loader module format.
|
---|
| 289 | */
|
---|
| 290 | typedef enum KLDRFMT
|
---|
| 291 | {
|
---|
| 292 | /** The usual invalid 0 format. */
|
---|
| 293 | KLDRFMT_INVALID = 0,
|
---|
| 294 | /** The native OS loader. */
|
---|
| 295 | KLDRFMT_NATIVE,
|
---|
| 296 | /** The AOUT loader. */
|
---|
| 297 | KLDRFMT_AOUT,
|
---|
| 298 | /** The ELF loader. */
|
---|
| 299 | KLDRFMT_ELF,
|
---|
| 300 | /** The LX loader. */
|
---|
| 301 | KLDRFMT_LX,
|
---|
| 302 | /** The Mach-O loader. */
|
---|
| 303 | KLDRFMT_MACHO,
|
---|
| 304 | /** The PE loader. */
|
---|
| 305 | KLDRFMT_PE,
|
---|
| 306 | /** The end of the valid format values (exclusive). */
|
---|
| 307 | KLDRFMT_END,
|
---|
| 308 | /** Hack to blow the type up to 32-bit. */
|
---|
| 309 | KLDRFMT_32BIT_HACK = 0x7fffffff
|
---|
| 310 | } KLDRFMT;
|
---|
| 311 |
|
---|
| 312 |
|
---|
| 313 | /**
|
---|
| 314 | * Loader module type.
|
---|
| 315 | */
|
---|
| 316 | typedef enum KLDRTYPE
|
---|
| 317 | {
|
---|
| 318 | /** The usual invalid 0 type. */
|
---|
| 319 | KLDRTYPE_INVALID = 0,
|
---|
| 320 | /** Object file. */
|
---|
| 321 | KLDRTYPE_OBJECT,
|
---|
| 322 | /** Executable module, fixed load address. */
|
---|
| 323 | KLDRTYPE_EXECUTABLE_FIXED,
|
---|
| 324 | /** Executable module, relocatable, non-fixed load address. */
|
---|
| 325 | KLDRTYPE_EXECUTABLE_RELOCATABLE,
|
---|
| 326 | /** Executable module, position independent code, non-fixed load address. */
|
---|
| 327 | KLDRTYPE_EXECUTABLE_PIC,
|
---|
| 328 | /** Shared library, fixed load address.
|
---|
| 329 | * Typically a system library. */
|
---|
| 330 | KLDRTYPE_SHARED_LIBRARY_FIXED,
|
---|
| 331 | /** Shared library, relocatable, non-fixed load address. */
|
---|
| 332 | KLDRTYPE_SHARED_LIBRARY_RELOCATABLE,
|
---|
| 333 | /** Shared library, position independent code, non-fixed load address. */
|
---|
| 334 | KLDRTYPE_SHARED_LIBRARY_PIC,
|
---|
| 335 | /** DLL that contains no code or data only imports and exports. (Chiefly OS/2.) */
|
---|
| 336 | KLDRTYPE_FORWARDER_DLL,
|
---|
| 337 | /** Core or dump. */
|
---|
| 338 | KLDRTYPE_CORE,
|
---|
[41] | 339 | /** Debug module (debug info with empty code & data segments). */
|
---|
| 340 | KLDRTYPE_DEBUG_INFO,
|
---|
[2] | 341 | /** The end of the valid types values (exclusive). */
|
---|
| 342 | KLDRTYPE_END,
|
---|
| 343 | /** Hack to blow the type up to 32-bit. */
|
---|
| 344 | KLDRTYPE_32BIT_HACK = 0x7fffffff
|
---|
| 345 | } KLDRTYPE;
|
---|
| 346 |
|
---|
| 347 |
|
---|
| 348 | /**
|
---|
| 349 | * Loader endian indicator.
|
---|
| 350 | */
|
---|
| 351 | typedef enum KLDRENDIAN
|
---|
| 352 | {
|
---|
| 353 | /** The usual invalid endian. */
|
---|
| 354 | KLDRENDIAN_INVALID,
|
---|
| 355 | /** Little endian. */
|
---|
| 356 | KLDRENDIAN_LITTLE,
|
---|
| 357 | /** Bit endian. */
|
---|
| 358 | KLDRENDIAN_BIG,
|
---|
| 359 | /** Endianness doesn't have a meaning in the context. */
|
---|
| 360 | KLDRENDIAN_NA,
|
---|
| 361 | /** The end of the valid endian values (exclusive). */
|
---|
| 362 | KLDRENDIAN_END,
|
---|
| 363 | /** Hack to blow the type up to 32-bit. */
|
---|
| 364 | KLDRENDIAN_32BIT_HACK = 0x7fffffff
|
---|
| 365 | } KLDRENDIAN;
|
---|
| 366 |
|
---|
| 367 |
|
---|
[58] | 368 | /** @name KLDRMOD::fFlags
|
---|
| 369 | * @{ */
|
---|
| 370 | /** The link address doesn't form a contiguous image, from the first to the
|
---|
| 371 | * last segment. */
|
---|
| 372 | #define KLDRMOD_FLAGS_NON_CONTIGUOUS_LINK_ADDRS K_BIT32(0)
|
---|
| 373 | /** @} */
|
---|
| 374 |
|
---|
[2] | 375 | /** Pointer to a module interpreter method table. */
|
---|
| 376 | typedef struct KLDRMODOPS *PKLDRMODOPS;
|
---|
| 377 | /** Pointer to const module interpreter methods table. */
|
---|
| 378 | typedef const struct KLDRMODOPS *PCKLDRMODOPS;
|
---|
| 379 |
|
---|
| 380 | /**
|
---|
| 381 | * Module interpreter instance.
|
---|
| 382 | * All members are read only unless you're kLdrMod or the module interpreter.
|
---|
| 383 | */
|
---|
| 384 | typedef struct KLDRMOD
|
---|
| 385 | {
|
---|
| 386 | /** Magic number (KLDRMOD_MAGIC). */
|
---|
| 387 | KU32 u32Magic;
|
---|
| 388 | /** The format of this module. */
|
---|
| 389 | KLDRFMT enmFmt;
|
---|
| 390 | /** The type of module. */
|
---|
| 391 | KLDRTYPE enmType;
|
---|
| 392 | /** The CPU architecture this module was built for. */
|
---|
| 393 | KCPUARCH enmArch;
|
---|
| 394 | /** The minium cpu this module was built for.
|
---|
| 395 | * This might not be accurate, so use kLdrModCanExecuteOn() to check. */
|
---|
| 396 | KCPU enmCpu;
|
---|
| 397 | /** The endian used by the module. */
|
---|
| 398 | KLDRENDIAN enmEndian;
|
---|
[117] | 399 | /** Module open flags, KLDRMOD_OPEN_FLAGS_XXX. */
|
---|
[58] | 400 | KU32 fFlags;
|
---|
[2] | 401 | /** The filename length (bytes). */
|
---|
| 402 | KU32 cchFilename;
|
---|
| 403 | /** The filename. */
|
---|
| 404 | const char *pszFilename;
|
---|
| 405 | /** The module name. */
|
---|
| 406 | const char *pszName;
|
---|
| 407 | /** The module name length (bytes). */
|
---|
| 408 | KU32 cchName;
|
---|
| 409 | /** The number of segments in the module. */
|
---|
| 410 | KU32 cSegments;
|
---|
| 411 | /** Pointer to the loader methods.
|
---|
| 412 | * Not meant for calling directly thru! */
|
---|
| 413 | PCKLDRMODOPS pOps;
|
---|
| 414 | /** Pointer to the read instance. (Can be NULL after kLdrModDone().)*/
|
---|
| 415 | PKRDR pRdr;
|
---|
| 416 | /** The module data. */
|
---|
| 417 | void *pvData;
|
---|
| 418 | /** Segments. (variable size, can be zero) */
|
---|
| 419 | KLDRSEG aSegments[1];
|
---|
| 420 | } KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
|
---|
| 421 |
|
---|
| 422 | /** The magic for KLDRMOD::u32Magic. (Kosuke Fujishima) */
|
---|
| 423 | #define KLDRMOD_MAGIC 0x19640707
|
---|
| 424 |
|
---|
| 425 |
|
---|
| 426 | /** Special base address value alias for the link address. */
|
---|
| 427 | #define KLDRMOD_BASEADDRESS_LINK (~(KLDRADDR)1)
|
---|
| 428 | /** Special base address value alias for the actual load address (must be mapped). */
|
---|
| 429 | #define KLDRMOD_BASEADDRESS_MAP (~(KLDRADDR)2)
|
---|
| 430 |
|
---|
| 431 | /** Special import module ordinal value used to indicate that there is no
|
---|
| 432 | * specific module associated with the requested symbol. */
|
---|
| 433 | #define NIL_KLDRMOD_IMPORT (~(KU32)0)
|
---|
| 434 |
|
---|
| 435 | /** Special symbol ordinal value used to indicate that the symbol
|
---|
| 436 | * only has a string name. */
|
---|
| 437 | #define NIL_KLDRMOD_SYM_ORDINAL (~(KU32)0)
|
---|
| 438 |
|
---|
| 439 |
|
---|
| 440 | /** @name Load symbol kind flags.
|
---|
| 441 | * @{ */
|
---|
| 442 | /** The bitness doesn't matter. */
|
---|
| 443 | #define KLDRSYMKIND_NO_BIT 0x00000000
|
---|
| 444 | /** 16-bit symbol. */
|
---|
| 445 | #define KLDRSYMKIND_16BIT 0x00000001
|
---|
| 446 | /** 32-bit symbol. */
|
---|
| 447 | #define KLDRSYMKIND_32BIT 0x00000002
|
---|
| 448 | /** 64-bit symbol. */
|
---|
| 449 | #define KLDRSYMKIND_64BIT 0x00000003
|
---|
| 450 | /** Mask out the bit.*/
|
---|
| 451 | #define KLDRSYMKIND_BIT_MASK 0x00000003
|
---|
| 452 | /** We don't know the type of symbol. */
|
---|
| 453 | #define KLDRSYMKIND_NO_TYPE 0x00000000
|
---|
| 454 | /** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
|
---|
| 455 | #define KLDRSYMKIND_CODE 0x00000010
|
---|
| 456 | /** The symbol is a data object. */
|
---|
| 457 | #define KLDRSYMKIND_DATA 0x00000020
|
---|
| 458 | /** Mask out the symbol type. */
|
---|
| 459 | #define KLDRSYMKIND_TYPE_MASK 0x00000030
|
---|
| 460 | /** Valid symbol kind mask. */
|
---|
| 461 | #define KLDRSYMKIND_MASK 0x00000033
|
---|
| 462 | /** Weak symbol. */
|
---|
| 463 | #define KLDRSYMKIND_WEAK 0x00000100
|
---|
| 464 | /** Forwarder symbol. */
|
---|
| 465 | #define KLDRSYMKIND_FORWARDER 0x00000200
|
---|
| 466 | /** Request a flat symbol address. */
|
---|
| 467 | #define KLDRSYMKIND_REQ_FLAT 0x00000000
|
---|
| 468 | /** Request a segmented symbol address. */
|
---|
| 469 | #define KLDRSYMKIND_REQ_SEGMENTED 0x40000000
|
---|
| 470 | /** Request type mask. */
|
---|
| 471 | #define KLDRSYMKIND_REQ_TYPE_MASK 0x40000000
|
---|
| 472 | /** @} */
|
---|
| 473 |
|
---|
| 474 | /** @name kLdrModEnumSymbols flags.
|
---|
| 475 | * @{ */
|
---|
| 476 | /** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
|
---|
| 477 | #define KLDRMOD_ENUM_SYMS_FLAGS_ALL 0x00000001
|
---|
| 478 | /** @} */
|
---|
| 479 |
|
---|
| 480 |
|
---|
| 481 | /**
|
---|
| 482 | * Callback for resolving imported symbols when applying fixups.
|
---|
| 483 | *
|
---|
| 484 | * @returns 0 on success and *pValue and *pfKind filled.
|
---|
| 485 | * @returns Non-zero OS specific or kLdr status code on failure.
|
---|
| 486 | *
|
---|
| 487 | * @param pMod The module which fixups are begin applied.
|
---|
| 488 | * @param iImport The import module ordinal number or NIL_KLDRMOD_IMPORT.
|
---|
| 489 | * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
|
---|
| 490 | * @param pchSymbol The symbol name. Can be NULL if iSymbol isn't nil. Doesn't have to be null-terminated.
|
---|
| 491 | * @param cchSymbol The length of the symbol.
|
---|
| 492 | * @param pszVersion The symbol version. NULL if not versioned.
|
---|
| 493 | * @param puValue Where to store the symbol value.
|
---|
| 494 | * @param pfKind Where to store the symbol kind flags.
|
---|
| 495 | * @param pvUser The user parameter specified to the relocation function.
|
---|
| 496 | */
|
---|
| 497 | typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, KU32 iImport, KU32 iSymbol, const char *pchSymbol, KSIZE cchSymbol,
|
---|
| 498 | const char *pszVersion, PKLDRADDR puValue, KU32 *pfKind, void *pvUser);
|
---|
| 499 | /** Pointer to a import callback. */
|
---|
| 500 | typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
|
---|
| 501 |
|
---|
| 502 | /**
|
---|
| 503 | * Symbol enumerator callback.
|
---|
| 504 | *
|
---|
| 505 | * @returns 0 if enumeration should continue.
|
---|
| 506 | * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumSymbols().
|
---|
| 507 | *
|
---|
| 508 | * @param pMod The module which symbols are being enumerated.s
|
---|
| 509 | * @param iSymbol The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
|
---|
| 510 | * @param pchSymbol The symbol name. This can be NULL if there is a symbol ordinal.
|
---|
| 511 | * This can also be an empty string if the symbol doesn't have a name
|
---|
| 512 | * or it's name has been stripped.
|
---|
| 513 | * Important, this doesn't have to be a null-terminated string.
|
---|
| 514 | * @param cchSymbol The length of the symbol.
|
---|
| 515 | * @param pszVersion The symbol version. NULL if not versioned.
|
---|
| 516 | * @param uValue The symbol value.
|
---|
| 517 | * @param fKind The symbol kind flags.
|
---|
| 518 | * @param pvUser The user parameter specified to kLdrModEnumSymbols().
|
---|
| 519 | */
|
---|
| 520 | typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, KU32 iSymbol, const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
|
---|
| 521 | KLDRADDR uValue, KU32 fKind, void *pvUser);
|
---|
| 522 | /** Pointer to a symbol enumerator callback. */
|
---|
| 523 | typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
|
---|
| 524 |
|
---|
| 525 | /**
|
---|
| 526 | * Debug info enumerator callback.
|
---|
| 527 | *
|
---|
| 528 | * @returns 0 to continue the enumeration.
|
---|
| 529 | * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumDbgInfo().
|
---|
| 530 | *
|
---|
| 531 | * @param pMod The module.
|
---|
| 532 | * @param iDbgInfo The debug info ordinal number / id.
|
---|
| 533 | * @param enmType The debug info type.
|
---|
| 534 | * @param iMajorVer The major version number of the debug info format. -1 if unknow - implies invalid iMinorVer.
|
---|
| 535 | * @param iMinorVer The minor version number of the debug info format. -1 when iMajorVer is -1.
|
---|
[41] | 536 | * @param pszPartNm The name of the debug info part, NULL if not applicable.
|
---|
[2] | 537 | * @param offFile The file offset *if* this type has one specific location in the executable image file.
|
---|
| 538 | * This is -1 if there isn't any specific file location.
|
---|
| 539 | * @param LinkAddress The link address of the debug info if it's loadable. NIL_KLDRADDR if not loadable.
|
---|
| 540 | * @param cb The size of the debug information. -1 is used if this isn't applicable.
|
---|
| 541 | * @param pszExtFile This points to the name of an external file containing the debug info.
|
---|
| 542 | * This is NULL if there isn't any external file.
|
---|
| 543 | * @param pvUser The user parameter specified to kLdrModEnumDbgInfo.
|
---|
| 544 | */
|
---|
| 545 | typedef int FNKLDRENUMDBG(PKLDRMOD pMod, KU32 iDbgInfo, KLDRDBGINFOTYPE enmType, KI16 iMajorVer, KI16 iMinorVer,
|
---|
[41] | 546 | const char *pszPartNm, KLDRFOFF offFile, KLDRADDR LinkAddress, KLDRSIZE cb,
|
---|
| 547 | const char *pszExtFile, void *pvUser);
|
---|
[2] | 548 | /** Pointer to a debug info enumerator callback. */
|
---|
| 549 | typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;
|
---|
| 550 |
|
---|
| 551 | /**
|
---|
| 552 | * Resource enumerator callback.
|
---|
| 553 | *
|
---|
| 554 | * @returns 0 to continue the enumeration.
|
---|
| 555 | * @returns non-zero if the enumeration should stop. This status code will then be returned by kLdrModEnumResources().
|
---|
| 556 | *
|
---|
| 557 | * @param pMod The module.
|
---|
| 558 | * @param idType The resource type id. NIL_KLDRMOD_RSRC_TYPE_ID if no type id.
|
---|
| 559 | * @param pszType The resource type name. NULL if no type name.
|
---|
| 560 | * @param idName The resource id. NIL_KLDRMOD_RSRC_NAME_ID if no id.
|
---|
| 561 | * @param pszName The resource name. NULL if no name.
|
---|
| 562 | * @param idLang The language id.
|
---|
| 563 | * @param AddrRsrc The address value for the resource.
|
---|
| 564 | * @param cbRsrc The size of the resource.
|
---|
| 565 | * @param pvUser The user parameter specified to kLdrModEnumDbgInfo.
|
---|
| 566 | */
|
---|
| 567 | typedef int FNKLDRENUMRSRC(PKLDRMOD pMod, KU32 idType, const char *pszType, KU32 idName, const char *pszName,
|
---|
| 568 | KU32 idLang, KLDRADDR AddrRsrc, KLDRSIZE cbRsrc, void *pvUser);
|
---|
| 569 | /** Pointer to a resource enumerator callback. */
|
---|
| 570 | typedef FNKLDRENUMRSRC *PFNKLDRENUMRSRC;
|
---|
| 571 |
|
---|
| 572 | /** NIL resource name ID. */
|
---|
| 573 | #define NIL_KLDRMOD_RSRC_NAME_ID ( ~(KU32)0 )
|
---|
| 574 | /** NIL resource type ID. */
|
---|
| 575 | #define NIL_KLDRMOD_RSRC_TYPE_ID ( ~(KU32)0 )
|
---|
| 576 | /** @name Language ID
|
---|
| 577 | *
|
---|
| 578 | * Except for the special IDs #defined here, the values are considered
|
---|
| 579 | * format specific for now since it's only used by the PE resources.
|
---|
| 580 | *
|
---|
| 581 | * @{ */
|
---|
| 582 | /** NIL language ID. */
|
---|
| 583 | #define NIL_KLDR_LANG_ID ( ~(KU32)0 )
|
---|
| 584 | /** Special language id value for matching any language. */
|
---|
| 585 | #define KLDR_LANG_ID_ANY ( ~(KU32)1 )
|
---|
| 586 | /** Special language id value indicating language neutral. */
|
---|
| 587 | #define KLDR_LANG_ID_NEUTRAL ( ~(KU32)2 )
|
---|
| 588 | /** Special language id value indicating user default language. */
|
---|
| 589 | #define KLDR_LANG_ID_USER_DEFAULT ( ~(KU32)3 )
|
---|
| 590 | /** Special language id value indicating system default language. */
|
---|
| 591 | #define KLDR_LANG_ID_SYS_DEFAULT ( ~(KU32)4 )
|
---|
| 592 | /** Special language id value indicating default custom locale. */
|
---|
| 593 | #define KLDR_LANG_ID_CUSTOM_DEFAULT ( ~(KU32)5 )
|
---|
| 594 | /** Special language id value indicating unspecified custom locale. */
|
---|
| 595 | #define KLDR_LANG_ID_CUSTOM_UNSPECIFIED ( ~(KU32)6 )
|
---|
| 596 | /** Special language id value indicating default custom MUI locale. */
|
---|
| 597 | #define KLDR_LANG_ID_UI_CUSTOM_DEFAULT ( ~(KU32)7 )
|
---|
| 598 | /** @} */
|
---|
| 599 |
|
---|
[117] | 600 | /** @name KLDRMOD_OPEN_FLAGS_XXX - Module Open Flags
|
---|
[52] | 601 | * @{ */
|
---|
| 602 | /** Indicates that we won't be loading the module, we're just getting
|
---|
| 603 | * information (like symbols and line numbers) out of it. */
|
---|
[117] | 604 | #define KLDRMOD_OPEN_FLAGS_FOR_INFO K_BIT32(0)
|
---|
| 605 | /** Native: Non-stub kLdrModCallInit & kLdrModCallTerm. */
|
---|
| 606 | #define KLDRMOD_OPEN_FLAGS_NATIVE_ALLOW_INIT_TERM K_BIT32(1)
|
---|
| 607 | /** Mask of valid flags. */
|
---|
| 608 | #define KLDRMOD_OPEN_FLAGS_VALID_MASK KU32_C(0x00000003)
|
---|
[52] | 609 | /** @} */
|
---|
[2] | 610 |
|
---|
[25] | 611 | int kLdrModOpen(const char *pszFilename, KU32 fFlags, KCPUARCH enmCpuArch, PPKLDRMOD ppMod);
|
---|
| 612 | int kLdrModOpenFromRdr(PKRDR pRdr, KU32 fFlags, KCPUARCH enmCpuArch, PPKLDRMOD ppMod);
|
---|
[117] | 613 | int kLdrModOpenNative(const char *pszFilename, KU32 fFlags, PPKLDRMOD ppMod);
|
---|
| 614 | int kLdrModOpenNativeByHandle(KUPTR uHandle, KU32 fFlags, PPKLDRMOD ppMod);
|
---|
[2] | 615 | int kLdrModClose(PKLDRMOD pMod);
|
---|
| 616 |
|
---|
| 617 | int kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 iSymbol,
|
---|
| 618 | const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
|
---|
| 619 | PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, PKLDRADDR puValue, KU32 *pfKind);
|
---|
| 620 | int kLdrModEnumSymbols(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress,
|
---|
| 621 | KU32 fFlags, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
|
---|
| 622 | int kLdrModGetImport(PKLDRMOD pMod, const void *pvBits, KU32 iImport, char *pszName, KSIZE cchName);
|
---|
| 623 | KI32 kLdrModNumberOfImports(PKLDRMOD pMod, const void *pvBits);
|
---|
| 624 | int kLdrModCanExecuteOn(PKLDRMOD pMod, const void *pvBits, KCPUARCH enmArch, KCPU enmCpu);
|
---|
| 625 | int kLdrModGetStackInfo(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
|
---|
| 626 | int kLdrModQueryMainEntrypoint(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
|
---|
[54] | 627 | int kLdrModQueryImageUuid(PKLDRMOD pMod, const void *pvBits, void *pvUuid, KSIZE cbUuid);
|
---|
[2] | 628 | int kLdrModQueryResource(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
|
---|
| 629 | KU32 idName, const char *pszName, KU32 idLang, PKLDRADDR pAddrRsrc, KSIZE *pcbRsrc);
|
---|
| 630 | int kLdrModEnumResources(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
|
---|
| 631 | KU32 idName, const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
|
---|
| 632 | int kLdrModEnumDbgInfo(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
|
---|
| 633 | int kLdrModHasDbgInfo(PKLDRMOD pMod, const void *pvBits);
|
---|
| 634 | int kLdrModMostlyDone(PKLDRMOD pMod);
|
---|
| 635 |
|
---|
| 636 |
|
---|
| 637 | /** @name Operations On The Internally Managed Mapping
|
---|
| 638 | * @{ */
|
---|
| 639 | int kLdrModMap(PKLDRMOD pMod);
|
---|
| 640 | int kLdrModUnmap(PKLDRMOD pMod);
|
---|
| 641 | int kLdrModReload(PKLDRMOD pMod);
|
---|
| 642 | int kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
|
---|
| 643 | /** @} */
|
---|
| 644 |
|
---|
| 645 | /** @name Operations On The Externally Managed Mappings
|
---|
| 646 | * @{ */
|
---|
| 647 | KLDRADDR kLdrModSize(PKLDRMOD pMod);
|
---|
| 648 | int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
|
---|
| 649 | int kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
|
---|
| 650 | PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
|
---|
| 651 | /** @} */
|
---|
| 652 |
|
---|
[81] | 653 | /** @name Operations on both internally and externally managed mappings.
|
---|
| 654 | * @{ */
|
---|
| 655 | /** Special pvMapping value to pass to kLdrModAllocTLS,
|
---|
| 656 | * kLdrModFreeTLS, kLdrModCallInit, kLdrModCallTerm, and kLdrModCallThread that
|
---|
| 657 | * specifies the internal mapping (kLdrModMap). */
|
---|
| 658 | #define KLDRMOD_INT_MAP ((void *)~(KUPTR)0)
|
---|
| 659 | int kLdrModAllocTLS(PKLDRMOD pMod, void *pvMapping);
|
---|
| 660 | void kLdrModFreeTLS(PKLDRMOD pMod, void *pvMapping);
|
---|
| 661 | int kLdrModCallInit(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle);
|
---|
| 662 | int kLdrModCallTerm(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle);
|
---|
| 663 | int kLdrModCallThread(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching);
|
---|
| 664 | /** @} */
|
---|
[2] | 665 |
|
---|
[81] | 666 |
|
---|
[2] | 667 | /**
|
---|
| 668 | * The loader module operation.
|
---|
| 669 | */
|
---|
| 670 | typedef struct KLDRMODOPS
|
---|
| 671 | {
|
---|
| 672 | /** The name of this module interpreter. */
|
---|
| 673 | const char *pszName;
|
---|
| 674 | /** Pointer to the next module interpreter. */
|
---|
| 675 | PCKLDRMODOPS pNext;
|
---|
| 676 |
|
---|
| 677 | /**
|
---|
| 678 | * Create a loader module instance interpreting the executable image found
|
---|
| 679 | * in the specified file provider instance.
|
---|
| 680 | *
|
---|
| 681 | * @returns 0 on success and *ppMod pointing to a module instance.
|
---|
| 682 | * On failure, a non-zero OS specific error code is returned.
|
---|
| 683 | * @param pOps Pointer to the registered method table.
|
---|
| 684 | * @param pRdr The file provider instance to use.
|
---|
[25] | 685 | * @param fFlags Flags, MBZ.
|
---|
| 686 | * @param enmCpuArch The desired CPU architecture. KCPUARCH_UNKNOWN means
|
---|
| 687 | * anything goes, but with a preference for the current
|
---|
| 688 | * host architecture.
|
---|
[2] | 689 | * @param offNewHdr The offset of the new header in MZ files. -1 if not found.
|
---|
| 690 | * @param ppMod Where to store the module instance pointer.
|
---|
| 691 | */
|
---|
[25] | 692 | int (* pfnCreate)(PCKLDRMODOPS pOps, PKRDR pRdr, KU32 fFlags, KCPUARCH enmCpuArch, KLDRFOFF offNewHdr, PPKLDRMOD ppMod);
|
---|
[2] | 693 | /**
|
---|
| 694 | * Destroys an loader module instance.
|
---|
| 695 | *
|
---|
| 696 | * The caller is responsible for calling kLdrModUnmap() and kLdrFreeTLS() first.
|
---|
| 697 | *
|
---|
| 698 | * @returns 0 on success, non-zero on failure. The module instance state
|
---|
| 699 | * is unknown on failure, it's best not to touch it.
|
---|
| 700 | * @param pMod The module.
|
---|
| 701 | */
|
---|
| 702 | int (* pfnDestroy)(PKLDRMOD pMod);
|
---|
| 703 |
|
---|
| 704 | /** @copydoc kLdrModQuerySymbol */
|
---|
| 705 | int (* pfnQuerySymbol)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 iSymbol,
|
---|
| 706 | const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
|
---|
| 707 | PFNKLDRMODGETIMPORT pfnGetForwarder, void *pvUser, PKLDRADDR puValue, KU32 *pfKind);
|
---|
| 708 | /** @copydoc kLdrModEnumSymbols */
|
---|
| 709 | int (* pfnEnumSymbols)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 fFlags,
|
---|
| 710 | PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
|
---|
| 711 | /** @copydoc kLdrModGetImport */
|
---|
| 712 | int (* pfnGetImport)(PKLDRMOD pMod, const void *pvBits, KU32 iImport, char *pszName, KSIZE cchName);
|
---|
| 713 | /** @copydoc kLdrModNumberOfImports */
|
---|
| 714 | KI32 (* pfnNumberOfImports)(PKLDRMOD pMod, const void *pvBits);
|
---|
| 715 | /** @copydoc kLdrModCanExecuteOn */
|
---|
| 716 | int (* pfnCanExecuteOn)(PKLDRMOD pMod, const void *pvBits, KCPUARCH enmArch, KCPU enmCpu);
|
---|
| 717 | /** @copydoc kLdrModGetStackInfo */
|
---|
| 718 | int (* pfnGetStackInfo)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
|
---|
| 719 | /** @copydoc kLdrModQueryMainEntrypoint */
|
---|
| 720 | int (* pfnQueryMainEntrypoint)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
|
---|
[54] | 721 | /** @copydoc kLdrModQueryImageUuid */
|
---|
| 722 | int (* pfnQueryImageUuid)(PKLDRMOD pMod, const void *pvBits, void *pvUuid, KSIZE pcbUuid);
|
---|
[2] | 723 | /** @copydoc kLdrModQueryResource */
|
---|
| 724 | int (* pfnQueryResource)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
|
---|
| 725 | KU32 idName, const char *pszName, KU32 idLang, PKLDRADDR pAddrRsrc, KSIZE *pcbRsrc);
|
---|
| 726 | /** @copydoc kLdrModEnumResources */
|
---|
| 727 | int (* pfnEnumResources)(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, KU32 idType, const char *pszType,
|
---|
| 728 | KU32 idName, const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
|
---|
| 729 | /** @copydoc kLdrModEnumDbgInfo */
|
---|
| 730 | int (* pfnEnumDbgInfo)(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
|
---|
| 731 | /** @copydoc kLdrModHasDbgInfo */
|
---|
| 732 | int (* pfnHasDbgInfo)(PKLDRMOD pMod, const void *pvBits);
|
---|
| 733 | /** @copydoc kLdrModMap */
|
---|
| 734 | int (* pfnMap)(PKLDRMOD pMod);
|
---|
| 735 | /** @copydoc kLdrModUnmap */
|
---|
| 736 | int (* pfnUnmap)(PKLDRMOD pMod);
|
---|
| 737 | /** @copydoc kLdrModAllocTLS */
|
---|
[81] | 738 | int (* pfnAllocTLS)(PKLDRMOD pMod, void *pvMapping);
|
---|
[2] | 739 | /** @copydoc kLdrModFreeTLS */
|
---|
[81] | 740 | void (*pfnFreeTLS)(PKLDRMOD pMod, void *pvMapping);
|
---|
[2] | 741 | /** @copydoc kLdrModReload */
|
---|
| 742 | int (* pfnReload)(PKLDRMOD pMod);
|
---|
| 743 | /** @copydoc kLdrModFixupMapping */
|
---|
| 744 | int (* pfnFixupMapping)(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
|
---|
| 745 | /** @copydoc kLdrModCallInit */
|
---|
[81] | 746 | int (* pfnCallInit)(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle);
|
---|
[2] | 747 | /** @copydoc kLdrModCallTerm */
|
---|
[81] | 748 | int (* pfnCallTerm)(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle);
|
---|
[2] | 749 | /** @copydoc kLdrModCallThread */
|
---|
[81] | 750 | int (* pfnCallThread)(PKLDRMOD pMod, void *pvMapping, KUPTR uHandle, unsigned fAttachingOrDetaching);
|
---|
[2] | 751 | /** @copydoc kLdrModSize */
|
---|
| 752 | KLDRADDR (* pfnSize)(PKLDRMOD pMod);
|
---|
| 753 | /** @copydoc kLdrModGetBits */
|
---|
| 754 | int (* pfnGetBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
|
---|
| 755 | /** @copydoc kLdrModRelocateBits */
|
---|
| 756 | int (* pfnRelocateBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
|
---|
| 757 | PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
|
---|
| 758 | /** @copydoc kLdrModMostlyDone */
|
---|
| 759 | int (* pfnMostlyDone)(PKLDRMOD pMod);
|
---|
| 760 | /** Dummy which should be assigned a non-zero value. */
|
---|
| 761 | KU32 uEndOfStructure;
|
---|
| 762 | } KLDRMODOPS;
|
---|
| 763 |
|
---|
| 764 |
|
---|
| 765 | /** @} */
|
---|
| 766 |
|
---|
| 767 |
|
---|
| 768 |
|
---|
| 769 |
|
---|
| 770 | /** @defgroup grp_kLdrDyld kLdrDyld - The dynamic loader
|
---|
| 771 | * @{ */
|
---|
| 772 |
|
---|
| 773 | /** The handle to a dynamic loader module. */
|
---|
| 774 | typedef struct KLDRDYLDMOD *HKLDRMOD;
|
---|
| 775 | /** Pointer to the handle to a dynamic loader module. */
|
---|
| 776 | typedef HKLDRMOD *PHKLDRMOD;
|
---|
| 777 | /** NIL handle value. */
|
---|
| 778 | #define NIL_HKLDRMOD ((HKLDRMOD)0)
|
---|
| 779 |
|
---|
| 780 |
|
---|
| 781 | /**
|
---|
| 782 | * File search method.
|
---|
| 783 | *
|
---|
| 784 | * In addition to it's own way of finding files, kLdr emulates
|
---|
| 785 | * the methods employed by the most popular systems.
|
---|
| 786 | */
|
---|
| 787 | typedef enum KLDRDYLDSEARCH
|
---|
| 788 | {
|
---|
| 789 | /** The usual invalid file search method. */
|
---|
| 790 | KLDRDYLD_SEARCH_INVALID = 0,
|
---|
| 791 | /** Uses the kLdr file search method.
|
---|
| 792 | * @todo invent me. */
|
---|
| 793 | KLDRDYLD_SEARCH_KLDR,
|
---|
| 794 | /** Use the emulation closest to the host system. */
|
---|
| 795 | KLDRDYLD_SEARCH_HOST,
|
---|
| 796 | /** Emulate the OS/2 file search method.
|
---|
| 797 | * On non-OS/2 systems, BEGINLIBPATH, LIBPATH, ENDLIBPATH and LIBPATHSTRICT are
|
---|
| 798 | * taken form the environment. */
|
---|
| 799 | KLDRDYLD_SEARCH_OS2,
|
---|
| 800 | /** Emulate the standard window file search method. */
|
---|
| 801 | KLDRDYLD_SEARCH_WINDOWS,
|
---|
| 802 | /** Emulate the alternative window file search method. */
|
---|
| 803 | KLDRDYLD_SEARCH_WINDOWS_ALTERED,
|
---|
| 804 | /** Emulate the most common UNIX file search method. */
|
---|
| 805 | KLDRDYLD_SEARCH_UNIX_COMMON,
|
---|
| 806 | /** End of the valid file search method values. */
|
---|
| 807 | KLDRDYLD_SEARCH_END,
|
---|
| 808 | /** Hack to blow the type up to 32-bit. */
|
---|
| 809 | KLDRDYLD_SEARCH_32BIT_HACK = 0x7fffffff
|
---|
| 810 | } KLDRDYLDSEARCH;
|
---|
| 811 |
|
---|
| 812 | /** @name kLdrDyldLoad and kLdrDyldFindByName flags.
|
---|
| 813 | * @{ */
|
---|
| 814 | /** The symbols in the module should be loaded into the global unix namespace.
|
---|
| 815 | * If not specified, the symbols are local and can only be referenced directly. */
|
---|
| 816 | #define KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS 0x00000001
|
---|
| 817 | /** The symbols in the module should be loaded into the global unix namespace and
|
---|
| 818 | * it's symbols should take precedence over all currently loaded modules.
|
---|
| 819 | * This implies KLDRYDLD_LOAD_FLAGS_GLOBAL_SYMBOLS. */
|
---|
| 820 | #define KLDRYDLD_LOAD_FLAGS_DEEP_SYMBOLS 0x00000002
|
---|
| 821 | /** The module shouldn't be found by a global module search.
|
---|
| 822 | * If not specified, the module can be found by unspecified module searches,
|
---|
| 823 | * typical used when loading import/dep modules. */
|
---|
| 824 | #define KLDRYDLD_LOAD_FLAGS_SPECIFIC_MODULE 0x00000004
|
---|
| 825 | /** Do a recursive initialization calls instead of defering them to the outermost call. */
|
---|
| 826 | #define KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT 0x00000008
|
---|
| 827 | /** We're loading the executable module.
|
---|
| 828 | * @internal */
|
---|
| 829 | #define KLDRDYLD_LOAD_FLAGS_EXECUTABLE 0x40000000
|
---|
| 830 | /** @} */
|
---|
| 831 |
|
---|
| 832 |
|
---|
| 833 | int kLdrDyldLoad(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
|
---|
| 834 | unsigned fFlags, PHKLDRMOD phMod, char *pszErr, KSIZE cchErr);
|
---|
| 835 | int kLdrDyldUnload(HKLDRMOD hMod);
|
---|
| 836 | int kLdrDyldFindByName(const char *pszDll, const char *pszPrefix, const char *pszSuffix, KLDRDYLDSEARCH enmSearch,
|
---|
| 837 | unsigned fFlags, PHKLDRMOD phMod);
|
---|
| 838 | int kLdrDyldFindByAddress(KUPTR Address, PHKLDRMOD phMod, KU32 *piSegment, KUPTR *poffSegment);
|
---|
| 839 | int kLdrDyldGetName(HKLDRMOD hMod, char *pszName, KSIZE cchName);
|
---|
| 840 | int kLdrDyldGetFilename(HKLDRMOD hMod, char *pszFilename, KSIZE cchFilename);
|
---|
| 841 | int kLdrDyldQuerySymbol(HKLDRMOD hMod, KU32 uSymbolOrdinal, const char *pszSymbolName,
|
---|
| 842 | const char *pszSymbolVersion, KUPTR *pValue, KU32 *pfKind);
|
---|
| 843 | int kLdrDyldQueryResource(HKLDRMOD hMod, KU32 idType, const char *pszType, KU32 idName,
|
---|
| 844 | const char *pszName, KU32 idLang, void **pvRsrc, KSIZE *pcbRsrc);
|
---|
| 845 | int kLdrDyldEnumResources(HKLDRMOD hMod, KU32 idType, const char *pszType, KU32 idName,
|
---|
| 846 | const char *pszName, KU32 idLang, PFNKLDRENUMRSRC pfnCallback, void *pvUser);
|
---|
| 847 |
|
---|
| 848 |
|
---|
| 849 | /** @name OS/2 like API
|
---|
| 850 | * @{ */
|
---|
| 851 | #if defined(__OS2__)
|
---|
| 852 | # define KLDROS2API _System
|
---|
| 853 | #else
|
---|
| 854 | # define KLDROS2API
|
---|
| 855 | #endif
|
---|
| 856 | int kLdrDosLoadModule(char *pszObject, KSIZE cbObject, const char *pszModule, PHKLDRMOD phMod);
|
---|
| 857 | int kLdrDosFreeModule(HKLDRMOD hMod);
|
---|
| 858 | int kLdrDosQueryModuleHandle(const char *pszModname, PHKLDRMOD phMod);
|
---|
| 859 | int kLdrDosQueryModuleName(HKLDRMOD hMod, KSIZE cchName, char *pszName);
|
---|
| 860 | int kLdrDosQueryProcAddr(HKLDRMOD hMod, KU32 iOrdinal, const char *pszProcName, void **ppvProcAddr);
|
---|
| 861 | int kLdrDosQueryProcType(HKLDRMOD hMod, KU32 iOrdinal, const char *pszProcName, KU32 *pfProcType);
|
---|
| 862 | int kLdrDosQueryModFromEIP(PHKLDRMOD phMod, KU32 *piObject, KSIZE cbName, char *pszName, KUPTR *poffObject, KUPTR ulEIP);
|
---|
| 863 | int kLdrDosReplaceModule(const char *pszOldModule, const char *pszNewModule, const char *pszBackupModule);
|
---|
| 864 | int kLdrDosGetResource(HKLDRMOD hMod, KU32 idType, KU32 idName, void **pvResAddr);
|
---|
| 865 | int kLdrDosQueryResourceSize(HKLDRMOD hMod, KU32 idType, KU32 idName, KU32 *pcb);
|
---|
| 866 | int kLdrDosFreeResource(void *pvResAddr);
|
---|
| 867 | /** @} */
|
---|
| 868 |
|
---|
| 869 | /** @name POSIX like API
|
---|
| 870 | * @{ */
|
---|
| 871 | HKLDRMOD kLdrDlOpen(const char *pszLibrary, int fFlags);
|
---|
| 872 | const char *kLdrDlError(void);
|
---|
| 873 | void * kLdrDlSym(HKLDRMOD hMod, const char *pszSymbol);
|
---|
| 874 | int kLdrDlClose(HKLDRMOD hMod);
|
---|
| 875 | /** @todo GNU extensions */
|
---|
| 876 | /** @} */
|
---|
| 877 |
|
---|
| 878 | /** @name Win32 like API
|
---|
| 879 | * @{ */
|
---|
| 880 | #if defined(_MSC_VER)
|
---|
| 881 | # define KLDRWINAPI __stdcall
|
---|
| 882 | #else
|
---|
| 883 | # define KLDRWINAPI
|
---|
| 884 | #endif
|
---|
| 885 | HKLDRMOD KLDRWINAPI kLdrWLoadLibrary(const char *pszFilename);
|
---|
| 886 | HKLDRMOD KLDRWINAPI kLdrWLoadLibraryEx(const char *pszFilename, void *hFileReserved, KU32 fFlags);
|
---|
| 887 | KU32 KLDRWINAPI kLdrWGetModuleFileName(HKLDRMOD hMod, char *pszModName, KSIZE cchModName);
|
---|
| 888 | HKLDRMOD KLDRWINAPI kLdrWGetModuleHandle(const char *pszFilename);
|
---|
| 889 | int KLDRWINAPI kLdrWGetModuleHandleEx(KU32 fFlags, const char *pszFilename, HKLDRMOD hMod);
|
---|
| 890 | void * KLDRWINAPI kLdrWGetProcAddress(HKLDRMOD hMod, const char *pszProcName);
|
---|
| 891 | KU32 KLDRWINAPI kLdrWGetDllDirectory(KSIZE cchDir, char *pszDir);
|
---|
| 892 | int KLDRWINAPI kLdrWSetDllDirectory(const char *pszDir);
|
---|
| 893 | int KLDRWINAPI kLdrWFreeLibrary(HKLDRMOD hMod);
|
---|
| 894 | int KLDRWINAPI kLdrWDisableThreadLibraryCalls(HKLDRMOD hMod);
|
---|
| 895 |
|
---|
| 896 | /** The handle to a resource that's been found. */
|
---|
| 897 | typedef struct KLDRWRSRCFOUND *HKLDRWRSRCFOUND;
|
---|
| 898 | /** The handle to a loaded resource. */
|
---|
| 899 | typedef struct KLDRWRSRCLOADED *HKLDRWRSRCLOADED;
|
---|
| 900 | HKLDRWRSRCFOUND KLDRWINAPI kLdrWFindResource(HKLDRMOD hMod, const char *pszType, const char *pszName);
|
---|
| 901 | HKLDRWRSRCFOUND KLDRWINAPI kLdrWFindResourceEx(HKLDRMOD hMod, const char *pszType, const char *pszName, KU16 idLang);
|
---|
| 902 | KU32 KLDRWINAPI kLdrWSizeofResource(HKLDRMOD hMod, HKLDRWRSRCFOUND hFoundRsrc);
|
---|
| 903 | HKLDRWRSRCLOADED KLDRWINAPI kLdrWLoadResource(HKLDRMOD hMod, HKLDRWRSRCFOUND hFoundRsrc);
|
---|
| 904 | void *KLDRWINAPI kLdrWLockResource(HKLDRMOD hMod, HKLDRWRSRCLOADED hLoadedRsrc);
|
---|
| 905 | int KLDRWINAPI kLdrWFreeResource(HKLDRMOD hMod, HKLDRWRSRCLOADED hLoadedRsrc);
|
---|
| 906 |
|
---|
| 907 | typedef int (KLDRWINAPI *PFNKLDRWENUMRESTYPE)(HKLDRMOD hMod, const char *pszType, KUPTR uUser);
|
---|
| 908 | int KLDRWINAPI kLdrWEnumResourceTypes(HKLDRMOD hMod, PFNKLDRWENUMRESTYPE pfnEnum, KUPTR uUser);
|
---|
| 909 | int KLDRWINAPI kLdrWEnumResourceTypesEx(HKLDRMOD hMod, PFNKLDRWENUMRESTYPE pfnEnum, KUPTR uUser, KU32 fFlags, KU16 idLang);
|
---|
| 910 |
|
---|
| 911 | typedef int (KLDRWINAPI *PFNKLDRWENUMRESNAME)(HKLDRMOD hMod, const char *pszType, char *pszName, KUPTR uUser);
|
---|
| 912 | int KLDRWINAPI kLdrWEnumResourceNames(HKLDRMOD hMod, const char *pszType, PFNKLDRWENUMRESNAME pfnEnum, KUPTR uUser);
|
---|
| 913 | int KLDRWINAPI kLdrWEnumResourceNamesEx(HKLDRMOD hMod, const char *pszType, PFNKLDRWENUMRESNAME pfnEnum, KUPTR uUser, KU32 fFlags, KU16 idLang);
|
---|
| 914 |
|
---|
| 915 | typedef int (KLDRWINAPI *PFNKLDRWENUMRESLANG)(HKLDRMOD hMod, const char *pszType, const char *pszName, KU16 idLang, KUPTR uUser);
|
---|
| 916 | int KLDRWINAPI kLdrWEnumResourceLanguages(HKLDRMOD hMod, const char *pszType, const char *pszName, PFNKLDRWENUMRESLANG pfnEnum, KUPTR uUser);
|
---|
| 917 | int KLDRWINAPI kLdrWEnumResourceLanguagesEx(HKLDRMOD hMod, const char *pszType, const char *pszName,
|
---|
| 918 | PFNKLDRWENUMRESLANG pfnEnum, KUPTR uUser, KU32 fFlags, KU16 idLang);
|
---|
| 919 | /** @} */
|
---|
| 920 |
|
---|
| 921 |
|
---|
| 922 | /** @name Process Bootstrapping
|
---|
| 923 | * @{ */
|
---|
| 924 |
|
---|
| 925 | /**
|
---|
| 926 | * Argument package from the stub.
|
---|
| 927 | */
|
---|
| 928 | typedef struct KLDREXEARGS
|
---|
| 929 | {
|
---|
| 930 | /** Load & search flags, some which will become defaults. */
|
---|
| 931 | KU32 fFlags;
|
---|
| 932 | /** The default search method. */
|
---|
| 933 | KLDRDYLDSEARCH enmSearch;
|
---|
| 934 | /** The executable file that the stub is supposed to load. */
|
---|
| 935 | char szExecutable[260];
|
---|
| 936 | /** The default prefix used when searching for DLLs. */
|
---|
| 937 | char szDefPrefix[16];
|
---|
| 938 | /** The default suffix used when searching for DLLs. */
|
---|
| 939 | char szDefSuffix[16];
|
---|
| 940 | /** The LD_LIBRARY_PATH prefix for the process.. */
|
---|
| 941 | char szLibPath[4096 - sizeof(KU32) - sizeof(KLDRDYLDSEARCH) - 16 - 16 - 260];
|
---|
| 942 | } KLDREXEARGS, *PKLDREXEARGS;
|
---|
| 943 | /** Pointer to a const argument package from the stub. */
|
---|
| 944 | typedef const KLDREXEARGS *PCKLDREXEARGS;
|
---|
| 945 |
|
---|
| 946 | void kLdrLoadExe(PCKLDREXEARGS pArgs, void *pvOS); /** @todo fix this mess... */
|
---|
| 947 | void kLdrDyldLoadExe(PCKLDREXEARGS pArgs, void *pvOS);
|
---|
| 948 | /** @} */
|
---|
| 949 |
|
---|
| 950 | /** @} */
|
---|
| 951 |
|
---|
| 952 | /** @} */
|
---|
| 953 |
|
---|
| 954 | #ifdef __cplusplus
|
---|
| 955 | }
|
---|
| 956 | #endif
|
---|
| 957 |
|
---|
| 958 | #endif
|
---|
| 959 |
|
---|