[NTDLL_APITEST] Allow the test to load on Windows XP. ROSTESTS-293

This commit is contained in:
Serge Gautherie 2017-11-30 01:44:40 +01:00 committed by Thomas Faber
parent d73a72c21d
commit 6fe9441d32
No known key found for this signature in database
GPG key ID: 076E7C3D44720826
3 changed files with 47 additions and 21 deletions

View file

@ -15,6 +15,7 @@ enum ServiceCommands
RegisterShimCacheWithoutHandle = 129,
};
static NTSTATUS (NTAPI *pNtApphelpCacheControl)(APPHELPCACHESERVICECLASS, PAPPHELP_CACHE_SERVICE_LOOKUP);
NTSTATUS CallCacheControl(UNICODE_STRING* PathName, BOOLEAN WithMapping, APPHELPCACHESERVICECLASS Service)
{
@ -38,7 +39,7 @@ NTSTATUS CallCacheControl(UNICODE_STRING* PathName, BOOLEAN WithMapping, APPHELP
{
CacheEntry.ImageHandle = INVALID_HANDLE_VALUE;
}
Status = NtApphelpCacheControl(Service, &CacheEntry);
Status = pNtApphelpCacheControl(Service, &CacheEntry);
if (CacheEntry.ImageHandle != INVALID_HANDLE_VALUE)
NtClose(CacheEntry.ImageHandle);
return Status;
@ -64,31 +65,31 @@ void CheckValidation(UNICODE_STRING* PathName)
NTSTATUS Status;
/* Validate the handling of a NULL pointer */
Status = NtApphelpCacheControl(ApphelpCacheServiceRemove, NULL);
Status = pNtApphelpCacheControl(ApphelpCacheServiceRemove, NULL);
ok_ntstatus(Status, STATUS_INVALID_PARAMETER);
Status = NtApphelpCacheControl(ApphelpCacheServiceLookup, NULL);
Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, NULL);
ok_ntstatus(Status, STATUS_INVALID_PARAMETER);
/* Validate the handling of a NULL pointer inside the struct */
Status = NtApphelpCacheControl(ApphelpCacheServiceRemove, &CacheEntry);
Status = pNtApphelpCacheControl(ApphelpCacheServiceRemove, &CacheEntry);
ok_ntstatus(Status, STATUS_INVALID_PARAMETER);
Status = NtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
ok_ntstatus(Status, STATUS_INVALID_PARAMETER);
/* Just call the dump function */
Status = NtApphelpCacheControl(ApphelpCacheServiceDump, NULL);
Status = pNtApphelpCacheControl(ApphelpCacheServiceDump, NULL);
ok_ntstatus(Status, STATUS_SUCCESS);
/* Validate the handling of an invalid handle inside the struct */
CacheEntry.ImageName = *PathName;
CacheEntry.ImageHandle = (HANDLE)2;
Status = NtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
ok_ntstatus(Status, STATUS_NOT_FOUND);
/* Validate the handling of an invalid service number */
Status = NtApphelpCacheControl(999, NULL);
Status = pNtApphelpCacheControl(999, NULL);
ok_ntstatus(Status, STATUS_INVALID_PARAMETER);
Status = NtApphelpCacheControl(999, &CacheEntry);
Status = pNtApphelpCacheControl(999, &CacheEntry);
ok_ntstatus(Status, STATUS_INVALID_PARAMETER);
}
@ -154,7 +155,7 @@ static void RunApphelpCacheControlTests(SC_HANDLE service_handle)
let's test invalid handle behavior */
CacheEntry.ImageName = ntPath;
CacheEntry.ImageHandle = 0;
Status = NtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
ok_ntstatus(Status, STATUS_NOT_FOUND);
/* re-add it for the next test */
@ -162,7 +163,7 @@ static void RunApphelpCacheControlTests(SC_HANDLE service_handle)
Status = CallCacheControl(&ntPath, TRUE, ApphelpCacheServiceLookup);
ok_ntstatus(Status, STATUS_SUCCESS);
CacheEntry.ImageHandle = (HANDLE)1;
Status = NtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
ok_ntstatus(Status, STATUS_NOT_FOUND);
/* and again */
@ -170,7 +171,7 @@ static void RunApphelpCacheControlTests(SC_HANDLE service_handle)
Status = CallCacheControl(&ntPath, TRUE, ApphelpCacheServiceLookup);
ok_ntstatus(Status, STATUS_SUCCESS);
CacheEntry.ImageHandle = (HANDLE)0x80000000;
Status = NtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
Status = pNtApphelpCacheControl(ApphelpCacheServiceLookup, &CacheEntry);
ok_ntstatus(Status, STATUS_NOT_FOUND);
RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer);
@ -343,6 +344,14 @@ START_TEST(NtApphelpCacheControl)
win_skip("RegisterServiceCtrlHandlerExA not available, skipping tests\n");
return;
}
pNtApphelpCacheControl = (void*)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtApphelpCacheControl");
if (!pNtApphelpCacheControl)
{
win_skip("NtApphelpCacheControl not available, skipping tests\n");
return;
}
argc = winetest_get_mainargs(&argv);
if(argc < 3)
{

View file

@ -25,6 +25,7 @@
#endif
static NTSTATUS (NTAPI *pNtUnloadKey2)(POBJECT_ATTRIBUTES, ULONG);
static BOOLEAN
RetrieveCurrentModuleNTDirectory(
@ -381,8 +382,12 @@ DisconnectRegistry(
OBJ_CASE_INSENSITIVE,
RootKey,
NULL);
// return NtUnloadKey(&ObjectAttributes);
return NtUnloadKey2(&ObjectAttributes, Flags);
if (!pNtUnloadKey2)
{
win_skip("NtUnloadKey2 unavailable, using NtUnloadKey. Flags %lu\n", Flags);
return NtUnloadKey(&ObjectAttributes);
}
return pNtUnloadKey2(&ObjectAttributes, Flags);
}
@ -409,6 +414,8 @@ START_TEST(NtLoadUnloadKey)
BOOLEAN PrivilegeSet[2] = {FALSE, FALSE};
WCHAR PathBuffer[MAX_PATH];
pNtUnloadKey2 = (PVOID)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "NtUnloadKey2");
/* Retrieve our current directory */
RetrieveCurrentModuleNTDirectory(&NtTestPath);

View file

@ -7,25 +7,35 @@
#include "precomp.h"
static NTSTATUS (NTAPI *pRtlCopyMappedMemory)(PVOID, const VOID *, SIZE_T);
START_TEST(RtlCopyMappedMemory)
{
NTSTATUS Status;
UCHAR Buffer1[32];
UCHAR Buffer2[32];
StartSeh() RtlCopyMappedMemory(NULL, NULL, 1); EndSeh(STATUS_ACCESS_VIOLATION);
StartSeh() RtlCopyMappedMemory(Buffer1, NULL, 1); EndSeh(STATUS_ACCESS_VIOLATION);
StartSeh() RtlCopyMappedMemory(NULL, Buffer1, 1); EndSeh(STATUS_ACCESS_VIOLATION);
pRtlCopyMappedMemory = (PVOID)GetProcAddress(GetModuleHandleW(L"ntdll.dll"),
"RtlCopyMappedMemory");
if (!pRtlCopyMappedMemory)
{
win_skip("RtlCopyMappedMemory (NT >= 5.2 API) not available\n");
return;
}
StartSeh() pRtlCopyMappedMemory(NULL, NULL, 1); EndSeh(STATUS_ACCESS_VIOLATION);
StartSeh() pRtlCopyMappedMemory(Buffer1, NULL, 1); EndSeh(STATUS_ACCESS_VIOLATION);
StartSeh() pRtlCopyMappedMemory(NULL, Buffer1, 1); EndSeh(STATUS_ACCESS_VIOLATION);
StartSeh()
Status = RtlCopyMappedMemory(NULL, NULL, 0);
Status = pRtlCopyMappedMemory(NULL, NULL, 0);
EndSeh(STATUS_SUCCESS);
ok(Status == STATUS_SUCCESS, "RtlCopyMappedMemory returned %lx\n", Status);
RtlFillMemory(Buffer1, sizeof(Buffer1), 0x11);
RtlFillMemory(Buffer2, sizeof(Buffer2), 0x22);
StartSeh()
Status = RtlCopyMappedMemory(Buffer1, Buffer2, sizeof(Buffer1));
Status = pRtlCopyMappedMemory(Buffer1, Buffer2, sizeof(Buffer1));
EndSeh(STATUS_SUCCESS);
ok(Status == STATUS_SUCCESS, "RtlCopyMappedMemory returned %lx\n", Status);
ok(RtlCompareMemory(Buffer1, Buffer2, sizeof(Buffer1)) == sizeof(Buffer1), "Data not copied\n");