-
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
Fix SafeHandle debug-only _ctorStackTrace for mono #82376
Conversation
2c3a993
to
2497e7d
Compare
/azp list |
/azp run runtime-community |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
This is technically fine, but maybe we should do something a bit cleaner.
Also I really think we need
#if MONO
[StructLayout(LayoutKind.Sequential)]
#endif
#if DEBUG && CORECLR | ||
private readonly string? _ctorStackTrace; | ||
#endif |
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.
@stephentoub questions:
- Can we move this member to the end of the set of instance members. (And I assume do the related changes on the native side in coreclr)
- For Mono we should really have
[StructLayout(Sequential)]
on any class where we care about the field layout. Otherwise we're just relying on auto layout coincidentally getting the fields in the right order. - Should we make
SafeHandle.Mono.cs
andSafeHandle.CoreCLR.cs
that just contain the instance field definitions?#if DEBUG && CORECLR
accomplishes the same thing but feels more fragile.
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.
Can we move this member to the end of the set of instance members. (And I assume do the related changes on the native side in coreclr)
I'd previously done that, and I believe the issues I hit were to do with alignment, though it's also possible I just messed something up or neglected to edit something I needed to edit.
For Mono we should really have [StructLayout(Sequential)] on any class where we care about the field layout. Otherwise we're just relying on auto layout coincidentally getting the fields in the right order.
This is irrespective of this change or this field, right? You're saying mono is expecting that handle is first and it may not be.
Should we make SafeHandle.Mono.cs and SafeHandle.CoreCLR.cs that just contain the instance field definitions? #if DEBUG && CORECLR accomplishes the same thing but feels more fragile.
I don't love the duplication there; that feels more fragile to me, actually. If this field is problematic, we can just remove it and I can put it back in the future should someone want to do another push like I did to drive down SafeHandle finalization debt.
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.
This is irrespective of this change or this field, right? You're saying mono is expecting that handle is first and it may not be.
Yea, it's not required for this PR (all the other fields are non-reference so auto layout will get things right). Just might as well do some future-proofing
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.
Overall I'm fine with the PR as is. It would be nice to get the layout attribute in here, but we could also do a separate PR for that. If splitting the file feels more fragile to you @stephentoub , I'm ok with the PR as is.
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.
@lambdageek, mono actually already has StructLayout applied:
runtime/src/mono/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.Mono.cs
Lines 6 to 8 in 5e3dd8d
// Mono runtime relies on exact layout | |
[StructLayout(LayoutKind.Sequential)] | |
public abstract partial class SafeHandle |
Try to fix mono failure
Fixes #82308