-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Fix native access violation (#18545) #18547
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
Conversation
The error occurs only when running x86 pwsh on x64 Windows 11 22H2, the first Windows version that has WldpCanExecuteFile().
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
We need to backport to 7.3 I believe. @chrullrich We started to migrate to from DllImport to LibraryImport. If you have an interest/experience with LibraryImport welcome to do that fix in follow PR (after we merge the PR). |
|
https://learn.microsoft.com/en-us/windows/win32/api/wldp/nf-wldp-wldpcanexecutefile
|
| [DefaultDllImportSearchPathsAttribute(DllImportSearchPath.System32)] | ||
| [DllImportAttribute("wldp.dll", EntryPoint = "WldpCanExecuteFile")] | ||
| internal static extern int WldpCanExecuteFile( | ||
| [MarshalAs(UnmanagedType.LPStruct)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a comment here that this is needed because the first argument is a REFGUID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I figured it out, so can anyone else. The signature of the native function isn't secret, after all. On the other hand, I would quite like it if all declarations of native functions had their full signature next to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for LPStruct DO indicate that this should ONLY be used for REFGUID, but someone not familiar with that may not understand the connection between this type and GUID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a suggestion to use the in modifier instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To allow anyone not familiar with the subject to understand why the attribute is there, you'd have to include a treatise on calling conventions and how C weirdly came up with the idea of passing structs on the stack. Anything less than that just ends up as a string of the same words you are trying to explain.
Link to https://learn.microsoft.com/en-us/dotnet/standard/native-interop/best-practices#guids ? That is what you are referring to above, I believe. That sentence doesn't say "the only type in the whole world that LPStruct should ever be used with is Guid", but "of the various ways of declaring a Guid argument, LPStruct should be used only with the ref kind". (If I find the time, I'll try and improve the Guid section of that page. I find it very confusing.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a suggestion to use the
inmodifier instead.
Doesn't in just mean the argument is effectively const on the receiving end? I admit I have never used it, but it does not look to me like it also means to pass the thing as a pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't
injust mean the argument is effectivelyconston the receiving end? I admit I have never used it, but it does not look to me like it also means to pass the thing as a pointer.
Oh, I take that back.
I'll leave it to the experts to decide whether it's correct, though. My C# is far from good enough.
| [MarshalAs(UnmanagedType.LPStruct)] | ||
| Guid host, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| [MarshalAs(UnmanagedType.LPStruct)] | |
| Guid host, | |
| in Guid host, |
|
/backport to release/v7.3.1 |
|
@chrullrich Thanks for your contribution! |
PR Summary
Fix #18545.
This fixes a crash caused by an incorrect declaration of a native function.
PR Context
The error occurs only when running x86 pwsh on Windows 11 22H2, the first Windows version that has WldpCanExecuteFile().
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).