This bug is really anoying me. I’m sure this will turn out to be something really silly. So, now, I created a simple IOCTL that simply fails all requests with STATUS_NO_MEMORY but my user-mode app still receives 0x00 for GetLastError().
Any Ideas? Here’s the actual code I’m using…
Here’s my driver code:
NTSTATUS MyCrappyDriverDeviceControl(PDEVICE_OBJECT DeviceObject,PIRP Irp)
{
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
PIO_STACK_LOCATION currentIrpStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS status;
IO_STATUS_BLOCK ioStatus;
DebugPrint((2, “MyCrappyDriverDeviceControl: DeviceObject %X Irp %X\n”, DeviceObject, Irp));
switch (currentIrpStack->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_MYCRAPPYIOCTL:
{
status = STATUS_NO_MEMORY;
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
… handle other stuff here (removed for readability) …
}
And here’s my user-mode code:
if (!DeviceIoControl(hHandle, IOCTL_MYCRAPPYIOCTL, ReadTarget, sizeof(READ_TARGET), ReadTarget, ReadTarget->BufferSize, &bytes, NULL))
{
LastError = GetLastError();
printf(“\nIOCTL_MYCRAPPYIOCTL device request failed: 0x%x\n”, LastError);
}
So, how can GetLastError() possibly return 0x00 and not not STATUS_NO_MEMORY??? User a debugger showed that my driver was called correctly and returned STATUS_NO_MEMORY.
“Doron Holan” wrote in message news:xxxxx@ntdev…
I hope you are calling IoCompleteRequest after setting the status in the
Irp. If not, that is probably your problem.
d
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Fred
Sent: Tuesday, April 12, 2005 1:59 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Error return translation from driver to win32
I’m sending an ioctl to my driver via IoDeviceControl(). If I fail the
ioctl with STATUS_NON_MEMORY then I expect that this will result in
IoDeviceControl() returning 0 as well as GetLastError() returning ‘no
memory’ error. But GetLastError() actually returns 0.
I’m setting :
Irp->IoStatus.Information = 0;
Irp->IoStatus.Status = STATUS_NO_MEMORY;
return STATUS_NO_MEMORY;
in my driver.
Shouldn’t the Win32 GetLastError() call get the error returned in
Irp->IoStatus.Status?
Thanks.
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com