VirtualBox

Changeset 25300 in vbox for trunk/src/VBox/HostDrivers


Ignore:
Timestamp:
Dec 10, 2009 2:09:44 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
55861
Message:

SUPDrv: Cleaned up the native loader implmenetation on windows and enabled it.

Location:
trunk/src/VBox/HostDrivers/Support
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/Makefile.kmk

    r25291 r25300  
    174174endif
    175175VBoxDrv_DEFS          = IN_RT_R0 IN_SUP_R0 SUPDRV_WITH_RELEASE_LOGGER
    176 VBoxDrv_DEFS.amd64    = RT_WITH_W64_UNWIND_HACK
     176ifdef VBOX_WITHOUT_NATIVE_R0_LOADER
     177 VBoxDrv_DEFS.amd64   = RT_WITH_W64_UNWIND_HACK VBOX_WITHOUT_NATIVE_R0_LOADER
     178endif
    177179ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
    178180VBoxDrv_DEFS         += VBOX_WITH_VMMR0_DISABLE_PREEMPTION
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r25278 r25300  
    261261*   Global Variables                                                           *
    262262*******************************************************************************/
    263 /** Pointer to the global info page for implementing SUPGetGIP(). */
    264 static PSUPGLOBALINFOPAGE      g_pSUPGlobalInfoPageInternal = NULL;
    265 #if defined(RT_OS_WINDOWS)
    266263DECLEXPORT(PSUPGLOBALINFOPAGE) g_pSUPGlobalInfoPage = NULL;
    267 # define SUPR0_EXPORT_GIP_POINTER
    268 #endif
    269264
    270265/**
     
    321316    { "SUPR0EnableVTx",                         (void *)SUPR0EnableVTx },
    322317    { "SUPGetGIP",                              (void *)SUPGetGIP },
    323     { "g_pSUPGlobalInfoPage",                   (void *)&g_pSUPGlobalInfoPageInternal },
     318    { "g_pSUPGlobalInfoPage",                   (void *)&g_pSUPGlobalInfoPage },
    324319    { "RTMemAlloc",                             (void *)UNWIND_WRAP(RTMemAlloc) },
    325320    { "RTMemAllocZ",                            (void *)UNWIND_WRAP(RTMemAllocZ) },
     
    30903085SUPDECL(PSUPGLOBALINFOPAGE) SUPGetGIP(void)
    30913086{
    3092     return g_pSUPGlobalInfoPageInternal;
     3087    return g_pSUPGlobalInfoPage;
    30933088}
    30943089
     
    45354530             */
    45364531            dprintf(("supdrvGipCreate: %ld ns interval.\n", (long)u32Interval));
    4537             g_pSUPGlobalInfoPageInternal = pGip;
    4538 #ifdef SUPR0_EXPORT_GIP_POINTER
    45394532            g_pSUPGlobalInfoPage = pGip;
    4540 #endif
    45414533            return VINF_SUCCESS;
    45424534        }
     
    45764568        pDevExt->pGip = NULL;
    45774569    }
    4578     g_pSUPGlobalInfoPageInternal = NULL;
    4579 #ifdef SUPR0_EXPORT_GIP_POINTER
    45804570    g_pSUPGlobalInfoPage = NULL;
    4581 #endif
    45824571
    45834572    /*
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r25278 r25300  
    3636#include <excpt.h>
    3737#include <iprt/assert.h>
     38#include <iprt/initterm.h>
     39#include <iprt/mem.h>
    3840#include <iprt/process.h>
    39 #include <iprt/initterm.h>
    4041#include <iprt/power.h>
     42#include <iprt/string.h>
    4143#include <VBox/log.h>
    4244
     
    595597
    596598
    597 #define MY_SystemLoadGdiDriverInformation               26
    598599#define MY_SystemLoadGdiDriverInSystemSpaceInformation  54
    599600#define MY_SystemUnloadGdiDriverInformation             27
     
    613614int  VBOXCALL   supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
    614615{
    615 #if 0
    616     MYSYSTEMGDIDRIVERINFO Info;
    617 
    618     /** @todo fix this horrible stuff. */
    619     WCHAR wszConv[192 + 32];
    620     unsigned i = 0;
    621     wszConv[i++] = '\\';
    622     wszConv[i++] = '?';
    623     wszConv[i++] = '?';
    624     wszConv[i++] = '\\';
    625     unsigned cchPref = i;
    626     char ch;
    627     do
    628     {
    629         ch = pszFilename[i - cchPref];
    630         wszConv[i++] = ch == '/' ? '\\' : ch;
    631     } while (ch);
    632     RtlInitUnicodeString(&Info.Name, wszConv);
    633 
    634     Info.ImageAddress           = NULL;
    635     Info.SectionPointer         = NULL;
    636     Info.EntryPointer           = NULL;
    637     Info.ExportSectionPointer   = NULL;
    638     Info.ImageLength            = 0;
    639 
    640     NTSTATUS rc = ZwSetSystemInformation(MY_SystemLoadGdiDriverInSystemSpaceInformation, &Info, sizeof(Info));
    641     if (NT_SUCCESS(rc))
    642     {
    643         pImage->pvImage = Info.ImageAddress;
    644         pImage->pvNtSectionObj = Info.SectionPointer;
    645         SUPR0Printf("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rc=%#x '%ws'\n",
    646                     Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rc, Info.Name.Buffer);
    647         if (pImage->cbImageBits == Info.ImageLength)
    648             return VINF_SUCCESS;
    649         supdrvOSLdrUnload(pDevExt, pImage);
    650         rc = STATUS_INFO_LENGTH_MISMATCH;
    651     }
    652     SUPR0Printf("rc=%#x '%ws'\n", rc, Info.Name.Buffer);
    653     //STATUS_OBJECT_NAME_NOT_FOUND       == 0xc0000034 -> SUPR0
    654     //STATUS_DRIVER_ENTRYPOINT_NOT_FOUND == 0xC0000263 -> SUPR0
    655 
    656     NOREF(pDevExt); NOREF(pszFilename);
    657     pImage->pvNtSectionObj = NULL;
    658     return VERR_INTERNAL_ERROR_5; /** @todo convert status, making sure it isn't NOT_SUPPORTED. */
    659 #else
     616#ifdef VBOX_WITHOUT_NATIVE_R0_LOADER
    660617    NOREF(pDevExt); NOREF(pszFilename); NOREF(pImage);
    661618    return VERR_NOT_SUPPORTED;
     619
     620#else
     621    /*
     622     * Convert the filename from DOS UTF-8 to NT UTF-16.
     623     */
     624    size_t cwcFilename;
     625    int rc = RTStrCalcUtf16LenEx(pszFilename, RTSTR_MAX, &cwcFilename);
     626    if (RT_FAILURE(rc))
     627        return rc;
     628
     629    PRTUTF16 pwcsFilename = (PRTUTF16)RTMemTmpAlloc((4 + cwcFilename + 1) * sizeof(RTUTF16));
     630    if (!pwcsFilename)
     631        return VERR_NO_TMP_MEMORY;
     632
     633    pwcsFilename[0] = '\\';
     634    pwcsFilename[1] = '?';
     635    pwcsFilename[2] = '?';
     636    pwcsFilename[3] = '\\';
     637    PRTUTF16 pwcsTmp = &pwcsFilename[4];
     638    rc = RTStrToUtf16Ex(pszFilename, RTSTR_MAX, &pwcsTmp, cwcFilename + 1, NULL);
     639    if (RT_SUCCESS(rc))
     640    {
     641        /*
     642         * Try load it.
     643         */
     644        MYSYSTEMGDIDRIVERINFO Info;
     645        RtlInitUnicodeString(&Info.Name, pwcsFilename);
     646        Info.ImageAddress           = NULL;
     647        Info.SectionPointer         = NULL;
     648        Info.EntryPointer           = NULL;
     649        Info.ExportSectionPointer   = NULL;
     650        Info.ImageLength            = 0;
     651
     652        NTSTATUS rcNt = ZwSetSystemInformation(MY_SystemLoadGdiDriverInSystemSpaceInformation, &Info, sizeof(Info));
     653        if (NT_SUCCESS(rcNt))
     654        {
     655            pImage->pvImage = Info.ImageAddress;
     656            pImage->pvNtSectionObj = Info.SectionPointer;
     657            Log(("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rcNt=%#x '%ls'\n",
     658                 Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer));
     659# ifdef DEBUG_bird
     660            SUPR0Printf("ImageAddress=%p SectionPointer=%p ImageLength=%#x cbImageBits=%#x rcNt=%#x '%ws'\n",
     661                        Info.ImageAddress, Info.SectionPointer, Info.ImageLength, pImage->cbImageBits, rcNt, Info.Name.Buffer);
     662# endif
     663            if (pImage->cbImageBits == Info.ImageLength)
     664            {
     665                /** @todo do we need to lock down the image? */
     666                rc = VINF_SUCCESS;
     667            }
     668            else
     669            {
     670                supdrvOSLdrUnload(pDevExt, pImage);
     671                rc = VERR_LDR_MISMATCH_NATIVE;
     672            }
     673        }
     674        else
     675        {
     676            Log(("rcNt=%#x '%ws'\n", rcNt, pwcsFilename));
     677            SUPR0Printf("VBoxDrv: rcNt=%#x '%ws'\n", rcNt, pwcsFilename);
     678            switch (rcNt)
     679            {
     680                case /* 0xc0000003 */ STATUS_INVALID_INFO_CLASS:
     681                    /*
     682                     * Use the old way of loading the modules if we can.  We do
     683                     * not try class 26 because it will not work correctly on
     684                     * terminal server and have issues with paging of the image.
     685                     *
     686                     * Note! Using the 64-bit wrappers will require hacking the
     687                     *       image verfication in supdrvOSLdrLoad.
     688                     */
     689# if !defined(RT_ARCH_AMD64) || defined(RT_WITH_W64_UNWIND_HACK)
     690                    rc = VERR_NOT_SUPPORTED;
     691# else
     692                    rc = VERR_NOT_IMPLEMENTED;
     693# endif
     694                    break;
     695                case /* 0xc0000034 */ STATUS_OBJECT_NAME_NOT_FOUND:
     696                    rc = VERR_MODULE_NOT_FOUND;
     697                    break;
     698                case /* 0xC0000263 */ STATUS_DRIVER_ENTRYPOINT_NOT_FOUND:
     699                    rc = VERR_LDR_IMPORTED_SYMBOL_NOT_FOUND;
     700                    break;
     701                default:
     702                    rc = VERR_LDR_GENERAL_FAILURE;
     703                    break;
     704            }
     705
     706            pImage->pvNtSectionObj = NULL;
     707        }
     708    }
     709
     710    RTMemTmpFree(pwcsFilename);
     711    NOREF(pDevExt);
     712    return rc;
    662713#endif
    663714}
     
    676727    if (pImage->pvNtSectionObj)
    677728    {
    678         /** @todo check that the two image versions matches. */
    679         return VINF_SUCCESS;
     729        if (!memcmp(pImage->pvImage, pbImageBits, pImage->cbImageBits))
     730            return VINF_SUCCESS;
     731
     732        /* trac down the difference and log it. */
     733        uint32_t        cbLeft = pImage->cbImageBits;
     734        const uint8_t  *pbNativeBits = (const uint8_t *)pImage->pvImage;
     735        for (size_t off = 0; cbLeft > 0; off++, cbLeft--)
     736            if (pbNativeBits[off] != pbImageBits[off])
     737            {
     738                char szBytes[128];
     739                RTStrPrintf(szBytes, sizeof(szBytes), "native: %.*Rhxs  our: %.*Rhxs",
     740                            RT_MIN(12, cbLeft), &pbNativeBits[off],
     741                            RT_MIN(12, cbLeft), &pbImageBits[off]);
     742                SUPR0Printf("VBoxDrv: Mismatch at %#x of %s: %s\n", off, pImage->szName, szBytes);
     743                return VERR_LDR_MISMATCH_NATIVE;
     744            }
    680745    }
    681746    return VERR_INTERNAL_ERROR_4;
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