Windows driver wdf--kmdf get Application Data buffer address

Source: Internet
Author: User

There are 3 common ways: method_buffered method_in_direct method_out_directalso Method_neither, "Windows device driver WDF development" is described as: the mode of VxD originating from Win 9x is not recommended for readers. It doesn't matter. method_buffered: Both read and write correspond to the same buffer method_in_direct\ method_out_direct : The input buffer can be used as an additional output buffer, the output buffer can be used as an additional input buffer, the difference is only in the DMA read and write to distinguish, see " Windows device drivers for WDF development "Dma_sample
to cite a simple example: the application layer DeviceIoControl the address of two Unchar (2 and 4) to the driver. Drive read address fetch value, two number add complete request return to application layer. The above procedures were: method_buffered method_in_direct method_out_direct Each execution once   Results:
driver Layer Evtdeviceiocontrol routine read processing section:    #define Iosample_ioctl_buffered Ctl_code (File_device_unknown, 0x800, method_buffered, file_any_access) #define Iosample_ioctl_in_direct Ctl_code (File_device_unknown, 0x801, Method_in_direct, file_any_access) #define IOSample_ Ioctl_out_direct Ctl_code (File_device_unknown, 0x802, Method_out_direct, file_any_access)
Switch (iocontrolcode)    {
Case iosample_ioctl_buffered : Case Iosample_ioctl_in_direct : Case Iosample_ioctl_out_direct : if (inputbufferlength = = 0 | | Outputbufferlength = = 0){//Check input, output parameter validityWdfrequestcomplete (Request, status_invalid_parameter);}Else{//method_buffered,method_out_direct,method_in_direct three different ways,The //input buffer address can be obtainedby calling the Wdfrequestretrieveinputb Uffer function//Output buffer address can be obtainedby calling the Wdfrequestretrieveoutput buffer function
//Get input buffer address bufferstatus = Wdfrequestretrieveinputbuffer (Request, 1, &buffer, NULL);if (! Nt_success (status)){Wdfrequestcomplete (Request, status_unsuccessful);break; }
//buffer represents the input buffer address//Enter the number that the X1= application passes to the driverx1 = * (UCHAR *) buffer;
//Get output buffer address bufferstatus = WdfrequestretrieveoutputBuffer (Request, 1, &buffer, NULL);if (! Nt_success (status)) {Wdfrequestcomplete (Request, status_unsuccessful);Break ;}//Input x2= the number that the application passes through the output buffer to the driverx2 = * (UCHAR *) buffer;
* (UCHAR *) buffer=x1+x2;
//completion of I/O requests, the data length of the driver passed to the application is 1 bytesWdfrequestcompletewithinFormation (Request, status_success, 1);}break;
default :Status = status_invalid_device_request; WdfrequestcompletewithinFormation (Request, status, 0);break;     }

Analysis:for method_buffered:the input and output buffers of the drive layer correspond to the input buffers and outputbuffers of the application layer, Wdfrequestretrieveinputb uffer and wdfrequestretrieveoutput buffer is read in the same location, so 2+2=4. The 6 address is unreadable in the driver layer, and he is just the application layer that accepts output from the driver.
for Method_out_direct,method_in_direct:drive layer input buffer, the drive layer output buffer corresponding to the application layer. So the 6 address is readable for the drive layer, which is actually the so-called "output buffer available as an additional input buffer"

Windows driver wdf--kmdf get Application Data buffer address

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.