Create asynchronic IRP

device driver

    Sponsored Links

    Next

  • 1. Win 2003 SP1 DDK vs Vista
    Hi! I'm developing my USB Isoch driver (2.0, full speed, streaming) using Win 2003 SP1 DDK based on the UsbIso example. Will Vista take this driver? Will I have to re-build it with a future release of the DDK? If I will have to: Will I have to modify the code? Will my driver achieve the same 1ms IRP completion period (IRP/URB queuing, 1ms bInterval) as it achieves on WinXP/2k? Regards, greg1x
  • 2. KeXXX functions in KMDF
    Is it good practice to be calling functions such as KeWaitForSingleObject() or KeDelayExecutionThread() from a KMDF driver. There don't appear to be any Wdf specific equivalents so i assuming these are ok. Are there any pitfalls to look out for. Thanks in advance.
  • 3. Debug in Visual Studio .Net?
    How can the Microsoft Visual Studio? debugger be used to debug user-mode programs(driver)? And how do I config my Visual Studio Environment? Thank you.

Create asynchronic IRP

Postby tamar » Tue, 09 Aug 2005 21:57:01 GMT

As a result from IoDeviceControl from an application i want to create a
new asynchronic IRP using IoAllocateIrp.
The input buffer for the new IRP is the same buffer got from the
application.


newIrp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

if(NULL != newIrp )
{
     NextStack = IoGetNextIrpStackLocation(Irp);
     NextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
     NextStack->Parameters.DeviceIoControl.IoControlCode =
IOCTL_INTERNAL_I8042_KEYBOARD_WRITE_BUFFER;

  buf  = Irp->AssociatedIrp.SystemBuffer;
  BufLen = stack->Parameters.DeviceIoControl.InputBufferLength;

  NextStack->Parameters.DeviceIoControl.Type3InputBuffer =
        ExAllocatePool(NonPagedPool,BufLen );

   RtlCopyMemory(
        NextStack->Parameters.DeviceIoControl.Type3InputBuffer,
	Irp->AssociatedIrp.SystemBuffer,
	BufferLength);

.....
}

Got blue screen with error 0xCC
PAGE_FAULT_IN_NONPAGED_AREA
Invalid system memory has been referenced.

can you tell me where i get wrong?


Re: Create asynchronic IRP

Postby Eliyas Yakub [MSFT] » Wed, 10 Aug 2005 14:29:43 GMT

 http://www.**--****.com/ ;en-us;326315

-- 









Re: Create asynchronic IRP

Postby Doron Holan [MS] » Wed, 10 Aug 2005 16:13:27 GMT

Irp->AssociatedIrp.SystemBuffer is not a valid buffer so when you call


your Source buffer is invalid

d

-- 
Please do not send e-mail directly to this alias. this alias is for 
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.









Re: Create asynchronic IRP

Postby Bill McKenzie » Fri, 12 Aug 2005 00:36:42 GMT

You aren't checking to see if the memory was actually allocated below. 
ExAllocatePool should never be used, you should use ExAllocatePoolWithTag, 
and be mindful that this call can return NULL which you need to check for 
before using  NextStack->Parameters.DeviceIoControl.Type3InputBuffer.  Also, 
why are you using  NextStack->Parameters.DeviceIoControl.Type3InputBuffer? 
Are you trying to send a buffer method neither I/O request down?  What type 
of buffering is being used for the IOCTL from which you received the 
incoming IRP?

It would probably be good for you if you got yourself a copy of Walter 
Oney's "Programming the Windows Driver Model 2ed."  This is *the* book on 
Windows drivers, and it explains the different buffering methods used for 
IOCTLs and reads and writes.

Bill M.









Re: Create asynchronic IRP

Postby Tim Roberts » Fri, 12 Aug 2005 12:35:30 GMT




Among the other problems pointed out to you, you are allocating BufLen
bytes, but copying BufferLength bytes.
-- 
- Tim Roberts,  XXXX@XXXXX.COM 
  Providenza & Boekelheide, Inc

Similar Threads:

1.how to terminate an IRP Create operation correctly?

I'm trying to prevent a certain file to be written anywhere in the 
filesystem. As far I understand, one can do that by terminating IRP Create 
(SpyCreate) when the file in question has been found with the following 
code:

        Irp->IoStatus.Information = 0;
        Irp->IoStatus.Status = STATUS_SUCCESS;
        IoCompleteRequest( Irp, IO_NO_INCREMENT );
        return STATUS_SUCCESS;

That code works fine when terminating eg IRP Writes but causes a BSOD when 
used in Create.

Any suggestion how to terminate an IRP Create operation correctly?

Your advice would be very much appreciated. 


2.Can't send IRP to the device which is created by the same driver

Hello:

I have a driver that created a control device object and will create an
another virtual device on demand. Each virtual device has a worker
thread to process the IRP that sent to it. The user mode application
can sent IOCTL to the control device object and these virtual device
objects.
This driver also register PnP notifcation by calling
IoRegisterPlugPlayNotification, and in callback function I will build
an IRP_MJ_INTERNAL_DEVICE_CONTROL and send to some virtual device
object. I can get the virtual device object since its created by
myself, but I fail to send this IRP to this virtual device, the return
code of IoCallDriver is 0xC0000010 (INVALID_DEVICE).
Below is the send IRP code snippet, is there any sight that I could dig
into, thanks.

VOID SendInternalIoctl(IN PDEVICE_OBJECT pDeviceObject, IN ULONG uCode)
{
    KEVENT event;
    IO_STATUS_BLOCK iostatus;
    PIRP pIrp;
    NTSTATUS status;

    KeInitializeEvent(&event, NotificationEvent, FALSE);

    pIrp = IoBuildDeviceIoControlRequest(uCode,

pDeviceObject,
			          NULL, 								 0,							          NULL,								 0,
                                                          TRUE,
			          &event, 						                         &iostatus);

    if (pIrp)
        status = IoCallDriver(ptarget_object, pIrp);
    else
        MYDEBUG(TRACE_ERROR, "IoBuildDeviceIoControlRequest error!\n");

    if (status == STATUS_PENDING)
    {
        MYDEBUG(TRACE_ENTRY, "IoCallDriver return pending.\n");
        KeWaitForSingleObject(&event,
	                           Executive,
		           KernelMode,
                                           FALSE,
		           NULL);
    }
    else
    {
        MYDEBUG(TRACE_ENTRY,
	          "SendInternalIoctl return with status = 0x%x.\n",	status);
    }
}

3.Creating an IRP in serial filter driver, and using IoCallDriver

I have a serial filter driver, based on the DDK samples. What it does right
now is intercept incoming data during MJ_READ. I want it to send a MJ_WRITE
to the lower driver, with some custom data I prepared.

Here is my current code (this is the last part of the master dispatch
function):

(pbFakeWrite is a buffer allocated with ExFreePool(NonPaged) and
ulFakeWriteLen is, amazingly, the length of said buffer)

--code starts here--
(...)
status = IoAcquireRemoveLock(&pdx->RemoveLock, Irp);
if(!NT_SUCCESS(status))
{
  ExFreePool(pbFakeWrite);
  return CompleteRequest(Irp, status, 0);
}
IoSkipCurrentIrpStackLocation(Irp);
status = IoCallDriver(pdx->LowerDeviceObject, Irp);
IoReleaseRemoveLock(&pdx->RemoveLock, Irp);
if(pbFakeWrite != NULL)
{
  NTSTATUS status2 = STATUS_SUCCESS;
  PIRP pNewIrp = NULL;
  PIO_STACK_LOCATION pStack = NULL;
  pNewIrp = IoAllocateIrp(pdx->LowerDeviceObject->StackSize, FALSE);
  pNewIrp->AssociatedIrp.SystemBuffer = pbFakeWrite;
  status2 = IoAcquireRemoveLock(&pdx->RemoveLock, pNewIrp);
  if(!NT_SUCCESS(status2))
  {
    IoFreeIrp(pNewIrp);
    ExFreePool(pbFakeWrite);
    return status2;
  }
  IoSetNextIrpStackLocation(pNewIrp);
  pStack = IoGetNextIrpStackLocation(pNewIrp);
  pStack->DeviceObject = pdx->LowerDeviceObject;
  pStack->MajorFunction = IRP_MJ_WRITE;
  pStack->MinorFunction = 0;
  pStack->Parameters.Write.Length = ulFakeWriteLen;
  IoSetCompletionRoutine(pNewIrp, (PIO_COMPLETION_ROUTINE)CompletionRoutine,
pdx, TRUE, TRUE, TRUE);
  status2 = IoCallDriver(pdx->LowerDeviceObject, pNewIrp);
  if(!NT_SUCCESS(status2))
  {
    KdPrint(("IoCallDriver failed (%08X)\n", status2));
  }
}
return status;
---code ends here---

My completion routine is as follows:

---code starts here---
NTSTATUS CompletionRoutine(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID
Context)
{
  if(Irp->AssociatedIrp.SystemBuffer != NULL)
  {
    ExFreePool(Irp->AssociatedIrp.SystemBuffer);
  }
  IoFreeIrp(Irp);
  IoReleaseRemoveLock(&((PDEVICE_EXTENSION)Context)->RemoveLock, Irp);
  return STATUS_MORE_PROCESSING_REQUIRED;
}
---code ends here---

It's the first time I actually attempt to create my own IRP. I took bits and
pieces from Walter Oney's book but I guess I'm missing something, as
IoCallDriver returns the very verbose 0xc0000001 code (STATUS_UNSUCCESSFUL).
The completion routine gets called successfully, by the way.

Any idea(s) as to why this doesn't work?

-----
Beno Bousquet
(e-mail address is invalid)


4.Creating Threads while handling an IRP

During the handling of IRP_MJ_CREATE in my Filter Driver I need to do some 
work 
that requires that I create a Thread.   

My IPR_MJ_CREATE handler, launches a system thread which will do some work 
for a while and then terminate.  PSCreateSystemThread gets launched ok, but 
Guess what , I'm clobbering the universe.

I call IOCallDriver and setup the Stack ok.  This all worked fine before I 
added in my thread. But now I've taken some of the work that was inline and 
put it in the thread.

now I can return back to the user quicker, but I've obviously got some 
things to deal with before this works correctly.  Do I have to handle 
IOCompletion differently now?





-- 
Gak -
 Finecats

5.IRP Create

About a month ago I asked how to correctly terminate an IRP Create 
operation. Thank you very much for your replies, Don Burn and Maxim 
Shatskih! So far they didn't help me a great deal, BUT please read on!

Your remark, Don Burn, that files can be renamed made me pondering a lot and 
for quite a while in our app I didn't come across a situation where that 
could happen until I found that download managers indeed do rename files 
when downloading is finished. Renaming starts with an IRP Create operation 
but so far I have to wait for an IRP SET_INFORMATION operation in order to 
find out whether a rename op is taking place or not. My app works perfectly 
that way but I'm not so happy with my code.

The I/O Manager knows from the very beginning what it is up to when it 
issues the appropriate commands for a specific file operation.

Now my question: Is there a way to find the kind of operation that is going 
to be performed (eg read, write, rename) when an IRP Create operation is 
issued?

I didn't find a hint in Walter Oney's Driver book.

Any suggestions would be highly appreciated.

Michael Keller


6. Create and Rename IRP's in relation to DFS

7. Can't send IRP to the device which is created by the same driver

8. IoMarkIrpPending(Irp) / IoUnmarkPendingIrp(Irp)



Return to device driver

 

Who is online

Users browsing this forum: No registered users and 4 guest