#include <mono/metadata/unicode.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/rand.h>
+#include <mono/metadata/sysmath.h>
+#include <mono/metadata/debug-symfile.h>
#include <mono/io-layer/io-layer.h>
#include "decimal.h"
MonoObject *idxs)
{
MonoArray *ao, *io, *vo;
- MonoClass *ac, *ic, *vc;
+ MonoClass *ac, *ic;
gint32 i, pos, *ind;
MONO_CHECK_ARG_NULL (idxs);
- vo = (MonoArray *)value;
- if (vo)
- vc = (MonoClass *)vo->obj.vtable->klass;
- else
- vc = NULL;
-
io = (MonoArray *)idxs;
ic = (MonoClass *)io->obj.vtable->klass;
ves_icall_type_from_name (MonoString *name)
{
MonoDomain *domain = mono_domain_get ();
- MonoClass *klass;
+ MonoType *type;
MonoImage *image;
MonoTypeNameParse info;
gchar *str;
/*g_print ("requested type %s\n", str);*/
if (!mono_reflection_parse_type (str, &info)) {
g_free (str);
+ g_list_free (info.modifiers);
return NULL;
}
/* do we need to load if it's not already loaded? */
if (!image) {
g_free (str);
+ g_list_free (info.modifiers);
return NULL;
}
} else
image = mono_defaults.corlib;
- if (info.nest_name) {
- klass = mono_class_from_name (image, info.nest_name_space, info.nest_name);
- if (klass) {
- GList *nested;
- mono_class_init (klass);
- nested = klass->nested_classes;
- while (nested) {
- klass = nested->data;
- if (strcmp (klass->name, info.nest_name) == 0 &&
- strcmp (klass->name_space, info.nest_name_space) == 0)
- break;
- klass = NULL;
- }
- }
- } else {
- klass = mono_class_from_name (image, info.name_space, info.name);
- }
+
+ type = mono_reflection_get_type (image, &info, FALSE);
g_free (str);
- if (!klass)
+ g_list_free (info.modifiers);
+ if (!type)
return NULL;
- mono_class_init (klass);
- if (info.rank) {
- klass = mono_array_class_get (&klass->byval_arg, info.rank);
- mono_class_init (klass);
- }
-
- if (info.isbyref || info.ispointer) /* hack */
- return mono_type_get_object (domain, &klass->this_arg);
- else
- return mono_type_get_object (domain, &klass->byval_arg);
+ /*g_print ("got it\n");*/
+ return mono_type_get_object (domain, type);
}
static MonoReflectionType*
info->attrs = class->flags;
info->rank = class->rank;
info->assembly = NULL; /* FIXME */
- if (class->enumtype)
+ if (class->enumtype && class->enum_basetype) /* types that are modifierd typebuilkders may not have enum_basetype set */
info->etype = mono_type_get_object (domain, class->enum_basetype);
else if (class->element_class)
info->etype = mono_type_get_object (domain, &class->element_class->byval_arg);
}
static MonoObject*
-ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params) {
- //MonoMethodSignature *sig = method->method->signature;
+ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
+{
+ MonoMethodSignature *sig = method->method->signature;
+ gpointer *pa;
+ int i;
- /*
- * Do we need to copy the values so that the called method can't change them?
- */
+ pa = alloca (sizeof (gpointer) * params->bounds->length);
- return NULL;
+ for (i = 0; i < params->bounds->length; i++) {
+ if (sig->params [i]->byref) {
+ /* fixme: don't know how to handle this */
+ g_assert_not_reached ();
+ }
+
+ switch (sig->params [i]->type) {
+ case MONO_TYPE_U1:
+ case MONO_TYPE_I1:
+ case MONO_TYPE_BOOLEAN:
+ case MONO_TYPE_U2:
+ case MONO_TYPE_I2:
+ case MONO_TYPE_CHAR:
+ case MONO_TYPE_U:
+ case MONO_TYPE_I:
+ case MONO_TYPE_U4:
+ case MONO_TYPE_I4:
+ case MONO_TYPE_U8:
+ case MONO_TYPE_I8:
+ case MONO_TYPE_VALUETYPE:
+ pa [i] = (char *)(((gpointer *)params->vector)[i]) + sizeof (MonoObject);
+ break;
+ case MONO_TYPE_STRING:
+ pa [i] = (char *)(((gpointer *)params->vector)[i]);
+ break;
+ default:
+ g_error ("type 0x%x not handled in invoke", sig->params [i]->type);
+ }
+ }
+
+ if (!strcmp (method->method->name, ".ctor")) {
+ this = mono_object_new (mono_domain_get (), method->method->klass);
+ mono_runtime_invoke (method->method, this, pa);
+ return this;
+ } else
+ return mono_runtime_invoke (method->method, this, pa);
}
static MonoObject *
mono_defaults.corlib, "System.Reflection", "FieldInfo");
res = mono_array_new (domain, System_Reflection_FieldInfo, len);
i = 0;
- tmp = l;
+ tmp = g_slist_reverse (l);
for (; tmp; tmp = tmp->next, ++i)
mono_array_set (res, gpointer, i, tmp->data);
g_slist_free (l);
}
static MonoReflectionType*
-ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly, MonoString *type, MonoBoolean throwOnError, MonoBoolean ignoreCase)
+ves_icall_System_Reflection_Assembly_GetType (MonoReflectionAssembly *assembly, MonoString *name, MonoBoolean throwOnError, MonoBoolean ignoreCase)
{
MonoDomain *domain = mono_domain_get ();
- /* FIXME : use ignoreCase */
- gchar *name, *namespace, *str;
- char *byref, *isarray, *ispointer, *isa2;
- guint rank, recarray = 0;
- MonoClass *klass;
+ gchar *str;
+ MonoType *type;
+ MonoTypeNameParse info;
- str = namespace = mono_string_to_utf8 (type);
+ str = mono_string_to_utf8 (name);
/*g_print ("requested type %s in %s\n", str, assembly->assembly->name);*/
-
- name = strrchr (str, '.');
- byref = strrchr (str, '&');
- ispointer = strrchr (str, '*');
- if (byref)
- *byref = 0;
- if (ispointer)
- *ispointer = 0;
- isarray = strrchr (str, '[');
- if (isarray) {
- rank = 1;
- *isarray = 0;
- while (*isarray) {
- if (*isarray == ',')
- rank++;
- if (*isarray == ']')
- break;
- ++isarray;
- }
- }
-
- isa2 = strrchr (str, '[');
- if (isa2 && *isa2 == '[') {
- /* g_print ("recarray for: type name search: %s.%s\n", namespace, name); */
- recarray = 1;
- *isa2 = 0;
- }
-
- if (name) {
- *name = 0;
- ++name;
- } else {
- namespace = "";
- name = str;
+ if (!mono_reflection_parse_type (str, &info)) {
+ g_free (str);
+ g_list_free (info.modifiers);
+ if (throwOnError) /* uhm: this is a parse error, though... */
+ mono_raise_exception (mono_get_exception_type_load ());
+ return NULL;
}
- /*g_print ("type name search: %s.%s\n", namespace, name);*/
- klass = mono_class_from_name (assembly->assembly->image, namespace, name);
+ type = mono_reflection_get_type (assembly->assembly->image, &info, ignoreCase);
g_free (str);
- if (!klass) {
+ g_list_free (info.modifiers);
+ if (!type) {
if (throwOnError)
mono_raise_exception (mono_get_exception_type_load ());
return NULL;
}
- if (!klass->inited)
- mono_class_init (klass);
-
- if (isarray) {
- klass = mono_array_class_get (&klass->byval_arg, rank);
- mono_class_init (klass);
- if (recarray) {
- klass = mono_array_class_get (&klass->byval_arg, rank);
- mono_class_init (klass);
- }
- /*g_print ("got array class %s [%d] (0x%x)\n", klass->element_class->name, klass->rank, klass->this_arg.type);*/
- }
+ /*g_print ("got it\n");*/
+ return mono_type_get_object (domain, type);
- if (byref || ispointer)
- return mono_type_get_object (domain, &klass->this_arg);
- else
- return mono_type_get_object (domain, &klass->byval_arg);
}
static MonoString *
}
static MonoReflectionType*
-ves_icall_ModuleBuilder_create_modified_type (MonoReflectionType *tb, gint32 arrayrank, MonoBoolean isbyref)
+ves_icall_ModuleBuilder_create_modified_type (MonoReflectionTypeBuilder *tb, MonoString *smodifiers)
{
MonoClass *klass;
-
- if (arrayrank)
- klass = mono_array_class_get (tb->type, arrayrank);
- else
- klass = mono_class_from_mono_type (tb->type);
-
- return mono_type_get_object (mono_domain_get (), isbyref? &klass->this_arg: &klass->byval_arg);
+ int isbyref = 0, rank;
+ char *str = mono_string_to_utf8 (smodifiers);
+ char *p;
+
+ klass = mono_class_from_mono_type (tb->type.type);
+ p = str;
+ /* logic taken from mono_reflection_parse_type(): keep in sync */
+ while (*p) {
+ switch (*p) {
+ case '&':
+ if (isbyref) /* only one level allowed by the spec */
+ return NULL;
+ isbyref = 1;
+ p++;
+ return mono_type_get_object (mono_domain_get (), &klass->this_arg);
+ break;
+ case '*':
+ klass = mono_ptr_class_get (&klass->byval_arg);
+ mono_class_init (klass);
+ p++;
+ break;
+ case '[':
+ rank = 1;
+ p++;
+ while (*p) {
+ if (*p == ']')
+ break;
+ if (*p == ',')
+ rank++;
+ else if (*p != '*') /* '*' means unknown lower bound */
+ return NULL;
+ ++p;
+ }
+ if (*p != ']')
+ return NULL;
+ p++;
+ klass = mono_array_class_get (&klass->byval_arg, rank);
+ mono_class_init (klass);
+ break;
+ default:
+ break;
+ }
+ }
+ g_free (str);
+ return mono_type_get_object (mono_domain_get (), &klass->byval_arg);
}
static MonoString *
gmtoff = tt.tm_gmtoff;
}
-
- return 0;
#endif
+ return 0;
+}
+
+static gpointer
+ves_icall_System_Object_obj_address (MonoObject *this) {
+ return this;
+}
+
+/* System.Buffer */
+
+static gint32
+ves_icall_System_Buffer_ByteLengthInternal (MonoArray *array) {
+ MonoClass *klass;
+ MonoTypeEnum etype;
+ int length, esize;
+ int i;
+
+ klass = array->obj.vtable->klass;
+ etype = klass->element_class->byval_arg.type;
+ if (etype < MONO_TYPE_BOOLEAN || etype > MONO_TYPE_R8)
+ return -1;
+
+ length = 0;
+ for (i = 0; i < klass->rank; ++ i)
+ length += array->bounds [i].length;
+
+ esize = mono_array_element_size (klass);
+ return length * esize;
+}
+
+static gint8
+ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 index) {
+ return mono_array_get (array, gint8, index);
+}
+
+static void
+ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 index, gint8 value) {
+ mono_array_set (array, gint8, index, value);
+}
+
+static void
+ves_icall_System_Buffer_BlockCopyInternal (MonoArray *src, gint32 src_offset, MonoArray *dest, gint32 dest_offset, gint32 count) {
+ char *src_buf, *dest_buf;
+
+ src_buf = (gint8 *)src->vector + src_offset;
+ dest_buf = (gint8 *)dest->vector + dest_offset;
+
+ memcpy (dest_buf, src_buf, count);
}
+/* icall map */
+
static gpointer icall_map [] = {
/*
* System.Array
"System.Object::MemberwiseClone", ves_icall_System_Object_MemberwiseClone,
"System.Object::GetType", ves_icall_System_Object_GetType,
"System.Object::GetHashCode", ves_icall_System_Object_GetHashCode,
+ "System.Object::obj_address", ves_icall_System_Object_obj_address,
/*
* System.ValueType
"System.Reflection.MonoFieldInfo::get_field_info", ves_icall_get_field_info,
"System.Reflection.MonoPropertyInfo::get_property_info", ves_icall_get_property_info,
"System.Reflection.MonoMethod::InternalInvoke", ves_icall_InternalInvoke,
+ "System.Reflection.MonoCMethod::InternalInvoke", ves_icall_InternalInvoke,
"System.MonoCustomAttrs::GetCustomAttributes", mono_reflection_get_custom_attrs,
"System.Reflection.Emit.CustomAttributeBuilder::GetBlob", mono_reflection_get_custom_attrs_blob,
"System.Reflection.MonoField::GetValue", ves_icall_MonoField_GetValue,
+ "System.Reflection.Emit.SignatureHelper::get_signature_local", mono_reflection_sighelper_get_signature_local,
+ "System.Reflection.Emit.SignatureHelper::get_signature_field", mono_reflection_sighelper_get_signature_field,
+
/* System.Enum */
* TypeBuilder
*/
"System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
+
/*
* MethodBuilder
* System.PAL.OpSys I/O Services
*/
"System.PAL.OpSys::GetStdHandle", ves_icall_System_PAL_OpSys_GetStdHandle,
- "System.PAL.OpSys::ReadFile", ves_icall_System_PAL_OpSys_ReadFile,
- "System.PAL.OpSys::WriteFile", ves_icall_System_PAL_OpSys_WriteFile,
- "System.PAL.OpSys::SetLengthFile", ves_icall_System_PAL_OpSys_SetLengthFile,
- "System.PAL.OpSys::OpenFile", ves_icall_System_PAL_OpSys_OpenFile,
- "System.PAL.OpSys::CloseFile", ves_icall_System_PAL_OpSys_CloseFile,
- "System.PAL.OpSys::SeekFile", ves_icall_System_PAL_OpSys_SeekFile,
"System.PAL.OpSys::DeleteFile", ves_icall_System_PAL_OpSys_DeleteFile,
"System.PAL.OpSys::ExistsFile", ves_icall_System_PAL_OpSys_ExistsFile,
"System.PAL.OpSys::GetFileTime", ves_icall_System_PAL_OpSys_GetFileTime,
"System.Security.Cryptography.RNGCryptoServiceProvider::GetBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetBytes,
"System.Security.Cryptography.RNG_CryptoServiceProvider::GetNonZeroBytes", ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_GetNonZeroBytes,
+
+ /*
+ * System.Buffer
+ */
+ "System.Buffer::ByteLengthInternal", ves_icall_System_Buffer_ByteLengthInternal,
+ "System.Buffer::GetByteInternal", ves_icall_System_Buffer_GetByteInternal,
+ "System.Buffer::SetByteInternal", ves_icall_System_Buffer_SetByteInternal,
+ "System.Buffer::BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal,
+
+ /*
+ * System.IO.FileStream
+ */
+ "System.IO.FileStream::FileOpen", ves_icall_System_IO_FileStream_FileOpen,
+ "System.IO.FileStream::FileClose", ves_icall_System_IO_FileStream_FileClose,
+ "System.IO.FileStream::FileRead", ves_icall_System_IO_FileStream_FileRead,
+ "System.IO.FileStream::FileWrite", ves_icall_System_IO_FileStream_FileWrite,
+ "System.IO.FileStream::FileSeek", ves_icall_System_IO_FileStream_FileSeek,
+ "System.IO.FileStream::FileGetLength", ves_icall_System_IO_FileStream_FileGetLength,
+ "System.IO.FileStream::FileSetLength", ves_icall_System_IO_FileStream_FileSetLength,
+ "System.IO.FileStream::FileFlush", ves_icall_System_IO_FileStream_FileFlush,
+
+ /*
+ * System.Math
+ */
+ "System.Math::Sin", ves_icall_System_Math_Sin,
+ "System.Math::Cos", ves_icall_System_Math_Cos,
+ "System.Math::Tan", ves_icall_System_Math_Tan,
+ "System.Math::Sinh", ves_icall_System_Math_Sinh,
+ "System.Math::Cosh", ves_icall_System_Math_Cosh,
+ "System.Math::Tanh", ves_icall_System_Math_Tanh,
+ "System.Math::Acos", ves_icall_System_Math_Acos,
+ "System.Math::Asin", ves_icall_System_Math_Asin,
+ "System.Math::Atan", ves_icall_System_Math_Atan,
+ "System.Math::Atan2", ves_icall_System_Math_Atan2,
+ "System.Math::Exp", ves_icall_System_Math_Exp,
+ "System.Math::Log", ves_icall_System_Math_Log,
+ "System.Math::Log10", ves_icall_System_Math_Log10,
+ "System.Math::Pow", ves_icall_System_Math_Pow,
+ "System.Math::Sqrt", ves_icall_System_Math_Sqrt,
+
+ /*
+ * Mono.CSharp.Debugger
+ */
+ "Mono.CSharp.Debugger.MonoSymbolWriter::get_local_type_from_sig", ves_icall_Debugger_MonoSymbolWriter_get_local_type_from_sig,
+ "Mono.CSharp.Debugger.MonoSymbolWriter::get_method", ves_icall_Debugger_MonoSymbolWriter_method_from_token,
+ "Mono.CSharp.Debugger.DwarfFileWriter::get_type_token", ves_icall_Debugger_DwarfFileWriter_get_type_token,
+
+
/*
* add other internal calls here