1 | /* $Id: kLdrInternal.h 2835 2006-10-26 01:03:39Z bird $ */
|
---|
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 |
|
---|
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 |
|
---|
55 | /** @defgroup grp_kLdrInternal Internals
|
---|
56 | * @internal
|
---|
57 | * @{
|
---|
58 | */
|
---|
59 |
|
---|
60 |
|
---|
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 | */
|
---|
93 | typedef struct KLDRDYLDMOD
|
---|
94 | {
|
---|
95 | /** Magic number. */
|
---|
96 | uint32_t u32MagicHead;
|
---|
97 | /** The module state. */
|
---|
98 | KLDRSTATE enmState;
|
---|
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;
|
---|
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;
|
---|
120 |
|
---|
121 | /** KLDRDYMOD magic value. (Fuyumi Soryo) */
|
---|
122 | #define KLDRDYMOD_MAGIC 0x19590106
|
---|
123 |
|
---|
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 |
|
---|
136 | int kldrDyldFindNewModule(const char *pszName, const char *pszPrefix, const char *pszSuffix,
|
---|
137 | KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRDYLDMOD ppMod);
|
---|
138 | int kldrDyldFindExistingModule(const char *pszName, const char *pszPrefix, const char *pszSuffix,
|
---|
139 | KLDRDYLDSEARCH enmSearch, unsigned fFlags, PPKLDRDYLDMOD ppMod);
|
---|
140 |
|
---|
141 |
|
---|
142 | int kldrDyldModCreate(PKLDRRDR pRdr, PPKLDRDYLDMOD ppMod);
|
---|
143 | int kldrDyldModDestroy(PKLDRDYLDMOD pMod);
|
---|
144 | int kldrDyldModAddDep(PKLDRDYLDMOD pMod, PKLDRDYLDMOD pModDep);
|
---|
145 | int kldrDyldModRemoveDep(PKLDRDYLDMOD pMod, PKLDRDYLDMOD pModDep);
|
---|
146 | int kldrDyldModDynamicLoad(PKLDRDYLDMOD pMod);
|
---|
147 | int kldrDyldModDynamicUnload(PKLDRDYLDMOD pMod);
|
---|
148 | int kldrDyldModMarkGlobal(PKLDRDYLDMOD pMod);
|
---|
149 | int kldrDyldModMarkSpecific(PKLDRDYLDMOD pMod);
|
---|
150 | int kldrDyldModSetBindable(PKLDRDYLDMOD pMod);
|
---|
151 | int kldrDyldModClearBindable(PKLDRDYLDMOD pMod);
|
---|
152 | int kldrDyldModSetDeepBindable(PKLDRDYLDMOD pMod);
|
---|
153 | int kldrDyldModClearDeepBindable(PKLDRDYLDMOD pMod);
|
---|
154 | int kldrDyldModMap(PKLDRDYLDMOD pMod);
|
---|
155 | int kldrDyldModUnmap(PKLDRDYLDMOD pMod);
|
---|
156 | int kldrDyldModLoadDependencies(PKLDRDYLDMOD pMod);
|
---|
157 | int kldrDyldModFixup(PKLDRDYLDMOD pMod);
|
---|
158 | int kldrDyldModCallInit(PKLDRDYLDMOD pMod);
|
---|
159 | int kldrDyldModCallTerm(PKLDRDYLDMOD pMod);
|
---|
160 | int kldrDyldModGetStackInfo(PKLDRDYLDMOD pMod, void *pvStack, size_t *pcbStack, size_t);
|
---|
161 | int kldrDyldModStartExe(PKLDRDYLDMOD pMod);
|
---|
162 |
|
---|
163 | int kldrDyldModGetName(PKLDRDYLDMOD pMod, char *pszName, size_t cchName);
|
---|
164 | int kldrDyldModGetFilename(PKLDRDYLDMOD pMod, char *pszFilename, size_t cchFilename);
|
---|
165 | int kldrDyldModQuerySymbol(PKLDRDYLDMOD pMod, uint32_t uSymbolOrdinal, const char *pszSymbolName, uintptr_t *pValue, uint32_t *pfKind);
|
---|
166 |
|
---|
167 |
|
---|
168 | void kldrDyldFailure(const char *pszFilename, ...);
|
---|
169 |
|
---|
170 |
|
---|
171 | /** Pointer to the head module (the executable). */
|
---|
172 | extern PKLDRDYLDMOD kLdrDyldModuleHead;
|
---|
173 | /** Pointer to the tail module. */
|
---|
174 | extern PKLDRDYLDMOD kLdrDyldModuleTail;
|
---|
175 | /** The Library search path. */
|
---|
176 | extern char kLdrDyldLibraryPath[4096];
|
---|
177 | /** The global error buffer. */
|
---|
178 | extern char g_szkLdrDyldError[1024];
|
---|
179 |
|
---|
180 |
|
---|
181 | /** @} */
|
---|
182 | #ifdef __cplusplus
|
---|
183 | }
|
---|
184 | #endif
|
---|
185 |
|
---|
186 | #endif
|
---|