ReactOS 0.4.16-dev-297-gc569aee
fxcommonbuffer.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxCommonBuffer.cpp
8
9Abstract:
10
11 WDF CommonBuffer Object
12
13Environment:
14
15 Kernel mode only.
16
17Notes:
18
19
20Revision History:
21
22--*/
23
24#include "fxdmapch.hpp"
25
26extern "C" {
27// #include "FxCommonBuffer.tmh"
28}
29
31 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
33 ) :
35{
37 m_BufferRawVA = NULL; // allocated buffer base (unaligned)
38 m_BufferAlignedVA = NULL; // aligned buffer base
39 m_BufferAlignedLA.QuadPart = NULL; // aligned physical buffer base
40 m_BufferRawLA.QuadPart = NULL; // allocated buffer phy base (unaligned)
41 m_Length = 0;
42 m_RawLength = 0;
43
45
46 //
47 // By default use the alignment of the dma enabler.
48 //
50}
51
54{
56 return TRUE;
57}
58
62 __in size_t Length
63 )
64{
69
70 //
71 // Must be running at PASIVE_LEVEL
72 //
74 if (!NT_SUCCESS(status)) {
75 return status;
76 }
77
79
80 //
81 // If required, add alignment to the length.
82 // If alignment is <= page-1, we actually don't need to do it b/c
83 // AllocateCommonBuffer allocates at least a page of memory, regardless
84 // of the requested Length. If driver version is < v1.11, we still add the
85 // alignment to the length for compatibility.
86 //
87 if (m_Alignment > PAGE_SIZE-1 ||
89
90 status = RtlSizeTAdd(Length, m_Alignment, &m_RawLength);
91 if (!NT_SUCCESS(status)) {
93 "WDFDMAENABLER %p AllocateCommonBuffer: overflow when adding Length "
94 "%I64d + Alignment %I64d", GetObjectHandle(), Length, m_Alignment);
96 return status;
97 }
98 }
99 else {
101 }
102
106 if (m_BufferRawVA) {
107
110
111 if (m_Alignment > PAGE_SIZE-1) {
112 //
113 // If the alignment mask is over a page-size then the aligned virtual
114 // and aligned logical could be pointing to different locations
115 // in memory. So ajdust the VA to match the LA address by adding
116 // the offset of alignedLA and RawLA to VA. By doing this we
117 // only guarantee alignment of LA when the page alignment exceeds PAGE_SIZE.
118 //
119 status = RtlULongLongSub(m_BufferAlignedLA.QuadPart,
121 &offset);
122 if (!NT_SUCCESS(status)) {
124 "WDFDMAENABLER %p AllocateCommonBuffer: overflow when subtracting "
125 "RawLA %I64x from AlignedLA %I64x",
128 return status;
129 }
130
131 status = RtlULongLongToULong(offset, &result);
132 if (!NT_SUCCESS(status)) {
134 "WDFDMAENABLER %p AllocateCommonBuffer: overflow when "
135 "converting from ULongLong %I64d to ULong",
138 return status;
139 }
140
142 }
143 else {
146 }
147 } else {
148 m_Length = 0;
149 m_RawLength = 0;
153 }
154
155 return status;
156}
157
158VOID
160 VOID
161 )
162{
163 //
164 // Free this CommonBuffer per DmaEnabler
165 //
166 if (m_BufferRawVA != NULL) {
170 }
171}
172
173
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
virtual BOOLEAN Dispose(VOID)
_Must_inspect_result_ NTSTATUS AllocateCommonBuffer(__in size_t Length)
FxCommonBuffer(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in FxDmaEnabler *pDmaEnabler)
PHYSICAL_ADDRESS m_BufferRawLA
PHYSICAL_ADDRESS m_BufferAlignedLA
VOID FreeCommonBuffer(VOID)
FxDmaEnabler * m_DmaEnabler
VOID AllocateCommonBuffer(__in size_t Length, __deref_out_opt PVOID *BufferVA, __out PHYSICAL_ADDRESS *BufferPA)
VOID FreeCommonBuffer(__in size_t Length, __in PVOID BufferVA, __in PHYSICAL_ADDRESS BufferPA)
__inline size_t GetAlignment(VOID)
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
VOID MarkDisposeOverride(__in FxObjectLockState State=ObjectLock)
Definition: fxobject.hpp:1101
#define __in
Definition: dbghelp.h:35
#define TRACINGDMA
Definition: dbgtrace.h:71
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define PAGE_SIZE
Definition: env_spec_w32.h:49
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
return pObject GetObjectHandle()
FORCEINLINE ULONGLONG FX_ALIGN_LOGICAL_ADDRESS(__in PHYSICAL_ADDRESS LA, __in size_t AlignTo)
FORCEINLINE PVOID FX_ALIGN_VIRTUAL_ADDRESS(__in PVOID VA, __in size_t AlignTo)
FxDmaEnabler * pDmaEnabler
FxVerifierDbgBreakPoint(pFxDriverGlobals)
@ ObjectDoNotLock
Definition: fxobject.hpp:128
@ FX_TYPE_COMMON_BUFFER
Definition: fxtypes.h:109
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
GLuint64EXT * result
Definition: glext.h:11304
GLintptr offset
Definition: glext.h:5920
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: no_sal2.h:62
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_Must_inspect_result_ BOOLEAN IsVersionGreaterThanOrEqualTo(__in ULONG Major, __in ULONG Minor)
Definition: globalskm.cpp:92
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONGLONG QuadPart
Definition: typedefs.h:114
#define WDF_PTR_ADD_OFFSET(_ptr, _offset)
Definition: wdfcore.h:144
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList