Fix the definition of BYTES_TO_PAGES. While the macro might look overcomplicated, it actually needs to be this way to prevent integer overflows.

svn path=/trunk/; revision=58738
This commit is contained in:
Timo Kreuzer 2013-04-13 16:10:09 +00:00
parent 4eb24ad42a
commit 12eabcde28
2 changed files with 38 additions and 34 deletions

View file

@ -11248,36 +11248,38 @@ void __PREfastPagedCodeLocked(void);
/* ULONG
* BYTE_OFFSET(
* IN PVOID Va)
* _In_ PVOID Va)
*/
#define BYTE_OFFSET(Va) \
((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
/* ULONG
* BYTES_TO_PAGES(
* IN ULONG Size)
* _In_ ULONG Size)
*
* Note: This needs to be like this to avoid overflows!
*/
#define BYTES_TO_PAGES(Size) \
(((Size) + PAGE_SIZE - 1) >> PAGE_SHIFT)
(((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
/* PVOID
* PAGE_ALIGN(
* IN PVOID Va)
* _In_ PVOID Va)
*/
#define PAGE_ALIGN(Va) \
((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
/* ULONG_PTR
* ROUND_TO_PAGES(
* IN ULONG_PTR Size)
* _In_ ULONG_PTR Size)
*/
#define ROUND_TO_PAGES(Size) \
(((ULONG_PTR) (Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
/* ULONG
* ADDRESS_AND_SIZE_TO_SPAN_PAGES(
* IN PVOID Va,
* IN ULONG Size)
* _In_ PVOID Va,
* _In_ ULONG Size)
*/
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size) \
((ULONG) ((((ULONG_PTR) (_Va) & (PAGE_SIZE - 1)) \
@ -11289,7 +11291,7 @@ void __PREfastPagedCodeLocked(void);
/*
* ULONG
* MmGetMdlByteCount(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmGetMdlByteCount(_Mdl) \
((_Mdl)->ByteCount)
@ -11307,7 +11309,7 @@ void __PREfastPagedCodeLocked(void);
/*
* PPFN_NUMBER
* MmGetMdlPfnArray(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmGetMdlPfnArray(_Mdl) \
((PPFN_NUMBER) ((_Mdl) + 1))
@ -11315,7 +11317,7 @@ void __PREfastPagedCodeLocked(void);
/*
* PVOID
* MmGetMdlVirtualAddress(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmGetMdlVirtualAddress(_Mdl) \
((PVOID) ((PCHAR) ((_Mdl)->StartVa) + (_Mdl)->ByteOffset))
@ -11324,7 +11326,7 @@ void __PREfastPagedCodeLocked(void);
#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
/* PVOID MmGetSystemAddressForMdl(
* IN PMDL Mdl);
* _In_ PMDL Mdl);
*/
#define MmGetSystemAddressForMdl(Mdl) \
(((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
@ -11334,8 +11336,8 @@ void __PREfastPagedCodeLocked(void);
/* PVOID
* MmGetSystemAddressForMdlSafe(
* IN PMDL Mdl,
* IN MM_PAGE_PRIORITY Priority)
* _In_ PMDL Mdl,
* _In_ MM_PAGE_PRIORITY Priority)
*/
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
(((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
@ -11347,9 +11349,9 @@ void __PREfastPagedCodeLocked(void);
/*
* VOID
* MmInitializeMdl(
* IN PMDL MemoryDescriptorList,
* IN PVOID BaseVa,
* IN SIZE_T Length)
* _In_ PMDL MemoryDescriptorList,
* _In_ PVOID BaseVa,
* _In_ SIZE_T Length)
*/
#define MmInitializeMdl(_MemoryDescriptorList, \
_BaseVa, \
@ -11367,7 +11369,7 @@ void __PREfastPagedCodeLocked(void);
/*
* VOID
* MmPrepareMdlForReuse(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmPrepareMdlForReuse(_Mdl) \
{ \

View file

@ -45,36 +45,38 @@ $if (_WDMDDK_)
/* ULONG
* BYTE_OFFSET(
* IN PVOID Va)
* _In_ PVOID Va)
*/
#define BYTE_OFFSET(Va) \
((ULONG) ((ULONG_PTR) (Va) & (PAGE_SIZE - 1)))
/* ULONG
* BYTES_TO_PAGES(
* IN ULONG Size)
* _In_ ULONG Size)
*
* Note: This needs to be like this to avoid overflows!
*/
#define BYTES_TO_PAGES(Size) \
(((Size) + PAGE_SIZE - 1) >> PAGE_SHIFT)
(((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
/* PVOID
* PAGE_ALIGN(
* IN PVOID Va)
* _In_ PVOID Va)
*/
#define PAGE_ALIGN(Va) \
((PVOID) ((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
/* ULONG_PTR
* ROUND_TO_PAGES(
* IN ULONG_PTR Size)
* _In_ ULONG_PTR Size)
*/
#define ROUND_TO_PAGES(Size) \
(((ULONG_PTR) (Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
/* ULONG
* ADDRESS_AND_SIZE_TO_SPAN_PAGES(
* IN PVOID Va,
* IN ULONG Size)
* _In_ PVOID Va,
* _In_ ULONG Size)
*/
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size) \
((ULONG) ((((ULONG_PTR) (_Va) & (PAGE_SIZE - 1)) \
@ -86,7 +88,7 @@ $if (_WDMDDK_)
/*
* ULONG
* MmGetMdlByteCount(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmGetMdlByteCount(_Mdl) \
((_Mdl)->ByteCount)
@ -104,7 +106,7 @@ $if (_WDMDDK_)
/*
* PPFN_NUMBER
* MmGetMdlPfnArray(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmGetMdlPfnArray(_Mdl) \
((PPFN_NUMBER) ((_Mdl) + 1))
@ -112,7 +114,7 @@ $if (_WDMDDK_)
/*
* PVOID
* MmGetMdlVirtualAddress(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmGetMdlVirtualAddress(_Mdl) \
((PVOID) ((PCHAR) ((_Mdl)->StartVa) + (_Mdl)->ByteOffset))
@ -121,7 +123,7 @@ $if (_WDMDDK_)
#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
/* PVOID MmGetSystemAddressForMdl(
* IN PMDL Mdl);
* _In_ PMDL Mdl);
*/
#define MmGetSystemAddressForMdl(Mdl) \
(((Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | \
@ -131,8 +133,8 @@ $if (_WDMDDK_)
/* PVOID
* MmGetSystemAddressForMdlSafe(
* IN PMDL Mdl,
* IN MM_PAGE_PRIORITY Priority)
* _In_ PMDL Mdl,
* _In_ MM_PAGE_PRIORITY Priority)
*/
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority) \
(((_Mdl)->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA \
@ -144,9 +146,9 @@ $if (_WDMDDK_)
/*
* VOID
* MmInitializeMdl(
* IN PMDL MemoryDescriptorList,
* IN PVOID BaseVa,
* IN SIZE_T Length)
* _In_ PMDL MemoryDescriptorList,
* _In_ PVOID BaseVa,
* _In_ SIZE_T Length)
*/
#define MmInitializeMdl(_MemoryDescriptorList, \
_BaseVa, \
@ -164,7 +166,7 @@ $if (_WDMDDK_)
/*
* VOID
* MmPrepareMdlForReuse(
* IN PMDL Mdl)
* _In_ PMDL Mdl)
*/
#define MmPrepareMdlForReuse(_Mdl) \
{ \