ReactOS 0.4.16-dev-306-g647d351
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
7static
8inline
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
42static
43inline
44VOID
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
56static
57inline
58VOID
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 */
static VOID MakeReadOnly(PVOID Pointer, SIZE_T SizeRequested)
Definition: apitest_guard.h:59
static VOID FreeGuarded(_In_ PVOID Pointer)
Definition: apitest_guard.h:45
static PVOID AllocateGuarded(_In_ SIZE_T SizeRequested)
Definition: apitest_guard.h:10
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:25
#define PAGE_ROUND_UP(x)
Definition: mmtypes.h:38
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define _In_
Definition: no_sal2.h:158
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RESERVE
Definition: nt_native.h:1314
#define MEM_RELEASE
Definition: nt_native.h:1316
#define MEM_COMMIT
Definition: nt_native.h:1313
#define PAGE_NOACCESS
Definition: nt_native.h:1302
NTSTATUS NTAPI NtFreeVirtualMemory(IN HANDLE ProcessHandle, IN PVOID *UBaseAddress, IN PSIZE_T URegionSize, IN ULONG FreeType)
Definition: virtual.c:5230
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:4492
#define STATUS_SUCCESS
Definition: shellext.h:65
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533