1#ifndef INCLUDE_REACTOS_CAPTURE_H
2#define INCLUDE_REACTOS_CAPTURE_H
6#if ! defined(_NTOSKRNL_) && ! defined(_WIN32K_)
7#error Header intended for use by NTOSKRNL/WIN32K only!
15#if defined(_WIN32K_) && !defined(__cplusplus)
22#define ProbeForWriteGenericType(Ptr, Type) \
24 if ((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
25 (ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) { \
26 ExRaiseAccessViolation(); \
28 *(volatile Type *)(Ptr) = *(volatile Type *)(Ptr); \
31#define ProbeForWriteBoolean(Ptr) ProbeForWriteGenericType(Ptr, BOOLEAN)
32#define ProbeForWriteUchar(Ptr) ProbeForWriteGenericType(Ptr, UCHAR)
33#define ProbeForWriteChar(Ptr) ProbeForWriteGenericType(Ptr, CHAR)
34#define ProbeForWriteUshort(Ptr) ProbeForWriteGenericType(Ptr, USHORT)
35#define ProbeForWriteShort(Ptr) ProbeForWriteGenericType(Ptr, SHORT)
36#define ProbeForWriteUlong(Ptr) ProbeForWriteGenericType(Ptr, ULONG)
37#define ProbeForWriteLong(Ptr) ProbeForWriteGenericType(Ptr, LONG)
38#define ProbeForWriteUint(Ptr) ProbeForWriteGenericType(Ptr, UINT)
39#define ProbeForWriteInt(Ptr) ProbeForWriteGenericType(Ptr, INT)
40#define ProbeForWriteUlonglong(Ptr) ProbeForWriteGenericType(Ptr, ULONGLONG)
41#define ProbeForWriteLonglong(Ptr) ProbeForWriteGenericType(Ptr, LONGLONG)
42#define ProbeForWritePointer(Ptr) ProbeForWriteGenericType(Ptr, PVOID)
43#define ProbeForWriteHandle(Ptr) ProbeForWriteGenericType(Ptr, HANDLE)
44#define ProbeForWriteLangId(Ptr) ProbeForWriteGenericType(Ptr, LANGID)
45#define ProbeForWriteSize_t(Ptr) ProbeForWriteGenericType(Ptr, SIZE_T)
46#define ProbeForWriteLargeInteger(Ptr) ProbeForWriteGenericType(&((PLARGE_INTEGER)Ptr)->QuadPart, LONGLONG)
47#define ProbeForWriteUlargeInteger(Ptr) ProbeForWriteGenericType(&((PULARGE_INTEGER)Ptr)->QuadPart, ULONGLONG)
48#define ProbeForWriteUnicodeString(Ptr) ProbeForWriteGenericType((PUNICODE_STRING)Ptr, UNICODE_STRING)
50#define ProbeForWriteLargeString(Ptr) ProbeForWriteGenericType((PLARGE_STRING)Ptr, LARGE_STRING)
52#define ProbeForWriteIoStatusBlock(Ptr) ProbeForWriteGenericType((PIO_STATUS_BLOCK)Ptr, IO_STATUS_BLOCK)
54#define ProbeForReadGenericType(Ptr, Type, Default) \
55 (((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
56 (ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) ? \
57 ExRaiseAccessViolation(), Default : \
58 *(const volatile Type *)(Ptr))
60#define ProbeForReadBoolean(Ptr) ProbeForReadGenericType(Ptr, BOOLEAN, FALSE)
61#define ProbeForReadUchar(Ptr) ProbeForReadGenericType(Ptr, UCHAR, 0)
62#define ProbeForReadChar(Ptr) ProbeForReadGenericType(Ptr, CHAR, 0)
63#define ProbeForReadUshort(Ptr) ProbeForReadGenericType(Ptr, USHORT, 0)
64#define ProbeForReadShort(Ptr) ProbeForReadGenericType(Ptr, SHORT, 0)
65#define ProbeForReadUlong(Ptr) ProbeForReadGenericType(Ptr, ULONG, 0)
66#define ProbeForReadLong(Ptr) ProbeForReadGenericType(Ptr, LONG, 0)
67#define ProbeForReadUint(Ptr) ProbeForReadGenericType(Ptr, UINT, 0)
68#define ProbeForReadInt(Ptr) ProbeForReadGenericType(Ptr, INT, 0)
69#define ProbeForReadUlonglong(Ptr) ProbeForReadGenericType(Ptr, ULONGLONG, 0)
70#define ProbeForReadLonglong(Ptr) ProbeForReadGenericType(Ptr, LONGLONG, 0)
71#define ProbeForReadPointer(Ptr) ProbeForReadGenericType(Ptr, PVOID, NULL)
72#define ProbeForReadHandle(Ptr) ProbeForReadGenericType(Ptr, HANDLE, NULL)
73#define ProbeForReadLangId(Ptr) ProbeForReadGenericType(Ptr, LANGID, 0)
74#define ProbeForReadSize_t(Ptr) ProbeForReadGenericType(Ptr, SIZE_T, 0)
75#define ProbeForReadLargeInteger(Ptr) ProbeForReadGenericType((const LARGE_INTEGER *)(Ptr), LARGE_INTEGER, __emptyLargeInteger)
76#define ProbeForReadUlargeInteger(Ptr) ProbeForReadGenericType((const ULARGE_INTEGER *)(Ptr), ULARGE_INTEGER, __emptyULargeInteger)
77#define ProbeForReadUnicodeString(Ptr) ProbeForReadGenericType((const UNICODE_STRING *)(Ptr), UNICODE_STRING, __emptyUnicodeString)
79#define ProbeForReadLargeString(Ptr) ProbeForReadGenericType((const LARGE_STRING *)(Ptr), LARGE_STRING, __emptyLargeString)
81#define ProbeForReadIoStatusBlock(Ptr) ProbeForReadGenericType((const IO_STATUS_BLOCK *)(Ptr), IO_STATUS_BLOCK, __emptyIoStatusBlock)
83#define ProbeAndZeroHandle(Ptr) \
85 if ((ULONG_PTR)(Ptr) + sizeof(HANDLE) - 1 < (ULONG_PTR)(Ptr) || \
86 (ULONG_PTR)(Ptr) + sizeof(HANDLE) - 1 >= (ULONG_PTR)MmUserProbeAddress) { \
87 ExRaiseAccessViolation(); \
89 *(volatile HANDLE *)(Ptr) = NULL; \
99ProbeArrayForRead(
IN const VOID *ArrayPtr,
108 if (ArraySize /
ItemSize != ItemCount)
129 if (ArraySize /
ItemSize != ItemCount)
161 if(Dest->Buffer !=
NULL)
163 if (Dest->Length != 0)
169 Dest->Length +
sizeof(
WCHAR),
183 if (Dest->Length %
sizeof(
WCHAR))
189 Dest->MaximumLength = Dest->Length;
193 Dest->MaximumLength = Dest->Length +
sizeof(
WCHAR);
199 Dest->MaximumLength = 0;
207 Dest->MaximumLength = 0;
218 Dest->MaximumLength = 0;
247 CapturedString->Length = 0;
248 CapturedString->MaximumLength = 0;
249 CapturedString->Buffer =
NULL;
#define ExAllocatePoolWithTag(hernya, size, tag)
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
#define EXCEPTION_EXECUTE_HANDLER
#define ExFreePoolWithTag(_P, _T)
#define UNICODE_STRING_MAX_BYTES
#define _SEH2_GetExceptionCode()
#define _SEH2_EXCEPT(...)
static __inline NTSTATUS ProbeAndCaptureUnicodeString(OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
static const ULARGE_INTEGER __emptyULargeInteger
static __inline VOID ReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
static const LARGE_INTEGER __emptyLargeInteger
static const IO_STATUS_BLOCK __emptyIoStatusBlock
#define ProbeForReadUnicodeString(Ptr)
static const UNICODE_STRING __emptyUnicodeString
#define _PRAGMA_WARNING_SUPPRESS(x)
#define __WARNING_PROBE_NO_TRY
#define RtlCopyMemory(Destination, Source, Length)
#define STATUS_INVALID_PARAMETER
#define STATUS_INSUFFICIENT_RESOURCES