VirtualBox

Changeset 5551 in vbox


Ignore:
Timestamp:
Oct 29, 2007 11:24:52 PM (17 years ago)
Author:
vboxsync
Message:

kStuff integration in progress.

Location:
trunk/src/VBox/Runtime
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r5490 r5551  
    117117RuntimeR3_SDKS.win      = WINPSDK W2K3DDK
    118118RuntimeR3_DEFS          = IN_RT_R3 IN_SUP_R3 LDR_WITH_NATIVE LDR_WITH_ELF32 LDR_WITH_PE RT_WITH_VBOX
     119ifdef IPRT_WITH_KSTUFF
     120 RuntimeR3_DEFS        += LDR_WITH_KLDR
     121endif
    119122ifdef IPRT_WITH_KLDR
    120123 RuntimeR3_DEFS        += LDR_WITH_KLDR KLDR_USE_CRT
     
    126129RuntimeR3_INCS          = \
    127130        $(PATH_ROOT)/src/libs/liblzf-1.51
     131ifdef IPRT_WITH_KSTUFF
     132 RuntimeR3_INCS        += \
     133        $(PATH_ROOT)/src/libs/kStuff/kStuff/include
     134endif
    128135ifdef IPRT_WITH_KLDR
    129136 RuntimeR3_INCS        += \
     
    221228#endif
    222229
     230ifdef IPRT_WITH_KSTUFF
     231 RuntimeR3_SOURCES += \
     232        common/ldr/ldrkStuff.cpp
     233endif
     234
    223235ifdef IPRT_WITH_KLDR
    224236 RuntimeR3_SOURCES += \
     
    548560        $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \
    549561        $(PATH_LIB)/VBox-liblzf$(VBOX_SUFF_LIB)
     562ifdef IPRT_WITH_KSTUFF
     563 VBoxRT_LIBS                  += \
     564        $(PATH_LIB)/VBox-kStuff$(VBOX_SUFF_LIB)
     565endif
    550566VBoxRT_LIBS.darwin             = \
    551567        iconv
  • trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp

    r5530 r5551  
    2424#include <iprt/file.h>
    2525#include <iprt/alloc.h>
     26#include <iprt/alloca.h>
    2627#include <iprt/assert.h>
    2728#include <iprt/string.h>
     
    3334#define KLDR_ALREADY_INCLUDE_STD_TYPES
    3435#define KLDR_NO_KLDR_H_INCLUDES
    35 #include <kLdr.h>
    36 #include "kLdrHlp.h"
     36#include <k/kLdr.h>
     37#include <k/kRdrAll.h>
     38#include <k/kErrors.h>
     39#include <k/kMagics.h>
    3740
    3841
     
    4649{
    4750    /** The core. */
    48     KLDRRDR         Core;
     51    KRDR            Core;
    4952    /** The IPRT bit reader. */
    5053    PRTLDRREADER    pReader;
     
    8790
    8891
    89 static int      rtkldrRdrCreate(  PPKLDRRDR ppRdr, const char *pszFilename);
    90 static int      rtkldrRdrDestroy( PKLDRRDR pRdr);
    91 static int      rtkldrRdrRead(    PKLDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);
    92 static int      rtkldrRdrAllMap(  PKLDRRDR pRdr, const void **ppvBits);
    93 static int      rtkldrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits);
    94 static KLDRFOFF rtkldrRdrSize(    PKLDRRDR pRdr);
    95 static KLDRFOFF rtkldrRdrTell(    PKLDRRDR pRdr);
    96 static const char * rtkldrRdrName(PKLDRRDR pRdr);
    97 static size_t   rtkldrRdrPageSize(PKLDRRDR pRdr);
    98 static int      rtkldrRdrMap(     PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed);
    99 static int      rtkldrRdrRefresh( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
    100 static int      rtkldrRdrProtect( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
    101 static int      rtkldrRdrUnmap(   PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments);
    102 static void     rtkldrRdrDone(    PKLDRRDR pRdr);
     92static int      rtkldrRdrCreate(  PPKRDR ppRdr, const char *pszFilename);
     93static int      rtkldrRdrDestroy( PKRDR pRdr);
     94static int      rtkldrRdrRead(    PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off);
     95static int      rtkldrRdrAllMap(  PKRDR pRdr, const void **ppvBits);
     96static int      rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits);
     97static KFOFF rtkldrRdrSize(    PKRDR pRdr);
     98static KFOFF rtkldrRdrTell(    PKRDR pRdr);
     99static const char * rtkldrRdrName(PKRDR pRdr);
     100static KIPTR    rtkldrRdrNativeFH(PKRDR pRdr);
     101static KSIZE    rtkldrRdrPageSize(PKRDR pRdr);
     102static int      rtkldrRdrMap(     PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed);
     103static int      rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
     104static int      rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect);
     105static int      rtkldrRdrUnmap(   PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
     106static void     rtkldrRdrDone(    PKRDR pRdr);
    103107
    104108
     
    108112                                           RTUINTPTR BaseAddress,PFNRTLDRENUMSYMS pfnCallback, void *pvUser);
    109113static int rtkldrEnumSymbolsWrapper(PKLDRMOD pMod, uint32_t iSymbol,
    110                                     const char *pchSymbol, size_t cchSymbol, const char *pszVersion,
     114                                    const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
    111115                                    KLDRADDR uValue, uint32_t fKind, void *pvUser);
    112 static DECLCALLBACK(size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod);
     116static DECLCALLBACK(KSIZE) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod);
    113117static DECLCALLBACK(int) rtkldrGetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress,
    114118                                       PFNRTLDRIMPORT pfnGetImport, void *pvUser);
    115119static DECLCALLBACK(int) rtkldrRelocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress,
    116120                                        RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser);
    117 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, size_t cchSymbol,
     121static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, KSIZE cchSymbol,
    118122                                  const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser);
    119123
     
    132136    switch (krc)
    133137    {
    134         case KLDR_ERR_INVALID_PARAMETER:                    return VERR_INVALID_PARAMETER;
    135         case KLDR_ERR_INVALID_HANDLE:                       return VERR_INVALID_HANDLE;
    136         case KLDR_ERR_NO_MEMORY:                            return VERR_NO_MEMORY;
     138        case KERR_INVALID_PARAMETER:                        return VERR_INVALID_PARAMETER;
     139        case KERR_INVALID_HANDLE:                           return VERR_INVALID_HANDLE;
     140        case KERR_NO_MEMORY:                                return VERR_NO_MEMORY;
    137141
    138142
     
    150154        case KLDR_ERR_PREREQUISITE_MODULE_NOT_FOUND:        return VERR_MODULE_NOT_FOUND;
    151155        case KLDR_ERR_MAIN_STACK_ALLOC_FAILED:              return VERR_NO_MEMORY;
    152         case KLDR_ERR_BUFFER_OVERFLOW:                      return VERR_BUFFER_OVERFLOW;
     156        case KERR_BUFFER_OVERFLOW:                          return VERR_BUFFER_OVERFLOW;
    153157        case KLDR_ERR_SYMBOL_NOT_FOUND:                     return VERR_SYMBOL_NOT_FOUND;
    154158        case KLDR_ERR_FORWARDER_SYMBOL:                     return VERR_BAD_EXE_FORMAT;
     
    161165
    162166        case KLDR_ERR_NOT_LOADED_DYNAMICALLY:
    163         case KLDR_ERR_ARCH_CPU_NOT_COMPATIBLE:
     167        case KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE:
    164168        case KLDR_ERR_TOO_LONG_FORWARDER_CHAIN:
    165169        case KLDR_ERR_MODULE_TERMINATING:
     
    171175        case KLDR_ERR_PREREQUISITE_RECURSED_TOO_DEEPLY:
    172176        case KLDR_ERR_THREAD_ATTACH_FAILED:
    173         case KLDR_ERR_TOO_MANY_MAPPINGS:
     177        case KRDR_ERR_TOO_MANY_MAPPINGS:
    174178        case KLDR_ERR_NOT_DLL:
    175179        case KLDR_ERR_NOT_EXE:
     
    219223    switch (rc)
    220224    {
    221         case VERR_NO_MEMORY:            return KLDR_ERR_NO_MEMORY;
    222         case VERR_INVALID_PARAMETER:    return KLDR_ERR_INVALID_PARAMETER;
    223         case VERR_INVALID_HANDLE:       return KLDR_ERR_INVALID_HANDLE;
    224         case VERR_BUFFER_OVERFLOW:      return KLDR_ERR_BUFFER_OVERFLOW;
     225        case VERR_NO_MEMORY:            return KERR_NO_MEMORY;
     226        case VERR_INVALID_PARAMETER:    return KERR_INVALID_PARAMETER;
     227        case VERR_INVALID_HANDLE:       return KERR_INVALID_HANDLE;
     228        case VERR_BUFFER_OVERFLOW:      return KERR_BUFFER_OVERFLOW;
    225229        default:
    226230            return rc;
     
    229233
    230234
    231 /*
    232  *
    233  *
    234  * Misc Helpers Implemented using IPRT instead of kLdr/native APIs.
    235  *
    236  *
    237  *
    238  */
    239 
    240 
    241 int     kldrHlpPageAlloc(void **ppv, size_t cb, KLDRPROT enmProt, unsigned fFixed)
    242 {
    243     AssertReturn(fFixed, KLDR_ERR_INVALID_PARAMETER); /* fixed address allocation not supported. */
    244 
    245     void *pv = RTMemPageAlloc(cb);
    246     if (!pv)
    247         return KLDR_ERR_NO_MEMORY;
    248 
    249     int rc = kldrHlpPageProtect(pv, cb, enmProt);
    250     if (!rc)
    251         *ppv = pv;
    252     else
    253         RTMemPageFree(pv);
    254     return rc;
    255 }
    256 
    257 
    258 int     kldrHlpPageProtect(void *pv, size_t cb, KLDRPROT enmProt)
    259 {
    260     unsigned fProtect;
    261     switch (enmProt)
    262     {
    263         case KLDRPROT_NOACCESS:
    264             fProtect = RTMEM_PROT_NONE;
    265             break;
    266         case KLDRPROT_READONLY:
    267             fProtect = RTMEM_PROT_READ;
    268             break;
    269         case KLDRPROT_READWRITE:
    270             fProtect = RTMEM_PROT_READ | RTMEM_PROT_WRITE;
    271             break;
    272         case KLDRPROT_EXECUTE:
    273             fProtect = RTMEM_PROT_EXEC;
    274             break;
    275         case KLDRPROT_EXECUTE_READ:
    276             fProtect = RTMEM_PROT_EXEC | RTMEM_PROT_READ;
    277             break;
    278         case KLDRPROT_EXECUTE_READWRITE:
    279         case KLDRPROT_EXECUTE_WRITECOPY:
    280             fProtect = RTMEM_PROT_EXEC | RTMEM_PROT_READ | RTMEM_PROT_WRITE;
    281             break;
    282         default:
    283             AssertMsgFailed(("enmProt=%d\n", enmProt));
    284             return KLDR_ERR_INVALID_PARAMETER;
    285     }
    286 
    287     int rc = RTMemProtect(pv, cb, fProtect);
    288     if (RT_SUCCESS(rc))
    289         return 0;
    290     return rtkldrConvertErrorFromIPRT(rc);
    291 }
    292 
    293 
    294 int     kldrHlpPageFree(void *pv, size_t cb)
    295 {
    296     if (pv)
    297         RTMemPageFree(pv);
    298     return 0;
    299 }
    300 
    301 
    302 void *  kldrHlpAlloc(size_t cb)
    303 {
    304     return RTMemAlloc(cb);
    305 }
    306 
    307 
    308 void *  kldrHlpAllocZ(size_t cb)
    309 {
    310     return RTMemAllocZ(cb);
    311 }
    312 
    313 
    314 void    kldrHlpFree(void *pv)
    315 {
    316     return RTMemFree(pv);
    317 }
    318 
    319 
    320 char   *kldrHlpGetFilename(const char *pszFilename)
    321 {
    322     return RTPathFilename(pszFilename);
    323 }
    324 
    325 
    326 void    kldrHlpAssertMsg(const char *pszExpr, const char *pszFile, unsigned iLine, const char *pszFunction)
    327 {
    328     AssertMsg1(pszExpr, iLine, pszFile, pszFunction);
    329 }
    330 
    331 
    332 
    333235
    334236
     
    338240 * We provide our own based on IPRT instead of using the kLdr ones.
    339241 */
    340 extern "C" const KLDRRDROPS g_kLdrRdrFileOps;
    341 extern "C" const KLDRRDROPS g_kLdrRdrFileOps =
     242extern "C" const KRDROPS g_kLdrRdrFileOps;
     243extern "C" const KRDROPS g_kLdrRdrFileOps =
    342244{
    343245    /* .pszName = */        "IPRT",
     
    351253    /* .pfnTell = */        rtkldrRdrTell,
    352254    /* .pfnName = */        rtkldrRdrName,
     255    /* .pfnNativeFH = */    rtkldrRdrNativeFH,
    353256    /* .pfnPageSize = */    rtkldrRdrPageSize,
    354257    /* .pfnMap = */         rtkldrRdrMap,
     
    363266/** @copydoc KLDRRDROPS::pfnCreate
    364267 * @remark This is a dummy which isn't used. */
    365 static int      rtkldrRdrCreate(  PPKLDRRDR ppRdr, const char *pszFilename)
     268static int      rtkldrRdrCreate(  PPKRDR ppRdr, const char *pszFilename)
    366269{
    367270    AssertReleaseFailed();
     
    371274
    372275/** @copydoc KLDRRDROPS::pfnDestroy */
    373 static int      rtkldrRdrDestroy( PKLDRRDR pRdr)
     276static int      rtkldrRdrDestroy( PKRDR pRdr)
    374277{
    375278    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    380283
    381284/** @copydoc KLDRRDROPS::pfnRead */
    382 static int      rtkldrRdrRead(    PKLDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off)
     285static int      rtkldrRdrRead(    PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off)
    383286{
    384287    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    389292
    390293/** @copydoc KLDRRDROPS::pfnAllMap */
    391 static int      rtkldrRdrAllMap(  PKLDRRDR pRdr, const void **ppvBits)
     294static int      rtkldrRdrAllMap(  PKRDR pRdr, const void **ppvBits)
    392295{
    393296    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    398301
    399302/** @copydoc KLDRRDROPS::pfnAllUnmap */
    400 static int      rtkldrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits)
     303static int      rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits)
    401304{
    402305    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    407310
    408311/** @copydoc KLDRRDROPS::pfnSize */
    409 static KLDRFOFF rtkldrRdrSize(    PKLDRRDR pRdr)
     312static KFOFF rtkldrRdrSize(    PKRDR pRdr)
    410313{
    411314    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    412     return (KLDRFOFF)pReader->pfnSize(pReader);
     315    return (KFOFF)pReader->pfnSize(pReader);
    413316}
    414317
    415318
    416319/** @copydoc KLDRRDROPS::pfnTell */
    417 static KLDRFOFF rtkldrRdrTell(    PKLDRRDR pRdr)
     320static KFOFF rtkldrRdrTell(    PKRDR pRdr)
    418321{
    419322    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
    420     return (KLDRFOFF)pReader->pfnTell(pReader);
     323    return (KFOFF)pReader->pfnTell(pReader);
    421324}
    422325
    423326
    424327/** @copydoc KLDRRDROPS::pfnName */
    425 static const char * rtkldrRdrName(PKLDRRDR pRdr)
     328static const char * rtkldrRdrName(PKRDR pRdr)
    426329{
    427330    PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    430333
    431334
     335/** @copydoc KLDRRDROPS::pfnNativeFH */
     336static KIPTR rtkldrRdrNativeFH(PKRDR pRdr)
     337{
     338    AssertFailed();
     339    return -1;
     340}
     341
     342
    432343/** @copydoc KLDRRDROPS::pfnPageSize */
    433 static size_t   rtkldrRdrPageSize(PKLDRRDR pRdr)
     344static KSIZE rtkldrRdrPageSize(PKRDR pRdr)
    434345{
    435346    return PAGE_SIZE;
     
    438349
    439350/** @copydoc KLDRRDROPS::pfnMap */
    440 static int      rtkldrRdrMap(     PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed)
     351static int      rtkldrRdrMap(     PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed)
    441352{
    442353    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    447358
    448359/** @copydoc KLDRRDROPS::pfnRefresh */
    449 static int      rtkldrRdrRefresh( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments)
     360static int      rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
    450361{
    451362    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    456367
    457368/** @copydoc KLDRRDROPS::pfnProtect */
    458 static int      rtkldrRdrProtect( PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)
     369static int      rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect)
    459370{
    460371    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    465376
    466377/** @copydoc KLDRRDROPS::pfnUnmap */
    467 static int      rtkldrRdrUnmap(   PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments)
     378static int      rtkldrRdrUnmap(   PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
    468379{
    469380    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    473384
    474385/** @copydoc KLDRRDROPS::pfnDone */
    475 static void     rtkldrRdrDone(    PKLDRRDR pRdr)
     386static void     rtkldrRdrDone(    PKRDR pRdr)
    476387{
    477388    //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader;
     
    539450/** @copydoc FNKLDRMODENUMSYMS */
    540451static int rtkldrEnumSymbolsWrapper(PKLDRMOD pMod, uint32_t iSymbol,
    541                                     const char *pchSymbol, size_t cchSymbol, const char *pszVersion,
     452                                    const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion,
    542453                                    KLDRADDR uValue, uint32_t fKind, void *pvUser)
    543454{
     
    568479
    569480/** @copydoc RTLDROPS::pfnGetImageSize */
    570 static DECLCALLBACK(size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod)
     481static DECLCALLBACK(KSIZE) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod)
    571482{
    572483    PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod;
     
    606517
    607518/** @copydoc FNKLDRMODGETIMPORT */
    608 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, size_t cchSymbol,
     519static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, KSIZE cchSymbol,
    609520                                  const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser)
    610521{
     
    698609    if (!pRdr)
    699610        return VERR_NO_MEMORY;
    700     pRdr->Core.u32Magic = KLDRRDR_MAGIC;
     611    pRdr->Core.u32Magic = KRDR_MAGIC;
    701612    pRdr->Core.pOps = &g_kLdrRdrFileOps;
    702613    pRdr->pReader = pReader;
     
    719630        }
    720631        kLdrModClose(pMod);
    721         krc = KLDR_ERR_NO_MEMORY;
     632        krc = KERR_NO_MEMORY;
    722633    }
    723634    return rtkldrConvertError(krc);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette