Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

How can I get WDFFILEOBJECT from WDFREQUEST created by WdfRequestCreate

tatuotatuo Member Posts: 39

Hi
Who can tell me how to get WDFFILEOBJECT from WDFREQUEST created by WdfRequestCreate?

First, I create a WDFDEVICE as below.

WDF_OBJECT_ATTRIBUTES_INIT(&objectAttribs);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objectAttribs,
                                FILE_OBJECT_CONTEXT);

WdfDeviceInitSetFileObjectConfig(DeviceInit,
                                   &fileConfig,
                                   &objectAttribs);
WdfDeviceInitSetRequestAttributes(
    DeviceInit,
    &objectAttribs
);    
status = WdfDeviceCreate(&DeviceInit,
                         &objectAttribs,
                         &controlDevice);

Then, I create a WDFREQUEST.

            WDFREQUEST               sendRequest;

        WDF_OBJECT_ATTRIBUTES           RequestObjectAttributes;
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&RequestObjectAttributes,
        FILE_OBJECT_CONTEXT);
    RequestObjectAttributes.ParentObject = controlDevice;
    Status = WdfRequestCreate(
        &RequestObjectAttributes,
        NULL,
        &sendRequest
    );

sendRequest is used in the following function.

   NTSTATUS SendData(
IN PUCHAR pDataBuffer,
IN ULONG DataLength,
IN WDFREQUEST   Request)
   {
......
WDFFILEOBJECT           fileObject;
......
fileObject = WdfRequestGetFileObject(Request);
......

     }

SendData is used as

   NtStatus = SendData(pDataBuffer, 1000, sendRequest);

Computer is crashed when WdfRequestGetFileObject is called.
But WdfRequestGetFileObject can get WDFFILEOBJECT from WDFREQUEST created by framework such as EvtIoRead.
Cannot WdfRequestGetFileObject get WDFFILEOBJECT from WDFREQUEST created by its own WdfRequestCreate ?
Or WDFREQUEST should be initialised with some WDFFILEOBJECT after it is created?
(The WDFREQUEST is not sent to another driver. It is sent to itself.)

Thanks.

Tatuo

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,339

    Cannot WdfRequestGetFileObject get WDFFILEOBJECT from WDFREQUEST created by its own WdfRequestCreate ?

    What File Object would be associated with this Request?

    In other words, YOU created the Request... It doesn't have an associated open instance of your device. So... there IS no File Object. What are you expecting to get back?

    Now, having said that, WdfRequestGetFileObject shouldn't CRASH. That's pretty poor behavior (you might want to file a bug or even submit a fix for this).

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • tatuotatuo Member Posts: 39

    Dear Viscarola

    Thank you very much.

    What File Object would be associated with this Request?

    I want to get the FILE_OBJECT_CONTEXT, which I associated with WDFDEVICE in macro WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE before I call WdfDeviceCreate.
    After I get WDFFILEOBJECT, I can get FILE_OBJECT_CONTEXT with GetFileObjectContext(fileObject).

    It doesn't have an associated open instance of your device.

    I do not know WdfRequestCreate does not associate WDFFILEOBJECT with the request .
    I am stumped about how can I reuse a WDFREQUEST to send data again and again, and how can I associate a WDFFILEOBJECT with the request.

    you might want to file a bug or even submit a fix for this

    Thank you very mch. I have downloaded it. But I do not know how to use it........

    Best regard.

    Tatuo

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,339
    edited July 9

    Mr. Tatuo... my point is that there is no File Object associated with a WDFREQUEST that you create. That’s why you can’t get it; There isn’t one.

    A File Object is created as a result of an fopen/CreateFile being processed. When you create a Request, you’re not doing an open operation.

    am stumped about how can I reuse a WDFREQUEST to send data again and again

    Take a look at WdfRequestReuse.

    and how can I associate a WDFFILEOBJECT with the request.

    Hmmmm... maybe don’t do it that way? Perhaps have a Context in the Request instead?

    Does that Help?

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • tatuotatuo Member Posts: 39

    Dear Mr. Viscarola

    Hmmmm... maybe don’t do it that way? Perhaps have a Context in the Request instead?

    Thank you very much.
    I understand you say.
    The problem is solved by adding an argument of Context to the function.

    NTSTATUS SendData(
    IN PUCHAR pDataBuffer,
    IN ULONG DataLength,
    IN WDFREQUEST   Request,
    IN PNDISPROT_OPEN_CONTEXT  pOpenContext))
     {
     ......
     }
    

    Thanks a lot.

    Tatuo

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA