-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Last PInvoke error in LibraryImport may not be preserved after runtime internal calls #79546
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsHi! It turned out that sometimes .NET 7 managed app may behave differently while under profiling. For example, as far as I can see
In this case
Profiler Enter callback resets the last error code when
These callbacks are set by I have also looked into Linked issues: #10727, #75828, #77364.
|
I would be great if the future fix will be backported to 7.0.x. Because huge impact for all profilers. |
Friendly ping. |
1 similar comment
This comment was marked as duplicate.
This comment was marked as duplicate.
I believe it is up to profilers to ensure that they don't change any state that can be unintentionally observed by managed code. I'll send this to the profiler team to see what they think. |
Tagging subscribers to this area: @tommcdon Issue DetailsHi! It turned out that sometimes .NET 7 managed app may behave differently while under profiling. For example, as far as I can see
In this case
Profiler Enter callback resets the last error code when
These callbacks are set by I have also looked into Same also applies for profiler based IL instrumentation (code coverage). Linked issues: #10727, #75828, #77364.
|
We are past platform shutdown for .NET 8 and are driving to zero bugs. Since this looks like a pre-existing issue and seems to be a non-trivial amount of work, moving to .NET 9 |
Hi!
It turned out that sometimes .NET 7 managed app may behave differently while under profiling. For example, as far as I can see
File.Exists()
usesGetFileAttributesExW()
as follows:In this case
File.Exists()
returnstrue
for files that do not exist when profiler's ELT hooks are used, here is demo app:Profiler Enter callback resets the last error code when
Marshal.GetLastSystemError()
is being called:These callbacks are set by
SetJitHelperFunction()
and there are other JIT helper functions (e.g.CORINFO_HELP_NEWARR_1_OBJ
) that probably won't be called beforeMarshal.GetLastSystemError()
in the generated code, and also there areBEGIN_PRESERVE_LAST_ERROR
/END_PRESERVE_LAST_ERROR
macros that are used in internal JIT helpers etc.I have also looked into
Thread::InjectActivation()
which usesPAL_InjectActivation()
andinject_activation_handler()
on Linux/macOS, and it preserveserrno
before callingHandleSuspensionForInterruptedThread()
, but it is not done forCheckActivationSafePoint()
which usesGetThreadNULLOk()
and e.g. on Linux ARM32 it internally calls__tls_get_addr()
, do we need to wrap it as well?Same also applies for profiler based IL instrumentation (code coverage).
Linked issues: #10727, #75828, #77364.
The text was updated successfully, but these errors were encountered: