Beispiel #1
0
VOID
DriverUnload(
    IN  PDRIVER_OBJECT  DriverObject
    )
{
    HANDLE              UnplugKey;
    HANDLE              ParametersKey;

    ASSERT3P(DriverObject, ==, __DriverGetDriverObject());

    Trace("====>\n");

    if (*InitSafeBootMode > 0)
        goto done;

    UnplugKey = __DriverGetUnplugKey();
    RegistryCloseKey(UnplugKey);
    __DriverSetUnplugKey(NULL);

    ParametersKey = __DriverGetParametersKey();
    if (ParametersKey != NULL) {
        RegistryCloseKey(ParametersKey);
        __DriverSetParametersKey(NULL);
    }

    RegistryTeardown();

done:
    __DriverSetDriverObject(NULL);

    ASSERT(IsZeroMemory(&Driver, sizeof (XENFILT_DRIVER)));

    Trace("<====\n");
}
Beispiel #2
0
VOID
DriverUnload(
    IN  PDRIVER_OBJECT  DriverObject
    )
{
    HANDLE              ServiceKey;
    HANDLE              AliasesKey;
    HANDLE              AddressesKey;
    HANDLE              ParametersKey;

    ASSERT3P(DriverObject, ==, __DriverGetDriverObject());

    Trace("====>\n");

    if (*InitSafeBootMode > 0)
        goto done;

    AliasesKey = __DriverGetAliasesKey();
    __DriverSetAliasesKey(NULL);

    RegistryCloseKey(AliasesKey);

    AddressesKey = __DriverGetParametersKey();
    __DriverSetAddressesKey(NULL);

    RegistryCloseKey(AddressesKey);

    ParametersKey = __DriverGetParametersKey();
    if (ParametersKey != NULL) {
        __DriverSetParametersKey(NULL);

        RegistryCloseKey(ParametersKey);
    }

    ServiceKey = __DriverGetServiceKey();
    __DriverSetServiceKey(NULL);

    RegistryCloseKey(ServiceKey);

    RegistryTeardown();

done:
    __DriverSetDriverObject(NULL);

    ASSERT(IsZeroMemory(&Driver, sizeof (XENVIF_DRIVER)));

    Trace("<====\n");
}
Beispiel #3
0
VOID
DriverUnload(
    IN  PDRIVER_OBJECT  DriverObject
    )
{
    HANDLE              ParametersKey;

    ASSERT3P(DriverObject, ==, __DriverGetDriverObject());

    Trace("====>\n");

    if (*InitSafeBootMode > 0)
        goto done;

    ParametersKey = __DriverGetParametersKey();
    if (ParametersKey != NULL) {
        RegistryCloseKey(ParametersKey);
        __DriverSetParametersKey(NULL);
    }

    ProcessTeardown();

    ModuleTeardown();

    HypercallTeardown(&Driver.HypercallInterface);

    LogTeardown();

    RegistryTeardown();

done:
    __DriverSetDriverObject(NULL);

    ASSERT(IsZeroMemory(&Driver, sizeof (XEN_DRIVER)));

    Trace("<====\n");
}
Beispiel #4
0
NTSTATUS
DriverEntry(
    IN  PDRIVER_OBJECT  DriverObject,
    IN  PUNICODE_STRING RegistryPath
    )
{
    HANDLE              ServiceKey;
    HANDLE              ParametersKey;
    HANDLE              UnplugKey;
    ULONG               Index;
    NTSTATUS            status;

    ASSERT3P(__DriverGetDriverObject(), ==, NULL);

    ExInitializeDriverRuntime(DrvRtPoolNxOptIn);

    __DbgPrintEnable();

    Trace("====>\n");

    __DriverSetDriverObject(DriverObject);

    DriverObject->DriverUnload = DriverUnload;

    if (*InitSafeBootMode > 0)
        goto done;

    XenTouch();

    Info("XENFILT %d.%d.%d (%d) (%02d.%02d.%04d)\n",
         MAJOR_VERSION,
         MINOR_VERSION,
         MICRO_VERSION,
         BUILD_NUMBER,
         DAY,
         MONTH,
         YEAR);

    status = RegistryInitialize(RegistryPath);
    if (!NT_SUCCESS(status))
        goto fail1;

    status = RegistryOpenServiceKey(KEY_READ, &ServiceKey);
    if (!NT_SUCCESS(status))
        goto fail2;

    status = RegistryOpenSubKey(ServiceKey, "Parameters", KEY_READ, &ParametersKey);
    if (NT_SUCCESS(status))
        __DriverSetParametersKey(ParametersKey);

    status = RegistryOpenSubKey(ServiceKey, "Unplug", KEY_READ, &UnplugKey);
    if (!NT_SUCCESS(status))
        goto fail3;

    __DriverSetUnplugKey(UnplugKey);

    RegistryCloseKey(ServiceKey);

    DriverObject->DriverExtension->AddDevice = AddDevice;

    for (Index = 0; Index <= IRP_MJ_MAXIMUM_FUNCTION; Index++) {
#pragma prefast(suppress:28169) // No __drv_dispatchType annotation
#pragma prefast(suppress:28168) // No matching __drv_dispatchType annotation for IRP_MJ_CREATE
        DriverObject->MajorFunction[Index] = Dispatch;
    }

done:
    Trace("<====\n");
    return STATUS_SUCCESS;

fail3:
    Error("fail3\n");

    if (ParametersKey != NULL) {
        RegistryCloseKey(ParametersKey);
        __DriverSetParametersKey(NULL);
    }

fail2:
    Error("fail2\n");

    RegistryTeardown();

fail1:
    Error("fail1 (%08x)\n", status);

    __DriverSetDriverObject(NULL);

    ASSERT(IsZeroMemory(&Driver, sizeof (XENFILT_DRIVER)));

    return status;
}
Beispiel #5
0
NTSTATUS
DriverEntry(
    IN  PDRIVER_OBJECT      DriverObject,
    IN  PUNICODE_STRING     RegistryPath
    )
{
    HANDLE                  ServiceKey;
    HANDLE                  ParametersKey;
    ULONG                   Index;
    NTSTATUS                status;

    ASSERT3P(__DriverGetDriverObject(), ==, NULL);

    ExInitializeDriverRuntime(DrvRtPoolNxOptIn);

    __EnableDbgPrint();

    Trace("====>\n");

    __DriverSetDriverObject(DriverObject);

    if (*InitSafeBootMode > 0)
        goto done;

    status = LogInitialize();
    if (!NT_SUCCESS(status))
        goto fail1;

    Info("%s (%s)\n",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
         DAY_STR "/" MONTH_STR "/" YEAR_STR);

    SystemGetInformation();

    status = HypercallInitialize(&Driver.HypercallInterface);
    if (!NT_SUCCESS(status))
        goto fail2;

    status = ModuleInitialize();
    if (!NT_SUCCESS(status))
        goto fail3;

    status = ProcessInitialize();
    if (!NT_SUCCESS(status))
        goto fail4;

    status = RegistryInitialize(RegistryPath);
    if (!NT_SUCCESS(status))
        goto fail5;

    status = RegistryOpenServiceKey(KEY_READ, &ServiceKey);
    if (!NT_SUCCESS(status))
        goto fail6;

    status = RegistryOpenSubKey(ServiceKey, "Parameters", KEY_READ, &ParametersKey);
    if (NT_SUCCESS(status))
        __DriverSetParametersKey(ParametersKey);

    RegistryCloseKey(ServiceKey);

    Driver.DriverObject->DriverUnload = DriverUnload;
    Driver.DriverObject->DriverExtension->AddDevice = AddDevice;

    for (Index = 0; Index <= IRP_MJ_MAXIMUM_FUNCTION; Index++) {
#pragma prefast(suppress:28169) // No __drv_dispatchType annotation
#pragma prefast(suppress:28168) // No matching __drv_dispatchType annotation for IRP_MJ_CREATE
       Driver.DriverObject->MajorFunction[Index] = Dispatch;
    }

done:
    Trace("<====\n");

    return STATUS_SUCCESS;

fail6:
    Error("fail6\n");

    RegistryTeardown();

fail5:
    Error("fail5\n");

    ProcessTeardown();

fail4:
    Error("fail4\n");

    ModuleTeardown();

fail3:
    Error("fail3\n");

    HypercallTeardown(&Driver.HypercallInterface);

fail2:
    Error("fail2\n");

    LogTeardown();

fail1:
    Error("fail1 (%08x)\n", status);

    __DriverSetDriverObject(NULL);

    ASSERT(IsZeroMemory(&Driver, sizeof (XEN_DRIVER)));

    return status;
}