Why do you think that you need to do this?
If you have a PDEVICE_OBJECT pointer that you’re using, then you need to *know* it’s valid. There’s no “if”. Think about it for a moment; it’s a race condition, even if there were a way to instantaneously make such a decision (which there isn’t).
You should explain more about what you’re trying to actually accomplish and why, as it sounds like you’re a bit confused on what you should be doing right now to have started down this path (which, whatever its goal is, it’s the wrong one if you need to ask these sorts of questions).
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Saturday, November 08, 2008 9:30 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How check PDEVICE_OBJECT is valid
Hello,
I have to check if a kernel driver DEVICE_OBJECT is valid (valid anymore).
Is there a kernel function for this type of check?
I have only the folloing solutions…
PDEVICE_OBJECT pDevice = “Kernel Driver Device”
if (pDevice == NULL) {return FALSE;}
if (MmIsAddressValid(pDevice) == FALSE) {return FALSE;}
Maybe another funny solution…
ULONG i = 0;
ULONG size = sizeof(PDEVICE_OBJECT) / sizeof(ULONG);
ULONG64 address = (ULONG64)HardDriveDevice;
for (i = 0; i < size; i++)
{
address = address + sizeof(ULONG);
if (MmIsAddressValid((PDEVICE_OBJECT)address) == FALSE)
{
return STATUS_INVALID_HANDLE;
}
}
Is there another better way to check if the DEVICE_OBJECT is valid?
Thanks.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer