1 /*
2  * PROJECT:     ReactOS api tests
3  * LICENSE:     LGPL-2.0-or-later (https://spdx.org/licenses/LGPL-2.0-or-later)
4  * PURPOSE:     Test for NtUserProcessConnect
5  * COPYRIGHT:   Copyright 2008-2020 Timo Kreuzer
6  *              Copyright 2021 Hermes Belusca-Maito
7  */
8 
9 #include "../win32nt.h"
10 
11 #define NTOS_MODE_USER
12 #include <ndk/exfuncs.h>
13 
14 START_TEST(NtUserProcessConnect)
15 {
16     HANDLE hProcess;
17     NTSTATUS Status;
18     USERCONNECT UserConnect = {0};
19     SYSTEM_BASIC_INFORMATION SystemInformation;
20     ULONG_PTR MaximumUserModeAddress;
21 
22     hProcess = GetCurrentProcess();
23 
24     UserConnect.ulVersion = MAKELONG(0, 5); // == USER_VERSION
25     // UserConnect.dwDispatchCount;
26     Status = NtUserProcessConnect(hProcess, &UserConnect, sizeof(UserConnect));
27     TEST(NT_SUCCESS(Status));
28 
29     printf("UserConnect.ulVersion = 0x%lx\n", UserConnect.ulVersion);
30     printf("UserConnect.ulCurrentVersion = 0x%lx\n", UserConnect.ulCurrentVersion);
31     printf("UserConnect.dwDispatchCount = 0x%lx\n", UserConnect.dwDispatchCount);
32     printf("UserConnect.siClient.psi = 0x%p\n", UserConnect.siClient.psi);
33     printf("UserConnect.siClient.aheList = 0x%p\n", UserConnect.siClient.aheList);
34     printf("UserConnect.siClient.pDispInfo = 0x%p\n", UserConnect.siClient.pDispInfo);
35     printf("UserConnect.siClient.ulSharedDelta = 0x%Ix\n", UserConnect.siClient.ulSharedDelta);
36 
37     /* Verify the validity of some mandatory fields */
38     TEST(UserConnect.ulVersion == MAKELONG(0, 5));
39     TEST(UserConnect.ulCurrentVersion == 0);
40     TEST(UserConnect.siClient.ulSharedDelta != 0);
41 
42     /* Get the max um address */
43     Status = NtQuerySystemInformation(SystemBasicInformation,
44                                       &SystemInformation,
45                                       sizeof(SystemInformation),
46                                       NULL);
47     TEST(NT_SUCCESS(Status));
48 
49     MaximumUserModeAddress = SystemInformation.MaximumUserModeAddress;
50 
51     /* Verify the validity of pointers -- They must be in client space */
52     TEST(UserConnect.siClient.psi != NULL);
53     TEST(UserConnect.siClient.aheList != NULL);
54     // TEST(UserConnect.siClient.pDispInfo != NULL);
55     TEST((ULONG_PTR)UserConnect.siClient.psi < MaximumUserModeAddress);
56     TEST((ULONG_PTR)UserConnect.siClient.aheList < MaximumUserModeAddress);
57     // TEST((ULONG_PTR)UserConnect.siClient.pDispInfo < MaximumUserModeAddress);
58 }
59