Skip to content

Commit

Permalink
[icall] If Stream:BeginWrite/EndWrite are linked out, they're not ove…
Browse files Browse the repository at this point in the history
…rridden (#56559)

Add the same logic that we already have for BeginRead/EndRead - if we can't
find a vtable slot that has the method in the base class, it must have been
linked out, so a subclass can't possibly override it.

Fixes #56315
  • Loading branch information
lambdageek committed Jul 30, 2021
1 parent 03211e3 commit 09305a8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -3256,9 +3256,12 @@ ves_icall_System_IO_Stream_HasOverriddenBeginEndWrite (MonoObjectHandle stream,
if (!io_stream_slots_set)
init_io_stream_slots ();

// slots can still be -1 and it means Linker removed the methods from the base class (Stream)
// in this case we can safely assume the methods are not overridden
// otherwise - check vtable
MonoMethod **curr_klass_vtable = m_class_get_vtable (curr_klass);
gboolean begin_write_is_overriden = curr_klass_vtable [io_stream_begin_write_slot]->klass != base_klass;
gboolean end_write_is_overriden = curr_klass_vtable [io_stream_end_write_slot]->klass != base_klass;
gboolean begin_write_is_overriden = io_stream_begin_write_slot != -1 && curr_klass_vtable [io_stream_begin_write_slot]->klass != base_klass;
gboolean end_write_is_overriden = io_stream_end_write_slot != -1 && curr_klass_vtable [io_stream_end_write_slot]->klass != base_klass;

// return true if BeginWrite or EndWrite were overriden
return begin_write_is_overriden || end_write_is_overriden;
Expand Down

0 comments on commit 09305a8

Please sign in to comment.