VirtualBox

Ignore:
Timestamp:
Jul 19, 2011 4:19:42 PM (14 years ago)
Author:
vboxsync
Message:

SUPDrv: Check pSession in the IOCtl routine and clean up a little earlier on windows.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPDrv.c

    r37955 r38075  
    974974     * We check the two prereqs after doing this only to allow the compiler to optimize things better.
    975975     */
    976     if (RT_LIKELY(pSession->pVM && pDevExt->pfnVMMR0EntryFast))
     976    if (RT_LIKELY(   RT_VALID_PTR(pSession)
     977                  && pSession->pVM
     978                  && pDevExt->pfnVMMR0EntryFast))
    977979    {
    978980        switch (uIOCtl)
     
    10461048        OSDBGPRINT(("vboxdrv: Bad ioctl request header; cbIn=%#lx cbOut=%#lx fFlags=%#lx\n",
    10471049                    (long)pReqHdr->cbIn, (long)pReqHdr->cbOut, (long)pReqHdr->fFlags));
     1050        VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VINF_SUCCESS);
     1051        return VERR_INVALID_PARAMETER;
     1052    }
     1053    if (RT_UNLIKELY(!RT_VALID_PTR(pSession)))
     1054    {
     1055        OSDBGPRINT(("vboxdrv: Invalid pSession valud %p (ioctl=%p)\n", pSession, (void *)uIOCtl));
    10481056        VBOXDRV_SUPDRV_IOCTL_RETURN(pSession, uIOCtl, pReqHdr, VERR_INVALID_PARAMETER, VINF_SUCCESS);
    10491057        return VERR_INVALID_PARAMETER;
  • trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp

    r37249 r38075  
    7575static void     _stdcall   VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj);
    7676static NTSTATUS _stdcall   VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);
     77static NTSTATUS _stdcall   VBoxDrvNtCleanup(PDEVICE_OBJECT pDevObj, PIRP pIrp);
    7778static NTSTATUS _stdcall   VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
    7879static NTSTATUS _stdcall   VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
     
    138139                    pDrvObj->DriverUnload                                   = VBoxDrvNtUnload;
    139140                    pDrvObj->MajorFunction[IRP_MJ_CREATE]                   = VBoxDrvNtCreate;
     141                    pDrvObj->MajorFunction[IRP_MJ_CLEANUP]                  = VBoxDrvNtCleanup;
    140142                    pDrvObj->MajorFunction[IRP_MJ_CLOSE]                    = VBoxDrvNtClose;
    141143                    pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL]           = VBoxDrvNtDeviceControl;
    142 //#if 0 /** @todo test IDC on windows. */
    143144                    pDrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL]  = VBoxDrvNtInternalDeviceControl;
    144 //#endif
    145145                    pDrvObj->MajorFunction[IRP_MJ_READ]                     = VBoxDrvNtNotSupportedStub;
    146146                    pDrvObj->MajorFunction[IRP_MJ_WRITE]                    = VBoxDrvNtNotSupportedStub;
     
    272272
    273273/**
    274  * Close file entry point.
     274 * Clean up file handle entry point.
    275275 *
    276276 * @param   pDevObj     Device object.
    277277 * @param   pIrp        Request packet.
    278278 */
     279NTSTATUS _stdcall VBoxDrvNtCleanup(PDEVICE_OBJECT pDevObj, PIRP pIrp)
     280{
     281    PSUPDRVDEVEXT       pDevExt  = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
     282    PIO_STACK_LOCATION  pStack   = IoGetCurrentIrpStackLocation(pIrp);
     283    PFILE_OBJECT        pFileObj = pStack->FileObject;
     284    PSUPDRVSESSION      pSession = (PSUPDRVSESSION)pFileObj->FsContext;
     285
     286    Log(("VBoxDrvNtCleanup: pDevExt=%p pFileObj=%p pSession=%p\n", pDevExt, pFileObj, pSession));
     287    if (pSession)
     288    {
     289        supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
     290        pFileObj->FsContext = NULL;
     291    }
     292
     293    pIrp->IoStatus.Information = 0;
     294    pIrp->IoStatus.Status = STATUS_SUCCESS;
     295    IoCompleteRequest(pIrp, IO_NO_INCREMENT);
     296
     297    return STATUS_SUCCESS;
     298}
     299
     300
     301/**
     302 * Close file entry point.
     303 *
     304 * @param   pDevObj     Device object.
     305 * @param   pIrp        Request packet.
     306 */
    279307NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
    280308{
    281     PSUPDRVDEVEXT       pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
    282     PIO_STACK_LOCATION  pStack = IoGetCurrentIrpStackLocation(pIrp);
     309    PSUPDRVDEVEXT       pDevExt  = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
     310    PIO_STACK_LOCATION  pStack   = IoGetCurrentIrpStackLocation(pIrp);
    283311    PFILE_OBJECT        pFileObj = pStack->FileObject;
    284     Log(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
    285          pDevExt, pFileObj, pFileObj->FsContext));
    286     supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
    287     pFileObj->FsContext = NULL;
     312    PSUPDRVSESSION      pSession = (PSUPDRVSESSION)pFileObj->FsContext;
     313
     314    Log(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n", pDevExt, pFileObj, pSession));
     315    if (pSession)
     316    {
     317        supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
     318        pFileObj->FsContext = NULL;
     319    }
     320
    288321    pIrp->IoStatus.Information = 0;
    289322    pIrp->IoStatus.Status = STATUS_SUCCESS;
     
    446479          pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
    447480          pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
    448 
    449 /** @todo IDC on NT: figure when to create the session and that stuff... */
    450481
    451482    /* Verify that it's a buffered CTL. */
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