Changeset 2825 for trunk/kLdr/kLdr.h


Ignore:
Timestamp:
Oct 22, 2006, 5:57:19 PM (19 years ago)
Author:
bird
Message:

heap and file provider.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdr.h

    r2824 r2825  
    3434/* kLdr depend on size_t, [u]intNN_t, [u]intptr_t and some related constants. */
    3535#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
     38typedef signed char         int8_t;
     39typedef unsigned char       uint8_t;
     40typedef signed short        int16_t;
     41typedef unsigned short      uint16_t;
     42typedef signed int          int32_t;
     43typedef unsigned int        uint32_t;
     44typedef signed __int64      int64_t;
     45typedef unsigned __int64    uint64_t;
     46typedef 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. */
     56typedef struct KLDRRDR *PKLDRRDR;
     57/** Pointer to a file provider instance core pointer. */
     58typedef struct KLDRRDR **PPKLDRRDR;
     59
     60/**
     61 * File provider instance operations.
     62 */
     63typedef 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. */
     129typedef KLDRRDROPS *PKLDRRDROPS;
     130/** Pointer to const file provider operations. */
     131typedef const KLDRRDROPS *PCKLDRRDROPS;
     132
     133
     134/**
     135 * File provider instance core.
     136 */
     137typedef struct KLDRRDR
     138{
     139    /** Pointer to the file provider operations. */
     140    PCKLDRRDROPS pOps;
     141} KLDRRDR;
     142
     143void    kLdrRdrAddProvider(PKLDRRDROPS pAdd);
     144
     145int     kLdrRdrOpen(    PPKLDRRDR ppRdr, const char *pszFilename);
     146int     kLdrRdrClose(   PKLDRRDR pRdr);
     147int     kLdrRdrRead(    PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
     148int     kLdrRdrAllMap(  PKLDRRDR pRdr, const void **ppvBits);
     149int     kLdrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits);
     150off_t   kLdrRdrSize(    PKLDRRDR pRdr);
     151off_t   kLdrRdrTell(    PKLDRRDR pRdr);
     152const char *kLdrRdrName(PKLDRRDR pRdr);
     153
     154/** @} */
     155
     156
     157
     158/** @defgroup grp_kLdrMod   kLdrMod - The executable image intepreter
     159 * @{ */
    41160
    42161/**
     
    81200
    82201/**
    83  * The state of a module.
    84  */
    85 typedef enum KLDRSTATE
    86 {
    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 = 0x7fffffff
    104 } KLDRSTATE;
    105 
    106 
    107 /**
    108202 * Loader module.
    109203 */
    110204typedef struct KLDRMOD
    111205{
    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;
    118210    /** The module data. */
    119211    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;
    138212    /** The filename length (bytes). */
    139213    uint32_t            cchFilename;
     
    150224} KLDRMOD, *PKLDRMOD, **PPKLDRMOD;
    151225
    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
     227int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod);
     228int kLdrModClose(PKLDRMOD pMod);
     229int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, unsigned *pfType);
     230int kLdrModGetSymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, unsigned *pfType);
     231
     232size_t kLdrModSize(PKLDRMOD pMod);
     233
     234typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, uintmax_t *pValue, void *pvUser);
     235typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
     236int kLdrModGetBits(PKLDRMOD pMod, void *pvBits, uintmax_t BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
     237int kLdrModRelocate(PKLDRMOD pMod, void *pvBits, uintmax_t NewBaseAddress, uintmax_t OldBaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
     238
     239typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, const char *pszSymbol, unsigned uSymbol, uintmax_t Value, void *pvUser);
     240typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
     241int 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*/
     257typedef struct KLDRDY *PKLDRDY;
     258
     259/*
     260int kLdrLoadDll(const char *pszFilename, unsigned fFlags, unsigned long *pvmod);
     261*/
    158262
    159263/** @name Process Bootstrapping
     
    176280/** @} */
    177281
    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/** @} */
    195283
    196284#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.