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

Set ExactSpelling=true on P/Invokes in System.Private.CoreLib that already specify the unicode W suffix #36257

Merged
merged 2 commits into from
May 13, 2020

Conversation

elinor-fung
Copy link
Member

If a p/invoke is declared with CharSet.Unicode and ExactSpelling=false, the runtime will (on Windows) look for both the specified entry point name and the name with the W suffix. We explicitly specify the W suffix for the entry point name in a number of cases without setting ExactSpelling=true, resulting in the runtime looking for entry points that we know will not exist (e.g. looking for GetEnvironmentVariableWW in kernel32).

This change updates such cases in System.Private.CoreLib to set ExactSpelling=true.

cc @AaronRobinsonMSFT @jkoritzinsky @stephentoub

@@ -16,7 +16,7 @@ internal static partial class Advapi32
{
// Note: RegCreateKeyEx won't set the last error on failure - it returns
// an error code if it fails.
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegCreateKeyExW")]
[DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, BestFitMapping = false, EntryPoint = "RegCreateKeyExW", ExactSpelling = true)]
internal static extern int RegCreateKeyEx(
Copy link
Member

@stephentoub stephentoub May 12, 2020

Choose a reason for hiding this comment

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

Not for this PR, but we might want to subsequently rename all of the methods to use the exact entrypoint name; doing that would make it more clear at the call site exactly which method was being used, would remove the need to specify EntryPoint as well, would increase our consistency (sometimes we use W in the name and sometimes we don't), and also fits with the goal of minimizing magic. Not a big deal, though.

@stephentoub
Copy link
Member

the runtime will (on Windows)

The comment at #35695 (comment) suggests that we're doing this erroneously on Unix as well. Is that the case?

@elinor-fung
Copy link
Member Author

#33246 for not doing it on Unix is already addressed and we are no longer doing the probing there.

@stephentoub
Copy link
Member

not doing it on Unix is already addressed

I even reviewed #33250. Losing my mind apparently :-)

jkotas added a commit to dotnet/corert that referenced this pull request May 12, 2020
@stephentoub stephentoub merged commit f2cdf3b into dotnet:master May 13, 2020
@elinor-fung elinor-fung deleted the exactSpelling-coreLib branch July 2, 2020 18:23
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants