-
-
Notifications
You must be signed in to change notification settings - Fork 226
Add Kernel32 and User32 methods, and tests #329 #338
Conversation
|
I suspect that the exact error @AkariAkaori has to be platform related (Some OS version might setlasterror on success, other not. So we should fix our CoreClr did the wise thing here and guarantee that SetLastError is always called on PInvoke having SetLastError=true dotnet/coreclr#614 |
Yes, that occurred to me as well. It could be .NET Framework that fixed this too (an equivalent fix that CoreCLR made). If @AkariAkaori can specify what version of .NET Framework is installed and what build of Windows, I'd be willing to investigate more. But I don't want to fix a problem that I can't repro since my fix may or may not be effective. @vbfox I've never written a CER in C# (unless you count locks). What construct would protect against interruptions? BTW, as the last error is thread-local, I imagine as long as I don't allocate memory, it's impossible (I think?) for the CLR to actually do work on my thread so I think(?) my LastError is safe if I were to set it to zero. |
|
I've only used CER in a few specific cases and i'm far from knowledgeable in the domain but yes they protect against all interruptions by the runtime as long as you respect a big amount of constraints RuntimeHelpers.PrepareConstrainedRegions();
try { }
finally
{
// Code Here won't be interruptible
}I agree with you that it should be an impossible situation in the current CRL implementations. Especially as I don't think that the GC really uses code that set the win32 last error. I was pointing at the possibility because while I think that if we can find a case were it's provably broken we should fix it by adding a |
Thinking about this more, I see no reason to worry about using a CER. That's why the Framework gives us So IMO it's still a debate whether we need to call |
My point was more about the time between our hypothetical call to |
|
Managed to reproduce it here: https://streamable.com/gdkio Tested latest PInvoke 0.5.86 and 0.5.64, and frameworks 4.5.2, 4.6.2 and 4.7 |
I added some methods (including those required to test #329) and added a test to reproduce #329. But the test passed so I don't think we actually have an issue, unless @AkariAkaori can help point out what is wrong in my repro.
Closes #329