Skip to content

[mono] Possible GC hole in runtime invoke #58957

@lambdageek

Description

@lambdageek

Introduced by #58215 and the 6.0 backport #58364

The issue was: if a method is returning a large valuetype that will need to be boxed into a MonoObject that is bigger than the fixed-size stack allocated buffer that we prepare, use malloc to allocate a bigger buffer on the unmanaged heap and store the result there and then copy it over into a MonoObject.

The problem is that while the value is only in the unmanaged heap buffer, if it has any reference types pointing into the managed heap, those pointers are not visible to the GC. So if there's a collection between when the invoked method returns and the point where we copy the result to the MonoObject, we will have GC holes.


Probably what we need to do is use alloca (upto some bigger bound - originally it was 256 bytes, but maybe it needs to be larger).

Alternately, if we always expect to box the result anyway, we could just write it directly into the MonoObject (I think the managed code would always have write barriers there).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions