* Authors:
* Dietmar Maurer (dietmar@ximian.com)
* Paolo Molaro (lupus@ximian.com)
+ * Patrik Torstensson (patrik.torstensson@labs2.com)
*
* (C) 2001 Ximian, Inc.
*/
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
+#if defined (PLATFORM_WIN32)
+#include <stdlib.h>
+#endif
#include <mono/metadata/object.h>
#include <mono/metadata/threads.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/rand.h>
#include <mono/metadata/sysmath.h>
+#include <mono/metadata/debug-symfile.h>
+#include <mono/metadata/string-icalls.h>
#include <mono/io-layer/io-layer.h>
+
#include "decimal.h"
+static MonoString *
+mono_double_ToStringImpl (double value)
+{
+ /* FIXME: Handle formats, etc. */
+ const gchar *retVal;
+ retVal = g_strdup_printf ("%f", value);
+ return mono_string_new (mono_domain_get (), retVal);
+}
static MonoObject *
ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
}
static void
-ves_icall_System_Array_SetValueImpl (MonoObject *this, MonoObject *value, guint32 pos)
+ves_icall_System_Array_SetValueImpl (MonoArray *this, MonoObject *value, guint32 pos)
{
- MonoArray *ao, *vo;
MonoClass *ac, *vc, *ec;
gint32 esize, vsize;
gpointer *ea, *va;
gint64 i64;
gdouble r64;
- vo = (MonoArray *)value;
- if (vo)
- vc = (MonoClass *)vo->obj.vtable->klass;
+ if (value)
+ vc = value->vtable->klass;
else
vc = NULL;
- ao = (MonoArray *)this;
- ac = (MonoClass *)ao->obj.vtable->klass;
+ ac = this->obj.vtable->klass;
ec = ac->element_class;
esize = mono_array_element_size (ac);
- ea = (gpointer*)((char*)ao->vector + (pos * esize));
- va = (gpointer*)((char*)vo + sizeof (MonoObject));
+ ea = (gpointer*)((char*)this->vector + (pos * esize));
+ va = (gpointer*)((char*)value + sizeof (MonoObject));
- if (!vo) {
+ if (!value) {
memset (ea, 0, esize);
return;
}
}
if (!ec->valuetype) {
- *ea = (gpointer)vo;
+ *ea = (gpointer)value;
return;
}
if (mono_object_isinst (value, ec)) {
- memcpy (ea, (char *)vo + sizeof (MonoObject), esize);
+ memcpy (ea, (char *)value + sizeof (MonoObject), esize);
return;
}
}
static void
-ves_icall_System_Array_SetValue (MonoObject *this, MonoObject *value,
- MonoObject *idxs)
+ves_icall_System_Array_SetValue (MonoArray *this, MonoObject *value,
+ MonoArray *idxs)
{
- MonoArray *ao, *io, *vo;
MonoClass *ac, *ic;
gint32 i, pos, *ind;
MONO_CHECK_ARG_NULL (idxs);
- io = (MonoArray *)idxs;
- ic = (MonoClass *)io->obj.vtable->klass;
-
- ao = (MonoArray *)this;
- ac = (MonoClass *)ao->obj.vtable->klass;
+ ic = idxs->obj.vtable->klass;
+ ac = this->obj.vtable->klass;
g_assert (ic->rank == 1);
- if (io->bounds [0].length != ac->rank)
+ if (idxs->bounds [0].length != ac->rank)
mono_raise_exception (mono_get_exception_argument (NULL, NULL));
- ind = (guint32 *)io->vector;
+ ind = (guint32 *)idxs->vector;
for (i = 0; i < ac->rank; i++)
- if ((ind [i] < ao->bounds [i].lower_bound) ||
- (ind [i] >= ao->bounds [i].length + ao->bounds [i].lower_bound))
+ if ((ind [i] < this->bounds [i].lower_bound) ||
+ (ind [i] >= this->bounds [i].length + this->bounds [i].lower_bound))
mono_raise_exception (mono_get_exception_index_out_of_range ());
- pos = ind [0] - ao->bounds [0].lower_bound;
+ pos = ind [0] - this->bounds [0].lower_bound;
for (i = 1; i < ac->rank; i++)
- pos = pos*ao->bounds [i].length + ind [i] -
- ao->bounds [i].lower_bound;
+ pos = pos * this->bounds [i].length + ind [i] -
+ this->bounds [i].lower_bound;
ves_icall_System_Array_SetValueImpl (this, value, pos);
}
void * dest_addr = mono_array_addr_with_size (dest, element_size, dest_idx);
void * source_addr = mono_array_addr_with_size (source, element_size, source_idx);
- memcpy (dest_addr, source_addr, element_size * length);
+ g_assert (dest_idx + length <= mono_array_length (dest));
+ g_assert (source_idx + length <= mono_array_length (source));
+ memmove (dest_addr, source_addr, element_size * length);
}
static void
size = this->vtable->klass->instance_size - sizeof (MonoObject);
- p = (char *)this + sizeof (MonoObject);
+ p = (const char *)this + sizeof (MonoObject);
for (i = 0; i < size; i++) {
h = (h << 5) - h + *p;
return h;
}
+static MonoBoolean
+ves_icall_System_ValueType_Equals (MonoObject *this, MonoObject *that)
+{
+ gint32 size;
+ const char *p, *s;
+
+ MONO_CHECK_ARG_NULL (that);
+
+ if (this->vtable != that->vtable)
+ return FALSE;
+
+ size = this->vtable->klass->instance_size - sizeof (MonoObject);
+
+ p = (const char *)this + sizeof (MonoObject);
+ s = (const char *)that + sizeof (MonoObject);
+
+ return memcmp (p, s, size)? FALSE: TRUE;
+}
+
static MonoReflectionType *
ves_icall_System_Object_GetType (MonoObject *obj)
{
}
static gint32
-ves_icall_get_data_chunk (MonoReflectionAssemblyBuilder *assb, gint32 offset, MonoArray *buf)
+ves_icall_AssemblyBuilder_getPEHeader (MonoReflectionAssemblyBuilder *assb, MonoArray *buf, gint32 *data_size)
{
- int count;
+ int count, hsize;
+ MonoDynamicAssembly *ass = assb->dynamic_assembly;
+
+ hsize = mono_image_get_header (assb, (char*)buf->vector, buf->bounds->length);
+ if (hsize < 0)
+ return hsize;
+ count = ass->code.index + ass->meta_size;
+ count += 512 - 1;
+ count &= ~(512 - 1);
+ *data_size = count;
+
+ return hsize;
+}
- if (offset == 0) { /* get the header */
- count = mono_image_get_header (assb, (char*)buf->vector, buf->bounds->length);
- if (count != -1)
- return count;
- } else {
- MonoDynamicAssembly *ass = assb->dynamic_assembly;
- char *p = mono_array_addr (buf, char, 0);
- int chunklen;
- offset--;
- count = ass->code.index + ass->meta_size;
- if (count - offset > buf->bounds->length) {
- count = buf->bounds->length;
- } else
- count = count - offset;
- if (offset < ass->code.index) {
- chunklen = ass->code.index - offset;
- memcpy (p, ass->code.data + offset, chunklen);
- offset += chunklen;
- p += chunklen;
- chunklen = count - chunklen;
- } else
- chunklen = count;
- offset -= ass->code.index;
- memcpy (p, ass->assembly.image->raw_metadata + offset, chunklen);
- return count;
- }
+static gint32
+ves_icall_AssemblyBuilder_getDataChunk (MonoReflectionAssemblyBuilder *assb, MonoArray *buf)
+{
+ int count, real_data;
+ MonoDynamicAssembly *ass = assb->dynamic_assembly;
+ char *p = mono_array_addr (buf, char, 0);
- return 0;
+ count = real_data = ass->code.index + ass->meta_size;
+ count += 512 - 1;
+ count &= ~(512 - 1);
+ if (count > mono_array_length (buf))
+ return -1;
+ count -= real_data;
+
+ memcpy (p, ass->code.data, ass->code.index);
+ p += ass->code.index;
+ memcpy (p, ass->assembly.image->raw_metadata, ass->meta_size);
+ p += ass->meta_size;
+ /* null-pad section */
+ memset (p, 0, count);
+
+ return real_data + count;
}
static MonoReflectionType*
info->parent = mono_type_get_object (domain, &method->klass->byval_arg);
info->ret = mono_type_get_object (domain, method->signature->ret);
- info->name = mono_string_new (domain, method->name);
info->attrs = method->flags;
info->implattrs = method->iflags;
}
info->name_space = mono_string_new (domain, class->name_space);
info->attrs = class->flags;
info->rank = class->rank;
- info->assembly = NULL; /* FIXME */
+ info->assembly = mono_assembly_get_object (domain, class->image->assembly);
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->isprimitive = (type->type >= MONO_TYPE_BOOLEAN) && (type->type <= MONO_TYPE_R8);
}
-static MonoObject*
+static MonoObject *
ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
{
- MonoMethodSignature *sig = method->method->signature;
- gpointer *pa;
- int i;
+ return mono_runtime_invoke_array (method->method, this, params);
+}
- pa = alloca (sizeof (gpointer) * params->bounds->length);
+static MonoObject *
+ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this, MonoArray *params, MonoArray **outArgs)
+{
+ MonoDomain *domain = mono_domain_get ();
+ MonoMethod *m = method->method;
+ MonoMethodSignature *sig = m->signature;
+ MonoArray *out_args;
+ MonoObject *result;
+ int i, j, outarg_count = 0;
+
+ if (m->klass == mono_defaults.object_class) {
+
+ if (!strcmp (m->name, "FieldGetter")) {
+ MonoClass *k = this->vtable->klass;
+ MonoString *name = mono_array_get (params, MonoString *, 1);
+ char *str;
+
+ str = mono_string_to_utf8 (name);
+
+ for (i = 0; i < k->field.count; i++) {
+ if (!strcmp (k->fields [i].name, str)) {
+ MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
+ if (field_klass->valuetype)
+ result = mono_value_box (domain, field_klass,
+ (char *)this + k->fields [i].offset);
+ else
+ result = *((gpointer *)((char *)this + k->fields [i].offset));
+
+ g_assert (result);
+ out_args = mono_array_new (domain, mono_defaults.object_class, 1);
+ *outArgs = out_args;
+ mono_array_set (out_args, gpointer, 0, result);
+ g_free (str);
+ return NULL;
+ }
+ }
- for (i = 0; i < params->bounds->length; i++) {
- if (sig->params [i]->byref) {
- /* fixme: don't know how to handle this */
+ g_free (str);
g_assert_not_reached ();
+
+ } else if (!strcmp (m->name, "FieldSetter")) {
+ MonoClass *k = this->vtable->klass;
+ MonoString *name = mono_array_get (params, MonoString *, 1);
+ int size, align;
+ char *str;
+
+ str = mono_string_to_utf8 (name);
+
+ for (i = 0; i < k->field.count; i++) {
+ if (!strcmp (k->fields [i].name, str)) {
+ MonoClass *field_klass = mono_class_from_mono_type (k->fields [i].type);
+ MonoObject *val = mono_array_get (params, gpointer, 2);
+
+ if (field_klass->valuetype) {
+ size = mono_type_size (k->fields [i].type, &align);
+ memcpy ((char *)this + k->fields [i].offset,
+ ((char *)val) + sizeof (MonoObject), size);
+ } else
+ *((gpointer *)this + k->fields [i].offset) = val;
+
+ g_assert (result);
+ g_free (str);
+ return NULL;
+ }
+ }
+
+ g_free (str);
+ 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);
+ for (i = 0; i < params->bounds->length; i++) {
+ if (sig->params [i]->byref)
+ outarg_count++;
+ }
+
+ out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
+
+ for (i = 0, j = 0; i < params->bounds->length; i++) {
+ if (sig->params [i]->byref) {
+ gpointer arg;
+ arg = mono_array_get (params, gpointer, i);
+ mono_array_set (out_args, gpointer, j, arg);
+ j++;
}
}
- 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);
+ /* fixme: handle constructors? */
+ if (!strcmp (method->method->name, ".ctor"))
+ g_assert_not_reached ();
+
+ result = mono_runtime_invoke_array (method->method, this, params);
+
+ *outArgs = out_args;
+
+ return result;
}
static MonoObject *
ves_icall_System_Enum_ToObject (MonoReflectionType *type, MonoObject *obj)
{
MonoDomain *domain = mono_domain_get ();
- MonoClass *enumc;
+ MonoClass *enumc, *objc;
gint32 s1, s2;
MonoObject *res;
MONO_CHECK_ARG_NULL (obj);
enumc = mono_class_from_mono_type (type->type);
+ objc = obj->vtable->klass;
MONO_CHECK_ARG (obj, enumc->enumtype == TRUE);
- MONO_CHECK_ARG (obj, obj->vtable->klass->byval_arg.type >= MONO_TYPE_I1 &&
- obj->vtable->klass->byval_arg.type <= MONO_TYPE_U8);
-
+ MONO_CHECK_ARG (obj, (objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 &&
+ objc->byval_arg.type <= MONO_TYPE_U8));
s1 = mono_class_value_size (enumc, NULL);
- s2 = mono_class_value_size (obj->vtable->klass, NULL);
+ s2 = mono_class_value_size (objc, NULL);
res = mono_object_new (domain, enumc);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- memcpy ((gpointer)res + sizeof (MonoObject), (gpointer)obj + sizeof (MonoObject), MIN (s1, s2));
+ memcpy ((char *)res + sizeof (MonoObject), (char *)obj + sizeof (MonoObject), MIN (s1, s2));
#else
- memcpy ((gpointer)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
- (gpointer)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
+ memcpy ((char *)res + sizeof (MonoObject) + (s1 > s2 ? s1 - s2 : 0),
+ (char *)obj + sizeof (MonoObject) + (s2 > s1 ? s2 - s1 : 0),
MIN (s1, s2));
#endif
return res;
enumc = mono_class_from_mono_type (this->vtable->klass->enum_basetype);
res = mono_object_new (domain, enumc);
- dst = (gpointer)res + sizeof (MonoObject);
- src = (gpointer)this + sizeof (MonoObject);
+ dst = (char *)res + sizeof (MonoObject);
+ src = (char *)this + sizeof (MonoObject);
size = mono_class_value_size (enumc, NULL);
memcpy (dst, src, size);
info->utype = mono_type_get_object (domain, enumc->enum_basetype);
nvalues = enumc->field.count - 1;
info->names = mono_array_new (domain, mono_defaults.string_class, nvalues);
- info->values = mono_array_new (domain, mono_class_from_mono_type (enumc->enum_basetype), nvalues);
+ info->values = mono_array_new (domain, enumc, nvalues);
for (i = 0, j = 0; i < enumc->field.count; ++i) {
field = &enumc->fields [i];
}
static MonoMethod*
-search_method (MonoReflectionType *type, char *name, guint32 flags, MonoArray *args)
+search_method (MonoReflectionType *type, const char *name, guint32 flags, MonoArray *args)
{
MonoClass *klass, *start_class;
MonoMethod *m;
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);
domain = ((MonoObject *)type)->vtable->domain;
klass = startklass = mono_class_from_mono_type (type->type);
-handle_parent:
+handle_parent:
for (i = 0; i < klass->method.count; ++i) {
match = 0;
method = klass->methods [i];
domain = ((MonoObject *)type)->vtable->domain;
klass = startklass = mono_class_from_mono_type (type->type);
-handle_parent:
+handle_parent:
for (i = 0; i < klass->property.count; ++i) {
prop = &klass->properties [i];
match = 0;
return res;
}
+static MonoArray*
+ves_icall_Type_GetNestedTypes (MonoReflectionType *type, guint32 bflags)
+{
+ MonoDomain *domain;
+ GSList *l = NULL, *tmp;
+ GList *tmpn;
+ MonoClass *startklass, *klass;
+ MonoArray *res;
+ MonoObject *member;
+ int i, len, match;
+ MonoClass *nested;
+
+ domain = ((MonoObject *)type)->vtable->domain;
+ klass = startklass = mono_class_from_mono_type (type->type);
+
+ for (tmpn = klass->nested_classes; tmpn; tmpn = tmpn->next) {
+ match = 0;
+ nested = tmpn->data;
+ if ((nested->flags & TYPE_ATTRIBUTE_VISIBILITY_MASK) == TYPE_ATTRIBUTE_NESTED_PUBLIC) {
+ if (bflags & BFLAGS_Public)
+ match++;
+ } else {
+ if (bflags & BFLAGS_NonPublic)
+ match++;
+ }
+ if (!match)
+ continue;
+ member = (MonoObject*)mono_type_get_object (domain, &nested->byval_arg);
+ l = g_slist_prepend (l, member);
+ }
+ len = g_slist_length (l);
+ res = mono_array_new (domain, mono_defaults.monotype_class, len);
+ i = 0;
+ tmp = g_slist_reverse (l);
+ for (; tmp; tmp = tmp->next, ++i)
+ mono_array_set (res, gpointer, i, tmp->data);
+ g_slist_free (l);
+ return res;
+}
+
static gpointer
ves_icall_System_Runtime_InteropServices_Marshal_ReadIntPtr (gpointer ptr)
{
}
static MonoString *
-ves_icall_System_MonoType_assQualifiedName (MonoReflectionType *object)
+ves_icall_System_MonoType_getFullName (MonoReflectionType *object)
{
MonoDomain *domain = mono_domain_get ();
- /* FIXME : real rules are more complicated (internal classes,
- reference types, array types, etc. */
MonoString *res;
- gchar *fullname;
+ gchar *name;
+
+ name = mono_type_get_name (object->type);
+ res = mono_string_new (domain, name);
+ g_free (name);
+
+ return res;
+}
+
+static MonoArray*
+ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
+{
+ MonoDomain *domain = mono_domain_get ();
+ MonoArray *res;
MonoClass *klass;
- char *append = NULL;
-
- switch (object->type->type) {
- case MONO_TYPE_ARRAY: {
- int i, rank = object->type->data.array->rank;
- char *tmp, *str = g_strdup ("[");
- klass = mono_class_from_mono_type (object->type->data.array->type);
- for (i = 1; i < rank; i++) {
- tmp = g_strconcat (str, ",", NULL);
- g_free (str);
- str = tmp;
+ MonoTableInfo *tdef = &assembly->assembly->image->tables [MONO_TABLE_TYPEDEF];
+ int i, count;
+ guint32 attrs, visibility;
+
+ if (exportedOnly) {
+ count = 0;
+ for (i = 0; i < tdef->rows; ++i) {
+ attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
+ visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
+ if (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)
+ count++;
}
- tmp = g_strconcat (str, "]", NULL);
- g_free (str);
- append = tmp;
- break;
+ } else {
+ count = tdef->rows;
}
- case MONO_TYPE_SZARRAY:
- klass = mono_class_from_mono_type (object->type->data.type);
- append = g_strdup ("[]");
- break;
- case MONO_TYPE_PTR:
- klass = mono_class_from_mono_type (object->type->data.type);
- append = g_strdup ("*");
- break;
- default:
- klass = object->type->data.klass;
- break;
+ res = mono_array_new (domain, mono_defaults.monotype_class, count);
+ count = 0;
+ for (i = 0; i < tdef->rows; ++i) {
+ attrs = mono_metadata_decode_row_col (tdef, i, MONO_TYPEDEF_FLAGS);
+ visibility = attrs & TYPE_ATTRIBUTE_VISIBILITY_MASK;
+ if (!exportedOnly || (visibility == TYPE_ATTRIBUTE_PUBLIC || visibility == TYPE_ATTRIBUTE_NESTED_PUBLIC)) {
+ klass = mono_class_get (assembly->assembly->image, (i + 1) | MONO_TOKEN_TYPE_DEF);
+ mono_array_set (res, gpointer, count, mono_type_get_object (domain, &klass->byval_arg));
+ count++;
+ }
}
-
- fullname = g_strconcat (klass->name_space, ".",
- klass->name, append, ",",
- klass->image->assembly_name, NULL);
- res = mono_string_new (domain, fullname);
- g_free (fullname);
- g_free (append);
-
+
return res;
}
return mono_type_get_object (mono_domain_get (), &klass->byval_arg);
}
-static MonoString *
-ves_icall_System_PAL_GetCurrentDirectory (MonoObject *object)
-{
- MonoDomain *domain = mono_domain_get ();
- MonoString *res;
- gchar *path = g_get_current_dir ();
- res = mono_string_new (domain, path);
- g_free (path);
- return res;
-}
-
/*
* Magic number to convert a time which is relative to
* Jan 1, 1970 into a value which is relative to Jan 1, 0001.
#define EPOCH_ADJUST ((gint64)62135596800L)
static gint64
-ves_icall_System_DateTime_GetNow ()
+ves_icall_System_DateTime_GetNow (void)
{
#ifndef PLATFORM_WIN32
/* FIXME: put this in io-layer and call it GetLocalTime */
gmtoff = tt.tm_gmtoff;
}
+ return 1;
#endif
+ /* FIXME: This is a reminder to implement this icall on windows */
return 0;
}
}
static gint8
-ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 index) {
- return mono_array_get (array, gint8, index);
+ves_icall_System_Buffer_GetByteInternal (MonoArray *array, gint32 idx) {
+ return mono_array_get (array, gint8, idx);
}
static void
-ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 index, gint8 value) {
- mono_array_set (array, gint8, index, value);
+ves_icall_System_Buffer_SetByteInternal (MonoArray *array, gint32 idx, gint8 value) {
+ mono_array_set (array, gint8, idx, value);
}
static void
memcpy (dest_buf, src_buf, count);
}
+static MonoObject *
+ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this)
+{
+ MonoDomain *domain = mono_domain_get ();
+ MonoObject *res;
+ MonoRealProxy *rp = ((MonoRealProxy *)this);
+ MonoType *type;
+ MonoClass *klass;
+
+ res = mono_object_new (domain, mono_defaults.transparent_proxy_class);
+
+ ((MonoTransparentProxy *)res)->rp = rp;
+ type = ((MonoReflectionType *)rp->class_to_proxy)->type;
+ klass = mono_class_from_mono_type (type);
+
+ ((MonoTransparentProxy *)res)->klass = klass;
+
+ res->vtable = mono_class_proxy_vtable (domain, klass);
+
+ return res;
+}
+
+/* System.Environment */
+
+static MonoString *
+ves_icall_System_Environment_get_MachineName (void)
+{
+#if defined (PLATFORM_WIN32)
+ gunichar2 *buf;
+ guint32 len;
+ MonoString *result;
+
+ len = MAX_COMPUTERNAME_LENGTH + 1;
+ buf = g_new (gunichar2, len);
+
+ result = NULL;
+ if (GetComputerName (buf, &len))
+ result = mono_string_new_utf16 (mono_domain_get (), buf, len);
+
+ g_free (buf);
+ return result;
+#else
+ gchar *buf;
+ int len;
+ MonoString *result;
+
+ len = 256;
+ buf = g_new (gchar, len);
+
+ result = NULL;
+ if (gethostname (buf, len) != 0)
+ result = mono_string_new (mono_domain_get (), buf);
+
+ g_free (buf);
+ return result;
+#endif
+}
+
+static MonoString *
+ves_icall_System_Environment_get_NewLine (void)
+{
+#if defined (PLATFORM_WIN32)
+ return mono_string_new (mono_domain_get (), "\r\n");
+#else
+ return mono_string_new (mono_domain_get (), "\n");
+#endif
+}
+
+static MonoString *
+ves_icall_System_Environment_GetEnvironmentVariable (MonoString *name)
+{
+ const gchar *value;
+ gchar *utf8_name;
+
+ if (name == NULL)
+ return NULL;
+
+ utf8_name = mono_string_to_utf8 (name); /* FIXME: this should be ascii */
+ value = g_getenv (utf8_name);
+ g_free (utf8_name);
+
+ if (value == 0)
+ return NULL;
+
+ return mono_string_new (mono_domain_get (), value);
+}
+
+/*
+ * There is no standard way to get at environ.
+ */
+extern char **environ;
+
+static MonoArray *
+ves_icall_System_Environment_GetEnvironmentVariableNames (void)
+{
+ MonoArray *names;
+ MonoDomain *domain;
+ MonoString *str;
+ gchar **e, **parts;
+ int n;
+
+ n = 0;
+ for (e = environ; *e != 0; ++ e)
+ ++ n;
+
+ domain = mono_domain_get ();
+ names = mono_array_new (domain, mono_defaults.string_class, n);
+
+ n = 0;
+ for (e = environ; *e != 0; ++ e) {
+ parts = g_strsplit (*e, "=", 2);
+ if (*parts != 0) {
+ str = mono_string_new (domain, *parts);
+ mono_array_set (names, MonoString *, n, str);
+ }
+
+ g_strfreev (parts);
+
+ ++ n;
+ }
+
+ return names;
+}
+
+static MonoString *
+ves_icall_System_Environment_GetCommandLine (void)
+{
+ return NULL; /* FIXME */
+}
+
+static void
+ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this,
+ MonoReflectionMethod *method,
+ MonoArray *out_args)
+{
+ MonoDomain *domain = mono_domain_get ();
+
+ mono_message_init (domain, this, method, out_args);
+}
+
+static MonoBoolean
+ves_icall_IsTransparentProxy (MonoObject *proxy)
+{
+ if (!proxy)
+ return 0;
+
+ if (proxy->vtable->klass == mono_defaults.transparent_proxy_class)
+ return 1;
+
+ return 0;
+}
+
+static gint32
+ves_icall_System_String_InternalIndexOfAny (MonoString *str, MonoArray *chars, gint32 start, gint32 count)
+{
+ int i, j;
+ gunichar2 *data = mono_string_chars (str);
+
+ for (i = start; i < start + count; ++i) {
+ for (j = 0; j < mono_array_length (chars); ++j) {
+ if (data [i] == mono_array_get (chars, guint16, j))
+ return i;
+ }
+ }
+ return -1;
+}
+
+static gint32
+ves_icall_System_String_GetHashCode (MonoString *str)
+{
+ int i, h = 0;
+ gunichar2 *data = mono_string_chars (str);
+
+ for (i = 0; i < mono_string_length (str); ++i)
+ h = (h << 5) - h + data [i];
+ return h;
+}
+
/* icall map */
-static gpointer icall_map [] = {
+static gconstpointer icall_map [] = {
/*
* System.Array
*/
* System.ValueType
*/
"System.ValueType::GetHashCode", ves_icall_System_ValueType_GetHashCode,
+ "System.ValueType::Equals", ves_icall_System_ValueType_Equals,
/*
* System.String
*/
- "System.String::_IsInterned", mono_string_is_interned,
- "System.String::_Intern", mono_string_intern,
+
+ "System.String::InternalJoin", mono_string_InternalJoin,
+ "System.String::InternalInsert", mono_string_InternalInsert,
+ "System.String::InternalReplace(char,char)", mono_string_InternalReplaceChar,
+ "System.String::InternalReplace(string,string)", mono_string_InternalReplaceStr,
+ "System.String::InternalRemove", mono_string_InternalRemove,
+ "System.String::InternalCopyTo", mono_string_InternalCopyTo,
+ "System.String::InternalSplit", mono_string_InternalSplit,
+ "System.String::InternalTrim", mono_string_InternalTrim,
+ "System.String::InternalIndexOf(char,uint,uint)", mono_string_InternalIndexOfChar,
+ "System.String::InternalIndexOf(string,uint,uint)", mono_string_InternalIndexOfStr,
+ "System.String::InternalIndexOfAny", mono_string_InternalIndexOfAny,
+ "System.String::InternalLastIndexOf(char,uint,uint)", mono_string_InternalLastIndexOfChar,
+ "System.String::InternalLastIndexOf(string,uint,uint)", mono_string_InternalLastIndexOfStr,
+ "System.String::InternalLastIndexOfAny", mono_string_InternalLastIndexOfAny,
+ "System.String::InternalPad", mono_string_InternalPad,
+ "System.String::InternalToLower", mono_string_InternalToLower,
+ "System.String::InternalToUpper", mono_string_InternalToUpper,
+ "System.String::InternalAllocateStr", mono_string_InternalAllocateStr,
+ "System.String::InternalStrcpy(string,uint,string)", mono_string_InternalStrcpyStr,
+ "System.String::InternalStrcpy(string,uint,string,uint,uint)", mono_string_InternalStrcpyStrN,
+ "System.String::InternalIntern", mono_string_intern,
+ "System.String::InternalIsInterned", mono_string_is_interned,
+ "System.String::InternalCompare(string,uint,string,uint,uint,bool)", mono_string_InternalCompareStrN,
+ "System.String::GetHashCode", mono_string_GetHashCode,
+ "System.String::get_Chars", mono_string_get_Chars,
/*
* System.AppDomain
*/
"System.AppDomainSetup::InitAppDomainSetup", ves_icall_System_AppDomainSetup_InitAppDomainSetup,
+ /*
+ * System.Double
+ */
+ "System.Double::ToStringImpl", mono_double_ToStringImpl,
+
/*
* System.Decimal
*/
/*
* AssemblyBuilder
*/
- "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_get_data_chunk,
+ "System.Reflection.Emit.AssemblyBuilder::getDataChunk", ves_icall_AssemblyBuilder_getDataChunk,
+ "System.Reflection.Emit.AssemblyBuilder::getPEHeader", ves_icall_AssemblyBuilder_getPEHeader,
"System.Reflection.Emit.AssemblyBuilder::getUSIndex", mono_image_insert_string,
"System.Reflection.Emit.AssemblyBuilder::getToken", ves_icall_AssemblyBuilder_getToken,
"System.Reflection.Emit.AssemblyBuilder::basic_init", mono_image_basic_init,
* TypeBuilder
*/
"System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
+
/*
* MethodBuilder
"System.Threading.Thread::Start_internal", ves_icall_System_Threading_Thread_Start_internal,
"System.Threading.Thread::Sleep_internal", ves_icall_System_Threading_Thread_Sleep_internal,
"System.Threading.Thread::CurrentThread_internal", ves_icall_System_Threading_Thread_CurrentThread_internal,
+ "System.Threading.Thread::CurrentThreadDomain_internal", ves_icall_System_Threading_Thread_CurrentThreadDomain_internal,
"System.Threading.Thread::Join_internal", ves_icall_System_Threading_Thread_Join_internal,
"System.Threading.Thread::SlotHash_lookup", ves_icall_System_Threading_Thread_SlotHash_lookup,
"System.Threading.Thread::SlotHash_store", ves_icall_System_Threading_Thread_SlotHash_store,
"System.Runtime.InteropServices.Marshal::GetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error,
"System.Reflection.Assembly::GetType", ves_icall_System_Reflection_Assembly_GetType,
+ "System.Reflection.Assembly::GetTypes", ves_icall_System_Reflection_Assembly_GetTypes,
"System.Reflection.Assembly::get_code_base", ves_icall_System_Reflection_Assembly_get_code_base,
/*
* System.MonoType.
*/
- "System.MonoType::assQualifiedName", ves_icall_System_MonoType_assQualifiedName,
+ "System.MonoType::getFullName", ves_icall_System_MonoType_getFullName,
"System.MonoType::type_from_obj", mono_type_type_from_obj,
"System.MonoType::get_type_info", ves_icall_get_type_info,
"System.MonoType::GetFields", ves_icall_Type_GetFields,
"System.MonoType::GetProperties", ves_icall_Type_GetProperties,
"System.MonoType::GetEvents", ves_icall_Type_GetEvents,
"System.MonoType::GetInterfaces", ves_icall_Type_GetInterfaces,
-
- "System.PAL.OpSys::GetCurrentDirectory", ves_icall_System_PAL_GetCurrentDirectory,
-
- /*
- * System.PAL.OpSys I/O Services
- */
- "System.PAL.OpSys::GetStdHandle", ves_icall_System_PAL_OpSys_GetStdHandle,
- "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.PAL.OpSys::SetFileTime", ves_icall_System_PAL_OpSys_SetFileTime,
+ "System.MonoType::GetNestedTypes", ves_icall_Type_GetNestedTypes,
/*
* System.Net.Sockets I/O Services
"System.Buffer::BlockCopyInternal", ves_icall_System_Buffer_BlockCopyInternal,
/*
- * System.IO.FileStream
+ * System.IO.MonoIO
*/
- "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.IO.MonoIO::GetLastError", ves_icall_System_IO_MonoIO_GetLastError,
+ "System.IO.MonoIO::CreateDirectory", ves_icall_System_IO_MonoIO_CreateDirectory,
+ "System.IO.MonoIO::RemoveDirectory", ves_icall_System_IO_MonoIO_RemoveDirectory,
+ "System.IO.MonoIO::FindFirstFile", ves_icall_System_IO_MonoIO_FindFirstFile,
+ "System.IO.MonoIO::FindNextFile", ves_icall_System_IO_MonoIO_FindNextFile,
+ "System.IO.MonoIO::FindClose", ves_icall_System_IO_MonoIO_FindClose,
+ "System.IO.MonoIO::GetCurrentDirectory", ves_icall_System_IO_MonoIO_GetCurrentDirectory,
+ "System.IO.MonoIO::SetCurrentDirectory", ves_icall_System_IO_MonoIO_SetCurrentDirectory,
+ "System.IO.MonoIO::MoveFile", ves_icall_System_IO_MonoIO_MoveFile,
+ "System.IO.MonoIO::CopyFile", ves_icall_System_IO_MonoIO_CopyFile,
+ "System.IO.MonoIO::DeleteFile", ves_icall_System_IO_MonoIO_DeleteFile,
+ "System.IO.MonoIO::GetFileAttributes", ves_icall_System_IO_MonoIO_GetFileAttributes,
+ "System.IO.MonoIO::SetFileAttributes", ves_icall_System_IO_MonoIO_SetFileAttributes,
+ "System.IO.MonoIO::GetFileStat", ves_icall_System_IO_MonoIO_GetFileStat,
+ "System.IO.MonoIO::Open", ves_icall_System_IO_MonoIO_Open,
+ "System.IO.MonoIO::Close", ves_icall_System_IO_MonoIO_Close,
+ "System.IO.MonoIO::Read", ves_icall_System_IO_MonoIO_Read,
+ "System.IO.MonoIO::Write", ves_icall_System_IO_MonoIO_Write,
+ "System.IO.MonoIO::Seek", ves_icall_System_IO_MonoIO_Seek,
+ "System.IO.MonoIO::GetLength", ves_icall_System_IO_MonoIO_GetLength,
+ "System.IO.MonoIO::SetLength", ves_icall_System_IO_MonoIO_SetLength,
+ "System.IO.MonoIO::SetFileTime", ves_icall_System_IO_MonoIO_SetFileTime,
+ "System.IO.MonoIO::Flush", ves_icall_System_IO_MonoIO_Flush,
+ "System.IO.MonoIO::get_ConsoleOutput", ves_icall_System_IO_MonoIO_get_ConsoleOutput,
+ "System.IO.MonoIO::get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput,
+ "System.IO.MonoIO::get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError,
+ "System.IO.MonoIO::get_VolumeSeparatorChar", ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar,
+ "System.IO.MonoIO::get_DirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_DirectorySeparatorChar,
+ "System.IO.MonoIO::get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar,
+ "System.IO.MonoIO::get_PathSeparator", ves_icall_System_IO_MonoIO_get_PathSeparator,
+ "System.IO.MonoIO::get_InvalidPathChars", ves_icall_System_IO_MonoIO_get_InvalidPathChars,
/*
* System.Math
"System.Math::Pow", ves_icall_System_Math_Pow,
"System.Math::Sqrt", ves_icall_System_Math_Sqrt,
+ /*
+ * System.Environment
+ */
+ "System.Environment::get_MachineName", ves_icall_System_Environment_get_MachineName,
+ "System.Environment::get_NewLine", ves_icall_System_Environment_get_NewLine,
+ "System.Environment::GetEnvironmentVariable", ves_icall_System_Environment_GetEnvironmentVariable,
+ "System.Environment::GetEnvironmentVariableNames", ves_icall_System_Environment_GetEnvironmentVariableNames,
+ "System.Environment::GetCommandLine", ves_icall_System_Environment_GetCommandLine,
+
+ /*
+ * 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,
+
+
+ /*
+ * System.Runtime.Remoting
+ */
+ "System.Runtime.Remoting.RemotingServices::InternalExecute",
+ ves_icall_InternalExecute,
+ "System.Runtime.Remoting.RemotingServices::IsTransparentProxy",
+ ves_icall_IsTransparentProxy,
+
+ /*
+ * System.Runtime.Remoting.Messaging
+ */
+ "System.Runtime.Remoting.Messaging.MonoMethodMessage::InitMessage",
+ ves_icall_MonoMethodMessage_InitMessage,
+
+ /*
+ * System.Runtime.Remoting.Proxies
+ */
+ "System.Runtime.Remoting.Proxies.RealProxy::GetTransparentProxy",
+ ves_icall_Remoting_RealProxy_GetTransparentProxy,
+
/*
* add other internal calls here
*/
};
void
-mono_init_icall ()
+mono_init_icall (void)
{
- char *n;
+ const char *name;
int i = 0;
- while ((n = icall_map [i])) {
- mono_add_internal_call (n, icall_map [i+1]);
+ while ((name = icall_map [i])) {
+ mono_add_internal_call (name, icall_map [i+1]);
i += 2;
}