ReactOS  0.4.15-dev-3440-g915569a
NtAllocateVirtualMemory.c File Reference
#include "precomp.h"
#include <pseh/pseh2.h>
Include dependency graph for NtAllocateVirtualMemory.c:

Go to the source code of this file.

Macros

#define RUNS   32
 

Functions

static VOID ValidateAllocations (VOID)
 
static PVOID Allocate (SIZE_T DataSize)
 
static VOID Free (PVOID UserBuffer)
 
static PVOID ReAllocate (PVOID OldUserBuffer, SIZE_T NewDataSize)
 
static VOID AccessMemory1 (PVOID UserBuffer, SIZE_T DataSize)
 
static BOOLEAN CheckMemory1 (PVOID UserBuffer, SIZE_T DataSize)
 
static VOID AccessMemory2 (PVOID UserBuffer, SIZE_T DataSize)
 
static BOOLEAN CheckMemory2 (PVOID UserBuffer, SIZE_T DataSize)
 
VOID CheckSize (ULONG_PTR Base, SIZE_T InSize, SIZE_T ExpectedSize)
 
VOID CheckAlignment ()
 
static VOID CheckAdjacentVADs ()
 
static VOID CheckSomeDefaultAddresses (VOID)
 
 START_TEST (NtAllocateVirtualMemory)
 

Variables

static PVOID Allocations [4096] = { NULL }
 
static ULONG CurrentAllocation = 0
 

Macro Definition Documentation

◆ RUNS

#define RUNS   32

Definition at line 747 of file NtAllocateVirtualMemory.c.

Function Documentation

◆ AccessMemory1()

static VOID AccessMemory1 ( PVOID  UserBuffer,
SIZE_T  DataSize 
)
static

Definition at line 143 of file NtAllocateVirtualMemory.c.

146 {
147  PBYTE Buffer = UserBuffer;
148  SIZE_T i;
149 
150  for (i = 0; i < DataSize; ++i)
151  Buffer[i] = LOBYTE(i);
152 }
#define LOBYTE(W)
Definition: jmemdos.c:487
Definition: bufpool.h:45
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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
BYTE * PBYTE
Definition: pedump.c:66
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by START_TEST().

◆ AccessMemory2()

static VOID AccessMemory2 ( PVOID  UserBuffer,
SIZE_T  DataSize 
)
static

Definition at line 175 of file NtAllocateVirtualMemory.c.

178 {
179  PBYTE Buffer = UserBuffer;
180  SIZE_T i;
181 
182  for (i = 0; i < DataSize; ++i)
183  Buffer[i] = UCHAR_MAX - LOBYTE(i);
184 }
#define LOBYTE(W)
Definition: jmemdos.c:487
Definition: bufpool.h:45
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 UCHAR_MAX
Definition: limits.h:25
BYTE * PBYTE
Definition: pedump.c:66
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by START_TEST().

◆ Allocate()

static PVOID Allocate ( SIZE_T  DataSize)
static

Definition at line 45 of file NtAllocateVirtualMemory.c.

47 {
49  PVOID AllocationStart = NULL;
51  PVOID FirstPageStart;
52  SIZE_T NumberOfPages = AllocationSize / PAGE_SIZE;
53  SIZE_T Size;
54  PUCHAR UserBuffer;
55 
57 
58  if (!NT_SUCCESS(Status))
59  return NULL;
60 
61  FirstPageStart = (PUCHAR)AllocationStart + AllocationSize - PAGE_SIZE * NumberOfPages;
62  Size = (NumberOfPages - 1) * PAGE_SIZE;
64  if (!NT_SUCCESS(Status))
65  {
66  AllocationSize = 0;
69  return NULL;
70  }
71  ASSERT(Size % sizeof(ULONG) == 0);
72  ASSERT(RtlCompareMemoryUlong(FirstPageStart, Size, 0) == Size);
73 
74  UserBuffer = AllocationStart;
75  UserBuffer += AllocationSize - PAGE_SIZE - DataSize;
76  RtlFillMemory(FirstPageStart, UserBuffer - (PUCHAR)FirstPageStart, 0xae);
77  RtlZeroMemory(UserBuffer, DataSize);
78  ((PSIZE_T)UserBuffer)[-2] = AllocationSize;
79  ((PSIZE_T)UserBuffer)[-1] = DataSize;
80 
81  Allocations[CurrentAllocation++] = UserBuffer;
83  return UserBuffer;
84 }
_Must_inspect_result_ NTSYSAPI SIZE_T NTAPI RtlCompareMemoryUlong(_In_reads_bytes_(Length) PVOID Source, _In_ SIZE_T Length, _In_ ULONG Pattern)
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define MEM_COMMIT
Definition: nt_native.h:1313
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static VOID ValidateAllocations(VOID)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:319
ULONG_PTR SIZE_T
Definition: typedefs.h:80
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4481
#define NULL
Definition: types.h:112
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
static PVOID Allocations[4096]
#define MEM_RELEASE
Definition: nt_native.h:1316
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
static ULONG CurrentAllocation
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by ReAllocate(), and START_TEST().

◆ CheckAdjacentVADs()

static VOID CheckAdjacentVADs ( )
static

Definition at line 366 of file NtAllocateVirtualMemory.c.

367 {
370  SIZE_T Size;
371  MEMORY_BASIC_INFORMATION MemoryBasicInfo;
372 
373  /* Reserve a full 64k region */
374  BaseAddress = UlongToPtr(0x50000000);
375  Size = 0x10000;
377  &BaseAddress,
378  0,
379  &Size,
380  MEM_RESERVE,
381  PAGE_NOACCESS);
383  if (!NT_SUCCESS(Status))
384  return;
385 
386  /* Reserve another 64k region, but with 64k between */
387  BaseAddress = UlongToPtr(0x50020000);
388  Size = 0x10000;
390  &BaseAddress,
391  0,
392  &Size,
393  MEM_RESERVE,
394  PAGE_NOACCESS);
396  if (!NT_SUCCESS(Status))
397  return;
398 
399  /* Try to free the whole at once */
400  BaseAddress = UlongToPtr(0x50000000);
401  Size = 0x30000;
404 
405  /* Reserve the part in the middle */
406  BaseAddress = UlongToPtr(0x50010000);
407  Size = 0x10000;
409  &BaseAddress,
410  0,
411  &Size,
412  MEM_RESERVE,
413  PAGE_NOACCESS);
415 
416  /* Try to commit memory covering 2 allocations */
417  BaseAddress = UlongToPtr(0x50004000);
418  Size = 0x10000;
420  &BaseAddress,
421  0,
422  &Size,
423  MEM_COMMIT,
424  PAGE_NOACCESS);
426 
427  /* Commit a page */
428  BaseAddress = UlongToPtr(0x50000000);
429  Size = 0x1000;
431  &BaseAddress,
432  0,
433  &Size,
434  MEM_COMMIT,
437 
438  /* Commit another page */
439  BaseAddress = UlongToPtr(0x50002000);
440  Size = 0x1000;
442  &BaseAddress,
443  0,
444  &Size,
445  MEM_COMMIT,
446  PAGE_NOACCESS);
448 
449  _SEH2_TRY
450  {
451  *(int*)UlongToPtr(0x50000000) = 1;
452  }
454  {
455  ok(0, "Got exception\n");
456  }
457  _SEH2_END;
458 
459  _SEH2_TRY
460  {
461  (void)*(volatile int*)UlongToPtr(0x50002000);
462  }
464  {
466  }
467  _SEH2_END;
469 
470  /* Allocate 3 pages, on top of the previous 2 */
471  BaseAddress = UlongToPtr(0x50000000);
472  Size = 0x3000;
474  &BaseAddress,
475  0,
476  &Size,
477  MEM_COMMIT,
478  PAGE_READONLY);
480 
481  _SEH2_TRY
482  {
483  *(int*)UlongToPtr(0x50000000) = 1;
484  }
486  {
488  }
489  _SEH2_END;
491 
492  /* Commit a page at the end of the first region */
493  BaseAddress = UlongToPtr(0x5000F000);
494  Size = 0x1000;
496  &BaseAddress,
497  0,
498  &Size,
499  MEM_COMMIT,
502  ok_ptr(BaseAddress, UlongToPtr(0x5000F000));
503 
504  /* See where is the base of this newly committed area
505  * (choose a base address in the middle of it) */
507  UlongToPtr(0x5000F700),
509  &MemoryBasicInfo,
510  sizeof(MemoryBasicInfo),
511  NULL);
513  /* The base address is the beginning of the committed area */
514  ok_ptr(MemoryBasicInfo.BaseAddress, UlongToPtr(0x5000F000));
515  /* The allocation base address is the beginning of the whole region */
516  ok_ptr(MemoryBasicInfo.AllocationBase, UlongToPtr(0x50000000));
517  /* This is the protection of the memory when it was reserved. */
518  ok_long(MemoryBasicInfo.AllocationProtect, PAGE_NOACCESS);
519  /* This is the size of the committed region. (ie, smallest chunk size) */
520  ok_long(MemoryBasicInfo.RegionSize, 0x1000);
521  /* This is the state of the queried address */
522  ok_long(MemoryBasicInfo.State, MEM_COMMIT);
523  /* This is the protection of the queried address */
524  ok_long(MemoryBasicInfo.Protect, PAGE_READWRITE);
525  /* NtAllocateVirtualMemory makes it MEM_PRIVATE */
526  ok_long(MemoryBasicInfo.Type, MEM_PRIVATE);
527 
528  /* Try to free the whole region at once */
529  BaseAddress = UlongToPtr(0x50000000);
530  Size = 0x30000;
533 
534  BaseAddress = UlongToPtr(0x50000000);
535  Size = 0x10000;
538 
539  BaseAddress = UlongToPtr(0x50010000);
540  Size = 0x10000;
543 
544  BaseAddress = UlongToPtr(0x50020000);
545  Size = 0x10000;
548 
549  /* Reserve 3 full 64k region */
550  BaseAddress = UlongToPtr(0x50000000);
551  Size = 0x30000;
553  &BaseAddress,
554  0,
555  &Size,
556  MEM_RESERVE,
557  PAGE_NOACCESS);
559  if (!NT_SUCCESS(Status))
560  return;
561 
562  /* Release the 64k region in the middle */
563  BaseAddress = UlongToPtr(0x50010000);
564  Size = 0x10000;
567 
568 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NtQueryVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN MEMORY_INFORMATION_CLASS MemoryInformationClass, OUT PVOID MemoryInformation, IN SIZE_T MemoryInformationLength, OUT PSIZE_T ReturnLength)
Definition: virtual.c:4398
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define ok_long(expression, result)
Definition: atltest.h:133
#define MEM_COMMIT
Definition: nt_native.h:1313
_SEH2_TRY
Definition: create.c:4226
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define UlongToPtr(u)
Definition: config.h:106
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define STATUS_UNABLE_TO_FREE_VM
Definition: ntstatus.h:263
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define MEM_PRIVATE
Definition: nt_native.h:1318
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4481
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define MEM_RELEASE
Definition: nt_native.h:1316
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by START_TEST().

◆ CheckAlignment()

VOID CheckAlignment ( )

Definition at line 229 of file NtAllocateVirtualMemory.c.

230 {
233  SIZE_T Size;
234 
235  CheckSize(0x50000000, 0x0001, 0x1000);
236  CheckSize(0x50008000, 0x0001, 0x9000);
237  CheckSize(0x50000010, 0x1000, 0x2000);
238  CheckSize(0x50010000, 0x2000, 0x2000);
239  CheckSize(0x5000FFFF, 0x3000, 0x13000);
240  CheckSize(0x50001010, 0x7000, 0x9000);
241  CheckSize(0x50001010, 0xC000, 0xe000);
242 
243  /* Reserve memory not aligned to allocation granularity */
244  BaseAddress = UlongToPtr(0x50001010);
245  Size = 0x1000;
247  &BaseAddress,
248  0,
249  &Size,
250  MEM_RESERVE,
251  PAGE_NOACCESS);
253  ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
254  ok(Size == 0x3000, "Got back wrong size: 0x%Ix", Size);
255 
256  /* Try to reserve again in the same 64k region */
257  BaseAddress = UlongToPtr(0x50008000);
258  Size = 0x1000;
260  &BaseAddress,
261  0,
262  &Size,
263  MEM_RESERVE,
264  PAGE_NOACCESS);
266 
267  /* Commit memory */
268  BaseAddress = UlongToPtr(0x50002000);
269  Size = 0x1000;
271  &BaseAddress,
272  0,
273  &Size,
274  MEM_COMMIT,
275  PAGE_NOACCESS);
277  ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
278  ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
279 
280  /* Commit the same address again with a different protection */
281  BaseAddress = UlongToPtr(0x50002000);
282  Size = 0x1000;
284  &BaseAddress,
285  0,
286  &Size,
287  MEM_COMMIT,
290  ok(BaseAddress == UlongToPtr(0x50002000), "Got back wrong base address: %p", BaseAddress);
291  ok(Size == 0x1000, "Got back wrong size: 0x%Ix", Size);
292 
293  /* Commit memory at a too high address */
294  BaseAddress = UlongToPtr(0x50003000);
295  Size = 0x1000;
297  &BaseAddress,
298  0,
299  &Size,
300  MEM_COMMIT,
301  PAGE_NOACCESS);
303 
304  /* Decommit the memory, even those pages that were not committed */
305  BaseAddress = UlongToPtr(0x50000000);
306  Size = 0x3000;
309 
310  /* Try to release memory in a different 64k region */
311  BaseAddress = UlongToPtr(0x50010000);
312  Size = 0x1000;
315 
316  /* Release the memory in the same 64k region at a different address */
317  BaseAddress = UlongToPtr(0x50008000);
318  Size = 0x1000;
321 
322  /* Release the memory at the correct address but with wrong size */
323  BaseAddress = UlongToPtr(0x50000000);
324  Size = 0x4000;
327 
328  /* Release the memory */
329  BaseAddress = UlongToPtr(0x50000000);
330  Size = 0x3000;
333 
334  /* Reserve and commit at once */
335  BaseAddress = UlongToPtr(0x50004080);
336  Size = 0x1000;
338  &BaseAddress,
339  0,
340  &Size,
344  ok(BaseAddress == UlongToPtr(0x50000000), "Got back wrong base address: %p", BaseAddress);
345  ok(Size == 0x6000, "Got back wrong size: 0x%Ix", Size);
346 
347  _SEH2_TRY
348  {
349  *(int*)BaseAddress = 1;
350  *(int*)UlongToPtr(0x50004080) = 1;
351  }
353  {
354  ok(0, "Got exception\n");
355  }
356  _SEH2_END;
357 
358  /* Release the memory */
361 
362 }
VOID CheckSize(ULONG_PTR Base, SIZE_T InSize, SIZE_T ExpectedSize)
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define MEM_COMMIT
Definition: nt_native.h:1313
_SEH2_TRY
Definition: create.c:4226
#define MEM_DECOMMIT
Definition: nt_native.h:1315
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PAGE_NOACCESS
Definition: nt_native.h:1302
#define UlongToPtr(u)
Definition: config.h:106
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define STATUS_UNABLE_TO_FREE_VM
Definition: ntstatus.h:263
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4481
#define STATUS_MEMORY_NOT_ALLOCATED
Definition: ntstatus.h:396
#define ok(value,...)
Definition: atltest.h:57
#define MEM_RELEASE
Definition: nt_native.h:1316
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define PAGE_READWRITE
Definition: nt_native.h:1304
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by PPBridge_SaveCurrentSettings(), and START_TEST().

◆ CheckMemory1()

static BOOLEAN CheckMemory1 ( PVOID  UserBuffer,
SIZE_T  DataSize 
)
static

Definition at line 156 of file NtAllocateVirtualMemory.c.

159 {
160  PBYTE Buffer = UserBuffer;
161  SIZE_T i;
162 
163  for (i = 0; i < DataSize; ++i)
164  if (Buffer[i] != LOBYTE(i))
165  {
166  trace("Mismatch in region %p at index %lu. Value=%02x\n", UserBuffer, (ULONG)i, Buffer[i]);
167  ASSERT(FALSE);
168  return FALSE;
169  }
170  return TRUE;
171 }
#define LOBYTE(W)
Definition: jmemdos.c:487
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
#define trace
Definition: atltest.h:70
#define ASSERT(a)
Definition: mode.c:44
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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
unsigned int ULONG
Definition: retypes.h:1
BYTE * PBYTE
Definition: pedump.c:66
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by START_TEST().

◆ CheckMemory2()

static BOOLEAN CheckMemory2 ( PVOID  UserBuffer,
SIZE_T  DataSize 
)
static

Definition at line 188 of file NtAllocateVirtualMemory.c.

191 {
192  PBYTE Buffer = UserBuffer;
193  SIZE_T i;
194 
195  for (i = 0; i < DataSize; ++i)
196  if (Buffer[i] != UCHAR_MAX - LOBYTE(i))
197  {
198  trace("Mismatch in region %p at index %lu. Value=%02x\n", UserBuffer, (ULONG)i, Buffer[i]);
199  ASSERT(FALSE);
200  return FALSE;
201  }
202  return TRUE;
203 }
#define LOBYTE(W)
Definition: jmemdos.c:487
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
#define trace
Definition: atltest.h:70
#define ASSERT(a)
Definition: mode.c:44
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 UCHAR_MAX
Definition: limits.h:25
unsigned int ULONG
Definition: retypes.h:1
BYTE * PBYTE
Definition: pedump.c:66
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by START_TEST().

◆ CheckSize()

VOID CheckSize ( ULONG_PTR  Base,
SIZE_T  InSize,
SIZE_T  ExpectedSize 
)

Definition at line 206 of file NtAllocateVirtualMemory.c.

207 {
210  SIZE_T Size;
211 
212  /* Reserve memory */
214  Size = InSize;
216  &BaseAddress,
217  0,
218  &Size,
219  MEM_RESERVE,
220  PAGE_NOACCESS);
221  ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed!\n");
222  ok(BaseAddress == (PVOID)(Base & ~((ULONG_PTR)0xFFFF)), "Got back wrong base address: %p\n", BaseAddress);
223  ok(Size == ExpectedSize, "Alloc of 0x%Ix: got back wrong size: 0x%Ix, expected 0x%Ix\n", InSize, Size, ExpectedSize);
225  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed!\n");
226 }
LONG NTSTATUS
Definition: precomp.h:26
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2386
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define MEM_RESERVE
Definition: nt_native.h:1314
#define PAGE_NOACCESS
Definition: nt_native.h:1302
void * PVOID
Definition: retypes.h:9
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG_PTR SIZE_T
Definition: typedefs.h:80
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4481
#define ok(value,...)
Definition: atltest.h:57
#define MEM_RELEASE
Definition: nt_native.h:1316
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by CheckAlignment().

◆ CheckSomeDefaultAddresses()

static VOID CheckSomeDefaultAddresses ( VOID  )
static

Definition at line 572 of file NtAllocateVirtualMemory.c.

573 {
576  SIZE_T Size;
577 
578  // NULL.
579 
580  /* Reserve memory dynamically, not at 0x00000000 */
581  BaseAddress = NULL;
582  Size = 0x1000;
584  &BaseAddress,
585  0,
586  &Size,
587  MEM_RESERVE,
590  ok(BaseAddress != 0x00000000, "Unexpected BaseAddress = 0x00000000\n");
593 
594  // 0x00000000, 64k: Free.
595 
596  /* Reserve and commit memory at 0x00000000, after round down */
597  BaseAddress = UlongToPtr(0x00000000 + 0x0FFF);
598  Size = 0x1000;
600  &BaseAddress,
601  0,
602  &Size,
606  ok_ptr(BaseAddress, 0x00000000);
607 
608  // Double-check that it is not forbidden "in order to catch null pointer accesses".
609  StartSeh()
610  *(int*)UlongToPtr(0x00000000) = 1;
612 
615 
616  /* Reserve memory above 0x00000000 */
617  BaseAddress = UlongToPtr(0x00000000 + 0x1000);
618  Size = 0x1000;
620  &BaseAddress,
621  0,
622  &Size,
623  MEM_RESERVE,
628 
629  /* The following checks assume very default addresses,
630  * no address space layout randomization (ASLR). */
631 #ifdef _WIN64
632  ok(FALSE, "ToDo, 64-bit: Check/Adapt 32-bit results\n");
633 #endif
634 
635  // 0x00010000, 4k: Private Data.
636  // 0x00011000, 60k: Unusable.
637 
638  /* Reserve memory below 0x00010000 */
639  BaseAddress = UlongToPtr(0x00010000 - 0x1000);
640  Size = 0x1000;
642  &BaseAddress,
643  0,
644  &Size,
645  MEM_RESERVE,
650 
651  /* Reserve memory at 0x00010000:
652  * Windows NT legacy default executable image base */
653  BaseAddress = UlongToPtr(0x00010000);
654  Size = 0x1000;
656  &BaseAddress,
657  0,
658  &Size,
659  MEM_RESERVE,
662  if (NT_SUCCESS(Status))
663  { // Unexpected, cleanup.
666  }
667 
668  // 0x00400000: Image base.
669 
670  /* Reserve memory below 0x00400000 */
671  BaseAddress = UlongToPtr(0x00400000 - 0x1000);
672  Size = 0x1000;
674  &BaseAddress,
675  0,
676  &Size,
677  MEM_RESERVE,
679  if (NT_SUCCESS(Status))
680  {
681  trace("Below 0x00400000 is available, as on ReactOS and Windows S03\n");
682  // 0x003F0000, 64k: Free.
686  }
687  else
688  {
689  trace("Below 0x00400000 is not available, as on Windows XP\n");
690  // 0x003F0000, 4k: Shareable.
691  // 0x003F1000, 60k: Unusable.
693  }
694 
695  /* Reserve memory at 0x00400000:
696  * Windows NT legacy default DLL image base,
697  * (ReactOS and) Windows 95 new default executable image base */
698  BaseAddress = UlongToPtr(0x00400000);
699  Size = 0x1000;
701  &BaseAddress,
702  0,
703  &Size,
704  MEM_RESERVE,
707  if (NT_SUCCESS(Status))
708  { // Unexpected, cleanup.
711  }
712 
713  // 0x10000000: Free.
714 
715  /* Reserve memory below 0x10000000 */
716  BaseAddress = UlongToPtr(0x10000000 - 0x1000);
717  Size = 0x1000;
719  &BaseAddress,
720  0,
721  &Size,
722  MEM_RESERVE,
727 
728  /* Reserve memory at 0x10000000:
729  * Windows new default non-OS DLL image base */
730  BaseAddress = UlongToPtr(0x10000000);
731  Size = 0x1000;
733  &BaseAddress,
734  0,
735  &Size,
736  MEM_RESERVE,
741 
742 #ifdef _WIN64
743  skip("ToDo, 64-bit: Add 0x140000000/Exe and 0x180000000/DLL checks\n");
744 #endif
745 }
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define MEM_COMMIT
Definition: nt_native.h:1313
#define StartSeh()
Definition: _sntprintf.h:16
#define FALSE
Definition: types.h:117
#define MEM_RESERVE
Definition: nt_native.h:1314
#define UlongToPtr(u)
Definition: config.h:106
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define trace
Definition: atltest.h:70
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG_PTR SIZE_T
Definition: typedefs.h:80
NTSTATUS NTAPI NtAllocateVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UBaseAddress, IN ULONG_PTR ZeroBits, IN OUT PSIZE_T URegionSize, IN ULONG AllocationType, IN ULONG Protect)
Definition: virtual.c:4481
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
#define MEM_RELEASE
Definition: nt_native.h:1316
#define ok_ntstatus(status, expected)
Definition: atltest.h:135
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by START_TEST().

◆ Free()

static VOID Free ( PVOID  UserBuffer)
static

Definition at line 88 of file NtAllocateVirtualMemory.c.

90 {
92  PVOID AllocationStart;
93  SIZE_T Zero = 0;
96  ULONG i;
97 
98  AllocationSize = ((PSIZE_T)UserBuffer)[-2];
99  DataSize = ((PSIZE_T)UserBuffer)[-1];
100  ASSERT(DataSize != 0);
101 
102  AllocationStart = (PUCHAR)UserBuffer + DataSize + PAGE_SIZE - AllocationSize;
103  ASSERT((SIZE_T)AllocationStart % PAGE_SIZE == 0);
104 
105  RtlFillMemory(UserBuffer, DataSize, 0xbe);
106  ((PSIZE_T)UserBuffer)[-1] = 0;
107  ((PSIZE_T)UserBuffer)[-2] = 0xFAFBFCFD;
108 
109  for (i = 0; i < CurrentAllocation; ++i)
110  if (Allocations[i] == UserBuffer)
111  {
112  Allocations[i] = NULL;
113  break;
114  }
116 
117  Status = NtFreeVirtualMemory(NtCurrentProcess(), &AllocationStart, &Zero, MEM_RELEASE);
119 }
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static VOID ValidateAllocations(VOID)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:319
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 NULL
Definition: types.h:112
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:411
static PVOID Allocations[4096]
#define MEM_RELEASE
Definition: nt_native.h:1316
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
static ULONG CurrentAllocation
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by ReAllocate(), and START_TEST().

◆ ReAllocate()

static PVOID ReAllocate ( PVOID  OldUserBuffer,
SIZE_T  NewDataSize 
)
static

Definition at line 123 of file NtAllocateVirtualMemory.c.

126 {
127  PVOID NewUserBuffer;
128  SIZE_T OldDataSize;
129 
130  OldDataSize = ((PSIZE_T)OldUserBuffer)[-1];
131  ASSERT(OldDataSize != 0);
132 
133  NewUserBuffer = Allocate(NewDataSize);
134  ASSERT(((PSIZE_T)OldUserBuffer)[-1] == OldDataSize);
135  RtlCopyMemory(NewUserBuffer, OldUserBuffer, min(OldDataSize, NewDataSize));
136  ASSERT(((PSIZE_T)OldUserBuffer)[-1] == OldDataSize);
137  Free(OldUserBuffer);
138  return NewUserBuffer;
139 }
static VOID Free(PVOID UserBuffer)
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
static PVOID Allocate(SIZE_T DataSize)
#define ASSERT(a)
Definition: mode.c:44
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define min(a, b)
Definition: monoChain.cc:55
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( NtAllocateVirtualMemory  )

Definition at line 749 of file NtAllocateVirtualMemory.c.

750 {
751  PVOID Mem1, Mem2;
752  SIZE_T Size1, Size2;
753  ULONG i;
754 
755  CheckAlignment();
758 
759  Size1 = 32;
760  Mem1 = Allocate(Size1);
761  AccessMemory1(Mem1, Size1);
762  Size2 = 128;
763  Mem2 = Allocate(Size2);
764  AccessMemory2(Mem2, Size2);
765  for (i = 0; i < RUNS; ++i)
766  {
767  PVOID New;
768  ok(CheckMemory1(Mem1, Size1) == TRUE, "CheckMemory1 failure\n");
769  New = ReAllocate(Mem1, Size1 * 3 / 2);
770  if (New == NULL)
771  {
772  skip("Realloc failure\n");
773  break;
774  }
775  Mem1 = New;
776  ok(CheckMemory1(Mem1, Size1) == TRUE, "CheckMemory1 failure\n");
777  Size1 = Size1 * 3 / 2;
778  AccessMemory1(Mem1, Size1);
779 
780  ok(CheckMemory2(Mem2, Size2) == TRUE, "CheckMemory2 failure\n");
781  New = ReAllocate(Mem2, Size2 + 128);
782  if (New == NULL)
783  {
784  skip("Realloc failure\n");
785  break;
786  }
787  Mem2 = New;
788  ok(CheckMemory2(Mem2, Size2) == TRUE, "CheckMemory2 failure\n");
789  Size2 += 128;
790  AccessMemory2(Mem2, Size2);
791  }
792  ok(CheckMemory2(Mem2, Size2) == TRUE, "CheckMemory2 failure\n");
793  Free(Mem2);
794  ok(CheckMemory1(Mem1, Size1) == TRUE, "CheckMemory1 failure\n");
795  Free(Mem1);
796 }
#define TRUE
Definition: types.h:120
static VOID Free(PVOID UserBuffer)
#define New(t)
Definition: rtf.h:1086
static PVOID ReAllocate(PVOID OldUserBuffer, SIZE_T NewDataSize)
static PVOID Allocate(SIZE_T DataSize)
VOID CheckAlignment()
static VOID CheckSomeDefaultAddresses(VOID)
#define RUNS
static BOOLEAN CheckMemory2(PVOID UserBuffer, SIZE_T DataSize)
static VOID AccessMemory2(PVOID UserBuffer, SIZE_T DataSize)
static VOID CheckAdjacentVADs()
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 CheckMemory1(PVOID UserBuffer, SIZE_T DataSize)
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
static VOID AccessMemory1(PVOID UserBuffer, SIZE_T DataSize)

◆ ValidateAllocations()

static VOID ValidateAllocations ( VOID  )
static

Definition at line 20 of file NtAllocateVirtualMemory.c.

21 {
22  ULONG i;
23 
24  ASSERT(CurrentAllocation < sizeof(Allocations) / sizeof(Allocations[0]));
25  for (i = 0; i < CurrentAllocation; ++i)
26  {
27  PUCHAR UserBuffer = Allocations[i];
30 
31  if (UserBuffer == NULL)
32  continue;
33 
34  AllocationSize = ((PSIZE_T)UserBuffer)[-2];
35  DataSize = ((PSIZE_T)UserBuffer)[-1];
36  ASSERT(AllocationSize != 0);
38  ASSERT(DataSize != 0);
39  ASSERT(((SIZE_T)UserBuffer + DataSize) % PAGE_SIZE == 0);
40  }
41 }
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
#define ASSERT(a)
Definition: mode.c:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:319
ULONG_PTR SIZE_T
Definition: typedefs.h:80
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 NULL
Definition: types.h:112
static PVOID Allocations[4096]
unsigned int ULONG
Definition: retypes.h:1
static ULONG CurrentAllocation
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751

Referenced by Allocate(), and Free().

Variable Documentation

◆ Allocations

PVOID Allocations[4096] = { NULL }
static

Definition at line 15 of file NtAllocateVirtualMemory.c.

Referenced by Allocate(), Free(), and ValidateAllocations().

◆ CurrentAllocation

ULONG CurrentAllocation = 0
static

Definition at line 16 of file NtAllocateVirtualMemory.c.

Referenced by Allocate(), Free(), and ValidateAllocations().