/* $Id: $ */ /** @file * * kLdr - The Dynamic Loader. * * Copyright (c) 2006 knut st. osmundsen * * * This file is part of kLdr. * * kLdr is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * kLdr is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with kLdr; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #ifndef __kLdr_h__ #define __kLdr_h__ #ifdef __cplusplus extern "C" { #endif #include #include /** A KLDRMOD handle. */ typedef struct KLDRMOD *HKLDRMOD; /** * Loader segment. */ typedef struct KLDRSEG { /** The segment load address. */ void *pv; /** The size of the segment. */ size_t cb; /** The segment is readable. */ uint32_t fRead : 1; /** The segment is writable. */ uint32_t fWrite : 1; /** The segment is executable. */ uint32_t fExecute : 1; /** Reserved for future use. */ uint32_t fReserved : 29; /** Reserved for future use. */ uint32_t u32Reserved; } KLDRSEG, *PKLDRSEG; /** * Loader module type. */ typedef enum KLDRTYPE { /** The usual invalid 0 type. */ KLDRTYPE_INVALID = 0, /** The native OS loader. */ KLDRTYPE_NATIVE, /** The LX loader. */ KLDRTYPE_LX, /** The end type (not included). */ KLDRTYPE_END, /** Hack to blow the type up to 32-bit. */ KLDRTYPE_32BIT_HACK = 0x7fffffff } KLDRTYPE; /** * The state of a module. */ typedef enum KLDRSTATE { /** The usual invalid 0 enum. */ KLDRSTATE_INVALID = 0, /** kldrOpen succeeded. * Modules in this state will be freed at */ KLDRSTATE_OPEN, /** Dependencies has been loaded. */ KLDRSTATE_DEPS, /** Fixups has been applied. */ KLDRSTATE_FIXED, /** The module has been initialized. */ KLDRSTATE_INITED, /** The module is loaded successfully. */ KLDRSTATE_LOADED, /** The end of valid states (exclusive) */ KLDRSTATE_END, /** The usual 32-bit blowup. */ KLDRSTATE_32BIT_HACK = 0x7fffffff } KLDRSTATE; /** * Loader module. */ typedef struct KLDRMOD { /** Pointer to the next module. */ struct KLDRMOD *pNext; /** Pointer to the previous module. */ struct KLDRMOD *pPrev; /** Our module handle. */ HKLDRMOD hmod; /** The module data. */ void *pvData; /** The type of module this is. */ KLDRTYPE enmType; /** The module state. */ KLDRSTATE enmState; /** The number of references. */ uint32_t cRefs; /** The number of dynamic references. */ uint32_t cDynRefs; /** Magic number. */ uint32_t u32Magic; /** Set if this is the executable module. */ uint32_t fExecutable : 1; /** Global DLL (set) or specific DLL (clear). */ uint32_t fGlobal : 1; /** Load stage one. */ uint32_t fLoadStageOne : 1; /** Reserved for future use. */ uint32_t fReserved : 29; /** The filename length (bytes). */ uint32_t cchFilename; /** The filename. */ const char *pszFilename; /** The module name. */ const char *pszName; /** The module name length (bytes). */ uint32_t cchName; /** The number of segments in the module. */ uint32_t cSegments; /** Segments. (variable size, can be zero) */ KLDRSEG aSegments[1]; } KLDRMOD, *PKLDRMOD, **PPKLDRMOD; /** Pointer to the head module (the executable). */ extern PKLDRMOD kLdrModuleHead; /** Pointer to the tail module. */ extern PKLDRMOD kLdrModuleTail; /** The Library search path. */ extern char kLdrLibraryPath[4096]; /** @name Process Bootstrapping * @{ */ /** * Argument package from the stub. */ typedef struct KLDREXEARGS { /** Flags. (Currently unused, MBZ.) */ uint32_t fFlags; /** The executable file that the stub is supposed to load. */ char szExecutable[260]; /** The LD_LIBRARY_PATH prefix for the process.. */ char szLibPath[4096 - 260 - sizeof(uint32_t)]; } KLDREXEARGS, *PKLDREXEARGS; void kLdrLoadExe(PKLDREXEARGS pArgs); /** @} */ /** @name The Internal APIs * @internal * @{ */ int kldrOpenExe(const char *pszFilename, PPKLDRMOD ppMod) int kldrOpen(const char *pszFilename, unsigned fFlags, PPKLDRMOD ppMod); int kldrClose(PKLDRMOD pMod); void kldrFailure(const char *pszFilename, ...); /** @} */ /* int kLdrLoadDll(const char *pszFilename, unsigned fFlags, unsigned long *pvmod); */ #ifndef NULL # define NULL 0 #endif #ifdef __cplusplus } #endif #endif