VirtualBox

Changeset 99539 in vbox


Ignore:
Timestamp:
Apr 26, 2023 9:34:08 PM (18 months ago)
Author:
vboxsync
Message:

VBoxDef2LazyLoad.cpp: Added support for explicit load functions for system libraries (x86 & amd64).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/VBoxDef2LazyLoad.cpp

    r98660 r99539  
    836836    if (g_fWithExplictLoadFunction)
    837837    {
    838         if (g_fSystemLibrary) /* Lazy bird. */
    839         {
    840             fprintf(stderr, "error: cannot use --system with --explicit-load-function, sorry\n");
    841             return RTEXITCODE_FAILURE;
    842         }
    843 
    844838        int cchLibBaseName = (int)(strchr(g_pszLibrary, '.') ? strchr(g_pszLibrary, '.') - g_pszLibrary : strlen(g_pszLibrary));
    845839        fprintf(pOutput,
     
    847841                "; ExplicitlyLoad%.*s(bool fResolveAllImports, pErrInfo);\n"
    848842                ";\n"
     843                "%%ifdef IN_RT_R3\n"
     844                "extern NAME(RTErrInfoSet)\n"
     845                "%%else\n"
    849846                "EXTERN_IMP2 RTErrInfoSet\n"
     847                "%%endif\n"
    850848                "BEGINCODE\n"
    851849                "BEGINPROC ExplicitlyLoad%.*s\n"
     
    882880                "    ; Load the module.\n"
    883881                "    ;\n"
    884                 "%%ifdef ASM_CALL64_GCC\n"
    885                 "    mov     rcx, [xBP - xCB * 4]       ; pErrInfo\n"
    886                 "    xor     rdx, rdx                   ; fFlags (local load)\n"
    887                 "    lea     rsi, [g_hMod wrt rip]      ; phLdrMod\n"
    888                 "    lea     rdi, [g_szLibrary wrt rip] ; pszFilename\n"
    889                 "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
    890                 "\n"
    891                 "%%elifdef ASM_CALL64_MSC\n"
    892                 "    mov     r9, [xBP - xCB * 4]        ; pErrInfo\n"
    893                 "    xor     r8, r8                     ; fFlags (local load)\n"
    894                 "    lea     rdx, [g_hMod wrt rip]      ; phLdrMod\n"
    895                 "    lea     rcx, [g_szLibrary wrt rip] ; pszFilename\n"
    896                 "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
    897                 "\n"
    898                 "%%elifdef RT_ARCH_X86\n"
    899                 "    sub     xSP, 0ch\n"
    900                 "    push    dword [xBP + 12]           ; pErrInfo\n"
    901                 "    push    0                          ; fFlags (local load)\n"
    902                 "    push    g_hMod                     ; phLdrMod\n"
    903                 "    push    g_szLibrary                ; pszFilename\n"
    904                 "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
    905                 "    add     esp, 1ch\n"
    906                 "%%else\n"
    907                 " %%error \"Unsupported architecture\"\n"
    908                 "%%endif\n"
     882                ,
     883                cchLibBaseName, g_pszLibrary,
     884                cchLibBaseName, g_pszLibrary);
     885        if (!g_fSystemLibrary)
     886            fprintf(pOutput,
     887                    "%%ifdef ASM_CALL64_GCC\n"
     888                    "    mov     rcx, [xBP - xCB * 4]       ; pErrInfo\n"
     889                    "    xor     rdx, rdx                   ; fFlags (local load)\n"
     890                    "    lea     rsi, [g_hMod wrt rip]      ; phLdrMod\n"
     891                    "    lea     rdi, [g_szLibrary wrt rip] ; pszFilename\n"
     892                    "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
     893                    "\n"
     894                    "%%elifdef ASM_CALL64_MSC\n"
     895                    "    mov     r9, [xBP - xCB * 4]        ; pErrInfo\n"
     896                    "    xor     r8, r8                     ; fFlags (local load)\n"
     897                    "    lea     rdx, [g_hMod wrt rip]      ; phLdrMod\n"
     898                    "    lea     rcx, [g_szLibrary wrt rip] ; pszFilename\n"
     899                    "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
     900                    "\n"
     901                    "%%elifdef RT_ARCH_X86\n"
     902                    "    sub     xSP, 0ch\n"
     903                    "    push    dword [xBP + 12]           ; pErrInfo\n"
     904                    "    push    0                          ; fFlags (local load)\n"
     905                    "    push    g_hMod                     ; phLdrMod\n"
     906                    "    push    g_szLibrary                ; pszFilename\n"
     907                    "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
     908                    "    add     esp, 1ch\n"
     909                    "%%else\n"
     910                    " %%error \"Unsupported architecture\"\n"
     911                    "%%endif\n");
     912        else
     913            fprintf(pOutput,
     914                    "%%ifdef ASM_CALL64_GCC\n"
     915                    "    lea     rdx, [g_hMod wrt rip]      ; phLdrMod\n"
     916                    "    mov     esi, 1                     ; fNoUnload=true\n"
     917                    "    lea     rdi, [g_szLibrary wrt rip] ; pszFilename\n"
     918                    " %%ifdef IN_RT_R3\n"
     919                    "    call    NAME(RTLdrLoadSystem)\n"
     920                    " %%else\n"
     921                    "    call    IMP2(RTLdrLoadSystem)\n"
     922                    " %%endif\n"
     923                    "\n"
     924                    "%%elifdef ASM_CALL64_MSC\n"
     925                    "    lea     r8, [g_hMod wrt rip]       ; phLdrMod\n"
     926                    "    mov     edx, 1                     ; fNoUnload=true\n"
     927                    "    lea     rcx, [g_szLibrary wrt rip] ; pszFilename\n"
     928                    " %%ifdef IN_RT_R3\n"
     929                    "    call    NAME(RTLdrLoadSystem)\n"
     930                    " %%else\n"
     931                    "    call    IMP2(RTLdrLoadSystem)\n"
     932                    " %%endif\n"
     933                    "\n"
     934                    "%%elifdef RT_ARCH_X86\n"
     935                    "    push    g_hMod                     ; phLdrMod\n"
     936                    "    push    1                          ; fNoUnload=true\n"
     937                    "    push    g_szLibrary                ; pszFilename\n"
     938                    " %%ifdef IN_RT_R3\n"
     939                    "    call    NAME(RTLdrLoadSystem)\n"
     940                    " %%else\n"
     941                    "    call    IMP2(RTLdrLoadSystem)\n"
     942                    " %%endif\n"
     943                    "    add     esp, 0ch\n"
     944                    "%%else\n"
     945                    " %%error \"Unsupported architecture\"\n"
     946                    "%%endif\n");
     947         fprintf(pOutput,
    909948                "    or      eax, eax\n"
    910949                "    jnz     .return\n"
     
    930969                "    mov     rsi, pszCurStr            ; pszSymbol\n"
    931970                "    mov     rdi, [g_hMod wrt rip]     ; hLdrMod\n"
     971                " %%ifdef IN_RT_R3\n"
     972                "    call    NAME(RTLdrGetSymbol)\n"
     973                " %%else\n"
    932974                "    call    IMP2(RTLdrGetSymbol)\n"
     975                " %%endif\n"
    933976                "%%elifdef ASM_CALL64_MSC\n"
    934977                "    mov     r8, xBX                   ; ppvValue\n"
    935978                "    mov     rdx, pszCurStr            ; pszSymbol\n"
    936979                "    mov     rcx, [g_hMod wrt rip]     ; pszSymbol\n"
     980                " %%ifdef IN_RT_R3\n"
     981                "    call    NAME(RTLdrGetSymbol)\n"
     982                " %%else\n"
    937983                "    call    IMP2(RTLdrGetSymbol)\n"
     984                " %%endif\n"
    938985                "%%else\n"
    939986                "    push    xBX                       ; ppvValue\n"
    940987                "    push    pszCurStr                 ; pszSymbol\n"
    941988                "    push    RTCCPTR_PRE [g_hMod]      ; hLdrMod\n"
     989                " %%ifdef IN_RT_R3\n"
     990                "    call    NAME(RTLdrGetSymbol)\n"
     991                " %%else\n"
    942992                "    call    IMP2(RTLdrGetSymbol)\n"
     993                " %%endif\n"
    943994                "    add     xSP, 0ch\n"
    944995                "%%endif\n"
     
    9671018                "    mov     esi, eax                  ; rc\n"
    9681019                "    mov     rdi, [xBP - xCB * 4]      ; pErrInfo\n"
     1020                " %%ifdef IN_RT_R3\n"
     1021                "    call    NAME(RTErrInfoSet)\n"
     1022                " %%else\n"
    9691023                "    call    IMP2(RTErrInfoSet)\n"
     1024                " %%endif\n"
    9701025                "%%elifdef ASM_CALL64_MSC\n"
    9711026                "    mov     r8, pszCurStr             ; pszMsg\n"
    9721027                "    mov     edx, eax                  ; rc\n"
    9731028                "    mov     rcx, [xBP - xCB * 4]      ; pErrInfo\n"
     1029                " %%ifdef IN_RT_R3\n"
     1030                "    call    NAME(RTErrInfoSet)\n"
     1031                " %%else\n"
    9741032                "    call    IMP2(RTErrInfoSet)\n"
     1033                " %%endif\n"
    9751034                "%%else\n"
    9761035                "    push    pszCurStr                 ; pszMsg\n"
    9771036                "    push    eax                       ; pszSymbol\n"
    9781037                "    push    dword [xBP + 0ch]         ; pErrInfo\n"
     1038                " %%ifdef IN_RT_R3\n"
     1039                "    call    NAME(RTErrInfoSet)\n"
     1040                " %%else\n"
    9791041                "    call    IMP2(RTErrInfoSet)\n"
     1042                " %%endif\n"
    9801043                "    add     xSP, 0ch\n"
    9811044                "%%endif\n"
     
    9911054                "\n"
    9921055                ,
    993                 cchLibBaseName, g_pszLibrary,
    994                 cchLibBaseName, g_pszLibrary,
    995                 cchLibBaseName, g_pszLibrary
    996                 );
     1056                cchLibBaseName, g_pszLibrary);
    9971057    }
    9981058
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