Error return translation from driver to win32

Yes your problem is annoying :slight_smile:

So just to be absolutely clear about this: DeviceIoControl returns false and
GetLastError returns zero, right? That actually makes very little sense.

Also what is the point in your crappy driver routine
MyCrappyDriverDeviceControl of the “IO_STATUS_BLOCK ioStatus” variable? Is
there any possiblity that your pseudo code has glossed over an error here?
Like your real code is setting ioStatus rather than Irp->IoStatus?

Finally, last resort, (or maybe first resort) turn on driver verifier and
run this mess on a checked build kernel.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Fred
Sent: Wednesday, April 13, 2005 7:26 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Error return translation from driver to win32

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” mailto:xxxxx > wrote in message news:xxxxx@ntdev
news:xxxxx
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
[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
http:

You are currently subscribed to ntdev as:
xxxxx@windows.microsoft.com mailto:xxxxx
To unsubscribe send a blank email to xxxxx@lists.osr.com
mailto:xxxxx

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx></mailto:xxxxx>

Use STATUS_INSUFFICIENT_RESOURCES instead.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
----- Original Message -----
From: Fred
Newsgroups: ntdev
To: Windows System Software Devs Interest List
Sent: Thursday, April 14, 2005 3:25 AM
Subject: Re:[ntdev] Error return translation from driver to win32

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

Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

OK, as both of these are NTSTATUS error code values and both of them have
translations to win32 error codes, why would changing the NTSTATUS value
returned make any difference? Not that this isn’t a good experiment to try,
I just don’t see how it is going to make any difference.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Thursday, April 14, 2005 2:28 AM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] Error return translation from driver to
win32

Use STATUS_INSUFFICIENT_RESOURCES instead.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: Fred mailto:xxxxx
Newsgroups: ntdev
To: Windows System Software Devs Interest List
mailto:xxxxx
Sent: Thursday, April 14, 2005 3:25 AM
Subject: Re:[ntdev] Error return translation from driver to
win32

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” mailto:xxxxx > wrote in message news:xxxxx@ntdev
news:xxxxx
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
[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
http:

You are currently subscribed to ntdev as:
xxxxx@windows.microsoft.com mailto:xxxxx
To unsubscribe send a blank email to
xxxxx@lists.osr.com mailto:xxxxx

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst
tag argument: ‘’
To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

At the risk of taunting everyone with another internal debugging tool
:slight_smile:

When the user-mode application has come back from the DeviceIoControl
call, try running the !gle command in the debugger. This will show you
both the last win32 & the last NT error returned - if you see
ERROR_SUCCESSS & STATUS_NO_MEMORY I’ll be surprised.

You aren’t calling some other Win32 function (CloseHandle for example)
between the failure of DeviceIoControl and the time you get the status
by any chance? I hate to suggest really stupid errors, but I think
we’re getting to that point :slight_smile:

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Thursday, April 14, 2005 4:17 AM
To: Windows System Software Devs Interest List
Subject: RE: Re:[ntdev] Error return translation from driver to win32

OK, as both of these are NTSTATUS error code values and both of them
have translations to win32 error codes, why would changing the NTSTATUS
value returned make any difference? Not that this isn’t a good
experiment to try, I just don’t see how it is going to make any
difference.

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032 www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Thursday, April 14, 2005 2:28 AM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] Error return translation from driver to
win32

Use STATUS_INSUFFICIENT_RESOURCES instead.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: Fred mailto:xxxxx
Newsgroups: ntdev
To: Windows System Software Devs Interest List
mailto:xxxxx
Sent: Thursday, April 14, 2005 3:25 AM
Subject: Re:[ntdev] Error return translation from driver
to
win32

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” mailto:xxxxx > wrote in message
news:xxxxx@ntdev news:xxxxx
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
[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
http:

You are currently subscribed to ntdev as:
xxxxx@windows.microsoft.com mailto:xxxxx
To unsubscribe send a blank email to
xxxxx@lists.osr.com mailto:xxxxx


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown
lmsubst tag argument: ‘’
To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’
To unsubscribe send a blank email to
xxxxx@lists.osr.com


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</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Thanks for all the input! I’ve found the error.

As it turns out, the user-mode call was calling from a class scope that was
derived from a class which had a function named GetLastError(). :: scope
resolution! I decided to step-into the GetLastError to find out what it was
doing and … bam (or duh! … which ever you prefer). I had too much focus
on this as a driver bug.

(I will now crawl under my desk)

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> Yes your problem is annoying :slight_smile:
>
> So just to be absolutely clear about this: DeviceIoControl returns false
> and
> GetLastError returns zero, right? That actually makes very little sense.
>
> Also what is the point in your crappy driver routine
> MyCrappyDriverDeviceControl of the “IO_STATUS_BLOCK ioStatus” variable? Is
> there any possiblity that your pseudo code has glossed over an error here?
> Like your real code is setting ioStatus rather than Irp->IoStatus?
>
> Finally, last resort, (or maybe first resort) turn on driver verifier and
> run this mess on a checked build kernel.
>
>
>
>
> =====================
> Mark Roddy
> Windows .NET/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>
>
>
> ________________________________
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Fred
> Sent: Wednesday, April 13, 2005 7:26 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] Error return translation from driver to win32
>
>
> 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” > mailto:xxxxx > wrote in message news:xxxxx@ntdev
> news:xxxxx
> 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
> [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
> http:
>
> You are currently subscribed to ntdev as:
> xxxxx@windows.microsoft.com mailto:xxxxx
> To unsubscribe send a blank email to xxxxx@lists.osr.com
> mailto:xxxxx
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
></mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx></mailto:xxxxx>

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Fred[SMTP:xxxxx@charter.net]
Reply To: Windows System Software Devs Interest List
Sent: Thursday, April 14, 2005 9:10 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Error return translation from driver to win32

As it turns out, the user-mode call was calling from a class scope that was
derived from a class which had a function named GetLastError(). :: scope
resolution! I decided to step-into the GetLastError to find out what it was
doing and … bam (or duh! … which ever you prefer). I had too much focus
on this as a driver bug.

Well, it is the joke of the month in this list :wink:

Nice demonstration of C++ power. However, I’d bet if you use ::GetLastError(), it would work correctly. Win32 APIs should be always called this way. Or do you mean you did it and class had overriden it in global scope? Somewhat unbelievable but C++ isn’t my main language.

BTW, if you use PC-lint, it would warn about it.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

STATUS_NO_MEMORY is successful status - something around 0x117

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Mark Roddy”
To: “Windows System Software Devs Interest List”
Sent: Thursday, April 14, 2005 3:16 PM
Subject: RE: Re:[ntdev] Error return translation from driver to win32

> OK, as both of these are NTSTATUS error code values and both of them have
> translations to win32 error codes, why would changing the NTSTATUS value
> returned make any difference? Not that this isn’t a good experiment to try,
> I just don’t see how it is going to make any difference.
>
>
> =====================
> Mark Roddy
> Windows .NET/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>
>
>
> ________________________________
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
> Sent: Thursday, April 14, 2005 2:28 AM
> To: Windows System Software Devs Interest List
> Subject: Re: Re:[ntdev] Error return translation from driver to
> win32
>
>
> Use STATUS_INSUFFICIENT_RESOURCES instead.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: Fred mailto:xxxxx
> Newsgroups: ntdev
> To: Windows System Software Devs Interest List
> mailto:xxxxx
> Sent: Thursday, April 14, 2005 3:25 AM
> Subject: Re:[ntdev] Error return translation from driver to
> win32
>
> 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” > mailto:xxxxx > wrote in message news:xxxxx@ntdev
> news:xxxxx
> 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
> [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
> http:
>
> You are currently subscribed to ntdev as:
> xxxxx@windows.microsoft.com mailto:xxxxx
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com mailto:xxxxx
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst
> tag argument: ‘’
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag
> argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

#define STATUS_NO_MEMORY ((NTSTATUS)0xC0000017L) // winnt

=====================
Mark Roddy
Windows .NET/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim
S. Shatskih
Sent: Thursday, April 14, 2005 9:57 PM
To: Windows System Software Devs Interest List
Subject: Re: Re:[ntdev] Error return translation from driver to win32

STATUS_NO_MEMORY is successful status - something around 0x117

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Mark Roddy”
> To: “Windows System Software Devs Interest List”
> Sent: Thursday, April 14, 2005 3:16 PM
> Subject: RE: Re:[ntdev] Error return translation from driver to win32
>
>
> > OK, as both of these are NTSTATUS error code values and
> both of them have
> > translations to win32 error codes, why would changing the
> NTSTATUS value
> > returned make any difference? Not that this isn’t a good
> experiment to try,
> > I just don’t see how it is going to make any difference.
> >
> >
> > =====================
> > Mark Roddy
> > Windows .NET/XP/2000 Consulting
> > Hollis Technology Solutions 603-321-1032
> > www.hollistech.com
> >
> >
> >
> >
> > ________________________________
> >
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of
> Maxim S. Shatskih
> > Sent: Thursday, April 14, 2005 2:28 AM
> > To: Windows System Software Devs Interest List
> > Subject: Re: Re:[ntdev] Error return translation from driver to
> > win32
> >
> >
> > Use STATUS_INSUFFICIENT_RESOURCES instead.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> > ----- Original Message -----
> > From: Fred mailto:xxxxx
> > Newsgroups: ntdev
> > To: Windows System Software Devs Interest List
> > mailto:xxxxx
> > Sent: Thursday, April 14, 2005 3:25 AM
> > Subject: Re:[ntdev] Error return translation from driver to
> > win32
> >
> > 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” > > mailto:xxxxx > wrote in message
> news:xxxxx@ntdev
> > news:xxxxx
> > 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
> > [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
> > http:
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@windows.microsoft.com mailto:xxxxx
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> mailto:xxxxx
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown lmsubst
> > tag argument: ‘’
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: unknown lmsubst tag
> > argument: ‘’
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> >
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@hollistech.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
></mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>