2005-06-27 21:47:48 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for PSAPI
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Felix Nawothnig
|
2012-01-27 08:33:19 +01:00
|
|
|
* Copyright (C) 2012 Dmitry Timoshkov
|
2005-06-27 21:47:48 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-27 21:47:48 +02:00
|
|
|
*/
|
|
|
|
|
2013-02-20 13:17:12 +01:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2012-02-03 10:23:47 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winnls.h"
|
2018-05-29 16:33:03 +02:00
|
|
|
#include "winuser.h"
|
2018-07-06 00:05:36 +02:00
|
|
|
#define PSAPI_VERSION 1
|
2005-06-27 21:47:48 +02:00
|
|
|
#include "psapi.h"
|
2012-02-03 10:23:47 +01:00
|
|
|
#include "wine/test.h"
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2014-11-14 06:47:13 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
|
2020-03-15 01:45:10 +01:00
|
|
|
static NTSTATUS (WINAPI *pNtQueryVirtualMemory)(HANDLE, LPCVOID, MEMORY_INFORMATION_CLASS, PVOID, SIZE_T, SIZE_T *);
|
2018-05-29 16:33:03 +02:00
|
|
|
static BOOL (WINAPI *pIsWow64Process)(HANDLE, BOOL *);
|
|
|
|
static BOOL (WINAPI *pWow64DisableWow64FsRedirection)(void **);
|
|
|
|
static BOOL (WINAPI *pWow64RevertWow64FsRedirection)(void *);
|
2020-01-24 21:19:40 +01:00
|
|
|
static BOOL (WINAPI *pQueryWorkingSetEx)(HANDLE, PVOID, DWORD);
|
2018-05-29 16:33:03 +02:00
|
|
|
|
|
|
|
static BOOL wow64;
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
static BOOL init_func_ptrs(void)
|
2005-06-27 21:47:48 +02:00
|
|
|
{
|
2014-11-14 06:47:13 +01:00
|
|
|
pNtQuerySystemInformation = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQuerySystemInformation");
|
2013-10-24 00:30:04 +02:00
|
|
|
pNtQueryVirtualMemory = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQueryVirtualMemory");
|
2018-05-29 16:33:03 +02:00
|
|
|
pIsWow64Process = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsWow64Process");
|
|
|
|
pWow64DisableWow64FsRedirection = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "Wow64DisableWow64FsRedirection");
|
|
|
|
pWow64RevertWow64FsRedirection = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "Wow64RevertWow64FsRedirection");
|
2020-01-24 21:19:40 +01:00
|
|
|
pQueryWorkingSetEx = (void *)GetProcAddress(GetModuleHandleA("psapi.dll"), "QueryWorkingSetEx");
|
2005-06-27 21:47:48 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-07-06 00:05:37 +02:00
|
|
|
static HANDLE hpSR, hpQI, hpVR, hpQV;
|
2005-06-27 21:47:48 +02:00
|
|
|
static const HANDLE hBad = (HANDLE)0xdeadbeef;
|
|
|
|
|
|
|
|
static void test_EnumProcesses(void)
|
|
|
|
{
|
2010-10-07 11:53:04 +02:00
|
|
|
DWORD pid, ret, cbUsed = 0xdeadbeef;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcesses(NULL, 0, &cbUsed);
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
|
|
|
ok(cbUsed == 0, "cbUsed=%d\n", cbUsed);
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcesses(&pid, 4, &cbUsed);
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
|
|
|
ok(cbUsed == 4, "cbUsed=%d\n", cbUsed);
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_EnumProcessModules(void)
|
|
|
|
{
|
2018-05-29 16:33:03 +02:00
|
|
|
char buffer[200] = "C:\\windows\\system32\\notepad.exe";
|
|
|
|
PROCESS_INFORMATION pi = {0};
|
|
|
|
STARTUPINFOA si = {0};
|
|
|
|
void *cookie;
|
2018-01-11 16:27:45 +01:00
|
|
|
HMODULE hMod;
|
2010-10-07 11:53:04 +02:00
|
|
|
DWORD ret, cbNeeded = 0xdeadbeef;
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
EnumProcessModules(NULL, NULL, 0, &cbNeeded);
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
EnumProcessModules(hpQI, NULL, 0, &cbNeeded);
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
|
|
|
|
2012-06-21 23:11:22 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-01-11 16:27:45 +01:00
|
|
|
hMod = (void *)0xdeadbeef;
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(hpQI, &hMod, sizeof(HMODULE), NULL);
|
2012-06-21 23:11:22 +02:00
|
|
|
ok(!ret, "succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-01-11 16:27:45 +01:00
|
|
|
hMod = (void *)0xdeadbeef;
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(hpQV, &hMod, sizeof(HMODULE), NULL);
|
2012-06-21 23:11:22 +02:00
|
|
|
ok(!ret, "succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_NOACCESS, "expected error=ERROR_NOACCESS but got %d\n", GetLastError());
|
2018-01-19 15:50:38 +01:00
|
|
|
ok(hMod == GetModuleHandleA(NULL),
|
2018-01-11 16:27:45 +01:00
|
|
|
"hMod=%p GetModuleHandleA(NULL)=%p\n", hMod, GetModuleHandleA(NULL));
|
2012-06-21 23:11:22 +02:00
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(hpQV, NULL, 0, &cbNeeded);
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
|
|
|
|
2015-07-02 04:41:05 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(hpQV, NULL, sizeof(HMODULE), &cbNeeded);
|
2015-07-02 04:41:05 +02:00
|
|
|
ok(!ret, "succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_NOACCESS, "expected error=ERROR_NOACCESS but got %d\n", GetLastError());
|
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-01-11 16:27:45 +01:00
|
|
|
hMod = (void *)0xdeadbeef;
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(hpQV, &hMod, sizeof(HMODULE), &cbNeeded);
|
2018-01-11 16:27:45 +01:00
|
|
|
ok(ret == 1, "got %d, failed with %d\n", ret, GetLastError());
|
2013-10-24 00:30:04 +02:00
|
|
|
ok(hMod == GetModuleHandleA(NULL),
|
|
|
|
"hMod=%p GetModuleHandleA(NULL)=%p\n", hMod, GetModuleHandleA(NULL));
|
2011-08-26 16:09:03 +02:00
|
|
|
ok(cbNeeded % sizeof(hMod) == 0, "not a multiple of sizeof(HMODULE) cbNeeded=%d\n", cbNeeded);
|
2018-05-29 16:33:03 +02:00
|
|
|
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcess failed: %u\n", GetLastError());
|
|
|
|
|
2019-10-30 22:35:35 +01:00
|
|
|
ret = WaitForInputIdle(pi.hProcess, 5000);
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(!ret, "wait timed out\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hMod = NULL;
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(pi.hProcess, &hMod, sizeof(HMODULE), &cbNeeded);
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(ret == 1, "got %d, error %u\n", ret, GetLastError());
|
|
|
|
ok(!!hMod, "expected non-NULL module\n");
|
|
|
|
ok(cbNeeded % sizeof(hMod) == 0, "got %u\n", cbNeeded);
|
|
|
|
|
|
|
|
TerminateProcess(pi.hProcess, 0);
|
|
|
|
|
|
|
|
if (sizeof(void *) == 8)
|
|
|
|
{
|
2018-05-29 16:33:06 +02:00
|
|
|
MODULEINFO info;
|
2018-05-29 16:33:04 +02:00
|
|
|
char name[40];
|
|
|
|
|
2018-05-29 16:33:03 +02:00
|
|
|
strcpy(buffer, "C:\\windows\\syswow64\\notepad.exe");
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
ok(ret, "CreateProcess failed: %u\n", GetLastError());
|
|
|
|
|
2019-10-30 22:35:35 +01:00
|
|
|
ret = WaitForInputIdle(pi.hProcess, 5000);
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(!ret, "wait timed out\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
hMod = NULL;
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(pi.hProcess, &hMod, sizeof(HMODULE), &cbNeeded);
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(ret == 1, "got %d, error %u\n", ret, GetLastError());
|
|
|
|
ok(!!hMod, "expected non-NULL module\n");
|
|
|
|
ok(cbNeeded % sizeof(hMod) == 0, "got %u\n", cbNeeded);
|
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleBaseNameA(pi.hProcess, hMod, name, sizeof(name));
|
2018-05-29 16:33:04 +02:00
|
|
|
ok(ret, "got error %u\n", GetLastError());
|
|
|
|
ok(!strcmp(name, "notepad.exe"), "got %s\n", name);
|
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(pi.hProcess, hMod, name, sizeof(name));
|
2018-05-29 16:33:05 +02:00
|
|
|
ok(ret, "got error %u\n", GetLastError());
|
|
|
|
todo_wine
|
|
|
|
ok(!strcmp(name, buffer), "got %s\n", name);
|
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleInformation(pi.hProcess, hMod, &info, sizeof(info));
|
2018-05-29 16:33:06 +02:00
|
|
|
ok(ret, "got error %u\n", GetLastError());
|
|
|
|
ok(info.lpBaseOfDll == hMod, "expected %p, got %p\n", hMod, info.lpBaseOfDll);
|
|
|
|
ok(info.SizeOfImage, "image size was 0\n");
|
|
|
|
ok(info.EntryPoint >= info.lpBaseOfDll, "got entry point %p\n", info.EntryPoint);
|
|
|
|
|
2018-05-29 16:33:03 +02:00
|
|
|
TerminateProcess(pi.hProcess, 0);
|
|
|
|
}
|
|
|
|
else if (wow64)
|
|
|
|
{
|
|
|
|
pWow64DisableWow64FsRedirection(&cookie);
|
|
|
|
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
|
|
|
|
pWow64RevertWow64FsRedirection(cookie);
|
|
|
|
ok(ret, "CreateProcess failed: %u\n", GetLastError());
|
|
|
|
|
2019-10-30 22:35:35 +01:00
|
|
|
ret = WaitForInputIdle(pi.hProcess, 5000);
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(!ret, "wait timed out\n");
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = EnumProcessModules(pi.hProcess, &hMod, sizeof(HMODULE), &cbNeeded);
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(!ret, "got %d\n", ret);
|
2018-06-22 16:46:26 +02:00
|
|
|
todo_wine
|
2018-05-29 16:33:03 +02:00
|
|
|
ok(GetLastError() == ERROR_PARTIAL_COPY, "got error %u\n", GetLastError());
|
|
|
|
|
|
|
|
TerminateProcess(pi.hProcess, 0);
|
|
|
|
}
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetModuleInformation(void)
|
|
|
|
{
|
2013-10-24 00:30:04 +02:00
|
|
|
HMODULE hMod = GetModuleHandleA(NULL);
|
2005-06-27 21:47:48 +02:00
|
|
|
MODULEINFO info;
|
2010-10-07 11:53:04 +02:00
|
|
|
DWORD ret;
|
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleInformation(NULL, hMod, &info, sizeof(info));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleInformation(hpQI, hMod, &info, sizeof(info));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleInformation(hpQV, hBad, &info, sizeof(info));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleInformation(hpQV, hMod, &info, sizeof(info)-1);
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
|
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleInformation(hpQV, hMod, &info, sizeof(info));
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
|
|
|
ok(info.lpBaseOfDll == hMod, "lpBaseOfDll=%p hMod=%p\n", info.lpBaseOfDll, hMod);
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
2015-09-20 14:43:46 +02:00
|
|
|
static BOOL check_with_margin(SIZE_T perf, SIZE_T sysperf, int margin)
|
|
|
|
{
|
|
|
|
return (perf >= max(sysperf, margin) - margin && perf <= sysperf + margin);
|
|
|
|
}
|
|
|
|
|
2014-11-14 06:47:13 +01:00
|
|
|
static void test_GetPerformanceInfo(void)
|
|
|
|
{
|
|
|
|
PERFORMANCE_INFORMATION info;
|
|
|
|
NTSTATUS status;
|
|
|
|
DWORD size;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetPerformanceInfo(&info, sizeof(info)-1);
|
2014-11-14 06:47:13 +01:00
|
|
|
ok(!ret, "GetPerformanceInfo unexpectedly succeeded\n");
|
|
|
|
ok(GetLastError() == ERROR_BAD_LENGTH, "expected error=ERROR_BAD_LENGTH but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
if (!pNtQuerySystemInformation)
|
|
|
|
win_skip("NtQuerySystemInformation not found, skipping tests\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char performance_buffer[sizeof(SYSTEM_PERFORMANCE_INFORMATION) + 16]; /* larger on w2k8/win7 */
|
|
|
|
SYSTEM_PERFORMANCE_INFORMATION *sys_performance_info = (SYSTEM_PERFORMANCE_INFORMATION *)performance_buffer;
|
|
|
|
SYSTEM_PROCESS_INFORMATION *sys_process_info = NULL, *spi;
|
|
|
|
SYSTEM_BASIC_INFORMATION sys_basic_info;
|
|
|
|
DWORD process_count, handle_count, thread_count;
|
|
|
|
|
|
|
|
/* compare with values from SYSTEM_PERFORMANCE_INFORMATION */
|
|
|
|
size = 0;
|
|
|
|
status = pNtQuerySystemInformation(SystemPerformanceInformation, sys_performance_info, sizeof(performance_buffer), &size);
|
|
|
|
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
|
|
|
|
ok(size >= sizeof(SYSTEM_PERFORMANCE_INFORMATION), "incorrect length %d\n", size);
|
|
|
|
|
2018-07-06 00:05:39 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = GetPerformanceInfo(&info, sizeof(info));
|
|
|
|
ok(ret, "GetPerformanceInfo failed with %d\n", GetLastError());
|
|
|
|
ok(info.cb == sizeof(PERFORMANCE_INFORMATION), "got %d\n", info.cb);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2019-10-19 21:39:58 +02:00
|
|
|
ok(check_with_margin(info.CommitTotal, sys_performance_info->TotalCommittedPages, 2048),
|
2015-09-20 14:43:46 +02:00
|
|
|
"expected approximately %ld but got %d\n", info.CommitTotal, sys_performance_info->TotalCommittedPages);
|
|
|
|
|
|
|
|
ok(check_with_margin(info.CommitLimit, sys_performance_info->TotalCommitLimit, 32),
|
|
|
|
"expected approximately %ld but got %d\n", info.CommitLimit, sys_performance_info->TotalCommitLimit);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2015-09-20 14:43:46 +02:00
|
|
|
ok(check_with_margin(info.CommitPeak, sys_performance_info->PeakCommitment, 32),
|
|
|
|
"expected approximately %ld but got %d\n", info.CommitPeak, sys_performance_info->PeakCommitment);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2019-10-19 21:39:58 +02:00
|
|
|
ok(check_with_margin(info.PhysicalAvailable, sys_performance_info->AvailablePages, 2048),
|
2015-09-20 14:43:46 +02:00
|
|
|
"expected approximately %ld but got %d\n", info.PhysicalAvailable, sys_performance_info->AvailablePages);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
|
|
|
/* TODO: info.SystemCache not checked yet - to which field(s) does this value correspond to? */
|
|
|
|
|
2018-01-01 03:21:15 +01:00
|
|
|
ok(check_with_margin(info.KernelTotal, sys_performance_info->PagedPoolUsage + sys_performance_info->NonPagedPoolUsage, 256),
|
2015-09-20 14:43:46 +02:00
|
|
|
"expected approximately %ld but got %d\n", info.KernelTotal,
|
|
|
|
sys_performance_info->PagedPoolUsage + sys_performance_info->NonPagedPoolUsage);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2018-01-01 03:21:15 +01:00
|
|
|
ok(check_with_margin(info.KernelPaged, sys_performance_info->PagedPoolUsage, 256),
|
2015-09-20 14:43:46 +02:00
|
|
|
"expected approximately %ld but got %d\n", info.KernelPaged, sys_performance_info->PagedPoolUsage);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2017-10-18 07:28:35 +02:00
|
|
|
ok(check_with_margin(info.KernelNonpaged, sys_performance_info->NonPagedPoolUsage, 16),
|
2015-09-20 14:43:46 +02:00
|
|
|
"expected approximately %ld but got %d\n", info.KernelNonpaged, sys_performance_info->NonPagedPoolUsage);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
|
|
|
/* compare with values from SYSTEM_BASIC_INFORMATION */
|
|
|
|
size = 0;
|
|
|
|
status = pNtQuerySystemInformation(SystemBasicInformation, &sys_basic_info, sizeof(sys_basic_info), &size);
|
|
|
|
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
|
|
|
|
ok(size >= sizeof(SYSTEM_BASIC_INFORMATION), "incorrect length %d\n", size);
|
|
|
|
|
|
|
|
ok(info.PhysicalTotal == sys_basic_info.MmNumberOfPhysicalPages,
|
|
|
|
"expected info.PhysicalTotal=%u but got %u\n",
|
|
|
|
sys_basic_info.MmNumberOfPhysicalPages, (ULONG)info.PhysicalTotal);
|
|
|
|
|
|
|
|
ok(info.PageSize == sys_basic_info.PageSize,
|
|
|
|
"expected info.PageSize=%u but got %u\n",
|
|
|
|
sys_basic_info.PageSize, (ULONG)info.PageSize);
|
|
|
|
|
|
|
|
/* compare with values from SYSTEM_PROCESS_INFORMATION */
|
|
|
|
size = 0;
|
|
|
|
status = pNtQuerySystemInformation(SystemProcessInformation, NULL, 0, &size);
|
2015-11-17 05:21:40 +01:00
|
|
|
ok(status == STATUS_INFO_LENGTH_MISMATCH, "expected STATUS_INFO_LENGTH_MISMATCH, got %08x\n", status);
|
2014-11-14 06:47:13 +01:00
|
|
|
ok(size > 0, "incorrect length %d\n", size);
|
|
|
|
while (status == STATUS_INFO_LENGTH_MISMATCH)
|
|
|
|
{
|
|
|
|
sys_process_info = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
ok(sys_process_info != NULL, "failed to allocate memory\n");
|
|
|
|
status = pNtQuerySystemInformation(SystemProcessInformation, sys_process_info, size, &size);
|
|
|
|
if (status == STATUS_SUCCESS) break;
|
|
|
|
HeapFree(GetProcessHeap(), 0, sys_process_info);
|
|
|
|
}
|
|
|
|
ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %08x\n", status);
|
|
|
|
|
|
|
|
process_count = handle_count = thread_count = 0;
|
|
|
|
for (spi = sys_process_info;; spi = (SYSTEM_PROCESS_INFORMATION *)(((char *)spi) + spi->NextEntryOffset))
|
|
|
|
{
|
|
|
|
process_count++;
|
|
|
|
handle_count += spi->HandleCount;
|
|
|
|
thread_count += spi->dwThreadCount;
|
|
|
|
if (spi->NextEntryOffset == 0) break;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, sys_process_info);
|
|
|
|
|
2019-10-19 21:39:58 +02:00
|
|
|
ok(check_with_margin(info.HandleCount, handle_count, 512),
|
2015-09-20 14:43:46 +02:00
|
|
|
"expected approximately %d but got %d\n", info.HandleCount, handle_count);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2015-09-20 14:43:46 +02:00
|
|
|
ok(check_with_margin(info.ProcessCount, process_count, 4),
|
|
|
|
"expected approximately %d but got %d\n", info.ProcessCount, process_count);
|
2014-11-14 06:47:13 +01:00
|
|
|
|
2015-09-20 14:43:46 +02:00
|
|
|
ok(check_with_margin(info.ThreadCount, thread_count, 4),
|
|
|
|
"expected approximately %d but got %d\n", info.ThreadCount, thread_count);
|
2014-11-14 06:47:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-27 21:47:48 +02:00
|
|
|
static void test_GetProcessMemoryInfo(void)
|
|
|
|
{
|
|
|
|
PROCESS_MEMORY_COUNTERS pmc;
|
2010-10-07 11:53:04 +02:00
|
|
|
DWORD ret;
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessMemoryInfo(NULL, &pmc, sizeof(pmc));
|
2012-03-22 09:27:26 +01:00
|
|
|
ok(!ret, "GetProcessMemoryInfo should fail\n");
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessMemoryInfo(hpSR, &pmc, sizeof(pmc));
|
2012-03-22 09:27:26 +01:00
|
|
|
ok(!ret, "GetProcessMemoryInfo should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
2010-10-05 02:56:49 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc)-1);
|
2012-03-22 09:27:26 +01:00
|
|
|
ok(!ret, "GetProcessMemoryInfo should fail\n");
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
|
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessMemoryInfo(hpQI, &pmc, sizeof(pmc));
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
2012-02-03 10:23:47 +01:00
|
|
|
static BOOL nt_get_mapped_file_name(HANDLE process, LPVOID addr, LPWSTR name, DWORD len)
|
|
|
|
{
|
|
|
|
MEMORY_SECTION_NAME *section_name;
|
|
|
|
WCHAR *buf;
|
2012-02-07 04:17:56 +01:00
|
|
|
SIZE_T buf_len, ret_len;
|
2012-02-03 10:23:47 +01:00
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (!pNtQueryVirtualMemory) return FALSE;
|
|
|
|
|
|
|
|
buf_len = len * sizeof(WCHAR) + sizeof(MEMORY_SECTION_NAME);
|
|
|
|
buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buf_len);
|
|
|
|
|
2012-02-07 04:17:56 +01:00
|
|
|
ret_len = 0xdeadbeef;
|
|
|
|
status = pNtQueryVirtualMemory(process, addr, MemorySectionName, buf, buf_len, &ret_len);
|
|
|
|
ok(!status, "NtQueryVirtualMemory error %x\n", status);
|
2012-02-03 10:23:47 +01:00
|
|
|
|
|
|
|
section_name = (MEMORY_SECTION_NAME *)buf;
|
2012-02-07 04:17:56 +01:00
|
|
|
ok(ret_len == section_name->SectionFileName.MaximumLength + sizeof(*section_name), "got %lu, %u\n",
|
|
|
|
ret_len, section_name->SectionFileName.MaximumLength);
|
2012-02-03 10:23:47 +01:00
|
|
|
ok((char *)section_name->SectionFileName.Buffer == (char *)section_name + sizeof(*section_name), "got %p, %p\n",
|
|
|
|
section_name, section_name->SectionFileName.Buffer);
|
|
|
|
ok(section_name->SectionFileName.MaximumLength == section_name->SectionFileName.Length + sizeof(WCHAR), "got %u, %u\n",
|
|
|
|
section_name->SectionFileName.MaximumLength, section_name->SectionFileName.Length);
|
|
|
|
ok(section_name->SectionFileName.Length == lstrlenW(section_name->SectionFileName.Buffer) * sizeof(WCHAR), "got %u, %u\n",
|
|
|
|
section_name->SectionFileName.Length, lstrlenW(section_name->SectionFileName.Buffer));
|
|
|
|
|
|
|
|
memcpy(name, section_name->SectionFileName.Buffer, section_name->SectionFileName.MaximumLength);
|
|
|
|
HeapFree(GetProcessHeap(), 0, buf);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-27 21:47:48 +02:00
|
|
|
static void test_GetMappedFileName(void)
|
|
|
|
{
|
2013-10-24 00:30:04 +02:00
|
|
|
HMODULE hMod = GetModuleHandleA(NULL);
|
2005-06-27 21:47:48 +02:00
|
|
|
char szMapPath[MAX_PATH], szModPath[MAX_PATH], *szMapBaseName;
|
|
|
|
DWORD ret;
|
2012-01-27 08:33:19 +01:00
|
|
|
char *base;
|
|
|
|
char temp_path[MAX_PATH], file_name[MAX_PATH], map_name[MAX_PATH], device_name[MAX_PATH], drive[3];
|
2012-02-03 10:23:47 +01:00
|
|
|
WCHAR map_nameW[MAX_PATH], nt_map_name[MAX_PATH];
|
2012-01-27 08:33:19 +01:00
|
|
|
HANDLE hfile, hmap;
|
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(NULL, hMod, szMapPath, sizeof(szMapPath));
|
2012-03-22 09:27:26 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(hpSR, hMod, szMapPath, sizeof(szMapPath));
|
2012-03-22 09:27:26 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
2010-02-05 11:39:24 +01:00
|
|
|
|
|
|
|
SetLastError( 0xdeadbeef );
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(hpQI, hMod, szMapPath, sizeof(szMapPath));
|
2010-02-05 11:39:24 +01:00
|
|
|
ok( ret || broken(GetLastError() == ERROR_UNEXP_NET_ERR), /* win2k */
|
|
|
|
"GetMappedFileNameA failed with error %u\n", GetLastError() );
|
2012-01-31 14:43:03 +01:00
|
|
|
if (ret)
|
2005-06-27 21:47:48 +02:00
|
|
|
{
|
2012-01-31 14:43:03 +01:00
|
|
|
ok(ret == strlen(szMapPath), "szMapPath=\"%s\" ret=%d\n", szMapPath, ret);
|
|
|
|
ok(szMapPath[0] == '\\', "szMapPath=\"%s\"\n", szMapPath);
|
|
|
|
szMapBaseName = strrchr(szMapPath, '\\'); /* That's close enough for us */
|
|
|
|
ok(szMapBaseName && *szMapBaseName, "szMapPath=\"%s\"\n", szMapPath);
|
|
|
|
if (szMapBaseName)
|
|
|
|
{
|
|
|
|
GetModuleFileNameA(NULL, szModPath, sizeof(szModPath));
|
|
|
|
ok(!strcmp(strrchr(szModPath, '\\'), szMapBaseName),
|
|
|
|
"szModPath=\"%s\" szMapBaseName=\"%s\"\n", szModPath, szMapBaseName);
|
|
|
|
}
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
2012-01-27 08:33:19 +01:00
|
|
|
|
2013-10-24 00:30:04 +02:00
|
|
|
GetTempPathA(MAX_PATH, temp_path);
|
|
|
|
GetTempFileNameA(temp_path, "map", 0, file_name);
|
2012-01-27 08:33:19 +01:00
|
|
|
|
|
|
|
drive[0] = file_name[0];
|
|
|
|
drive[1] = ':';
|
|
|
|
drive[2] = 0;
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-24 00:30:04 +02:00
|
|
|
ret = QueryDosDeviceA(drive, device_name, sizeof(device_name));
|
|
|
|
ok(ret, "QueryDosDeviceA error %d\n", GetLastError());
|
2012-01-27 08:33:19 +01:00
|
|
|
trace("%s -> %s\n", drive, device_name);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-24 00:30:04 +02:00
|
|
|
hfile = CreateFileA(file_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
|
|
|
|
ok(hfile != INVALID_HANDLE_VALUE, "CreateFileA(%s) error %d\n", file_name, GetLastError());
|
2012-01-27 08:33:19 +01:00
|
|
|
SetFilePointer(hfile, 0x4000, NULL, FILE_BEGIN);
|
|
|
|
SetEndOfFile(hfile);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-24 00:30:04 +02:00
|
|
|
hmap = CreateFileMappingA(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
|
|
|
|
ok(hmap != 0, "CreateFileMappingA error %d\n", GetLastError());
|
2012-01-27 08:33:19 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
base = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
ok(base != NULL, "MapViewOfFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base, map_name, 0);
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
2012-12-03 22:55:35 +01:00
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
|
|
|
"wrong error %d\n", GetLastError());
|
2012-01-27 08:33:19 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base, 0, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base, map_name, 1);
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(ret == 1, "GetMappedFileName error %d\n", GetLastError());
|
|
|
|
ok(!map_name[0] || broken(map_name[0] == device_name[0]) /* before win2k */, "expected 0, got %c\n", map_name[0]);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base, map_name, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(ret, "GetMappedFileName error %d\n", GetLastError());
|
2012-02-03 10:23:47 +01:00
|
|
|
ok(ret > strlen(device_name), "map_name should be longer than device_name\n");
|
2021-02-11 11:01:28 +01:00
|
|
|
todo_wine
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(memcmp(map_name, device_name, strlen(device_name)) == 0, "map name does not start with a device name: %s\n", map_name);
|
|
|
|
|
2012-02-03 10:23:47 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameW(GetCurrentProcess(), base, map_nameW, ARRAY_SIZE(map_nameW));
|
2012-02-03 10:23:47 +01:00
|
|
|
ok(ret, "GetMappedFileNameW error %d\n", GetLastError());
|
|
|
|
ok(ret > strlen(device_name), "map_name should be longer than device_name\n");
|
2018-06-08 22:19:05 +02:00
|
|
|
if (nt_get_mapped_file_name(GetCurrentProcess(), base, nt_map_name, ARRAY_SIZE(nt_map_name)))
|
2012-02-03 10:23:47 +01:00
|
|
|
{
|
|
|
|
ok(memcmp(map_nameW, nt_map_name, lstrlenW(map_nameW)) == 0, "map name does not start with a device name: %s\n", map_name);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, map_nameW, -1, map_name, MAX_PATH, NULL, NULL);
|
2021-02-10 16:09:49 +01:00
|
|
|
todo_wine
|
2012-02-03 10:23:47 +01:00
|
|
|
ok(memcmp(map_name, device_name, strlen(device_name)) == 0, "map name does not start with a device name: %s\n", map_name);
|
|
|
|
}
|
|
|
|
|
2012-01-27 08:33:19 +01:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base + 0x2000, map_name, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(ret, "GetMappedFileName error %d\n", GetLastError());
|
2012-02-03 10:23:47 +01:00
|
|
|
ok(ret > strlen(device_name), "map_name should be longer than device_name\n");
|
2021-02-11 11:01:28 +01:00
|
|
|
todo_wine
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(memcmp(map_name, device_name, strlen(device_name)) == 0, "map name does not start with a device name: %s\n", map_name);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base + 0x4000, map_name, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_UNEXP_NET_ERR, "expected ERROR_UNEXP_NET_ERR, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), NULL, map_name, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_UNEXP_NET_ERR, "expected ERROR_UNEXP_NET_ERR, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(0, base, map_name, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
UnmapViewOfFile(base);
|
|
|
|
CloseHandle(hmap);
|
|
|
|
CloseHandle(hfile);
|
2013-10-24 00:30:04 +02:00
|
|
|
DeleteFileA(file_name);
|
2012-01-27 08:33:19 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2013-10-24 00:30:04 +02:00
|
|
|
hmap = CreateFileMappingA(INVALID_HANDLE_VALUE, NULL, PAGE_READONLY | SEC_COMMIT, 0, 4096, NULL);
|
|
|
|
ok(hmap != 0, "CreateFileMappingA error %d\n", GetLastError());
|
2012-01-27 08:33:19 +01:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
base = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
ok(base != NULL, "MapViewOfFile error %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetMappedFileNameA(GetCurrentProcess(), base, map_name, sizeof(map_name));
|
2012-01-27 08:33:19 +01:00
|
|
|
ok(!ret, "GetMappedFileName should fail\n");
|
|
|
|
ok(GetLastError() == ERROR_FILE_INVALID, "expected ERROR_FILE_INVALID, got %d\n", GetLastError());
|
|
|
|
|
|
|
|
UnmapViewOfFile(base);
|
|
|
|
CloseHandle(hmap);
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetProcessImageFileName(void)
|
|
|
|
{
|
2013-10-24 00:30:04 +02:00
|
|
|
HMODULE hMod = GetModuleHandleA(NULL);
|
2005-06-27 21:47:48 +02:00
|
|
|
char szImgPath[MAX_PATH], szMapPath[MAX_PATH];
|
2009-04-06 22:32:33 +02:00
|
|
|
WCHAR szImgPathW[MAX_PATH];
|
2010-10-07 11:53:04 +02:00
|
|
|
DWORD ret, ret1;
|
2005-06-27 21:47:48 +02:00
|
|
|
|
|
|
|
/* This function is available on WinXP+ only */
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
if(!GetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath)))
|
2005-06-27 21:47:48 +02:00
|
|
|
{
|
2009-04-06 22:32:33 +02:00
|
|
|
if(GetLastError() == ERROR_INVALID_FUNCTION) {
|
2008-10-20 22:44:09 +02:00
|
|
|
win_skip("GetProcessImageFileName not implemented\n");
|
2009-04-06 22:32:33 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-02-11 11:01:28 +01:00
|
|
|
ok(0, "failed with %d\n", GetLastError());
|
2009-04-06 22:32:33 +02:00
|
|
|
}
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameA(NULL, szImgPath, sizeof(szImgPath));
|
2011-08-05 09:56:26 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
2010-10-05 02:56:49 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameA(hpSR, szImgPath, sizeof(szImgPath));
|
2011-08-05 09:56:26 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
2010-10-05 02:56:49 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameA(hpQI, szImgPath, 0);
|
2011-08-05 09:56:26 +02:00
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
|
2010-10-05 02:56:49 +02:00
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessImageFileNameA(hpQI, szImgPath, sizeof(szImgPath));
|
|
|
|
ret1 = GetMappedFileNameA(hpQV, hMod, szMapPath, sizeof(szMapPath));
|
2010-10-07 11:53:04 +02:00
|
|
|
if(ret && ret1)
|
|
|
|
{
|
2009-04-06 22:32:33 +02:00
|
|
|
/* Windows returns 2*strlen-1 */
|
2021-02-11 11:01:28 +01:00
|
|
|
ok(ret >= strlen(szImgPath), "szImgPath=\"%s\" ret=%d\n", szImgPath, ret);
|
2010-10-07 11:53:04 +02:00
|
|
|
todo_wine ok(!strcmp(szImgPath, szMapPath), "szImgPath=\"%s\" szMapPath=\"%s\"\n", szImgPath, szMapPath);
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
2009-04-06 22:32:33 +02:00
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameW(NULL, szImgPathW, ARRAY_SIZE(szImgPathW));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
2009-04-06 22:32:33 +02:00
|
|
|
/* no information about correct buffer size returned: */
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameW(hpQI, szImgPathW, 0);
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameW(hpQI, NULL, 0);
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
|
2009-04-06 22:32:33 +02:00
|
|
|
|
|
|
|
/* correct call */
|
|
|
|
memset(szImgPathW, 0xff, sizeof(szImgPathW));
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessImageFileNameW(hpQI, szImgPathW, ARRAY_SIZE(szImgPathW));
|
2009-04-06 22:32:33 +02:00
|
|
|
ok(ret > 0, "GetProcessImageFileNameW should have succeeded.\n");
|
|
|
|
ok(szImgPathW[0] == '\\', "GetProcessImageFileNameW should have returned an NT path.\n");
|
2010-10-04 02:53:03 +02:00
|
|
|
ok(lstrlenW(szImgPathW) == ret, "Expected length to be %d, got %d\n", ret, lstrlenW(szImgPathW));
|
2009-04-06 22:32:33 +02:00
|
|
|
|
|
|
|
/* boundary values of 'size' */
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetProcessImageFileNameW(hpQI, szImgPathW, ret);
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "expected error=ERROR_INSUFFICIENT_BUFFER but got %d\n", GetLastError());
|
2009-04-06 22:32:33 +02:00
|
|
|
|
|
|
|
memset(szImgPathW, 0xff, sizeof(szImgPathW));
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetProcessImageFileNameW(hpQI, szImgPathW, ret + 1);
|
2009-04-06 22:32:33 +02:00
|
|
|
ok(ret > 0, "GetProcessImageFileNameW should have succeeded.\n");
|
|
|
|
ok(szImgPathW[0] == '\\', "GetProcessImageFileNameW should have returned an NT path.\n");
|
2010-10-04 02:53:03 +02:00
|
|
|
ok(lstrlenW(szImgPathW) == ret, "Expected length to be %d, got %d\n", ret, lstrlenW(szImgPathW));
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetModuleFileNameEx(void)
|
|
|
|
{
|
2013-10-24 00:30:04 +02:00
|
|
|
HMODULE hMod = GetModuleHandleA(NULL);
|
2005-06-27 21:47:48 +02:00
|
|
|
char szModExPath[MAX_PATH+1], szModPath[MAX_PATH+1];
|
2012-04-30 14:19:57 +02:00
|
|
|
WCHAR buffer[MAX_PATH];
|
2005-06-27 21:47:48 +02:00
|
|
|
DWORD ret;
|
2012-04-30 14:19:57 +02:00
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(NULL, hMod, szModExPath, sizeof(szModExPath));
|
2012-04-30 14:19:57 +02:00
|
|
|
ok( !ret, "GetModuleFileNameExA succeeded\n" );
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(hpQI, hMod, szModExPath, sizeof(szModExPath));
|
2012-04-30 14:19:57 +02:00
|
|
|
ok( !ret, "GetModuleFileNameExA succeeded\n" );
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(hpQV, hBad, szModExPath, sizeof(szModExPath));
|
2012-04-30 14:19:57 +02:00
|
|
|
ok( !ret, "GetModuleFileNameExA succeeded\n" );
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(hpQV, NULL, szModExPath, sizeof(szModExPath));
|
2010-10-07 11:53:04 +02:00
|
|
|
if(!ret)
|
|
|
|
return;
|
2006-10-11 00:00:25 +02:00
|
|
|
ok(ret == strlen(szModExPath), "szModExPath=\"%s\" ret=%d\n", szModExPath, ret);
|
2005-06-27 21:47:48 +02:00
|
|
|
GetModuleFileNameA(NULL, szModPath, sizeof(szModPath));
|
|
|
|
ok(!strncmp(szModExPath, szModPath, MAX_PATH),
|
2005-07-06 17:46:47 +02:00
|
|
|
"szModExPath=\"%s\" szModPath=\"%s\"\n", szModExPath, szModPath);
|
2012-04-30 14:19:57 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset( szModExPath, 0xcc, sizeof(szModExPath) );
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(hpQV, NULL, szModExPath, 4 );
|
2015-10-03 18:58:39 +02:00
|
|
|
ok( ret == 4 || ret == strlen(szModExPath), "wrong length %u\n", ret );
|
2012-04-30 14:19:57 +02:00
|
|
|
ok( broken(szModExPath[3]) /*w2kpro*/ || strlen(szModExPath) == 3,
|
|
|
|
"szModExPath=\"%s\" ret=%d\n", szModExPath, ret );
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "got error %d\n", GetLastError());
|
|
|
|
|
2015-10-03 18:57:47 +02:00
|
|
|
if (0) /* crashes on Windows 10 */
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExA(hpQV, NULL, szModExPath, 0 );
|
2015-10-03 18:57:47 +02:00
|
|
|
ok( ret == 0, "wrong length %u\n", ret );
|
|
|
|
ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %d\n", GetLastError());
|
|
|
|
}
|
2012-04-30 14:19:57 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
memset( buffer, 0xcc, sizeof(buffer) );
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExW(hpQV, NULL, buffer, 4 );
|
2015-10-03 18:58:39 +02:00
|
|
|
ok( ret == 4 || ret == lstrlenW(buffer), "wrong length %u\n", ret );
|
2012-04-30 14:19:57 +02:00
|
|
|
ok( broken(buffer[3]) /*w2kpro*/ || lstrlenW(buffer) == 3,
|
|
|
|
"buffer=%s ret=%d\n", wine_dbgstr_w(buffer), ret );
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "got error %d\n", GetLastError());
|
|
|
|
|
2015-10-03 18:57:47 +02:00
|
|
|
if (0) /* crashes on Windows 10 */
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
buffer[0] = 0xcc;
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleFileNameExW(hpQV, NULL, buffer, 0 );
|
2015-10-03 18:57:47 +02:00
|
|
|
ok( ret == 0, "wrong length %u\n", ret );
|
|
|
|
ok(GetLastError() == 0xdeadbeef, "got error %d\n", GetLastError());
|
|
|
|
ok( buffer[0] == 0xcc, "buffer modified %s\n", wine_dbgstr_w(buffer) );
|
|
|
|
}
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_GetModuleBaseName(void)
|
|
|
|
{
|
2013-10-24 00:30:04 +02:00
|
|
|
HMODULE hMod = GetModuleHandleA(NULL);
|
2005-06-27 21:47:48 +02:00
|
|
|
char szModPath[MAX_PATH], szModBaseName[MAX_PATH];
|
|
|
|
DWORD ret;
|
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleBaseNameA(NULL, hMod, szModBaseName, sizeof(szModBaseName));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleBaseNameA(hpQI, hMod, szModBaseName, sizeof(szModBaseName));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
GetModuleBaseNameA(hpQV, hBad, szModBaseName, sizeof(szModBaseName));
|
2010-10-05 02:56:49 +02:00
|
|
|
ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetModuleBaseNameA(hpQV, NULL, szModBaseName, sizeof(szModBaseName));
|
2010-10-07 11:53:04 +02:00
|
|
|
if(!ret)
|
2005-06-27 21:47:48 +02:00
|
|
|
return;
|
2006-10-11 00:00:25 +02:00
|
|
|
ok(ret == strlen(szModBaseName), "szModBaseName=\"%s\" ret=%d\n", szModBaseName, ret);
|
2005-06-27 21:47:48 +02:00
|
|
|
GetModuleFileNameA(NULL, szModPath, sizeof(szModPath));
|
|
|
|
ok(!strcmp(strrchr(szModPath, '\\') + 1, szModBaseName),
|
|
|
|
"szModPath=\"%s\" szModBaseName=\"%s\"\n", szModPath, szModBaseName);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_ws_functions(void)
|
|
|
|
{
|
|
|
|
PSAPI_WS_WATCH_INFORMATION wswi[4096];
|
2018-07-06 00:05:37 +02:00
|
|
|
HANDLE ws_handle;
|
2005-06-27 21:47:48 +02:00
|
|
|
char *addr;
|
2007-05-28 01:17:28 +02:00
|
|
|
unsigned int i;
|
2010-06-22 12:55:23 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
2018-07-06 00:05:37 +02:00
|
|
|
ws_handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_QUOTA |
|
|
|
|
PROCESS_SET_INFORMATION, FALSE, GetCurrentProcessId());
|
|
|
|
ok(!!ws_handle, "got error %u\n", GetLastError());
|
|
|
|
|
2010-10-05 02:56:49 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
EmptyWorkingSet(NULL);
|
2010-10-05 02:56:49 +02:00
|
|
|
todo_wine ok(GetLastError() == ERROR_INVALID_HANDLE, "expected error=ERROR_INVALID_HANDLE but got %d\n", GetLastError());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
EmptyWorkingSet(hpSR);
|
2010-10-05 02:56:49 +02:00
|
|
|
todo_wine ok(GetLastError() == ERROR_ACCESS_DENIED, "expected error=ERROR_ACCESS_DENIED but got %d\n", GetLastError());
|
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:37 +02:00
|
|
|
ret = EmptyWorkingSet(ws_handle);
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
2010-06-22 12:55:23 +02:00
|
|
|
|
|
|
|
SetLastError( 0xdeadbeef );
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = InitializeProcessForWsWatch( NULL );
|
2010-06-22 12:55:23 +02:00
|
|
|
todo_wine ok( !ret, "InitializeProcessForWsWatch succeeded\n" );
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
if (GetLastError() == ERROR_INVALID_FUNCTION) /* not supported on xp in wow64 mode */
|
|
|
|
{
|
|
|
|
trace( "InitializeProcessForWsWatch not supported\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %u\n", GetLastError() );
|
|
|
|
}
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:37 +02:00
|
|
|
ret = InitializeProcessForWsWatch(ws_handle);
|
2010-10-07 11:53:04 +02:00
|
|
|
ok(ret == 1, "failed with %d\n", GetLastError());
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
addr = VirtualAlloc(NULL, 1, MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
if(!addr)
|
2005-06-27 21:47:48 +02:00
|
|
|
return;
|
|
|
|
|
2010-06-22 12:55:23 +02:00
|
|
|
*addr = 0; /* make sure it's paged in (needed on wow64) */
|
2005-06-27 21:47:48 +02:00
|
|
|
if(!VirtualLock(addr, 1))
|
|
|
|
{
|
2006-10-11 00:00:25 +02:00
|
|
|
trace("locking failed (error=%d) - skipping test\n", GetLastError());
|
2005-06-27 21:47:48 +02:00
|
|
|
goto free_page;
|
|
|
|
}
|
2010-06-22 12:55:23 +02:00
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-07-06 00:05:36 +02:00
|
|
|
ret = GetWsChanges(hpQI, wswi, sizeof(wswi));
|
2010-10-07 11:53:04 +02:00
|
|
|
todo_wine ok(ret == 1, "failed with %d\n", GetLastError());
|
|
|
|
if(ret == 1)
|
2005-06-27 21:47:48 +02:00
|
|
|
{
|
|
|
|
for(i = 0; wswi[i].FaultingVa; i++)
|
|
|
|
if(((ULONG_PTR)wswi[i].FaultingVa & ~0xfffL) == (ULONG_PTR)addr)
|
|
|
|
{
|
2010-10-07 11:53:04 +02:00
|
|
|
todo_wine ok(ret == 1, "GetWsChanges found our page\n");
|
2005-06-27 21:47:48 +02:00
|
|
|
goto free_page;
|
|
|
|
}
|
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
todo_wine ok(0, "GetWsChanges didn't find our page\n");
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
free_page:
|
|
|
|
VirtualFree(addr, 0, MEM_RELEASE);
|
|
|
|
}
|
|
|
|
|
2020-01-24 21:19:40 +01:00
|
|
|
static void check_QueryWorkingSetEx(PVOID addr, const char *desc, DWORD expected_valid,
|
2020-07-13 19:49:22 +02:00
|
|
|
DWORD expected_protection, DWORD expected_shared, BOOL todo)
|
2020-01-24 21:19:40 +01:00
|
|
|
{
|
|
|
|
PSAPI_WORKING_SET_EX_INFORMATION info;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
memset(&info, 0x41, sizeof(info));
|
|
|
|
info.VirtualAddress = addr;
|
|
|
|
ret = pQueryWorkingSetEx(GetCurrentProcess(), &info, sizeof(info));
|
|
|
|
ok(ret, "QueryWorkingSetEx failed with %d\n", GetLastError());
|
|
|
|
|
|
|
|
todo_wine_if(todo)
|
|
|
|
ok(info.VirtualAttributes.Valid == expected_valid, "%s expected Valid=%u but got %u\n",
|
|
|
|
desc, expected_valid, info.VirtualAttributes.Valid);
|
|
|
|
|
|
|
|
todo_wine_if(todo)
|
|
|
|
ok(info.VirtualAttributes.Win32Protection == expected_protection, "%s expected Win32Protection=%u but got %u\n",
|
|
|
|
desc, expected_protection, info.VirtualAttributes.Win32Protection);
|
|
|
|
|
|
|
|
ok(info.VirtualAttributes.Node == 0, "%s expected Node=0 but got %u\n",
|
|
|
|
desc, info.VirtualAttributes.Node);
|
|
|
|
ok(info.VirtualAttributes.LargePage == 0, "%s expected LargePage=0 but got %u\n",
|
|
|
|
desc, info.VirtualAttributes.LargePage);
|
|
|
|
|
|
|
|
ok(info.VirtualAttributes.Shared == expected_shared || broken(!info.VirtualAttributes.Valid) /* w2003 */,
|
|
|
|
"%s expected Shared=%u but got %u\n", desc, expected_shared, info.VirtualAttributes.Shared);
|
|
|
|
if (info.VirtualAttributes.Valid && info.VirtualAttributes.Shared)
|
|
|
|
ok(info.VirtualAttributes.ShareCount > 0, "%s expected ShareCount > 0 but got %u\n",
|
|
|
|
desc, info.VirtualAttributes.ShareCount);
|
|
|
|
else
|
|
|
|
ok(info.VirtualAttributes.ShareCount == 0, "%s expected ShareCount == 0 but got %u\n",
|
|
|
|
desc, info.VirtualAttributes.ShareCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_QueryWorkingSetEx(void)
|
|
|
|
{
|
|
|
|
PVOID addr;
|
|
|
|
DWORD prot;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (pQueryWorkingSetEx == NULL)
|
|
|
|
{
|
|
|
|
win_skip("QueryWorkingSetEx not found, skipping tests\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = GetModuleHandleA(NULL);
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "exe", 1, PAGE_READONLY, 1, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
ret = VirtualProtect(addr, 0x1000, PAGE_NOACCESS, &prot);
|
|
|
|
ok(ret, "VirtualProtect failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "exe,noaccess", 0, 0, 1, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
ret = VirtualProtect(addr, 0x1000, prot, &prot);
|
|
|
|
ok(ret, "VirtualProtect failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "exe,readonly1", 0, 0, 1, TRUE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
*(volatile char *)addr;
|
|
|
|
ok(ret, "VirtualProtect failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "exe,readonly2", 1, PAGE_READONLY, 1, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
addr = VirtualAlloc(NULL, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
|
|
|
ok(addr != NULL, "VirtualAlloc failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc", 0, 0, 0, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
*(volatile char *)addr;
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc,read", 1, PAGE_READWRITE, 0, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
*(volatile char *)addr = 0x42;
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc,write", 1, PAGE_READWRITE, 0, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
ret = VirtualProtect(addr, 0x1000, PAGE_NOACCESS, &prot);
|
|
|
|
ok(ret, "VirtualProtect failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc,noaccess", 0, 0, 0, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
ret = VirtualProtect(addr, 0x1000, prot, &prot);
|
|
|
|
ok(ret, "VirtualProtect failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc,readwrite1", 0, 0, 0, TRUE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
*(volatile char *)addr;
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc,readwrite2", 1, PAGE_READWRITE, 0, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
|
|
|
|
ret = VirtualFree(addr, 0, MEM_RELEASE);
|
|
|
|
ok(ret, "VirtualFree failed with %d\n", GetLastError());
|
2020-07-13 19:49:22 +02:00
|
|
|
check_QueryWorkingSetEx(addr, "valloc,free", FALSE, 0, 0, FALSE);
|
2020-01-24 21:19:40 +01:00
|
|
|
}
|
|
|
|
|
2005-06-27 21:47:48 +02:00
|
|
|
START_TEST(psapi_main)
|
|
|
|
{
|
2018-07-06 00:05:36 +02:00
|
|
|
DWORD pid = GetCurrentProcessId();
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
init_func_ptrs();
|
2005-06-27 21:47:48 +02:00
|
|
|
|
2018-07-06 00:05:36 +02:00
|
|
|
if (pIsWow64Process)
|
|
|
|
IsWow64Process(GetCurrentProcess(), &wow64);
|
2018-05-29 16:33:03 +02:00
|
|
|
|
2010-10-07 11:53:04 +02:00
|
|
|
hpSR = OpenProcess(STANDARD_RIGHTS_REQUIRED, FALSE, pid);
|
2018-07-06 00:05:38 +02:00
|
|
|
ok(!!hpSR, "got error %u\n", GetLastError());
|
2010-10-07 11:53:04 +02:00
|
|
|
hpQI = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
|
2018-07-06 00:05:38 +02:00
|
|
|
ok(!!hpQI, "got error %u\n", GetLastError());
|
2010-10-07 11:53:04 +02:00
|
|
|
hpVR = OpenProcess(PROCESS_VM_READ, FALSE, pid);
|
2018-07-06 00:05:38 +02:00
|
|
|
ok(!!hpVR, "got error %u\n", GetLastError());
|
2010-10-07 11:53:04 +02:00
|
|
|
hpQV = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
|
2018-07-06 00:05:38 +02:00
|
|
|
ok(!!hpQV, "got error %u\n", GetLastError());
|
|
|
|
|
|
|
|
test_EnumProcesses();
|
|
|
|
test_EnumProcessModules();
|
|
|
|
test_GetModuleInformation();
|
|
|
|
test_GetPerformanceInfo();
|
|
|
|
test_GetProcessMemoryInfo();
|
|
|
|
test_GetMappedFileName();
|
|
|
|
test_GetProcessImageFileName();
|
|
|
|
test_GetModuleFileNameEx();
|
|
|
|
test_GetModuleBaseName();
|
2020-01-24 21:19:40 +01:00
|
|
|
test_QueryWorkingSetEx();
|
2018-07-06 00:05:38 +02:00
|
|
|
test_ws_functions();
|
2018-07-06 00:05:36 +02:00
|
|
|
|
|
|
|
CloseHandle(hpSR);
|
|
|
|
CloseHandle(hpQI);
|
|
|
|
CloseHandle(hpVR);
|
|
|
|
CloseHandle(hpQV);
|
2005-06-27 21:47:48 +02:00
|
|
|
}
|