-
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
Guard members of MonoType union & fix related bugs #111645
base: main
Are you sure you want to change the base?
Changes from 5 commits
71d52ae
55fdf8a
3ec7a60
8ad069c
2d41bb5
5fd3623
db37234
1145217
31fa3c9
ae64025
fdf66d2
c8c6460
41bf23c
48e7a1a
cb26e90
1fc1fe5
8153494
40e6dd9
892e4fe
772a3fa
dac61f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ struct _MonoType { | |
MonoMethodSignature *method; | ||
MonoGenericParam *generic_param; /* for VAR and MVAR */ | ||
MonoGenericClass *generic_class; /* for GENERICINST */ | ||
} data; | ||
} data; /* don't access directly, use m_type_data_get_<name> */ | ||
unsigned int attrs : 16; /* param attributes or field flags */ | ||
MonoTypeEnum type : 8; | ||
unsigned int has_cmods : 1; | ||
|
@@ -1296,6 +1296,92 @@ m_type_is_byref (const MonoType *type) | |
return type->byref__; | ||
} | ||
|
||
MONO_NEVER_INLINE void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are going to have this in production than I believe we should adopt a similar pattern as we have when using MONO_CLASS_DEF_PRIVATE, either extend that or make a similar thing for MonoType, that way we would run all these additional checks when running ENABLE_CHECKED_BUILD_PRIVATE_TYPES (we should have CI legs doing that), but use inline wrappers with zero overhead on release builds. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to do actual full checks in Release unless benchmarks show that it meaningfully regresses performance, at least during the preview period, in order to flush out any remaining issues of this type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would still add the same support for types as we have for class so we could do a MONO_TYPE_DEF_PRIVATE under ENABLED_CHECKED_BUILD_PRIVATE_TYPES to catch errors bypassing the getters on CI. We could also add support for the full check vs zero overhead wrappers as part of that and then just decide to initially opt into full checks during preview (and monitor perf hit during that time) and then have the option to move back to zero wrappers closer to release, but keep the full checks on CI builds running with the ENABLED_CHECKED_BUILD_PRIVATE_TYPES. |
||
m_type_invalid_access (const char *fn_name, MonoTypeEnum actual_type); | ||
|
||
static inline MonoClass * | ||
m_type_data_get_klass (const MonoType *type) | ||
{ | ||
switch (type->type) { | ||
// list based on class.c mono_class_from_mono_type_internal cases | ||
case MONO_TYPE_OBJECT: | ||
case MONO_TYPE_VOID: | ||
case MONO_TYPE_BOOLEAN: | ||
case MONO_TYPE_CHAR: | ||
case MONO_TYPE_I1: | ||
case MONO_TYPE_U1: | ||
case MONO_TYPE_I2: | ||
case MONO_TYPE_U2: | ||
case MONO_TYPE_I4: | ||
case MONO_TYPE_U4: | ||
case MONO_TYPE_I: | ||
case MONO_TYPE_U: | ||
case MONO_TYPE_I8: | ||
case MONO_TYPE_U8: | ||
case MONO_TYPE_R4: | ||
case MONO_TYPE_R8: | ||
case MONO_TYPE_STRING: | ||
case MONO_TYPE_TYPEDBYREF: | ||
case MONO_TYPE_CLASS: | ||
case MONO_TYPE_VALUETYPE: | ||
case MONO_TYPE_SZARRAY: | ||
return type->data.klass; | ||
default: | ||
m_type_invalid_access (__func__, type->type); | ||
return NULL; | ||
} | ||
} | ||
|
||
static inline MonoGenericParam * | ||
m_type_data_get_generic_param (const MonoType *type) | ||
{ | ||
if (G_LIKELY((type->type == MONO_TYPE_VAR) || (type->type == MONO_TYPE_MVAR))) | ||
return type->data.generic_param; | ||
|
||
m_type_invalid_access (__func__, type->type); | ||
return NULL; | ||
} | ||
|
||
static inline MonoArrayType * | ||
m_type_data_get_array (const MonoType *type) | ||
{ | ||
if (G_LIKELY(type->type == MONO_TYPE_ARRAY)) | ||
return type->data.array; | ||
|
||
m_type_invalid_access (__func__, type->type); | ||
return NULL; | ||
} | ||
|
||
static inline MonoType * | ||
m_type_data_get_type (const MonoType *type) | ||
{ | ||
if (G_LIKELY(type->type == MONO_TYPE_PTR)) | ||
return type->data.type; | ||
|
||
m_type_invalid_access (__func__, type->type); | ||
return NULL; | ||
} | ||
|
||
static inline MonoMethodSignature * | ||
m_type_data_get_method (const MonoType *type) | ||
{ | ||
if (G_LIKELY(type->type == MONO_TYPE_FNPTR)) | ||
return type->data.method; | ||
|
||
m_type_invalid_access (__func__, type->type); | ||
return NULL; | ||
} | ||
|
||
static inline MonoGenericClass * | ||
m_type_data_get_generic_class (const MonoType *type) | ||
{ | ||
if (G_LIKELY(type->type == MONO_TYPE_GENERICINST)) | ||
return type->data.generic_class; | ||
|
||
m_type_invalid_access (__func__, type->type); | ||
return NULL; | ||
} | ||
|
||
/** | ||
* mono_type_get_class_internal: | ||
* \param type the \c MonoType operated on | ||
|
@@ -1308,7 +1394,7 @@ static inline MonoClass* | |
mono_type_get_class_internal (MonoType *type) | ||
{ | ||
/* FIXME: review the runtime users before adding the assert here */ | ||
return type->data.klass; | ||
return m_type_data_get_klass (type); | ||
} | ||
|
||
/** | ||
|
@@ -1322,7 +1408,7 @@ mono_type_get_class_internal (MonoType *type) | |
static inline MonoArrayType* | ||
mono_type_get_array_type_internal (MonoType *type) | ||
{ | ||
return type->data.array; | ||
return m_type_data_get_array (type); | ||
} | ||
|
||
static inline int | ||
|
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 assume you should be able to handle both cases similar, except that you can't assume mono_type is MonoArrayType it could also be MonoClass, so you would just need to handle the case where you get the type, rank and mono_type_parameter differently.