NDIS_STATUS NICDeregisterDevice(VOID) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; PAGED_CODE(); if (g_NdisDeviceHandle != NULL) { Status = NdisMDeregisterDevice(g_NdisDeviceHandle); g_NdisDeviceHandle = NULL; } return Status; }
void __fastcall ssh_interceptor_iodevice_close_device(SshInterceptorIoDevice io_dev) { SSH_ASSERT(io_dev != NULL); NdisAcquireSpinLock(&io_dev->output_queue_lock); if (InterlockedCompareExchange(&io_dev->opened_instances, 0, 0) != 0) { SSH_DEBUG(SSH_D_HIGHSTART, ("I/O device is still open; marking it for delayed destroy")); io_dev->destroy_after_close = TRUE; NdisReleaseSpinLock(&io_dev->output_queue_lock); return; } NdisReleaseSpinLock(&io_dev->output_queue_lock); if (InterlockedCompareExchange(&io_dev->io_device_created, 0, 1) == 0) { SSH_DEBUG(SSH_D_HIGHSTART, ("I/O device already closed; ignoring this call")); return; } SSH_DEBUG(SSH_D_HIGHSTART, ("Closing I/O device and symbolic link...")); SSH_ASSERT(ssh_interceptor_iodevice_is_open(io_dev) == FALSE); /* Restore the original security descriptor back and free the modified one */ if (io_dev->orig_sd) { #pragma warning(disable : 28175) ssh_free(io_dev->device->SecurityDescriptor); io_dev->device->SecurityDescriptor = io_dev->orig_sd; #pragma warning(default : 28175) } #ifdef SSH_IM_INTERCEPTOR NdisMDeregisterDevice(io_dev->handle); #else /* not SSH_IM_INTERCEPTOR */ if (!NT_SUCCESS(IoDeleteSymbolicLink(&io_dev->symlink_name))) { SSH_DEBUG(SSH_D_FAIL, ("ssh_interceptor_iodevice_uninitialize(): " "IoDeleteSymbolicLink() failed !")); } IoDeleteDevice(io_dev->device); #endif /* not SSH_IM_INTERCEPTOR */ }
NDIS_STATUS ProtocolDeregisterDevice( VOID ) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; NdisAcquireSpinLock(&GlobalLock); ASSERT(MiniportCount > 0); --MiniportCount; if (0 == MiniportCount) { // // All miniport instances have been halted. Deregister // the control device. // ASSERT(ControlDeviceState == PS_DEVICE_STATE_READY); // // Block PtRegisterDevice() while we release the control // device lock and deregister the device. // ControlDeviceState = PS_DEVICE_STATE_DELETING; NdisReleaseSpinLock(&GlobalLock); if (NdisDeviceHandle != NULL) { Status = NdisMDeregisterDevice(NdisDeviceHandle); NdisDeviceHandle = NULL; } NdisAcquireSpinLock(&GlobalLock); ControlDeviceState = PS_DEVICE_STATE_READY; } NdisReleaseSpinLock(&GlobalLock); return Status; }
// Release the control device void NeoFreeControlDevice() { if (ctx == NULL) { return; } if (ctx->Opened != FALSE) { // Delete the event NeoSet(ctx->Event); NeoFreeEvent(ctx->Event); ctx->Event = NULL; ctx->Opened = FALSE; } // Delet the device NdisMDeregisterDevice(ctx->NdisControl); }
NDIS_STATUS PtDeregisterDevice( VOID ) /*++ Routine Description: Deregister the ioctl interface. This is called whenever a miniport instance is halted. When the last miniport instance is halted, we request NDIS to delete the device object Arguments: NdisDeviceHandle - Handle returned by NdisMRegisterDevice Return Value: NDIS_STATUS_SUCCESS if everything worked ok --*/ { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; DBGPRINT(("==>PassthruDeregisterDevice\n")); NdisAcquireSpinLock(&GlobalLock); ASSERT(MiniportCount > 0); --MiniportCount; if (0 == MiniportCount) { // // All miniport instances have been halted. Deregister // the control device. // ASSERT(ControlDeviceState == PS_DEVICE_STATE_READY); // // Block PtRegisterDevice() while we release the control // device lock and deregister the device. // ControlDeviceState = PS_DEVICE_STATE_DELETING; NdisReleaseSpinLock(&GlobalLock); if (NdisDeviceHandle != NULL) { Status = NdisMDeregisterDevice(NdisDeviceHandle); NdisDeviceHandle = NULL; } NdisAcquireSpinLock(&GlobalLock); ControlDeviceState = PS_DEVICE_STATE_READY; } NdisReleaseSpinLock(&GlobalLock); DBGPRINT(("<== PassthruDeregisterDevice: %x\n", Status)); return Status; }