ReactOS  r76032
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

#define ProbeAndZeroHandle (   Ptr)
Value:
do { \
if ((ULONG_PTR)(Ptr) + sizeof(HANDLE) - 1 < (ULONG_PTR)(Ptr) || \
} \
*(volatile HANDLE *)(Ptr) = NULL; \
} while (0)
ULONG MmUserProbeAddress
Definition: init.c:50
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:557
if(!(yy_init))
Definition: macro.lex.yy.c:704
VOID NTAPI ExRaiseAccessViolation(VOID)
Definition: harderr.c:284
DWORD *typedef HANDLE
Definition: winlogon.h:52

Definition at line 83 of file probe.h.

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

Definition at line 60 of file probe.h.

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

Definition at line 62 of file probe.h.

#define ProbeForReadGenericType (   Ptr,
  Type,
  Default 
)
Value:
(((ULONG_PTR)(Ptr) + sizeof(Type) - 1 < (ULONG_PTR)(Ptr) || \
(ULONG_PTR)(Ptr) + sizeof(Type) - 1 >= (ULONG_PTR)MmUserProbeAddress) ? \
*(const volatile Type *)(Ptr))
ULONG MmUserProbeAddress
Definition: init.c:50
Type
Definition: Type.h:6
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID NTAPI ExRaiseAccessViolation(VOID)
Definition: harderr.c:284
#define ULONG_PTR
Definition: config.h:101

Definition at line 54 of file probe.h.

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

Definition at line 72 of file probe.h.

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

Definition at line 68 of file probe.h.

Definition at line 81 of file probe.h.

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

Definition at line 73 of file probe.h.

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

Definition at line 66 of file probe.h.

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

Definition at line 70 of file probe.h.

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

Definition at line 71 of file probe.h.

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

Definition at line 64 of file probe.h.

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

Definition at line 74 of file probe.h.

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

Definition at line 61 of file probe.h.

Referenced by DetermineSIDSize(), and ExpDebuggerWorker().

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

Definition at line 67 of file probe.h.

Referenced by NtUserRegisterClassExWOW().

Definition at line 76 of file probe.h.

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

Definition at line 65 of file probe.h.

Referenced by NtReadFile(), NtWriteFile(), PsGetContextThread(), and PsSetContextThread().

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

Definition at line 69 of file probe.h.

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

Definition at line 63 of file probe.h.

Referenced by DetermineACLSize().

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

Definition at line 31 of file probe.h.

Referenced by NtCancelTimer(), NtCompareTokens(), NtPrivilegeCheck(), and NtSetTimer().

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

Definition at line 33 of file probe.h.

Referenced by MmProbeAndLockPages().

#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) { \
} \
*(volatile Type *)(Ptr) = *(volatile Type *)(Ptr); \
} while (0)
ULONG MmUserProbeAddress
Definition: init.c:50
Type
Definition: Type.h:6
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
uint32_t ULONG_PTR
Definition: typedefs.h:63
if(!(yy_init))
Definition: macro.lex.yy.c:704
VOID NTAPI ExRaiseAccessViolation(VOID)
Definition: harderr.c:284

Definition at line 22 of file probe.h.

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

Definition at line 39 of file probe.h.

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

Definition at line 37 of file probe.h.

Referenced by NtPulseEvent(), NtReleaseMutant(), NtReleaseSemaphore(), NtResetEvent(), and NtSetEvent().

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

Definition at line 41 of file probe.h.

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

Definition at line 35 of file probe.h.

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

Definition at line 32 of file probe.h.

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

Definition at line 38 of file probe.h.

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

Definition at line 47 of file probe.h.

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

Definition at line 40 of file probe.h.

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

Definition at line 48 of file probe.h.

Referenced by NtQuerySymbolicLinkObject(), and NtUserGetClassName().

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

Definition at line 34 of file probe.h.

Referenced by NtAddAtom(), and NtFindAtom().

Function Documentation

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.

Referenced by NtCloseObjectAuditAlarm(), NtCreatePagingFile(), NtLoadDriver(), NtOpenObjectAuditAlarm(), NtPrivilegedServiceAuditAlarm(), NtQuerySystemEnvironmentValue(), NtSetSystemEnvironmentValue(), NtSetValueKey(), NtUserFindExistingCursorIcon(), NtUserRegisterUserApiHook(), NtUserSetCursorIconData(), NtUserThunkedMenuItemInfo(), and SepAccessCheckAndAuditAlarm().

145 {
147  PWCHAR Buffer = NULL;
148  ASSERT(Dest != NULL);
149 
150  /* Probe the structure and buffer*/
151  if(CurrentMode != KernelMode)
152  {
153  _SEH2_TRY
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  {
174  _SEH2_LEAVE;
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  Dest->MaximumLength = Dest->Length + sizeof(WCHAR);
184  }
185  else
186  {
187  /* Sanitize structure */
188  Dest->MaximumLength = 0;
189  Dest->Buffer = NULL;
190  }
191  }
192  else
193  {
194  /* Sanitize structure */
195  Dest->Length = 0;
196  Dest->MaximumLength = 0;
197  }
198  }
200  {
201  /* Free allocated resources and zero the destination string */
202  if (Buffer != NULL)
203  {
204  ExFreePoolWithTag(Buffer, 'RTSU');
205  }
206  Dest->Length = 0;
207  Dest->MaximumLength = 0;
208  Dest->Buffer = NULL;
209 
210  /* Return the error code */
211  Status = _SEH2_GetExceptionCode();
212  }
213  _SEH2_END;
214  }
215  else
216  {
217  /* Just copy the UNICODE_STRING structure, don't allocate new memory!
218  We trust the caller to supply valid pointers and data. */
219  *Dest = *UnsafeSrc;
220  }
221 
222  /* Return */
223  return Status;
224 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
uint16_t * PWCHAR
Definition: typedefs.h:54
#define WCHAR
Definition: msvc.h:43
#define UNICODE_NULL
#define _SEH2_END
Definition: pseh2_64.h:7
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:557
Definition: bufpool.h:45
UINTN VOID * Buffer
Definition: acefiex.h:370
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
#define _SEH2_LEAVE
Definition: pseh2_64.h:9
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
#define _SEH2_TRY
Definition: pseh2_64.h:5
#define ProbeForReadUnicodeString(Ptr)
Definition: probe.h:77
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1097
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
static __inline VOID ReleaseCapturedUnicodeString ( IN PUNICODE_STRING  CapturedString,
IN KPROCESSOR_MODE  CurrentMode 
)
static

Definition at line 228 of file probe.h.

Referenced by NtCloseObjectAuditAlarm(), NtCreatePagingFile(), NtLoadDriver(), NtOpenObjectAuditAlarm(), NtPrivilegedServiceAuditAlarm(), NtQuerySystemEnvironmentValue(), NtSetSystemEnvironmentValue(), NtSetValueKey(), NtUserFindExistingCursorIcon(), NtUserRegisterUserApiHook(), NtUserSetCursorIconData(), NtUserThunkedMenuItemInfo(), SepAccessCheckAndAuditAlarm(), and UserUnregisterUserApiHook().

230 {
231  if(CurrentMode != KernelMode && CapturedString->Buffer != NULL)
232  {
233  ExFreePoolWithTag(CapturedString->Buffer, 'RTSU');
234  }
235 
236  CapturedString->Length = 0;
237  CapturedString->MaximumLength = 0;
238  CapturedString->Buffer = NULL;
239 }
smooth NULL
Definition: ftsmooth.c:557
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1097

Variable Documentation

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

Definition at line 13 of file probe.h.

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

Definition at line 11 of file probe.h.

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

Definition at line 12 of file probe.h.

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

Definition at line 10 of file probe.h.