Skip to content
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

Stash additional Mono APIs needed for serialization prototype. #1586

Draft
wants to merge 1 commit into
base: unity-main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3448,6 +3448,28 @@ mono_field_set_value (MonoObject *obj, MonoClassField *field, void *value)
MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_field_set_value_internal (obj, field, value));
}

void
mono_field_set_value_offset_internal (MonoObject* obj, MonoClassField* field, int declaring_field_offset, void* value)
{
void* dest;

if ((field->type->attrs & FIELD_ATTRIBUTE_STATIC))
return;

dest = (char*)obj + field->offset + declaring_field_offset - MONO_ABI_SIZEOF(MonoObject);
#if ENABLE_NETCORE
mono_copy_value (field->type, dest, value, value && field->type->type == MONO_TYPE_PTR);
#else
mono_copy_value (field->type, dest, value, FALSE);
#endif
}

void
mono_unity_field_set_value_offset (MonoObject* obj, MonoClassField* field, int declaring_field_offset, void* value)
{
MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_field_set_value_offset_internal (obj, field, declaring_field_offset, value));
}

void
mono_field_static_set_value_internal (MonoVTable *vt, MonoClassField *field, void *value)
{
Expand Down Expand Up @@ -3576,6 +3598,27 @@ mono_field_get_value_internal (MonoObject *obj, MonoClassField *field, void *val
mono_copy_value (field->type, value, src, TRUE);
}

void
mono_field_get_value_offset_internal(MonoObject* obj, MonoClassField* field, int declaring_field_offset, void* value)
{
MONO_REQ_GC_UNSAFE_MODE;

void* src;

g_assert (obj);

g_return_if_fail (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC));

src = (char*)obj + field->offset + declaring_field_offset - MONO_ABI_SIZEOF(MonoObject);
mono_copy_value (field->type, value, src, TRUE);
}

void
mono_unity_field_get_value_offset(MonoObject* obj, MonoClassField* field, int declaring_field_offset, void* value)
{
MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_field_get_value_offset_internal (obj, field, declaring_field_offset, value));
}

/**
* mono_field_get_value_object:
* \param domain domain where the object will be created (if boxing)
Expand Down Expand Up @@ -9413,6 +9456,22 @@ mono_array_length (MonoArray *array)
MONO_EXTERNAL_ONLY (uintptr_t, mono_array_length_internal (array));
}

void
mono_unity_array_set_range(MonoArray* dest, uintptr_t destidx, void* src, uintptr_t byteSize)
{
int32_t element_size = mono_array_element_size (dest->obj.vtable->klass);
char* start = mono_array_addr_with_size_fast (dest, element_size, destidx);
memcpy(start, src, byteSize);
}

void
mono_unity_array_get_range(MonoArray* src, uintptr_t srcidx, void* dest, uintptr_t byteSize)
{
int32_t element_size = mono_array_element_size(src->obj.vtable->klass);
char* start = mono_array_addr_with_size_fast(src, element_size, srcidx);
memcpy(dest, start, byteSize);
}

#ifdef ENABLE_CHECKED_BUILD_GC

/**
Expand Down
12 changes: 12 additions & 0 deletions mono/metadata/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ mono_array_addr_with_size (MonoArray *array, int size, uintptr_t idx);
MONO_API MONO_RT_EXTERNAL_ONLY uintptr_t
mono_array_length (MonoArray *array);

MONO_API MONO_RT_EXTERNAL_ONLY void
mono_unity_array_set_range(MonoArray* dest, uintptr_t destidx, void* src, uintptr_t byteSize);

MONO_API MONO_RT_EXTERNAL_ONLY void
mono_unity_array_get_range(MonoArray* src, uintptr_t srcidx, void* dest, uintptr_t byteSize);

MONO_API MONO_RT_EXTERNAL_ONLY MonoString*
mono_string_empty (MonoDomain *domain);

Expand Down Expand Up @@ -347,6 +353,12 @@ mono_field_static_get_value (MonoVTable *vt, MonoClassField *field, void *value)
MONO_API MONO_RT_EXTERNAL_ONLY MonoObject *
mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObject *obj);

MONO_API MONO_RT_EXTERNAL_ONLY void
mono_unity_field_set_value_offset (MonoObject* obj, MonoClassField* field, int declaring_field_offset, void* value);

MONO_API MONO_RT_EXTERNAL_ONLY void
mono_unity_field_get_value_offset (MonoObject* obj, MonoClassField* field, int declaring_field_offset, void* value);

MONO_API MONO_RT_EXTERNAL_ONLY void
mono_property_set_value (MonoProperty *prop, void *obj, void **params, MonoObject **exc);

Expand Down