Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lambdageek
Copy link
Member

@lambdageek lambdageek commented Feb 24, 2018

  1. Add m_class_offsetof_fieldName functions
    They just call MONO_STRUCT_OFFSET (MonoClass, fieldName). If the MonoClass definition is hidden, you get prototypes from mono/metadata/class-abi-details.h, otherwise the functions are inlined in that header.
  2. Add mono_class_set_nonblittable accessor function.
    I don't really understand why, but mono_marshal_load_type_info wants to overwrite the MonoClass:blittable flag sometimes.
  3. Change everything in marshal.c to use m_class_get_field getters. No functional change.

#6925

Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be assume that the caller holds the loader lock.

These look like:
```c
intptr_t
m_class_offsetof_someField (void) {
  return MONO_STRUCT_OFFSET (MonoClass, someField);
}
```

When Mono is compiled with the definition of MonoClass
hidden (--enable-checked-build=private_types),
only the function prototypes are available via
mono/metadata/class-abi-details.h
When Mono is compiled without the checked build flag,
the functions are inlined into that header.
This is needed by mono_marshal_load_type_info ()
@lambdageek
Copy link
Member Author

Changed mono_class_set_nonblittable to take the loader lock.

@luhenry luhenry self-assigned this Feb 26, 2018
@lambdageek lambdageek merged commit b8da973 into mono:master Feb 27, 2018
@lambdageek lambdageek deleted the use-getters-marshal branch February 27, 2018 15:59
@HinTak
Copy link
Contributor

HinTak commented Sep 23, 2018

I am wondering if I can ask some question about this particular pull here . I am finally spending some time to get my own hand dirty try to get an old mixed-mode assembly application to work ( #10268 ) and is somewhat pleasantly surprised that with mono 5.12 or below, it asserts at the g_assert line after mono_class_get_checked() in mono_marshal_set_callconv_from_modopt() in mono/metadata/marshal.c. While with mono 5.14 it went a lot further (with --verbose) .

The only important difference within mono_marshal_set_callconv_from_modopt() between those versions seems to be this pull.

So my question is, why would switching to getter/setter from direct access fixes problem with that particular assertion? Or, if this is not the fix for the assertion, what other changes around that time might be? I just like to understanding more about this pull.

I see the purpose of mono_marshal_set_callconv_from_modopt() is responsible for passing delegates to native code (I think this is called "reverse P/Invoke") which the application I am interested in certainly does.

@lambdageek
Copy link
Member Author

@HinTak it's unlikely that switching from direct access to MonoClass fields to using getters had the effect you describe.

It's more likely a result of #7012 - I think part of what that PR did was to correct which MonoImage is associated with a custom modifier, which could explain why we don't fail immediately at mono_class_get_checked

@HinTak
Copy link
Contributor

HinTak commented Sep 24, 2018 via email

@HinTak
Copy link
Contributor

HinTak commented Sep 24, 2018

I check git log and it cannot be #7012 - #7012 entered master at the right time frame to master but wasn't cherry-pick/backported into 5.14, and it appears only at 5.16 onwards. Still, thanks a lot for the time, and I learned something just reading the #7012 issue entry and what follows.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* [runtime] Use getters in IS_MONOTYPE()

* [metadata] Add m_class_offsetof_fieldName accessors

These look like:
```c
intptr_t
m_class_offsetof_someField (void) {
  return MONO_STRUCT_OFFSET (MonoClass, someField);
}
```

When Mono is compiled with the definition of MonoClass
hidden (--enable-checked-build=private_types),
only the function prototypes are available via
mono/metadata/class-abi-details.h
When Mono is compiled without the checked build flag,
the functions are inlined into that header.

* [metadata] Add accessor function mono_class_set_nonblittable

This is needed by mono_marshal_load_type_info ()

* [marshal] Use m_class_get_ getters to access MonoClass fields


Commit migrated from mono/mono@b8da973
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants