Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
/* This is an icall */
void *
mono_mmap_open_file (MonoString *path, int mode, MonoString *mapName, gint64 *capacity, int access, int options, int *ioerror)
{
	MonoError error;
	MmapHandle *handle = NULL;
	g_assert (path || mapName);

	if (!mapName) {
		char * c_path = mono_string_to_utf8_checked (path, &error);
		if (mono_error_set_pending_exception (&error))
			return NULL;
		handle = open_file_map (c_path, -1, mode, capacity, access, options, ioerror);
		g_free (c_path);
		return handle;
	}

	char *c_mapName = mono_string_to_utf8_checked (mapName, &error);
	if (mono_error_set_pending_exception (&error))
		return NULL;

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

	g_free (c_mapName);
	return handle;
}