ReactOS  0.4.13-dev-100-gc8611ae
iomdl.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for iomdl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PMDL NTAPI IoAllocateMdl (IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
 
VOID NTAPI IoBuildPartialMdl (IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
 
VOID NTAPI IoFreeMdl (PMDL Mdl)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file iomdl.c.

Function Documentation

◆ IoAllocateMdl()

PMDL NTAPI IoAllocateMdl ( IN PVOID  VirtualAddress,
IN ULONG  Length,
IN BOOLEAN  SecondaryBuffer,
IN BOOLEAN  ChargeQuota,
IN PIRP  Irp 
)

Definition at line 22 of file iomdl.c.

27 {
28  PMDL Mdl = NULL, p;
29  ULONG Flags = 0;
30  ULONG Size;
31 
32  /* Make sure we got a valid length */
33  ASSERT(Length != 0);
34 
35  /* Fail if allocation is over 2GB */
36  if (Length & 0x80000000) return NULL;
37 
38  /* Calculate the number of pages for the allocation */
40  if (Size > 23)
41  {
42  /* This is bigger then our fixed-size MDLs. Calculate real size */
43  Size *= sizeof(PFN_NUMBER);
44  Size += sizeof(MDL);
45  if (Size > MAXUSHORT) return NULL;
46  }
47  else
48  {
49  /* Use an internal fixed MDL size */
50  Size = (23 * sizeof(PFN_NUMBER)) + sizeof(MDL);
52 
53  /* Allocate one from the lookaside list */
55  }
56 
57  /* Check if we don't have an mdl yet */
58  if (!Mdl)
59  {
60  /* Allocate one from pool */
62  if (!Mdl) return NULL;
63  }
64 
65  /* Initialize it */
67  Mdl->MdlFlags |= Flags;
68 
69  /* Check if an IRP was given too */
70  if (Irp)
71  {
72  /* Check if it came with a secondary buffer */
73  if (SecondaryBuffer)
74  {
75  /* Insert the MDL at the end */
76  p = Irp->MdlAddress;
77  while (p->Next) p = p->Next;
78  p->Next = Mdl;
79  }
80  else
81  {
82  /* Otherwise, insert it directly */
83  Irp->MdlAddress = Mdl;
84  }
85  }
86 
87  /* Return the allocated mdl */
88  return Mdl;
89 }
#define MmInitializeMdl(_MemoryDescriptorList, _BaseVa, _Length)
_In_ PIRP Irp
Definition: csq.h:116
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ULONG PFN_NUMBER
Definition: ke.h:8
smooth NULL
Definition: ftsmooth.c:416
#define IopAllocateMdlFromLookaside
Definition: io.h:108
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define TAG_MDL
Definition: tag.h:86
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
MDL
Definition: mmtypes.h:117
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3773
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
_In_ ULONG _In_ BOOLEAN SecondaryBuffer
Definition: iofuncs.h:657
#define MAXUSHORT
Definition: typedefs.h:81
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
#define MDL_ALLOCATED_FIXED_SIZE
Definition: mmtypes.h:21

Referenced by _Requires_lock_held_(), add_thread_job(), AfdGetSockName(), BuildAndSubmitIrp(), BuildDeviceInputMdl(), CcpBuildCacheMdl(), CcReadVirtualAddress(), CcWriteVirtualAddress(), CdCreateUserMdl(), CdMultipleXAAsync(), CdRomAllocateMmcResources(), CdRomDeviceControlDvdSendKey(), CdRomDeviceControlDvdStartSessionReadKey(), CdRomSetVolumeIntermediateCompletion(), CdRomStartIo(), CdRomUpdateCapacity(), ClasspInitializeGesn(), ClassSendDeviceIoControlSynchronous(), ClassSendSrbAsynchronous(), ClassSendSrbSynchronous(), CUSBDevice::CreateDeviceDescriptor(), CreateDMA(), DiskInfoExceptionCheck(), DispTdiQueryInformationEx(), DriverIoControl(), ExLockUserBuffer(), Ext2CreateMdl(), Ext2LockUserBuffer(), Ext2ReadWriteBlocks(), FatBuildZeroMdl(), FatLockUserBuffer(), FatMultipleAsync(), FatPagingFileIo(), FatSingleNonAlignedSync(), FFSLockUserBuffer(), FFSReadWriteBlocks(), FreeBT_DispatchRead(), FreeBT_DispatchWrite(), CUSBDevice::GetConfigurationDescriptor(), HackSecureVirtualMemory(), HalInitializeBios(), IoBuildAsynchronousFsdRequest(), IoBuildDeviceIoControlRequest(), IopDeviceFsIoControl(), KbdHid_StartDevice(), KsProbeStreamIrp(), LockBuffers(), LockRequest(), MapAndLockUserBuffer(), MouHid_StartDevice(), MupBuildIoControlRequest(), NdisAllocateBuffer(), NdisCopyBuffer(), nfs41_QueryDirectory(), NtfsLockUserBuffer(), NtQueryDirectoryFile(), NtReadFile(), NtStartProfile(), NtWriteFile(), prepare_raid0_write(), prepare_raid10_write(), prepare_raid5_write(), prepare_raid6_write(), read_data(), RfsdLockUserBuffer(), RfsdReadWriteBlocks(), RxLockUserBuffer(), scrub_chunk_raid56_stripe_run(), scrub_extent(), ScsiCdRomStartIo(), ScsiClassSendSrbAsynchronous(), START_TEST(), CUSBDevice::SubmitSetupPacket(), sync_read_phys(), TdiQueryMaxDatagramLength(), TdiReceive(), TdiReceiveDatagram(), TdiSend(), TdiSendDatagram(), TestMessageHandler(), TestMmBuildMdlForNonPagedPool(), TestProviderInfo(), ToshibaProcessError(), UDFLockCallersBuffer(), USBPORT_SendSetupPacket(), USBPORT_ValidateTransferParametersURB(), USBSTOR_AllocateIrp(), USBSTOR_SendRequest(), VfatLockUserBuffer(), VfatReadDiskPartial(), VfatWriteDiskPartial(), VideoPortLockBuffer(), write_data(), write_data_phys(), and write_superblock().

◆ IoBuildPartialMdl()

VOID NTAPI IoBuildPartialMdl ( IN PMDL  SourceMdl,
IN PMDL  TargetMdl,
IN PVOID  VirtualAddress,
IN ULONG  Length 
)

Definition at line 96 of file iomdl.c.

100 {
101  PPFN_NUMBER TargetPages = (PPFN_NUMBER)(TargetMdl + 1);
102  PPFN_NUMBER SourcePages = (PPFN_NUMBER)(SourceMdl + 1);
103  ULONG Offset;
104  ULONG FlagsMask = (MDL_IO_PAGE_READ |
107  MDL_IO_SPACE);
108 
109  /* Calculate the offset */
111  (ULONG_PTR)SourceMdl->StartVa) -
112  SourceMdl->ByteOffset;
113 
114  /* Check if we don't have a length and calculate it */
115  if (!Length) Length = SourceMdl->ByteCount - Offset;
116 
117  /* Write the process, start VA and byte data */
119  TargetMdl->Process = SourceMdl->Process;
120  TargetMdl->ByteCount = Length;
121  TargetMdl->ByteOffset = BYTE_OFFSET(VirtualAddress);
122 
123  /* Recalculate the length in pages */
125 
126  /* Set the MDL Flags */
128  TargetMdl->MdlFlags |= SourceMdl->MdlFlags & FlagsMask;
129  TargetMdl->MdlFlags |= MDL_PARTIAL;
130 
131  /* Set the mapped VA */
132  TargetMdl->MappedSystemVa = (PCHAR)SourceMdl->MappedSystemVa + Offset;
133 
134  /* Now do the copy */
135  Offset = (ULONG)(((ULONG_PTR)TargetMdl->StartVa -
136  (ULONG_PTR)SourceMdl->StartVa) >> PAGE_SHIFT);
137  SourcePages += Offset;
138  RtlCopyMemory(TargetPages, SourcePages, Length * sizeof(PFN_NUMBER));
139 }
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
_Inout_ PMDL TargetMdl
Definition: iofuncs.h:728
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define MDL_MAPPED_TO_SYSTEM_VA
Definition: mmtypes.h:18
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define MDL_IO_SPACE
Definition: mmtypes.h:29
ULONG * PPFN_NUMBER
Definition: ke.h:8
ULONG PFN_NUMBER
Definition: ke.h:8
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define MDL_ALLOCATED_MUST_SUCCEED
Definition: mmtypes.h:32
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
void * PVOID
Definition: retypes.h:9
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define PCHAR
Definition: match.c:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3773
#define MDL_PARTIAL
Definition: mmtypes.h:22
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define BYTE_OFFSET(Va)
#define MDL_ALLOCATED_FIXED_SIZE
Definition: mmtypes.h:21

Referenced by _Requires_lock_held_(), CdMultipleXAAsync(), Ext2ReadWriteBlocks(), FatMultipleAsync(), FatPagingFileIo(), FFSReadWriteBlocks(), FreeBT_DispatchRead(), FreeBT_DispatchWrite(), FreeBT_WriteCompletion(), NdisCopyBuffer(), RfsdReadWriteBlocks(), USBSTOR_SendRequest(), VfatReadDiskPartial(), VfatWriteDiskPartial(), and write_data().

◆ IoFreeMdl()

VOID NTAPI IoFreeMdl ( PMDL  Mdl)

Definition at line 146 of file iomdl.c.

147 {
148  /* Tell Mm to reuse the MDL */
150 
151  /* Check if this was a pool allocation */
152  if (!(Mdl->MdlFlags & MDL_ALLOCATED_FIXED_SIZE))
153  {
154  /* Free it from the pool */
156  }
157  else
158  {
159  /* Free it from the lookaside */
161  }
162 }
#define TAG_MDL
Definition: tag.h:86
#define MmPrepareMdlForReuse(_Mdl)
#define IopFreeMdlFromLookaside
Definition: io.h:110
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define MDL_ALLOCATED_FIXED_SIZE
Definition: mmtypes.h:21

Referenced by _Function_class_(), _Requires_lock_held_(), add_thread_job(), AfdGetSockName(), BuildAndSubmitIrp(), BuildDeviceInputMdl(), CcMdlReadComplete(), CcMdlReadComplete2(), CcMdlWriteAbort(), CcMdlWriteComplete(), CcReadVirtualAddress(), CcWriteVirtualAddress(), CdCreateUserMdl(), CdFinishBuffers(), CdMultiAsyncCompletionRoutine(), CdMultiSyncCompletionRoutine(), CdRomAllocateMmcResources(), CdRomDeAllocateMmcResources(), CdRomDeviceControlCompletion(), CdRomDeviceControlDvdSendKey(), CdRomDeviceControlDvdStartSessionReadKey(), CdRomSetVolumeIntermediateCompletion(), CdRomSwitchModeCompletion(), CdRomUpdateGeometryCompletion(), ClassAsynchronousCompletion(), ClassCompletionRoutine(), ClasspInitializeGesn(), ClasspSendSynchronousCompletion(), ClassSendDeviceIoControlSynchronous(), ClassSendSrbSynchronous(), CommonForwardedIoCompletionRoutine(), CUSBDevice::CreateDeviceDescriptor(), DiskInfoExceptionComplete(), DiskReregWorker(), DispTdiQueryInformationEx(), DispTdiQueryInformationExComplete(), DriverCleanup(), DriverIoControl(), ExpDeleteProfile(), Ext2CreateMdl(), Ext2DestroyMdl(), Ext2LockUserBuffer(), Ext2ReadWriteBlocks(), Ext2ReadWriteBlockSyncCompletionRoutine(), FatDeleteIrpContext_Real(), FatLockUserBuffer(), FatMultipleAsync(), FatMultiSyncCompletionRoutine(), FatPagingFileCompletionRoutineCatch(), FatSingleNonAlignedSync(), FFSLockUserBuffer(), FFSReadWriteBlocks(), FFSReadWriteBlockSyncCompletionRoutine(), free_write_data_stripes(), FreeBT_DispatchRead(), FreeBT_DispatchWrite(), FreeBT_ReadCompletion(), FreeBT_WriteCompletion(), FreeDeviceInputMdl(), CUSBDevice::GetConfigurationDescriptor(), HackSecureVirtualMemory(), HackUnsecureVirtualMemory(), IoBuildAsynchronousFsdRequest(), IoBuildDeviceIoControlRequest(), IofCompleteRequest(), IopCleanupAfterException(), IopCleanupIrp(), IopCompleteRequest(), KbdHid_FreeResources(), LockBuffers(), LockRequest(), MapAndLockUserBuffer(), MouHid_FreeResources(), NdisFreeBuffer(), nfs41_downcall(), nfs41_QueryDirectory(), NtfsLockUserBuffer(), NtStopProfile(), prepare_raid0_write(), prepare_raid10_write(), prepare_raid5_write(), prepare_raid6_write(), read_data(), RfsdLockUserBuffer(), RfsdReadWriteBlocks(), RfsdReadWriteBlockSyncCompletionRoutine(), RxLockUserBuffer(), scrub_chunk_raid56_stripe_run(), scrub_extent(), ScsiClassAsynchronousCompletion(), SpiCompletionRoutine(), START_TEST(), CUSBDevice::SubmitSetupPacket(), sync_read_phys(), TdiQueryMaxDatagramLength(), TdiReceive(), TdiReceiveDatagram(), TdiSend(), TdiSendDatagram(), TestCleanEverything(), TestMmBuildMdlForNonPagedPool(), TestProviderInfo(), ToshibaProcessErrorCompletion(), UDFAsyncCompletionRoutine(), UDFLockCallersBuffer(), UnlockBuffers(), UnlockRequest(), USBPORT_CompleteTransfer(), USBSTOR_CSWCompletionRoutine(), USBSTOR_SendIrp(), VfatLockUserBuffer(), VfatReadWritePartialCompletion(), VideoPortUnlockBuffer(), write_data(), write_data_phys(), and write_superblocks().