Module: wine Branch: master Commit: 27b9a2c62140a45020e79254841c56e691a5874e URL: https://source.winehq.org/git/wine.git/?a=commit;h=27b9a2c62140a45020e792548...
Author: Alexandre Julliard julliard@winehq.org Date: Wed Feb 10 11:30:34 2021 +0100
ntdll/tests: Add some tests for NtQueryVirtualMemory(MemorySectionName).
Partly based on a patch by Dmitry Timoshkov.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/ntdll/tests/info.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-)
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c index 405b628d712..c848248fae3 100644 --- a/dlls/ntdll/tests/info.c +++ b/dlls/ntdll/tests/info.c @@ -2196,7 +2196,7 @@ static void test_threadstack(void) static void test_queryvirtualmemory(void) { NTSTATUS status; - SIZE_T readcount; + SIZE_T readcount, prev; static const char teststring[] = "test string"; static char datatestbuf[42] = "abc"; static char rwtestbuf[42]; @@ -2204,6 +2204,8 @@ static void test_queryvirtualmemory(void) char stackbuf[42]; HMODULE module; void *user_shared_data = (void *)0x7ffe0000; + char buffer[1024]; + MEMORY_SECTION_NAME *name = (MEMORY_SECTION_NAME *)buffer;
module = GetModuleHandleA( "ntdll.dll" ); status = pNtQueryVirtualMemory(NtCurrentProcess(), module, MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION), &readcount); @@ -2286,6 +2288,82 @@ static void test_queryvirtualmemory(void) /* check error code when len is less than MEMORY_BASIC_INFORMATION size */ status = pNtQueryVirtualMemory(NtCurrentProcess(), GetProcessHeap(), MemoryBasicInformation, &mbi, sizeof(MEMORY_BASIC_INFORMATION) - 1, &readcount); ok(status == STATUS_INFO_LENGTH_MISMATCH, "Expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status); + + module = GetModuleHandleA( "ntdll.dll" ); + memset(buffer, 0xcc, sizeof(buffer)); + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory(NtCurrentProcess(), module, MemorySectionName, + name, sizeof(*name) + 16, &readcount); + ok(status == STATUS_BUFFER_OVERFLOW, "got %08x\n", status); + ok(name->SectionFileName.Length == 0xcccc || broken(!name->SectionFileName.Length), /* vista64 */ + "Wrong len %u\n", name->SectionFileName.Length); + ok(readcount > sizeof(*name), "Wrong count %lu\n", readcount); + + memset(buffer, 0xcc, sizeof(buffer)); + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory(NtCurrentProcess(), (char *)module + 1234, MemorySectionName, + name, sizeof(buffer), &readcount); + ok(status == STATUS_SUCCESS, "got %08x\n", status); + ok(name->SectionFileName.Buffer == (WCHAR *)(name + 1), "Wrong ptr %p/%p\n", + name->SectionFileName.Buffer, name + 1 ); + ok(name->SectionFileName.Length != 0xcccc, "Wrong len %u\n", name->SectionFileName.Length); + ok(name->SectionFileName.MaximumLength == name->SectionFileName.Length + sizeof(WCHAR), + "Wrong maxlen %u/%u\n", name->SectionFileName.MaximumLength, name->SectionFileName.Length); + ok(readcount == sizeof(name->SectionFileName) + name->SectionFileName.MaximumLength, + "Wrong count %lu/%u\n", readcount, name->SectionFileName.MaximumLength); + ok( !name->SectionFileName.Buffer[name->SectionFileName.Length / sizeof(WCHAR)], + "buffer not null-terminated\n" ); + + memset(buffer, 0xcc, sizeof(buffer)); + status = pNtQueryVirtualMemory(NtCurrentProcess(), (char *)module + 1234, MemorySectionName, + name, sizeof(buffer), NULL); + ok(status == STATUS_SUCCESS, "got %08x\n", status); + + status = pNtQueryVirtualMemory(NtCurrentProcess(), (char *)module + 1234, MemorySectionName, + NULL, sizeof(buffer), NULL); + ok(status == STATUS_ACCESS_VIOLATION, "got %08x\n", status); + + memset(buffer, 0xcc, sizeof(buffer)); + prev = readcount; + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory(NtCurrentProcess(), (char *)module + 321, MemorySectionName, + name, sizeof(*name) - 1, &readcount); + ok(status == STATUS_INFO_LENGTH_MISMATCH, "got %08x\n", status); + ok(name->SectionFileName.Length == 0xcccc, "Wrong len %u\n", name->SectionFileName.Length); + ok(readcount == prev, "Wrong count %lu\n", readcount); + + memset(buffer, 0xcc, sizeof(buffer)); + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory((HANDLE)0xdead, (char *)module + 1234, MemorySectionName, + name, sizeof(buffer), &readcount); + ok(status == STATUS_INVALID_HANDLE, "got %08x\n", status); + ok(readcount == 0xdeadbeef || broken(readcount == 1024 + sizeof(*name)), /* wow64 */ + "Wrong count %lu\n", readcount); + + memset(buffer, 0xcc, sizeof(buffer)); + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory(NtCurrentProcess(), buffer, MemorySectionName, + name, sizeof(buffer), &readcount); + ok(status == STATUS_INVALID_ADDRESS, "got %08x\n", status); + ok(name->SectionFileName.Length == 0xcccc, "Wrong len %u\n", name->SectionFileName.Length); + ok(readcount == 0xdeadbeef || broken(readcount == 1024 + sizeof(*name)), /* wow64 */ + "Wrong count %lu\n", readcount); + + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory(NtCurrentProcess(), (void *)0x1234, MemorySectionName, + name, sizeof(buffer), &readcount); + ok(status == STATUS_INVALID_ADDRESS, "got %08x\n", status); + ok(name->SectionFileName.Length == 0xcccc, "Wrong len %u\n", name->SectionFileName.Length); + ok(readcount == 0xdeadbeef || broken(readcount == 1024 + sizeof(*name)), /* wow64 */ + "Wrong count %lu\n", readcount); + + readcount = 0xdeadbeef; + status = pNtQueryVirtualMemory(NtCurrentProcess(), (void *)0x1234, MemorySectionName, + name, sizeof(*name) - 1, &readcount); + ok(status == STATUS_INVALID_ADDRESS, "got %08x\n", status); + ok(name->SectionFileName.Length == 0xcccc, "Wrong len %u\n", name->SectionFileName.Length); + ok(readcount == 0xdeadbeef || broken(readcount == 15), /* wow64 */ + "Wrong count %lu\n", readcount); }
static void test_affinity(void)