ReactOS  0.4.15-dev-1377-ga59cecd
apitest_guard.h
Go to the documentation of this file.
1 #ifndef _APITEST_GUARD_H
2 #define _APITEST_GUARD_H
3 
4 #include <ndk/mmfuncs.h>
5 #include <ndk/psfuncs.h>
6 
7 static
8 inline
9 PVOID
11  _In_ SIZE_T SizeRequested)
12 {
14  SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
15  PVOID VirtualMemory = NULL;
16  PCHAR StartOfBuffer;
17 
19 
20  if (!NT_SUCCESS(Status))
21  return NULL;
22 
23  Size -= PAGE_SIZE;
24  if (Size)
25  {
27  if (!NT_SUCCESS(Status))
28  {
29  Size = 0;
31  ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
32  return NULL;
33  }
34  }
35 
36  StartOfBuffer = VirtualMemory;
37  StartOfBuffer += Size - SizeRequested;
38 
39  return StartOfBuffer;
40 }
41 
42 static
43 inline
44 VOID
46  _In_ PVOID Pointer)
47 {
49  PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
50  SIZE_T Size = 0;
51 
53  ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
54 }
55 
56 static
57 inline
58 VOID
60  PVOID Pointer,
61  SIZE_T SizeRequested)
62 {
64  SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
65  PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
66 
67  if (Size)
68  {
70  if (!NT_SUCCESS(Status))
71  {
72  Size = 0;
74  ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
75  }
76  }
77 }
78 
79 #endif /* _APITEST_GUARD_H */
signed char * PCHAR
Definition: retypes.h:7
LONG NTSTATUS
Definition: precomp.h:26
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
#define MEM_COMMIT
Definition: nt_native.h:1313
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PAGE_SIZE
Definition: env_spec_w32.h:49
static VOID MakeReadOnly(PVOID Pointer, SIZE_T SizeRequested)
Definition: apitest_guard.h:59
#define _In_
Definition: no_sal2.h:158
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:4407
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
#define MEM_RELEASE
Definition: nt_native.h:1316
#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:5130