Skip to content

Commit 0f36093

Browse files
committed
chore: Improve handling of property and event maps in hot reload to prevent crashes on type additions
1 parent 1611997 commit 0f36093

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

patches/0001-fix-hot-reload-propertymap-eventmap-crash-on-type-addition.patch

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/src/mono/mono/component/hot_reload.c b/src/mono/mono/component/hot_reload.c
2-
index e5614bb0788..cf7afa0b52a 100644
2+
index e5614bb0788..ff2ea665159 100644
33
--- a/src/mono/mono/component/hot_reload.c
44
+++ b/src/mono/mono/component/hot_reload.c
55
@@ -1995,7 +1995,6 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
@@ -39,7 +39,7 @@ index e5614bb0788..cf7afa0b52a 100644
3939
break;
4040
case ENC_FUNC_ADD_PROPERTY:
4141
/* adding a new property to a propertymap. could be new or existing propertymap. */
42-
@@ -2149,10 +2149,13 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
42+
@@ -2149,16 +2149,21 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
4343
default:
4444
g_assert_not_reached (); /* unexpected func code */
4545
}
@@ -57,7 +57,18 @@ index e5614bb0788..cf7afa0b52a 100644
5757
break;
5858
}
5959
case MONO_TABLE_PROPERTY: {
60-
@@ -2194,8 +2197,7 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
60+
- /* allow updates to existing properties. */
61+
- if (is_addition) {
62+
- g_assert (add_property_propertymap != 0);
63+
+ /* Register properties when signaled by a preceding ENC_FUNC_ADD_PROPERTY
64+
+ * entry (add_property_propertymap != 0). Use this context variable instead
65+
+ * of is_addition because is_addition is unreliable — token indices can fall
66+
+ * within prev_gen_rows when re-applying the same type across generations. */
67+
+ if (add_property_propertymap != 0) {
68+
69+
uint32_t parent_type_token = mono_metadata_decode_row_col (&image_base->tables [MONO_TABLE_PROPERTYMAP], mono_metadata_token_index (add_property_propertymap) - 1, MONO_PROPERTY_MAP_PARENT);
70+
parent_type_token = mono_metadata_make_token (MONO_TABLE_TYPEDEF, parent_type_token);
71+
@@ -2194,8 +2199,7 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
6172
case MONO_TABLE_EVENTMAP: {
6273
switch (func_code) {
6374
case ENC_FUNC_DEFAULT:
@@ -67,7 +78,7 @@ index e5614bb0788..cf7afa0b52a 100644
6778
break;
6879
case ENC_FUNC_ADD_EVENT:
6980
/* adding a new event to an eventmap. could be new or existing eventmap. */
70-
@@ -2203,12 +2205,14 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
81+
@@ -2203,16 +2207,17 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
7182
default:
7283
g_assert_not_reached (); /* unexpected func code */
7384
}
@@ -86,8 +97,13 @@ index e5614bb0788..cf7afa0b52a 100644
8697
-
8798
}
8899
case MONO_TABLE_EVENT: {
89-
if (is_addition) {
90-
@@ -2284,12 +2288,10 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
100+
- if (is_addition) {
101+
- g_assert (add_event_eventmap != 0);
102+
+ if (add_event_eventmap != 0) {
103+
104+
uint32_t parent_type_token = mono_metadata_decode_row_col (&image_base->tables [MONO_TABLE_EVENTMAP], mono_metadata_token_index (add_event_eventmap) - 1, MONO_EVENT_MAP_PARENT);
105+
parent_type_token = mono_metadata_make_token (MONO_TABLE_TYPEDEF, parent_type_token);
106+
@@ -2284,12 +2289,10 @@ apply_enclog_pass2 (Pass2Context *ctx, MonoImage *image_base, BaselineInfo *base
91107
break;
92108
}
93109
case MONO_TABLE_INTERFACEIMPL: {

0 commit comments

Comments
 (0)