Skip to content

Conversation

@chrullrich
Copy link
Contributor

@chrullrich chrullrich commented Nov 13, 2022

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

The error occurs only when running x86 pwsh on x64 Windows 11 22H2, the
first Windows version that has WldpCanExecuteFile().
@pull-request-quantifier-deprecated

This PR has 1 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +1 -0
Percentile : 0.4%

Total files changed: 1

Change summary by file extension:
.cs : +1 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@ghost ghost assigned PaulHigin Nov 13, 2022
@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 14, 2022
@iSazonov
Copy link
Collaborator

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).

@xtqqczze
Copy link
Contributor

xtqqczze commented Nov 14, 2022

https://learn.microsoft.com/en-us/windows/win32/api/wldp/nf-wldp-wldpcanexecutefile

Queries whether the execution policy allows execution of the code in the supplied file.

[DefaultDllImportSearchPathsAttribute(DllImportSearchPath.System32)]
[DllImportAttribute("wldp.dll", EntryPoint = "WldpCanExecuteFile")]
internal static extern int WldpCanExecuteFile(
[MarshalAs(UnmanagedType.LPStruct)]
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.)

Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

@chrullrich chrullrich Nov 14, 2022

Choose a reason for hiding this comment

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

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.

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.

Comment on lines +699 to 700
[MarshalAs(UnmanagedType.LPStruct)]
Guid host,
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
[MarshalAs(UnmanagedType.LPStruct)]
Guid host,
in Guid host,

@TravisEz13
Copy link
Member

/backport to release/v7.3.1

@iSazonov
Copy link
Collaborator

@chrullrich Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.3.x-Done CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Extra Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7.3.0 x86 crashes on startup on Windows 11 22H2

8 participants