VirtualBox

Ignore:
Timestamp:
Oct 17, 2013 7:22:02 AM (11 years ago)
Author:
vboxsync
Message:

SUPR3: Use NtDeviceIoControlFile instead of DeviceIoControl to avoid wasting precious ticks on silly API conversions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp

    r44528 r49150  
    3838#endif
    3939
    40 #include <Windows.h>
     40#define USE_NT_DEVICE_IO_CONTROL_FILE
     41#ifdef USE_NT_DEVICE_IO_CONTROL_FILE
     42# include <iprt/nt/nt-and-windows.h>
     43#else
     44# include <Windows.h>
     45#endif
    4146
    4247#include <VBox/sup.h>
     
    7580static int suplibOsStartService(void);
    7681static int suplibOsStopService(void);
     82#ifdef USE_NT_DEVICE_IO_CONTROL_FILE
     83static int suplibConvertNtStatus(NTSTATUS rcNt);
     84#else
    7785static int suplibConvertWin32Err(int);
     86#endif
    7887
    7988
     
    496505    PSUPREQHDR pHdr = (PSUPREQHDR)pvReq;
    497506    Assert(cbReq == RT_MAX(pHdr->cbIn, pHdr->cbOut));
     507# ifdef USE_NT_DEVICE_IO_CONTROL_FILE
     508    IO_STATUS_BLOCK Ios;
     509    Ios.Status = -1;
     510    Ios.Information = 0;
     511    NTSTATUS rcNt = NtDeviceIoControlFile((HANDLE)pThis->hDevice, NULL /*hEvent*/, NULL /*pfnApc*/, NULL /*pvApcCtx*/, &Ios,
     512                                          (ULONG)uFunction,
     513                                          pvReq /*pvInput */, pHdr->cbIn /* cbInput */,
     514                                          pvReq /*pvOutput*/, pHdr->cbOut /* cbOutput */);
     515    if (NT_SUCCESS(rcNt))
     516    {
     517        if (NT_SUCCESS(Ios.Status))
     518            return VINF_SUCCESS;
     519        rcNt = Ios.Status;
     520    }
     521    return suplibConvertNtStatus(rcNt);
     522
     523# else
    498524    DWORD cbReturned = (ULONG)pHdr->cbOut;
    499525    if (DeviceIoControl((HANDLE)pThis->hDevice, uFunction, pvReq, pHdr->cbIn, pvReq, cbReturned, &cbReturned, NULL))
    500526        return 0;
    501527    return suplibConvertWin32Err(GetLastError());
     528# endif
    502529}
    503530
     
    508535     * Issue device I/O control.
    509536     */
     537# ifdef USE_NT_DEVICE_IO_CONTROL_FILE
     538    IO_STATUS_BLOCK Ios;
     539    Ios.Status = -1;
     540    Ios.Information = 0;
     541    NTSTATUS rcNt = NtDeviceIoControlFile((HANDLE)pThis->hDevice, NULL /*hEvent*/, NULL /*pfnApc*/, NULL /*pvApcCtx*/, &Ios,
     542                                          (ULONG)uFunction,
     543                                          (PVOID)idCpu /*pvInput */, 0 /* cbInput */,
     544                                          NULL /*pvOutput*/, 0 /* cbOutput */);
     545    if (NT_SUCCESS(rcNt))
     546    {
     547        if (NT_SUCCESS(Ios.Status))
     548            return VINF_SUCCESS;
     549        rcNt = Ios.Status;
     550    }
     551    return suplibConvertNtStatus(rcNt);
     552# else
    510553    DWORD cbReturned = 0;
    511554    if (DeviceIoControl((HANDLE)pThis->hDevice, uFunction, NULL, 0, (LPVOID)idCpu, 0, &cbReturned, NULL))
    512555        return VINF_SUCCESS;
    513556    return suplibConvertWin32Err(GetLastError());
     557# endif
    514558}
    515559
     
    521565    if (*ppvPages)
    522566        return VINF_SUCCESS;
    523     return suplibConvertWin32Err(GetLastError());
     567    return RTErrConvertFromWin32(GetLastError());
    524568}
    525569
     
    530574    if (VirtualFree(pvPages, 0, MEM_RELEASE))
    531575        return VINF_SUCCESS;
    532     return suplibConvertWin32Err(GetLastError());
    533 }
    534 
    535 
     576    return RTErrConvertFromWin32(GetLastError());
     577}
     578
     579
     580# ifndef USE_NT_DEVICE_IO_CONTROL_FILE
    536581/**
    537582 * Converts a supdrv win32 error code to an IPRT status code.
     
    585630    return RTErrConvertFromWin32(rc);
    586631}
     632# else
     633/**
     634 * Reverse of VBoxDrvNtErr2NtStatus
     635 * returns VBox status code.
     636 * @param   rcNt    NT status code.
     637 */
     638static int suplibConvertNtStatus(NTSTATUS rcNt)
     639{
     640    switch (rcNt)
     641    {
     642        case STATUS_SUCCESS:                    return VINF_SUCCESS;
     643        case STATUS_NOT_SUPPORTED:              return VERR_GENERAL_FAILURE;
     644        case STATUS_INVALID_PARAMETER:          return VERR_INVALID_PARAMETER;
     645        case STATUS_UNKNOWN_REVISION:           return VERR_INVALID_MAGIC;
     646        case STATUS_INVALID_HANDLE:             return VERR_INVALID_HANDLE;
     647        case STATUS_INVALID_ADDRESS:            return VERR_INVALID_POINTER;
     648        case STATUS_NOT_LOCKED:                 return VERR_LOCK_FAILED;
     649        case STATUS_IMAGE_ALREADY_LOADED:       return VERR_ALREADY_LOADED;
     650        case STATUS_ACCESS_DENIED:              return VERR_PERMISSION_DENIED;
     651        case STATUS_REVISION_MISMATCH:          return VERR_VERSION_MISMATCH;
     652    }
     653
     654    /* Fall back on IPRT for the rest. */
     655    return RTErrConvertFromNtStatus(rcNt);
     656}
     657# endif
    587658
    588659#endif /* !IN_SUP_HARDENED_R3 */
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