ReactOS  0.4.15-dev-2961-gecb0c09
fxrequestbufferkm.hpp
Go to the documentation of this file.
1 /*++
2 
3  Copyright (c) Microsoft Corporation
4 
5  Module Name:
6 
7  FxRequestBufferKm.hpp
8 
9  Abstract:
10 
11  This module implements km specific functions for FxRequestBuffer.
12 
13  Author:
14 
15 
16 
17  Environment:
18 
19  Kernel mode only
20 
21  Revision History:
22 
23  --*/
24 
25 #ifndef _FXREQUESTBUFFERKM_HPP_
26 #define _FXREQUESTBUFFERKM_HPP_
27 
28 __inline
29 VOID
31  __in PMDL Mdl,
33  )
34 {
36  u.Mdl.Mdl = Mdl;
37  u.Mdl.Length = Length;
38 }
39 
43  __in PFX_DRIVER_GLOBALS FxDriverGlobals,
45  __in BOOLEAN * ReuseMdl,
48  __inout size_t* SizeOfMdl,
49  __in BOOLEAN UnlockWhenFreed,
50  __deref_out_opt PMDL* MdlToFree
51  )
52 {
53  size_t sizeofCurrentMdl;
54  sizeofCurrentMdl = MmSizeOfMdl(Buffer, Length);
55 
56  //
57  // Caller of this function (GetOrAllocateMdl) verifies that pages
58  // are already unlocked. Asserting here, in case we start using this
59  // function elsewhere.
60  //
61  // This is why we don't unlock pages either in reuse or non-reuse case.
62  //
63  ASSERT(UnlockWhenFreed == FALSE);
64  UNREFERENCED_PARAMETER(UnlockWhenFreed); //for fre build
65 
66  //
67  // If ReuseMdl is TRUE then the Mdl to be reused is passed in.
68  //
69  if (*ReuseMdl && sizeofCurrentMdl <= *SizeOfMdl) {
70  MmPrepareMdlForReuse(*MdlToFree);
71  *Mdl = *MdlToFree;
72  }
73  else {
74  *ReuseMdl = FALSE;
75 
76  //
77  // Since *Mdl may have the original IRP Mdl
78  // free *MdlToFree and not *Mdl
79  //
80  if (*MdlToFree != NULL) {
81  FxMdlFree(FxDriverGlobals, *MdlToFree);
82  *MdlToFree = NULL;
83  if (SizeOfMdl != NULL) {
84  *SizeOfMdl = 0;
85  }
86  }
87 
88  *Mdl = FxMdlAllocate(FxDriverGlobals,
89  NULL, // owning FxObject
90  Buffer,
91  Length,
92  FALSE,
93  FALSE);
94 
95  if (*Mdl == NULL) {
96 
97  ASSERT(SizeOfMdl ? (*SizeOfMdl == 0) : TRUE);
98 
100  }
101 
102  if (SizeOfMdl != NULL) {
103  *SizeOfMdl = sizeofCurrentMdl;
104  }
105  }
106 
107  return STATUS_SUCCESS;
108 }
109 
110 
111 #endif // _FXREQUESTBUFFERKM_HPP_
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
Definition: bufpool.h:45
#define ASSERT(a)
Definition: mode.c:44
static ULONG SizeOfMdl(VOID)
Definition: NtReadFile.c:36
VOID __inline FxMdlFree(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PMDL Mdl)
Definition: fxmdl.h:60
SIZE_T NTAPI MmSizeOfMdl(IN PVOID Base, IN SIZE_T Length)
Definition: mdlsup.c:400
#define __inout
Definition: dbghelp.h:50
#define MmPrepareMdlForReuse(_Mdl)
union FxRequestBuffer::@4600 u
#define FORCEINLINE
Definition: wdftypes.h:67
FxRequestBufferType DataType
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define __deref_out_opt
Definition: dbghelp.h:29
NTSTATUS GetOrAllocateMdlWorker(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __deref_out PMDL *Mdl, __in BOOLEAN *ReuseMdl, __in LONG Length, __in PVOID Buffer, __inout size_t *SizeOfMdl, __in BOOLEAN UnlockWhenFreed, __deref_out_opt PMDL *MdlToFree)
#define __deref_out
Definition: dbghelp.h:26
unsigned int ULONG
Definition: retypes.h:1
PMDL FORCEINLINE FxMdlAllocate(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxObject *Owner, __in PVOID VirtualAddress, __in ULONG Length, __in BOOLEAN SecondaryBuffer, __in BOOLEAN ChargeQuota)
Definition: fxmdl.h:31
VOID SetMdl(__in PMDL Mdl, __in ULONG Length)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35