https://git.reactos.org/?p=reactos.git;a=commitdiff;h=787b2c76604a96444c5ff…
commit 787b2c76604a96444c5fffe206b3c3fb5dcdedee
Author: Thomas Faber <thomas.faber(a)reactos.org>
AuthorDate: Wed Jul 10 12:25:36 2019 +0200
Commit: Thomas Faber <thomas.faber(a)reactos.org>
CommitDate: Tue Dec 31 15:18:41 2019 +0100
[APITESTS] Centrally define AllocateGuarded/FreeGuarded instead of duplicating them.
---
modules/rostests/apitests/crt/sprintf.c | 48 +------------
modules/rostests/apitests/include/apitest_guard.h | 79 ++++++++++++++++++++++
modules/rostests/apitests/ntdll/RtlBitmap.c | 47 -------------
modules/rostests/apitests/ntdll/RtlDeleteAce.c | 47 -------------
.../apitests/ntdll/RtlDetermineDosPathNameType.c | 69 -------------------
modules/rostests/apitests/ntdll/RtlFirstFreeAce.c | 47 -------------
modules/rostests/apitests/ntdll/RtlImageRvaToVa.c | 47 -------------
modules/rostests/apitests/ntdll/precomp.h | 1 +
.../apitests/user32/GetUserObjectInformation.c | 48 +------------
modules/rostests/apitests/ws2_32/WSAStartup.c | 48 +------------
10 files changed, 83 insertions(+), 398 deletions(-)
diff --git a/modules/rostests/apitests/crt/sprintf.c
b/modules/rostests/apitests/crt/sprintf.c
index b612d6d993f..8d42148142c 100644
--- a/modules/rostests/apitests/crt/sprintf.c
+++ b/modules/rostests/apitests/crt/sprintf.c
@@ -6,6 +6,7 @@
*/
#include <apitest.h>
+#include <apitest_guard.h>
#define WIN32_NO_STATUS
#include <stdio.h>
@@ -25,53 +26,6 @@
#endif
#endif
-static
-PVOID
-AllocateGuarded(
- SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
/* NOTE: This test is not only used for all the CRT apitests, but also for
* user32's wsprintf. Make sure to test them all */
START_TEST(sprintf)
diff --git a/modules/rostests/apitests/include/apitest_guard.h
b/modules/rostests/apitests/include/apitest_guard.h
new file mode 100644
index 00000000000..26b8ea0adf1
--- /dev/null
+++ b/modules/rostests/apitests/include/apitest_guard.h
@@ -0,0 +1,79 @@
+#ifndef _APITEST_GUARD_H
+#define _APITEST_GUARD_H
+
+#include <ndk/mmfuncs.h>
+#include <ndk/psfuncs.h>
+
+static
+inline
+PVOID
+AllocateGuarded(
+ _In_ SIZE_T SizeRequested)
+{
+ NTSTATUS Status;
+ SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
+ PVOID VirtualMemory = NULL;
+ PCHAR StartOfBuffer;
+
+ Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
+
+ if (!NT_SUCCESS(Status))
+ return NULL;
+
+ Size -= PAGE_SIZE;
+ if (Size)
+ {
+ Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ Size = 0;
+ Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
+ ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
+ return NULL;
+ }
+ }
+
+ StartOfBuffer = VirtualMemory;
+ StartOfBuffer += Size - SizeRequested;
+
+ return StartOfBuffer;
+}
+
+static
+inline
+VOID
+FreeGuarded(
+ _In_ PVOID Pointer)
+{
+ NTSTATUS Status;
+ PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
+ SIZE_T Size = 0;
+
+ Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
+ ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
+}
+
+static
+inline
+VOID
+MakeReadOnly(
+ PVOID Pointer,
+ SIZE_T SizeRequested)
+{
+ NTSTATUS Status;
+ SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
+ PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
+
+ if (Size)
+ {
+ Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ Size = 0;
+ Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
+ ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
+ }
+ }
+}
+
+#endif /* _APITEST_GUARD_H */
diff --git a/modules/rostests/apitests/ntdll/RtlBitmap.c
b/modules/rostests/apitests/ntdll/RtlBitmap.c
index e524872b64c..355ccee0aff 100644
--- a/modules/rostests/apitests/ntdll/RtlBitmap.c
+++ b/modules/rostests/apitests/ntdll/RtlBitmap.c
@@ -4,53 +4,6 @@
static BOOL IsBroken = FALSE;
-static
-PVOID
-AllocateGuarded(
- _In_ SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- _In_ PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
void
Test_RtlFindMostSignificantBit(void)
{
diff --git a/modules/rostests/apitests/ntdll/RtlDeleteAce.c
b/modules/rostests/apitests/ntdll/RtlDeleteAce.c
index 4c4aaf58cdb..327247c728c 100644
--- a/modules/rostests/apitests/ntdll/RtlDeleteAce.c
+++ b/modules/rostests/apitests/ntdll/RtlDeleteAce.c
@@ -7,53 +7,6 @@
#include "precomp.h"
-static
-PVOID
-AllocateGuarded(
- _In_ SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- _In_ PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
static
PACL
MakeAcl(
diff --git a/modules/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c
b/modules/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c
index 3f99a38a9bd..ed197720302 100644
--- a/modules/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c
+++ b/modules/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c
@@ -30,75 +30,6 @@ ULONG
//= (PVOID)0x7c830669;
;
-static
-PVOID
-AllocateGuarded(
- SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-MakeReadOnly(
- PVOID Pointer,
- SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested);
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
-
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- }
- }
-}
-
-static
-VOID
-FreeGuarded(
- PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
START_TEST(RtlDetermineDosPathNameType)
{
RTL_PATH_TYPE PathType;
diff --git a/modules/rostests/apitests/ntdll/RtlFirstFreeAce.c
b/modules/rostests/apitests/ntdll/RtlFirstFreeAce.c
index 0022945e416..654fdb09363 100644
--- a/modules/rostests/apitests/ntdll/RtlFirstFreeAce.c
+++ b/modules/rostests/apitests/ntdll/RtlFirstFreeAce.c
@@ -7,53 +7,6 @@
#include "precomp.h"
-static
-PVOID
-AllocateGuarded(
- _In_ SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- _In_ PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
static
PACL
MakeAcl(
diff --git a/modules/rostests/apitests/ntdll/RtlImageRvaToVa.c
b/modules/rostests/apitests/ntdll/RtlImageRvaToVa.c
index 9d15c58e717..ba9f75d7d7a 100644
--- a/modules/rostests/apitests/ntdll/RtlImageRvaToVa.c
+++ b/modules/rostests/apitests/ntdll/RtlImageRvaToVa.c
@@ -7,53 +7,6 @@
#include "precomp.h"
-static
-PVOID
-AllocateGuarded(
- _In_ SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- _In_ PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
START_TEST(RtlImageRvaToVa)
{
PIMAGE_NT_HEADERS NtHeader;
diff --git a/modules/rostests/apitests/ntdll/precomp.h
b/modules/rostests/apitests/ntdll/precomp.h
index 39ff188224d..82d3e0733b0 100644
--- a/modules/rostests/apitests/ntdll/precomp.h
+++ b/modules/rostests/apitests/ntdll/precomp.h
@@ -8,6 +8,7 @@
#define COM_NO_WINDOWS_H
#include <apitest.h>
+#include <apitest_guard.h>
#include <ndk/ntndk.h>
#include <strsafe.h>
diff --git a/modules/rostests/apitests/user32/GetUserObjectInformation.c
b/modules/rostests/apitests/user32/GetUserObjectInformation.c
index 71c441fc852..423e3e649bf 100644
--- a/modules/rostests/apitests/user32/GetUserObjectInformation.c
+++ b/modules/rostests/apitests/user32/GetUserObjectInformation.c
@@ -6,6 +6,7 @@
*/
#include "precomp.h"
+#include <apitest_guard.h>
#include <ndk/mmfuncs.h>
#include <ndk/pstypes.h>
@@ -30,53 +31,6 @@ CheckBuffer(
return TRUE;
}
-static
-PVOID
-AllocateGuarded(
- SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
-
#define xok ok // Make the test succeed on Win2003
//#define xok(...) // This should make the test succeed on all Windows versions
#define NOTSET 1234
diff --git a/modules/rostests/apitests/ws2_32/WSAStartup.c
b/modules/rostests/apitests/ws2_32/WSAStartup.c
index 11e731a805e..d3b203f2393 100644
--- a/modules/rostests/apitests/ws2_32/WSAStartup.c
+++ b/modules/rostests/apitests/ws2_32/WSAStartup.c
@@ -6,53 +6,7 @@
*/
#include "ws2_32.h"
-
-static
-PVOID
-AllocateGuarded(
- SIZE_T SizeRequested)
-{
- NTSTATUS Status;
- SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE);
- PVOID VirtualMemory = NULL;
- PCHAR StartOfBuffer;
-
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_RESERVE, PAGE_NOACCESS);
-
- if (!NT_SUCCESS(Status))
- return NULL;
-
- Size -= PAGE_SIZE;
- if (Size)
- {
- Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0,
&Size, MEM_COMMIT, PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- Size = 0;
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory,
&Size, MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
- return NULL;
- }
- }
-
- StartOfBuffer = VirtualMemory;
- StartOfBuffer += Size - SizeRequested;
-
- return StartOfBuffer;
-}
-
-static
-VOID
-FreeGuarded(
- PVOID Pointer)
-{
- NTSTATUS Status;
- PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer);
- SIZE_T Size = 0;
-
- Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size,
MEM_RELEASE);
- ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status);
-}
+#include <apitest_guard.h>
static
BOOLEAN