Esempio n. 1
1
static void OutputExceptionDetails(MonoObject* exc)
{
	MonoClass* eclass = mono_object_get_class(exc);

	if (eclass)
	{
		MonoObject* toStringExc = nullptr;
		MonoString* msg = mono_object_to_string(exc, &toStringExc);

		MonoProperty* prop = mono_class_get_property_from_name(eclass, "StackTrace");
		MonoMethod* getter = mono_property_get_get_method(prop);
		MonoString* msg2 = (MonoString*)mono_runtime_invoke(getter, exc, NULL, NULL);

		if (toStringExc)
		{
			MonoProperty* prop = mono_class_get_property_from_name(eclass, "Message");
			MonoMethod* getter = mono_property_get_get_method(prop);
			msg = (MonoString*)mono_runtime_invoke(getter, exc, NULL, NULL);
		}

		GlobalError("Unhandled exception in Mono script environment: %s %s", mono_string_to_utf8(msg), mono_string_to_utf8(msg2));
	}
}
void ConHostI_InvokeHostFunction(MonoString* functionNameStr, MonoString* argumentStr)
{
	char* functionName = mono_string_to_utf8(functionNameStr);
	char* argument = mono_string_to_utf8(argumentStr);

	ConHost::OnInvokeNative(functionName, argument);
}
Esempio n. 3
0
MonoBoolean
ves_icall_System_ConsoleDriver_TtySetup (MonoString *keypad, MonoString *teardown, MonoArray **control_chars, int **size)
{
	int dims;

	MONO_ARCH_SAVE_REGS;

	dims = terminal_get_dimensions ();
	if (dims == -1){
		int cols = 0, rows = 0;
				      
		char *str = getenv ("COLUMNS");
		if (str != NULL)
			cols = atoi (str);
		str = getenv ("LINES");
		if (str != NULL)
			rows = atoi (str);

		if (cols != 0 && rows != 0)
			cols_and_lines = (cols << 16) | rows;
		else
			cols_and_lines = -1;
	} else {
		cols_and_lines = dims;
	}
	
	*size = &cols_and_lines;

	/* 17 is the number of entries set in set_control_chars() above.
	 * NCCS is the total size, but, by now, we only care about those 17 values*/
	mono_gc_wbarrier_generic_store (control_chars, (MonoObject*) mono_array_new (mono_domain_get (), mono_defaults.byte_class, 17));
	if (tcgetattr (STDIN_FILENO, &initial_attr) == -1)
		return FALSE;

	mono_attr = initial_attr;
	mono_attr.c_lflag &= ~(ICANON);
	mono_attr.c_iflag &= ~(IXON|IXOFF);
	mono_attr.c_cc [VMIN] = 1;
	mono_attr.c_cc [VTIME] = 0;
	if (tcsetattr (STDIN_FILENO, TCSANOW, &mono_attr) == -1)
		return FALSE;

	set_control_chars (*control_chars, mono_attr.c_cc);
	/* If initialized from another appdomain... */
	if (setup_finished)
		return TRUE;

	keypad_xmit_str = keypad != NULL ? mono_string_to_utf8 (keypad) : NULL;
	
	console_set_signal_handlers ();
	setup_finished = TRUE;
	if (!atexit_called) {
		if (teardown != NULL)
			teardown_str = mono_string_to_utf8 (teardown);

		atexit (tty_teardown);
	}

	return TRUE;
}
Esempio n. 4
0
void purple_debug_glue(int type, MonoString *cat, MonoString *str)
{
	char *ccat;
	char *cstr;

	ccat = mono_string_to_utf8(cat);
	cstr = mono_string_to_utf8(str);

	purple_debug(type, ccat, "%s", cstr);

	g_free(ccat);
	g_free(cstr);
}
Esempio n. 5
0
static int sr_mono_pv_sets (MonoString *pv, MonoString *sv)
{
	str pvn = {0};
	pv_spec_t *pvs;
    pv_value_t val;
	int pl;
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	pvn.s = mono_string_to_utf8(pv);

	if(pvn.s==NULL || env_M->msg==NULL)
		goto error;

	memset(&val, 0, sizeof(pv_value_t));
	val.rs.s = mono_string_to_utf8(sv);
	if(val.rs.s == NULL)
		goto error;

	val.rs.len = strlen(val.rs.s);
	val.flags |= PV_VAL_STR;
	
	pvn.len = strlen(pvn.s);
	LM_DBG("pv set: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		goto error;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		goto error;
	}
	if(pv_set_spec_value(env_M->msg, pvs, 0, &val)<0)
	{
		LM_ERR("unable to set pv [%s]\n", pvn.s);
		return -1;
	}

	mono_free(pvn.s);
	return 0;
error:
	if(pvn.s!=NULL)
		mono_free(pvn.s);
	return -1;
}
Esempio n. 6
0
static int sr_mono_hdr_append_to_reply (MonoString *hv)
{
	str txt = {0};
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	txt.s = mono_string_to_utf8(hv);

	if(txt.s==NULL || env_M->msg==NULL)
		goto error;

	txt.len = strlen(txt.s);

	LM_DBG("append to reply: %s\n", txt.s);

	if(add_lump_rpl(env_M->msg, txt.s, txt.len, LUMP_RPL_HDR)==0)
	{
		LM_ERR("unable to add reply lump\n");
		goto error;
	}

	mono_free(txt.s);
	return 0;

error:
	if(txt.s!=NULL)
		mono_free(txt.s);
	return -1;
}
Esempio n. 7
0
void *
mono_mmap_open_handle (void *input_fd, MonoString *mapName, gint64 *capacity, int access, int options, int *error)
{
    MmapHandle *handle;
    if (!mapName) {
        handle = (MmapHandle *)open_file_map (NULL, GPOINTER_TO_INT (input_fd), FILE_MODE_OPEN, capacity, access, options, error);
    } else {
        char *c_mapName = mono_string_to_utf8 (mapName);

        named_regions_lock ();
        handle = (MmapHandle*)g_hash_table_lookup (named_regions, c_mapName);
        if (handle) {
            *error = FILE_ALREADY_EXISTS;
            handle = NULL;
        } else {
            //XXX we're exploiting wapi HANDLE == FD equivalence. THIS IS FRAGILE, create a _wapi_handle_to_fd call
            handle = (MmapHandle *)open_file_map (NULL, GPOINTER_TO_INT (input_fd), FILE_MODE_OPEN, capacity, access, options, error);
            handle->name = g_strdup (c_mapName);
            g_hash_table_insert (named_regions, handle->name, handle);
        }
        named_regions_unlock ();

        g_free (c_mapName);
    }
    return handle;
}
Esempio n. 8
0
int purple_signal_connect_glue(MonoObject* h, MonoObject *plugin, MonoString *signal, MonoObject *func)
{
	char *sig;
	void **instance = NULL;
	SignalData *sig_data;
	PurpleMonoPlugin *mplug;
	MonoClass *klass;
		
	sig = mono_string_to_utf8(signal);
	purple_debug(PURPLE_DEBUG_INFO, "mono", "connecting signal: %s\n", sig);
	
	instance = (void*)mono_object_unbox(h);
	
	sig_data = g_new0(SignalData, 1);
	
	sig_data->func = func;
	sig_data->signal = sig;
	
	purple_signal_get_values(*instance, sig, &sig_data->ret_value, &sig_data->num_vals, &sig_data->values);
	
	klass = mono_object_get_class(plugin);
	
	mplug = ml_find_plugin_by_class(klass);
	
	mplug->signal_data = g_list_append(mplug->signal_data, (gpointer)sig_data);

	return purple_signal_connect(*instance, sig, (gpointer)klass, get_callback(sig_data), (gpointer)sig_data);
}
Esempio n. 9
0
CFArrayRef CMCreateArrayWithMonoStringArray(CFAllocatorRef allocator, MonoArray *monoArray) {
    CFArrayRef array = NULL;
    if (monoArray) {
        uintptr_t n = mono_array_length(monoArray);
        CFTypeRef *values = CFAllocatorAllocate(allocator, n * sizeof(CFTypeRef), 0);
        if (values) {

            for (uintptr_t i = 0; i < n; i++) {
                values[i] = kCFNull;
                MonoString *monoString = mono_array_get(monoArray, MonoString*, i);
                if (monoString) {
                    char *utf8MonoString = mono_string_to_utf8(monoString);
                    if (utf8MonoString) {
                        CFStringRef string = CFStringCreateWithCString(allocator, utf8MonoString, kCFStringEncodingUTF8);
                        if (string) {
                            values[i] = string;
                        }
                        mono_free(utf8MonoString);
                    }
                }
            }

            array = CFArrayCreate(allocator, values, n, &kCFTypeArrayCallBacks);

            for (uintptr_t i = 0; i < n; i++) {
                if (values[i] != kCFNull) {
                    CFRelease(values[i]);
                }
            }

            CFAllocatorDeallocate(allocator, values);
        }
    }
    return array;
}
Esempio n. 10
0
static inline void print_report (const gchar *format, ...)
{
	MonoError error;
	MonoClass *klass;
	MonoProperty *prop;
	MonoString *str;
	char *stack_trace;
	va_list ap;

	fprintf (stdout, "-=-=-=-=-=-=- MONO_IOMAP REPORT -=-=-=-=-=-=-\n");
	va_start (ap, format);
	vfprintf (stdout, format, ap);
	fprintf (stdout, "\n");
	va_end (ap);
	klass = mono_class_load_from_name (mono_get_corlib (), "System", "Environment");
	mono_class_init (klass);
	prop = mono_class_get_property_from_name (klass, "StackTrace");
	str = (MonoString*)mono_property_get_value_checked (prop, NULL, NULL, &error);
	mono_error_assert_ok (&error);
	stack_trace = mono_string_to_utf8 (str);

	fprintf (stdout, "-= Stack Trace =-\n%s\n\n", stack_trace);
	g_free (stack_trace);
	fflush (stdout);
}
Esempio n. 11
0
void *
mono_mmap_open_file (MonoString *path, int mode, MonoString *mapName, gint64 *capacity, int access, int options, int *error)
{
	g_assert (path || mapName);

	if (!mapName)
		return open_file_map (path, -1, mode, capacity, access, options, error);

	if (path) {
		MmapHandle *handle;
		char *c_mapName = mono_string_to_utf8 (mapName);

		named_regions_lock ();
		handle = (MmapHandle*)g_hash_table_lookup (named_regions, c_mapName);
		if (handle) {
			*error = FILE_ALREADY_EXISTS;
			handle = NULL;
		} else {
			handle = open_file_map (path, -1, mode, capacity, access, options, error);
			if (handle) {
				handle->name = g_strdup (c_mapName);
				g_hash_table_insert (named_regions, handle->name, handle);
			}
		}
		named_regions_unlock ();

		g_free (c_mapName);
		return handle;
	}

	return open_memory_map (mapName, mode, capacity, access, options, error);
}
Esempio n. 12
0
mono_string_utf8::mono_string_utf8( MonoString* str )
:m_str(NULL), m_nLength(0)
{
	if(str!=0)
	{
		m_str = mono_string_to_utf8 (str);
	}
}
Esempio n. 13
0
void JniManager::toProcessRequest(jobject obj, MonoObject* processRequest)
{
    JNIEnv* env = getEnv();

    MonoDomain* monoDomain = getMonoDomain();

    string c_assemblyName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyName, "()Ljava/lang/String;"));
    string c_assemblyPath = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getAssemblyPath, "()Ljava/lang/String;"));
    string c_methodName = typeConverter->convertToC<string>(env, env->CallObjectMethod(obj, getMethodName, "()Ljava/lang/String;"));

    MonoString* assemblyName = mono_string_new(monoDomain, c_assemblyName.c_str());
    MonoString* assemblyPath = mono_string_new(monoDomain, c_assemblyPath.c_str());
    MonoString* methodName = mono_string_new(monoDomain, c_methodName.c_str());
    bool fullTrust = env->CallBooleanMethod(obj, getFullTrust);
    bool isSingleton = env->CallBooleanMethod(obj, getIsSingleton);
    bool log = env->CallBooleanMethod(obj, getLog);
    bool notifyEvents = env->CallBooleanMethod(obj, getNotifyEvents);

    MonoObject* exception = NULL;

    void* args[1];
    args[0] = assemblyName;
    mono_runtime_invoke(setAssemblyNameField, processRequest, args, &exception);

    args[0] = assemblyPath;
    mono_runtime_invoke(setAssemblyPathField, processRequest, args, &exception);

    args[0] = methodName;
    mono_runtime_invoke(setMethodNameField, processRequest, args, &exception);

    args[0] = &fullTrust;
    mono_runtime_invoke(setFullTrustField, processRequest, args, &exception);

    args[0] = &log;
    mono_runtime_invoke(setLogField, processRequest, args, &exception);

    args[0] = &isSingleton;
    mono_runtime_invoke(setIsSingletonField, processRequest, args, &exception);

    args[0] = &notifyEvents;
    mono_runtime_invoke(setNotifyEventsField, processRequest, args, &exception);

    if (exception)
    {
        const char* message = mono_string_to_utf8(mono_object_to_string(exception, NULL));
        throwException(message);
    }

    jobject javaMethodArguments = env->CallObjectMethod(obj, getMethodArguments);

    setProperties(env, javaMethodArguments, addMethodArgumentsProperty, processRequest);
    //request->MethodArguments = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getMethodArguments));
    //request->InboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInboundProperties));
    //request->InvocationProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getInvocationProperties));
    //request->OutboundProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getOutboundProperties));
    //request->SessionProperties = typeConverter->convertToC<Dictionary<String^, Object^>^>(env, env->CallObjectMethod(obj, getSessionProperties));
}
Esempio n. 14
0
// Get string from a Mono exception 
char* PyNet_ExceptionToString(MonoObject *e) {
    MonoMethodDesc* mdesc = mono_method_desc_new(":ToString()", FALSE);
    MonoMethod* mmethod = mono_method_desc_search_in_class(mdesc, mono_get_object_class());
    mono_method_desc_free(mdesc);

    mmethod = mono_object_get_virtual_method(e, mmethod);
    MonoString* monoString = (MonoString*) mono_runtime_invoke(mmethod, e, NULL, NULL);
    mono_runtime_invoke(mmethod, e, NULL, NULL);
    return mono_string_to_utf8(monoString);
}
Esempio n. 15
0
void JniManager::setProperties(JNIEnv* env, jobject map, MonoMethod* method, MonoObject* instance)
{
    assert(env);

    MonoDomain* monoDomain = getMonoDomain();

    if (map == NULL)
    {
        return;
    }

    int mapSize = env->CallIntMethod(map, typeConverter->size);

    jobject keys = env->CallObjectMethod(map, typeConverter->keySet);

    jobjectArray arrayOfKeys = (jobjectArray)env->CallObjectMethod(keys, typeConverter->toArray);

    for (int i = 0; i < mapSize; i++)
    {
        jstring javaKeyName = (jstring)env->GetObjectArrayElement(arrayOfKeys, i);
        string keyName = typeConverter->convertToC<string>(env, javaKeyName);
        jobject mapValue = env->CallObjectMethod(map, typeConverter->getMapValue, javaKeyName);

        //if (env->IsInstanceOf(mapValue, typeConverter->mapClazz))
        //{

        //}

        MonoObject* exc = NULL;
        void* args[2];
        args[0] = mono_string_new(monoDomain, keyName.c_str());
        args[1] = toMonoObject(env, mapValue);

        mono_runtime_invoke(method, instance, args, &exc);

        if (exc)
        {
            const char* message = mono_string_to_utf8(mono_object_to_string(exc, NULL));
            throwException(message);
            return;
        }


        env->DeleteLocalRef(javaKeyName);
        env->DeleteLocalRef(mapValue);
    }

    env->DeleteLocalRef(keys);
    env->DeleteLocalRef(arrayOfKeys);
    env->DeleteLocalRef(map);
}
Esempio n. 16
0
gchar* ml_get_prop_string(MonoObject *obj, char *field)
{
	MonoClass *klass;
	MonoProperty *prop;
	MonoString *str;

	klass = mono_object_get_class(obj);

	prop = mono_class_get_property_from_name(klass, field);

	str = (MonoString*)mono_property_get_value(prop, obj, NULL, NULL);

	return mono_string_to_utf8(str);
}
Esempio n. 17
0
static int sr_mono_hdr_append (MonoString *hv)
{
	struct lump* anchor;
	struct hdr_field *hf;
	char *hdr;
	str txt = {0};
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	txt.s = mono_string_to_utf8(hv);

	if(txt.s==NULL || env_M->msg==NULL)
		goto error;

	txt.len = strlen(txt.s);

	LM_DBG("append hf: %s\n", txt.s);
	if (parse_headers(env_M->msg, HDR_EOH_F, 0) == -1)
	{
		LM_ERR("error while parsing message\n");
		goto error;
	}

	hf = env_M->msg->last_header;
	hdr = (char*)pkg_malloc(txt.len+1);
	if(hdr==NULL)
	{
		PKG_MEM_ERROR;
		goto error;
	}
	memcpy(hdr, txt.s, txt.len);
	hdr[txt.len] = '\0';
	anchor = anchor_lump(env_M->msg,
				hf->name.s + hf->len - env_M->msg->buf, 0, 0);
	if(insert_new_lump_before(anchor, hdr, txt.len, 0) == 0)
	{
		LM_ERR("can't insert lump\n");
		pkg_free(hdr);
		goto error;
	}
	mono_free(txt.s);
	return 0;

error:
	if(txt.s!=NULL)
		mono_free(txt.s);
	return -1;
}
Esempio n. 18
0
int
ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 mask)
{
	char *str, *path;
	int retval;

	MONO_ARCH_SAVE_REGS;

	if (name == NULL)
		return -1;

	str = mono_string_to_utf8 (name);
	path = mono_portability_find_file (str, TRUE);
	if (!path)
		path = str;

	retval = syscall (__NR_inotify_add_watch, fd, path, mask);
	if (retval < 0) {
		switch (errno) {
		case EACCES:
			errno = ERROR_ACCESS_DENIED;
			break;
		case EBADF:
			errno = ERROR_INVALID_HANDLE;
			break;
		case EFAULT:
			errno = ERROR_INVALID_ACCESS;
			break;
		case EINVAL:
			errno = ERROR_INVALID_DATA;
			break;
		case ENOMEM:
			errno = ERROR_NOT_ENOUGH_MEMORY;
			break;
		case ENOSPC:
			errno = ERROR_TOO_MANY_OPEN_FILES;
			break;
		default:
			errno = ERROR_GEN_FAILURE;
			break;
		}
		mono_marshal_set_last_error ();
	}
	if (path != str)
		g_free (path);
	g_free (str);
	return retval;
}
Esempio n. 19
0
static int sr_mono_pv_geti (MonoString *pv)
{
	str pvn = {0};
	pv_spec_t *pvs;
    pv_value_t val;
	int pl;
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	pvn.s = mono_string_to_utf8(pv);

	if(pvn.s==NULL || env_M->msg==NULL)
		goto error;

	pvn.len = strlen(pvn.s);
	LM_DBG("pv get: %s\n", pvn.s);
	pl = pv_locate_name(&pvn);
	if(pl != pvn.len)
	{
		LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len);
		goto error;
	}
	pvs = pv_cache_get(&pvn);
	if(pvs==NULL)
	{
		LM_ERR("cannot get pv spec for [%s]\n", pvn.s);
		goto error;
	}
	memset(&val, 0, sizeof(pv_value_t));
	if(pv_get_spec_value(env_M->msg, pvs, &val) != 0)
	{
		LM_ERR("unable to get pv value for [%s]\n", pvn.s);
		goto error;
	}
	if((val.flags&PV_VAL_NULL) || !(val.flags&PV_TYPE_INT))
	{
		mono_free(pvn.s);
		return 0;
	}
	mono_free(pvn.s);
	return val.ri;

error:
	if(pvn.s!=NULL)
		mono_free(pvn.s);
	return 0;
}
Esempio n. 20
0
static int sr_mono_hdr_remove (MonoString *hv)
{
	struct lump* anchor;
	struct hdr_field *hf;
	str hname;
	str txt = {0};
	sr_mono_env_t *env_M;

	env_M = sr_mono_env_get();
	txt.s = mono_string_to_utf8(hv);

	if(txt.s==NULL || env_M->msg==NULL)
		goto error;

	txt.len = strlen(txt.s);

	LM_DBG("remove hf: %s\n", txt.s);
	if (parse_headers(env_M->msg, HDR_EOH_F, 0) == -1) {
		LM_ERR("error while parsing message\n");
		goto error;
	}

	hname.s = txt.s;
	hname.len = txt.len;
	for (hf=env_M->msg->headers; hf; hf=hf->next)
	{
		if (cmp_hdrname_str(&hf->name, &hname)==0)
		{
			anchor=del_lump(env_M->msg,
					hf->name.s - env_M->msg->buf, hf->len, 0);
			if (anchor==0)
			{
				LM_ERR("cannot remove hdr %s\n", txt.s);
				goto error;
			}
		}
	}
	mono_free(txt.s);
	return 0;

error:
	if(txt.s!=NULL)
		mono_free(txt.s);
	return -1;
}
Esempio n. 21
0
MonoBoolean
ves_icall_System_Globalization_CalendarData_fill_calendar_data (MonoCalendarData *this_obj, MonoString *name, gint32 calendar_index)
{
	MonoDomain *domain;
	const DateTimeFormatEntry *dfe;
	const CultureInfoNameEntry *ne;
	const CultureInfoEntry *ci;
	char *n;

	n = mono_string_to_utf8 (name);
	ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
			sizeof (CultureInfoNameEntry), culture_name_locator);
	g_free (n);
	if (ne == NULL) {
		return FALSE;
	}

	ci = &culture_entries [ne->culture_entry_index];
	dfe = &datetime_format_entries [ci->datetime_format_index];

	domain = mono_domain_get ();

	MONO_OBJECT_SETREF (this_obj, NativeName, mono_string_new (domain, idx2string (ci->nativename)));
	MONO_OBJECT_SETREF (this_obj, ShortDatePatterns, create_names_array_idx_dynamic (dfe->short_date_patterns,
			NUM_SHORT_DATE_PATTERNS));
	MONO_OBJECT_SETREF (this_obj, YearMonthPatterns, create_names_array_idx_dynamic (dfe->year_month_patterns,
			NUM_YEAR_MONTH_PATTERNS));

	MONO_OBJECT_SETREF (this_obj, LongDatePatterns, create_names_array_idx_dynamic (dfe->long_date_patterns,
			NUM_LONG_DATE_PATTERNS));
	MONO_OBJECT_SETREF (this_obj, MonthDayPattern, mono_string_new (domain, idx2string (dfe->month_day_pattern)));

	MONO_OBJECT_SETREF (this_obj, DayNames, create_names_array_idx (dfe->day_names, NUM_DAYS));
	MONO_OBJECT_SETREF (this_obj, AbbreviatedDayNames, create_names_array_idx (dfe->abbreviated_day_names, 
			NUM_DAYS));
	MONO_OBJECT_SETREF (this_obj, SuperShortDayNames, create_names_array_idx (dfe->shortest_day_names, NUM_DAYS));
	MONO_OBJECT_SETREF (this_obj, MonthNames, create_names_array_idx (dfe->month_names, NUM_MONTHS));
	MONO_OBJECT_SETREF (this_obj, AbbreviatedMonthNames, create_names_array_idx (dfe->abbreviated_month_names,
			NUM_MONTHS));
	MONO_OBJECT_SETREF (this_obj, GenitiveMonthNames, create_names_array_idx (dfe->month_genitive_names, NUM_MONTHS));
	MONO_OBJECT_SETREF (this_obj, GenitiveAbbreviatedMonthNames, create_names_array_idx (dfe->abbreviated_month_genitive_names, NUM_MONTHS));

	return TRUE;
}
Esempio n. 22
0
static gboolean saved_strings_find_func (gpointer key, gpointer value, gpointer user_data)
{
	SavedStringFindInfo *info = (SavedStringFindInfo*)user_data;
	SavedString *saved = (SavedString*)value;
	gchar *utf_str;
	guint32 hash;

	if (!info || !saved || mono_string_length (saved->string) != info->len)
		return FALSE;

	utf_str = mono_string_to_utf8 (saved->string);
	hash = do_calc_string_hash (0, utf_str);
	g_free (utf_str);

	if (hash != info->hash)
		return FALSE;

	return TRUE;
}
Esempio n. 23
0
static MonoReflectionAssembly *
ves_icall_VInvoke_LoadAssemblyFromVirtuoso (MonoAppDomain *ad, MonoString *message)
{
  char *asm_name;
  caddr_t name = NULL;
  caddr_t code = NULL;
  long len;

  MonoAssembly *ass;
  MonoDomain *domain = virtuoso_domain;
  MonoImage *image = NULL;
#ifdef OLD_KIT_1_1_5
  MonoImageOpenStatus *status;
#else
  MonoImageOpenStatus status;
#endif

  asm_name = mono_string_to_utf8 (message);
  name = box_copy (asm_name);

  code = mono_get_assembly_by_name (&name);

  if (!code)
    return NULL;

  len = box_length (code);

  image = mono_image_open_from_data (code, len, 0, NULL);

  if (!image)
    return NULL;

#ifdef OLD_KIT_1_1_5
  ass = mono_assembly_open ("", NULL, image);
#else
  ass = mono_assembly_load_from (image, "", &status);
#endif

  if (!ass && !status)
    return NULL;

  return mono_assembly_get_object (domain, ass);
}
Esempio n. 24
0
MonoBoolean
ves_icall_System_Globalization_CultureInfo_construct_internal_locale_from_name (MonoCultureInfo *this_obj,
		MonoString *name)
{
	const CultureInfoNameEntry *ne;
	char *n;
	
	n = mono_string_to_utf8 (name);
	ne = (const CultureInfoNameEntry *)mono_binary_search (n, culture_name_entries, NUM_CULTURE_ENTRIES,
			sizeof (CultureInfoNameEntry), culture_name_locator);

	if (ne == NULL) {
		/*g_print ("ne (%s) is null\n", n);*/
		g_free (n);
		return FALSE;
	}
	g_free (n);

	return construct_culture (this_obj, &culture_entries [ne->culture_entry_index]);
}
Esempio n. 25
0
MonoBoolean
ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name (MonoRegionInfo *this_obj,
		MonoString *name)
{
	const RegionInfoNameEntry *ne;
	char *n;
	
	n = mono_string_to_utf8 (name);
	ne = (const RegionInfoNameEntry *)mono_binary_search (n, region_name_entries, NUM_REGION_ENTRIES,
		sizeof (RegionInfoNameEntry), region_name_locator);

	if (ne == NULL) {
		/*g_print ("ne (%s) is null\n", n);*/
		g_free (n);
		return FALSE;
	}
	g_free (n);

	return construct_region (this_obj, &region_entries [ne->region_entry_index]);
}
Esempio n. 26
0
caddr_t
dotnet_get_instance_name (int instance)
{
  MonoArray *v_args;
  MonoObject *mono_ret;
  caddr_t ret = NULL;
  MonoDomain *domain = virtuoso_domain;
  char *utf8;

  get_mono_thread ();
  v_args = MAKE_PARAM_ARRAY (domain, 1);

  SET_INT_ARG (domain, v_args, 0, instance);

  mono_ret = call_mono (VIRTCLR_NAME, "VInvoke:get_instance_name", v_args, domain);

  if (!mono_ret || !mono_object_isinst (mono_ret, mono_get_string_class ()))
    GPF_T1 ("not a string in dotnet_get_instance_name");
  utf8 = mono_string_to_utf8 ((MonoString *)mono_ret);
  ret = box_dv_short_string (utf8);
  g_free (utf8);

  return ret;
}
Esempio n. 27
0
void print(MonoString* str) {
	char* cstr = mono_string_to_utf8(str);

	std::cout << cstr << std::endl;
}
Esempio n. 28
0
static void*
open_memory_map (MonoString *mapName, int mode, gint64 *capacity, int access, int options, int *error)
{
	char *c_mapName;
	MmapHandle *handle;
	if (*capacity <= 1) {
		*error = CAPACITY_MUST_BE_POSITIVE;
		return NULL;
	}

	if (!(mode == FILE_MODE_CREATE_NEW || mode == FILE_MODE_OPEN_OR_CREATE || mode == FILE_MODE_OPEN)) {
		*error = INVALID_FILE_MODE;
		return NULL;
	}

	c_mapName = mono_string_to_utf8 (mapName);

	named_regions_lock ();
	handle = (MmapHandle*)g_hash_table_lookup (named_regions, c_mapName);
	if (handle) {
		if (mode == FILE_MODE_CREATE_NEW) {
			*error = FILE_ALREADY_EXISTS;
			goto done;
		}

		handle->ref_count++;
		//XXX should we ftruncate if the file is smaller than capacity?
	} else {
		int fd;
		char file_name [sizeof (MONO_ANON_FILE_TEMPLATE) + 1];
		int unused G_GNUC_UNUSED;

		if (mode == FILE_MODE_OPEN) {
			*error = FILE_NOT_FOUND;
			goto done;
		}
		*capacity = align_up_to_page_size (*capacity);

		strcpy (file_name, MONO_ANON_FILE_TEMPLATE);
		fd = mkstemp (file_name);
		if (fd == -1) {
			*error = COULD_NOT_MAP_MEMORY;
			goto done;
		}

		unlink (file_name);
		unused = ftruncate (fd, (off_t)*capacity);

		handle = g_new0 (MmapHandle, 1);
		handle->ref_count = 1;
		handle->capacity = *capacity;
		handle->fd = fd;
		handle->name = g_strdup (c_mapName);

		g_hash_table_insert (named_regions, handle->name, handle);

	}

done:
	named_regions_unlock ();

	g_free (c_mapName);
	return handle;
}
Esempio n. 29
0
/*
XXX implement options
*/
static void*
open_file_map (MonoString *path, int input_fd, int mode, gint64 *capacity, int access, int options, int *error)
{
	struct stat buf;
	char *c_path = path ? mono_string_to_utf8 (path) : NULL;
	MmapHandle *handle = NULL;
	int result, fd;

	if (path)
		result = stat (c_path, &buf);
	else
		result = fstat (input_fd, &buf);

	if (mode == FILE_MODE_TRUNCATE || mode == FILE_MODE_APPEND || mode == FILE_MODE_OPEN) {
		if (result == -1) { //XXX translate errno?
			*error = FILE_NOT_FOUND;
			goto done;
		}
	}

	if (mode == FILE_MODE_CREATE_NEW && result == 0) {
		*error = FILE_ALREADY_EXISTS;
		goto done;
	}

	if (result == 0) {
		if (*capacity == 0) {
			/**
			 * Special files such as FIFOs, sockets, and devices can have a size of 0. Specifying a capacity for these
			 * also makes little sense, so don't do the check if th file is one of these.
			 */
			if (buf.st_size == 0 && !is_special_zero_size_file (&buf)) {
				*error = CAPACITY_SMALLER_THAN_FILE_SIZE;
				goto done;
			}
			*capacity = buf.st_size;
		} else if (*capacity < buf.st_size) {
			*error = CAPACITY_SMALLER_THAN_FILE_SIZE;
			goto done;
		}
	} else {
		if (mode == FILE_MODE_CREATE_NEW && *capacity == 0) {
			*error = CAPACITY_SMALLER_THAN_FILE_SIZE;
			goto done;
		}
	}

	if (path) //FIXME use io portability?
		fd = open (c_path, file_mode_to_unix (mode) | access_mode_to_unix (access), DEFAULT_FILEMODE);
	else
		fd = dup (input_fd);

	if (fd == -1) { //XXX translate errno?
		*error = COULD_NOT_OPEN;
		goto done;
	}

	*capacity = align_up_to_page_size ((size_t)*capacity);

	if (*capacity > buf.st_size) {
		int unused G_GNUC_UNUSED = ftruncate (fd, (off_t)*capacity);
	}

	handle = g_new0 (MmapHandle, 1);
	handle->ref_count = 1;
	handle->capacity = *capacity;
	handle->fd = fd;

done:
	g_free (c_path);
	return (void*)handle;
}
Esempio n. 30
0
jobject JniManager::toResponse(MonoObject* monoObject)
{
    assert(monoObject);

    JNIEnv* env = getEnv();

    assert(env);

    jobject response = env->NewObject(responseClazz, responseCtor);

    MonoObject* exc = NULL;

    MonoObject* result = mono_runtime_invoke(getResult, monoObject, NULL, &exc);

    if (exc)
    {
        const char* message = mono_string_to_utf8(mono_object_to_string(exc, NULL));
        throwException(message);
        return NULL;
    }

    jobject jPayload = NULL;

    if (result != NULL)
    {
        MonoClass* resultClass = mono_object_get_class(result);

        MonoType* monoType = mono_class_get_type(resultClass);

        string typeName = string(mono_type_get_name(monoType));

        // If it's a string or byte[]
        if (typeName == "System.String")
        {
            const char* convertedPayload = mono_string_to_utf8(mono_object_to_string(result, NULL));
            jPayload = env->NewStringUTF(convertedPayload);
        }
        else
        {
            jPayload = typeConverter->convertToJavaArray<jbyteArray>(env, result);
        }

        env->CallVoidMethod(response, setPayloadMethod, jPayload);
        env->DeleteLocalRef(jPayload);
    }

    // set Mule Message properties
    //jobject jInvocationProperties = typeConverter->convertToJavaMap(env, request->InvocationProperties);
    //jobject jSessionProperties = typeConverter->convertToJavaMap(env, request->SessionProperties);
    //jobject jOutboundProperties = typeConverter->convertToJavaMap(env, request->OutboundProperties);

    /*env->CallVoidMethod(response, setInvocationProperties, jInvocationProperties);
    env->CallVoidMethod(response, setOutboundProperties, jOutboundProperties);
    env->CallVoidMethod(response, setSessionProperties, jSessionProperties);

    env->DeleteLocalRef(jInvocationProperties);
    env->DeleteLocalRef(jOutboundProperties);
    env->DeleteLocalRef(jSessionProperties);*/

    return response;
}