-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add Get/SetLastPInvokeError and Get/SetLastSystemError APIs #51505
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
Outdated
Show resolved
Hide resolved
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.
Mono changes look fine, but like Jan said I think it would be preferable to just move the identical functions to the shared portion. Thanks!
src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
Show resolved
Hide resolved
|
||
public static int GetLastWin32Error() | ||
{ | ||
return GetLastPInvokeError(); |
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 GetLastPInvokeError is the recommended API to use moving forward, should we change all of our netcoreapp usage of GetLastWin32Error to instead use GetLastPInvokeError?
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.
Yes, I think so. I didn't try to do it with this change for adding the new API just because it would touch so much, but the plan would be to do so for 6.0.
@CoffeeFlux what is the expected behaviour on mono for the stored last error when calling a P/Invoke with I added a test to check that |
Should work the same way as CoreCLR - errno should be set to 0 before the call, and then after the call It's possible that it isn't working right (maybe while JITing the wrapper method for the pinvoke, the JIT sets errno to 1 for some reason). |
I added the |
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.
Are we going to have a follow up to change all existing usage? Might be something we can file and mark "up-for-grabs" as it would be a relatively easy issue if someone in the community wanted to do the work.
private const string SetError = nameof(SetError); | ||
|
||
[DllImport(nameof(SetLastErrorNative), EntryPoint = SetError)] | ||
public static extern void SetError_Default(int error, byte shouldSetError); |
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 don't recall for sure, but can you add a comment on these P/Invokes if they need to be blittable in order to make this work.
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.
They don't need to be blittable. I can just change this to bool.
Yes for existing usage for netcoreapp. As I mentioned in another comment, I didn't do it here since it would touch so much, but it would be a follow-up change for 6.0.
I like that idea. Filed: #51648 |
Implements #46843
cc @AaronRobinsonMSFT @jkoritzinsky