Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USER32] Implement IsServerSideWindow (undocumented) #7577

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

oleg-dubinskiy
Copy link
Contributor

Purpose

Implement IsServerSideWindow function in user32. It checks whether a window has a window procedure that resides in kernel mode and returns a boolean condition based on the appropriate internal window state flag (WNDS_SERVERSIDEWINDOWPROC).
This function is not officially documented by Microsoft, but fortunately it has unofficial documentation at http://undoc.airesoft.co.uk/user32.dll/IsServerSideWindow.php. According to that doc, bServerSideWindowProc bit seems actually correspond to WNDS_SERVERSIDEWINDOWPROC.
Required and used internally by uxtheme.dll from Windows XP/2003/Vista/7/etc. The log spams with it a lot, when using uxtheme.dll from Windows in ReactOS.

JIRA issue: CORE-19946

Proposed changes

  • Implement the function itself.
  • Add its prototype in the header (since the function is not officially documented).
  • Write an apitest for this function.

TODO

  • Fix/add correct test condition in apitest, to properly test the behaviour of the function! Currently, the function returns FALSE in both cases, and both in Windows and ReactOS, which means the condition for input window is not tested properly.
  • Also, an apitest probably needs to be improved in other parts.

Analysis

As it's visible on the following screenshot, uxtheme.dll actually needs that function in Windows XP SP3 at least:
uxtheme-XP

Since the function is not offfically documented.
Required by the further implementation and an appropriate apitest.
CORE-19946
@oleg-dubinskiy oleg-dubinskiy added the enhancement For PRs with an enhancement/new feature. label Dec 23, 2024
@oleg-dubinskiy oleg-dubinskiy self-assigned this Dec 23, 2024
@github-actions github-actions bot added ROSTESTS Label for ROS testcases PRs. Win32SS For Win32 subsystem (Win32k, GDI/USER DLLs, etc.) related components PRs. labels Dec 23, 2024
@oleg-dubinskiy
Copy link
Contributor Author

Note: with current state of this PR, results of executing an apitest are identical both in ReactOS and Windows.

…ted)

Add a test for IsServerSideWindow() function is user32. It tests whether the window procedure of the window resides in the kernel mode or not.
It is not documented by Microsoft, but fortunately has unofficial (3rd party) documentation at http://undoc.airesoft.co.uk/user32.dll/IsServerSideWindow.php.
Required and used internally by uxtheme.dll from XP/2003/Vista/7/etc.
TODO: Fix/add correct test condition, to properly test the behavoiur of the function! Currently, the function returns FALSE in both cases, which means the condition for input window is not tested properly.
Implement IsServerSideWindow function in user32. It checks whether a window has a window procedure that resides in kernel mode and returns a boolean condition based on the appropriate internal window state flag (WNDS_SERVERSIDEWINDOWPROC).
This function is not officially documented by Microsoft, but fortunately it has unofficial documentation at http://undoc.airesoft.co.uk/user32.dll/IsServerSideWindow.php.
Required and used internally by uxtheme.dll from Windows XP/2003/Vista/7/etc. The log spams with it a lot, when using uxtheme.dll from Windows in ReactOS.
CORE-19946
Copy link
Contributor

@HBelusca HBelusca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider converting the serverside test into a true apitest (to be added in user32_apitest, see modules/rostests/apitests/user32/).


/* This testapp tests behaviour of IsServerSideWindow() function in user32. */

#define _WINE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a wine test, so please remove this.

Copy link
Contributor Author

@oleg-dubinskiy oleg-dubinskiy Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not. But this define is required to properly include undocuser.h (which contains IsServerSideWindow declaration) from winuser.h. See https://git.reactos.org/?p=reactos.git;a=blob;f=sdk/include/psdk/winuser.h;hb=d7f1a784a86570863804daaf6479ffba2863422f#l5891. But I think it can be included directly in apitest instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a hack for Wine code only.
For ReactOS code, you explicitly include the undocuser.h header when you need it, see for example:
https://git.reactos.org/?p=reactos.git&a=search&h=HEAD&st=grep&s=undocuser.h

LPWSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd1a, hWnd1b;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just use one single window handle hWnd, and you use this one consecutively for each CreateWindowExW + the test.

UINT result;
BOOL ret;

memset(&wcx, 0, sizeof(wcx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
memset(&wcx, 0, sizeof(wcx));
ZeroMemory(&wcx, sizeof(wcx));

DPRINT("OK: the window %p has a valid kernel mode wndproc\n", hWnd1a);
else
DPRINT("FAIL: the window %p is not valid or has no valid kernel mode wndproc\n", hWnd1a);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing: DestroyWindow(hWnd1a);

DPRINT("FAIL: the window %p has a valid kernel mode wndproc when it shouldn't\n", hWnd1b);
else
DPRINT("OK: the window %p has no valid kernel mode wndproc\n", hWnd1b);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing: DestroyWindow(hWnd1b);

Comment on lines +1539 to +1542
if (Wnd != NULL)
return (Wnd->state & WNDS_SERVERSIDEWINDOWPROC) != 0;

return FALSE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (Wnd != NULL)
return (Wnd->state & WNDS_SERVERSIDEWINDOWPROC) != 0;
return FALSE;
if (!Wnd)
return FALSE;
return (Wnd->state & WNDS_SERVERSIDEWINDOWPROC) != 0;

or a one-line:

    return (Wnd ? !!(Wnd->state & WNDS_SERVERSIDEWINDOWPROC) : FALSE);

IsServerSideWindow(
_In_ HWND hWnd)
{
PWND Wnd = ValidateHwnd(hWnd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this function (and thus, your IsServerSideWindow implementation as it is currently written) will set the last-error in case the window handle is invalid. You should probably add a test for this.
If the last-error remains untouched, then please use ValidateHwndNoErr instead.

WNDCLASSEXW wcx;
UINT result;
BOOL ret;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing: testing IsServerSideWindow with invalid window handles (e.g. NULL and 0xdeadbeef), and check the last-error.

ShowWindow(hWnd1a, SW_SHOW);
UpdateWindow(hWnd1a);

ret = IsServerSideWindow(hWnd1a);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be of interest to check whether the last-error has been set to something, or is left unchanged.

Copy link
Contributor

@wjk wjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much to say. The background brush issue is the only thing that jumped out at me, and @HBelusca’s review is far more thorough than mine could ever be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For PRs with an enhancement/new feature. ROSTESTS Label for ROS testcases PRs. Win32SS For Win32 subsystem (Win32k, GDI/USER DLLs, etc.) related components PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants