Changeset 2825 for trunk/kLdr/kLdr.h
- Timestamp:
- Oct 22, 2006, 5:57:19 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdr.h
r2824 r2825 34 34 /* kLdr depend on size_t, [u]intNN_t, [u]intptr_t and some related constants. */ 35 35 #include <sys/types.h> 36 #include <stdint.h> 37 38 39 /** A KLDRMOD handle. */ 40 typedef struct KLDRMOD *HKLDRMOD; 36 #include <stddef.h> 37 #ifdef _MSC_VER 38 typedef signed char int8_t; 39 typedef unsigned char uint8_t; 40 typedef signed short int16_t; 41 typedef unsigned short uint16_t; 42 typedef signed int int32_t; 43 typedef unsigned int uint32_t; 44 typedef signed __int64 int64_t; 45 typedef unsigned __int64 uint64_t; 46 typedef uint64_t uintmax_t; 47 #else 48 # include <stdint.h> 49 #endif 50 51 52 /** @defgroup grp_kLdrRdr kLdrRdr - The file provider 53 * @{ */ 54 55 /** Pointer to a file provider instance core. */ 56 typedef struct KLDRRDR *PKLDRRDR; 57 /** Pointer to a file provider instance core pointer. */ 58 typedef struct KLDRRDR **PPKLDRRDR; 59 60 /** 61 * File provider instance operations. 62 */ 63 typedef struct KLDRRDROPS 64 { 65 /** The name of this file provider. */ 66 const char *pszName; 67 /** Pointer to the next file provider. */ 68 const struct KLDRRDROPS *pNext; 69 70 /** Try create a new file provider instance. 71 * 72 * @returns 0 on success, OS specific error code on failure. 73 * @param ppRdr Where to store the file provider instance. 74 * @param pszFilename The filename to open. 75 */ 76 int (* pfnCreate)( PPKLDRRDR ppRdr, const char *pszFilename); 77 /** Destroy the file provider instance. 78 * 79 * @returns 0 on success, OS specific error code on failure. 80 * On failure, the file provider instance will be in an indeterminate state - don't touch it! 81 * @param pRdr The file provider instance. 82 */ 83 int (* pfnDestroy)( PKLDRRDR pRdr); 84 /** Read bits from the file. 85 * 86 * @returns 0 on success, OS specific error code on failure. 87 * @param pRdr The file provider instance. 88 * @param pvBuf Where to put the bits. 89 * @param cb The number of bytes to read. 90 * @param off Where to start reading. 91 */ 92 int (* pfnRead)( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off); 93 /** Map all the file bits into memory (read only). 94 * 95 * @returns 0 on success, OS specific error code on failure. 96 * @param pRdr The file provider instance. 97 * @param ppvBits Where to store the address of the mapping. 98 * The size can be obtained using pfnSize. 99 */ 100 int (* pfnAllMap)( PKLDRRDR pRdr, const void **ppvBits); 101 /** Unmap a file bits mapping obtained by KLDRRDROPS::pfnAllMap. 102 * 103 * @returns 0 on success, OS specific error code on failure. 104 * @param pRdr The file provider instance. 105 * @param pvBits The mapping address. 106 */ 107 int (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits); 108 /** @todo generic mmap/MapViewOfFile */ 109 /** Get the file size. 110 * 111 * @returns The file size. Returns -1 on failure. 112 * @param pRdr The file provider instance. 113 */ 114 off_t (* pfnSize)( PKLDRRDR pRdr); 115 /** Get the file pointer offset. 116 * 117 * @returns The file pointer offset. Returns -1 on failure. 118 * @param pRdr The file provider instance. 119 */ 120 off_t (* pfnTell)( PKLDRRDR pRdr); 121 /** Get the file name. 122 * 123 * @returns The file size. Returns -1 on failure. 124 * @param pRdr The file provider instance. 125 */ 126 const char * (* pfnName)(PKLDRRDR pRdr); 127 } KLDRRDROPS; 128 /** Pointer to file provider operations. */ 129 typedef KLDRRDROPS *PKLDRRDROPS; 130 /** Pointer to const file provider operations. */ 131 typedef const KLDRRDROPS *PCKLDRRDROPS; 132 133 134 /** 135 * File provider instance core. 136 */ 137 typedef struct KLDRRDR 138 { 139 /** Pointer to the file provider operations. */ 140 PCKLDRRDROPS pOps; 141 } KLDRRDR; 142 143 void kLdrRdrAddProvider(PKLDRRDROPS pAdd); 144 145 int kLdrRdrOpen( PPKLDRRDR ppRdr, const char *pszFilename); 146 int kLdrRdrClose( PKLDRRDR pRdr); 147 int kLdrRdrRead( PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off); 148 int kLdrRdrAllMap( PKLDRRDR pRdr, const void **ppvBits); 149 int kLdrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits); 150 off_t kLdrRdrSize( PKLDRRDR pRdr); 151 off_t kLdrRdrTell( PKLDRRDR pRdr); 152 const char *kLdrRdrName(PKLDRRDR pRdr); 153 154 /** @} */ 155 156 157 158 /** @defgroup grp_kLdrMod kLdrMod - The executable image intepreter 159 * @{ */ 41 160 42 161 /** … … 81 200 82 201 /** 83 * The state of a module.84 */85 typedef enum KLDRSTATE86 {87 /** The usual invalid 0 enum. */88 KLDRSTATE_INVALID = 0,89 /** kldrOpen succeeded.90 * Modules in this state will be freed at */91 KLDRSTATE_OPEN,92 /** Dependencies has been loaded. */93 KLDRSTATE_DEPS,94 /** Fixups has been applied. */95 KLDRSTATE_FIXED,96 /** The module has been initialized. */97 KLDRSTATE_INITED,98 /** The module is loaded successfully. */99 KLDRSTATE_LOADED,100 /** The end of valid states (exclusive) */101 KLDRSTATE_END,102 /** The usual 32-bit blowup. */103 KLDRSTATE_32BIT_HACK = 0x7fffffff104 } KLDRSTATE;105 106 107 /**108 202 * Loader module. 109 203 */ 110 204 typedef struct KLDRMOD 111 205 { 112 /** Pointer to the next module. */ 113 struct KLDRMOD *pNext; 114 /** Pointer to the previous module. */ 115 struct KLDRMOD *pPrev; 116 /** Our module handle. */ 117 HKLDRMOD hmod; 206 /** Magic number. */ 207 uint32_t u32Magic; 208 /** The type of module this is. */ 209 KLDRTYPE enmType; 118 210 /** The module data. */ 119 211 void *pvData; 120 /** The type of module this is. */121 KLDRTYPE enmType;122 /** The module state. */123 KLDRSTATE enmState;124 /** The number of references. */125 uint32_t cRefs;126 /** The number of dynamic references. */127 uint32_t cDynRefs;128 /** Magic number. */129 uint32_t u32Magic;130 /** Set if this is the executable module. */131 uint32_t fExecutable : 1;132 /** Global DLL (set) or specific DLL (clear). */133 uint32_t fGlobal : 1;134 /** Load stage one. */135 uint32_t fLoadStageOne : 1;136 /** Reserved for future use. */137 uint32_t fReserved : 29;138 212 /** The filename length (bytes). */ 139 213 uint32_t cchFilename; … … 150 224 } KLDRMOD, *PKLDRMOD, **PPKLDRMOD; 151 225 152 /** Pointer to the head module (the executable). */ 153 extern PKLDRMOD kLdrModuleHead; 154 /** Pointer to the tail module. */ 155 extern PKLDRMOD kLdrModuleTail; 156 /** The Library search path. */ 157 extern char kLdrLibraryPath[4096]; 226 227 int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod); 228 int kLdrModClose(PKLDRMOD pMod); 229 int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, unsigned *pfType); 230 int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, unsigned *pfType); 231 232 size_t kLdrModSize(PKLDRMOD pMod); 233 234 typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, uintmax_t *pValue, void *pvUser); 235 typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT; 236 int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, uintmax_t BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 237 int kLdrModRelocate(PKLDRMOD pMod, void *pvBits, uintmax_t NewBaseAddress, uintmax_t OldBaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser); 238 239 typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, const char *pszSymbol, unsigned uSymbol, uintmax_t Value, void *pvUser); 240 typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS; 241 int kLdrModEnumSymbols(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, uintmax_t BaseAddress, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser); 242 /** @name kLdrModEnumSymbols flags. 243 * @{ */ 244 /** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */ 245 #define KLDRMOD_ENUM_SYMBOL_FLAGS_ALL 0x00000001 246 /** @} */ 247 248 /** @} */ 249 250 251 252 253 /** @defgroup grp_kLdrDy kLdrDy - The dynamic loader 254 * @{ */ 255 256 /** The h*/ 257 typedef struct KLDRDY *PKLDRDY; 258 259 /* 260 int kLdrLoadDll(const char *pszFilename, unsigned fFlags, unsigned long *pvmod); 261 */ 158 262 159 263 /** @name Process Bootstrapping … … 176 280 /** @} */ 177 281 178 /** @name The Internal APIs 179 * @internal 180 * @{ */ 181 int kldrOpenExe(const char *pszFilename, PPKLDRMOD ppMod) 182 int kldrOpen(const char *pszFilename, unsigned fFlags, PPKLDRMOD ppMod); 183 int kldrClose(PKLDRMOD pMod); 184 185 void kldrFailure(const char *pszFilename, ...); 186 /** @} */ 187 188 /* 189 int kLdrLoadDll(const char *pszFilename, unsigned fFlags, unsigned long *pvmod); 190 */ 191 192 #ifndef NULL 193 # define NULL 0 194 #endif 282 /** @} */ 195 283 196 284 #ifdef __cplusplus
Note:
See TracChangeset
for help on using the changeset viewer.