ReactOS  0.4.15-dev-499-g1f31905
RtlMemory.c File Reference
#include <stddef.h>
#include <kmt_test.h>
Include dependency graph for RtlMemory.c:

Go to the source code of this file.

Macros

#define KMT_EMULATE_KERNEL
 

Functions

 __declspec (dllimport)
 
static BOOLEAN CheckBuffer (IN const VOID *Buffer,...)
 
static VOID MakePattern (OUT PVOID Buffer,...)
 
static BOOLEAN CheckPattern (IN const VOID *Buffer,...)
 
 START_TEST (RtlMemory)
 

Macro Definition Documentation

◆ KMT_EMULATE_KERNEL

#define KMT_EMULATE_KERNEL

Function Documentation

◆ __declspec()

__declspec ( dllimport  )

Definition at line 9 of file RtlMemory.c.

24 {
25  PUCHAR OutBuffer = Buffer;
26  INT Count;
27  INT Value;
28  va_list Arguments;
29 
30  va_start(Arguments, Buffer);
31 
32  while (1)
33  {
34  Count = va_arg(Arguments, INT);
35  if (!Count)
36  break;
37  ASSERT(Count > 0);
38 
39  Value = va_arg(Arguments, INT);
40  while (Count--)
41  *OutBuffer++ = Value;
42  }
43 
44  va_end(Arguments);
45 }
unsigned char * PUCHAR
Definition: retypes.h:3
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1173
int32_t INT
Definition: typedefs.h:57
IN UCHAR Value
Definition: halp.h:394
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define va_start(ap, A)
Definition: acmsvcex.h:91
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ CheckBuffer()

static BOOLEAN CheckBuffer ( IN const VOID Buffer,
  ... 
)
static

Definition at line 49 of file RtlMemory.c.

52 {
53  CONST UCHAR *OutBuffer = Buffer;
54  INT Count;
55  INT Value;
56  va_list Arguments;
57 
58  va_start(Arguments, Buffer);
59 
60  while (1)
61  {
62  Count = va_arg(Arguments, INT);
63  if (!Count)
64  break;
65  ASSERT(Count > 0);
66 
67  Value = va_arg(Arguments, INT);
68  while (Count--)
69  if (*OutBuffer++ != Value)
70  {
71  --OutBuffer;
72  trace("CheckBuffer failed at offset %d, value %x, expected %x\n", OutBuffer - (CONST UCHAR*)Buffer, *OutBuffer, Value);
73  return FALSE;
74  }
75  }
76 
77  va_end(Arguments);
78  return TRUE;
79 }
#define TRUE
Definition: types.h:120
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1173
int32_t INT
Definition: typedefs.h:57
IN UCHAR Value
Definition: halp.h:394
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
#define trace
Definition: atltest.h:70
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define va_start(ap, A)
Definition: acmsvcex.h:91
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define CONST
Definition: pedump.c:81

Referenced by START_TEST().

◆ CheckPattern()

static BOOLEAN CheckPattern ( IN const VOID Buffer,
  ... 
)
static

Definition at line 117 of file RtlMemory.c.

120 {
121  CONST UCHAR *OutBuffer = Buffer;
122  INT Count, Repeat, i;
123  INT Values[16];
124  va_list Arguments;
125 
126  va_start(Arguments, Buffer);
127 
128  while (1)
129  {
130  Count = va_arg(Arguments, INT);
131  if (!Count)
132  break;
133  ASSERT(Count > 0 && Count < sizeof Values / sizeof Values[0]);
134 
135  Repeat = va_arg(Arguments, INT);
136  ASSERT(Repeat > 0);
137 
138  for (i = 0; i < Count; ++i)
139  Values[i] = va_arg(Arguments, INT);
140 
141  while (Repeat--)
142  for (i = 0; i < Count; ++i)
143  if (*OutBuffer++ != Values[i])
144  {
145  --OutBuffer;
146  trace("CheckPattern failed at offset %d, value %x, expected %x\n", OutBuffer - (CONST UCHAR*)Buffer, *OutBuffer, Values[i]);
147  return FALSE;
148  }
149  }
150 
151  va_end(Arguments);
152  return TRUE;
153 }
#define TRUE
Definition: types.h:120
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1173
int32_t INT
Definition: typedefs.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
#define trace
Definition: atltest.h:70
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
static BOOLEAN Repeat
Definition: dem.c:247
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define va_start(ap, A)
Definition: acmsvcex.h:91
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define CONST
Definition: pedump.c:81

Referenced by START_TEST().

◆ MakePattern()

static VOID MakePattern ( OUT PVOID  Buffer,
  ... 
)
static

Definition at line 83 of file RtlMemory.c.

86 {
87  PUCHAR OutBuffer = Buffer;
88  INT Count, Repeat, i;
89  INT Values[16];
90  va_list Arguments;
91 
92  va_start(Arguments, Buffer);
93 
94  while (1)
95  {
96  Count = va_arg(Arguments, INT);
97  if (!Count)
98  break;
99  ASSERT(Count > 0 && Count < sizeof Values / sizeof Values[0]);
100 
101  Repeat = va_arg(Arguments, INT);
102  ASSERT(Repeat > 0);
103 
104  for (i = 0; i < Count; ++i)
105  Values[i] = va_arg(Arguments, INT);
106 
107  while (Repeat--)
108  for (i = 0; i < Count; ++i)
109  *OutBuffer++ = Values[i];
110  }
111 
112  va_end(Arguments);
113 }
unsigned char * PUCHAR
Definition: retypes.h:3
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1173
int32_t INT
Definition: typedefs.h:57
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static BOOLEAN Repeat
Definition: dem.c:247
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define va_start(ap, A)
Definition: acmsvcex.h:91
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( RtlMemory  )

Definition at line 155 of file RtlMemory.c.

156 {
158  UCHAR Buffer[513];
159  const SIZE_T Size = 512;
160  const SIZE_T HalfSize = Size / 2;
161  SIZE_T RetSize;
162  KIRQL Irql;
163  SIZE_T i;
164 
166  /* zero everything behind 'Size'. Tests will check that this wasn't changed.
167  * TODO: use guarded memory for this! */
168  MakeBuffer(Buffer + Size, sizeof Buffer - Size, 0, 0);
169 
170  /* test our helper functions first */
171  MakeBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 0);
172  for (i = 0; i < HalfSize; ++i)
173  ok_eq_uint(Buffer[i], 0x55);
174  for (i = HalfSize; i < Size; ++i)
175  ok_eq_uint(Buffer[i], 0xAA);
176  ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
177 
178  MakePattern(Buffer, 3, 20, 0x11, 0x22, 0x33, 1, 4, 0x44, 0);
179  for (i = 0; i < 60; i += 3)
180  {
181  ok_eq_uint(Buffer[i+0], 0x11);
182  ok_eq_uint(Buffer[i+1], 0x22);
183  ok_eq_uint(Buffer[i+2], 0x33);
184  }
185  for (i = 60; i < 64; ++i)
186  ok_eq_uint(Buffer[i], 0x44);
187  for (i = 64; i < HalfSize; ++i)
188  ok_eq_uint(Buffer[i], 0x55);
189  for (i = HalfSize; i < Size; ++i)
190  ok_eq_uint(Buffer[i], 0xAA);
191  ok_bool_true(CheckPattern(Buffer, 3, 20, 0x11, 0x22, 0x33, 1, 4, 0x44, 0), "CheckPattern");
192 
193  /* RtlMoveMemory */
194  MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
195  RtlMoveMemory(Buffer + 13, Buffer + 62, 95);
196  ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
197 
198  MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
199  RtlMoveMemory(Buffer + 78, Buffer + 43, 107);
200  ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
201 
202  KeLowerIrql(Irql);
204  _SEH2_TRY {
205  RtlMoveMemory(NULL, NULL, 0);
208  } _SEH2_END;
211 
212 #undef RtlMoveMemory
213  /* RtlMoveMemory export */
214  MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
215  RtlMoveMemory(Buffer + 13, Buffer + 62, 95);
216  ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
217 
218  MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
219  RtlMoveMemory(Buffer + 78, Buffer + 43, 107);
220  ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
221 
222  KeLowerIrql(Irql);
224  _SEH2_TRY {
225  RtlMoveMemory(NULL, NULL, 0);
228  } _SEH2_END;
231 
232  /* RtlCopyMemory */
233  MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
234  RtlCopyMemory(Buffer + 13, Buffer + 62, 95);
235  ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
236 
237  MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
238  RtlCopyMemory(Buffer + 78, Buffer + 43, 107);
239  ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
240 
241  KeLowerIrql(Irql);
243  _SEH2_TRY {
244  RtlCopyMemory(NULL, NULL, 0);
247  } _SEH2_END;
250 
251  /* RtlCopyMemoryNonTemporal */
252  MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
253  RtlCopyMemoryNonTemporal(Buffer + 13, Buffer + 62, 95);
254  ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
255 
256  MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
257  RtlCopyMemoryNonTemporal(Buffer + 78, Buffer + 43, 107);
258  ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
259 
260  KeLowerIrql(Irql);
262  _SEH2_TRY {
266  } _SEH2_END;
269 
270  /* RtlCopyBytes */
271  MakePattern(Buffer, 2, 64, 0x12, 0x34, 2, 192, 0x56, 0x78, 0);
272  RtlCopyBytes(Buffer + 13, Buffer + 62, 95);
273  ok_bool_true(CheckPattern(Buffer, 2, 6, 0x12, 0x34, 1, 1, 0x12, 2, 33, 0x12, 0x34, 2, 14, 0x56, 0x78, 1, 1, 0x56, 2, 10, 0x12, 0x34, 2, 192, 0x56, 0x78, 1, 1, 0, 0), "CheckPattern");
274 
275  MakePattern(Buffer, 2, 32, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 192, 0x9A, 0xAB, 0);
276  RtlCopyBytes(Buffer + 78, Buffer + 43, 107);
277  ok_bool_true(CheckPattern(Buffer, 2, 32, 0x12, 0x34, 2, 7, 0x56, 0x78, 1, 1, 0x34, 2, 10, 0x12, 0x34, 2, 32, 0x56, 0x78, 2, 11, 0x9A, 0xAB, 1, 1, 0xAB, 2, 163, 0x9A, 0xAB, 1, 1, 0, 0), "CheckPattern");
278 
279  KeLowerIrql(Irql);
281  _SEH2_TRY {
282  RtlCopyBytes(NULL, NULL, 0);
285  } _SEH2_END;
288 
289  /* RtlEqualMemory */
290  MakePattern(Buffer, 8, HalfSize / 8 - 1, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
291  1, 1, 0x12,
292  8, HalfSize / 8, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
293  1, 7, 0x12, 0);
294 
296  "RtlEqualMemory returned");
297  ok_bool_true(RtlEqualMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8),
298  "RtlEqualMemory returned");
299  ok_bool_true(RtlEqualMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 1),
300  "RtlEqualMemory returned");
301  ok_bool_false(RtlEqualMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 2),
302  "RtlEqualMemory returned");
303 
304  /* RtlCompareMemory */
305  MakePattern(Buffer, 8, HalfSize / 8 - 1, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
306  1, 1, 0x12,
307  8, HalfSize / 8, 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
308  1, 7, 0x12, 0);
309 
310  RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8);
311  ok_eq_size(RetSize, HalfSize - 8);
312  RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 1);
313  ok_eq_size(RetSize, HalfSize - 8 + 1);
314  RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, HalfSize - 8 + 2);
315  ok_eq_size(RetSize, HalfSize - 8 + 1);
316 
317  KeLowerIrql(Irql);
319  _SEH2_TRY {
320  RetSize = RtlCompareMemory(Buffer, Buffer + HalfSize - 7, SIZE_MAX);
321  ok_eq_size(RetSize, HalfSize - 8 + 1);
322  RetSize = RtlCompareMemory(NULL, NULL, 0);
323  ok_eq_size(RetSize, 0);
326  } _SEH2_END;
329 
330  /* RtlCompareMemoryUlong */
331  MakeBuffer(Buffer, 8, 0x55, Size - 8, 0, 0);
332  RetSize = RtlCompareMemoryUlong(Buffer, sizeof(ULONG), 0x55555555LU);
333  ok_eq_size(RetSize, 4);
334  RetSize = RtlCompareMemoryUlong(Buffer + 1, sizeof(ULONG), 0x55555555LU);
335  ok_eq_size(RetSize, 4);
336  RetSize = RtlCompareMemoryUlong(Buffer + 2, sizeof(ULONG), 0x55555555LU);
337  ok_eq_size(RetSize, 4);
338  RetSize = RtlCompareMemoryUlong(Buffer + 3, sizeof(ULONG), 0x55555555LU);
339  ok_eq_size(RetSize, 4);
340  RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x55555555LU);
341  ok_eq_size(RetSize, 0);
342  RetSize = RtlCompareMemoryUlong(Buffer + 5, sizeof(ULONG), 0x00555555LU);
343  ok_eq_size(RetSize, 4);
344  RetSize = RtlCompareMemoryUlong(Buffer, 1, 0x55555555LU);
345  ok_eq_size(RetSize, 0);
346  RetSize = RtlCompareMemoryUlong(Buffer, 2, 0x55555555LU);
347  ok_eq_size(RetSize, 0);
348  RetSize = RtlCompareMemoryUlong(Buffer, 3, 0x55555555LU);
349  ok_eq_size(RetSize, 0);
350  RetSize = RtlCompareMemoryUlong(Buffer, 5, 0x55555555LU);
351  ok_eq_size(RetSize, 4);
352 
353  KeLowerIrql(Irql);
355  _SEH2_TRY {
356  RetSize = RtlCompareMemoryUlong(NULL, 0, 0x55555555LU);
357  ok_eq_size(RetSize, 0);
360  } _SEH2_END;
363 
364  /* RtlZeroMemory */
365  MakeBuffer(Buffer, Size, 0x11, 0);
366  RtlZeroMemory(Buffer, 1);
367  ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
368  Buffer[0] = 0x11;
369  RtlZeroMemory(Buffer, Size - 1);
370  ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
371 
372  KeLowerIrql(Irql);
374  _SEH2_TRY {
375  RtlZeroMemory(NULL, 0);
378  } _SEH2_END;
381 
382  /* RtlSecureZeroMemory */
383  MakeBuffer(Buffer, Size, 0x11, 0);
385  ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
386  Buffer[0] = 0x11;
388  ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
389 
390  KeLowerIrql(Irql);
392  _SEH2_TRY {
396  } _SEH2_END;
399 
400  /* RtlZeroBytes */
401  MakeBuffer(Buffer, Size, 0x11, 0);
402  RtlZeroBytes(Buffer, 1);
403  ok_bool_true(CheckBuffer(Buffer, 1, 0, Size - 1, 0x11, 1, 0, 0), "CheckBuffer");
404  Buffer[0] = 0x11;
405  RtlZeroBytes(Buffer, Size - 1);
406  ok_bool_true(CheckBuffer(Buffer, Size - 1, 0, 1, 0x11, 1, 0, 0), "CheckBuffer");
407 
408  KeLowerIrql(Irql);
410  _SEH2_TRY {
411  RtlZeroBytes(NULL, 0);
414  } _SEH2_END;
417 
418  /* RtlFillMemory */
419  MakeBuffer(Buffer, Size, 0, 0);
420  RtlFillMemory(Buffer, HalfSize, 0x55);
421  RtlFillMemory(Buffer + HalfSize, HalfSize, 0xAA);
422  ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
423  RtlFillMemory(Buffer + 3, 7, 0x88);
424  ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
425 
426  KeLowerIrql(Irql);
428  _SEH2_TRY {
429 #if defined(__GNUC__) && __GNUC__ >= 5
430 #pragma GCC diagnostic push
431 #pragma GCC diagnostic ignored "-Wmemset-transposed-args"
432 #endif
433  RtlFillMemory(NULL, 0, 0x55);
434 #if defined(__GNUC__) && __GNUC__ >= 5
435 #pragma GCC diagnostic pop
436 #endif
439  } _SEH2_END;
442 
443 #undef RtlFillMemory
444  /* RtlFillMemory export */
445  MakeBuffer(Buffer, Size, 0, 0);
446  RtlFillMemory(Buffer, HalfSize, 0x55);
447  RtlFillMemory(Buffer + HalfSize, HalfSize, 0xAA);
448  ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
449  RtlFillMemory(Buffer + 3, 7, 0x88);
450  ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
451 
452  KeLowerIrql(Irql);
454  _SEH2_TRY {
455  RtlFillMemory(NULL, 0, 0x55);
458  } _SEH2_END;
461 
462  /* TODO: fix NDK. This should work! */
463 #if !defined _M_AMD64 || defined KMT_KERNEL_MODE
464  /* RtlFillMemoryUlong */
465  MakeBuffer(Buffer, Size, 0, 0);
466  RtlFillMemoryUlong(Buffer, HalfSize, 0x01234567LU);
467  RtlFillMemoryUlong(Buffer + HalfSize, HalfSize, 0x89ABCDEFLU);
468  ok_bool_true(CheckPattern(Buffer, 4, HalfSize / 4, 0x67, 0x45, 0x23, 0x01, 4, HalfSize / 4, 0xEF, 0xCD, 0xAB, 0x89, 1, 1, 0, 0), "CheckPattern");
469 
470  KeLowerIrql(Irql);
472  _SEH2_TRY {
473  MakeBuffer(Buffer, Size, 0, 0);
474  RtlFillMemoryUlong(Buffer + 1, sizeof(ULONG), 0xAAAAAAAALU);
475  ok_bool_true(CheckBuffer(Buffer, 1, 0, sizeof(ULONG), 0xAA, Size - sizeof(ULONG) - 1, 0, 1, 0, 0), "CheckBuffer");
476 
477  RtlFillMemoryUlong(NULL, 0, 0x55555555LU);
480  } _SEH2_END;
483 #endif
484 
485  /* RtlFillMemoryUlonglong */
486  /* TODO: this function doesn't exist in 2k3/x86? wdm.h error? */
487 
488  /* RtlFillBytes */
489  MakeBuffer(Buffer, Size, 0, 0);
490  RtlFillBytes(Buffer, HalfSize, 0x55);
491  RtlFillBytes(Buffer + HalfSize, HalfSize, 0xAA);
492  ok_bool_true(CheckBuffer(Buffer, HalfSize, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
493  RtlFillBytes(Buffer + 3, 7, 0x88);
494  ok_bool_true(CheckBuffer(Buffer, 3, 0x55, 7, 0x88, HalfSize - 10, 0x55, HalfSize, 0xAA, 1, 0, 0), "CheckBuffer");
495 
496  KeLowerIrql(Irql);
498  _SEH2_TRY {
499  RtlFillBytes(NULL, 0, 0x55);
502  } _SEH2_END;
505 
506  /* RtlPrefetchMemoryNonTemporal */
508 
509  KeLowerIrql(Irql);
511  _SEH2_TRY {
515  } _SEH2_END;
518 
519  KeLowerIrql(Irql);
520 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
_Must_inspect_result_ NTSYSAPI SIZE_T NTAPI RtlCompareMemoryUlong(_In_reads_bytes_(Length) PVOID Source, _In_ SIZE_T Length, _In_ ULONG Pattern)
#define ok_eq_size(value, expected)
Definition: kmt_test.h:247
LONG NTSTATUS
Definition: precomp.h:26
#define RtlCopyMemoryNonTemporal
Definition: rtlfuncs.h:293
#define RtlZeroBytes
Definition: rtlfuncs.h:383
_Out_ PKIRQL Irql
Definition: csq.h:179
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_SEH2_TRY
Definition: create.c:4226
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
#define RtlCopyBytes
Definition: rtlfuncs.h:282
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOLEAN CheckBuffer(IN const VOID *Buffer,...)
Definition: RtlMemory.c:49
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define SIZE_MAX
Definition: asmshader.yy.c:347
Definition: bufpool.h:45
#define RtlFillMemoryUlong(dst, len, val)
Definition: mkhive.h:55
static VOID MakePattern(OUT PVOID Buffer,...)
Definition: RtlMemory.c:83
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
unsigned char UCHAR
Definition: xmlstorage.h:181
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
Status
Definition: gdiplustypes.h:24
static BOOLEAN CheckPattern(IN const VOID *Buffer,...)
Definition: RtlMemory.c:117
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
_SEH2_END
Definition: create.c:4400
unsigned int ULONG
Definition: retypes.h:1
#define RtlFillBytes
Definition: rtlfuncs.h:322
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ok_eq_hex(value, expected)
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
return STATUS_SUCCESS
Definition: btrfs.c:3014
FORCEINLINE PVOID RtlSecureZeroMemory(_Out_writes_bytes_all_(Size) PVOID Pointer, _In_ SIZE_T Size)
Definition: rtlfuncs.h:3127
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
VOID FASTCALL RtlPrefetchMemoryNonTemporal(IN PVOID Source, IN SIZE_T Length)
Definition: misc.c:71