Closed Bug 1400317 Opened 7 years ago Closed 4 years ago

nsUXThemeData uses win32k APIs in content process

Categories

(Core :: Widget: Win32, enhancement, P1)

Unspecified
Windows
enhancement

Tracking

()

RESOLVED FIXED
Tracking Status
firefox-esr52 --- wontfix
firefox55 --- wontfix
firefox56 --- wontfix
firefox57 --- wontfix

People

(Reporter: Alex_Gaynor, Assigned: cmartin)

References

(Blocks 1 open bug)

Details

(Whiteboard: [gfx-noted])

Attachments

(9 files, 2 obsolete files)

(deleted), application/octet-stream
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), application/octet-stream
Details
win32u!NtUserSystemParametersInfo USER32!RealSystemParametersInfoW+0x82 USER32!SystemParametersInfoW+0xae dwmapi!DwmIsCompositionEnabled+0x5b xul!nsUXThemeData::CheckForCompositor+0xd xul!nsUXThemeData::Initialize+0x25 xul!DllMain+0x12 win32u!NtUserSystemParametersInfo USER32!RealSystemParametersInfoW+0x82 USER32!SystemParametersInfoW+0xae xul!nsUXThemeData::Invalidate+0x4b xul!DllMain+0x12 A few more blockers for the "remove win32k API usage from content".
Component: Graphics → Widget: Win32

We should be able to remote all of this over to the main process.

If fact, we may not need to initialize this module. Depends on who's calling into it. Layout might rely on this, and the theme module might as well. Once we get rid of theme, this might go away on its own.

Assignee: nobody → jewilde
Status: NEW → ASSIGNED
Priority: P3 → P1
Blocks: 1382326
No longer blocks: win32k-lockdown
No longer blocks: 1382326
Depends on: 1382326
Attached file Win32k log 2020-04-21 cmartin (deleted) —

I'm attaching a recent Win32k log from my machine. Can see that this still has calls to dwmapi!DwmIsCompositionEnabled in it.

Assignee: jewilde → nobody
Status: ASSIGNED → NEW

Currently, There are multiple places that call the Win32 APIs for DWM status.

Once Win32k lockdown is enabled, this API will be unavailable and will need
to be remoted. This new function will be made to work in both parent and
content processes, and therefore all DWM queries must be directed to it.

Also, some minor cleanup because... Why not?

The only caveat here is that gfxVars are not atomic, but multiple threads can
query DWM status. To solve this, changes to the var are mirrored into an atomic
and that is read instead.

DWM status changes are indicated by Windows via a window message. We use that
window message to cause the update to propagate

Depends on D73742

Assignee: nobody → cmartin
Status: NEW → ASSIGNED
Pushed by cmartin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/474b8b0d69b1 Create single source of truth for DWM status r=jrmuizel https://hg.mozilla.org/integration/autoland/rev/57e14417817e Use gfxVars to mirror DWM status to content processes r=jrmuizel
Keywords: leave-open
Attached file Bug 1400317 - Centralize ThemeData-related calls (obsolete) (deleted) —

To enable Win32k lockdown, calls involving native theme will need to be
removed.

Currently these calls are scattered around several files. This class creates
a proxy for the Win32 calls. Whitelisting this class in awcw32ks makes it much
easier to track Win32k removal with themes removed.

As an added benefit, once non-native theming is done it will be easy to verify
by asserting that this class is never created in Content.

Currently, a SystemParametersInfo(SPI_GETFLATMENU) happens very very early
during the XUL DLL startup. This is unnecessary, as this value is not used
until way later.

For Win32k lockdown, we will need to remote this call, so ContentChild must
be available.

By loading this value lazily, we ensure IPC will be available and also get to
remove a Win32 call from the Firefox startup time.

There are a number of system parameters that return simple floats and bools
and are just different forms of system parameter query.

This introduces a new singleton and IPDL calls to send these values from parent
to content processes and cache them in content.

I started with these 2 variables because their values don't go stale. In a
later changeset, I will add more logic to invalidate cached values that go
stale, such as for the SPI_GETFLATMENU metric.

This is not meant to actually be checked in, but it demonstrates how to remote
a theme drawing call using this centralized theme change.

The vertical scrollbar for the main window uses this API, so the fact that it
works shows that it works and is possible.

Depends on D75946

Pushed by cmartin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7e57777825f2 Use SPI_GETFLATMENU lazily to avoid early Win32k call r=jmathies
Attachment #9153619 - Attachment is obsolete: true
Pushed by cmartin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c5704e3fc7fa Add new async calls/singleton for remoting system parameters r=jmathies
Pushed by cmartin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/5777919cd214 Centralize ThemeData-related calls r=jmathies

Push with failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception&revision=9cb0de45cc862420703f2d0bf1e9c9b09d54a058&searchStr=windows%2Cmingw%2Call&selectedTaskRun=BuoqfxHRS-2GpQ2Y1QZWIg.0

Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=306421086&repo=autoland

Backout link: https://hg.mozilla.org/integration/autoland/rev/323418a0d68fb43e033a82addb3475724217c0bc

[task 2020-06-15T22:50:57.615Z] 22:50:57  WARNING -  /builds/worker/checkouts/gecko/widget/windows/TaskbarTabPreview.h:39:16: warning: 'DetachFromNSWindow' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -    virtual void DetachFromNSWindow();
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                 ^
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  /builds/worker/checkouts/gecko/widget/windows/TaskbarPreview.h:50:16: note: overridden virtual function is here
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -    virtual void DetachFromNSWindow();
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                 ^
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  In file included from Unified_cpp_widget_windows1.cpp:56:
[task 2020-06-15T22:50:57.615Z] 22:50:57    ERROR -  /builds/worker/checkouts/gecko/widget/windows/WinThemeData.cpp:74:38: error: cannot initialize a parameter of type 'RECT *' (aka 'tagRECT *') with an lvalue of type 'LPCRECT' (aka 'const tagRECT *')
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                                       aDrawRect, aMargins));
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                                       ^~~~~~~~~
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  /builds/worker/fetches/clang/bin/../x86_64-w64-mingw32/include/winerror.h:2224:34: note: expanded from macro 'SUCCEEDED'
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                                   ^~
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  /builds/worker/fetches/clang/bin/../x86_64-w64-mingw32/include/uxtheme.h:326:91: note: passing argument to parameter 'prc' here
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  THEMEAPI GetThemeMargins(HTHEME hTheme,HDC hdc,int iPartId,int iStateId,int iPropId,RECT *prc,MARGINS *pMargins);
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                                                                                            ^
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  In file included from Unified_cpp_widget_windows1.cpp:56:
[task 2020-06-15T22:50:57.615Z] 22:50:57    ERROR -  /builds/worker/checkouts/gecko/widget/windows/WinThemeData.cpp:82:39: error: cannot initialize a parameter of type 'RECT *' (aka 'tagRECT *') with an lvalue of type 'LPCRECT' (aka 'const tagRECT *')
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                                        aDrawRect, aSizeType, aPartSize));
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -                                        ^~~~~~~~~
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  /builds/worker/fetches/clang/bin/../x86_64-w64-mingw32/include/winerror.h:2224:34: note: expanded from macro 'SUCCEEDED'
[task 2020-06-15T22:50:57.615Z] 22:50:57     INFO -  #define SUCCEEDED(hr) ((HRESULT)(hr) >= 0)

There are also these talos failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=pending%2Crunning%2Csuccess%2Ctestfailed%2Cbusted%2Cexception&searchStr=windows%2C10%2Cx64%2Cwebrender%2Cshippable%2Copt%2Ctalos%2Cperformance%2Ctests%2Ctest-windows10-64-shippable-qr%2Fopt-talos-xperf-e10s%2Ct%28x%29&tochange=323418a0d68fb43e033a82addb3475724217c0bc&fromchange=b41a8f8bcf1c30d276883f90b119d9c7fd98f7d5

Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=306431229&repo=autoland

Flags: needinfo?(cmartin)

It appears that MinGW's header files have the wrong "const-ness" for these functions (they expect a RECT* argument instead of a const RECT* argument)

I'm going to have to use const_cast<T> to appease MinGW. Unfortunate...

Flags: needinfo?(cmartin)

SPI_GETFLATMENU uses the newly-added WinContentSystemParameters and adds
the ability to update theme-related variables when they change.

This Win32 API will need to be remoted for Win32k lockdown. As it falls under
the <uxtheme.h> system header, I believe it makes the most sense to centralize
it as "nsUXThemeData::IsAppThemed()", and then turn that into a remoted API.

Depends on D80071

Depends on D80564

Pushed by cmartin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f16561d47196 Win32k Lockdown: Remote SPI_GETFLATMENU r=jmathies
Pushed by cmartin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c26a3724c8c1 Create single source of truth for IsAppThemed r=jmathies https://hg.mozilla.org/integration/autoland/rev/634e89e8e717 Win32k Lockdown: Remote IsAppThemed() r=jmathies
Attached file Log from 2020-07-24 run of awcw32ks (deleted) —

Closing ticket as updated run of awcw32ks tool shows that the only nsUXThemeData calls still making Win32k calls are the ones blocked on non-native themeing, which is out-of-scope for this bug.

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Attachment #9150130 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: