WdfRequestCreate failed

Hi All,

I want to send device control codes which is received from one driver to
another driver, below is my devicecontrol code

switch (IoControlCode) {

case IOCTL_MUX_CREATE_RFM_UPLINK:

WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);

objAttributes.ParentObject = devContext->frameTarget;

status = WdfRequestCreate(&objAttributes, devContext->frameTarget,
&localRequest);

if(!NTSTATUS(status)) {

MUXDBGERR((“\nWdfRequestCreate failed 0x%0x\n”,status));

WdfRequestComplete(Request, status);

}

status = WdfIoTargetFormatRequestForIoctl(devContext->frameTarget,
localRequest,

(ULONG)IOCTL_MUX_CREATE_RFM_UPLINK, NULL, NULL, NULL, NULL);

if(!NTSTATUS(status)) {

MUXDBGERR((“\nWdfRequestCreate failed 0x%0x\n”,status));

WdfObjectDelete(localRequest);

WdfRequestComplete(Request, status);

}

MUXDBGERR((“\ndevContext->rfmTarget = ioTarget; removed”));

WDF_REQUEST_SEND_OPTIONS_INIT(&sendOptions,
WDF_REQUEST_SEND_OPTION_SYNCHRONOUS);

if(!WdfRequestSend(localRequest, devContext->frameTarget, &sendOptions)) {

MUXDBGERR((“\n MUX WdfRequestSend failed”));

//To Get the status

status = WdfRequestGetStatus(Request);

if(!NT_SUCCESS(status)) {

MUXDBGERR((“\n MUX WdfRequestGetStatus failed 0x%0x\n”,status));

}

}

MUXDBGERR((“\n MUX WdfRequestSend complete”));

WdfObjectDelete(localRequest);

break;

default:

MUXDBG((“\n MUX MuxEvtDeviceControl default Start\n”));

break;

}

MUXDBGERR((“\n MUX WdfRequestComplete start”));

WdfRequestComplete(Request, status);

MUXDBGERR((“\n MUX WdfRequestComplete end”));
But my problem is wdfrequestcreate fail at very first step with error code
0x0 and same code work in Queue write callback function


Thanks and Regards
Shiva Kumara R

The returned status is 0x00??

That’s STATUS_SUCCESS :slight_smile:

#define STATUS_SUCCESS ((NTSTATUS) 0x00000000)

If that’s a typo in your post… here’s the “standard” answer: But have you enabled KMDF Verifier and looked to see the output of !WDFKD.WDFLOGDUMP ?

Peter
OSR

shiva kumara wrote:

Hi All,

I want to send device control codes which is received from one driver
to another driver, below is my devicecontrol code

switch(IoControlCode) { caseIOCTL_MUX_CREATE_RFM_UPLINK:

WDF_OBJECT_ATTRIBUTES_INIT(&objAttributes);

objAttributes.ParentObject = devContext->frameTarget;

status = WdfRequestCreate(&objAttributes, devContext->frameTarget,
&localRequest);

if(!NTSTATUS(status)) {

Your code is working just fine. It is your detection of the error that
is incorrect The line just above casts status to an “NTSTATUS” (which
does nothing) and then, if the value is 0, assumes there was an error.
Since 0 is actually success, you’re getting the opposite result.

You wanted NT_SUCCESS here, not NTSTATUS.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

There you go: An illustration of the difference between reading the TEXT of somebody’s post (which is what I did) and reading the code they provide (which is clearly what Mr. Roberts did).

Nice pickup Tim,

Peter
OSR

On 08-Mar-2012 20:03, xxxxx@osr.com wrote:

There you go: An illustration of the difference between reading the TEXT of somebody’s post (which is what I did) and reading the code they provide (which is clearly what Mr. Roberts did).

Nice pickup Tim,

+1

Yet another illustration of how C++ behaves in kernel mode.
Crap in - crap out, but more powerful.

Regards,
– pa

> -----Original Message-----

From: xxxxx@lists.osr.com [mailto:bounce-496423-
xxxxx@lists.osr.com] On Behalf Of Pavel A
Sent: Thursday, March 08, 2012 11:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] WdfRequestCreate failed

On 08-Mar-2012 20:03, xxxxx@osr.com wrote:
> [quote]
> You wanted NT_SUCCESS here, not NTSTATUS.
> [/quote]
>
> There you go: An illustration of the difference between reading the TEXT of
somebody’s post (which is what I did) and reading the code they provide (which
is clearly what Mr. Roberts did).
>
> Nice pickup Tim,

+1

Yet another illustration of how C++ behaves in kernel mode.
Crap in - crap out, but more powerful.

Agree that Tim wins the patient mentor award, hands down.

Nice troll, pa. And I’ll bite. That’s a perfect example of what is wrong with *C*. Has nothing to do with C++.

Phil
Not speaking for LogRhythm

On 08-Mar-2012 20:38, Phil Barila wrote:

Nice troll, pa. And I’ll bite. That’s a perfect example of what is wrong with *C*. Has nothing to do with C++.

No, Mr. Barilla, it has.

The OP’s code is " if(!NTSTATUS(status)) { … "
NTSTATUS is a typedef, so in C++ NTSTATUS(status) is a ctor call.
In plain C it just would not compile, so the OP would have to fix it,
rather than run and see weird behavior.

– pa

> -----Original Message-----

From: xxxxx@lists.osr.com [mailto:bounce-496438-
xxxxx@lists.osr.com] On Behalf Of Pavel A
Sent: Thursday, March 08, 2012 1:39 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] WdfRequestCreate failed

On 08-Mar-2012 20:38, Phil Barila wrote:
> Nice troll, pa. And I’ll bite. That’s a perfect example of what is wrong
with *C*. Has nothing to do with C++.
>

No, Mr. Barilla, it has.

The OP’s code is " if(!NTSTATUS(status)) { … "
NTSTATUS is a typedef, so in C++ NTSTATUS(status) is a ctor call.
In plain C it just would not compile, so the OP would have to fix it,
rather than run and see weird behavior.

Can’t argue with that. I have always disagreed with the C/C++ notion of using a non-Boolean type as a Boolean (i.e. “if(ptr) …”), so I missed the obvious syntactic delta between C and C++ in this instance.

My bad, as is sometimes said. :slight_smile:

Phil B
Not speaking for LogRhythm

I’m surprised it compiles properly in EITHER C or C++…

But I just tried it, because I know so little C++ and couldn’t believe it…

And it does compile without error in C++… and it gets C2063: ‘NTSTATUS’: not a function in C.

Yuck.

Peter
OSR

I now rewrite a lot of (what I believed is) tidy, working code
for MISRA C compliance. Sigh.
What a bag of crutches for cheap programmers in outsourcing countries as
they were 20 years ago.
Or not? Was it really meant for some kind of automatic validation tools?
Anyway - it pains.

And yes I actually like to use pointers as booleans.
In C++ the boolean cast can be even redefined
so the code below will do “what intended”. A perfect circus.

HANDLE h = INVALID_HANDLE_VALUE; // -1
if (!h) printf(“invalid”);

Regards,
– pa