Changeset 2848


Ignore:
Timestamp:
Nov 2, 2006, 1:08:16 AM (19 years ago)
Author:
bird
Message:

stubbed all the interpreter entry points.

Location:
trunk/kLdr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/kLdr/kLdr.h

    r2847 r2848  
    5353/** @defgroup grp_kLdrRdr   kLdrRdr - The file provider
    5454 * @{ */
     55
     56/** The kLdr address type. */
     57typedef uint64_t KLDRADDR;
     58/** Pointer to a kLdr address. */
     59typedef KLDRADDR *PKLDRADDR;
     60/** Pointer to a const kLdr address. */
     61typedef const KLDRADDR *PCKLDRADDR;
     62
     63/** NIL address. */
     64#define NIL_KLDRADDR    (~(uint64_t)0)
     65
     66/** The kLdr size type. */
     67typedef uint64_t KLDRSIZE;
     68/** Pointer to a kLdr size. */
     69typedef KLDRSIZE *PKLDRSIZE;
     70/** Pointer to a const kLdr size. */
     71typedef const KLDRSIZE *PCKLDRSIZE;
     72
     73
    5574
    5675/**
     
    268287typedef struct KLDRSTACKINFO
    269288{
     289    /** The base address of the stack (sub) segment.
     290     * Set this to NIL_KLDRADDR if the module doesn't include any stack segment. */
     291    KLDRADDR        Address;
    270292    /** The base address of the stack (sub) segment, link address.
    271      * Set this to ~(uintmax_t)0 if the module doesn't include any stack (sub)segment. */
    272     uintmax_t           uLinkAddress;
    273     /** The base address of the stack (sub) segment, actual load address.
    274      * Set this to ~(uintmax_t)0 if the module doesn't include any stack (sub)segment or if
    275      * the module isn't mapped (loaded) yet. */
    276     uintmax_t           uLoadAddress;
     293     * Set this to NIL_KLDRADDR if the module doesn't include any stack (sub)segment. */
     294    KLDRADDR        LinkAddress;
    277295    /** The stack size of the main thread.
    278296     * If no stack (sub)segment in the module, this is the stack size of the main thread.
    279297     * If the module doesn't contain this kind of information this field will be set to 0. */
    280     uintmax_t           cbStack;
     298    KLDRSIZE        cbStack;
    281299    /** The stack size of non-main threads.
    282300     * If the module doesn't contain this kind of information this field will be set to 0. */
    283     uintmax_t           cbStackThread;
    284 } KLDRSTACKINFO, *PKLDRSTACKINFO;
     301    KLDRSIZE        cbStackThread;
     302} KLDRSTACKINFO;
     303/** Pointer to stack information. */
     304typedef KLDRSTACKINFO *PKLDRSTACKINFO;
     305/** Pointer to const stack information. */
     306typedef const KLDRSTACKINFO *PCKLDRSTACKINFO;
    285307
    286308
     
    295317    const char     *pszName;
    296318    /** The size of the segment. */
    297     uintmax_t       cb;
     319    KLDRSIZE        cb;
    298320    /** The link time load address. */
    299     uintmax_t       LinkAddress;
    300     /** The actual load address (if loaded). */
    301     uintmax_t       LoadAddress;
     321    KLDRADDR        LinkAddress;
     322    /** The address the segment was mapped at by kLdrModMap().
     323     * Set to NIL_KLDRADDR if not mapped. */
     324    KLDRADDR        MapAddress;
    302325    /** The segment protection. */
    303326    KLDRPROT        enmProt;
    304 } KLDRSEG, *PKLDRSEG;
     327} KLDRSEG;
     328/** Pointer to a loader segment. */
     329typedef KLDRSEG *PKLDRSEG;
     330/** Pointer to a loader segment. */
     331typedef const KLDRSEG *PCKLDRSEG;
    305332
    306333
     
    513540
    514541/** Special base address value alias for the link address. */
    515 #define KLDRMOD_BASEADDRESS_LINK            (~(uintmax_t)1)
     542#define KLDRMOD_BASEADDRESS_LINK            (~(KLDRADDR)1)
    516543/** Special base address value alias for the actual load address (must be mapped). */
    517 #define KLDRMOD_BASEADDRESS_MAP             (~(uintmax_t)2)
     544#define KLDRMOD_BASEADDRESS_MAP             (~(KLDRADDR)2)
     545
     546/** Special import module ordinal value used to indicate that there is no
     547 * specific module associated with the requested symbol. */
     548#define NIL_KLDRMOD_IMPORT                 (~(uint32_t)0)
     549
     550/** Special symbol ordinal value used to indicate that the symbol
     551 * only has a string name. */
     552#define NIL_KLDRMOD_SYM_ORDINAL            (~(uint32_t)0)
     553
    518554
    519555/** @name Load symbol kind flags.
    520556 * @{ */
    521557/** The bitness doesn't matter. */
    522 #define KLDRSYMKIND_NO_BIT          0x00000000
     558#define KLDRSYMKIND_NO_BIT                  0x00000000
    523559/** 16-bit symbol. */
    524 #define KLDRSYMKIND_16BIT           0x00000001
     560#define KLDRSYMKIND_16BIT                   0x00000001
    525561/** 32-bit symbol. */
    526 #define KLDRSYMKIND_32BIT           0x00000002
     562#define KLDRSYMKIND_32BIT                   0x00000002
    527563/** 64-bit symbol. */
    528 #define KLDRSYMKIND_64BIT           0x00000003
     564#define KLDRSYMKIND_64BIT                   0x00000003
    529565/** Mask out the bit.*/
    530 #define KLDRSYMKIND_BIT_MASK        0x00000003
     566#define KLDRSYMKIND_BIT_MASK                0x00000003
    531567/** We don't know the type of symbol. */
    532 #define KLDRSYMKIND_NO_TYPE         0x00000000
     568#define KLDRSYMKIND_NO_TYPE                 0x00000000
    533569/** The symbol is a code object (method/function/procedure/whateveryouwannacallit). */
    534 #define KLDRSYMKIND_CODE            0x00000010
     570#define KLDRSYMKIND_CODE                    0x00000010
    535571/** The symbol is a data object. */
    536 #define KLDRSYMKIND_DATA            0x00000020
     572#define KLDRSYMKIND_DATA                    0x00000020
    537573/** Mask out the symbol type. */
    538 #define KLDRSYMKIND_TYPE_MASK       0x00000030
     574#define KLDRSYMKIND_TYPE_MASK               0x00000030
    539575/** Valid symbol kind mask. */
    540 #define KLDRSYMKIND_MASK            0x00000033
     576#define KLDRSYMKIND_MASK                    0x00000033
    541577/** @} */
    542578
     
    544580 * @{ */
    545581/** Returns ALL kinds of symbols. The default is to only return public/exported symbols. */
    546 #define KLDRMOD_ENUM_SYMBOL_FLAGS_ALL       0x00000001
    547 /** @} */
    548 
    549 
    550 typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, const char *pszModule, const char *pszSymbol, uint32_t uSymbol,
    551                                uintmax_t *pValue, uint32_t *pfKind, void *pvModuleUser, void *pvUser);
     582#define KLDRMOD_ENUM_SYMS_FLAGS_ALL         0x00000001
     583/** @} */
     584
     585
     586/**
     587 * Callback for resolving imported symbols when applying fixups.
     588 *
     589 * @returns 0 on success and *pValue and *pfKind filled.
     590 * @returns Non-zero OS specific or kLdr status code on failure.
     591 *
     592 * @param   pMod        The module which fixups are begin applied.
     593 * @param   iImport     The import module ordinal number or NIL_KLDRMOD_IMPORT.
     594 * @param   uSymbol     The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
     595 * @param   pszSymbol   The symbol name. Can be NULL if uSymbol isn't nil.
     596 * @param   puValue     Where to store the symbol value.
     597 * @param   pfKind      Where to store the symbol kind flags.
     598 * @param   pvUser      The user parameter specified to the relocation function.
     599 */
     600typedef int FNKLDRMODGETIMPORT(PKLDRMOD pMod, uint32_t iImport, uint32_t uSymbol, const char *pszSymbol,
     601                               PKLDRADDR puValue, uint32_t *pfKind, void *pvUser);
     602/** Pointer to a import callback. */
    552603typedef FNKLDRMODGETIMPORT *PFNKLDRMODGETIMPORT;
    553 typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, const char *pszSymbol, unsigned uSymbol, uintmax_t Value, uint32_t fKind, void *pvUser);
     604
     605/**
     606 * Symbol enumerator callback.
     607 *
     608 * @returns 0 if enumeration should continue.
     609 * @returns non-zero if the enumeration should stop. This status code is the returned by kLdrModEnumSymbols().
     610 *
     611 * @param   pMod        The module which symbols are being enumerated.s
     612 * @param   uSymbol     The symbol ordinal number or NIL_KLDRMOD_SYM_ORDINAL.
     613 * @param   pszSymbol   The symbol name. This can be NULL if there is a symbol ordinal.
     614 *                      This can also be an empty string if the symbol doesn't have a name
     615 *                      or it's name has been stripped.
     616 * @param   uValue      The symbol value.
     617 * @param   fKind       The symbol kind flags.
     618 * @param   pvUser      The user parameter specified to kLdrModEnumSymbols().
     619 */
     620typedef int FNKLDRMODENUMSYMS(PKLDRMOD pMod, uint32_t uSymbol, const char *pszSymbol,
     621                              KLDRADDR uValue, uint32_t fKind, void *pvUser);
     622/** Pointer to a symbol enumerator callback. */
    554623typedef FNKLDRMODENUMSYMS *PFNKLDRMODENUMSYMS;
    555624
     
    558627int     kLdrModOpenNative(const char *pszFilename, PPKLDRMOD ppMod);
    559628int     kLdrModClose(PKLDRMOD pMod);
    560 int     kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, uintmax_t BaseAddress, const char *pszSymbol, uintmax_t *pValue, uint32_t *pfKind);
    561 int     kLdrModEnumSymbols(PKLDRMOD pMod, unsigned fFlags, const void *pvBits, uintmax_t BaseAddress, PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
    562 int     kLdrModGetImport(PKLDRMOD pMod, uint32_t iImport, const char *pszName, size_t cchName);
    563 int32_t kLdrModNumberOfImports(PKLDRMOD pMod);
     629
     630int     kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t uSymbol,
     631                           const char *pszSymbol, PKLDRADDR puValue, uint32_t *pfKind);
     632int     kLdrModEnumSymbols(PKLDRMOD pMod, uint32_t fFlags, const void *pvBits, KLDRADDR BaseAddress,
     633                           PFNKLDRMODENUMSYMS pfnCallback, void *pvUser);
     634int     kLdrModGetImport(PKLDRMOD pMod, void *pvBits, uint32_t iImport, const char *pszName, size_t cchName);
     635int32_t kLdrModNumberOfImports(PKLDRMOD pMod, void *pvBits);
     636int     kLdrModCanExecuteOn(PKLDRMOD pMod, void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu);
     637int     kLdrModGetStackInfo(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo);
     638int     kLdrModQueryMainEntrypoint(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress);
     639size_t  kLdrModSize(PKLDRMOD pMod);
     640
     641/** @name Operations On The Internally Managed Mapping
     642 * @{ */
    564643int     kLdrModMap(PKLDRMOD pMod);
    565644int     kLdrModUnmap(PKLDRMOD pMod);
    566 int     kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    567 size_t  kLdrModSize(PKLDRMOD pMod);
    568 int     kLdrModGetBits(PKLDRMOD pMod, void *pvBits, uintmax_t BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    569 int     kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, uintmax_t NewBaseAddress, uintmax_t OldBaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    570 int     kLdrModCanExecuteOn(PKLDRMOD pMod, KLDRARCH enmArch, KLDRCPU enmCpu);
    571 int     kLdrModGetStackInfo(PKLDRMOD pMod, PKLDRSTACKINFO pStackInfo);
    572 int     kLdrModQueryMainEntrypoint(PKLDRMOD pMod, void *pvBits, uintmax_t uBaseAddress, uintmax_t *puValue);
    573645int     kLdrModAllocTLS(PKLDRMOD pMod);
    574646void    kLdrModFreeTLS(PKLDRMOD pMod);
    575647int     kLdrModReload(PKLDRMOD pMod);
     648int     kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
    576649int     kLdrModCallInit(PKLDRMOD pMod);
    577650int     kLdrModCallTerm(PKLDRMOD pMod);
    578651int     kLdrModCallThread(PKLDRMOD pMod, unsigned fAttachingOrDetaching);
     652/** @} */
     653
     654/** @name Operations On The Externally Managed Mappings
     655 * @{ */
     656int     kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
     657int     kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
     658                            PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser);
     659/** @} */
    579660
    580661/** @} */
     
    781862/** Buffer overflow. */
    782863#define KLDR_ERR_BUFFER_OVERFLOW                            (KLDR_ERR_BASE + 45)
     864/** The specified ARCH+CPU isn't compatible with image. */
     865#define KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE                    (KLDR_ERR_BASE + 45)
    783866
    784867/** Encountered a bad fixup. */
  • trunk/kLdr/kLdrDyld.c

    r2847 r2848  
    13671367        for (iSeg = 0; iSeg < pMod->pMod->cSegments; iSeg++)
    13681368        {
    1369             uintmax_t off = (uintmax_t)Address - pMod->pMod->aSegments[iSeg].LoadAddress;
     1369            KLDRADDR off = (KLDRADDR)Address - pMod->pMod->aSegments[iSeg].MapAddress;
    13701370            if (off < pMod->pMod->aSegments[iSeg].cb)
    13711371            {
  • trunk/kLdr/kLdrDyldMod.c

    r2847 r2848  
    704704     * Query number of prerequiste modules and allocate the array.
    705705     */
    706     cPrereqs = kLdrModNumberOfImports(pMod->pMod);
     706    cPrereqs = kLdrModNumberOfImports(pMod->pMod, NULL);
    707707    kldrHlpAssert(cPrereqs >= 0);
    708708    if (pMod->cPrereqs != cPrereqs)
     
    726726
    727727        KLDRDYLDMOD_ASSERT(pMod->papPrereqs[i] == NULL);
    728         rc = kLdrModGetImport(pMod->pMod, i, s_szPrereq, sizeof(s_szPrereq));
     728        rc = kLdrModGetImport(pMod->pMod, NULL, i, s_szPrereq, sizeof(s_szPrereq));
    729729        if (rc)
    730730            break;
     
    993993    if (!g_fkLdrDyldDoneMainStack)
    994994    {
    995         rc = kLdrModGetStackInfo(pMod->pMod, &StackInfo);
     995        rc = kLdrModGetStackInfo(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, &StackInfo);
    996996        if (!rc)
    997997        {
     
    10031003
    10041004            /* needs allocating? */
    1005             if (    StackInfo.uLinkAddress == ~(uintmax_t)0
     1005            if (    StackInfo.LinkAddress == NIL_KLDRADDR
    10061006                ||  StackInfo.cbStack < cbDefOverride)
    10071007            {
     
    10191019            else
    10201020            {
    1021                 KLDRDYLDMOD_ASSERT(StackInfo.uLoadAddress != ~(uintmax_t)0);
     1021                KLDRDYLDMOD_ASSERT(StackInfo.Address != NIL_KLDRADDR);
    10221022                KLDRDYLDMOD_ASSERT(StackInfo.cbStack > 0);
    10231023
    10241024                g_fkLdrDyldMainStackAllocated = 0;
    1025                 g_pvkLdrDyldMainStack = (void *)(uintptr_t)StackInfo.uLoadAddress;
    1026                 KLDRDYLDMOD_ASSERT((uintptr_t)g_pvkLdrDyldMainStack == StackInfo.uLoadAddress);
     1025                g_pvkLdrDyldMainStack = (void *)(uintptr_t)StackInfo.Address;
     1026                KLDRDYLDMOD_ASSERT((uintptr_t)g_pvkLdrDyldMainStack == StackInfo.Address);
    10271027
    10281028                g_cbkLdrDyldMainStack = (size_t)StackInfo.cbStack;
     
    10561056{
    10571057    int         rc;
    1058     uintmax_t   uValue;
     1058    KLDRADDR    MainEPAddress;
    10591059    void       *pvStack;
    10601060    size_t      cbStack;
    10611061    KLDRDYLDMOD_ASSERT(pMod->fExecutable);
    10621062
    1063     rc = kLdrModQueryMainEntrypoint(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, &uValue);
     1063    rc = kLdrModQueryMainEntrypoint(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP, &MainEPAddress);
    10641064    if (rc)
    10651065        return rc;
     
    10671067    if (rc)
    10681068        return rc;
    1069     return kldrDyldOSStartExe((uintptr_t)uValue, pvStack, cbStack);
     1069    return kldrDyldOSStartExe((uintptr_t)MainEPAddress, pvStack, cbStack);
    10701070}
    10711071
     
    11251125{
    11261126    int         rc;
    1127     uintmax_t   uValue = 0;
     1127    KLDRADDR    uValue = 0;
    11281128    uint32_t    fKind = 0;
    11291129
    11301130    rc = kLdrModQuerySymbol(pMod->pMod, NULL, KLDRMOD_BASEADDRESS_MAP,
    1131                             pszSymbolName ? pszSymbolName : (const char *)uSymbolOrdinal, &uValue, pfKind);
     1131                            uSymbolOrdinal, pszSymbolName, &uValue, &fKind);
    11321132    if (!rc)
    11331133    {
  • trunk/kLdr/kLdrMod.c

    r2828 r2848  
    3939# include "kLdrModELF64.h"
    4040#endif
     41
     42
     43/**
     44 * Open a executable image by file name.
     45 *
     46 * @returns 0 on success and *ppMod pointing to a module instance.
     47 *          On failure, a non-zero OS specific error code is returned.
     48 * @param   pszFilename     The filename to open.
     49 * @param   ppMod           Where to store the module handle.
     50 */
     51int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod)
     52{
     53    /*
     54     * Open the file using a bit provider.
     55     */
     56    PKLDRRDR pRdr;
     57    int rc = kLdrRdrOpen(&pRdr, pszFilename);
     58    if (!rc)
     59    {
     60        rc = kLdrModOpenFromRdr(pRdr, ppMod);
     61        if (!rc)
     62            return 0;
     63       kLdrRdrClose(pRdr);
     64    }
     65    return rc;
     66}
    4167
    4268
     
    108134
    109135/**
    110  * Open a executable image by file name.
     136 * Open a executable image using the native loader (if any).
    111137 *
    112138 * @returns 0 on success and *ppMod pointing to a module instance.
     
    115141 * @param   ppMod           Where to store the module handle.
    116142 */
    117 int kLdrModOpen(const char *pszFilename, PPKLDRMOD ppMod)
    118 {
    119     /*
    120      * Open the file using a bit provider.
    121      */
    122     PKLDRRDR pRdr;
    123     int rc = kLdrRdrOpen(&pRdr, pszFilename);
    124     if (!rc)
    125     {
    126         rc = kLdrModOpenFromRdr(pRdr, ppMod);
    127         if (!rc)
    128             return 0;
    129        kLdrRdrClose(pRdr);
    130     }
    131     return rc;
    132 }
    133 
     143int kLdrModOpenNative(const char *pszFilename, PPKLDRMOD ppMod)
     144{
     145#ifdef __OS2__
     146
     147    //DosLoadModule()
     148#elif defined(__WIN__)
     149
     150#else
     151# error "Port me"
     152#endif
     153    return -1;
     154}
     155
     156
     157
     158/**
     159 * Closes an open module.
     160 *
     161 * The caller is responsible for calling kLdrModUnmap() and kLdrFreeTLS()
     162 * before closing the module.
     163 *
     164 * @returns 0 on success,
     165 * @param   pMod    The module.
     166 */
     167int     kLdrModClose(PKLDRMOD pMod)
     168{
     169    //pMod->
     170    return -1;
     171}
     172
     173
     174
     175/**
     176 * Queries a symbol by name or ordinal number.
     177 *
     178 * @returns 0 and *puValue and *pfKind on success.
     179 *          KLDR_ERR_SYMBOL_NOT_FOUND is returned if the symbol wasn't found.
     180 *          Other failures could stem from bad executable format failures,
     181 *          read failure in case pvBits isn't specified and no mapping should be used.
     182 * @param   pMod            The module.
     183 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits() currently located at BaseAddress.
     184 *                          This can be used by some module interpreters to reduce memory consumption.
     185 * @param   BaseAddress     The module base address to use when calculating the symbol value.
     186 *                          There are two special values that can be used:
     187 *                              KLDRMOD_BASEADDRESS_LINK and KLDRMOD_BASEADDRESS_MAP.
     188 * @param   uSymbol         The symbol ordinal. (optional)
     189 * @param   pszSymbol       The symbol name. (optional)
     190 * @param   puValue         Where to store the symbol value. (optional)
     191 * @param   pfKind          Where to store the symbol kind. (optional)
     192 */
     193int     kLdrModQuerySymbol(PKLDRMOD pMod, const void *pvBits, KLDRADDR BaseAddress, uint32_t uSymbol,
     194                           const char *pszSymbol, PKLDRADDR puValue, uint32_t *pfKind)
     195{
     196    return -1;
     197}
     198
     199
     200/**
     201 * Enumerate the symbols in the module.
     202 *
     203 * @returns 0 on success and non-zero a status code on failure.
     204 * @param   pMod            The module which symbols should be enumerated.
     205 * @param   fFlags          The enumeration flags. A combination of the KLDRMOD_ENUM_SYMS_FLAGS_* \#defines.
     206 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits() currently located at BaseAddress.
     207 *                          This can be used by some module interpreters to reduce memory consumption.
     208 * @param   BaseAddress     The module base address to use when calculating the symbol values.
     209 *                          There are two special values that could be can:
     210 *                              KLDRMOD_BASEADDRESS_LINK and KLDRMOD_BASEADDRESS_MAP.
     211 * @param   pfnCallback     The enumeration callback function.
     212 * @param   pvUser          The user argument to the callback function.
     213 */
     214int     kLdrModEnumSymbols(PKLDRMOD pMod, uint32_t fFlags, const void *pvBits, KLDRADDR BaseAddress,
     215                           PFNKLDRMODENUMSYMS pfnCallback, void *pvUser)
     216{
     217    return -1;
     218}
     219
     220
     221/**
     222 * Get the name of an import module by ordinal number.
     223 *
     224 * @returns 0 and name in pszName on success.
     225 *          On buffer overruns KLDR_ERR_BUFFER_OVERFLOW will be returned.
     226 *          On other failures and appropriate error code is returned.
     227 * @param   pMod            The module.
     228 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits().
     229 *                          This can be used by some module interpreters to reduce memory consumption.
     230 * @param   iImport         The import module ordinal number.
     231 * @param   pszName         Where to store the name.
     232 * @param   cchName         The size of the name buffer.
     233 */
     234int     kLdrModGetImport(PKLDRMOD pMod, void *pvBits, uint32_t iImport, const char *pszName, size_t cchName)
     235{
     236    return -1;
     237}
     238
     239
     240/**
     241 * Get the number of import modules.
     242 *
     243 * @returns The number of import modules. -1 if something really bad happens.
     244 * @param   pMod            The module.
     245 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits().
     246 *                          This can be used by some module interpreters to reduce memory consumption.
     247 */
     248int32_t kLdrModNumberOfImports(PKLDRMOD pMod, void *pvBits)
     249{
     250    return -1;
     251}
     252
     253
     254/**
     255 * Checks if this module can be executed by the specified arch+cpu.
     256 *
     257 * @returns 0 if it can, KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE if it can't.
     258 *          Other failures may occur and cause other return values.
     259 * @param   pMod            The module.
     260 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits().
     261 *                          This can be used by some module interpreters to reduce memory consumption.
     262 */
     263int     kLdrModCanExecuteOn(PKLDRMOD pMod, void *pvBits, KLDRARCH enmArch, KLDRCPU enmCpu)
     264{
     265    //return KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE;
     266    return 0;
     267}
     268
     269
     270/**
     271 * Gets the image stack info.
     272 *
     273 * @returns 0 on success, non-zero on failure.
     274 * @param   pMod
     275 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits() currently located at BaseAddress.
     276 *                          This can be used by some module interpreters to reduce memory consumption.
     277 * @param   BaseAddress     The module base address to use when calculating the stack address.
     278 *                          There are two special values that can be used:
     279 *                              KLDRMOD_BASEADDRESS_LINK and KLDRMOD_BASEADDRESS_MAP.
     280 * @param   pStackInfo      The stack information.
     281 */
     282int     kLdrModGetStackInfo(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PKLDRSTACKINFO pStackInfo)
     283{
     284    return -1;
     285}
     286
     287
     288/**
     289 * Queries the main entrypoint of the module.
     290 *
     291 * Only executable are supposed to have an main entrypoint, though some object and DLL
     292 * formats will also allow this.
     293 *
     294 * @returns 0 and *pMainEPAddress on success. Non-zero status code on failure.
     295 * @param   pMod            The module.
     296 * @param   pvBits          Optional pointer to bits returned by kLdrModGetBits() currently located at BaseAddress.
     297 *                          This can be used by some module interpreters to reduce memory consumption.
     298 * @param   BaseAddress     The module base address to use when calculating the entrypoint address.
     299 *                          There are two special values that can be used:
     300 *                              KLDRMOD_BASEADDRESS_LINK and KLDRMOD_BASEADDRESS_MAP.
     301 * @param   pMainEPAddress  Where to store the entry point address.
     302 */
     303int     kLdrModQueryMainEntrypoint(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PKLDRADDR pMainEPAddress)
     304{
     305    return 1;
     306}
     307
     308
     309/**
     310 * Get the size of the mapped module.
     311 *
     312 * @returns The size of the mapped module (in bytes).
     313 * @param   pMod            The module.
     314 */
     315size_t  kLdrModSize(PKLDRMOD pMod)
     316{
     317    return 0;
     318}
     319
     320
     321/**
     322 * Maps the module into the memory of the caller.
     323 *
     324 * On success the actual addresses for the segments can be found in MapAddress
     325 * member of each segment in the segment array.
     326 *
     327 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     328 * @param   pMod            The module to be mapped.
     329 * @remark  kLdr only supports one mapping at a time of a module.
     330 */
     331int     kLdrModMap(PKLDRMOD pMod)
     332{
     333    return -1;
     334}
     335
     336
     337/**
     338 * Unmaps a module previously mapped by kLdrModMap().
     339 *
     340 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     341 * @param   pMod            The module to unmap.
     342 */
     343int     kLdrModUnmap(PKLDRMOD pMod)
     344{
     345    return -1;
     346}
     347
     348
     349/**
     350 * Allocates Thread Local Storage for module mapped by kLdrModMap().
     351 *
     352 * Calling kLdrModAllocTLS() more than once without calling kLdrModFreeTLS()
     353 * between each invocation is not supported.
     354 *
     355 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     356 * @param   pMod            The module.
     357 */
     358int     kLdrModAllocTLS(PKLDRMOD pMod)
     359{
     360    return 0;
     361}
     362
     363
     364/**
     365 * Frees Thread Local Storage previously allocated by kLdrModAllocTLS().
     366 *
     367 * The caller is responsible for only calling kLdrModFreeTLS() once
     368 * after calling kLdrModAllocTLS().
     369 *
     370 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     371 * @param   pMod            The module.
     372 */
     373void    kLdrModFreeTLS(PKLDRMOD pMod)
     374{
     375}
     376
     377
     378/**
     379 * Reloads all dirty pages in a module previously mapped by kLdrModMap().
     380 *
     381 * The module interpreter may omit code pages if it can safely apply code
     382 * fixups again in a subsequent kLdrModFixupMapping() call.
     383 *
     384 * The caller is responsible for freeing TLS before calling this function.
     385 *
     386 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     387 * @param   pMod            The module.
     388 */
     389int     kLdrModReload(PKLDRMOD pMod)
     390{
     391    return -1;
     392}
     393
     394
     395/**
     396 * Fixup the mapping made by kLdrModMap().
     397 *
     398 * The caller is only responsible for not calling this function more than
     399 * once without doing kLDrModReload() inbetween.
     400 *
     401 * @returns 0 on success, non-zero OS or kLdr status code on failure.
     402 * @param   pMod            The module.
     403 * @param   pfnGetImport    The callback for resolving external (imported) symbols.
     404 * @param   pvUser          The callback user argument.
     405 */
     406int     kLdrModFixupMapping(PKLDRMOD pMod, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser)
     407{
     408    return -1;
     409}
     410
     411
     412/**
     413 * Call the module initializiation function of a mapped module (if any).
     414 *
     415 * @returns 0 on success or no init function, non-zero on init function failure or invalid pMod.
     416 * @param   pMod            The module.
     417 */
     418int     kLdrModCallInit(PKLDRMOD pMod)
     419{
     420    return -1;
     421}
     422
     423
     424/**
     425 * Call the module termination function of a mapped module (if any).
     426 *
     427 * @returns 0 on success or no term function, non-zero on invalid pMod.
     428 * @param   pMod            The module.
     429 *
     430 * @remark  Termination function failure will be ignored by the module interpreter.
     431 */
     432int     kLdrModCallTerm(PKLDRMOD pMod)
     433{
     434    return 0;
     435}
     436
     437
     438/**
     439 * Call the thread attach or detach function of a mapped module (if any).
     440 *
     441 * @returns 0 on success or no attach/detach function, non-zero on attach failure or invalid pMod.
     442 * @param   pMod            The module.
     443 *
     444 * @remark  Detach function failure will be ignored by the module interpreter.
     445 */
     446int     kLdrModCallThread(PKLDRMOD pMod, unsigned fAttachingOrDetaching)
     447{
     448    return 0;
     449}
     450
     451
     452/**
     453 * Gets the module bits.
     454 *
     455 * The module interpreter will fill a mapping allocated by the caller with the
     456 * module bits reallocated to the specified address.
     457 *
     458 * @returns 0 on succes, non-zero OS or kLdr status code on failure.
     459 * @param   pMod            The module.
     460 * @param   pvBits          Where to put the bits.
     461 * @param   BaseAddress     The base address that should correspond to the first byte in pvBits
     462 *                          upon return.
     463 * @param   pfnGetImport    The callback ufor resolving external (imported) symbols.
     464 * @param   pvUser          The callback user argument.
     465 */
     466int     kLdrModGetBits(PKLDRMOD pMod, void *pvBits, KLDRADDR BaseAddress, PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser)
     467{
     468    return -1;
     469}
     470
     471
     472/**
     473 * Relocates the module bits previously obtained by kLdrModGetBits().
     474 *
     475 * @returns 0 on succes, non-zero OS or kLdr status code on failure.
     476 * @param   pMod            The module.
     477 * @param   pvBits          Where to put the bits.
     478 * @param   NewBaseAddress  The new base address.
     479 * @param   OldBaseAddress  The old base address (i.e. the one specified to kLdrModGetBits() or as
     480 *                          NewBaseAddressto the previous kLdrModRelocateBits() call).
     481 * @param   pfnGetImport    The callback ufor resolving external (imported) symbols.
     482 * @param   pvUser          The callback user argument.
     483 */
     484int     kLdrModRelocateBits(PKLDRMOD pMod, void *pvBits, KLDRADDR NewBaseAddress, KLDRADDR OldBaseAddress,
     485                            PFNKLDRMODGETIMPORT pfnGetImport, void *pvUser)
     486{
     487    return -1;
     488}
     489
     490
     491
Note: See TracChangeset for help on using the changeset viewer.