mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 12:55:43 +00:00
[APITESTS] Centrally define AllocateGuarded/FreeGuarded instead of duplicating them.
This commit is contained in:
parent
c904983b49
commit
787b2c7660
10 changed files with 83 additions and 398 deletions
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <apitest.h>
|
#include <apitest.h>
|
||||||
|
#include <apitest_guard.h>
|
||||||
|
|
||||||
#define WIN32_NO_STATUS
|
#define WIN32_NO_STATUS
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -25,53 +26,6 @@
|
||||||
#endif
|
#endif
|
||||||
#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
|
/* NOTE: This test is not only used for all the CRT apitests, but also for
|
||||||
* user32's wsprintf. Make sure to test them all */
|
* user32's wsprintf. Make sure to test them all */
|
||||||
START_TEST(sprintf)
|
START_TEST(sprintf)
|
||||||
|
|
79
modules/rostests/apitests/include/apitest_guard.h
Normal file
79
modules/rostests/apitests/include/apitest_guard.h
Normal file
|
@ -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 */
|
|
@ -4,53 +4,6 @@
|
||||||
|
|
||||||
static BOOL IsBroken = FALSE;
|
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
|
void
|
||||||
Test_RtlFindMostSignificantBit(void)
|
Test_RtlFindMostSignificantBit(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,53 +7,6 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#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
|
static
|
||||||
PACL
|
PACL
|
||||||
MakeAcl(
|
MakeAcl(
|
||||||
|
|
|
@ -30,75 +30,6 @@ ULONG
|
||||||
//= (PVOID)0x7c830669;
|
//= (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)
|
START_TEST(RtlDetermineDosPathNameType)
|
||||||
{
|
{
|
||||||
RTL_PATH_TYPE PathType;
|
RTL_PATH_TYPE PathType;
|
||||||
|
|
|
@ -7,53 +7,6 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#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
|
static
|
||||||
PACL
|
PACL
|
||||||
MakeAcl(
|
MakeAcl(
|
||||||
|
|
|
@ -7,53 +7,6 @@
|
||||||
|
|
||||||
#include "precomp.h"
|
#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)
|
START_TEST(RtlImageRvaToVa)
|
||||||
{
|
{
|
||||||
PIMAGE_NT_HEADERS NtHeader;
|
PIMAGE_NT_HEADERS NtHeader;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#define COM_NO_WINDOWS_H
|
#define COM_NO_WINDOWS_H
|
||||||
|
|
||||||
#include <apitest.h>
|
#include <apitest.h>
|
||||||
|
#include <apitest_guard.h>
|
||||||
#include <ndk/ntndk.h>
|
#include <ndk/ntndk.h>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
#include <apitest_guard.h>
|
||||||
|
|
||||||
#include <ndk/mmfuncs.h>
|
#include <ndk/mmfuncs.h>
|
||||||
#include <ndk/pstypes.h>
|
#include <ndk/pstypes.h>
|
||||||
|
@ -30,53 +31,6 @@ CheckBuffer(
|
||||||
return TRUE;
|
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 ok // Make the test succeed on Win2003
|
||||||
//#define xok(...) // This should make the test succeed on all Windows versions
|
//#define xok(...) // This should make the test succeed on all Windows versions
|
||||||
#define NOTSET 1234
|
#define NOTSET 1234
|
||||||
|
|
|
@ -6,53 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ws2_32.h"
|
#include "ws2_32.h"
|
||||||
|
#include <apitest_guard.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
static
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue