2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/io/mdl.c
5 * PURPOSE: Io manager mdl functions
6 * PROGRAMMER: David Welch (welch@mcmail.com)
11 /* INCLUDES *****************************************************************/
13 #include <internal/kernel.h>
14 #include <internal/linkage.h>
15 #include <internal/hal/page.h>
16 #include <ddk/ntddk.h>
18 #include <internal/debug.h>
20 /* FUNCTIONS *****************************************************************/
22 PMDL
IoAllocateMdl(PVOID VirtualAddress
,
24 BOOLEAN SecondaryBuffer
,
32 Mdl
= ExAllocatePoolWithQuota(NonPagedPool
,
33 MmSizeOfMdl(VirtualAddress
,Length
));
37 Mdl
= ExAllocatePool(NonPagedPool
,MmSizeOfMdl(VirtualAddress
,Length
));
39 MmInitializeMdl(Mdl
,VirtualAddress
,Length
);
40 if (Irp
!=NULL
&& !SecondaryBuffer
)
42 Irp
->MdlAddress
= Mdl
;
47 VOID
IoBuildPartialMdl(PMDL SourceMdl
,
52 PULONG TargetPages
= (PULONG
)(TargetMdl
+ 1);
53 PULONG SourcePages
= (PULONG
)(SourceMdl
+ 1);
55 ULONG Delta
= (PAGE_ROUND_DOWN(VirtualAddress
) - (ULONG
)SourceMdl
->StartVa
)/
58 for (Va
= 0; Va
< (PAGE_ROUND_UP(Length
)/PAGESIZE
); Va
++)
60 TargetPages
[Va
] = SourcePages
[Va
+Delta
];
64 VOID
IoFreeMdl(PMDL Mdl
)
66 MmUnmapLockedPages(MmGetSystemAddressForMdl(Mdl
),Mdl
);