vbox的更動 59404 路徑 trunk/src/bldprogs
- 時間撮記:
- 2016-1-19 上午10:10:39 (9 年 以前)
- 位置:
- trunk
- 檔案:
-
- 新增 1 筆資料
- 修改 3 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk
- 屬性 svn:mergeinfo 變動
/branches/VBox-5.0 已合併: 104938,104943,104950,104952-104953,104987-104988,104990
- 屬性 svn:mergeinfo 變動
-
trunk/src/bldprogs/Makefile.kmk
r58716 r59404 68 68 VBoxPeSetVersion_SOURCES = VBoxPeSetVersion.cpp 69 69 70 BLDPROGS.win += VBoxCheckImports 71 VBoxCheckImports_TEMPLATE = VBoxBldProg 72 VBoxCheckImports_SOURCES = VBoxCheckImports.cpp 73 70 74 BLDPROGS += VBoxDef2LazyLoad 71 75 VBoxDef2LazyLoad_TEMPLATE = VBoxBldProg -
trunk/src/bldprogs/VBoxDef2LazyLoad.cpp
r57353 r59404 35 35 { 36 36 struct MYEXPORT *pNext; 37 /** Pointer to unmangled name for stdcall (after szName), NULL if not. */ 38 char *pszUnstdcallName; 39 /** Pointer to the exported name. */ 40 char const *pszExportedNm; 41 unsigned uOrdinal; 37 42 bool fNoName; 38 unsigned uOrdinal;39 43 char szName[1]; 40 44 } MYEXPORT; … … 54 58 static bool g_fIgnoreData = true; 55 59 static bool g_fWithExplictLoadFunction = false; 60 static bool g_fSystemLibrary = false; 56 61 /** @} */ 57 62 … … 176 181 } 177 182 178 bool fNoName = true;183 bool fNoName = false; 179 184 unsigned uOrdinal = ~0U; 180 185 if (*psz == '@') … … 196 201 if (WORD_CMP(psz, cch, "NONAME")) 197 202 { 198 #if 0199 203 fNoName = true; 200 204 psz = leftStrip(psz + cch); 201 #else202 fprintf(stderr, "%s:%u: error: NONAME export not implemented.\n", pszInput, iLine);203 return RTEXITCODE_FAILURE;204 #endif205 205 } 206 206 } … … 228 228 229 229 /* 230 * Check for stdcall mangling. 231 */ 232 size_t cbExp = sizeof(MYEXPORT) + cchName; 233 unsigned cchStdcall = 0; 234 if (cchName > 3 && *pchName == '_' && isdigit(pchName[cchName - 1])) 235 { 236 if (cchName > 3 && pchName[cchName - 2] == '@') 237 cchStdcall = 2; 238 else if (cchName > 4 && pchName[cchName - 3] == '@' && isdigit(pchName[cchName - 2])) 239 cchStdcall = 3; 240 if (cchStdcall) 241 cbExp += cchName - 1 - cchStdcall; 242 } 243 244 /* 230 245 * Add the export. 231 246 */ 232 PMYEXPORT pExp = (PMYEXPORT)malloc(sizeof(*pExp) + cchName); 247 248 PMYEXPORT pExp = (PMYEXPORT)malloc(cbExp); 233 249 if (!pExp) 234 250 { … … 238 254 memcpy(pExp->szName, pchName, cchName); 239 255 pExp->szName[cchName] = '\0'; 240 pExp->uOrdinal = uOrdinal; 241 pExp->fNoName = fNoName; 242 pExp->pNext = NULL; 243 *g_ppExpNext = pExp; 244 g_ppExpNext = &pExp->pNext; 256 if (!cchStdcall) 257 { 258 pExp->pszUnstdcallName = NULL; 259 pExp->pszExportedNm = pExp->szName; 260 } 261 else 262 { 263 pExp->pszUnstdcallName = &pExp->szName[cchName + 1]; 264 memcpy(pExp->pszUnstdcallName, pchName + 1, cchName - 1 - cchStdcall); 265 pExp->pszUnstdcallName[cchName - 1 - cchStdcall] = '\0'; 266 pExp->pszExportedNm = pExp->pszUnstdcallName; 267 } 268 pExp->uOrdinal = uOrdinal; 269 pExp->fNoName = fNoName; 270 pExp->pNext = NULL; 271 *g_ppExpNext = pExp; 272 g_ppExpNext = &pExp->pNext; 245 273 } 246 274 } … … 322 350 "BEGINCODE\n"); 323 351 for (PMYEXPORT pExp = g_pExpHead; pExp; pExp = pExp->pNext) 324 fprintf(pOutput, 325 "BEGINPROC %s\n" 326 " jmp RTCCPTR_PRE [g_pfn%s xWrtRIP]\n" 327 "ENDPROC %s\n", 328 pExp->szName, 329 pExp->szName, 330 pExp->szName); 352 if (!pExp->pszUnstdcallName) 353 fprintf(pOutput, 354 "BEGINPROC %s\n" 355 " jmp RTCCPTR_PRE [g_pfn%s xWrtRIP]\n" 356 "ENDPROC %s\n", 357 pExp->szName, pExp->szName, pExp->szName); 358 else 359 fprintf(pOutput, 360 "%%ifdef RT_ARCH_X86\n" 361 "global %s\n" 362 "%s:\n" 363 " jmp RTCCPTR_PRE [g_pfn%s xWrtRIP]\n" 364 "%%else\n" 365 "BEGINPROC %s\n" 366 " jmp RTCCPTR_PRE [g_pfn%s xWrtRIP]\n" 367 "ENDPROC %s\n" 368 "%%endif\n", 369 pExp->szName, pExp->szName, pExp->pszUnstdcallName, 370 pExp->pszUnstdcallName, pExp->pszUnstdcallName, pExp->pszUnstdcallName); 371 331 372 fprintf(pOutput, 332 373 "\n" … … 348 389 "__imp_%s:\n" 349 390 "%%endif\n" 350 "g_pfn%s RTCCPTR_DEF ___LazyLoad___%s\n", 391 "g_pfn%s RTCCPTR_DEF ___LazyLoad___%s\n" 392 "\n", 351 393 pExp->szName, 352 394 pExp->szName, 353 pExp-> szName,354 pExp-> szName);395 pExp->pszExportedNm, 396 pExp->pszExportedNm); 355 397 fprintf(pOutput, 356 398 "RTCCPTR_DEF 0 ; Terminator entry for traversal.\n" … … 369 411 ";\n" 370 412 "BEGINCODE\n" 371 "g_szLibrary db '%s',0\n" 413 "g_szLibrary: db '%s',0\n" 414 "\n" 372 415 "g_szzNames:\n", 373 416 g_pszLibrary); 374 417 for (PMYEXPORT pExp = g_pExpHead; pExp; pExp = pExp->pNext) 375 fprintf(pOutput, "g_sz%s: db '%s',0\n", pExp->szName, pExp->szName); 418 if (!pExp->fNoName) 419 fprintf(pOutput, " g_sz%s:\n db '%s',0\n", pExp->pszExportedNm, pExp->pszExportedNm); 420 else 421 fprintf(pOutput, " g_sz%s:\n db '#%u',0\n", pExp->pszExportedNm, pExp->uOrdinal); 376 422 fprintf(pOutput, 377 423 "g_EndOfNames: db 0\n" 424 "\n" 425 "g_szFailLoadFmt: db 'Lazy loader failed to load \"%%s\": %%Rrc', 10, 0\n" 426 "g_szFailResolveFmt: db 'Lazy loader failed to resolve symbol \"%%s\" in \"%%s\": %%Rrc', 10, 0\n" 378 427 "\n" 379 428 "\n"); … … 388 437 "BEGINCODE\n"); 389 438 for (PMYEXPORT pExp = g_pExpHead; pExp; pExp = pExp->pNext) 390 fprintf(pOutput, 391 "___LazyLoad___%s:\n" 392 /* "int3\n" */ 393 "%%ifdef RT_ARCH_AMD64\n" 394 " lea rax, [g_sz%s wrt rip]\n" 395 " lea r10, [g_pfn%s wrt rip]\n" 396 "%%elifdef RT_ARCH_X86\n" 397 " push g_sz%s\n" 398 " push g_pfn%s\n" 399 "%%else\n" 400 " %%error \"Unsupported architecture\"\n" 401 "%%endif\n" 402 " call LazyLoadResolver\n" 403 "%%ifdef RT_ARCH_X86\n" 404 " add esp, 8h\n" 405 "%%endif\n" 406 " jmp NAME(%s)\n" 407 "\n" 408 , 409 pExp->szName, 410 pExp->szName, 411 pExp->szName, 412 pExp->szName, 413 pExp->szName, 414 pExp->szName); 439 { 440 if (!pExp->fNoName) 441 fprintf(pOutput, 442 "___LazyLoad___%s:\n" 443 /* "int3\n" */ 444 "%%ifdef RT_ARCH_AMD64\n" 445 " lea rax, [g_sz%s wrt rip]\n" 446 " lea r10, [g_pfn%s wrt rip]\n" 447 " call LazyLoadResolver\n" 448 "%%elifdef RT_ARCH_X86\n" 449 " push g_sz%s\n" 450 " push g_pfn%s\n" 451 " call LazyLoadResolver\n" 452 " add esp, 8h\n" 453 "%%else\n" 454 " %%error \"Unsupported architecture\"\n" 455 "%%endif\n" 456 , 457 pExp->pszExportedNm, 458 pExp->pszExportedNm, 459 pExp->pszExportedNm, 460 pExp->pszExportedNm, 461 pExp->pszExportedNm); 462 else 463 fprintf(pOutput, 464 "___LazyLoad___%s:\n" 465 /* "int3\n" */ 466 "%%ifdef RT_ARCH_AMD64\n" 467 " mov eax, %u\n" 468 " lea r10, [g_pfn%s wrt rip]\n" 469 " call LazyLoadResolver\n" 470 "%%elifdef RT_ARCH_X86\n" 471 " push %u\n" 472 " push g_pfn%s\n" 473 " call LazyLoadResolver\n" 474 " add esp, 8h\n" 475 "%%else\n" 476 " %%error \"Unsupported architecture\"\n" 477 "%%endif\n" 478 , 479 pExp->pszExportedNm, 480 pExp->uOrdinal, 481 pExp->pszExportedNm, 482 pExp->uOrdinal, 483 pExp->pszExportedNm); 484 if (!pExp->pszUnstdcallName) 485 fprintf(pOutput, " jmp NAME(%s)\n", pExp->szName); 486 else 487 fprintf(pOutput, 488 "%%ifdef RT_ARCH_X86\n" 489 " jmp %s\n" 490 "%%else\n" 491 " jmp NAME(%s)\n" 492 "%%endif\n" 493 , 494 pExp->szName, pExp->szName); 495 fprintf(pOutput, "\n"); 496 } 415 497 fprintf(pOutput, 416 498 "\n" … … 437 519 * saved all necessary registers. 438 520 */ 439 fprintf(pOutput, 440 ";\n" 441 ";SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod,\n" 442 "; uint32_t fFlags, PRTERRINFO pErrInfo);\n" 443 ";\n" 444 "EXTERN_IMP2 SUPR3HardenedLdrLoadAppPriv\n" 445 "BEGINCODE\n" 446 "\n" 447 "LazyLoading:\n" 448 " mov xCX, [g_hMod xWrtRIP]\n" 449 " or xCX, xCX\n" 450 " jnz .return\n" 451 "\n" 452 "%%ifdef ASM_CALL64_GCC\n" 453 " xor rcx, rcx ; pErrInfo\n" 454 " xor rdx, rdx ; fFlags (local load)\n" 455 " lea rsi, [g_hMod wrt rip] ; phLdrMod\n" 456 " lea rdi, [g_szLibrary wrt rip] ; pszFilename\n" 457 " sub rsp, 08h\n" 458 " call IMP2(SUPR3HardenedLdrLoadAppPriv)\n" 459 " add rsp, 08h\n" 460 "\n" 461 "%%elifdef ASM_CALL64_MSC\n" 462 " xor r9, r9 ; pErrInfo\n" 463 " xor r8, r8 ; fFlags (local load)\n" 464 " lea rdx, [g_hMod wrt rip] ; phLdrMod\n" 465 " lea rcx, [g_szLibrary wrt rip] ; pszFilename\n" 466 " sub rsp, 28h\n" 467 " call IMP2(SUPR3HardenedLdrLoadAppPriv)\n" 468 " add rsp, 28h\n" 469 "\n" 470 "%%elifdef RT_ARCH_X86\n" 471 " sub xSP, 0ch\n" 472 " push 0 ; pErrInfo\n" 473 " push 0 ; fFlags (local load)\n" 474 " push g_hMod ; phLdrMod\n" 475 " push g_szLibrary ; pszFilename\n" 476 " call IMP2(SUPR3HardenedLdrLoadAppPriv)\n" 477 " add esp, 1ch\n" 478 "%%else\n" 479 " %%error \"Unsupported architecture\"\n" 480 "%%endif\n" 521 if (!g_fSystemLibrary) 522 fprintf(pOutput, 523 ";\n" 524 ";SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod,\n" 525 "; uint32_t fFlags, PRTERRINFO pErrInfo);\n" 526 ";\n" 527 "EXTERN_IMP2 SUPR3HardenedLdrLoadAppPriv\n" 528 "%%ifdef IN_RT_R3\n" 529 "extern NAME(RTAssertMsg2Weak)\n" 530 "%%else\n" 531 "EXTERN_IMP2 RTAssertMsg2Weak\n" 532 "%%endif\n" 533 "BEGINCODE\n" 534 "\n" 535 "LazyLoading:\n" 536 " mov xCX, [g_hMod xWrtRIP]\n" 537 " or xCX, xCX\n" 538 " jnz .return\n" 539 "\n" 540 "%%ifdef ASM_CALL64_GCC\n" 541 " xor rcx, rcx ; pErrInfo\n" 542 " xor rdx, rdx ; fFlags (local load)\n" 543 " lea rsi, [g_hMod wrt rip] ; phLdrMod\n" 544 " lea rdi, [g_szLibrary wrt rip] ; pszFilename\n" 545 " sub rsp, 08h\n" 546 " call IMP2(SUPR3HardenedLdrLoadAppPriv)\n" 547 " add rsp, 08h\n" 548 "\n" 549 "%%elifdef ASM_CALL64_MSC\n" 550 " xor r9, r9 ; pErrInfo\n" 551 " xor r8, r8 ; fFlags (local load)\n" 552 " lea rdx, [g_hMod wrt rip] ; phLdrMod\n" 553 " lea rcx, [g_szLibrary wrt rip] ; pszFilename\n" 554 " sub rsp, 28h\n" 555 " call IMP2(SUPR3HardenedLdrLoadAppPriv)\n" 556 " add rsp, 28h\n" 557 "\n" 558 "%%elifdef RT_ARCH_X86\n" 559 " sub xSP, 0ch\n" 560 " push 0 ; pErrInfo\n" 561 " push 0 ; fFlags (local load)\n" 562 " push g_hMod ; phLdrMod\n" 563 " push g_szLibrary ; pszFilename\n" 564 " call IMP2(SUPR3HardenedLdrLoadAppPriv)\n" 565 " add esp, 1ch\n" 566 "%%else\n" 567 " %%error \"Unsupported architecture\"\n" 568 "%%endif\n"); 569 else 570 fprintf(pOutput, 571 ";\n" 572 "; RTDECL(int) RTLdrLoadSystem(const char *pszFilename, bool fNoUnload, PRTLDRMOD phLdrMod);\n" 573 ";\n" 574 "%%ifdef IN_RT_R3\n" 575 "extern NAME(RTLdrLoadSystem)\n" 576 "extern NAME(RTAssertMsg2Weak)\n" 577 "%%else\n" 578 "EXTERN_IMP2 RTLdrLoadSystem\n" 579 "EXTERN_IMP2 RTAssertMsg2Weak\n" 580 "%%endif\n" 581 "BEGINCODE\n" 582 "\n" 583 "LazyLoading:\n" 584 " mov xCX, [g_hMod xWrtRIP]\n" 585 " or xCX, xCX\n" 586 " jnz .return\n" 587 "\n" 588 "%%ifdef ASM_CALL64_GCC\n" 589 " lea rdx, [g_hMod wrt rip] ; phLdrMod\n" 590 " mov esi, 1 ; fNoUnload=true\n" 591 " lea rdi, [g_szLibrary wrt rip] ; pszFilename\n" 592 " sub rsp, 08h\n" 593 " %%ifdef IN_RT_R3\n" 594 " call NAME(RTLdrLoadSystem)\n" 595 " %%else\n" 596 " call IMP2(RTLdrLoadSystem)\n" 597 " %%endif\n" 598 " add rsp, 08h\n" 599 "\n" 600 "%%elifdef ASM_CALL64_MSC\n" 601 " lea r8, [g_hMod wrt rip] ; phLdrMod\n" 602 " mov edx, 1 ; fNoUnload=true\n" 603 " lea rcx, [g_szLibrary wrt rip] ; pszFilename\n" 604 " sub rsp, 28h\n" 605 " %%ifdef IN_RT_R3\n" 606 " call NAME(RTLdrLoadSystem)\n" 607 " %%else\n" 608 " call IMP2(RTLdrLoadSystem)\n" 609 " %%endif\n" 610 " add rsp, 28h\n" 611 "\n" 612 "%%elifdef RT_ARCH_X86\n" 613 " push g_hMod ; phLdrMod\n" 614 " push 1 ; fNoUnload=true\n" 615 " push g_szLibrary ; pszFilename\n" 616 " %%ifdef IN_RT_R3\n" 617 " call NAME(RTLdrLoadSystem)\n" 618 " %%else\n" 619 " call IMP2(RTLdrLoadSystem)\n" 620 " %%endif\n" 621 " add esp, 0ch\n" 622 "%%else\n" 623 " %%error \"Unsupported architecture\"\n" 624 "%%endif\n"); 625 fprintf(pOutput, 481 626 " or eax, eax\n" 482 " jz .loadok\n" 483 ".badload:\n" 484 " int3\n" 485 " jmp .badload\n" 486 ".loadok:\n" 627 " jnz .badload\n" 487 628 " mov xCX, [g_hMod xWrtRIP]\n" 488 629 ".return:\n" 489 630 " ret\n" 631 "\n" 632 ".badload:\n" 633 "%%ifdef ASM_CALL64_GCC\n" 634 " mov edx, eax\n" 635 " lea rsi, [g_szLibrary wrt rip]\n" 636 " lea rdi, [g_szFailLoadFmt wrt rip]\n" 637 " sub rsp, 08h\n" 638 "%%elifdef ASM_CALL64_MSC\n" 639 " mov r8d, eax\n" 640 " lea rdx, [g_szLibrary wrt rip]\n" 641 " lea rcx, [g_szFailLoadFmt wrt rip]\n" 642 " sub rsp, 28h\n" 643 "%%elifdef RT_ARCH_X86\n" 644 " push eax\n" 645 " push g_szLibrary\n" 646 " push g_szFailLoadFmt\n" 647 "%%endif\n" 648 "%%ifdef IN_RT_R3\n" 649 " call NAME(RTAssertMsg2Weak)\n" 650 "%%else\n" 651 " call IMP2(RTAssertMsg2Weak)\n" 652 "%%endif\n" 653 ".badloadloop:\n" 654 " int3\n" 655 " jmp .badloadloop\n" 490 656 "LazyLoading_End:\n" 491 657 "\n" … … 497 663 ";RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);\n" 498 664 ";\n" 665 "%%ifdef IN_RT_R3\n" 666 "extern NAME(RTLdrGetSymbol)\n" 667 "%%else\n" 499 668 "EXTERN_IMP2 RTLdrGetSymbol\n" 669 "%%endif\n" 500 670 "BEGINCODE\n" 501 671 "LazyLoadResolver:\n" … … 531 701 " mov r8, r14 ; ppvValue\n" 532 702 " %%endif\n" 703 " %%ifdef IN_RT_R3\n" 704 " call NAME(RTLdrGetSymbol)\n" 705 " %%else\n" 533 706 " call IMP2(RTLdrGetSymbol)\n" 707 " %%endif\n" 534 708 " or eax, eax\n" 535 " jz .symok\n" 536 ".badsym:\n" 537 " int3\n" 538 " jmp .badsym\n" 539 ".symok:\n" 709 " jnz .badsym\n" 540 710 "\n" 541 711 " mov rsp, r12\n" … … 562 732 "\n" 563 733 ".loaded:\n" 564 " mov eax, [ebp + 4] ; value addr\n" 565 " push eax\n" 566 " mov edx, [ebp + 8] ; symbol name\n" 567 " push edx\n" 568 " call LazyLoading ; returns handle in ecx\n" 569 " mov ecx, [g_hMod]\n" 734 " call LazyLoading ; returns handle in ecx\n" 735 " push dword [ebp + 8] ; value addr\n" 736 " push dword [ebp + 12] ; symbol name\n" 737 " push ecx\n" 738 " %%ifdef IN_RT_R3\n" 739 " call NAME(RTLdrGetSymbol)\n" 740 " %%else\n" 570 741 " call IMP2(RTLdrGetSymbol)\n" 742 " %%endif\n" 571 743 " or eax, eax\n" 572 " jz .symok\n" 573 ".badsym:\n" 574 " int3\n" 575 " jmp .badsym\n" 576 ".symok:\n" 744 " jnz .badsym\n" 577 745 " lea esp, [ebp - 0ch]\n" 578 746 " pop edx\n" … … 584 752 "%%endif\n" 585 753 " ret\n" 754 "\n" 755 ".badsym:\n" 756 "%%ifdef ASM_CALL64_GCC\n" 757 " mov ecx, eax\n" 758 " lea rdx, [g_szLibrary wrt rip]\n" 759 " mov rsi, r15\n" 760 " lea rdi, [g_szFailResolveFmt wrt rip]\n" 761 " sub rsp, 08h\n" 762 "%%elifdef ASM_CALL64_MSC\n" 763 " mov r9d, eax\n" 764 " mov r8, r15\n" 765 " lea rdx, [g_szLibrary wrt rip]\n" 766 " lea rcx, [g_szFailResolveFmt wrt rip]\n" 767 " sub rsp, 28h\n" 768 "%%elifdef RT_ARCH_X86\n" 769 " push eax\n" 770 " push dword [ebp + 12]\n" 771 " push g_szLibrary\n" 772 " push g_szFailResolveFmt\n" 773 "%%endif\n" 774 "%%ifdef IN_RT_R3\n" 775 " call NAME(RTAssertMsg2Weak)\n" 776 "%%else\n" 777 " call IMP2(RTAssertMsg2Weak)\n" 778 "%%endif\n" 779 ".badsymloop:\n" 780 " int3\n" 781 " jmp .badsymloop\n" 782 "\n" 586 783 "LazyLoadResolver_End:\n" 587 784 "\n" … … 597 794 if (g_fWithExplictLoadFunction) 598 795 { 796 if (g_fSystemLibrary) /* Lazy bird. */ 797 { 798 fprintf(stderr, "error: cannot use --system with --explicit-load-function, sorry\n"); 799 return RTEXITCODE_FAILURE; 800 } 801 599 802 int cchLibBaseName = (int)(strchr(g_pszLibrary, '.') ? strchr(g_pszLibrary, '.') - g_pszLibrary : strlen(g_pszLibrary)); 600 803 fprintf(pOutput, … … 835 1038 else if (!strcmp(psz, "--no-explicit-load-function")) 836 1039 g_fWithExplictLoadFunction = false; 1040 else if (!strcmp(psz, "--system")) 1041 g_fSystemLibrary = true; 837 1042 /** @todo Support different load methods so this can be used on system libs and 838 1043 * such if we like. */
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器