Changeset 5551 in vbox
- Timestamp:
- Oct 29, 2007 11:24:52 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r5490 r5551 117 117 RuntimeR3_SDKS.win = WINPSDK W2K3DDK 118 118 RuntimeR3_DEFS = IN_RT_R3 IN_SUP_R3 LDR_WITH_NATIVE LDR_WITH_ELF32 LDR_WITH_PE RT_WITH_VBOX 119 ifdef IPRT_WITH_KSTUFF 120 RuntimeR3_DEFS += LDR_WITH_KLDR 121 endif 119 122 ifdef IPRT_WITH_KLDR 120 123 RuntimeR3_DEFS += LDR_WITH_KLDR KLDR_USE_CRT … … 126 129 RuntimeR3_INCS = \ 127 130 $(PATH_ROOT)/src/libs/liblzf-1.51 131 ifdef IPRT_WITH_KSTUFF 132 RuntimeR3_INCS += \ 133 $(PATH_ROOT)/src/libs/kStuff/kStuff/include 134 endif 128 135 ifdef IPRT_WITH_KLDR 129 136 RuntimeR3_INCS += \ … … 221 228 #endif 222 229 230 ifdef IPRT_WITH_KSTUFF 231 RuntimeR3_SOURCES += \ 232 common/ldr/ldrkStuff.cpp 233 endif 234 223 235 ifdef IPRT_WITH_KLDR 224 236 RuntimeR3_SOURCES += \ … … 548 560 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \ 549 561 $(PATH_LIB)/VBox-liblzf$(VBOX_SUFF_LIB) 562 ifdef IPRT_WITH_KSTUFF 563 VBoxRT_LIBS += \ 564 $(PATH_LIB)/VBox-kStuff$(VBOX_SUFF_LIB) 565 endif 550 566 VBoxRT_LIBS.darwin = \ 551 567 iconv -
trunk/src/VBox/Runtime/common/ldr/ldrkStuff.cpp
r5530 r5551 24 24 #include <iprt/file.h> 25 25 #include <iprt/alloc.h> 26 #include <iprt/alloca.h> 26 27 #include <iprt/assert.h> 27 28 #include <iprt/string.h> … … 33 34 #define KLDR_ALREADY_INCLUDE_STD_TYPES 34 35 #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> 37 40 38 41 … … 46 49 { 47 50 /** The core. */ 48 K LDRRDRCore;51 KRDR Core; 49 52 /** The IPRT bit reader. */ 50 53 PRTLDRREADER pReader; … … 87 90 88 91 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); 92 static int rtkldrRdrCreate( PPKRDR ppRdr, const char *pszFilename); 93 static int rtkldrRdrDestroy( PKRDR pRdr); 94 static int rtkldrRdrRead( PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off); 95 static int rtkldrRdrAllMap( PKRDR pRdr, const void **ppvBits); 96 static int rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits); 97 static KFOFF rtkldrRdrSize( PKRDR pRdr); 98 static KFOFF rtkldrRdrTell( PKRDR pRdr); 99 static const char * rtkldrRdrName(PKRDR pRdr); 100 static KIPTR rtkldrRdrNativeFH(PKRDR pRdr); 101 static KSIZE rtkldrRdrPageSize(PKRDR pRdr); 102 static int rtkldrRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed); 103 static int rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments); 104 static int rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect); 105 static int rtkldrRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments); 106 static void rtkldrRdrDone( PKRDR pRdr); 103 107 104 108 … … 108 112 RTUINTPTR BaseAddress,PFNRTLDRENUMSYMS pfnCallback, void *pvUser); 109 113 static int rtkldrEnumSymbolsWrapper(PKLDRMOD pMod, uint32_t iSymbol, 110 const char *pchSymbol, size_tcchSymbol, const char *pszVersion,114 const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion, 111 115 KLDRADDR uValue, uint32_t fKind, void *pvUser); 112 static DECLCALLBACK( size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod);116 static DECLCALLBACK(KSIZE) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod); 113 117 static DECLCALLBACK(int) rtkldrGetBits(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR BaseAddress, 114 118 PFNRTLDRIMPORT pfnGetImport, void *pvUser); 115 119 static DECLCALLBACK(int) rtkldrRelocate(PRTLDRMODINTERNAL pMod, void *pvBits, RTUINTPTR NewBaseAddress, 116 120 RTUINTPTR OldBaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser); 117 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, size_tcchSymbol,121 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, KSIZE cchSymbol, 118 122 const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser); 119 123 … … 132 136 switch (krc) 133 137 { 134 case K LDR_ERR_INVALID_PARAMETER:return VERR_INVALID_PARAMETER;135 case K LDR_ERR_INVALID_HANDLE:return VERR_INVALID_HANDLE;136 case K LDR_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; 137 141 138 142 … … 150 154 case KLDR_ERR_PREREQUISITE_MODULE_NOT_FOUND: return VERR_MODULE_NOT_FOUND; 151 155 case KLDR_ERR_MAIN_STACK_ALLOC_FAILED: return VERR_NO_MEMORY; 152 case K LDR_ERR_BUFFER_OVERFLOW:return VERR_BUFFER_OVERFLOW;156 case KERR_BUFFER_OVERFLOW: return VERR_BUFFER_OVERFLOW; 153 157 case KLDR_ERR_SYMBOL_NOT_FOUND: return VERR_SYMBOL_NOT_FOUND; 154 158 case KLDR_ERR_FORWARDER_SYMBOL: return VERR_BAD_EXE_FORMAT; … … 161 165 162 166 case KLDR_ERR_NOT_LOADED_DYNAMICALLY: 163 case K LDR_ERR_ARCH_CPU_NOT_COMPATIBLE:167 case KCPU_ERR_ARCH_CPU_NOT_COMPATIBLE: 164 168 case KLDR_ERR_TOO_LONG_FORWARDER_CHAIN: 165 169 case KLDR_ERR_MODULE_TERMINATING: … … 171 175 case KLDR_ERR_PREREQUISITE_RECURSED_TOO_DEEPLY: 172 176 case KLDR_ERR_THREAD_ATTACH_FAILED: 173 case K LDR_ERR_TOO_MANY_MAPPINGS:177 case KRDR_ERR_TOO_MANY_MAPPINGS: 174 178 case KLDR_ERR_NOT_DLL: 175 179 case KLDR_ERR_NOT_EXE: … … 219 223 switch (rc) 220 224 { 221 case VERR_NO_MEMORY: return K LDR_ERR_NO_MEMORY;222 case VERR_INVALID_PARAMETER: return K LDR_ERR_INVALID_PARAMETER;223 case VERR_INVALID_HANDLE: return K LDR_ERR_INVALID_HANDLE;224 case VERR_BUFFER_OVERFLOW: return K LDR_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; 225 229 default: 226 230 return rc; … … 229 233 230 234 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 else253 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 333 235 334 236 … … 338 240 * We provide our own based on IPRT instead of using the kLdr ones. 339 241 */ 340 extern "C" const K LDRRDROPS g_kLdrRdrFileOps;341 extern "C" const K LDRRDROPS g_kLdrRdrFileOps =242 extern "C" const KRDROPS g_kLdrRdrFileOps; 243 extern "C" const KRDROPS g_kLdrRdrFileOps = 342 244 { 343 245 /* .pszName = */ "IPRT", … … 351 253 /* .pfnTell = */ rtkldrRdrTell, 352 254 /* .pfnName = */ rtkldrRdrName, 255 /* .pfnNativeFH = */ rtkldrRdrNativeFH, 353 256 /* .pfnPageSize = */ rtkldrRdrPageSize, 354 257 /* .pfnMap = */ rtkldrRdrMap, … … 363 266 /** @copydoc KLDRRDROPS::pfnCreate 364 267 * @remark This is a dummy which isn't used. */ 365 static int rtkldrRdrCreate( PPK LDRRDR ppRdr, const char *pszFilename)268 static int rtkldrRdrCreate( PPKRDR ppRdr, const char *pszFilename) 366 269 { 367 270 AssertReleaseFailed(); … … 371 274 372 275 /** @copydoc KLDRRDROPS::pfnDestroy */ 373 static int rtkldrRdrDestroy( PK LDRRDR pRdr)276 static int rtkldrRdrDestroy( PKRDR pRdr) 374 277 { 375 278 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 380 283 381 284 /** @copydoc KLDRRDROPS::pfnRead */ 382 static int rtkldrRdrRead( PK LDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off)285 static int rtkldrRdrRead( PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off) 383 286 { 384 287 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 389 292 390 293 /** @copydoc KLDRRDROPS::pfnAllMap */ 391 static int rtkldrRdrAllMap( PK LDRRDR pRdr, const void **ppvBits)294 static int rtkldrRdrAllMap( PKRDR pRdr, const void **ppvBits) 392 295 { 393 296 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 398 301 399 302 /** @copydoc KLDRRDROPS::pfnAllUnmap */ 400 static int rtkldrRdrAllUnmap(PK LDRRDR pRdr, const void *pvBits)303 static int rtkldrRdrAllUnmap(PKRDR pRdr, const void *pvBits) 401 304 { 402 305 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 407 310 408 311 /** @copydoc KLDRRDROPS::pfnSize */ 409 static K LDRFOFF rtkldrRdrSize( PKLDRRDR pRdr)312 static KFOFF rtkldrRdrSize( PKRDR pRdr) 410 313 { 411 314 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 412 return (K LDRFOFF)pReader->pfnSize(pReader);315 return (KFOFF)pReader->pfnSize(pReader); 413 316 } 414 317 415 318 416 319 /** @copydoc KLDRRDROPS::pfnTell */ 417 static K LDRFOFF rtkldrRdrTell( PKLDRRDR pRdr)320 static KFOFF rtkldrRdrTell( PKRDR pRdr) 418 321 { 419 322 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; 420 return (K LDRFOFF)pReader->pfnTell(pReader);323 return (KFOFF)pReader->pfnTell(pReader); 421 324 } 422 325 423 326 424 327 /** @copydoc KLDRRDROPS::pfnName */ 425 static const char * rtkldrRdrName(PK LDRRDR pRdr)328 static const char * rtkldrRdrName(PKRDR pRdr) 426 329 { 427 330 PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 430 333 431 334 335 /** @copydoc KLDRRDROPS::pfnNativeFH */ 336 static KIPTR rtkldrRdrNativeFH(PKRDR pRdr) 337 { 338 AssertFailed(); 339 return -1; 340 } 341 342 432 343 /** @copydoc KLDRRDROPS::pfnPageSize */ 433 static size_t rtkldrRdrPageSize(PKLDRRDR pRdr)344 static KSIZE rtkldrRdrPageSize(PKRDR pRdr) 434 345 { 435 346 return PAGE_SIZE; … … 438 349 439 350 /** @copydoc KLDRRDROPS::pfnMap */ 440 static int rtkldrRdrMap( PK LDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsignedfFixed)351 static int rtkldrRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fFixed) 441 352 { 442 353 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 447 358 448 359 /** @copydoc KLDRRDROPS::pfnRefresh */ 449 static int rtkldrRdrRefresh( PK LDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments)360 static int rtkldrRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 450 361 { 451 362 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 456 367 457 368 /** @copydoc KLDRRDROPS::pfnProtect */ 458 static int rtkldrRdrProtect( PK LDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsignedfUnprotectOrProtect)369 static int rtkldrRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, KBOOL fUnprotectOrProtect) 459 370 { 460 371 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 465 376 466 377 /** @copydoc KLDRRDROPS::pfnUnmap */ 467 static int rtkldrRdrUnmap( PK LDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments)378 static int rtkldrRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 468 379 { 469 380 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 473 384 474 385 /** @copydoc KLDRRDROPS::pfnDone */ 475 static void rtkldrRdrDone( PK LDRRDR pRdr)386 static void rtkldrRdrDone( PKRDR pRdr) 476 387 { 477 388 //PRTLDRREADER pReader = ((PRTKLDRRDR)pRdr)->pReader; … … 539 450 /** @copydoc FNKLDRMODENUMSYMS */ 540 451 static int rtkldrEnumSymbolsWrapper(PKLDRMOD pMod, uint32_t iSymbol, 541 const char *pchSymbol, size_tcchSymbol, const char *pszVersion,452 const char *pchSymbol, KSIZE cchSymbol, const char *pszVersion, 542 453 KLDRADDR uValue, uint32_t fKind, void *pvUser) 543 454 { … … 568 479 569 480 /** @copydoc RTLDROPS::pfnGetImageSize */ 570 static DECLCALLBACK( size_t) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod)481 static DECLCALLBACK(KSIZE) rtkldrGetImageSize(PRTLDRMODINTERNAL pMod) 571 482 { 572 483 PKLDRMOD pModkLdr = ((PRTLDRMODKLDR)pMod)->pMod; … … 606 517 607 518 /** @copydoc FNKLDRMODGETIMPORT */ 608 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, size_tcchSymbol,519 static int rtkldrGetImportWrapper(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, KSIZE cchSymbol, 609 520 const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser) 610 521 { … … 698 609 if (!pRdr) 699 610 return VERR_NO_MEMORY; 700 pRdr->Core.u32Magic = K LDRRDR_MAGIC;611 pRdr->Core.u32Magic = KRDR_MAGIC; 701 612 pRdr->Core.pOps = &g_kLdrRdrFileOps; 702 613 pRdr->pReader = pReader; … … 719 630 } 720 631 kLdrModClose(pMod); 721 krc = K LDR_ERR_NO_MEMORY;632 krc = KERR_NO_MEMORY; 722 633 } 723 634 return rtkldrConvertError(krc);
Note:
See TracChangeset
for help on using the changeset viewer.