ReactOS 0.4.16-dev-92-g0c2cdca
scratch.h
Go to the documentation of this file.
1/*++
2
3Copyright (C) Microsoft Corporation. All rights reserved.
4
5Module Name:
6
7 mmc.h
8
9Abstract:
10
11 Functions/macros for using the scratch buffer and scratch request/SRB
12 in the serial I/O queue context
13
14Author:
15
16Environment:
17
18 kernel mode only
19
20Notes:
21
22
23Revision History:
24
25--*/
26
27#ifndef __SCRATCH_H__
28#define __SCRATCH_H__
29
30
32VOID
33ScratchBuffer_Deallocate(
34 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension
35 );
36
39ScratchBuffer_Allocate(
40 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension
41 );
42
43VOID
45 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension,
46 _In_ BOOLEAN ResetRequestHistory
47 );
48
50VOID
51ScratchBuffer_SetupSrb(
52 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension,
56 );
57
58VOID
60 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension,
61 _In_ WDFREQUEST OriginalRequest,
65 _In_ BOOLEAN IsReadRequest,
66 _In_ BOOLEAN UsePartialMdl
67 );
68
71 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension,
72 _In_ BOOLEAN SynchronousSrb,
73 _When_(SynchronousSrb, _Pre_null_)
74 _When_(!SynchronousSrb, _In_opt_)
75 PSRB_HISTORY_ITEM *SrbHistoryItem
76 );
77
80 _In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
82 );
83
84#if DBG
85 #define ScratchBuffer_BeginUse(context) ScratchBuffer_BeginUseX((context), __FILE__, __LINE__)
86#else
87 #define ScratchBuffer_BeginUse(context) ScratchBuffer_BeginUseX((context), NULL, (ULONG)-1)
88#endif
89
91{
92 // NOTE: these are not "real" locks. They are simply to help
93 // avoid multiple uses of the scratch buffer. Thus, it
94 // is not critical to have atomic operations here.
95 PVOID tmp = InterlockedCompareExchangePointer((PVOID)&(DeviceExtension->ScratchContext.ScratchInUse), (PVOID)-1, NULL);
96 NT_ASSERT(tmp == NULL);
97 UNREFERENCED_PARAMETER(tmp); //defensive coding, avoid PREFAST warning.
98 DeviceExtension->ScratchContext.ScratchInUseFileName = File;
99 DeviceExtension->ScratchContext.ScratchInUseLineNumber = Line;
100 ScratchBuffer_ResetItems(DeviceExtension, TRUE);
101 RequestClearSendTime(DeviceExtension->ScratchContext.ScratchRequest);
102 return;
103}
105{
106 // NOTE: these are not "real" locks. They are simply to help
107 // avoid multiple uses of the scratch buffer. Thus, it
108 // is not critical to have atomic operations here.
109
110 // On lock release, we erase ScratchInUseFileName and ScratchInUseLineNumber _before_ releasing ScratchInUse,
111 // because otherwise we may erase these after the lock has been acquired again by another thread. We store the
112 // old values of ScratchInUseFileName and ScratchInUseLineNumber in local variables to facilitate debugging,
113 // if the ASSERT at the end of the function is hit.
114 PCSTR scratchInUseFileName;
115 ULONG scratchInUseLineNumber;
116 PVOID tmp;
117
118 scratchInUseFileName = DeviceExtension->ScratchContext.ScratchInUseFileName;
119 scratchInUseLineNumber = DeviceExtension->ScratchContext.ScratchInUseLineNumber;
120 UNREFERENCED_PARAMETER(scratchInUseFileName);
121 UNREFERENCED_PARAMETER(scratchInUseLineNumber);
122 DeviceExtension->ScratchContext.ScratchInUseFileName = NULL;
123 DeviceExtension->ScratchContext.ScratchInUseLineNumber = 0;
124
125 //
126 // If we have used the PartialMdl in the scratch context we should notify MM that we will be reusing it
127 // otherwise it may leak System VA if some one below us has mapped the same.
128 //
129
130 if (DeviceExtension->ScratchContext.PartialMdlIsBuilt != FALSE)
131 {
132 MmPrepareMdlForReuse(DeviceExtension->ScratchContext.PartialMdl);
133 DeviceExtension->ScratchContext.PartialMdlIsBuilt = FALSE;
134 }
135
136 tmp = InterlockedCompareExchangePointer((PVOID)&(DeviceExtension->ScratchContext.ScratchInUse), NULL, (PVOID)-1);
137 NT_ASSERT(tmp == ((PVOID)-1));
138 UNREFERENCED_PARAMETER(tmp); //defensive coding, avoid PREFAST warning.
139 return;
140}
141
142VOID
145 );
146
147VOID
150 );
151
154ScratchBuffer_ExecuteCdbEx(
155 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension,
156 _In_opt_ WDFREQUEST OriginalRequest,
162 );
163
165FORCEINLINE // __REACTOS__
167ScratchBuffer_ExecuteCdb(
168 _Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension,
169 _In_opt_ WDFREQUEST OriginalRequest,
172 _In_ PCDB Cdb,
174 )
175{
176 return ScratchBuffer_ExecuteCdbEx(DeviceExtension,
180 Cdb,
182 0);
183}
184
186
187#endif //__SCRATCH_H__
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PFCB _In_ LONGLONG StartingOffset
Definition: cdprocs.h:291
VOID RequestClearSendTime(_In_ WDFREQUEST Request)
Definition: common.c:111
Definition: File.h:16
_In_opt_ PIRP _In_ PSCSI_REQUEST_BLOCK _In_ UCHAR _In_ ULONG _In_ ULONG _In_opt_ SRB_HISTORY * RequestHistory
Definition: classpnp.h:487
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define _IRQL_requires_max_(irql)
Definition: driverspecs.h:230
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define _Inout_
Definition: ms_sal.h:378
#define _Pre_null_
Definition: ms_sal.h:682
#define _Inout_updates_bytes_(size)
Definition: ms_sal.h:399
#define _When_(expr, annos)
Definition: ms_sal.h:254
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ FirstTry
Definition: copy.c:25
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB _In_ UCHAR _In_ ULONG TimeoutValue
Definition: scratch.h:162
VOID ScratchBuffer_ResetItems(_Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN ResetRequestHistory)
Definition: scratch.c:343
FORCEINLINE VOID ScratchBuffer_EndUse(_Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension)
Definition: scratch.h:104
FORCEINLINE VOID ScratchBuffer_BeginUseX(_Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_opt_ LPCSTR File, ULONG Line)
Definition: scratch.h:90
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:159
_In_opt_ WDFREQUEST _In_ ULONG MaximumTransferLength
Definition: scratch.h:54
_In_opt_ WDFREQUEST OriginalRequest
Definition: scratch.h:53
_In_opt_ WDFREQUEST _In_ ULONG TransferSize
Definition: scratch.h:157
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB _In_ UCHAR OprationLength
Definition: scratch.h:160
KDEFERRED_ROUTINE ScratchBuffer_ReadWriteTimerRoutine
Definition: scratch.h:185
NTSTATUS ScratchBuffer_SendSrb(_Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN SynchronousSrb, _When_(SynchronousSrb, _Pre_null_) _When_(!SynchronousSrb, _In_opt_) PSRB_HISTORY_ITEM *SrbHistoryItem)
Definition: scratch.c:906
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN GetDataFromDevice
Definition: scratch.h:56
VOID ValidateSrbHistoryDataPresumptions(_In_ SRB_HISTORY const *RequestHistory)
Definition: scratch.c:1135
NTSTATUS ScratchBuffer_PerformNextReadWrite(_In_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ BOOLEAN FirstTry)
Definition: scratch.c:429
VOID CompressSrbHistoryData(_Inout_ PSRB_HISTORY RequestHistory)
Definition: scratch.c:1033
VOID ScratchBuffer_SetupReadWriteSrb(_Inout_ PCDROM_DEVICE_EXTENSION DeviceExtension, _In_ WDFREQUEST OriginalRequest, _In_ LARGE_INTEGER StartingOffset, _In_ ULONG RequiredLength, _Inout_updates_bytes_(RequiredLength) UCHAR *DataBuffer, _In_ BOOLEAN IsReadRequest, _In_ BOOLEAN UsePartialMdl)
Definition: scratch.c:1212
Definition: ncftp.h:79
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG
Definition: typedefs.h:59
Definition: cdrw_hw.h:28
#define FORCEINLINE
Definition: wdftypes.h:67
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:30
#define MmPrepareMdlForReuse(_Mdl)
#define NT_ASSERT
Definition: rtlfuncs.h:3324
const char * LPCSTR
Definition: xmlstorage.h:183
unsigned char UCHAR
Definition: xmlstorage.h:181