ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

NTSTATUS NTAPI Ext2LockCallersBuffer ( PIRP  PtrIrp,
BOOLEAN  IsReadOperation,
uint32  Length 
)

Definition at line 1358 of file read.c.

Referenced by Ext2CommonRead(), Ext2CommonWrite(), Ext2PassDownMultiReadWriteIRP(), Ext2PassDownSingleReadWriteIRP(), and Ext2QueryDirectory().

{
    NTSTATUS            RC = STATUS_SUCCESS;
    PMDL                PtrMdl = NULL;

    ASSERT(PtrIrp);
    
    try 
    {
        // Is a MDL already present in the IRP
        if( !(PtrIrp->MdlAddress) )
        {
            // Allocate a MDL
            if (!(PtrMdl = IoAllocateMdl(PtrIrp->UserBuffer, Length, FALSE, FALSE, PtrIrp))) 
            {
                RC = STATUS_INSUFFICIENT_RESOURCES;
                try_return();
            }

            // Probe and lock the pages described by the MDL
            // We could encounter an exception doing so, swallow the exception
            // NOTE: The exception could be due to an unexpected (from our
            // perspective), invalidation of the virtual addresses that comprise
            // the passed in buffer
            try 
            {
                MmProbeAndLockPages(PtrMdl, PtrIrp->RequestorMode, (IsReadOperation ? IoWriteAccess:IoReadAccess));
            } 
            except(EXCEPTION_EXECUTE_HANDLER) 
            {
                RC = STATUS_INVALID_USER_BUFFER;
            }
        }

        try_exit:   NOTHING;

    } 
    finally 
    {
        if (!NT_SUCCESS(RC) && PtrMdl) 
        {
            IoFreeMdl(PtrMdl);
            // You MUST NULL out the MdlAddress field in the IRP after freeing
            // the MDL, else the I/O Manager will also attempt to free the MDL
            // pointed to by that field during I/O completion. Obviously, the
            // pointer becomes invalid once you free the allocated MDL and hence
            // you will encounter a system crash during IRP completion.
            PtrIrp->MdlAddress = NULL;
        }
    }

    return(RC);
}

Generated on Sun May 27 2012 05:23:38 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.