Blue screen of death mistery

Hello,

I’m completely new in KMDF… and… I’m trying to get the name of the manufacturer over the USB.

Unfortunatelly, the following code causes the blue screen of death on my Vista…

The line that crashes the system is this one (numCharacters is 30):

KdPrint ( (“All ok, bailing out! %c%c%c%c\n”, memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4] ));

What am I doing wrong? How to get the contents of the memoryHandle?

The return value of the WdfUsbTargetDeviceAllocAndQueryString is OK.

NTSTATUS getUSBDeviceDescriptorString( IN WDFDEVICE Device )
{
NTSTATUS status;
PDEVICE_CONTEXT pDeviceContext;

USHORT numCharacters;
PUSHORT stringBuf;
WDFMEMORY memoryHandle;
WDF_MEMORY_DESCRIPTOR memoryDescriptor;

//
// initialize variables
//

pDeviceContext = GetDeviceContext(Device);

status = WdfUsbTargetDeviceAllocAndQueryString(
pDeviceContext->WdfUsbTargetDevice,
WDF_NO_OBJECT_ATTRIBUTES,
&memoryHandle,
&numCharacters,
pDeviceContext->UsbDeviceDescriptor.iManufacturer,
0x0409
);

KdPrint ( (“All ok, bailing out! %c%c%c%c\n”, memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4] ));
return -1;
}

Thanks.

Best regards,
Damir Colak

As the variable name “memoryHandle” implies, the WDFMEMORY that you get back
is a handle, not a buffer pointer. You need to call WdfMemoryGetBuffer to
get a kernel virtual address.

Also:

  1. “%c%c%c%c” is four parameters, you’re passing five.

  2. You need to check the return of WdfUsbTargetDeviceAllocAndQueryString
    with NT_SUCCESS

And, while it wasn’t necessary here, in the future provide the full
!analyze -v output.

-scott


Scott Noone
Software Engineer
OSR Open Systems Resources, Inc.
http://www.osronline.com

“Damir Colak” wrote in message news:xxxxx@windbg…
Hello,

I’m completely new in KMDF… and… I’m trying to get the name of the
manufacturer over the USB.

Unfortunatelly, the following code causes the blue screen of death on my
Vista…

The line that crashes the system is this one (numCharacters is 30):

KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
));

What am I doing wrong? How to get the contents of the memoryHandle?

The return value of the WdfUsbTargetDeviceAllocAndQueryString is OK.

NTSTATUS getUSBDeviceDescriptorString( IN WDFDEVICE Device )
{
NTSTATUS status;
PDEVICE_CONTEXT pDeviceContext;

USHORT numCharacters;
PUSHORT stringBuf;
WDFMEMORY memoryHandle;
WDF_MEMORY_DESCRIPTOR memoryDescriptor;

//
// initialize variables
//

pDeviceContext = GetDeviceContext(Device);

status = WdfUsbTargetDeviceAllocAndQueryString(
pDeviceContext->WdfUsbTargetDevice,
WDF_NO_OBJECT_ATTRIBUTES,
&memoryHandle,
&numCharacters,
pDeviceContext->UsbDeviceDescriptor.iManufacturer,
0x0409
);

KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
));
return -1;
}

Thanks.

Best regards,
Damir Colak

Well the obvious ones are:

  1. The code you gave does not check the status to see if the call
    suceeded
  2. The code you gave does not check the numCharacters to see if there
    are 5 present
  3. The code does not use WdgMemoryGetBuffer to convert the handle to a
    pointer

These are better answered at NTDEV


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“Damir Colak” wrote in message news:xxxxx@windbg…
Hello,

I’m completely new in KMDF… and… I’m trying to get the name of the
manufacturer over the USB.

Unfortunatelly, the following code causes the blue screen of death on my
Vista…

The line that crashes the system is this one (numCharacters is 30):

KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
));

What am I doing wrong? How to get the contents of the memoryHandle?

The return value of the WdfUsbTargetDeviceAllocAndQueryString is OK.

NTSTATUS getUSBDeviceDescriptorString( IN WDFDEVICE Device )
{
NTSTATUS status;
PDEVICE_CONTEXT pDeviceContext;

USHORT numCharacters;
PUSHORT stringBuf;
WDFMEMORY memoryHandle;
WDF_MEMORY_DESCRIPTOR memoryDescriptor;

//
// initialize variables
//

pDeviceContext = GetDeviceContext(Device);

status = WdfUsbTargetDeviceAllocAndQueryString(
pDeviceContext->WdfUsbTargetDevice,
WDF_NO_OBJECT_ATTRIBUTES,
&memoryHandle,
&numCharacters,
pDeviceContext->UsbDeviceDescriptor.iManufacturer,
0x0409
);

KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
));
return -1;
}

Thanks.

Best regards,
Damir Colak

Scott, Don,

Thank you both.

The status was NT_SUCCESS, numCharacters was 30…

But, you both opened my eyes with WdfMemoryGetBuffer! :slight_smile:

To Scott, I’m still trying to learn all the cryptic !commands of WinDbg…

Is there anything resembling Visual Studio IDE for KMDF?

The lack of autocomplete in the code editor is a horrible thing to live with…

NTDEV is a mailing list? Sorry for asking so many lame questions.

Thanks again.

Regards,
Damir Colak

“Don Burn” wrote in message news:…
> Well the obvious ones are:
>
> 1. The code you gave does not check the status to see if the call
> suceeded
> 2. The code you gave does not check the numCharacters to see if there
> are 5 present
> 3. The code does not use WdgMemoryGetBuffer to convert the handle to
> a pointer
>
> These are better answered at NTDEV
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
> “Damir Colak” wrote in message news:xxxxx@windbg…
> Hello,
>
> I’m completely new in KMDF… and… I’m trying to get the name of the
> manufacturer over the USB.
>
> Unfortunatelly, the following code causes the blue screen of death on my
> Vista…
>
> The line that crashes the system is this one (numCharacters is 30):
>
> KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
> memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
> ));
>
> What am I doing wrong? How to get the contents of the memoryHandle?
>
> The return value of the WdfUsbTargetDeviceAllocAndQueryString is OK.
>
> NTSTATUS getUSBDeviceDescriptorString( IN WDFDEVICE Device )
> {
> NTSTATUS status;
> PDEVICE_CONTEXT pDeviceContext;
>
> USHORT numCharacters;
> PUSHORT stringBuf;
> WDFMEMORY memoryHandle;
> WDF_MEMORY_DESCRIPTOR memoryDescriptor;
>
> //
> // initialize variables
> //
>
> pDeviceContext = GetDeviceContext(Device);
>
>
>
> status = WdfUsbTargetDeviceAllocAndQueryString(
> pDeviceContext->WdfUsbTargetDevice,
> WDF_NO_OBJECT_ATTRIBUTES,
> &memoryHandle,
> &numCharacters,
>
> pDeviceContext->UsbDeviceDescriptor.iManufacturer,
> 0x0409
> );
>
> KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
> memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
> ));
> return -1;
> }
>
> Thanks.
>
> Best regards,
> Damir Colak
>
>
> —
> You are currently subscribed to windbg as: xxxxx@colaksoft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

NTDEV is another mailing list hosted by OSR. OSR and
http://www.hollistech.com/ both have versions of a tool called DDKBUILD
which allow some integration with Visual Studio. I prefer the hollistech
one but that is mainly because I have used it for years, and the doc’s are
good.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply

“Damir Colak” wrote in message news:xxxxx@windbg…

Scott, Don,

Thank you both.

The status was NT_SUCCESS, numCharacters was 30…

But, you both opened my eyes with WdfMemoryGetBuffer! :slight_smile:

To Scott, I’m still trying to learn all the cryptic !commands of WinDbg…

Is there anything resembling Visual Studio IDE for KMDF?

The lack of autocomplete in the code editor is a horrible thing to live
with…

NTDEV is a mailing list? Sorry for asking so many lame questions.

Thanks again.

Regards,
Damir Colak

“Don Burn” wrote in message news:…
> Well the obvious ones are:
>
> 1. The code you gave does not check the status to see if the call
> suceeded
> 2. The code you gave does not check the numCharacters to see if there
> are 5 present
> 3. The code does not use WdgMemoryGetBuffer to convert the handle to
> a pointer
>
> These are better answered at NTDEV
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Website: http://www.windrvr.com
> Blog: http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
>
>
> “Damir Colak” wrote in message news:xxxxx@windbg…
> Hello,
>
> I’m completely new in KMDF… and… I’m trying to get the name of the
> manufacturer over the USB.
>
> Unfortunatelly, the following code causes the blue screen of death on my
> Vista…
>
> The line that crashes the system is this one (numCharacters is 30):
>
> KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
> memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
> ));
>
> What am I doing wrong? How to get the contents of the memoryHandle?
>
> The return value of the WdfUsbTargetDeviceAllocAndQueryString is OK.
>
> NTSTATUS getUSBDeviceDescriptorString( IN WDFDEVICE Device )
> {
> NTSTATUS status;
> PDEVICE_CONTEXT pDeviceContext;
>
> USHORT numCharacters;
> PUSHORT stringBuf;
> WDFMEMORY memoryHandle;
> WDF_MEMORY_DESCRIPTOR memoryDescriptor;
>
> //
> // initialize variables
> //
>
> pDeviceContext = GetDeviceContext(Device);
>
>
>
> status = WdfUsbTargetDeviceAllocAndQueryString(
> pDeviceContext->WdfUsbTargetDevice,
> WDF_NO_OBJECT_ATTRIBUTES,
> &memoryHandle,
> &numCharacters,
>
> pDeviceContext->UsbDeviceDescriptor.iManufacturer,
> 0x0409
> );
>
> KdPrint ( (“All ok, bailing out! %c%c%c%c\n”,
> memoryHandle[0],memoryHandle[1],memoryHandle[2],memoryHandle[3],memoryHandle[4]
> ));
> return -1;
> }
>
> Thanks.
>
> Best regards,
> Damir Colak
>
>
> —
> You are currently subscribed to windbg as: xxxxx@colaksoft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>