win-pvdrivers

changeset 800:1d06ba3917d2

Unhook dbgprint on unload so we dont crash
author James Harper <james.harper@bendigoit.com.au>
date Thu Jun 24 12:51:23 2010 +1000 (2010-06-24)
parents 213306951ec5
children 0be989e514c0
files xenpci/xenpci.c xenpci/xenpci_dbgprint.c
line diff
     1.1 --- a/xenpci/xenpci.c	Sat May 22 20:39:27 2010 +1000
     1.2 +++ b/xenpci/xenpci.c	Thu Jun 24 12:51:23 2010 +1000
     1.3 @@ -388,7 +388,7 @@ VOID
     1.4  XenPci_HideQemuDevices()
     1.5  {
     1.6    WRITE_PORT_USHORT(XEN_IOPORT_DEVICE_MASK, (USHORT)qemu_hide_flags_value); //QEMU_UNPLUG_ALL_IDE_DISKS|QEMU_UNPLUG_ALL_NICS);
     1.7 -  KdPrint((__DRIVER_NAME "     Disabled qemu devices\n"));\
     1.8 +  KdPrint((__DRIVER_NAME "     Disabled qemu devices %02x\n", qemu_hide_flags_value));
     1.9  }
    1.10  
    1.11  static BOOLEAN
    1.12 @@ -540,6 +540,18 @@ XenPci_FixLoadOrder()
    1.13    return;
    1.14  }
    1.15  
    1.16 +EVT_WDF_DRIVER_UNLOAD EvtDriverUnload;
    1.17 +
    1.18 +VOID
    1.19 +XenPci_EvtDriverUnload(WDFDRIVER driver)
    1.20 +{
    1.21 +  UNREFERENCED_PARAMETER(driver);
    1.22 +  
    1.23 +  #if DBG
    1.24 +  XenPci_UnHookDbgPrint();
    1.25 +  #endif  
    1.26 +}
    1.27 +
    1.28  NTSTATUS
    1.29  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    1.30  {
    1.31 @@ -628,6 +640,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    1.32    }
    1.33    
    1.34    WDF_DRIVER_CONFIG_INIT(&config, XenPci_EvtDeviceAdd);
    1.35 +  config.EvtDriverUnload = XenPci_EvtDriverUnload;
    1.36    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, &driver);
    1.37  
    1.38    WdfCollectionCreate(WDF_NO_OBJECT_ATTRIBUTES, &qemu_hide_devices);
     2.1 --- a/xenpci/xenpci_dbgprint.c	Sat May 22 20:39:27 2010 +1000
     2.2 +++ b/xenpci/xenpci_dbgprint.c	Thu Jun 24 12:51:23 2010 +1000
     2.3 @@ -159,6 +159,24 @@ XenPci_HookDbgPrint_High(PVOID context)
     2.4    idt_entry->addr_32_63 = (ULONG)((ULONG_PTR)Int2dHandlerNew >> 32);
     2.5    #endif
     2.6  }
     2.7 +
     2.8 +static VOID
     2.9 +XenPci_UnHookDbgPrint_High(PVOID context)
    2.10 +{
    2.11 +  IDT idt;
    2.12 +  PIDT_ENTRY idt_entry;
    2.13 +
    2.14 +  UNREFERENCED_PARAMETER(context);  
    2.15 + 
    2.16 +  idt.limit = 0;
    2.17 +  __sidt(&idt);
    2.18 +  idt_entry = &idt.entries[0x2D];
    2.19 +  idt_entry->addr_0_15 = (USHORT)(ULONG_PTR)Int2dHandlerOld;
    2.20 +  idt_entry->addr_16_31 = (USHORT)((ULONG_PTR)Int2dHandlerOld >> 16);
    2.21 +  #ifdef _AMD64_ 
    2.22 +  idt_entry->addr_32_63 = (ULONG)((ULONG_PTR)Int2dHandlerOld >> 32);
    2.23 +  #endif
    2.24 +}
    2.25  #endif
    2.26  #endif
    2.27  
    2.28 @@ -202,3 +220,44 @@ XenPci_HookDbgPrint()
    2.29  
    2.30    return status;
    2.31  }
    2.32 +
    2.33 +NTSTATUS
    2.34 +XenPci_UnHookDbgPrint()
    2.35 +{
    2.36 +  NTSTATUS status = STATUS_SUCCESS;
    2.37 +
    2.38 +  if (READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0x49d2
    2.39 +    || READ_PORT_USHORT(XEN_IOPORT_MAGIC) == 0xd249)
    2.40 +  {
    2.41 +    //#pragma warning(suppress:4055)
    2.42 +    //DbgSetDebugPrintCallback = (PDBG_SET_DEBUGPRINT_CALLBACK)MmGetSystemRoutineAddress((PUNICODE_STRING)&DbgSetDebugPrintCallbackName);
    2.43 +#if (NTDDI_VERSION >= NTDDI_VISTA)
    2.44 +    KdPrint((__DRIVER_NAME "     DbgSetDebugPrintCallback found\n"));
    2.45 +    status = DbgSetDebugPrintCallback(XenPci_DbgPrintCallback, FALSE);
    2.46 +    if (!NT_SUCCESS(status))
    2.47 +    {
    2.48 +      KdPrint((__DRIVER_NAME "     DbgSetDebugPrintCallback failed - %08x\n", status));
    2.49 +    }
    2.50 +    //DbgSetDebugFilterState(componentid, level, state);
    2.51 +    //DbgSetDebugFilterState(DPFLTR_DEFAULT_ID, 0xFFFFFFFF, TRUE);
    2.52 +#else
    2.53 +    KdPrint((__DRIVER_NAME "     DbgSetDebugPrintCallback not found\n"));      
    2.54 +#ifndef _AMD64_ // can't patch IDT on AMD64 unfortunately - results in bug check 0x109
    2.55 +    XenPci_HighSync(XenPci_UnHookDbgPrint_High, XenPci_UnHookDbgPrint_High, NULL);
    2.56 +#endif
    2.57 +#endif
    2.58 +  }
    2.59 +  else
    2.60 +  {
    2.61 +    status = STATUS_UNSUCCESSFUL;
    2.62 +  }
    2.63 +  
    2.64 +  if (!KeDeregisterBugCheckCallback(&callback_record))
    2.65 +  {
    2.66 +    KdPrint((__DRIVER_NAME "     KeDeregisterBugCheckCallback failed\n"));
    2.67 +    status = STATUS_UNSUCCESSFUL;
    2.68 +  }
    2.69 +
    2.70 +  return status;
    2.71 +}
    2.72 +