18a978a17SVictor Perevertkin /*++
28a978a17SVictor Perevertkin
38a978a17SVictor Perevertkin Copyright (c) Microsoft Corporation
48a978a17SVictor Perevertkin
58a978a17SVictor Perevertkin Module Name:
68a978a17SVictor Perevertkin
78a978a17SVictor Perevertkin FxRequestContext.cpp
88a978a17SVictor Perevertkin
98a978a17SVictor Perevertkin Abstract:
108a978a17SVictor Perevertkin
118a978a17SVictor Perevertkin This module implements FxRequest object
128a978a17SVictor Perevertkin
138a978a17SVictor Perevertkin Author:
148a978a17SVictor Perevertkin
158a978a17SVictor Perevertkin
168a978a17SVictor Perevertkin
178a978a17SVictor Perevertkin Environment:
188a978a17SVictor Perevertkin
198a978a17SVictor Perevertkin Both kernel and user mode
208a978a17SVictor Perevertkin
218a978a17SVictor Perevertkin Revision History:
228a978a17SVictor Perevertkin
238a978a17SVictor Perevertkin
248a978a17SVictor Perevertkin
258a978a17SVictor Perevertkin --*/
268a978a17SVictor Perevertkin
278a978a17SVictor Perevertkin #include "coreprivshared.hpp"
288a978a17SVictor Perevertkin
298a978a17SVictor Perevertkin // Tracing support
308a978a17SVictor Perevertkin extern "C" {
31*1f377076SVictor Perevertkin // #include "FxRequestContext.tmh"
328a978a17SVictor Perevertkin }
338a978a17SVictor Perevertkin
FxRequestContext(__in FX_REQUEST_CONTEXT_TYPE Type)348a978a17SVictor Perevertkin FxRequestContext::FxRequestContext(
358a978a17SVictor Perevertkin __in FX_REQUEST_CONTEXT_TYPE Type
368a978a17SVictor Perevertkin ) :
378a978a17SVictor Perevertkin m_RequestType(Type),
388a978a17SVictor Perevertkin m_RequestMemory(NULL)
398a978a17SVictor Perevertkin
408a978a17SVictor Perevertkin /*++
418a978a17SVictor Perevertkin
428a978a17SVictor Perevertkin Routine Description:
438a978a17SVictor Perevertkin Constructs an FxRequestContext and initialized the m_RequestType field
448a978a17SVictor Perevertkin
458a978a17SVictor Perevertkin Arguments:
468a978a17SVictor Perevertkin Type - The type of this request.
478a978a17SVictor Perevertkin
488a978a17SVictor Perevertkin
498a978a17SVictor Perevertkin
508a978a17SVictor Perevertkin
518a978a17SVictor Perevertkin
528a978a17SVictor Perevertkin Return Value:
538a978a17SVictor Perevertkin None.
548a978a17SVictor Perevertkin
558a978a17SVictor Perevertkin --*/
568a978a17SVictor Perevertkin {
578a978a17SVictor Perevertkin InitCompletionParams();
588a978a17SVictor Perevertkin }
598a978a17SVictor Perevertkin
~FxRequestContext()608a978a17SVictor Perevertkin FxRequestContext::~FxRequestContext()
618a978a17SVictor Perevertkin /*++
628a978a17SVictor Perevertkin
638a978a17SVictor Perevertkin Routine Description:
648a978a17SVictor Perevertkin Destruct for an FxRequestContext. Releases all outstanding references.
658a978a17SVictor Perevertkin
668a978a17SVictor Perevertkin Arguments:
678a978a17SVictor Perevertkin None
688a978a17SVictor Perevertkin
698a978a17SVictor Perevertkin Return Value:
708a978a17SVictor Perevertkin None
718a978a17SVictor Perevertkin
728a978a17SVictor Perevertkin --*/
738a978a17SVictor Perevertkin {
748a978a17SVictor Perevertkin ASSERT(m_RequestMemory == NULL);
758a978a17SVictor Perevertkin }
768a978a17SVictor Perevertkin
778a978a17SVictor Perevertkin VOID
StoreAndReferenceMemory(__in FxRequestBuffer * Buffer)788a978a17SVictor Perevertkin FxRequestContext::StoreAndReferenceMemory(
798a978a17SVictor Perevertkin __in FxRequestBuffer* Buffer
808a978a17SVictor Perevertkin )
818a978a17SVictor Perevertkin {
828a978a17SVictor Perevertkin _StoreAndReferenceMemoryWorker(this, &m_RequestMemory, Buffer);
838a978a17SVictor Perevertkin }
848a978a17SVictor Perevertkin
858a978a17SVictor Perevertkin VOID
ReleaseAndRestore(__in FxRequestBase * Request)868a978a17SVictor Perevertkin FxRequestContext::ReleaseAndRestore(
878a978a17SVictor Perevertkin __in FxRequestBase* Request
888a978a17SVictor Perevertkin )
898a978a17SVictor Perevertkin /*++
908a978a17SVictor Perevertkin
918a978a17SVictor Perevertkin Routine Description:
928a978a17SVictor Perevertkin This routine releases any outstanding references taken on the previous
938a978a17SVictor Perevertkin format call and restores any fields in the PIRP that were overwritten
948a978a17SVictor Perevertkin when the formatting occurred.
958a978a17SVictor Perevertkin
968a978a17SVictor Perevertkin Arguments:
978a978a17SVictor Perevertkin Irp
988a978a17SVictor Perevertkin
998a978a17SVictor Perevertkin Return Value:
1008a978a17SVictor Perevertkin
1018a978a17SVictor Perevertkin
1028a978a17SVictor Perevertkin --*/
1038a978a17SVictor Perevertkin
1048a978a17SVictor Perevertkin {
1058a978a17SVictor Perevertkin #if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
1068a978a17SVictor Perevertkin Request->FreeMdls();
1078a978a17SVictor Perevertkin #else
1088a978a17SVictor Perevertkin UNREFERENCED_PARAMETER(Request);
1098a978a17SVictor Perevertkin #endif
1108a978a17SVictor Perevertkin
1118a978a17SVictor Perevertkin if (m_RequestMemory != NULL) {
1128a978a17SVictor Perevertkin m_RequestMemory->RELEASE(this);
1138a978a17SVictor Perevertkin m_RequestMemory = NULL;
1148a978a17SVictor Perevertkin }
1158a978a17SVictor Perevertkin
1168a978a17SVictor Perevertkin InitCompletionParams();
1178a978a17SVictor Perevertkin }
1188a978a17SVictor Perevertkin
1198a978a17SVictor Perevertkin VOID
_StoreAndReferenceMemoryWorker(__in PVOID Tag,__deref_out_opt IFxMemory ** PPMemory,__in FxRequestBuffer * Buffer)1208a978a17SVictor Perevertkin FxRequestContext::_StoreAndReferenceMemoryWorker(
1218a978a17SVictor Perevertkin __in PVOID Tag,
1228a978a17SVictor Perevertkin __deref_out_opt IFxMemory** PPMemory,
1238a978a17SVictor Perevertkin __in FxRequestBuffer* Buffer
1248a978a17SVictor Perevertkin )
1258a978a17SVictor Perevertkin {
1268a978a17SVictor Perevertkin ASSERT(*PPMemory == NULL);
1278a978a17SVictor Perevertkin
1288a978a17SVictor Perevertkin switch (Buffer->DataType) {
1298a978a17SVictor Perevertkin case FxRequestBufferMemory:
1308a978a17SVictor Perevertkin Buffer->u.Memory.Memory->ADDREF(Tag);
1318a978a17SVictor Perevertkin *PPMemory = Buffer->u.Memory.Memory;
1328a978a17SVictor Perevertkin break;
1338a978a17SVictor Perevertkin
1348a978a17SVictor Perevertkin case FxRequestBufferReferencedMdl:
1358a978a17SVictor Perevertkin Buffer->u.RefMdl.Memory->ADDREF(Tag);
1368a978a17SVictor Perevertkin *PPMemory = Buffer->u.RefMdl.Memory;
1378a978a17SVictor Perevertkin break;
1388a978a17SVictor Perevertkin
1398a978a17SVictor Perevertkin default:
1408a978a17SVictor Perevertkin *PPMemory = NULL;
1418a978a17SVictor Perevertkin }
1428a978a17SVictor Perevertkin }
1438a978a17SVictor Perevertkin
1448a978a17SVictor Perevertkin VOID
FormatWriteParams(__in_opt IFxMemory * WriteMemory,__in_opt PWDFMEMORY_OFFSET WriteOffsets)1458a978a17SVictor Perevertkin FxRequestContext::FormatWriteParams(
1468a978a17SVictor Perevertkin __in_opt IFxMemory* WriteMemory,
1478a978a17SVictor Perevertkin __in_opt PWDFMEMORY_OFFSET WriteOffsets
1488a978a17SVictor Perevertkin )
1498a978a17SVictor Perevertkin {
1508a978a17SVictor Perevertkin m_CompletionParams.Type = WdfRequestTypeWrite;
1518a978a17SVictor Perevertkin
1528a978a17SVictor Perevertkin if (WriteMemory != NULL) {
1538a978a17SVictor Perevertkin m_CompletionParams.Parameters.Write.Buffer = WriteMemory->GetHandle();
1548a978a17SVictor Perevertkin }
1558a978a17SVictor Perevertkin
1568a978a17SVictor Perevertkin if (WriteOffsets != NULL) {
1578a978a17SVictor Perevertkin m_CompletionParams.Parameters.Write.Offset =
1588a978a17SVictor Perevertkin WriteOffsets->BufferOffset;
1598a978a17SVictor Perevertkin }
1608a978a17SVictor Perevertkin else {
1618a978a17SVictor Perevertkin m_CompletionParams.Parameters.Write.Offset = 0;
1628a978a17SVictor Perevertkin }
1638a978a17SVictor Perevertkin }
1648a978a17SVictor Perevertkin
1658a978a17SVictor Perevertkin VOID
FormatReadParams(__in_opt IFxMemory * ReadMemory,__in_opt PWDFMEMORY_OFFSET ReadOffsets)1668a978a17SVictor Perevertkin FxRequestContext::FormatReadParams(
1678a978a17SVictor Perevertkin __in_opt IFxMemory* ReadMemory,
1688a978a17SVictor Perevertkin __in_opt PWDFMEMORY_OFFSET ReadOffsets
1698a978a17SVictor Perevertkin )
1708a978a17SVictor Perevertkin {
1718a978a17SVictor Perevertkin m_CompletionParams.Type = WdfRequestTypeRead;
1728a978a17SVictor Perevertkin
1738a978a17SVictor Perevertkin if (ReadMemory != NULL) {
1748a978a17SVictor Perevertkin m_CompletionParams.Parameters.Read.Buffer = ReadMemory->GetHandle();
1758a978a17SVictor Perevertkin }
1768a978a17SVictor Perevertkin
1778a978a17SVictor Perevertkin if (ReadOffsets != NULL) {
1788a978a17SVictor Perevertkin m_CompletionParams.Parameters.Read.Offset =
1798a978a17SVictor Perevertkin ReadOffsets->BufferOffset;
1808a978a17SVictor Perevertkin }
1818a978a17SVictor Perevertkin else {
1828a978a17SVictor Perevertkin m_CompletionParams.Parameters.Read.Offset = 0;
1838a978a17SVictor Perevertkin }
1848a978a17SVictor Perevertkin }
1858a978a17SVictor Perevertkin
1868a978a17SVictor Perevertkin VOID
FormatOtherParams(__in FxInternalIoctlParams * InternalIoctlParams)1878a978a17SVictor Perevertkin FxRequestContext::FormatOtherParams(
1888a978a17SVictor Perevertkin __in FxInternalIoctlParams *InternalIoctlParams
1898a978a17SVictor Perevertkin )
1908a978a17SVictor Perevertkin {
1918a978a17SVictor Perevertkin m_CompletionParams.Type = WdfRequestTypeOther;
1928a978a17SVictor Perevertkin m_CompletionParams.Parameters.Others.Argument1.Ptr = InternalIoctlParams->Argument1;
1938a978a17SVictor Perevertkin m_CompletionParams.Parameters.Others.Argument2.Ptr = InternalIoctlParams->Argument2;
1948a978a17SVictor Perevertkin m_CompletionParams.Parameters.Others.Argument4.Ptr = InternalIoctlParams->Argument4;
1958a978a17SVictor Perevertkin }
196