Fix DwmIsCompositionEnabled crash on Mono/wine-mono#11567
Open
williamzujkowski wants to merge 1 commit intodotnet:mainfrom
Open
Fix DwmIsCompositionEnabled crash on Mono/wine-mono#11567williamzujkowski wants to merge 1 commit intodotnet:mainfrom
williamzujkowski wants to merge 1 commit intodotnet:mainfrom
Conversation
The P/Invoke for DwmIsCompositionEnabled used PreserveSig = false, which transforms the native signature from: HRESULT DwmIsCompositionEnabled(BOOL *pfEnabled) to: bool DwmIsCompositionEnabled(void) This works on .NET Framework/CoreCLR but crashes on Mono and wine-mono, which don't support PreserveSig = false for DllImports. The marshalling is skipped, so dwmapi receives a garbage pointer instead of a valid BOOL*, causing an access violation. Fix: change to PreserveSig = true with an explicit out parameter, matching the pattern already used by DwmGetColorizationColor in the same file. The public wrapper now checks the HRESULT before returning the value. This fixes WPF applications crashing on minimize/restore when running under Wine on Linux, which affects tools like EQLogParser. Fixes: dotnet#4166
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes WPF applications crashing on minimize/restore when running under Wine on Linux.
History
This is a revival of #4155 (2021), which was closed because it depended on two mono PRs:
mono_mmap_open_file)The original issue #4166 was closed as completed in 2021, but the WPF-side fix was never actually merged. The bug still exists in the current codebase.
Root cause
The P/Invoke for
DwmIsCompositionEnabledinNativeMethods.csusesPreserveSig = false:This transforms the native signature from
HRESULT DwmIsCompositionEnabled(BOOL *pfEnabled)tobool DwmIsCompositionEnabled(void). On .NET Framework/CoreCLR this works via automatic HRESULT-to-exception conversion, but Mono and wine-mono do not supportPreserveSig = falsefor DllImports. The marshalling is skipped, sodwmapi.dllreceives a garbage pointer inrcx(x64) instead of a validBOOL*, causing an access violation.Fix
Change to
PreserveSig = truewith an explicitoutparameter, matching the pattern already used byDwmGetColorizationColoron line 2513 of the same file:The
WindowsBase/Utilities.csversion already uses the correct pattern viaPInvoke.DwmIsCompositionEnabled(out BOOL).Impact
HRESULT.S_OKis always returned,enabledreflects actual DWM stateSystemParameters.IsGlassEnabledorWindowChromeWorkerNote on mono dependency
This WPF-side fix is correct regardless of mono/mono#20831's status — it changes the P/Invoke to use the proper Windows API signature. The mono PR is a separate prerequisite for wine-mono to fully support the
PreserveSigattribute, but this change is independently valid since it switches FROMPreserveSig = false(the problematic path) TOPreserveSig = true(the working path).Fixes #4166
Supersedes #4155