[2826] | 1 | /* $Id: kLdrInternal.h 2833 2006-10-26 00:08:09Z bird $ */
|
---|
[2825] | 2 | /** @file
|
---|
| 3 | *
|
---|
| 4 | * kLdr - The Dynamic Loader, internal header.
|
---|
| 5 | *
|
---|
| 6 | * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@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 |
|
---|
| 28 | #ifndef __kLdrInternal_h__
|
---|
| 29 | #define __kLdrInternal_h__
|
---|
| 30 |
|
---|
| 31 | #ifdef __cplusplus
|
---|
| 32 | extern "C" {
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
[2827] | 35 | /* ignore definitions in winnt.h */
|
---|
| 36 | #undef IMAGE_DOS_SIGNATURE
|
---|
| 37 | #undef IMAGE_NT_SIGNATURE
|
---|
| 38 |
|
---|
| 39 | /** @name Signatures we know
|
---|
| 40 | * @{ */
|
---|
| 41 | /** ELF signature ("\x7fELF"). */
|
---|
| 42 | #define IMAGE_ELF_SIGNATURE KLDRHLP_LE2H_U32(0x7f | ('E' << 8) | ((uint32_t)'L' << 16) | ((uint32_t)'F' << 24))
|
---|
| 43 | /** PE signature ("PE\0\0"). */
|
---|
| 44 | #define IMAGE_NT_SIGNATURE KLDRHLP_LE2H_U32('P' | ('E' << 8))
|
---|
| 45 | /** LX signature ("LX") */
|
---|
| 46 | #define IMAGE_LX_SIGNATURE KLDRHLP_LE2H_U16('L' | ('X' << 8))
|
---|
| 47 | /** LE signature ("LE") */
|
---|
| 48 | #define IMAGE_LE_SIGNATURE KLDRHLP_LE2H_U16('L' | ('E' << 8))
|
---|
| 49 | /** NE signature ("NE") */
|
---|
| 50 | #define IMAGE_NE_SIGNATURE KLDRHLP_LE2H_U16('N' | ('E' << 8))
|
---|
| 51 | /** MZ signature ("MZ"). */
|
---|
| 52 | #define IMAGE_DOS_SIGNATURE KLDRHLP_LE2H_U16('M' | ('Z' << 8))
|
---|
| 53 | /** @} */
|
---|
| 54 |
|
---|
[2833] | 55 | /** @defgroup grp_kLdrInternal Internals
|
---|
| 56 | * @internal
|
---|
| 57 | * @{
|
---|
| 58 | */
|
---|
[2827] | 59 |
|
---|
[2833] | 60 |
|
---|
[2825] | 61 | /** Native file provider operations. */
|
---|
| 62 | extern const KLDRRDROPS g_kLdrRdrFileOps;
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * The state of a dynamic loader module.
|
---|
| 67 | */
|
---|
| 68 | typedef enum KLDRSTATE
|
---|
| 69 | {
|
---|
| 70 | /** The usual invalid 0 enum. */
|
---|
| 71 | KLDRSTATE_INVALID = 0,
|
---|
| 72 | /** kldrOpen succeeded.
|
---|
| 73 | * Modules in this state will be freed at */
|
---|
| 74 | KLDRSTATE_OPEN,
|
---|
| 75 | /** Dependencies has been loaded. */
|
---|
| 76 | KLDRSTATE_DEPS,
|
---|
| 77 | /** Fixups has been applied. */
|
---|
| 78 | KLDRSTATE_FIXED,
|
---|
| 79 | /** The module has been initialized. */
|
---|
| 80 | KLDRSTATE_INITED,
|
---|
| 81 | /** The module is loaded successfully. */
|
---|
| 82 | KLDRSTATE_LOADED,
|
---|
| 83 | /** The end of valid states (exclusive) */
|
---|
| 84 | KLDRSTATE_END,
|
---|
| 85 | /** The usual 32-bit blowup. */
|
---|
| 86 | KLDRSTATE_32BIT_HACK = 0x7fffffff
|
---|
| 87 | } KLDRSTATE;
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Dynamic loader module.
|
---|
| 92 | */
|
---|
[2833] | 93 | typedef struct KLDRDYLDMOD
|
---|
[2825] | 94 | {
|
---|
[2833] | 95 | /** Magic number. */
|
---|
| 96 | uint32_t u32MagicHead;
|
---|
| 97 | /** The module state. */
|
---|
| 98 | KLDRSTATE enmState;
|
---|
[2825] | 99 | /** The module. */
|
---|
| 100 | PKLDRMOD pMod;
|
---|
| 101 | /** The number of references. */
|
---|
| 102 | uint32_t cRefs;
|
---|
| 103 | /** The number of dynamic references. */
|
---|
| 104 | uint32_t cDynRefs;
|
---|
| 105 | /** Set if this is the executable module. */
|
---|
| 106 | uint32_t fExecutable : 1;
|
---|
| 107 | /** Global DLL (set) or specific DLL (clear). */
|
---|
| 108 | uint32_t fGlobal : 1;
|
---|
| 109 | /** Load stage one. */
|
---|
| 110 | uint32_t fLoadStageOne : 1;
|
---|
| 111 | /** Reserved for future use. */
|
---|
| 112 | uint32_t fReserved : 29;
|
---|
[2833] | 113 | /** The next module in the list. */
|
---|
| 114 | struct KLDRDYMOD *pNext;
|
---|
| 115 | /** The prev module in the list. */
|
---|
| 116 | struct KLDRDYMOD *pPrev;
|
---|
| 117 | /** Magic number. */
|
---|
| 118 | uint32_t u32MagicTail;
|
---|
| 119 | } KLDRDYLDMOD, *PKLDRDYLDMOD, **PPKLDRDYLDMOD;
|
---|
[2825] | 120 |
|
---|
[2833] | 121 | /** KLDRDYMOD magic value. (Fuyumi Soryo) */
|
---|
| 122 | #define KLDRDYMOD_MAGIC 0x19590106
|
---|
[2825] | 123 |
|
---|
[2833] | 124 | /** Return / crash validation of a module handle argument. */
|
---|
| 125 | #define KLDRDYLD_VALIDATE_HKLDRMOD(hMod) \
|
---|
| 126 | do { \
|
---|
| 127 | if ( (hMod) == NIL_HKLDRMOD \
|
---|
| 128 | || (hMod)->u32MagicHead != KLDRDYMOD_MAGIC \
|
---|
| 129 | || (hMod)->u32MagicTail != KLDRDYMOD_MAGIC) \
|
---|
| 130 | { \
|
---|
| 131 | return KLDR_ERR_INVALID_HANDLE; \
|
---|
| 132 | } \
|
---|
| 133 | } while (0)
|
---|
| 134 |
|
---|
| 135 |
|
---|
[2825] | 136 | /** Pointer to the head module (the executable). */
|
---|
[2833] | 137 | extern PKLDRDYLDMOD kLdrDyldModuleHead;
|
---|
[2825] | 138 | /** Pointer to the tail module. */
|
---|
[2833] | 139 | extern PKLDRDYLDMOD kLdrDyldModuleTail;
|
---|
[2825] | 140 | /** The Library search path. */
|
---|
[2833] | 141 | extern char kLdrDyldLibraryPath[4096];
|
---|
[2825] | 142 |
|
---|
[2833] | 143 |
|
---|
[2825] | 144 | #if 0
|
---|
| 145 | void kldrFailure(const char *pszFilename, ...);
|
---|
| 146 | #endif
|
---|
[2833] | 147 |
|
---|
[2825] | 148 | /** @} */
|
---|
| 149 | #ifdef __cplusplus
|
---|
| 150 | }
|
---|
| 151 | #endif
|
---|
| 152 |
|
---|
| 153 | #endif
|
---|