Hi All
Scenario:
i)PnP NIC PcCard USB driver with an IO manager interface created with
NdisMRegisterDevice().
ii)Application opens device with CreateFile() and gets a valid handle.
iii) Stop NIC driver with Safely Remove Hardware. (Driver Halt
function gets called and devext is freed)
iv) Application calls DeviceIoControl() on the STILL VALID HANDLE.
v) NIC driver image stil in memory, so IOCTL handler called which
refgerences the now invalid devext.
vi) CRASH.
Now, to quote the DDK: "Note that, if a handle to the device object
created with NdisMRegisterDevice is open, the driver that created the
device object cannot be unloaded."
Oh yeah, even NdisMDeregisterDevice() returns 0 if an application
still has the handle open.
And further: "Before opening a handle to the device object, a user-mode
application should therefore register for device event notification,
specifying GUID_NDIS_LAN_CLASS as the interface class GUID. On
receiving a DBT_DEVICEQUERYREMOVE device event for the device object,
the application should close the handle"
So it is up to the good behaviour of an application to controlll wether
the kernel crashes or not. Hmmm not a very good idea.
I suggest the IO manager returns INVALID_HANDLE_VALUE if the device got
unloaded and an app calls an IO manager function on it.