Changeset 2856 for trunk/kLdr/kLdr.h


Ignore:
Timestamp:
Nov 4, 2006, 11:19:33 PM (19 years ago)
Author:
bird
Message:

More code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdr.h

    r2855 r2856  
    136136     */
    137137    int     (* pfnDestroy)( PKLDRRDR pRdr);
    138     /** Read bits from the file.
    139      *
    140      * @returns 0 on success, OS specific error code on failure.
    141      * @param   pRdr        The file provider instance.
    142      * @param   pvBuf       Where to put the bits.
    143      * @param   cb          The number of bytes to read.
    144      * @param   off         Where to start reading.
    145      */
     138    /** @copydoc kLdrRdrRead */
    146139    int     (* pfnRead)(    PKLDRRDR pRdr, void *pvBuf, size_t cb, off_t off);
    147     /** Map all the file bits into memory (read only).
    148      *
    149      * @returns 0 on success, OS specific error code on failure.
    150      * @param   pRdr        The file provider instance.
    151      * @param   ppvBits     Where to store the address of the mapping.
    152      *                      The size can be obtained using pfnSize.
    153      */
     140    /** @copydoc kLdrRdrAllMap */
    154141    int     (* pfnAllMap)(  PKLDRRDR pRdr, const void **ppvBits);
    155     /** Unmap a file bits mapping obtained by KLDRRDROPS::pfnAllMap.
    156      *
    157      * @returns 0 on success, OS specific error code on failure.
    158      * @param   pRdr        The file provider instance.
    159      * @param   pvBits      The mapping address.
    160      */
     142    /** @copydoc kLdrRdrAllUnmap */
    161143    int     (* pfnAllUnmap)(PKLDRRDR pRdr, const void *pvBits);
    162     /** Get the file size.
    163      *
    164      * @returns The file size. Returns -1 on failure.
    165      * @param   pRdr        The file provider instance.
    166      */
     144    /** @copydoc kLdrRdrSize */
    167145    off_t   (* pfnSize)(    PKLDRRDR pRdr);
    168     /** Get the file pointer offset.
    169      *
    170      * @returns The file pointer offset. Returns -1 on failure.
    171      * @param   pRdr        The file provider instance.
    172      */
     146    /** @copydoc kLdrRdrTell */
    173147    off_t   (* pfnTell)(    PKLDRRDR pRdr);
    174     /** Get the file name.
    175      *
    176      * @returns The file size. Returns -1 on failure.
    177      * @param   pRdr        The file provider instance.
    178      */
     148    /** @copydoc kLdrRdrName */
    179149    const char * (* pfnName)(PKLDRRDR pRdr);
    180     /**
    181      * Prepares a memory region to map file sections into.
    182      *
    183      * @returns 0 on success, OS specific error code on failure.
    184      * @param   pRdr        The file provider instance.
    185      * @param   ppv         If fFixed is set, *ppv contains the memory location which
    186      *                      the region should be based at. If fFixed is clear the OS
    187      *                      is free to choose the location.
    188      *                      On successful return *ppv contains address of the prepared
    189      *                      memory region.
    190      * @param   cb          The size of the memory region to prepare.
    191      * @param   fFixed      When set *ppv will contain the desired region address.
    192      *
    193      */
     150    /** @copydoc kLdrRdrPageSize */
     151    size_t  (* pfnPageSize)(PKLDRRDR pRdr);
     152    /** @copydoc kLdrRdrPrepare */
    194153    int     (* pfnPrepare)(PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed);
    195     /**
    196      * Maps a section of the file into the memory region reserved by pfnPrepare.
    197      *
    198      * @returns 0 on success, OS specific error code on failure.
    199      * @param   pRdr        The file provider instance.
    200      * @param   pv          The address in the prepared region.
    201      * @param   cb          The size of the memory mapping.
    202      * @param   enmProt     The desired memory protection.
    203      * @param   offFile     The start of the raw file bytes.
    204      * @param   cbFile      The number of raw file bytes. This must be less or equal to cb.
    205      */
     154    /** @copydoc kLdrRdrMap */
    206155    int     (* pfnMap)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile);
    207     /**
    208      * Changes the page protection of a section mapped using pfnMap.
    209      *
    210      * This is typically used for applying fixups and similar.
    211      *
    212      * @returns 0 on success, OS specific error code on failure.
    213      * @param   pRdr        The file provider instance.
    214      * @param   pv          The address passed to pfnMap.
    215      * @param   cb          The size passed to pfnMap.
    216      * @param   enmProt     The desired memory protection.
    217      */
     156    /** @copydoc kLdrRdrRefreshMap */
     157    int     (* pfnRefreshMap)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile);
     158    /** @copydoc kLdrRdrProtect */
    218159    int     (* pfnProtect)(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt);
    219     /**
    220      * Unmaps a section of the file previously mapped using pfnMap.
    221      *
    222      * @returns 0 on success, OS specific error code on failure.
    223      * @param   pRdr        The file provider instance.
    224      * @param   pv          The address passed to pfnMap.
    225      * @param   cb          The size passed to pfnMap.
    226      */
     160    /** @copydoc kLdrRdrUnmap */
    227161    int     (* pfnUnmap)(PKLDRRDR pRdr, void *pv, size_t cb);
    228     /**
    229      * Releases the memory region prepared by pfnPrepare().
    230      *
    231      * Before calling this function, all sections mapped by pfnMap must first be unmapped by calling pfnUnmap.
    232      *
    233      * @returns 0 on success, OS specific error code on failure.
    234      * @param   pRdr        The file provider instance.
    235      * @param   pv          The address of the prepared region.
    236      * @param   cb          The size of the prepared region.
    237      */
     162    /** @copydoc kLdrRdrUnprepare */
    238163    int     (* pfnUnprepare)(PKLDRRDR pRdr, void *pv, size_t cb);
    239     /**
    240      * We're done reading from the file but would like to keep file mappings.
    241      *
    242      * If the OS support closing the file handle while the file is mapped,
    243      * the reader should do so.
    244      *
    245      * @param   pRdr        The file provider instance.
    246      */
     164    /** @copydoc kLdrRdrDone */
    247165    void    (* pfnDone)(PKLDRRDR pRdr);
    248166    /** The usual non-zero dummy that makes sure we've initialized all members. */
     
    260178typedef struct KLDRRDR
    261179{
     180    /** Magic number (KLDRRDR_MAGIC). */
     181    uint32_t     u32Magic;
    262182    /** Pointer to the file provider operations. */
    263183    PCKLDRRDROPS pOps;
    264184} KLDRRDR;
     185
     186/** The magic for KLDRRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */
     187#define KLDRRDR_MAGIC   0x19610919
    265188
    266189void    kLdrRdrAddProvider(PKLDRRDROPS pAdd);
     
    274197off_t   kLdrRdrTell(    PKLDRRDR pRdr);
    275198const char *kLdrRdrName(PKLDRRDR pRdr);
     199size_t  kLdrRdrPageSize(PKLDRRDR pRdr);
     200int     kLdrRdrPrepare( PKLDRRDR pRdr, void **ppv, size_t cb, unsigned fFixed);
     201int     kLdrRdrMap(     PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile);
     202int     kLdrRdrRefreshMap(PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt, off_t offFile, size_t cbFile);
     203int     kLdrRdrProtect( PKLDRRDR pRdr, void *pv, size_t cb, KLDRPROT enmProt);
     204int     kLdrRdrUnmap(   PKLDRRDR pRdr, void *pv, size_t cb);
     205int     kLdrRdrUnprepare(PKLDRRDR pRdr, void *pv, size_t cb);
     206void    kLdrRdrDone(    PKLDRRDR pRdr);
    276207
    277208/** @} */
     
    399330    /** The usual invalid enum value. */
    400331    KLDRDBGINFOTYPE_INVALID = 0,
     332    /** Unknown debug info format. */
     333    KLDRDBGINFOTYPE_UNKNOWN,
    401334    /** Stabs. */
    402335    KLDRDBGINFOTYPE_STABS,
     
    456389    /** The size of the segment. */
    457390    KLDRSIZE        cb;
    458     /** The required segment alignment. */
     391    /** The required segment alignment.
     392     * The to 0 if the segment isn't supposed to be mapped. */
    459393    KLDRADDR        Alignment;
    460394    /** The link address.
    461      * Set to NIL_KLDRADDR if the segment isn't supposed to be mapped. */
     395     * Set to NIL_KLDRADDR if the segment isn't supposed to be
     396     * mapped or if the image doesn't have link addresses. */
    462397    KLDRADDR        LinkAddress;
    463     /** The address the segment was mapped at by kLdrModMap().
    464      * Set to NIL_KLDRADDR if not mapped. */
    465     KLDRADDR        MapAddress;
    466398    /** The segment protection. */
    467399    KLDRPROT        enmProt;
     400    /** The address the segment was mapped at by kLdrModMap().
     401     * Set to 0 if not mapped. */
     402    uintptr_t       MapAddress;
     403    /** File offset of the segment.
     404     * Set to -1 if no file backing (like BSS). */
     405    off_t           offFile;
     406    /** Size of the file bits of the segment.
     407     * Set to -1 if no file backing (like BSS). */
     408    off_t           cbFile;
    468409} KLDRSEG;
    469410/** Pointer to a loader segment. */
     
    563504typedef struct KLDRMOD
    564505{
    565     /** Magic number. */
     506    /** Magic number (KLDRMOD_MAGIC). */
    566507    uint32_t            u32Magic;
    567508    /** The format of this module. */
     
    696637 *
    697638 * @param   pMod        The module.
     639 * @param   iDbgInfo    The debug info ordinal number / id.
    698640 * @param   enmType     The debug info type.
    699  * @param   iDbgInfo    The debug info ordinal number / id.
     641 * @param   iMajorVer   The major version number of the debug info format. -1 if unknow - implies invalid iMinorVer.
     642 * @param   iMinorVer   The minor version number of the debug info format. -1 when iMajorVer is -1.
    700643 * @param   offFile     The file offset *if* this type has one specific location in the executable image file.
    701644 *                      This is -1 if there isn't any specific file location.
    702  * @param   cbFile      The file size.
    703  *                      This is 0 if there isn't any specific file location.
     645 * @param   LinkAddress The link address of the debug info if it's loadable. NIL_KLDRADDR if not loadable.
     646 * @param   cb          The size of the debug information. -1 is used if this isn't applicable.
    704647 * @param   pszExtFile  This points to the name of an external file containing the debug info.
    705648 *                      This is NULL if there isn't any external file.
    706649 * @param   pvUser      The user parameter specified to kLdrModEnumDbgInfo.
    707650 */
    708 typedef int FNKLDRENUMDBG(PKLDRMOD pMod, KLDRDBGINFOTYPE enmType, uint32_t iDbgInfo, off_t offFile, off_t cbFile,
    709                           const char *pszExtFile, void *pvUser);
     651typedef int FNKLDRENUMDBG(PKLDRMOD pMod, uint32_t iDbgInfo, KLDRDBGINFOTYPE enmType, int16_t iMajorVer, int16_t iMinorVer,
     652                          off_t offFile, KLDRADDR LinkAddress, off_t cb, const char *pszExtFile, void *pvUser);
     653/** Pointer to a debug info enumberator callback. */
     654typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;
    710655
    711656int     kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod);
     
    724669int     kLdrModGetStackInfo(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
    725670int     kLdrModQueryMainEntrypoint(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
    726 /** Pointer to a debug info enumberator callback. */
    727 typedef FNKLDRENUMDBG *PFNKLDRENUMDBG;
    728671int     kLdrModEnumDbgInfo(PKLDRMOD pMod, const void *pvBits, PFNKLDRENUMDBG pfnCallback, void *pvUser);
    729672int     kLdrModHasDbgInfo(PKLDRMOD pMod, const void *pvBits);
     
    737680int     kLdrModReload(PKLDRMOD pMod);
    738681int     kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    739 int     kLdrModCallInit(PKLDRMOD pMod);
    740 int     kLdrModCallTerm(PKLDRMOD pMod);
    741 int     kLdrModCallThread(PKLDRMOD pMod, unsigned fAttachingOrDetaching);
     682int     kLdrModCallInit(PKLDRMOD pMod, uintptr_t uHandle);
     683int     kLdrModCallTerm(PKLDRMOD pMod, uintptr_t uHandle);
     684int     kLdrModCallThread(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching);
    742685/** @} */
    743686
    744687/** @name Operations On The Externally Managed Mappings
    745688 * @{ */
    746 size_t kLdrModSize(PKLDRMOD pMod);
     689KLDRADDR kLdrModSize(PKLDRMOD pMod);
    747690int     kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    748691int     kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
     
    818761    int (* pfnFixupMapping)(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    819762    /** @copydoc kLdrModCallInit */
    820     int (* pfnCallInit)(PKLDRMOD pMod);
     763    int (* pfnCallInit)(PKLDRMOD pMod, uintptr_t uHandle);
    821764    /** @copydoc kLdrModCallTerm */
    822     int (* pfnCallTerm)(PKLDRMOD pMod);
     765    int (* pfnCallTerm)(PKLDRMOD pMod, uintptr_t uHandle);
    823766    /** @copydoc kLdrModCallThread */
    824     int (* pfnCallThread)(PKLDRMOD pMod, unsigned fAttachingOrDetaching);
     767    int (* pfnCallThread)(PKLDRMOD pMod, uintptr_t uHandle, unsigned fAttachingOrDetaching);
    825768    /** @copydoc kLdrModSize */
    826     size_t (* pfnSize)(PKLDRMOD pMod);
     769    KLDRADDR (* pfnSize)(PKLDRMOD pMod);
    827770    /** @copydoc kLdrModGetBits */
    828771    int (* pfnGetBits)(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
     
    1052995/** A forwarder chain was too long. */
    1053996#define KLDR_ERR_TOO_LONG_FORWARDER_CHAIN                   (KLDR_ERR_BASE + 51)
     997/** The module has no debug info. */
     998#define KLDR_ERR_NO_DEBUG_INFO                              (KLDR_ERR_BASE + 52)
     999/** The module is already mapped.
     1000 * kLdrModMap() can only be called once (without kLdrModUnmap() in between). */
     1001#define KLDR_ERR_ALREADY_MAPPED                             (KLDR_ERR_BASE + 53)
     1002/** The module was not mapped.
     1003 * kLdrModUnmap() should not called without being preceeded by a kLdrModMap(). */
     1004#define KLDR_ERR_NOT_MAPPED                                 (KLDR_ERR_BASE + 54)
    10541005
    10551006/** @name kLdrModPE status codes
Note: See TracChangeset for help on using the changeset viewer.