ReactOS 0.4.15-dev-7942-gd23573b
memstream.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for memstream.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static PRTL_MEMORY_STREAM IStream_To_RTL_MEMORY_STREAM (_In_ IStream *Interface)
 
VOID NTAPI RtlInitMemoryStream (_Out_ PRTL_MEMORY_STREAM Stream)
 
VOID NTAPI RtlInitOutOfProcessMemoryStream (_Out_ PRTL_MEMORY_STREAM Stream)
 
VOID NTAPI RtlFinalReleaseOutOfProcessMemoryStream (_In_ PRTL_MEMORY_STREAM Stream)
 
HRESULT NTAPI RtlQueryInterfaceMemoryStream (_In_ IStream *This, _In_ REFIID RequestedIid, _Outptr_ PVOID *ResultObject)
 
ULONG NTAPI RtlAddRefMemoryStream (_In_ IStream *This)
 
ULONG NTAPI RtlReleaseMemoryStream (_In_ IStream *This)
 
HRESULT NTAPI RtlReadMemoryStream (_In_ IStream *This, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_opt_ PULONG BytesRead)
 
HRESULT NTAPI RtlReadOutOfProcessMemoryStream (_In_ IStream *This, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_opt_ PULONG BytesRead)
 
HRESULT NTAPI RtlSeekMemoryStream (_In_ IStream *This, _In_ LARGE_INTEGER RelativeOffset, _In_ ULONG Origin, _Out_opt_ PULARGE_INTEGER ResultOffset)
 
HRESULT NTAPI RtlCopyMemoryStreamTo (_In_ IStream *This, _In_ IStream *Target, _In_ ULARGE_INTEGER Length, _Out_opt_ PULARGE_INTEGER BytesRead, _Out_opt_ PULARGE_INTEGER BytesWritten)
 
HRESULT NTAPI RtlStatMemoryStream (_In_ IStream *This, _Out_ STATSTG *Stats, _In_ ULONG Flags)
 
HRESULT NTAPI RtlWriteMemoryStream (_In_ IStream *This, _In_reads_bytes_(Length) CONST VOID *Buffer, _In_ ULONG Length, _Out_opt_ PULONG BytesWritten)
 
HRESULT NTAPI RtlSetMemoryStreamSize (_In_ IStream *This, _In_ ULARGE_INTEGER NewSize)
 
HRESULT NTAPI RtlCommitMemoryStream (_In_ IStream *This, _In_ ULONG CommitFlags)
 
HRESULT NTAPI RtlRevertMemoryStream (_In_ IStream *This)
 
HRESULT NTAPI RtlLockMemoryStreamRegion (_In_ IStream *This, _In_ ULARGE_INTEGER Offset, _In_ ULARGE_INTEGER Length, _In_ ULONG LockType)
 
HRESULT NTAPI RtlUnlockMemoryStreamRegion (_In_ IStream *This, _In_ ULARGE_INTEGER Offset, _In_ ULARGE_INTEGER Length, _In_ ULONG LockType)
 
HRESULT NTAPI RtlCloneMemoryStream (_In_ IStream *This, _Outptr_ IStream **ResultStream)
 
NTSTATUS NTAPI RtlCopyMappedMemory (_Out_writes_bytes_all_(Size) PVOID Destination, _In_reads_bytes_(Size) const VOID *Source, _In_ SIZE_T Size)
 

Variables

const struct IStreamVtbl RtlMemoryStreamVtbl
 
const struct IStreamVtbl RtlOutOfProcessMemoryStreamVtbl
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file memstream.c.

Function Documentation

◆ IStream_To_RTL_MEMORY_STREAM()

static PRTL_MEMORY_STREAM IStream_To_RTL_MEMORY_STREAM ( _In_ IStream Interface)
static

Definition at line 58 of file memstream.c.

60{
61 if (Interface == NULL)
62 return NULL;
63
64 return CONTAINING_RECORD(Interface, RTL_MEMORY_STREAM, Vtbl);
65}
#define NULL
Definition: types.h:112
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465

Referenced by RtlAddRefMemoryStream(), RtlReadMemoryStream(), RtlReadOutOfProcessMemoryStream(), RtlReleaseMemoryStream(), RtlSeekMemoryStream(), and RtlStatMemoryStream().

◆ RtlAddRefMemoryStream()

ULONG NTAPI RtlAddRefMemoryStream ( _In_ IStream This)

Definition at line 131 of file memstream.c.

133{
134 PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
135
136 return InterlockedIncrement(&Stream->RefCount);
137}
#define InterlockedIncrement
Definition: armddk.h:53
static PRTL_MEMORY_STREAM IStream_To_RTL_MEMORY_STREAM(_In_ IStream *Interface)
Definition: memstream.c:58
static IStream Stream
Definition: htmldoc.c:1115

◆ RtlCloneMemoryStream()

HRESULT NTAPI RtlCloneMemoryStream ( _In_ IStream This,
_Outptr_ IStream **  ResultStream 
)

Definition at line 464 of file memstream.c.

467{
469 UNREFERENCED_PARAMETER(ResultStream);
470
471 return E_NOTIMPL;
472}
#define E_NOTIMPL
Definition: ddrawi.h:99
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317

◆ RtlCommitMemoryStream()

HRESULT NTAPI RtlCommitMemoryStream ( _In_ IStream This,
_In_ ULONG  CommitFlags 
)

Definition at line 398 of file memstream.c.

401{
403 UNREFERENCED_PARAMETER(CommitFlags);
404
405 return E_NOTIMPL;
406}

◆ RtlCopyMappedMemory()

NTSTATUS NTAPI RtlCopyMappedMemory ( _Out_writes_bytes_all_(Size) PVOID  Destination,
_In_reads_bytes_(Size) const VOID Source,
_In_ SIZE_T  Size 
)

Definition at line 479 of file memstream.c.

483{
486 {
488 }
492 {
494 }
495 _SEH2_END;
496 return Status;
497}
LONG NTSTATUS
Definition: precomp.h:26
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
#define STATUS_IN_PAGE_ERROR
Definition: ntstatus.h:243
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

◆ RtlCopyMemoryStreamTo()

HRESULT NTAPI RtlCopyMemoryStreamTo ( _In_ IStream This,
_In_ IStream Target,
_In_ ULARGE_INTEGER  Length,
_Out_opt_ PULARGE_INTEGER  BytesRead,
_Out_opt_ PULARGE_INTEGER  BytesWritten 
)

Definition at line 282 of file memstream.c.

288{
289 CHAR Buffer[1024];
290 ULONGLONG TotalSize;
291 ULONG Left, Amount;
293
294 if (BytesRead)
295 BytesRead->QuadPart = 0;
296 if (BytesWritten)
297 BytesWritten->QuadPart = 0;
298
299 if (!Target)
300 return S_OK;
301
302 if (!Length.QuadPart)
303 return S_OK;
304
305 /* Copy data */
306 TotalSize = Length.QuadPart;
307 while (TotalSize)
308 {
309 Left = (ULONG)min(TotalSize, sizeof(Buffer));
310
311 /* Read */
312 Result = IStream_Read(This, Buffer, Left, &Amount);
313 if (BytesRead)
314 BytesRead->QuadPart += Amount;
315 if (FAILED(Result) || Amount == 0)
316 break;
317
318 Left = Amount;
319
320 /* Write */
321 Result = IStream_Write(Target, Buffer, Left, &Amount);
322 if (BytesWritten)
323 BytesWritten->QuadPart += Amount;
324 if (FAILED(Result) || Amount != Left)
325 break;
326
327 TotalSize -= Left;
328 }
329 return Result;
330}
Definition: bufpool.h:45
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
Definition: fsrtlfuncs.h:551
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define min(a, b)
Definition: monoChain.cc:55
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
char CHAR
Definition: xmlstorage.h:175

◆ RtlFinalReleaseOutOfProcessMemoryStream()

VOID NTAPI RtlFinalReleaseOutOfProcessMemoryStream ( _In_ PRTL_MEMORY_STREAM  Stream)

Definition at line 97 of file memstream.c.

99{
101}
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CustomFinalReleaseOutOfProcessMemoryStream(), RtlInitOutOfProcessMemoryStream(), and test_OutOfProcess().

◆ RtlInitMemoryStream()

VOID NTAPI RtlInitMemoryStream ( _Out_ PRTL_MEMORY_STREAM  Stream)

Definition at line 72 of file memstream.c.

74{
75 RtlZeroMemory(Stream, sizeof(RTL_MEMORY_STREAM));
77}
const struct IStreamVtbl RtlMemoryStreamVtbl
Definition: memstream.c:18
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by test_InProcess().

◆ RtlInitOutOfProcessMemoryStream()

VOID NTAPI RtlInitOutOfProcessMemoryStream ( _Out_ PRTL_MEMORY_STREAM  Stream)

Definition at line 84 of file memstream.c.

86{
87 RtlZeroMemory(Stream, sizeof(RTL_MEMORY_STREAM));
90}
const struct IStreamVtbl RtlOutOfProcessMemoryStreamVtbl
Definition: memstream.c:36
VOID NTAPI RtlFinalReleaseOutOfProcessMemoryStream(_In_ PRTL_MEMORY_STREAM Stream)
Definition: memstream.c:97

Referenced by test_OutOfProcess().

◆ RtlLockMemoryStreamRegion()

HRESULT NTAPI RtlLockMemoryStreamRegion ( _In_ IStream This,
_In_ ULARGE_INTEGER  Offset,
_In_ ULARGE_INTEGER  Length,
_In_ ULONG  LockType 
)

Definition at line 426 of file memstream.c.

431{
436
437 return E_NOTIMPL;
438}
_In_ WDFREQUEST _In_ MEDIA_LOCK_TYPE LockType
Definition: cdrom.h:1335
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101

◆ RtlQueryInterfaceMemoryStream()

HRESULT NTAPI RtlQueryInterfaceMemoryStream ( _In_ IStream This,
_In_ REFIID  RequestedIid,
_Outptr_ PVOID ResultObject 
)

Definition at line 108 of file memstream.c.

112{
113 if (IsEqualGUID(RequestedIid, &IID_IUnknown) ||
114 IsEqualGUID(RequestedIid, &IID_ISequentialStream) ||
115 IsEqualGUID(RequestedIid, &IID_IStream))
116 {
117 IStream_AddRef(This);
118 *ResultObject = This;
119 return S_OK;
120 }
121
122 *ResultObject = NULL;
123 return E_NOINTERFACE;
124}
const GUID IID_IUnknown
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ RtlReadMemoryStream()

HRESULT NTAPI RtlReadMemoryStream ( _In_ IStream This,
_Out_writes_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length,
_Out_opt_ PULONG  BytesRead 
)

Definition at line 166 of file memstream.c.

171{
172 ULONG CopyLength;
173 PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
174 SIZE_T Available = (PUCHAR)Stream->End - (PUCHAR)Stream->Current;
175
176 if (BytesRead)
177 *BytesRead = 0;
178
179 if (!Length)
180 return S_OK;
181
182 CopyLength = min(Available, Length);
183
184 RtlMoveMemory(Buffer, Stream->Current, CopyLength);
185
186 Stream->Current = (PUCHAR)Stream->Current + CopyLength;
187
188 *BytesRead = CopyLength;
189
190 return S_OK;
191}
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
unsigned char * PUCHAR
Definition: typedefs.h:53

◆ RtlReadOutOfProcessMemoryStream()

HRESULT NTAPI RtlReadOutOfProcessMemoryStream ( _In_ IStream This,
_Out_writes_bytes_(Length) PVOID  Buffer,
_In_ ULONG  Length,
_Out_opt_ PULONG  BytesRead 
)

Definition at line 198 of file memstream.c.

203{
205 ULONG CopyLength;
206 PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
207 SIZE_T Available = (PUCHAR)Stream->End - (PUCHAR)Stream->Current;
208 SIZE_T LocalBytesRead = 0;
209
210 if (BytesRead)
211 *BytesRead = 0;
212
213 if (!Length)
214 return S_OK;
215
216 CopyLength = min(Available, Length);
217
218 Status = NtReadVirtualMemory(Stream->ProcessHandle,
219 Stream->Current,
220 Buffer,
221 CopyLength,
222 &LocalBytesRead);
223
224 if (NT_SUCCESS(Status))
225 {
226 Stream->Current = (PUCHAR)Stream->Current + LocalBytesRead;
227 if (BytesRead)
228 *BytesRead = (ULONG)LocalBytesRead;
229 }
230
232}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
if(dx< 0)
Definition: linetemp.h:194
NTSTATUS NTAPI NtReadVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, OUT PVOID Buffer, IN SIZE_T NumberOfBytesToRead, OUT PSIZE_T NumberOfBytesRead OPTIONAL)
Definition: virtual.c:2816
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

◆ RtlReleaseMemoryStream()

ULONG NTAPI RtlReleaseMemoryStream ( _In_ IStream This)

Definition at line 144 of file memstream.c.

146{
147 PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
148 LONG Result;
149
150 Result = InterlockedDecrement(&Stream->RefCount);
151
152 if (Result == 0)
153 {
154 if (Stream->FinalRelease)
155 Stream->FinalRelease(Stream);
156 }
157
158 return Result;
159}
#define InterlockedDecrement
Definition: armddk.h:52
long LONG
Definition: pedump.c:60

◆ RtlRevertMemoryStream()

HRESULT NTAPI RtlRevertMemoryStream ( _In_ IStream This)

Definition at line 413 of file memstream.c.

415{
417
418 return E_NOTIMPL;
419}

◆ RtlSeekMemoryStream()

HRESULT NTAPI RtlSeekMemoryStream ( _In_ IStream This,
_In_ LARGE_INTEGER  RelativeOffset,
_In_ ULONG  Origin,
_Out_opt_ PULARGE_INTEGER  ResultOffset 
)

Definition at line 239 of file memstream.c.

244{
245 PVOID NewPosition;
246 PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
247
248 switch (Origin)
249 {
250 case STREAM_SEEK_SET:
251 NewPosition = (PUCHAR)Stream->Start + RelativeOffset.QuadPart;
252 break;
253
254 case STREAM_SEEK_CUR:
255 NewPosition = (PUCHAR)Stream->Current + RelativeOffset.QuadPart;
256 break;
257
258 case STREAM_SEEK_END:
259 NewPosition = (PUCHAR)Stream->End - RelativeOffset.QuadPart;
260 break;
261
262 default:
263 return E_INVALIDARG;
264 }
265
266 if (NewPosition < Stream->Start || NewPosition > Stream->End)
268
269 Stream->Current = NewPosition;
270
271 if (ResultOffset)
272 ResultOffset->QuadPart = (PUCHAR)Stream->Current - (PUCHAR)Stream->Start;
273
274 return S_OK;
275}
#define E_INVALIDARG
Definition: ddrawi.h:101
@ Start
Definition: partlist.h:33
#define STG_E_INVALIDPOINTER
Definition: winerror.h:2571

◆ RtlSetMemoryStreamSize()

HRESULT NTAPI RtlSetMemoryStreamSize ( _In_ IStream This,
_In_ ULARGE_INTEGER  NewSize 
)

Definition at line 383 of file memstream.c.

386{
389
390 return E_NOTIMPL;
391}
_Must_inspect_result_ _In_ USHORT NewSize
Definition: fltkernel.h:975

◆ RtlStatMemoryStream()

HRESULT NTAPI RtlStatMemoryStream ( _In_ IStream This,
_Out_ STATSTG *  Stats,
_In_ ULONG  Flags 
)

Definition at line 337 of file memstream.c.

341{
342 PRTL_MEMORY_STREAM Stream = IStream_To_RTL_MEMORY_STREAM(This);
343
344 if (!Stats)
346
347 RtlZeroMemory(Stats, sizeof(STATSTG));
348 Stats->type = STGTY_STREAM;
349 Stats->cbSize.QuadPart = (PUCHAR)Stream->End - (PUCHAR)Stream->Start;
350
351 return S_OK;
352}

◆ RtlUnlockMemoryStreamRegion()

HRESULT NTAPI RtlUnlockMemoryStreamRegion ( _In_ IStream This,
_In_ ULARGE_INTEGER  Offset,
_In_ ULARGE_INTEGER  Length,
_In_ ULONG  LockType 
)

Definition at line 445 of file memstream.c.

◆ RtlWriteMemoryStream()

HRESULT NTAPI RtlWriteMemoryStream ( _In_ IStream This,
_In_reads_bytes_(Length) CONST VOID Buffer,
_In_ ULONG  Length,
_Out_opt_ PULONG  BytesWritten 
)

Variable Documentation

◆ RtlMemoryStreamVtbl

const struct IStreamVtbl RtlMemoryStreamVtbl
Initial value:
=
{
}
HRESULT NTAPI RtlSeekMemoryStream(_In_ IStream *This, _In_ LARGE_INTEGER RelativeOffset, _In_ ULONG Origin, _Out_opt_ PULARGE_INTEGER ResultOffset)
Definition: memstream.c:239
HRESULT NTAPI RtlQueryInterfaceMemoryStream(_In_ IStream *This, _In_ REFIID RequestedIid, _Outptr_ PVOID *ResultObject)
Definition: memstream.c:108
HRESULT NTAPI RtlSetMemoryStreamSize(_In_ IStream *This, _In_ ULARGE_INTEGER NewSize)
Definition: memstream.c:383
HRESULT NTAPI RtlCopyMemoryStreamTo(_In_ IStream *This, _In_ IStream *Target, _In_ ULARGE_INTEGER Length, _Out_opt_ PULARGE_INTEGER BytesRead, _Out_opt_ PULARGE_INTEGER BytesWritten)
Definition: memstream.c:282
HRESULT NTAPI RtlCommitMemoryStream(_In_ IStream *This, _In_ ULONG CommitFlags)
Definition: memstream.c:398
ULONG NTAPI RtlAddRefMemoryStream(_In_ IStream *This)
Definition: memstream.c:131
HRESULT NTAPI RtlLockMemoryStreamRegion(_In_ IStream *This, _In_ ULARGE_INTEGER Offset, _In_ ULARGE_INTEGER Length, _In_ ULONG LockType)
Definition: memstream.c:426
HRESULT NTAPI RtlWriteMemoryStream(_In_ IStream *This, _In_reads_bytes_(Length) CONST VOID *Buffer, _In_ ULONG Length, _Out_opt_ PULONG BytesWritten)
Definition: memstream.c:364
HRESULT NTAPI RtlUnlockMemoryStreamRegion(_In_ IStream *This, _In_ ULARGE_INTEGER Offset, _In_ ULARGE_INTEGER Length, _In_ ULONG LockType)
Definition: memstream.c:445
HRESULT NTAPI RtlReadMemoryStream(_In_ IStream *This, _Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _Out_opt_ PULONG BytesRead)
Definition: memstream.c:166
HRESULT NTAPI RtlCloneMemoryStream(_In_ IStream *This, _Outptr_ IStream **ResultStream)
Definition: memstream.c:464
ULONG NTAPI RtlReleaseMemoryStream(_In_ IStream *This)
Definition: memstream.c:144
HRESULT NTAPI RtlRevertMemoryStream(_In_ IStream *This)
Definition: memstream.c:413
HRESULT NTAPI RtlStatMemoryStream(_In_ IStream *This, _Out_ STATSTG *Stats, _In_ ULONG Flags)
Definition: memstream.c:337

Definition at line 18 of file memstream.c.

Referenced by RtlInitMemoryStream().

◆ RtlOutOfProcessMemoryStreamVtbl

const struct IStreamVtbl RtlOutOfProcessMemoryStreamVtbl