You are putting data in your output buffer but you did you did not check if
it’s valid, you do not check the status of functions such as
WdfRequestRetrieveOutputBuffer.
Also, did you compile with /w4 or/wall, fix all your warnings and enabled
verifier on the driver as was suggested before ? I suppose not, here’s how
to get started: click Start, then Run and type verifier. You are really
going to need it.
//Daniel
status = WdfRequestRetrieveOutputBuffer
(Request,sizeof(FIOA_READ_LONG_REPLY),
&pOutBuffer, &Length);
pReadReply = (FIOA_READ_LONG_REPLY *)pOutBuffer;
//KdPrint((“ReadLong: Address=%x\n”,pReadRequest->Address));
pReadReply->Data = READ_REGISTER_ULONG
((PULONG)(devExt->Bar1Address+pReadRequest->Address));
wrote in message news:xxxxx@ntdev…
> Dear Pavel,
>
> What are “private functions” ? How can I set the code so that all
> functions will be “public” ?
>
> Following Mr. Zhang request here is the code of IoControl.c:
>
> /++
>
> Copyright (c) Microsoft Corporation. All rights reserved.
>
> THIS CODE AND INFORMATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY
> KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
> IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
> PURPOSE.
>
> Module Name:
>
> IoControl.c
>
> Abstract:
>
>
> Environment:
>
> Kernel mode
>
> –/
>
> #include “precomp.h”
> #include “…\Common\FioAdapterIoControl.h”
>
> /
> Function: PlxIoDeviceControl
>
> Description:
>* /
> VOID PLxEvtIoControl ( IN WDFQUEUE Queue,
> IN WDFREQUEST Request,
> IN size_t OutputBufferLength,
> IN size_t InputBufferLength,
> IN ULONG IoControlCode)
> /++
>
> Routine Description:
>
> This event is called when the framework receives IRP_MJ_DEVICE_CONTROL
> requests from the system.
>
> Arguments:
>
> Queue - Handle to the framework queue object that is associated
> with the I/O request.
> Request - Handle to a framework request object.
>
> OutputBufferLength - length of the request’s output buffer,
> if an output buffer is available.
> InputBufferLength - length of the request’s input buffer,
> if an input buffer is available.
>
> IoControlCode - the driver-defined or system-defined I/O control code
> (IOCTL) that is associated with the request.
> Return Value:
>
> VOID
>
> –/
> {
> WDFDEVICE device;
> PDEVICE_EXTENSION devExt = NULL;
> size_t bytesReturned = 0;
> BOOLEAN requestPending = FALSE;
> NTSTATUS status = STATUS_INVALID_DEVICE_REQUEST;
> //unsigned long Address;
> unsigned long Length;
> void *pInBuffer;
> void *pOutBuffer;
>
> FIOA_WRITE_LONG *pWriteRequest;
> FIOA_READ_LONG *pReadRequest;
>
> FIOA_READ_LONG_REPLY *pReadReply;
>
> WDFREQUEST InternalRequest;
> WDFREQUEST DpcRequest;
>
> PMDL CommonBufferMdl;
> PVOID CommonBufferVirtualAddress;
> ULONG CommonBufferLength;
> PUCHAR pDst;
>
> UNREFERENCED_PARAMETER(InputBufferLength);
> UNREFERENCED_PARAMETER(OutputBufferLength);
>
> KdPrint((“–> PlxEvtIoDeviceControl Code=%x\n”,IoControlCode));
> //
> // initialize variables
> //
> device = WdfIoQueueGetDevice(Queue);
>
> devExt = PLxGetDeviceContext(device);
>
> switch (IoControlCode)
> {
> case FIOA_WRITE_LONG_CODE:
> status = WdfRequestRetrieveInputBuffer (Request,sizeof(FIOA_WRITE_LONG),
> &pInBuffer, &Length);
> pWriteRequest = (FIOA_WRITE_LONG *)pInBuffer;
>
> /KdPrint((“Write (Address=%x,Data=%x)\n”,pWriteRequest->Address,
> pWriteRequest->Data));/
> WRITE_REGISTER_ULONG((PULONG)(devExt->Bar1Address+pWriteRequest->Address),
> pWriteRequest->Data);
>
> bytesReturned = 0;
>
> WdfRequestCompleteWithInformation (Request,STATUS_SUCCESS,bytesReturned);
> break;
>
> case FIOA_READ_LONG_CODE:
> status = WdfRequestRetrieveInputBuffer (Request,sizeof(FIOA_READ_LONG),
> &pInBuffer, &Length);
> pReadRequest = (FIOA_READ_LONG *)pInBuffer;
>
> status = WdfRequestRetrieveOutputBuffer
> (Request,sizeof(FIOA_READ_LONG_REPLY),
> &pOutBuffer, &Length);
> pReadReply = (FIOA_READ_LONG_REPLY *)pOutBuffer;
>
> //KdPrint((“ReadLong: Address=%x\n”,pReadRequest->Address));
>
> pReadReply->Data = READ_REGISTER_ULONG
> ((PULONG)(devExt->Bar1Address+pReadRequest->Address));
>
> //KdPrint((“ReadLong: Data=%x\n”,pReadReply->Data));
>
> bytesReturned = sizeof(FIOA_READ_LONG_REPLY);
>
> WdfRequestCompleteWithInformation (Request,STATUS_SUCCESS,bytesReturned);
> break;
>
> case FIOA_INTERRUPT_CODE:
> //Forward IOCTL request to a queue. Request will be completed in DPC
> //status = WdfRequestForwardToIoQueue(Request,devExt->InternalQueue);
> break;
>
> case FIOA_ALLOCATE_COMMON_BUFFER:
> status = WdfRequestRetrieveOutputBuffer
> (Request,sizeof(FIOA_READ_LONG_REPLY),
> &pOutBuffer, &Length);
>
> pReadReply = (FIOA_READ_LONG_REPLY *)pOutBuffer;
>
> bytesReturned = sizeof(FIOA_READ_LONG_REPLY);
>
> //Map common buffer to user space. This can be done only upon IOCTL
> request
> __try
> {
> devExt->UserSpaceCommonBuffer =
> MmMapLockedPagesSpecifyCache(devExt->CommonBufferMdl,
> UserMode,
> MmCached ,
> NULL,
> FALSE,
> NormalPagePriority);
>
> if (!devExt->UserSpaceCommonBuffer)
> {
> KdPrint ((“MmMapLockedPagesSpecifyCache failed.\n”));
> }
> }
>__except (EXCEPTION_EXECUTE_HANDLER)
> {
> devExt->UserSpaceCommonBuffer = 0x0;
> KdPrint ((“MmMapLockedPagesSpecifyCache caused exception:
> %x\n”,GetExceptionCode()));
> }
>
> pReadReply->Data = (unsigned long)devExt->UserSpaceCommonBuffer;
>
> WdfRequestCompleteWithInformation (Request,STATUS_SUCCESS,sizeof(long));
> break;
> }
>
> KdPrint((“<– PlxEvtIoDeviceControl\n”));
>
> return;
> }
>
> Thanks,
> Zvika.
>