Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At the time <code>DriverUnload</code> is called there're no more created devices. Hence - it's obsolete to try to use <code>DeviceObject</code> and <code>NextDevice</code> members of the <code>DRIVER_OBJECT</code> structure.</p> <p>What's surprising is that <code>NextDevice</code> isn't set to <code>NULL</code>, according to your debug output, but nevertheless it's just a technical note.</p> <p>If you want to do a per-device cleanup you should rather do it in your dispatch routine in response to <code>IRP_MJ_CLOSE</code>.</p> <p><strong>UPD</strong></p> <p>The question author posted in the comments that iterating through the created devices in the driver unload routine is a common practice, and provided the reference article at the codeproject, with the appropriate source code.</p> <p>After reading the article and the source code it became more clear.</p> <p>Usually the driver "creates a device" (i.e. calls <code>IoCreateDevice</code>) in response to the OS request, which originates from a call to <code>CreateFile</code> (or similar). When the device handle is closed - driver receives the appropriate request and "destroys" the device (<code>IoDeleteDevice</code>). The OS will not unload the driver if there're open handles to its devices, hence within the driver uninitialization routine there are no created devices.</p> <p>However the driver in the reference article doesn't follow this logic. It creates the device at the beginning, right in its initialization routine <code>DriverEntry</code>. This does not prevent the OS from unloading the driver, because there're no open references to this device, hence the driver really needs to do the device cleanup in its <code>DriverUnload</code>.</p> <p>Alright, this makes sense now. Except, from my personal experience, it's <strong>not</strong> a common practice to work this way, but this is not forbidden nevertheless.</p> <p>Now, regarding your problem. Maybe you just made a mistake in the loop? I mean:</p> <pre><code>while (pNextObj != NULL) { PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION) pNextObj-&gt;DeviceExtension; // ... pNextObj = pNextObj-&gt;NextDevice; // then delete the device using the Extension IoDeleteDevice( pDevExt-&gt;pDevice ); } </code></pre> <p>Are you sure you do the things in the same order? Means, you first get the pointer to the next device object, and then call <code>IoDeleteDevice</code>?</p> <p>Please post the whole code of your <code>DriverUnload</code> if you still have the problem.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload