_Must_inspect_result_
NTSTATUS
FxLibraryCommonUnregisterClient(
    __in PWDF_BIND_INFO        Info,
    __in PWDF_DRIVER_GLOBALS   WdfDriverGlobals
    )
{
    NTSTATUS status;

    __Print((LITERAL(WDF_LIBRARY_UNREGISTER_CLIENT) ": enter\n"));

    ASSERT(Info);
    ASSERT(WdfDriverGlobals);

    if (Info != NULL && WdfDriverGlobals != NULL) {
        PFX_DRIVER_GLOBALS pFxDriverGlobals;

        status = STATUS_SUCCESS;

        pFxDriverGlobals = GetFxDriverGlobals(WdfDriverGlobals);

        //
        // Destroy this FxDriver instance, if its still indicated.
        //
        if (pFxDriverGlobals->Driver != NULL) {
            //
            // Association support, we are a root with no parent
            //
            pFxDriverGlobals->Driver->DeleteObject();

            FxDestroy(pFxDriverGlobals);
        }

        //
        // Stop IFR logging
        //
        FxIFRStop(pFxDriverGlobals);

        //
        // unlock enhanced-verifier image sections
        //
        if (IsFxVerifierFunctionTableHooking(pFxDriverGlobals)) {
            UnlockVerifierSection(pFxDriverGlobals);
        }

        //
        // This will free the client's FxDriverGlobals area
        //
        FxFreeDriverGlobals(WdfDriverGlobals);
    }
    else {
        status = STATUS_UNSUCCESSFUL;
    }

    __Print((LITERAL(WDF_LIBRARY_UNREGISTER_CLIENT)
             ": exit: status %X\n", status));

    return status;
}
VOID
FxDriver::Unload(
    __in MdDriverObject DriverObject
    )
{
    PFX_DRIVER_GLOBALS pFxDriverGlobals;
    FxDriver *pDriver;

    pDriver = FxDriver::GetFxDriver(DriverObject);
    if (pDriver == NULL) {
        return;
    }
    
    pFxDriverGlobals = pDriver->GetDriverGlobals();

    DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGDRIVER,
                        "Unloading WDFDRIVER %p, PDRIVER_OBJECT_UM %p",
                        pDriver->GetHandle(), DriverObject);
    //
    // Invoke the driver if they specified an unload routine.
    //
    if (pDriver->m_DriverUnload.Method) {
        pDriver->m_DriverUnload.Invoke(pDriver->GetHandle());
        DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGDRIVER,
                            "Driver unload routine Exit WDFDRIVER %p, PDRIVER_OBJECT_UM %p",
                            pDriver->GetHandle(), DriverObject);
    }

    //
    // Delete the FxDriver object.
    //
    // This releases the FxDriver reference.  Must be called at PASSIVE
    //
    pDriver->DeleteObject();

    pFxDriverGlobals->Driver = NULL;

    FxDestroy(pFxDriverGlobals);
}