[PATCH 2/2] kernel32: Implement GetSystemCpuSetInformation().
Paul Gofman
pgofman at codeweavers.com
Wed Mar 24 12:25:11 CDT 2021
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
...api-ms-win-core-processthreads-l1-1-3.spec | 2 +-
dlls/kernel32/kernel32.spec | 1 +
dlls/kernel32/tests/process.c | 66 +++++++++++++++++++
dlls/kernelbase/kernelbase.spec | 2 +-
dlls/kernelbase/memory.c | 16 +++++
include/winbase.h | 1 +
6 files changed, 86 insertions(+), 2 deletions(-)
diff --git a/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec b/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec
index 9cc853d2884..8f2daaefe74 100644
--- a/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec
+++ b/dlls/api-ms-win-core-processthreads-l1-1-3/api-ms-win-core-processthreads-l1-1-3.spec
@@ -1,6 +1,6 @@
@ stub GetProcessDefaultCpuSets
@ stub GetProcessInformation
-@ stub GetSystemCpuSetInformation
+@ stdcall GetSystemCpuSetInformation(ptr long ptr ptr long) kernel32.GetSystemCpuSetInformation
@ stdcall GetThreadDescription(long ptr) kernel32.GetThreadDescription
@ stub GetThreadSelectedCpuSets
@ stub SetProcessDefaultCpuSets
diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec
index d14bf010383..0312e044a86 100644
--- a/dlls/kernel32/kernel32.spec
+++ b/dlls/kernel32/kernel32.spec
@@ -822,6 +822,7 @@
@ stdcall GetStringTypeExA(long long str long ptr)
@ stdcall -import GetStringTypeExW(long long wstr long ptr)
@ stdcall -import GetStringTypeW(long wstr long ptr)
+@ stdcall -import GetSystemCpuSetInformation(ptr long ptr ptr long)
@ stdcall -import GetSystemFileCacheSize(ptr ptr ptr)
@ stdcall -import GetSystemDefaultLCID()
@ stdcall -import GetSystemDefaultLangID()
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 373212cd2da..433c12ff1fb 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -79,6 +79,7 @@ static BOOL (WINAPI *pSetInformationJobObject)(HANDLE job, JOBOBJECTINFOCLASS
static HANDLE (WINAPI *pCreateIoCompletionPort)(HANDLE file, HANDLE existing_port, ULONG_PTR key, DWORD threads);
static BOOL (WINAPI *pGetNumaProcessorNode)(UCHAR, PUCHAR);
static NTSTATUS (WINAPI *pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
+static NTSTATUS (WINAPI *pNtQuerySystemInformationEx)(SYSTEM_INFORMATION_CLASS, void*, ULONG, void*, ULONG, ULONG*);
static DWORD (WINAPI *pWTSGetActiveConsoleSessionId)(void);
static HANDLE (WINAPI *pCreateToolhelp32Snapshot)(DWORD, DWORD);
static BOOL (WINAPI *pProcess32First)(HANDLE, PROCESSENTRY32*);
@@ -87,6 +88,7 @@ static BOOL (WINAPI *pThread32First)(HANDLE, THREADENTRY32*);
static BOOL (WINAPI *pThread32Next)(HANDLE, THREADENTRY32*);
static BOOL (WINAPI *pGetLogicalProcessorInformationEx)(LOGICAL_PROCESSOR_RELATIONSHIP,SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*,DWORD*);
static SIZE_T (WINAPI *pGetLargePageMinimum)(void);
+static BOOL (WINAPI *pGetSystemCpuSetInformation)(SYSTEM_CPU_SET_INFORMATION*,ULONG,ULONG*,HANDLE,ULONG);
static BOOL (WINAPI *pInitializeProcThreadAttributeList)(struct _PROC_THREAD_ATTRIBUTE_LIST*, DWORD, DWORD, SIZE_T*);
static BOOL (WINAPI *pUpdateProcThreadAttribute)(struct _PROC_THREAD_ATTRIBUTE_LIST*, DWORD, DWORD_PTR, void *,SIZE_T,void*,SIZE_T*);
static void (WINAPI *pDeleteProcThreadAttributeList)(struct _PROC_THREAD_ATTRIBUTE_LIST*);
@@ -245,6 +247,7 @@ static BOOL init(void)
hntdll = GetModuleHandleA("ntdll.dll");
pNtQueryInformationProcess = (void *)GetProcAddress(hntdll, "NtQueryInformationProcess");
+ pNtQuerySystemInformationEx = (void *)GetProcAddress(hntdll, "NtQuerySystemInformationEx");
pGetNativeSystemInfo = (void *) GetProcAddress(hkernel32, "GetNativeSystemInfo");
pGetSystemRegistryQuota = (void *) GetProcAddress(hkernel32, "GetSystemRegistryQuota");
@@ -269,6 +272,7 @@ static BOOL init(void)
pThread32Next = (void *)GetProcAddress(hkernel32, "Thread32Next");
pGetLogicalProcessorInformationEx = (void *)GetProcAddress(hkernel32, "GetLogicalProcessorInformationEx");
pGetLargePageMinimum = (void *)GetProcAddress(hkernel32, "GetLargePageMinimum");
+ pGetSystemCpuSetInformation = (void *)GetProcAddress(hkernel32, "GetSystemCpuSetInformation");
pInitializeProcThreadAttributeList = (void *)GetProcAddress(hkernel32, "InitializeProcThreadAttributeList");
pUpdateProcThreadAttribute = (void *)GetProcAddress(hkernel32, "UpdateProcThreadAttribute");
pDeleteProcThreadAttributeList = (void *)GetProcAddress(hkernel32, "DeleteProcThreadAttributeList");
@@ -3786,6 +3790,67 @@ static void test_GetLogicalProcessorInformationEx(void)
HeapFree(GetProcessHeap(), 0, info);
}
+static void test_GetSystemCpuSetInformation(void)
+{
+ SYSTEM_CPU_SET_INFORMATION *info, *info_nt;
+ HANDLE process = GetCurrentProcess();
+ ULONG size, expected_size;
+ NTSTATUS status;
+ SYSTEM_INFO si;
+ BOOL ret;
+
+ if (!pGetSystemCpuSetInformation)
+ {
+ win_skip("GetSystemCpuSetInformation() is not supported.\n");
+ return;
+ }
+
+ GetSystemInfo(&si);
+
+ expected_size = sizeof(*info) * si.dwNumberOfProcessors;
+
+ if (0)
+ {
+ /* Crashes on Windows with NULL return length. */
+ pGetSystemCpuSetInformation(NULL, 0, NULL, process, 0);
+ }
+
+ size = 0xdeadbeef;
+ SetLastError(0xdeadbeef);
+ ret = pGetSystemCpuSetInformation(NULL, size, &size, process, 0);
+ ok(!ret && GetLastError() == ERROR_NOACCESS, "Got unexpected ret %#x, GetLastError() %u.\n", ret, GetLastError());
+ ok(!size, "Got unexpected size %u.\n", size);
+
+ size = 0xdeadbeef;
+ SetLastError(0xdeadbeef);
+ ret = pGetSystemCpuSetInformation(NULL, 0, &size, (HANDLE)0xdeadbeef, 0);
+ ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "Got unexpected ret %#x, GetLastError() %u.\n", ret, GetLastError());
+ ok(!size, "Got unexpected size %u.\n", size);
+
+ size = 0xdeadbeef;
+ SetLastError(0xdeadbeef);
+ ret = pGetSystemCpuSetInformation(NULL, 0, &size, process, 0);
+ ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Got unexpected ret %#x, GetLastError() %u.\n", ret, GetLastError());
+ ok(size == expected_size, "Got unexpected size %u.\n", size);
+
+ info = heap_alloc(size);
+ info_nt = heap_alloc(size);
+
+ status = pNtQuerySystemInformationEx(SystemCpuSetInformation, &process, sizeof(process), info_nt, expected_size, NULL);
+ ok(!status, "Got unexpected status %#x.\n", status);
+
+ size = 0xdeadbeef;
+ SetLastError(0xdeadbeef);
+ ret = pGetSystemCpuSetInformation(info, expected_size, &size, process, 0);
+ ok(ret && GetLastError() == 0xdeadbeef, "Got unexpected ret %#x, GetLastError() %u.\n", ret, GetLastError());
+ ok(size == expected_size, "Got unexpected size %u.\n", size);
+
+ ok(!memcmp(info, info_nt, expected_size), "Info does not match NtQuerySystemInformationEx().");
+
+ heap_free(info_nt);
+ heap_free(info);
+}
+
static void test_largepages(void)
{
SIZE_T size;
@@ -4348,6 +4413,7 @@ START_TEST(process)
test_GetNumaProcessorNode();
test_session_info();
test_GetLogicalProcessorInformationEx();
+ test_GetSystemCpuSetInformation();
test_largepages();
test_ProcThreadAttributeList();
test_SuspendProcessState();
diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec
index 08a2f726817..8cb15fff084 100644
--- a/dlls/kernelbase/kernelbase.spec
+++ b/dlls/kernelbase/kernelbase.spec
@@ -681,7 +681,7 @@
@ stdcall GetStringTypeW(long wstr long ptr)
# @ stub GetSystemAppDataFolder
# @ stub GetSystemAppDataKey
-# @ stub GetSystemCpuSetInformation
+@ stdcall GetSystemCpuSetInformation(ptr long ptr ptr long)
@ stdcall GetSystemDefaultLCID()
@ stdcall GetSystemDefaultLangID()
@ stdcall GetSystemDefaultLocaleName(ptr long)
diff --git a/dlls/kernelbase/memory.c b/dlls/kernelbase/memory.c
index 2bfd3893e8e..60333db242f 100644
--- a/dlls/kernelbase/memory.c
+++ b/dlls/kernelbase/memory.c
@@ -1130,6 +1130,22 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetLogicalProcessorInformationEx( LOGICAL_PROCESSO
}
+/***********************************************************************
+ * GetSystemCpuSetInformation (kernelbase.@)
+ */
+BOOL WINAPI GetSystemCpuSetInformation(SYSTEM_CPU_SET_INFORMATION *info, ULONG buffer_length, ULONG *return_length,
+ HANDLE process, ULONG flags)
+{
+ if (flags)
+ FIXME("Unsupported flags %#x.\n", flags);
+
+ *return_length = 0;
+
+ return set_ntstatus( NtQuerySystemInformationEx( SystemCpuSetInformation, &process, sizeof(process), info,
+ buffer_length, return_length ));
+}
+
+
/**********************************************************************
* GetNumaHighestNodeNumber (kernelbase.@)
*/
diff --git a/include/winbase.h b/include/winbase.h
index 651da6d6906..beb91371bb6 100644
--- a/include/winbase.h
+++ b/include/winbase.h
@@ -2274,6 +2274,7 @@ WINBASEAPI VOID WINAPI GetStartupInfoA(LPSTARTUPINFOA);
WINBASEAPI VOID WINAPI GetStartupInfoW(LPSTARTUPINFOW);
#define GetStartupInfo WINELIB_NAME_AW(GetStartupInfo)
WINBASEAPI HANDLE WINAPI GetStdHandle(DWORD);
+WINBASEAPI BOOL WINAPI GetSystemCpuSetInformation(SYSTEM_CPU_SET_INFORMATION*,ULONG,ULONG*,HANDLE,ULONG);
WINBASEAPI UINT WINAPI GetSystemDirectoryA(LPSTR,UINT);
WINBASEAPI UINT WINAPI GetSystemDirectoryW(LPWSTR,UINT);
#define GetSystemDirectory WINELIB_NAME_AW(GetSystemDirectory)
--
2.30.2
More information about the wine-devel
mailing list