Serial Port Issue

I’m trying to use IoGetDeviceObjectPointer to get the port number for a serial port. However there are times when it either returns ACCESS_DENIED every other time or just randomly and that !object [port address] doesn’t show any used handles for some odd reason. I’m not sure if this is relating to type of serial port that I’m using because I’ve recently noticed with the case of the port returning ACCESS_DENIED every other time occuring with a USB to Serial Com port.

Are you Ob derefencing the file object when you are done?

Bent from my phone


From: 30441503600n behalf of
Sent: Tuesday, August 14, 2018 7:21 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Serial Port Issue

I’m trying to use IoGetDeviceObjectPointer to get the port number for a serial port. However there are times when it either returns ACCESS_DENIED every other time or just randomly and that !object [port address] doesn’t show any used handles for some odd reason. I’m not sure if this is relating to type of serial port that I’m using because I’ve recently noticed with the case of the port returning ACCESS_DENIED every other time occuring with a USB to Serial Com port.


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Hi Doron,

Yes we are. Here is the code written below

static NTSTATUS
p_mkSerialDevLink
(
const UNICODE_STRING* symLinkName,
ACCESS_MASK access,
cyiSerialPortLink* data
)
{
NTSTATUS status;

assert(KeGetCurrentIrql()==PASSIVE_LEVEL); /* When calling printf with wide characters.*/
status = IoGetDeviceObjectPointer /* Get a pointer to the device. */
(
(UNICODE_STRING*)symLinkName, /* Surely this does not modify the source. */
access,
&data->fileObject,
&data->devObj
);
if(NT_SUCCESS(status) ) /* If success…*/
{
assert(status!=STATUS_PENDING);
status = p_getTargetDevicePdo /* …get the PDO.*/
(
data->devObj,
data->fileObject,
&data->pdo
);
if(NT_SUCCESS(status) ) /* If success…*/
return STATUS_SUCCESS; /* …we are done. */
ObDereferenceObject(data->fileObject); /* Something went wrong. Clean up. This will invalidate the devObj as well. */
data->fileObject=NULL; /* Mark ourselves as invalid. */
data->devObj=NULL;
}

return status;
}

static void
p_unMkSerialDevLink
(
cyiSerialPortLink* data
)
{
assert(data);
if(data->devObj)
{
cyiDebugString(“@@@@ p_unMkSerialDevLink YES”);
ObDereferenceObject(data->fileObject); /* This will invalidate the devObj as well. */
ObDereferenceObject(data->pdo);
data->devObj=NULL; /* Now we are invalid.*/
}
else
cyiDebugString(“@@@@ p_unMkSerialDevLink NO”); v

}