Reactos

[APITESTS] Centrally define AllocateGuarded/FreeGuarded instead of duplicating them.

+83 -398
+1 -47
modules/rostests/apitests/crt/sprintf.c
··· 6 6 */ 7 7 8 8 #include <apitest.h> 9 + #include <apitest_guard.h> 9 10 10 11 #define WIN32_NO_STATUS 11 12 #include <stdio.h> ··· 24 25 #pragma GCC diagnostic ignored "-Wformat-overflow" 25 26 #endif 26 27 #endif 27 - 28 - static 29 - PVOID 30 - AllocateGuarded( 31 - SIZE_T SizeRequested) 32 - { 33 - NTSTATUS Status; 34 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 35 - PVOID VirtualMemory = NULL; 36 - PCHAR StartOfBuffer; 37 - 38 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 39 - 40 - if (!NT_SUCCESS(Status)) 41 - return NULL; 42 - 43 - Size -= PAGE_SIZE; 44 - if (Size) 45 - { 46 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 47 - if (!NT_SUCCESS(Status)) 48 - { 49 - Size = 0; 50 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 51 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 52 - return NULL; 53 - } 54 - } 55 - 56 - StartOfBuffer = VirtualMemory; 57 - StartOfBuffer += Size - SizeRequested; 58 - 59 - return StartOfBuffer; 60 - } 61 - 62 - static 63 - VOID 64 - FreeGuarded( 65 - PVOID Pointer) 66 - { 67 - NTSTATUS Status; 68 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 69 - SIZE_T Size = 0; 70 - 71 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 72 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 73 - } 74 28 75 29 /* NOTE: This test is not only used for all the CRT apitests, but also for 76 30 * user32's wsprintf. Make sure to test them all */
+79
modules/rostests/apitests/include/apitest_guard.h
··· 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 10 + AllocateGuarded( 11 + _In_ SIZE_T SizeRequested) 12 + { 13 + NTSTATUS Status; 14 + SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 15 + PVOID VirtualMemory = NULL; 16 + PCHAR StartOfBuffer; 17 + 18 + Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 19 + 20 + if (!NT_SUCCESS(Status)) 21 + return NULL; 22 + 23 + Size -= PAGE_SIZE; 24 + if (Size) 25 + { 26 + Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 27 + if (!NT_SUCCESS(Status)) 28 + { 29 + Size = 0; 30 + Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 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 45 + FreeGuarded( 46 + _In_ PVOID Pointer) 47 + { 48 + NTSTATUS Status; 49 + PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 50 + SIZE_T Size = 0; 51 + 52 + Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 53 + ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 54 + } 55 + 56 + static 57 + inline 58 + VOID 59 + MakeReadOnly( 60 + PVOID Pointer, 61 + SIZE_T SizeRequested) 62 + { 63 + NTSTATUS Status; 64 + SIZE_T Size = PAGE_ROUND_UP(SizeRequested); 65 + PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 66 + 67 + if (Size) 68 + { 69 + Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 70 + if (!NT_SUCCESS(Status)) 71 + { 72 + Size = 0; 73 + Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 74 + ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 75 + } 76 + } 77 + } 78 + 79 + #endif /* _APITEST_GUARD_H */
-47
modules/rostests/apitests/ntdll/RtlBitmap.c
··· 4 4 5 5 static BOOL IsBroken = FALSE; 6 6 7 - static 8 - PVOID 9 - AllocateGuarded( 10 - _In_ SIZE_T SizeRequested) 11 - { 12 - NTSTATUS Status; 13 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 14 - PVOID VirtualMemory = NULL; 15 - PCHAR StartOfBuffer; 16 - 17 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 18 - 19 - if (!NT_SUCCESS(Status)) 20 - return NULL; 21 - 22 - Size -= PAGE_SIZE; 23 - if (Size) 24 - { 25 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 26 - if (!NT_SUCCESS(Status)) 27 - { 28 - Size = 0; 29 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 30 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 31 - return NULL; 32 - } 33 - } 34 - 35 - StartOfBuffer = VirtualMemory; 36 - StartOfBuffer += Size - SizeRequested; 37 - 38 - return StartOfBuffer; 39 - } 40 - 41 - static 42 - VOID 43 - FreeGuarded( 44 - _In_ PVOID Pointer) 45 - { 46 - NTSTATUS Status; 47 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 48 - SIZE_T Size = 0; 49 - 50 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 51 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 52 - } 53 - 54 7 void 55 8 Test_RtlFindMostSignificantBit(void) 56 9 {
-47
modules/rostests/apitests/ntdll/RtlDeleteAce.c
··· 8 8 #include "precomp.h" 9 9 10 10 static 11 - PVOID 12 - AllocateGuarded( 13 - _In_ SIZE_T SizeRequested) 14 - { 15 - NTSTATUS Status; 16 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 17 - PVOID VirtualMemory = NULL; 18 - PCHAR StartOfBuffer; 19 - 20 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 21 - 22 - if (!NT_SUCCESS(Status)) 23 - return NULL; 24 - 25 - Size -= PAGE_SIZE; 26 - if (Size) 27 - { 28 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 29 - if (!NT_SUCCESS(Status)) 30 - { 31 - Size = 0; 32 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 33 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 34 - return NULL; 35 - } 36 - } 37 - 38 - StartOfBuffer = VirtualMemory; 39 - StartOfBuffer += Size - SizeRequested; 40 - 41 - return StartOfBuffer; 42 - } 43 - 44 - static 45 - VOID 46 - FreeGuarded( 47 - _In_ PVOID Pointer) 48 - { 49 - NTSTATUS Status; 50 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 51 - SIZE_T Size = 0; 52 - 53 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 54 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 55 - } 56 - 57 - static 58 11 PACL 59 12 MakeAcl( 60 13 _In_ ULONG AceCount,
-69
modules/rostests/apitests/ntdll/RtlDetermineDosPathNameType.c
··· 30 30 //= (PVOID)0x7c830669; 31 31 ; 32 32 33 - static 34 - PVOID 35 - AllocateGuarded( 36 - SIZE_T SizeRequested) 37 - { 38 - NTSTATUS Status; 39 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 40 - PVOID VirtualMemory = NULL; 41 - PCHAR StartOfBuffer; 42 - 43 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 44 - 45 - if (!NT_SUCCESS(Status)) 46 - return NULL; 47 - 48 - Size -= PAGE_SIZE; 49 - if (Size) 50 - { 51 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 52 - if (!NT_SUCCESS(Status)) 53 - { 54 - Size = 0; 55 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 56 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 57 - return NULL; 58 - } 59 - } 60 - 61 - StartOfBuffer = VirtualMemory; 62 - StartOfBuffer += Size - SizeRequested; 63 - 64 - return StartOfBuffer; 65 - } 66 - 67 - static 68 - VOID 69 - MakeReadOnly( 70 - PVOID Pointer, 71 - SIZE_T SizeRequested) 72 - { 73 - NTSTATUS Status; 74 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested); 75 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 76 - 77 - if (Size) 78 - { 79 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 80 - if (!NT_SUCCESS(Status)) 81 - { 82 - Size = 0; 83 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 84 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 85 - } 86 - } 87 - } 88 - 89 - static 90 - VOID 91 - FreeGuarded( 92 - PVOID Pointer) 93 - { 94 - NTSTATUS Status; 95 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 96 - SIZE_T Size = 0; 97 - 98 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 99 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 100 - } 101 - 102 33 START_TEST(RtlDetermineDosPathNameType) 103 34 { 104 35 RTL_PATH_TYPE PathType;
-47
modules/rostests/apitests/ntdll/RtlFirstFreeAce.c
··· 8 8 #include "precomp.h" 9 9 10 10 static 11 - PVOID 12 - AllocateGuarded( 13 - _In_ SIZE_T SizeRequested) 14 - { 15 - NTSTATUS Status; 16 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 17 - PVOID VirtualMemory = NULL; 18 - PCHAR StartOfBuffer; 19 - 20 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 21 - 22 - if (!NT_SUCCESS(Status)) 23 - return NULL; 24 - 25 - Size -= PAGE_SIZE; 26 - if (Size) 27 - { 28 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 29 - if (!NT_SUCCESS(Status)) 30 - { 31 - Size = 0; 32 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 33 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 34 - return NULL; 35 - } 36 - } 37 - 38 - StartOfBuffer = VirtualMemory; 39 - StartOfBuffer += Size - SizeRequested; 40 - 41 - return StartOfBuffer; 42 - } 43 - 44 - static 45 - VOID 46 - FreeGuarded( 47 - _In_ PVOID Pointer) 48 - { 49 - NTSTATUS Status; 50 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 51 - SIZE_T Size = 0; 52 - 53 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 54 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 55 - } 56 - 57 - static 58 11 PACL 59 12 MakeAcl( 60 13 _In_ ULONG AceCount,
-47
modules/rostests/apitests/ntdll/RtlImageRvaToVa.c
··· 7 7 8 8 #include "precomp.h" 9 9 10 - static 11 - PVOID 12 - AllocateGuarded( 13 - _In_ SIZE_T SizeRequested) 14 - { 15 - NTSTATUS Status; 16 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 17 - PVOID VirtualMemory = NULL; 18 - PCHAR StartOfBuffer; 19 - 20 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 21 - 22 - if (!NT_SUCCESS(Status)) 23 - return NULL; 24 - 25 - Size -= PAGE_SIZE; 26 - if (Size) 27 - { 28 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 29 - if (!NT_SUCCESS(Status)) 30 - { 31 - Size = 0; 32 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 33 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 34 - return NULL; 35 - } 36 - } 37 - 38 - StartOfBuffer = VirtualMemory; 39 - StartOfBuffer += Size - SizeRequested; 40 - 41 - return StartOfBuffer; 42 - } 43 - 44 - static 45 - VOID 46 - FreeGuarded( 47 - _In_ PVOID Pointer) 48 - { 49 - NTSTATUS Status; 50 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 51 - SIZE_T Size = 0; 52 - 53 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 54 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 55 - } 56 - 57 10 START_TEST(RtlImageRvaToVa) 58 11 { 59 12 PIMAGE_NT_HEADERS NtHeader;
+1
modules/rostests/apitests/ntdll/precomp.h
··· 8 8 #define COM_NO_WINDOWS_H 9 9 10 10 #include <apitest.h> 11 + #include <apitest_guard.h> 11 12 #include <ndk/ntndk.h> 12 13 #include <strsafe.h> 13 14
+1 -47
modules/rostests/apitests/user32/GetUserObjectInformation.c
··· 6 6 */ 7 7 8 8 #include "precomp.h" 9 + #include <apitest_guard.h> 9 10 10 11 #include <ndk/mmfuncs.h> 11 12 #include <ndk/pstypes.h> ··· 28 29 return FALSE; 29 30 } 30 31 return TRUE; 31 - } 32 - 33 - static 34 - PVOID 35 - AllocateGuarded( 36 - SIZE_T SizeRequested) 37 - { 38 - NTSTATUS Status; 39 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 40 - PVOID VirtualMemory = NULL; 41 - PCHAR StartOfBuffer; 42 - 43 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 44 - 45 - if (!NT_SUCCESS(Status)) 46 - return NULL; 47 - 48 - Size -= PAGE_SIZE; 49 - if (Size) 50 - { 51 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 52 - if (!NT_SUCCESS(Status)) 53 - { 54 - Size = 0; 55 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 56 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 57 - return NULL; 58 - } 59 - } 60 - 61 - StartOfBuffer = VirtualMemory; 62 - StartOfBuffer += Size - SizeRequested; 63 - 64 - return StartOfBuffer; 65 - } 66 - 67 - static 68 - VOID 69 - FreeGuarded( 70 - PVOID Pointer) 71 - { 72 - NTSTATUS Status; 73 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 74 - SIZE_T Size = 0; 75 - 76 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 77 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 78 32 } 79 33 80 34 #define xok ok // Make the test succeed on Win2003
+1 -47
modules/rostests/apitests/ws2_32/WSAStartup.c
··· 6 6 */ 7 7 8 8 #include "ws2_32.h" 9 - 10 - static 11 - PVOID 12 - AllocateGuarded( 13 - SIZE_T SizeRequested) 14 - { 15 - NTSTATUS Status; 16 - SIZE_T Size = PAGE_ROUND_UP(SizeRequested + PAGE_SIZE); 17 - PVOID VirtualMemory = NULL; 18 - PCHAR StartOfBuffer; 19 - 20 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_RESERVE, PAGE_NOACCESS); 21 - 22 - if (!NT_SUCCESS(Status)) 23 - return NULL; 24 - 25 - Size -= PAGE_SIZE; 26 - if (Size) 27 - { 28 - Status = NtAllocateVirtualMemory(NtCurrentProcess(), &VirtualMemory, 0, &Size, MEM_COMMIT, PAGE_READWRITE); 29 - if (!NT_SUCCESS(Status)) 30 - { 31 - Size = 0; 32 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 33 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 34 - return NULL; 35 - } 36 - } 37 - 38 - StartOfBuffer = VirtualMemory; 39 - StartOfBuffer += Size - SizeRequested; 40 - 41 - return StartOfBuffer; 42 - } 43 - 44 - static 45 - VOID 46 - FreeGuarded( 47 - PVOID Pointer) 48 - { 49 - NTSTATUS Status; 50 - PVOID VirtualMemory = (PVOID)PAGE_ROUND_DOWN((SIZE_T)Pointer); 51 - SIZE_T Size = 0; 52 - 53 - Status = NtFreeVirtualMemory(NtCurrentProcess(), &VirtualMemory, &Size, MEM_RELEASE); 54 - ok(Status == STATUS_SUCCESS, "Status = %lx\n", Status); 55 - } 9 + #include <apitest_guard.h> 56 10 57 11 static 58 12 BOOLEAN