#include <mono/metadata/process.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/profiler-private.h>
+#include <mono/metadata/locales.h>
#include <mono/io-layer/io-layer.h>
#include <mono/utils/strtod.h>
}
if (!ec->valuetype) {
+ if (!mono_object_isinst (value, ec))
+ INVALID_CAST;
*ea = (gpointer)value;
return;
}
}
static MonoArray*
-ves_icall_Type_GetGenericParameters (MonoReflectionType *type)
+ves_icall_Type_GetGenericArguments (MonoReflectionType *type)
{
MonoArray *res;
MonoClass *klass, *pklass;
} else if (klass->gen_params) {
res = mono_array_new (mono_object_domain (type), mono_defaults.monotype_class, klass->num_gen_params);
for (i = 0; i < klass->num_gen_params; ++i) {
- pklass = mono_class_from_gen_param (klass->image, FALSE, i, &klass->gen_params [i]);
+ pklass = mono_class_from_generic_parameter (&klass->gen_params [i], klass->image, FALSE);
mono_array_set (res, gpointer, i, mono_type_get_object (mono_object_domain (type), &pklass->byval_arg));
}
} else if (klass->generic_inst) {
return res;
}
+static gboolean
+ves_icall_Type_get_IsGenericTypeDefinition (MonoReflectionType *type)
+{
+ MonoClass *klass;
+ MONO_ARCH_SAVE_REGS;
+
+ if (type->type->byref)
+ return FALSE;
+ klass = mono_class_from_mono_type (type->type);
+
+ return klass->gen_params != NULL;
+}
+
static MonoReflectionType*
-ves_icall_Type_GetGenericTypeDefinition (MonoReflectionType *type)
+ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
{
MonoClass *klass;
MONO_ARCH_SAVE_REGS;
if (klass->gen_params) {
return type; /* check this one */
}
- if (klass->generic_inst)
- return mono_type_get_object (mono_object_domain (type), klass->generic_inst->data.generic_inst->generic_type);
+ if (klass->generic_inst) {
+ MonoType *generic_type = klass->generic_inst->data.generic_inst->generic_type;
+ MonoClass *generic_class = mono_class_from_mono_type (generic_type);
+
+ if (generic_class->wastypebuilder && generic_class->reflection_info)
+ return generic_class->reflection_info;
+ else
+ return mono_type_get_object (mono_object_domain (type), generic_type);
+ }
return NULL;
}
ves_icall_Type_BindGenericParameters (MonoReflectionType *type, MonoArray *types)
{
MonoClass *klass;
- MonoType *geninst;
- MonoGenericInst *ginst;
- int i;
MONO_ARCH_SAVE_REGS;
if (type->type->byref)
return NULL;
- klass = mono_class_from_mono_type (type->type);
- if (klass->num_gen_params != mono_array_length (types))
- return NULL;
- geninst = g_new0 (MonoType, 1);
- geninst->type = MONO_TYPE_GENERICINST;
- geninst->data.generic_inst = ginst = g_new0 (MonoGenericInst, 1);
- ginst->generic_type = &klass->byval_arg;
- ginst->type_argc = klass->num_gen_params;
- ginst->type_argv = g_new0 (MonoType, klass->num_gen_params);
- for (i = 0; i < klass->num_gen_params; ++i) {
- MonoReflectionType *garg = mono_array_get (types, gpointer, i);
- ginst->type_argv [i] = garg->type;
- }
+ klass = mono_reflection_bind_generic_parameters (type, types);
- klass = mono_class_from_generic (geninst);
- return mono_type_get_object (mono_object_domain (type), &klass->byval_arg);
+ return mono_type_get_object (mono_object_domain (type), klass->generic_inst);
}
-static MonoReflectionType*
-ves_icall_Type_IsGenericTypeDefinition (MonoReflectionType *type)
+static gboolean
+ves_icall_Type_get_IsGenericInstance (MonoReflectionType *type)
{
MonoClass *klass;
MONO_ARCH_SAVE_REGS;
if (type->type->byref)
- return NULL;
+ return FALSE;
klass = mono_class_from_mono_type (type->type);
- if (klass->gen_params) {
- return type; /* check this one */
- }
- if (klass->generic_inst)
- return mono_type_get_object (mono_object_domain (type), klass->generic_inst->data.generic_inst->generic_type);
- return NULL;
+ return klass->generic_inst != NULL;
}
static gint32
ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
{
- MonoClass *klass;
MONO_ARCH_SAVE_REGS;
if (type->type->byref)
return -1;
if (type->type->type == MONO_TYPE_VAR || type->type->type == MONO_TYPE_MVAR)
- return type->type->data.type_param;
+ return type->type->data.generic_param->num;
return -1;
}
static MonoBoolean
-ves_icall_MonoType_get_HasGenericParameteres (MonoReflectionType *type)
+ves_icall_MonoType_get_HasGenericArguments (MonoReflectionType *type)
{
MonoClass *klass;
MONO_ARCH_SAVE_REGS;
}
static MonoBoolean
-ves_icall_MonoType_get_IsUnboundGenericParameter (MonoReflectionType *type)
+ves_icall_MonoType_get_IsGenericParameter (MonoReflectionType *type)
{
MONO_ARCH_SAVE_REGS;
}
static MonoBoolean
-ves_icall_MonoType_get_HasUnboundGenericParameters (MonoReflectionType *type)
+ves_icall_TypeBuilder_get_IsGenericParameter (MonoReflectionTypeBuilder *tb)
{
+ MONO_ARCH_SAVE_REGS;
+
+ if (tb->type.type->byref)
+ return FALSE;
+ if (tb->type.type->type == MONO_TYPE_VAR || tb->type.type->type == MONO_TYPE_MVAR)
+ return TRUE;
+ return FALSE;
+}
+
+static MonoReflectionType*
+ves_icall_TypeBuilder_define_generic_parameter (MonoReflectionTypeBuilder *tb, MonoReflectionGenericParam *gparam)
+{
+ guint32 index;
+
+ MONO_ARCH_SAVE_REGS;
+
+ index = mono_array_length (tb->generic_params) - 1;
+ return mono_reflection_define_generic_parameter (tb, NULL, index, gparam);
+}
+
+static MonoReflectionType*
+ves_icall_MethodBuilder_define_generic_parameter (MonoReflectionMethodBuilder *mb, MonoReflectionGenericParam *gparam)
+{
+ guint32 index;
+
+ MONO_ARCH_SAVE_REGS;
+
+ index = mono_array_length (mb->generic_params) - 1;
+ return mono_reflection_define_generic_parameter (NULL, mb, index, gparam);
+}
+
+static MonoReflectionMethod *
+ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *type)
+{
+ MonoMethod *method;
MonoClass *klass;
+
MONO_ARCH_SAVE_REGS;
if (type->type->byref)
return FALSE;
+
+ method = type->type->data.generic_param->method;
+ if (!method)
+ return NULL;
+
klass = mono_class_from_mono_type (type->type);
- if (klass->gen_params)
- return TRUE;
- return FALSE;
+ return mono_method_get_object (mono_object_domain (type), method, klass);
}
+
static MonoObject *
ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoArray *params)
{
if (!mono_object_isinst (this, m->klass))
mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
m = mono_object_get_virtual_method (this, m);
- } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor"))
+ } else if (!(m->flags & METHOD_ATTRIBUTE_STATIC) && strcmp (m->name, ".ctor") && !m->wrapper_type)
mono_raise_exception (mono_exception_from_name (mono_defaults.corlib, "System.Reflection", "TargetException"));
pcount = params? mono_array_length (params): 0;
return NULL;
}
- return mono_image_get_resource (assembly->assembly->image, cols [MONO_MANIFEST_OFFSET], size);
+ return (void*)mono_image_get_resource (assembly->assembly->image, cols [MONO_MANIFEST_OFFSET], size);
}
static gboolean
static MonoBoolean
ves_icall_Type_IsArrayImpl (MonoReflectionType *t)
{
- MonoType *type = t->type;
- MonoBoolean res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
-
+ MonoType *type;
+ MonoBoolean res;
+
+ MONO_ARCH_SAVE_REGS;
+
+ type = t->type;
+ res = !type->byref && (type->type == MONO_TYPE_ARRAY || type->type == MONO_TYPE_SZARRAY);
+
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)
+#define EPOCH_ADJUST ((guint64)62135596800L)
+/*
+ * Magic number to convert FILETIME base Jan 1, 1601 to DateTime - base Jan, 1, 0001
+ */
+#define FILETIME_ADJUST ((guint64)504911232000000000LL)
+
+/*
+ * This returns Now in UTC
+ */
static gint64
ves_icall_System_DateTime_GetNow (void)
{
GetLocalTime (&st);
SystemTimeToFileTime (&st, &ft);
- return (gint64)504911232000000000L + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
+ return (gint64) FILETIME_ADJUST + ((((gint64)ft.dwHighDateTime)<<32) | ft.dwLowDateTime);
#else
/* FIXME: put this in io-layer and call it GetLocalTime */
struct timeval tv;
#endif
}
+#ifdef PLATFORM_WIN32
+/* convert a SYSTEMTIME which is of the form "last thursday in october" to a real date */
+static void
+convert_to_absolute_date(SYSTEMTIME *date)
+{
+#define IS_LEAP(y) ((y % 4) == 0 && ((y % 100) != 0 || (y % 400) == 0))
+ static int days_in_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+ static int leap_days_in_month[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+ /* from the calendar FAQ */
+ int a = (14 - date->wMonth) / 12;
+ int y = date->wYear - a;
+ int m = date->wMonth + 12 * a - 2;
+ int d = (1 + y + y/4 - y/100 + y/400 + (31*m)/12) % 7;
+
+ /* d is now the day of the week for the first of the month (0 == Sunday) */
+
+ int day_of_week = date->wDayOfWeek;
+
+ /* set day_in_month to the first day in the month which falls on day_of_week */
+ int day_in_month = 1 + (day_of_week - d);
+ if (day_in_month <= 0)
+ day_in_month += 7;
+
+ /* wDay is 1 for first weekday in month, 2 for 2nd ... 5 means last - so work that out allowing for days in the month */
+ date->wDay = day_in_month + (date->wDay - 1) * 7;
+ if (date->wDay > (IS_LEAP(date->wYear) ? leap_days_in_month[date->wMonth - 1] : days_in_month[date->wMonth - 1]))
+ date->wDay -= 7;
+}
+#endif
+
+#ifndef PLATFORM_WIN32
+/*
+ * Return's the offset from GMT of a local time.
+ *
+ * tm is a local time
+ * t is the same local time as seconds.
+ */
+static int
+gmt_offset(struct tm *tm, time_t t)
+{
+#if defined (HAVE_TM_GMTOFF)
+ return tm->tm_gmtoff;
+#else
+ struct tm g;
+ time_t t2;
+ g = *gmtime(&t);
+ g.tm_isdst = tm->tm_isdst;
+ t2 = mktime(&g);
+ return (int)difftime(t, t2);
+#endif
+}
+#endif
/*
* This is heavily based on zdump.c from glibc 2.2.
*
start.tm_year = year-1900;
t = mktime (&start);
-#if defined (HAVE_TIMEZONE)
-#define gmt_offset(x) (-1 * (((timezone / 60 / 60) - daylight) * 100))
-#elif defined (HAVE_TM_GMTOFF)
-#define gmt_offset(x) x.tm_gmtoff
-#else
-#error Neither HAVE_TIMEZONE nor HAVE_TM_GMTOFF defined. Rerun autoheader, autoconf, etc.
-#endif
-
- gmtoff = gmt_offset (start);
+ gmtoff = gmt_offset (&start, t);
/* For each day of the year, calculate the tm_gmtoff. */
for (day = 0; day < 365; day++) {
tt = *localtime (&t);
/* Daylight saving starts or ends here. */
- if (gmt_offset (tt) != gmtoff) {
+ if (gmt_offset (&tt, t) != gmtoff) {
struct tm tt1;
time_t t1;
do {
t1 -= 3600;
tt1 = *localtime (&t1);
- } while (gmt_offset (tt1) != gmtoff);
+ } while (gmt_offset (&tt1, t1) != gmtoff);
/* Try to find the exact minute when daylight saving starts/ends. */
do {
t1 += 60;
tt1 = *localtime (&t1);
- } while (gmt_offset (tt1) == gmtoff);
+ } while (gmt_offset (&tt1, t1) == gmtoff);
strftime (tzone, sizeof (tzone), "%Z", &tt);
/* This is only set once when we enter daylight saving. */
mono_array_set ((*data), gint64, 2, (gint64)gmtoff * 10000000L);
- mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (tt) - gmtoff) * 10000000L);
+ mono_array_set ((*data), gint64, 3, (gint64)(gmt_offset (&tt, t) - gmtoff) * 10000000L);
- gmtoff = gmt_offset (tt);
+ gmtoff = gmt_offset (&tt, t);
}
-
- gmtoff = gmt_offset (tt);
}
if (!is_daylight) {
TIME_ZONE_INFORMATION tz_info;
FILETIME ft;
int i;
+ int err, tz_id;
- GetTimeZoneInformation (&tz_info);
+ tz_id = GetTimeZoneInformation (&tz_info);
+ if (tz_id == TIME_ZONE_ID_INVALID)
+ return 0;
MONO_CHECK_ARG_NULL (data);
MONO_CHECK_ARG_NULL (names);
break;
mono_array_set ((*names), gpointer, 0, mono_string_new_utf16 (domain, tz_info.StandardName, i));
- SystemTimeToFileTime (&tz_info.StandardDate, &ft);
- mono_array_set ((*data), gint64, 1, ((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime);
- SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
- mono_array_set ((*data), gint64, 0, ((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime);
- mono_array_set ((*data), gint64, 3, tz_info.Bias + tz_info.StandardBias);
- mono_array_set ((*data), gint64, 2, tz_info.Bias + tz_info.DaylightBias);
+ if ((year <= 1601) || (year > 30827)) {
+ /*
+ * According to MSDN, the MS time functions can't handle dates outside
+ * this interval.
+ */
+ return 1;
+ }
+
+ /* even if the timezone has no daylight savings it may have Bias (e.g. GMT+13 it seems) */
+ if (tz_id != TIME_ZONE_ID_UNKNOWN) {
+ tz_info.StandardDate.wYear = year;
+ convert_to_absolute_date(&tz_info.StandardDate);
+ err = SystemTimeToFileTime (&tz_info.StandardDate, &ft);
+ g_assert(err);
+ mono_array_set ((*data), gint64, 1, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
+ tz_info.DaylightDate.wYear = year;
+ convert_to_absolute_date(&tz_info.DaylightDate);
+ err = SystemTimeToFileTime (&tz_info.DaylightDate, &ft);
+ g_assert(err);
+ mono_array_set ((*data), gint64, 0, FILETIME_ADJUST + (((guint64)ft.dwHighDateTime<<32) | ft.dwLowDateTime));
+ }
+ mono_array_set ((*data), gint64, 2, (tz_info.Bias + tz_info.StandardBias) * -600000000LL);
+ mono_array_set ((*data), gint64, 3, (tz_info.DaylightBias - tz_info.StandardBias) * -600000000LL);
return 1;
#endif
static MonoString *
ves_icall_System_Configuration_DefaultConfig_get_machine_config_path (void)
{
- static MonoString *mcpath;
+ MonoString *mcpath;
gchar *path;
MONO_ARCH_SAVE_REGS;
- if (mcpath != NULL)
- return mcpath;
-
path = g_build_path (G_DIR_SEPARATOR_S, mono_cfg_dir, "mono", "machine.config", NULL);
#if defined (PLATFORM_WIN32)
return mcpath;
}
+static MonoString *
+ves_icall_System_Web_Util_ICalls_get_machine_install_dir (void)
+{
+ MonoString *ipath;
+ gchar *path;
+
+ MONO_ARCH_SAVE_REGS;
+
+ path = g_path_get_dirname (mono_cfg_dir);
+
+#if defined (PLATFORM_WIN32)
+ /* Avoid mixing '/' and '\\' */
+ {
+ gint i;
+ for (i = strlen (path) - 1; i >= 0; i--)
+ if (path [i] == '/')
+ path [i] = '\\';
+ }
+#endif
+ ipath = mono_string_new (mono_domain_get (), path);
+ g_free (path);
+
+ return ipath;
+}
+
static void
ves_icall_System_Diagnostics_DefaultTraceListener_WriteWindowsDebugString (MonoString *message)
{
"System.Reflection.Emit.TypeBuilder::setup_internal_class", mono_reflection_setup_internal_class,
"System.Reflection.Emit.TypeBuilder::create_internal_class", mono_reflection_create_internal_class,
"System.Reflection.Emit.TypeBuilder::create_runtime_class", mono_reflection_create_runtime_class,
+ "System.Reflection.Emit.TypeBuilder::setup_generic_class", mono_reflection_setup_generic_class,
+
+ /*
+ * TypeBuilder generics icalls.
+ */
+ "System.Reflection.Emit.TypeBuilder::get_IsGenericParameter", ves_icall_TypeBuilder_get_IsGenericParameter,
+ "System.Reflection.Emit.TypeBuilder::define_generic_parameter", ves_icall_TypeBuilder_define_generic_parameter,
/*
- * MethodBuilder
+ * MethodBuilder generic icalls.
*/
+ "System.Reflection.Emit.MethodBuilder::define_generic_parameter", ves_icall_MethodBuilder_define_generic_parameter,
/*
* System.Type
"System.Type::IsArrayImpl", ves_icall_Type_IsArrayImpl,
/* Type generics icalls */
- "System.Type::GetGenericParameters", ves_icall_Type_GetGenericParameters,
+ "System.Type::GetGenericArguments", ves_icall_Type_GetGenericArguments,
"System.Type::GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition,
- "System.Type::GetGenericTypeDefinition", ves_icall_Type_GetGenericTypeDefinition,
+ "System.Type::get_IsGenericTypeDefinition", ves_icall_Type_get_IsGenericTypeDefinition,
+ "System.Type::GetGenericTypeDefinition_impl", ves_icall_Type_GetGenericTypeDefinition_impl,
"System.Type::BindGenericParameters", ves_icall_Type_BindGenericParameters,
- "System.Type::IsGenericTypeDefinition", ves_icall_Type_IsGenericTypeDefinition,
+ "System.Type::get_IsGenericInstance", ves_icall_Type_get_IsGenericInstance,
- "System.MonoType::get_HasGenericParameters", ves_icall_MonoType_get_HasGenericParameteres,
- "System.MonoType::get_HasUnboundGenericParameters", ves_icall_MonoType_get_HasUnboundGenericParameters,
- "System.MonoType::get_IsUnboundGenericParameter", ves_icall_MonoType_get_IsUnboundGenericParameter,
+ "System.MonoType::get_HasGenericArguments", ves_icall_MonoType_get_HasGenericArguments,
+ "System.MonoType::get_IsGenericParameter", ves_icall_MonoType_get_IsGenericParameter,
+ "System.MonoType::get_DeclaringMethod", ves_icall_MonoType_get_DeclaringMethod,
+
/*
* System.Reflection.FieldInfo
*/
"System.Activator::CreateInstanceInternal",
ves_icall_System_Activator_CreateInstanceInternal,
+
+ /*
+ * System.Web
+ */
+ "System.Web.Util.ICalls::GetMachineConfigPath",
+ ves_icall_System_Configuration_DefaultConfig_get_machine_config_path,
+
+ "System.Web.Util.ICalls::GetMachineInstallDirectory",
+ ves_icall_System_Web_Util_ICalls_get_machine_install_dir,
+
+ /*
+ * System.Globalization
+ */
+ "System.Globalization.CultureInfo::construct_internal_locale(string)", ves_icall_System_Globalization_CultureInfo_construct_internal_locale,
+ "System.Globalization.CultureInfo::construct_compareinfo(object,string)", ves_icall_System_Globalization_CultureInfo_construct_compareinfo,
+ "System.Globalization.CompareInfo::internal_compare(string,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_internal_compare,
+ "System.Globalization.CompareInfo::free_internal_collator()", ves_icall_System_Globalization_CompareInfo_free_internal_collator,
+ "System.Globalization.CompareInfo::assign_sortkey(object,string,System.Globalization.CompareOptions)", ves_icall_System_Globalization_CompareInfo_assign_sortkey,
+
/*
* add other internal calls here
*/