[PATCH 2/6] ntoskrnl/tests: Retrieve test global variables from a memory section.
Zebediah Figura
z.figura12 at gmail.com
Tue Apr 6 22:42:21 CDT 2021
Signed-off-by: Zebediah Figura <z.figura12 at gmail.com>
---
dlls/ntoskrnl.exe/ntoskrnl.exe.spec | 6 +++---
dlls/ntoskrnl.exe/tests/driver.c | 10 +++-------
dlls/ntoskrnl.exe/tests/driver.h | 6 +++++-
dlls/ntoskrnl.exe/tests/driver_netio.c | 5 -----
dlls/ntoskrnl.exe/tests/ntoskrnl.c | 27 ++++++++++++++++----------
dlls/ntoskrnl.exe/tests/utils.h | 26 ++++++++++++++++++++++++-
6 files changed, 53 insertions(+), 27 deletions(-)
diff --git a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec
index b6808c2fa38..bdb3687cfe2 100644
--- a/dlls/ntoskrnl.exe/ntoskrnl.exe.spec
+++ b/dlls/ntoskrnl.exe/ntoskrnl.exe.spec
@@ -1430,7 +1430,7 @@
@ stdcall -private ZwLockFile(long long ptr ptr ptr ptr ptr ptr long long) NtLockFile
@ stdcall -private ZwLockVirtualMemory(long ptr ptr long) NtLockVirtualMemory
@ stdcall ZwMakeTemporaryObject(long) NtMakeTemporaryObject
-@ stdcall -private ZwMapViewOfSection(long long ptr long long ptr ptr long long long) NtMapViewOfSection
+@ stdcall ZwMapViewOfSection(long long ptr long long ptr ptr long long long) NtMapViewOfSection
@ stdcall -private ZwNotifyChangeDirectoryFile(long long ptr ptr ptr ptr long long long) NtNotifyChangeDirectoryFile
@ stdcall -private ZwNotifyChangeKey(long long ptr ptr ptr long long ptr long long) NtNotifyChangeKey
@ stdcall ZwOpenDirectoryObject(ptr long ptr) NtOpenDirectoryObject
@@ -1444,7 +1444,7 @@
@ stdcall -private ZwOpenProcess(ptr long ptr ptr) NtOpenProcess
@ stdcall -private ZwOpenProcessToken(long long ptr) NtOpenProcessToken
@ stdcall -private ZwOpenProcessTokenEx(long long long ptr) NtOpenProcessTokenEx
-@ stdcall -private ZwOpenSection(ptr long ptr) NtOpenSection
+@ stdcall ZwOpenSection(ptr long ptr) NtOpenSection
@ stdcall -private ZwOpenSymbolicLinkObject(ptr long ptr) NtOpenSymbolicLinkObject
@ stdcall -private ZwOpenThread(ptr long ptr ptr) NtOpenThread
@ stdcall -private ZwOpenThreadToken(long long long ptr) NtOpenThreadToken
@@ -1520,7 +1520,7 @@
@ stdcall -private ZwUnloadKey(ptr) NtUnloadKey
@ stdcall -private ZwUnlockFile(long ptr ptr ptr ptr) NtUnlockFile
@ stdcall -private ZwUnlockVirtualMemory(long ptr ptr long) NtUnlockVirtualMemory
-@ stdcall -private ZwUnmapViewOfSection(long ptr) NtUnmapViewOfSection
+@ stdcall ZwUnmapViewOfSection(long ptr) NtUnmapViewOfSection
@ stdcall -private ZwWaitForMultipleObjects(long ptr long long ptr) NtWaitForMultipleObjects
@ stdcall ZwWaitForSingleObject(long long ptr) NtWaitForSingleObject
@ stdcall ZwWriteFile(long long ptr ptr ptr ptr long ptr ptr) NtWriteFile
diff --git a/dlls/ntoskrnl.exe/tests/driver.c b/dlls/ntoskrnl.exe/tests/driver.c
index 1d78f576ecf..c5e0bdf754f 100644
--- a/dlls/ntoskrnl.exe/tests/driver.c
+++ b/dlls/ntoskrnl.exe/tests/driver.c
@@ -1990,7 +1990,7 @@ static void test_dpc(void)
KeRevertToUserAffinityThread();
}
-static void test_process_memory(const struct test_input *test_input)
+static void test_process_memory(const struct main_test_input *test_input)
{
NTSTATUS (WINAPI *pMmCopyVirtualMemory)(PEPROCESS fromprocess, void *fromaddress, PEPROCESS toprocess,
void *toaddress, SIZE_T bufsize, KPROCESSOR_MODE mode, SIZE_T *copied);
@@ -2044,7 +2044,7 @@ static void test_process_memory(const struct test_input *test_input)
win_skip("MmCopyVirtualMemory is not available.\n");
}
- if (!test_input->running_under_wine)
+ if (!running_under_wine)
{
KeStackAttachProcess((PKPROCESS)process, &state);
todo_wine ok(!strcmp(teststr, (char *)(base + test_input->teststr_offset)),
@@ -2107,7 +2107,7 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
{
ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
void *buffer = irp->AssociatedIrp.SystemBuffer;
- struct test_input *test_input = (struct test_input *)buffer;
+ struct main_test_input *test_input = (struct main_test_input *)buffer;
NTSTATUS status;
if (!buffer)
@@ -2115,10 +2115,6 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
if (length < sizeof(failures))
return STATUS_BUFFER_TOO_SMALL;
- running_under_wine = test_input->running_under_wine;
- winetest_debug = test_input->winetest_debug;
- winetest_report_success = test_input->winetest_report_success;
-
if ((status = winetest_init()))
return status;
diff --git a/dlls/ntoskrnl.exe/tests/driver.h b/dlls/ntoskrnl.exe/tests/driver.h
index d55dd95cf20..cdf706b9830 100644
--- a/dlls/ntoskrnl.exe/tests/driver.h
+++ b/dlls/ntoskrnl.exe/tests/driver.h
@@ -38,11 +38,15 @@
static const char teststr[] = "Wine is not an emulator";
-struct test_input
+struct test_data
{
int running_under_wine;
int winetest_report_success;
int winetest_debug;
+};
+
+struct main_test_input
+{
DWORD process_id;
SIZE_T teststr_offset;
ULONG64 *modified_value;
diff --git a/dlls/ntoskrnl.exe/tests/driver_netio.c b/dlls/ntoskrnl.exe/tests/driver_netio.c
index 98392c9c7fd..55b5688ff53 100644
--- a/dlls/ntoskrnl.exe/tests/driver_netio.c
+++ b/dlls/ntoskrnl.exe/tests/driver_netio.c
@@ -467,7 +467,6 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
{
ULONG length = stack->Parameters.DeviceIoControl.OutputBufferLength;
void *buffer = irp->AssociatedIrp.SystemBuffer;
- struct test_input *test_input = buffer;
NTSTATUS status;
if (!buffer)
@@ -475,10 +474,6 @@ static NTSTATUS main_test(DEVICE_OBJECT *device, IRP *irp, IO_STACK_LOCATION *st
if (length < sizeof(failures))
return STATUS_BUFFER_TOO_SMALL;
- running_under_wine = test_input->running_under_wine;
- winetest_debug = test_input->winetest_debug;
- winetest_report_success = test_input->winetest_report_success;
-
if ((status = winetest_init()))
return status;
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
index 4667915f621..92cbfa6a329 100644
--- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c
+++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c
@@ -4,6 +4,7 @@
* Copyright 2015 Sebastian Lackner
* Copyright 2015 Michael Müller
* Copyright 2015 Christian Costa
+ * Copyright 2020-2021 Zebediah Figura for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -367,7 +368,7 @@ static ULONG64 modified_value;
static void main_test(void)
{
- struct test_input *test_input;
+ struct main_test_input *test_input;
DWORD written, read;
LONG new_failures;
char buffer[512];
@@ -381,9 +382,6 @@ static void main_test(void)
ok(okfile != INVALID_HANDLE_VALUE, "failed to create file, error %u\n", GetLastError());
test_input = heap_alloc( sizeof(*test_input) );
- test_input->running_under_wine = !strcmp(winetest_platform, "wine");
- test_input->winetest_report_success = winetest_report_success;
- test_input->winetest_debug = winetest_debug;
test_input->process_id = GetCurrentProcessId();
test_input->teststr_offset = (SIZE_T)((BYTE *)&teststr - (BYTE *)NtCurrentTeb()->Peb->ImageBaseAddress);
test_input->modified_value = &modified_value;
@@ -1195,7 +1193,9 @@ START_TEST(ntoskrnl)
WCHAR filename[MAX_PATH], filename2[MAX_PATH];
struct testsign_context ctx;
SC_HANDLE service, service2;
+ struct test_data *data;
BOOL ret, is_wow64;
+ HANDLE mapping;
DWORD written;
pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(GetModuleHandleA("ntdll"), "RtlDosPathNameToNtPathName_U");
@@ -1215,18 +1215,22 @@ START_TEST(ntoskrnl)
if (!testsign_create_cert(&ctx))
return;
+ mapping = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
+ 0, sizeof(*data), "Global\\winetest_ntoskrnl_section");
+ ok(!!mapping, "got error %u\n", GetLastError());
+ data = MapViewOfFile(mapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 1024);
+ data->running_under_wine = !strcmp(winetest_platform, "wine");
+ data->winetest_report_success = winetest_report_success;
+ data->winetest_debug = winetest_debug;
+
subtest("driver");
if (!(service = load_driver(&ctx, filename, L"driver.dll", L"WineTestDriver")))
- {
- testsign_cleanup(&ctx);
- return;
- }
+ goto out;
if (!start_driver(service, FALSE))
{
DeleteFileW(filename);
- testsign_cleanup(&ctx);
- return;
+ goto out;
}
service2 = load_driver(&ctx, filename2, L"driver2.dll", L"WineTestDriver2");
@@ -1265,5 +1269,8 @@ START_TEST(ntoskrnl)
test_pnp_driver(&ctx);
+out:
testsign_cleanup(&ctx);
+ UnmapViewOfFile(data);
+ CloseHandle(mapping);
}
diff --git a/dlls/ntoskrnl.exe/tests/utils.h b/dlls/ntoskrnl.exe/tests/utils.h
index 508346ef9bf..f743e88097a 100644
--- a/dlls/ntoskrnl.exe/tests/utils.h
+++ b/dlls/ntoskrnl.exe/tests/utils.h
@@ -5,6 +5,7 @@
* Copyright 2015 Michael Müller
* Copyright 2015 Christian Costa
* Copyright 2020 Paul Gofman for CodeWeavers
+ * Copyright 2020-2021 Zebediah Figura for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -51,13 +52,36 @@ static inline void WINAPIV kprintf(const char *format, ...)
static inline NTSTATUS winetest_init(void)
{
+ const struct test_data *data;
+ SIZE_T size = sizeof(*data);
OBJECT_ATTRIBUTES attr;
UNICODE_STRING string;
IO_STATUS_BLOCK io;
+ void *addr = NULL;
+ HANDLE section;
+ NTSTATUS ret;
- RtlInitUnicodeString(&string, L"\\??\\C:\\windows\\winetest_ntoskrnl_okfile");
+ RtlInitUnicodeString(&string, L"\\BaseNamedObjects\\winetest_ntoskrnl_section");
/* OBJ_KERNEL_HANDLE is necessary for the file to be accessible from system threads */
InitializeObjectAttributes(&attr, &string, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 0, NULL);
+ if ((ret = ZwOpenSection(§ion, SECTION_MAP_READ, &attr)))
+ return ret;
+
+ if ((ret = ZwMapViewOfSection(section, NtCurrentProcess(), &addr,
+ 0, 0, NULL, &size, ViewUnmap, 0, PAGE_READONLY)))
+ {
+ ZwClose(section);
+ return ret;
+ }
+ data = addr;
+ running_under_wine = data->running_under_wine;
+ winetest_debug = data->winetest_debug;
+ winetest_report_success = data->winetest_report_success;
+
+ ZwUnmapViewOfSection(NtCurrentProcess(), addr);
+ ZwClose(section);
+
+ RtlInitUnicodeString(&string, L"\\??\\C:\\windows\\winetest_ntoskrnl_okfile");
return ZwOpenFile(&okfile, FILE_APPEND_DATA | SYNCHRONIZE, &attr, &io,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SYNCHRONOUS_IO_NONALERT);
}
--
2.30.2
More information about the wine-devel
mailing list