ReactOS  0.4.15-dev-3173-g40ee59d
NtFreeVirtualMemory.c File Reference
#include "precomp.h"
Include dependency graph for NtFreeVirtualMemory.c:

Go to the source code of this file.

Functions

static void Test_NtFreeVirtualMemory (void)
 
static void Test_NtFreeVirtualMemory_Parameters (void)
 
 START_TEST (NtFreeVirtualMemory)
 

Function Documentation

◆ START_TEST()

START_TEST ( NtFreeVirtualMemory  )

Definition at line 213 of file NtFreeVirtualMemory.c.

214 {
217 }
static void Test_NtFreeVirtualMemory(void)
static void Test_NtFreeVirtualMemory_Parameters(void)

◆ Test_NtFreeVirtualMemory()

static void Test_NtFreeVirtualMemory ( void  )
static

Definition at line 11 of file NtFreeVirtualMemory.c.

12 {
13  PVOID Buffer = NULL, Buffer2;
16 
18  &Buffer,
19  0,
20  &Length,
23  ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed : 0x%08lx\n", Status);
24  ok(Length == PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
25  ok(((ULONG_PTR)Buffer % PAGE_SIZE) == 0, "The buffer is not aligned to PAGE_SIZE.\n");
26 
28  &Buffer,
29  &Length,
30  MEM_DECOMMIT);
31  ok(Status == STATUS_SUCCESS, "NtFreeVirtualMemory failed : 0x%08lx\n", Status);
32 
33  /* Now try to free more than we got */
34  Length++;
36  &Buffer,
37  &Length,
38  MEM_DECOMMIT);
39  ok(Status == STATUS_UNABLE_TO_FREE_VM, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
40 
42  &Buffer,
43  &Length,
44  MEM_RELEASE);
45  ok(Status == STATUS_UNABLE_TO_FREE_VM, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
46 
47  /* Free out of bounds from the wrong origin */
48  Length = PAGE_SIZE;
49  Buffer2 = (PVOID)((ULONG_PTR)Buffer+1);
50 
52  &Buffer2,
53  &Length,
54  MEM_DECOMMIT);
55  ok(Status == STATUS_UNABLE_TO_FREE_VM, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
56 
57  Buffer2 = (PVOID)((ULONG_PTR)Buffer+1);
58  Length = PAGE_SIZE;
60  &Buffer2,
61  &Length,
62  MEM_RELEASE);
63  ok(Status == STATUS_UNABLE_TO_FREE_VM, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
64 
65  /* Same but in bounds */
66  Length = PAGE_SIZE - 1;
67  Buffer2 = (PVOID)((ULONG_PTR)Buffer+1);
68 
70  &Buffer2,
71  &Length,
72  MEM_DECOMMIT);
73  ok(Status == STATUS_SUCCESS, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
74  ok(Buffer2 == Buffer, "NtFreeVirtualMemory set wrong buffer.\n");
75  ok(Length == PAGE_SIZE, "NtFreeVirtualMemory did not round Length to PAGE_SIZE.\n");
76 
77  Buffer2 = (PVOID)((ULONG_PTR)Buffer+1);
78  Length = PAGE_SIZE-1;
80  &Buffer2,
81  &Length,
82  MEM_RELEASE);
83  ok(Status == STATUS_SUCCESS, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
84  ok(Buffer2 == Buffer, "NtFreeVirtualMemory set wrong buffer.\n");
85  ok(Length == PAGE_SIZE, "NtFreeVirtualMemory did not round Length to PAGE_SIZE.\n");
86 
87  /* Now allocate two pages and try to free them one after the other */
88  Length = 2*PAGE_SIZE;
90  &Buffer,
91  0,
92  &Length,
95  ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed : 0x%08lx\n", Status);
96  ok(Length == 2*PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
97  ok(((ULONG_PTR)Buffer % PAGE_SIZE) == 0, "The buffer is not aligned to PAGE_SIZE.\n");
98 
99  Buffer2 = Buffer;
100  Length = PAGE_SIZE;
102  &Buffer2,
103  &Length,
104  MEM_RELEASE);
105  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed : 0x%08lx\n", Status);
106  ok(Length == PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
107  ok(Buffer2 == Buffer, "The buffer is not aligned to PAGE_SIZE.\n");
108 
109  Buffer2 = (PVOID)((ULONG_PTR)Buffer+PAGE_SIZE);
110  Length = PAGE_SIZE;
112  &Buffer2,
113  &Length,
114  MEM_RELEASE);
115  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed : 0x%08lx\n", Status);
116  ok(Length == PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
117  ok(Buffer2 == (PVOID)((ULONG_PTR)Buffer+PAGE_SIZE), "The buffer is not aligned to PAGE_SIZE.\n");
118 
119  /* Same, but try to free the second page before the first one */
120  Length = 2*PAGE_SIZE;
122  &Buffer,
123  0,
124  &Length,
125  MEM_RESERVE,
127  ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed : 0x%08lx\n", Status);
128  ok(Length == 2*PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
129  ok(((ULONG_PTR)Buffer % PAGE_SIZE) == 0, "The buffer is not aligned to PAGE_SIZE.\n");
130 
131  Buffer2 = (PVOID)((ULONG_PTR)Buffer+PAGE_SIZE);
132  Length = PAGE_SIZE;
134  &Buffer2,
135  &Length,
136  MEM_RELEASE);
137  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed : 0x%08lx\n", Status);
138  ok(Length == PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
139  ok(Buffer2 == (PVOID)((ULONG_PTR)Buffer+PAGE_SIZE), "The buffer is not aligned to PAGE_SIZE.\n");
140 
141  Buffer2 = Buffer;
142  Length = PAGE_SIZE;
144  &Buffer2,
145  &Length,
146  MEM_RELEASE);
147  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed : 0x%08lx\n", Status);
148  ok(Length == PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
149  ok(Buffer2 == Buffer, "The buffer is not aligned to PAGE_SIZE.\n");
150 
151  /* Now allocate two pages and try to free them in the middle */
152  Length = 2*PAGE_SIZE;
154  &Buffer,
155  0,
156  &Length,
157  MEM_RESERVE,
159  ok(NT_SUCCESS(Status), "NtAllocateVirtualMemory failed : 0x%08lx\n", Status);
160  ok(Length == 2*PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
161  ok(((ULONG_PTR)Buffer % PAGE_SIZE) == 0, "The buffer is not aligned to PAGE_SIZE.\n");
162 
163  Buffer2 = (PVOID)((ULONG_PTR)Buffer+1);
164  Length = PAGE_SIZE;
166  &Buffer2,
167  &Length,
168  MEM_RELEASE);
169  ok(NT_SUCCESS(Status), "NtFreeVirtualMemory failed : 0x%08lx\n", Status);
170  ok(Length == 2*PAGE_SIZE, "Length mismatch : 0x%08lx\n", (ULONG)Length);
171  ok(Buffer2 == Buffer, "The buffer is not aligned to PAGE_SIZE.\n");
172 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
LONG NTSTATUS
Definition: precomp.h:26
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define MEM_DECOMMIT
Definition: nt_native.h:1315
#define MEM_RESERVE
Definition: nt_native.h:1314
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
#define STATUS_UNABLE_TO_FREE_VM
Definition: ntstatus.h:263
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PAGE_SIZE
Definition: env_spec_w32.h:49
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 MEM_RELEASE
Definition: nt_native.h:1316
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#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().

◆ Test_NtFreeVirtualMemory_Parameters()

static void Test_NtFreeVirtualMemory_Parameters ( void  )
static

Definition at line 174 of file NtFreeVirtualMemory.c.

175 {
177  ULONG FreeType;
178  int i;
179 
180  // 4th parameter: "ULONG FreeType".
181 
182  // A type is mandatory.
184  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
185 
186  // All but MEM_DECOMMIT and MEM_RELEASE are unsupported.
187  // Each bit one by one.
188  for (i = 0; i < 32; ++i)
189  {
190  FreeType = 1 << i;
192  continue;
193 
195  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
196  }
197  // All bits at once.
198  // Not testing all other values.
200  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
202  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
204  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
206  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
207 
208  // MEM_DECOMMIT and MEM_RELEASE are exclusive.
210  ok(Status == STATUS_INVALID_PARAMETER_4, "NtFreeVirtualMemory returned status : 0x%08lx\n", Status);
211 }
LONG NTSTATUS
Definition: precomp.h:26
#define MEM_DECOMMIT
Definition: nt_native.h:1315
Status
Definition: gdiplustypes.h:24
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
__kernel_entry _Inout_ _Inout_ PSIZE_T _In_ ULONG FreeType
Definition: mmfuncs.h:172
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define MEM_RELEASE
Definition: nt_native.h:1316
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5204

Referenced by START_TEST().