ReactOS 0.4.15-dev-5666-gc548b97
probe.h File Reference
#include <suppress.h>
Include dependency graph for probe.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ProbeForWriteGenericType(Ptr, Type)
 
#define ProbeForWriteBoolean(Ptr)   ProbeForWriteGenericType(Ptr, BOOLEAN)
 
#define ProbeForWriteUchar(Ptr)   ProbeForWriteGenericType(Ptr, UCHAR)
 
#define ProbeForWriteChar(Ptr)   ProbeForWriteGenericType(Ptr, CHAR)
 
#define ProbeForWriteUshort(Ptr)   ProbeForWriteGenericType(Ptr, USHORT)
 
#define ProbeForWriteShort(Ptr)   ProbeForWriteGenericType(Ptr, SHORT)
 
#define ProbeForWriteUlong(Ptr)   ProbeForWriteGenericType(Ptr, ULONG)
 
#define ProbeForWriteLong(Ptr)   ProbeForWriteGenericType(Ptr, LONG)
 
#define ProbeForWriteUint(Ptr)   ProbeForWriteGenericType(Ptr, UINT)
 
#define ProbeForWriteInt(Ptr)   ProbeForWriteGenericType(Ptr, INT)
 
#define ProbeForWriteUlonglong(Ptr)   ProbeForWriteGenericType(Ptr, ULONGLONG)
 
#define ProbeForWriteLonglong(Ptr)   ProbeForWriteGenericType(Ptr, LONGLONG)
 
#define ProbeForWritePointer(Ptr)   ProbeForWriteGenericType(Ptr, PVOID)
 
#define ProbeForWriteHandle(Ptr)   ProbeForWriteGenericType(Ptr, HANDLE)
 
#define ProbeForWriteLangId(Ptr)   ProbeForWriteGenericType(Ptr, LANGID)
 
#define ProbeForWriteSize_t(Ptr)   ProbeForWriteGenericType(Ptr, SIZE_T)
 
#define ProbeForWriteLargeInteger(Ptr)   ProbeForWriteGenericType(&((PLARGE_INTEGER)Ptr)->QuadPart, LONGLONG)
 
#define ProbeForWriteUlargeInteger(Ptr)   ProbeForWriteGenericType(&((PULARGE_INTEGER)Ptr)->QuadPart, ULONGLONG)
 
#define ProbeForWriteUnicodeString(Ptr)   ProbeForWriteGenericType((PUNICODE_STRING)Ptr, UNICODE_STRING)
 
#define ProbeForWriteIoStatusBlock(Ptr)   ProbeForWriteGenericType((PIO_STATUS_BLOCK)Ptr, IO_STATUS_BLOCK)
 
#define ProbeForReadGenericType(Ptr, Type, Default)
 
#define ProbeForReadBoolean(Ptr)   ProbeForReadGenericType(Ptr, BOOLEAN, FALSE)
 
#define ProbeForReadUchar(Ptr)   ProbeForReadGenericType(Ptr, UCHAR, 0)
 
#define ProbeForReadChar(Ptr)   ProbeForReadGenericType(Ptr, CHAR, 0)
 
#define ProbeForReadUshort(Ptr)   ProbeForReadGenericType(Ptr, USHORT, 0)
 
#define ProbeForReadShort(Ptr)   ProbeForReadGenericType(Ptr, SHORT, 0)
 
#define ProbeForReadUlong(Ptr)   ProbeForReadGenericType(Ptr, ULONG, 0)
 
#define ProbeForReadLong(Ptr)   ProbeForReadGenericType(Ptr, LONG, 0)
 
#define ProbeForReadUint(Ptr)   ProbeForReadGenericType(Ptr, UINT, 0)
 
#define ProbeForReadInt(Ptr)   ProbeForReadGenericType(Ptr, INT, 0)
 
#define ProbeForReadUlonglong(Ptr)   ProbeForReadGenericType(Ptr, ULONGLONG, 0)
 
#define ProbeForReadLonglong(Ptr)   ProbeForReadGenericType(Ptr, LONGLONG, 0)
 
#define ProbeForReadPointer(Ptr)   ProbeForReadGenericType(Ptr, PVOID, NULL)
 
#define ProbeForReadHandle(Ptr)   ProbeForReadGenericType(Ptr, HANDLE, NULL)
 
#define ProbeForReadLangId(Ptr)   ProbeForReadGenericType(Ptr, LANGID, 0)
 
#define ProbeForReadSize_t(Ptr)   ProbeForReadGenericType(Ptr, SIZE_T, 0)
 
#define ProbeForReadLargeInteger(Ptr)   ProbeForReadGenericType((const LARGE_INTEGER *)(Ptr), LARGE_INTEGER, __emptyLargeInteger)
 
#define ProbeForReadUlargeInteger(Ptr)   ProbeForReadGenericType((const ULARGE_INTEGER *)(Ptr), ULARGE_INTEGER, __emptyULargeInteger)
 
#define ProbeForReadUnicodeString(Ptr)   ProbeForReadGenericType((const UNICODE_STRING *)(Ptr), UNICODE_STRING, __emptyUnicodeString)
 
#define ProbeForReadIoStatusBlock(Ptr)   ProbeForReadGenericType((const IO_STATUS_BLOCK *)(Ptr), IO_STATUS_BLOCK, __emptyIoStatusBlock)
 
#define ProbeAndZeroHandle(Ptr)
 

Functions

static __inline NTSTATUS ProbeAndCaptureUnicodeString (OUT PUNICODE_STRING Dest, IN KPROCESSOR_MODE CurrentMode, IN const UNICODE_STRING *UnsafeSrc)
 
static __inline VOID ReleaseCapturedUnicodeString (IN PUNICODE_STRING CapturedString, IN KPROCESSOR_MODE CurrentMode)
 

Variables

static const UNICODE_STRING __emptyUnicodeString = {0, 0, NULL}
 
static const LARGE_INTEGER __emptyLargeInteger = {{0, 0}}
 
static const ULARGE_INTEGER __emptyULargeInteger = {{0, 0}}
 
static const IO_STATUS_BLOCK __emptyIoStatusBlock = {{0}, 0}
 

Macro Definition Documentation

◆ ProbeAndZeroHandle

#define ProbeAndZeroHandle (   Ptr)
Value:
do { \
if ((ULONG_PTR)(Ptr) + sizeof(HANDLE) - 1 < (ULONG_PTR)(Ptr) || \
(ULONG_PTR)(Ptr) + sizeof(HANDLE) - 1 >= (ULONG_PTR)MmUserProbeAddress) { \
ExRaiseAccessViolation(); \
} \
*(volatile HANDLE *)(Ptr) = NULL; \
} while (0)
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
ULONG MmUserProbeAddress
Definition: init.c:50
uint32_t ULONG_PTR
Definition: typedefs.h:65

Definition at line 83 of file probe.h.

◆ ProbeForReadBoolean

#define ProbeForReadBoolean (   Ptr)    ProbeForReadGenericType(Ptr, BOOLEAN, FALSE)

Definition at line 60 of file probe.h.

◆ ProbeForReadChar

#define ProbeForReadChar (   Ptr)    ProbeForReadGenericType(Ptr, CHAR, 0)

Definition at line 62 of file probe.h.

◆ ProbeForReadGenericType

#define ProbeForReadGenericType (   Ptr,
  Type,
  Default 
)
Value:
(((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
(ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) ? \
ExRaiseAccessViolation(), Default : \
*(const volatile Type *)(Ptr))
Type
Definition: Type.h:7
#define ULONG_PTR
Definition: config.h:101

Definition at line 54 of file probe.h.

◆ ProbeForReadHandle

#define ProbeForReadHandle (   Ptr)    ProbeForReadGenericType(Ptr, HANDLE, NULL)

Definition at line 72 of file probe.h.

◆ ProbeForReadInt

#define ProbeForReadInt (   Ptr)    ProbeForReadGenericType(Ptr, INT, 0)

Definition at line 68 of file probe.h.

◆ ProbeForReadIoStatusBlock

Definition at line 81 of file probe.h.

◆ ProbeForReadLangId

#define ProbeForReadLangId (   Ptr)    ProbeForReadGenericType(Ptr, LANGID, 0)

Definition at line 73 of file probe.h.

◆ ProbeForReadLargeInteger

Definition at line 75 of file probe.h.

◆ ProbeForReadLong

#define ProbeForReadLong (   Ptr)    ProbeForReadGenericType(Ptr, LONG, 0)

Definition at line 66 of file probe.h.

◆ ProbeForReadLonglong

#define ProbeForReadLonglong (   Ptr)    ProbeForReadGenericType(Ptr, LONGLONG, 0)

Definition at line 70 of file probe.h.

◆ ProbeForReadPointer

#define ProbeForReadPointer (   Ptr)    ProbeForReadGenericType(Ptr, PVOID, NULL)

Definition at line 71 of file probe.h.

◆ ProbeForReadShort

#define ProbeForReadShort (   Ptr)    ProbeForReadGenericType(Ptr, SHORT, 0)

Definition at line 64 of file probe.h.

◆ ProbeForReadSize_t

#define ProbeForReadSize_t (   Ptr)    ProbeForReadGenericType(Ptr, SIZE_T, 0)

Definition at line 74 of file probe.h.

◆ ProbeForReadUchar

#define ProbeForReadUchar (   Ptr)    ProbeForReadGenericType(Ptr, UCHAR, 0)

Definition at line 61 of file probe.h.

◆ ProbeForReadUint

#define ProbeForReadUint (   Ptr)    ProbeForReadGenericType(Ptr, UINT, 0)

Definition at line 67 of file probe.h.

◆ ProbeForReadUlargeInteger

Definition at line 76 of file probe.h.

◆ ProbeForReadUlong

#define ProbeForReadUlong (   Ptr)    ProbeForReadGenericType(Ptr, ULONG, 0)

Definition at line 65 of file probe.h.

◆ ProbeForReadUlonglong

#define ProbeForReadUlonglong (   Ptr)    ProbeForReadGenericType(Ptr, ULONGLONG, 0)

Definition at line 69 of file probe.h.

◆ ProbeForReadUnicodeString

Definition at line 77 of file probe.h.

◆ ProbeForReadUshort

#define ProbeForReadUshort (   Ptr)    ProbeForReadGenericType(Ptr, USHORT, 0)

Definition at line 63 of file probe.h.

◆ ProbeForWriteBoolean

#define ProbeForWriteBoolean (   Ptr)    ProbeForWriteGenericType(Ptr, BOOLEAN)

Definition at line 31 of file probe.h.

◆ ProbeForWriteChar

#define ProbeForWriteChar (   Ptr)    ProbeForWriteGenericType(Ptr, CHAR)

Definition at line 33 of file probe.h.

◆ ProbeForWriteGenericType

#define ProbeForWriteGenericType (   Ptr,
  Type 
)
Value:
do { \
if ((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
(ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) { \
ExRaiseAccessViolation(); \
} \
*(volatile Type *)(Ptr) = *(volatile Type *)(Ptr); \
} while (0)

Definition at line 22 of file probe.h.

◆ ProbeForWriteHandle

#define ProbeForWriteHandle (   Ptr)    ProbeForWriteGenericType(Ptr, HANDLE)

Definition at line 43 of file probe.h.

◆ ProbeForWriteInt

#define ProbeForWriteInt (   Ptr)    ProbeForWriteGenericType(Ptr, INT)

Definition at line 39 of file probe.h.

◆ ProbeForWriteIoStatusBlock

#define ProbeForWriteIoStatusBlock (   Ptr)    ProbeForWriteGenericType((PIO_STATUS_BLOCK)Ptr, IO_STATUS_BLOCK)

Definition at line 52 of file probe.h.

◆ ProbeForWriteLangId

#define ProbeForWriteLangId (   Ptr)    ProbeForWriteGenericType(Ptr, LANGID)

Definition at line 44 of file probe.h.

◆ ProbeForWriteLargeInteger

#define ProbeForWriteLargeInteger (   Ptr)    ProbeForWriteGenericType(&((PLARGE_INTEGER)Ptr)->QuadPart, LONGLONG)

Definition at line 46 of file probe.h.

◆ ProbeForWriteLong

#define ProbeForWriteLong (   Ptr)    ProbeForWriteGenericType(Ptr, LONG)

Definition at line 37 of file probe.h.

◆ ProbeForWriteLonglong

#define ProbeForWriteLonglong (   Ptr)    ProbeForWriteGenericType(Ptr, LONGLONG)

Definition at line 41 of file probe.h.

◆ ProbeForWritePointer

#define ProbeForWritePointer (   Ptr)    ProbeForWriteGenericType(Ptr, PVOID)

Definition at line 42 of file probe.h.

◆ ProbeForWriteShort

#define ProbeForWriteShort (   Ptr)    ProbeForWriteGenericType(Ptr, SHORT)

Definition at line 35 of file probe.h.

◆ ProbeForWriteSize_t

#define ProbeForWriteSize_t (   Ptr)    ProbeForWriteGenericType(Ptr, SIZE_T)

Definition at line 45 of file probe.h.

◆ ProbeForWriteUchar

#define ProbeForWriteUchar (   Ptr)    ProbeForWriteGenericType(Ptr, UCHAR)

Definition at line 32 of file probe.h.

◆ ProbeForWriteUint

#define ProbeForWriteUint (   Ptr)    ProbeForWriteGenericType(Ptr, UINT)

Definition at line 38 of file probe.h.

◆ ProbeForWriteUlargeInteger

#define ProbeForWriteUlargeInteger (   Ptr)    ProbeForWriteGenericType(&((PULARGE_INTEGER)Ptr)->QuadPart, ULONGLONG)

Definition at line 47 of file probe.h.

◆ ProbeForWriteUlong

#define ProbeForWriteUlong (   Ptr)    ProbeForWriteGenericType(Ptr, ULONG)

Definition at line 36 of file probe.h.

◆ ProbeForWriteUlonglong

#define ProbeForWriteUlonglong (   Ptr)    ProbeForWriteGenericType(Ptr, ULONGLONG)

Definition at line 40 of file probe.h.

◆ ProbeForWriteUnicodeString

#define ProbeForWriteUnicodeString (   Ptr)    ProbeForWriteGenericType((PUNICODE_STRING)Ptr, UNICODE_STRING)

Definition at line 48 of file probe.h.

◆ ProbeForWriteUshort

#define ProbeForWriteUshort (   Ptr)    ProbeForWriteGenericType(Ptr, USHORT)

Definition at line 34 of file probe.h.

Function Documentation

◆ ProbeAndCaptureUnicodeString()

static __inline NTSTATUS ProbeAndCaptureUnicodeString ( OUT PUNICODE_STRING  Dest,
IN KPROCESSOR_MODE  CurrentMode,
IN const UNICODE_STRING UnsafeSrc 
)
static

Definition at line 142 of file probe.h.

145{
148 ASSERT(Dest != NULL);
149
150 /* Probe the structure and buffer*/
151 if(CurrentMode != KernelMode)
152 {
154 {
155#ifdef __cplusplus
156 ProbeForRead(UnsafeSrc, sizeof(*UnsafeSrc), 1);
157 RtlCopyMemory(Dest, UnsafeSrc, sizeof(*UnsafeSrc));
158#else
159 *Dest = ProbeForReadUnicodeString(UnsafeSrc);
160#endif
161 if(Dest->Buffer != NULL)
162 {
163 if (Dest->Length != 0)
164 {
165 ProbeForRead(Dest->Buffer, Dest->Length, sizeof(WCHAR));
166
167 /* Allocate space for the buffer */
169 Dest->Length + sizeof(WCHAR),
170 'RTSU');
171 if (Buffer == NULL)
172 {
175 }
176
177 /* Copy it */
178 RtlCopyMemory(Buffer, Dest->Buffer, Dest->Length);
179 Buffer[Dest->Length / sizeof(WCHAR)] = UNICODE_NULL;
180
181 /* Set it as the buffer */
182 Dest->Buffer = Buffer;
183 if (Dest->Length % sizeof(WCHAR))
184 {
185 Dest->Length--;
186 }
187 if (Dest->Length >= UNICODE_STRING_MAX_BYTES)
188 {
189 Dest->MaximumLength = Dest->Length;
190 }
191 else
192 {
193 Dest->MaximumLength = Dest->Length + sizeof(WCHAR);
194 }
195 }
196 else
197 {
198 /* Sanitize structure */
199 Dest->MaximumLength = 0;
200 Dest->Buffer = NULL;
201 }
202 }
203 else
204 {
205 /* Sanitize structure */
206 Dest->Length = 0;
207 Dest->MaximumLength = 0;
208 }
209 }
211 {
212 /* Free allocated resources and zero the destination string */
213 if (Buffer != NULL)
214 {
215 ExFreePoolWithTag(Buffer, 'RTSU');
216 }
217 Dest->Length = 0;
218 Dest->MaximumLength = 0;
219 Dest->Buffer = NULL;
220
221 /* Return the error code */
223 }
224 _SEH2_END;
225 }
226 else
227 {
228 /* Just copy the UNICODE_STRING structure, don't allocate new memory!
229 We trust the caller to supply valid pointers and data. */
230 *Dest = *UnsafeSrc;
231 }
232
233 /* Return */
234 return Status;
235}
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define _SEH2_LEAVE
Definition: filesup.c:20
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define KernelMode
Definition: asm.h:34
#define UNICODE_NULL
#define UNICODE_STRING_MAX_BYTES
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
#define STATUS_SUCCESS
Definition: shellext.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by IopUnloadDriver(), NtCloseObjectAuditAlarm(), NtDeleteValueKey(), NtDisplayString(), NtLoadDriver(), NtOpenObjectAuditAlarm(), NtPrivilegedServiceAuditAlarm(), NtQuerySystemEnvironmentValue(), NtQueryValueKey(), NtSetSystemEnvironmentValue(), NtSetValueKey(), NtUserFindExistingCursorIcon(), NtUserRegisterUserApiHook(), NtUserResolveDesktop(), NtUserSetCursorIconData(), NtUserThunkedMenuItemInfo(), ProbeAndCaptureObjectAttributes(), and SepAccessCheckAndAuditAlarm().

◆ ReleaseCapturedUnicodeString()

static __inline VOID ReleaseCapturedUnicodeString ( IN PUNICODE_STRING  CapturedString,
IN KPROCESSOR_MODE  CurrentMode 
)
static

Variable Documentation

◆ __emptyIoStatusBlock

const IO_STATUS_BLOCK __emptyIoStatusBlock = {{0}, 0}
static

Definition at line 13 of file probe.h.

◆ __emptyLargeInteger

const LARGE_INTEGER __emptyLargeInteger = {{0, 0}}
static

Definition at line 11 of file probe.h.

◆ __emptyULargeInteger

const ULARGE_INTEGER __emptyULargeInteger = {{0, 0}}
static

Definition at line 12 of file probe.h.

◆ __emptyUnicodeString

const UNICODE_STRING __emptyUnicodeString = {0, 0, NULL}
static

Definition at line 10 of file probe.h.