* 4MB array.
*/
static GHashTable *file_share_table;
-static mono_mutex_t file_share_mutex;
+static MonoCoopMutex file_share_mutex;
static void
time_t_to_filetime (time_t timeval, FILETIME *filetime)
file_share_release (FileShare *share_info)
{
/* Prevent new entries racing with us */
- mono_os_mutex_lock (&file_share_mutex);
+ mono_coop_mutex_lock (&file_share_mutex);
g_assert (share_info->handle_refs > 0);
share_info->handle_refs -= 1;
if (share_info->handle_refs == 0)
g_hash_table_remove (file_share_table, share_info);
- mono_os_mutex_unlock (&file_share_mutex);
+ mono_coop_mutex_unlock (&file_share_mutex);
}
static gint
gboolean exists = FALSE;
/* Prevent new entries racing with us */
- mono_os_mutex_lock (&file_share_mutex);
+ mono_coop_mutex_lock (&file_share_mutex);
FileShare tmp;
g_hash_table_insert (file_share_table, file_share, file_share);
}
- mono_os_mutex_unlock (&file_share_mutex);
+ mono_coop_mutex_unlock (&file_share_mutex);
return(exists);
}
if (flags & O_CREAT) {
located_filename = mono_portability_find_file (pathname, FALSE);
if (located_filename == NULL) {
+ MONO_ENTER_GC_SAFE;
fd = open (pathname, flags, mode);
+ MONO_EXIT_GC_SAFE;
} else {
+ MONO_ENTER_GC_SAFE;
fd = open (located_filename, flags, mode);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
} else {
+ MONO_ENTER_GC_SAFE;
fd = open (pathname, flags, mode);
+ MONO_EXIT_GC_SAFE;
if (fd == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
located_filename = mono_portability_find_file (pathname, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
fd = open (located_filename, flags, mode);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = access (pathname, mode);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (pathname, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = access (located_filename, mode);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = chmod (pathname, mode);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (pathname, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = chmod (located_filename, mode);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = utime (filename, buf);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && errno == ENOENT && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (filename, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = utime (located_filename, buf);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = unlink (pathname);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR || errno == EISDIR) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (pathname, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = unlink (located_filename);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
gchar *located_newpath = mono_portability_find_file (newpath, FALSE);
if (located_newpath == NULL) {
+ MONO_ENTER_GC_SAFE;
ret = rename (oldpath, newpath);
+ MONO_EXIT_GC_SAFE;
} else {
+ MONO_ENTER_GC_SAFE;
ret = rename (oldpath, located_newpath);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == EISDIR || errno == ENAMETOOLONG || errno == ENOENT || errno == ENOTDIR || errno == EXDEV) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = rename (located_oldpath, located_newpath);
+ MONO_EXIT_GC_SAFE;
g_free (located_oldpath);
}
g_free (located_newpath);
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = stat (path, buf);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (path, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = stat (located_filename, buf);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = lstat (path, buf);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (path, TRUE);
gchar *located_filename = mono_portability_find_file (pathname, FALSE);
if (located_filename == NULL) {
+ MONO_ENTER_GC_SAFE;
ret = mkdir (pathname, mode);
+ MONO_EXIT_GC_SAFE;
} else {
+ MONO_ENTER_GC_SAFE;
ret = mkdir (located_filename, mode);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = rmdir (pathname);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (pathname, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = rmdir (located_filename);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
gint ret;
+ MONO_ENTER_GC_SAFE;
ret = chdir (path);
+ MONO_EXIT_GC_SAFE;
if (ret == -1 && (errno == ENOENT || errno == ENOTDIR || errno == ENAMETOOLONG) && IS_PORTABILITY_SET) {
gint saved_errno = errno;
gchar *located_filename = mono_portability_find_file (path, TRUE);
return -1;
}
+ MONO_ENTER_GC_SAFE;
ret = chdir (located_filename);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
}
{
GDir *ret;
+ MONO_ENTER_GC_SAFE;
ret = g_dir_open (path, flags, error);
+ MONO_EXIT_GC_SAFE;
if (ret == NULL && ((*error)->code == G_FILE_ERROR_NOENT || (*error)->code == G_FILE_ERROR_NOTDIR || (*error)->code == G_FILE_ERROR_NAMETOOLONG) && IS_PORTABILITY_SET) {
gchar *located_filename = mono_portability_find_file (path, TRUE);
GError *tmp_error = NULL;
return(NULL);
}
+ MONO_ENTER_GC_SAFE;
ret = g_dir_open (located_filename, flags, &tmp_error);
+ MONO_EXIT_GC_SAFE;
g_free (located_filename);
if (tmp_error == NULL) {
g_clear_error (error);
gchar *pattern2 = g_strndup (pattern, strlen (pattern) - 2);
gint result2;
+ MONO_ENTER_GC_SAFE;
g_dir_rewind (dir);
+ MONO_EXIT_GC_SAFE;
result2 = mono_w32file_unix_glob (dir, pattern2, flags | W32FILE_UNIX_GLOB_APPEND | W32FILE_UNIX_GLOB_UNIQUE, &glob_buf);
g_free (pattern2);
}
}
+ MONO_ENTER_GC_SAFE;
g_dir_close (dir);
+ MONO_EXIT_GC_SAFE;
if (glob_buf.gl_pathc == 0) {
return(0);
} else if (result != 0) {
*/
static void file_close (gpointer handle, gpointer data)
{
+ MONO_REQ_GC_SAFE_MODE; /* FIXME: after mono_w32handle_close is coop-aware, change this to UNSAFE_MODE and switch to SAFE around close() below */
MonoW32HandleFile *file_handle = (MonoW32HandleFile *)data;
gint fd = file_handle->fd;
}
do {
+ MONO_ENTER_GC_SAFE;
ret = read (fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
} while (ret == -1 && errno == EINTR &&
!mono_thread_info_is_interrupt_state (info));
* because we only do advisory locking on POSIX
* systems
*/
+ MONO_ENTER_GC_SAFE;
current_pos = lseek (fd, (off_t)0, SEEK_CUR);
+ MONO_EXIT_GC_SAFE;
if (current_pos == -1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p lseek failed: %s", __func__,
handle, strerror (errno));
}
do {
+ MONO_ENTER_GC_SAFE;
ret = write (fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
} while (ret == -1 && errno == EINTR &&
!mono_thread_info_is_interrupt_state (info));
return(FALSE);
}
+ MONO_ENTER_GC_SAFE;
ret=fsync(fd);
+ MONO_EXIT_GC_SAFE;
if (ret==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fsync of handle %p error: %s", __func__, handle,
strerror(errno));
#ifdef PLATFORM_ANDROID
/* bionic doesn't support -D_FILE_OFFSET_BITS=64 */
+ MONO_ENTER_GC_SAFE;
newpos=lseek64(fd, offset, whence);
+ MONO_EXIT_GC_SAFE;
#else
+ MONO_ENTER_GC_SAFE;
newpos=lseek(fd, offset, whence);
+ MONO_EXIT_GC_SAFE;
#endif
if(newpos==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: lseek on handle %p returned error %s",
* than the length, truncate the file.
*/
+ MONO_ENTER_GC_SAFE;
ret=fstat(fd, &statbuf);
+ MONO_EXIT_GC_SAFE;
if(ret==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__,
handle, strerror(errno));
return(FALSE);
}
+ MONO_ENTER_GC_SAFE;
pos=lseek(fd, (off_t)0, SEEK_CUR);
+ MONO_EXIT_GC_SAFE;
if(pos==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p lseek failed: %s", __func__,
handle, strerror(errno));
* drop this write.
*/
do {
+ MONO_ENTER_GC_SAFE;
ret = write (fd, "", 1);
+ MONO_EXIT_GC_SAFE;
} while (ret == -1 && errno == EINTR &&
!mono_thread_info_is_interrupt_state (info));
}
/* And put the file position back after the write */
+ MONO_ENTER_GC_SAFE;
ret = lseek (fd, pos, SEEK_SET);
+ MONO_EXIT_GC_SAFE;
if (ret == -1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p second lseek failed: %s",
__func__, handle, strerror(errno));
* byte to the end of the file
*/
do {
+ MONO_ENTER_GC_SAFE;
ret=ftruncate(fd, pos);
+ MONO_EXIT_GC_SAFE;
}
while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info));
if(ret==-1) {
*/
mono_w32error_set_last (ERROR_SUCCESS);
+ MONO_ENTER_GC_SAFE;
ret = fstat(fd, &statbuf);
+ MONO_EXIT_GC_SAFE;
if (ret == -1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__,
handle, strerror(errno));
#ifdef BLKGETSIZE64
if (S_ISBLK(statbuf.st_mode)) {
guint64 bigsize;
- if (ioctl(fd, BLKGETSIZE64, &bigsize) < 0) {
+ gint res;
+ MONO_ENTER_GC_SAFE;
+ res = ioctl (fd, BLKGETSIZE64, &bigsize);
+ MONO_EXIT_GC_SAFE;
+ if (res < 0) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p ioctl BLKGETSIZE64 failed: %s",
__func__, handle, strerror(errno));
return(FALSE);
}
+ MONO_ENTER_GC_SAFE;
ret=fstat(fd, &statbuf);
+ MONO_EXIT_GC_SAFE;
if(ret==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle,
strerror(errno));
/* Get the current times, so we can put the same times back in
* the event that one of the FileTime structs is NULL
*/
+ MONO_ENTER_GC_SAFE;
ret=fstat (fd, &statbuf);
+ MONO_EXIT_GC_SAFE;
if(ret==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle,
strerror(errno));
static void console_close (gpointer handle, gpointer data)
{
+ MONO_REQ_GC_SAFE_MODE; /* FIXME: after mono_w32handle_close is coop-aware, change this to UNSAFE_MODE and switch to SAFE around close() below */
MonoW32HandleFile *console_handle = (MonoW32HandleFile *)data;
gint fd = console_handle->fd;
}
do {
+ MONO_ENTER_GC_SAFE;
ret=read(fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
} while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info));
if(ret==-1) {
}
do {
+ MONO_ENTER_GC_SAFE;
ret = write(fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
} while (ret == -1 && errno == EINTR &&
!mono_thread_info_is_interrupt_state (info));
static void pipe_close (gpointer handle, gpointer data)
{
+ MONO_REQ_GC_SAFE_MODE; /* FIXME: after mono_w32handle_close is coop-aware, change this to UNSAFE_MODE and switch to SAFE around close() below */
MonoW32HandleFile *pipe_handle = (MonoW32HandleFile*)data;
gint fd = pipe_handle->fd;
numbytes, handle);
do {
+ MONO_ENTER_GC_SAFE;
ret=read(fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
} while (ret==-1 && errno==EINTR && !mono_thread_info_is_interrupt_state (info));
if (ret == -1) {
handle);
do {
+ MONO_ENTER_GC_SAFE;
ret = write (fd, buffer, numbytes);
+ MONO_EXIT_GC_SAFE;
} while (ret == -1 && errno == EINTR &&
!mono_thread_info_is_interrupt_state (info));
mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
+ MONO_ENTER_GC_SAFE;
close (fd);
+ MONO_EXIT_GC_SAFE;
g_free (filename);
return(INVALID_HANDLE_VALUE);
}
+ MONO_ENTER_GC_SAFE;
ret = fstat (fd, &statbuf);
+ MONO_EXIT_GC_SAFE;
if (ret == -1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fstat error of file %s: %s", __func__,
filename, strerror (errno));
_wapi_set_last_error_from_errno ();
g_free (filename);
+ MONO_ENTER_GC_SAFE;
close (fd);
+ MONO_EXIT_GC_SAFE;
return(INVALID_HANDLE_VALUE);
}
&file_handle.share_info) == FALSE) {
mono_w32error_set_last (ERROR_SHARING_VIOLATION);
g_free (filename);
+ MONO_ENTER_GC_SAFE;
close (fd);
+ MONO_EXIT_GC_SAFE;
return (INVALID_HANDLE_VALUE);
}
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: No space in the share table", __func__);
mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
+ MONO_ENTER_GC_SAFE;
close (fd);
+ MONO_EXIT_GC_SAFE;
g_free (filename);
return(INVALID_HANDLE_VALUE);
file_handle.attrs=attrs;
#ifdef HAVE_POSIX_FADVISE
- if (attrs & FILE_FLAG_SEQUENTIAL_SCAN)
+ if (attrs & FILE_FLAG_SEQUENTIAL_SCAN) {
+ MONO_ENTER_GC_SAFE;
posix_fadvise (fd, 0, 0, POSIX_FADV_SEQUENTIAL);
- if (attrs & FILE_FLAG_RANDOM_ACCESS)
+ MONO_EXIT_GC_SAFE;
+ }
+ if (attrs & FILE_FLAG_RANDOM_ACCESS) {
+ MONO_ENTER_GC_SAFE;
posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM);
+ MONO_EXIT_GC_SAFE;
+ }
#endif
#ifdef F_RDAHEAD
- if (attrs & FILE_FLAG_SEQUENTIAL_SCAN)
+ if (attrs & FILE_FLAG_SEQUENTIAL_SCAN) {
+ MONO_ENTER_GC_SAFE;
fcntl(fd, F_RDAHEAD, 1);
+ MONO_EXIT_GC_SAFE;
+ }
#endif
#ifndef S_ISFIFO
handle_type = MONO_W32HANDLE_FILE;
}
+ MONO_ENTER_GC_SAFE; /* FIXME: mono_w32handle_new_fd should be updated with coop transitions */
handle = mono_w32handle_new_fd (handle_type, fd, &file_handle);
+ MONO_EXIT_GC_SAFE;
if (handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating file handle", __func__);
g_free (filename);
+ MONO_ENTER_GC_SAFE;
close (fd);
+ MONO_EXIT_GC_SAFE;
mono_w32error_set_last (ERROR_GEN_FAILURE);
return(INVALID_HANDLE_VALUE);
gboolean
mono_w32file_close (gpointer handle)
{
- return mono_w32handle_close (handle);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ /* FIXME: we transition here and not in file_close, pipe_close,
+ * console_close because w32handle_close is not coop aware yet, but it
+ * calls back into w32file. */
+ res = mono_w32handle_close (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean mono_w32file_delete(const gunichar2 *name)
buf = (gchar *) g_malloc (buf_size);
for (;;) {
+ MONO_ENTER_GC_SAFE;
remain = read (src_fd, buf, buf_size);
+ MONO_EXIT_GC_SAFE;
if (remain < 0) {
if (errno == EINTR && !mono_thread_info_is_interrupt_state (info))
continue;
wbuf = buf;
while (remain > 0) {
- if ((n = write (dest_fd, wbuf, remain)) < 0) {
+ MONO_ENTER_GC_SAFE;
+ n = write (dest_fd, wbuf, remain);
+ MONO_EXIT_GC_SAFE;
+ if (n < 0) {
if (errno == EINTR && !mono_thread_info_is_interrupt_state (info))
continue;
struct utimbuf dest_time;
gboolean ret = TRUE;
gint ret_utime;
+ gint syscall_res;
if(name==NULL) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
return(FALSE);
}
- if (fstat (src_fd, &st) < 0) {
+ MONO_ENTER_GC_SAFE;
+ syscall_res = fstat (src_fd, &st);
+ MONO_EXIT_GC_SAFE;
+ if (syscall_res < 0) {
_wapi_set_last_error_from_errno ();
g_free (utf8_src);
g_free (utf8_dest);
+ MONO_ENTER_GC_SAFE;
close (src_fd);
+ MONO_EXIT_GC_SAFE;
return(FALSE);
}
g_free (utf8_src);
g_free (utf8_dest);
+ MONO_ENTER_GC_SAFE;
close (src_fd);
+ MONO_EXIT_GC_SAFE;
mono_w32error_set_last (ERROR_SHARING_VIOLATION);
return (FALSE);
g_free (utf8_src);
g_free (utf8_dest);
+ MONO_ENTER_GC_SAFE;
close (src_fd);
+ MONO_EXIT_GC_SAFE;
return(FALSE);
}
dest_time.modtime = st.st_mtime;
dest_time.actime = st.st_atime;
+ MONO_ENTER_GC_SAFE;
ret_utime = utime (utf8_dest, &dest_time);
+ MONO_EXIT_GC_SAFE;
if (ret_utime == -1)
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file [%s] utime failed: %s", __func__, utf8_dest, strerror(errno));
g_free (utf8_replacedFileName);
g_free (utf8_replacementFileName);
g_free (utf8_backupFileName);
- if (backup_fd != -1)
+ if (backup_fd != -1) {
+ MONO_ENTER_GC_SAFE;
close (backup_fd);
- if (replaced_fd != -1)
+ MONO_EXIT_GC_SAFE;
+ }
+ if (replaced_fd != -1) {
+ MONO_ENTER_GC_SAFE;
close (replaced_fd);
+ MONO_EXIT_GC_SAFE;
+ }
return ret;
}
-static mono_mutex_t stdhandle_mutex;
+static MonoCoopMutex stdhandle_mutex;
static gpointer
_wapi_stdhandle_create (gint fd, const gchar *name)
handle = GINT_TO_POINTER (fd);
- mono_os_mutex_lock (&stdhandle_mutex);
+ mono_coop_mutex_lock (&stdhandle_mutex);
ok = mono_w32handle_lookup (handle, MONO_W32HANDLE_CONSOLE,
(gpointer *)&file_handle);
}
done:
- mono_os_mutex_unlock (&stdhandle_mutex);
-
+ mono_coop_mutex_unlock (&stdhandle_mutex);
+
return(handle);
}
if ((buf.st_mode & S_IROTH) != 0)
exec_mask |= S_IXOTH;
+ MONO_ENTER_GC_SAFE;
result = chmod (utf8_name, buf.st_mode | exec_mask);
+ MONO_EXIT_GC_SAFE;
}
/* Don't bother to reset executable (might need to change this
* policy)
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Creating pipe", __func__);
+ MONO_ENTER_GC_SAFE;
ret=pipe (filedes);
+ MONO_EXIT_GC_SAFE;
if(ret==-1) {
mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error creating pipe: %s", __func__,
strerror (errno));
mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
+ MONO_ENTER_GC_SAFE;
close (filedes[0]);
close (filedes[1]);
+ MONO_EXIT_GC_SAFE;
return(FALSE);
}
&pipe_read_handle);
if (read_handle == INVALID_HANDLE_VALUE) {
g_warning ("%s: error creating pipe read handle", __func__);
+ MONO_ENTER_GC_SAFE;
close (filedes[0]);
close (filedes[1]);
+ MONO_EXIT_GC_SAFE;
mono_w32error_set_last (ERROR_GEN_FAILURE);
return(FALSE);
g_warning ("%s: error creating pipe write handle", __func__);
mono_w32handle_unref (read_handle);
+ MONO_ENTER_GC_SAFE;
close (filedes[0]);
close (filedes[1]);
+ MONO_EXIT_GC_SAFE;
mono_w32error_set_last (ERROR_GEN_FAILURE);
return(FALSE);
gint size, n, i;
gunichar2 *dir;
glong length, total = 0;
-
+ gint syscall_res;
+
+ MONO_ENTER_GC_SAFE;
n = getfsstat (NULL, 0, MNT_NOWAIT);
+ MONO_EXIT_GC_SAFE;
if (n == -1)
return 0;
size = n * sizeof (struct statfs);
stats = (struct statfs *) g_malloc (size);
if (stats == NULL)
return 0;
- if (getfsstat (stats, size, MNT_NOWAIT) == -1){
+ MONO_ENTER_GC_SAFE;
+ syscall_res = getfsstat (stats, size, MNT_NOWAIT);
+ MONO_EXIT_GC_SAFE;
+ if (syscall_res == -1){
g_free (stats);
return 0;
}
gboolean (*parser)(guint32, gunichar2*, LinuxMountInfoParseState*) = NULL;
memset (buf, 0, len * sizeof (gunichar2));
+ MONO_ENTER_GC_SAFE;
fd = open ("/proc/self/mountinfo", O_RDONLY);
+ MONO_EXIT_GC_SAFE;
if (fd != -1)
parser = GetLogicalDriveStrings_MountInfo;
else {
+ MONO_ENTER_GC_SAFE;
fd = open ("/proc/mounts", O_RDONLY);
+ MONO_EXIT_GC_SAFE;
if (fd != -1)
parser = GetLogicalDriveStrings_Mounts;
}
state.field_number = 1;
state.delimiter = ' ';
- while ((state.nbytes = read (fd, state.buffer, GET_LOGICAL_DRIVE_STRINGS_BUFFER)) > 0) {
+ while (1) {
+ MONO_ENTER_GC_SAFE;
+ state.nbytes = read (fd, state.buffer, GET_LOGICAL_DRIVE_STRINGS_BUFFER);
+ MONO_EXIT_GC_SAFE;
+ if (!(state.nbytes > 0))
+ break;
state.buffer_index = 0;
while ((*parser)(len, buf, &state)) {
ret = state.total;
done_and_out:
- if (fd != -1)
+ if (fd != -1) {
+ MONO_ENTER_GC_SAFE;
close (fd);
+ MONO_EXIT_GC_SAFE;
+ }
return ret;
}
/* Sigh, mntent and friends don't work well.
* It stops on the first line that doesn't begin with a '/'.
* (linux 2.6.5, libc 2.3.2.ds1-12) - Gonz */
+ MONO_ENTER_GC_SAFE;
fp = fopen ("/etc/mtab", "rt");
+ MONO_EXIT_GC_SAFE;
if (fp == NULL) {
+ MONO_ENTER_GC_SAFE;
fp = fopen ("/etc/mnttab", "rt");
+ MONO_EXIT_GC_SAFE;
if (fp == NULL)
return 1;
}
ptr = buf;
- while (fgets (buffer, 512, fp) != NULL) {
+ while (1) {
+ gchar *fgets_res;
+ MONO_ENTER_GC_SAFE;
+ fgets_res = fgets (buffer, 512, fp);
+ MONO_EXIT_GC_SAFE;
+ if (!fgets_res)
+ break;
if (*buffer != '/')
continue;
dir = g_utf8_to_utf16 (*(splitted + 1), -1, NULL, &length, NULL);
g_strfreev (splitted);
if (total + length + 1 > len) {
+ MONO_ENTER_GC_SAFE;
fclose (fp);
+ MONO_EXIT_GC_SAFE;
g_free (dir);
return len * 2; /* guess */
}
total += length + 1;
}
+ MONO_ENTER_GC_SAFE;
fclose (fp);
+ MONO_EXIT_GC_SAFE;
return total;
/* Commented out, does not work with my mtab!!! - Gonz */
#ifdef NOTENABLED /* HAVE_MNTENT_H */
glong len, total = 0;
+ MONO_ENTER_GC_SAFE;
fp = setmntent ("/etc/mtab", "rt");
+ MONO_EXIT_GC_SAFE;
if (fp == NULL) {
+ MONO_ENTER_GC_SAFE;
fp = setmntent ("/etc/mnttab", "rt");
+ MONO_EXIT_GC_SAFE;
if (fp == NULL)
return;
}
ptr = buf;
- while ((mnt = getmntent (fp)) != NULL) {
+ while (1) {
+ MONO_ENTER_GC_SAFE;
+ mnt = getmntent (fp);
+ MONO_EXIT_GC_SAFE;
+ if (mnt == NULL)
+ break;
g_print ("GOT %s\n", mnt->mnt_dir);
dir = g_utf8_to_utf16 (mnt->mnt_dir, &len, NULL, NULL, NULL);
if (total + len + 1 > len) {
+ MONO_ENTER_GC_SAFE;
+ endmntent (fp);
+ MONO_EXIT_GC_SAFE;
return len * 2; /* guess */
}
total += len + 1;
}
+ MONO_ENTER_GC_SAFE;
endmntent (fp);
+ MONO_EXIT_GC_SAFE;
return total;
}
#endif
do {
#ifdef HAVE_STATVFS
+ MONO_ENTER_GC_SAFE;
ret = statvfs (utf8_path_name, &fsstat);
+ MONO_EXIT_GC_SAFE;
isreadonly = ((fsstat.f_flag & ST_RDONLY) == ST_RDONLY);
block_size = fsstat.f_frsize;
#elif defined(HAVE_STATFS)
+ MONO_ENTER_GC_SAFE;
ret = statfs (utf8_path_name, &fsstat);
+ MONO_EXIT_GC_SAFE;
#if defined (MNT_RDONLY)
isreadonly = ((fsstat.f_flags & MNT_RDONLY) == MNT_RDONLY);
#elif defined (MS_RDONLY)
GetDriveTypeFromPath (const gchar *utf8_root_path_name)
{
struct statfs buf;
-
- if (statfs (utf8_root_path_name, &buf) == -1)
+ gint res;
+
+ MONO_ENTER_GC_SAFE;
+ res = statfs (utf8_root_path_name, &buf);
+ MONO_EXIT_GC_SAFE;
+ if (res == -1)
return DRIVE_UNKNOWN;
#if PLATFORM_MACOSX
return _wapi_get_drive_type (buf.f_fstypename);
gchar buffer [512];
gchar **splitted;
+ MONO_ENTER_GC_SAFE;
fp = fopen ("/etc/mtab", "rt");
+ MONO_EXIT_GC_SAFE;
if (fp == NULL) {
+ MONO_ENTER_GC_SAFE;
fp = fopen ("/etc/mnttab", "rt");
+ MONO_EXIT_GC_SAFE;
if (fp == NULL)
return(DRIVE_UNKNOWN);
}
drive_type = DRIVE_NO_ROOT_DIR;
- while (fgets (buffer, 512, fp) != NULL) {
+ while (1) {
+ gchar *fgets_res;
+ MONO_ENTER_GC_SAFE;
+ fgets_res = fgets (buffer, 512, fp);
+ MONO_EXIT_GC_SAFE;
+ if (fgets_res == NULL)
+ break;
splitted = g_strsplit (buffer, " ", 0);
if (!*splitted || !*(splitted + 1) || !*(splitted + 2)) {
g_strfreev (splitted);
g_strfreev (splitted);
}
+ MONO_ENTER_GC_SAFE;
fclose (fp);
+ MONO_EXIT_GC_SAFE;
return drive_type;
}
#endif
#if __linux__
_wapi_drive_type *current;
#endif
- if (statfs (utfpath, &stat) == -1)
+ gint statfs_res;
+ MONO_ENTER_GC_SAFE;
+ statfs_res = statfs (utfpath, &stat);
+ MONO_EXIT_GC_SAFE;
+ if (statfs_res == -1)
return NULL;
#if PLATFORM_MACOSX
return g_strdup (stat.f_fstypename);
void
mono_w32file_init (void)
{
- mono_os_mutex_init (&stdhandle_mutex);
- mono_os_mutex_init (&file_share_mutex);
+ mono_coop_mutex_init (&stdhandle_mutex);
+ mono_coop_mutex_init (&file_share_mutex);
mono_w32handle_register_ops (MONO_W32HANDLE_FILE, &_wapi_file_ops);
mono_w32handle_register_ops (MONO_W32HANDLE_CONSOLE, &_wapi_console_ops);
void
mono_w32file_cleanup (void)
{
- mono_os_mutex_destroy (&file_share_mutex);
+ mono_coop_mutex_destroy (&file_share_mutex);
if (file_share_table)
g_hash_table_destroy (file_share_table);
{
gboolean result;
- MONO_ENTER_GC_SAFE;
-
result = MoveFile (path, dest);
if (!result)
*error = mono_w32error_get_last ();
-
- MONO_EXIT_GC_SAFE;
-
return result;
}
{
gboolean result;
- MONO_ENTER_GC_SAFE;
-
result = CopyFile (path, dest, !overwrite);
if (!result)
*error = mono_w32error_get_last ();
- MONO_EXIT_GC_SAFE;
-
return result;
}
{
gboolean result;
- MONO_ENTER_GC_SAFE;
-
result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL);
if (!result)
*error = mono_w32error_get_last ();
-
- MONO_EXIT_GC_SAFE;
-
return result;
}
gint64 length;
guint32 length_hi;
- MONO_ENTER_GC_SAFE;
-
length = GetFileSize (handle, &length_hi);
if(length==INVALID_FILE_SIZE) {
*error=mono_w32error_get_last ();
}
- MONO_EXIT_GC_SAFE;
-
return length | ((gint64)length_hi << 32);
}
{
gboolean result;
- MONO_ENTER_GC_SAFE;
-
result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
if (!result)
*error = mono_w32error_get_last ();
-
- MONO_EXIT_GC_SAFE;
-
return result;
}
{
gboolean result;
- MONO_ENTER_GC_SAFE;
-
result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
if (!result)
*error = mono_w32error_get_last ();
-
- MONO_EXIT_GC_SAFE;
-
return result;
}
gpointer
mono_w32file_get_console_input (void)
{
- gpointer handle;
-
- MONO_ENTER_GC_SAFE;
- handle = mono_w32file_get_std_handle (STD_INPUT_HANDLE);
- MONO_EXIT_GC_SAFE;
-
- return handle;
+ return mono_w32file_get_std_handle (STD_INPUT_HANDLE);
}
gpointer
mono_w32file_get_console_output (void)
{
- gpointer handle;
-
- MONO_ENTER_GC_SAFE;
- handle = mono_w32file_get_std_handle (STD_OUTPUT_HANDLE);
- MONO_EXIT_GC_SAFE;
-
- return handle;
+ return mono_w32file_get_std_handle (STD_OUTPUT_HANDLE);
}
gpointer
mono_w32file_get_console_error (void)
{
- gpointer handle;
-
- MONO_ENTER_GC_SAFE;
- handle = mono_w32file_get_std_handle (STD_ERROR_HANDLE);
- MONO_EXIT_GC_SAFE;
-
- return handle;
+ return mono_w32file_get_std_handle (STD_ERROR_HANDLE);
}
gpointer
mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs)
{
- return CreateFile (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
+ gpointer res;
+ MONO_ENTER_GC_SAFE;
+ res = CreateFile (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_close (gpointer handle)
{
- return CloseHandle (handle);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = CloseHandle (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_delete (const gunichar2 *name)
{
- return DeleteFile (name);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = DeleteFile (name);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread)
{
- return ReadFile (handle, buffer, numbytes, bytesread, NULL);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = ReadFile (handle, buffer, numbytes, bytesread, NULL);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byteswritten)
{
- return WriteFile (handle, buffer, numbytes, byteswritten, NULL);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = WriteFile (handle, buffer, numbytes, byteswritten, NULL);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_flush (gpointer handle)
{
- return FlushFileBuffers (handle);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = FlushFileBuffers (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_truncate (gpointer handle)
{
- return SetEndOfFile (handle);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = SetEndOfFile (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
guint32
mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistance, guint32 method)
{
- return SetFilePointer (handle, movedistance, highmovedistance, method);
+ guint32 res;
+ MONO_ENTER_GC_SAFE;
+ res = SetFilePointer (handle, movedistance, highmovedistance, method);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gint
mono_w32file_get_type (gpointer handle)
{
- return GetFileType (handle);
+ gint res;
+ MONO_ENTER_GC_SAFE;
+ res = GetFileType (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_get_times (gpointer handle, FILETIME *create_time, FILETIME *access_time, FILETIME *write_time)
{
- return GetFileTime (handle, create_time, access_time, write_time);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = GetFileTime (handle, create_time, access_time, write_time);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_set_times (gpointer handle, const FILETIME *create_time, const FILETIME *access_time, const FILETIME *write_time)
{
- return SetFileTime (handle, create_time, access_time, write_time);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = SetFileTime (handle, create_time, access_time, write_time);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_filetime_to_systemtime (const FILETIME *file_time, SYSTEMTIME *system_time)
{
- return FileTimeToSystemTime (file_time, system_time);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = FileTimeToSystemTime (file_time, system_time);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gpointer
mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
{
- return FindFirstFile (pattern, find_data);
+ gpointer res;
+ MONO_ENTER_GC_SAFE;
+ res = FindFirstFile (pattern, find_data);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data)
{
- return FindNextFile (handle, find_data);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = FindNextFile (handle, find_data);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_find_close (gpointer handle)
{
- return FindClose (handle);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = FindClose (handle);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_create_directory (const gunichar2 *name)
{
- return CreateDirectory (name, NULL);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = CreateDirectory (name, NULL);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_remove_directory (const gunichar2 *name)
{
- return RemoveDirectory (name);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = RemoveDirectory (name);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
guint32
mono_w32file_get_attributes (const gunichar2 *name)
{
- return GetFileAttributes (name);
+ guint32 res;
+ MONO_ENTER_GC_SAFE;
+ res = GetFileAttributes (name);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
gboolean result;
WIN32_FILE_ATTRIBUTE_DATA data;
+ MONO_ENTER_GC_SAFE;
result = GetFileAttributesEx (name, GetFileExInfoStandard, &data);
+ MONO_EXIT_GC_SAFE;
if (result) {
stat->attributes = data.dwFileAttributes;
stat->creation_time = (gint64) ((((guint64) data.ftCreationTime.dwHighDateTime) << 32) + data.ftCreationTime.dwLowDateTime);
gboolean
mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
{
- return SetFileAttributes (name, attrs);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = SetFileAttributes (name, attrs);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
guint32
mono_w32file_get_cwd (guint32 length, gunichar2 *buffer)
{
- return GetCurrentDirectory (length, buffer);
+ guint32 res;
+ MONO_ENTER_GC_SAFE;
+ res = GetCurrentDirectory (length, buffer);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_set_cwd (const gunichar2 *path)
{
- return SetCurrentDirectory (path);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = SetCurrentDirectory (path);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
{
+ gboolean res;
SECURITY_ATTRIBUTES attr;
attr.nLength = sizeof(SECURITY_ATTRIBUTES);
attr.bInheritHandle = TRUE;
attr.lpSecurityDescriptor = NULL;
- return CreatePipe (readpipe, writepipe, &attr, size);
+ MONO_ENTER_GC_SAFE;
+ res = CreatePipe (readpipe, writepipe, &attr, size);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gboolean
ULARGE_INTEGER *wapi_total_number_of_bytes;
ULARGE_INTEGER *wapi_total_number_of_free_bytes;
+ MONO_ENTER_GC_SAFE;
result = GetDiskFreeSpaceEx (path_name, wapi_free_bytes_avail, wapi_total_number_of_bytes, wapi_total_number_of_free_bytes);
+ MONO_EXIT_GC_SAFE;
if (result) {
if (free_bytes_avail)
*free_bytes_avail = wapi_free_bytes_avail->QuadPart;
gboolean
mono_w32file_get_volume_information (const gunichar2 *path, gunichar2 *volumename, gint volumesize, gint *outserial, gint *maxcomp, gint *fsflags, gunichar2 *fsbuffer, gint fsbuffersize)
{
- return GetVolumeInformation (path, volumename, volumesize, outserial, maxcomp, fsflags, fsbuffer, fsbuffersize);
+ gboolean res;
+ MONO_ENTER_GC_SAFE;
+ res = GetVolumeInformation (path, volumename, volumesize, outserial, maxcomp, fsflags, fsbuffer, fsbuffersize);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
HANDLE
mono_w32file_get_console_input (void)
{
- return GetStdHandle (STD_INPUT_HANDLE);
+ HANDLE res;
+ MONO_ENTER_GC_SAFE;
+ res = GetStdHandle (STD_INPUT_HANDLE);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
HANDLE
mono_w32file_get_console_output (void)
{
- return GetStdHandle (STD_OUTPUT_HANDLE);
+ HANDLE res;
+ MONO_ENTER_GC_SAFE;
+ res = GetStdHandle (STD_OUTPUT_HANDLE);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
HANDLE
mono_w32file_get_console_error (void)
{
- return GetStdHandle (STD_ERROR_HANDLE);
+ HANDLE res;
+ MONO_ENTER_GC_SAFE;
+ res = GetStdHandle (STD_ERROR_HANDLE);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gint64
guint32
mono_w32file_get_drive_type (const gunichar2 *root_path_name)
{
- return GetDriveType (root_path_name);
+ guint32 res;
+ MONO_ENTER_GC_SAFE;
+ res = GetDriveType (root_path_name);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
gint32
mono_w32file_get_logical_drive (guint32 len, gunichar2 *buf)
{
- return GetLogicalDriveStrings (len, buf);
+ gint32 res;
+ MONO_ENTER_GC_SAFE;
+ res = GetLogicalDriveStrings (len, buf);
+ MONO_EXIT_GC_SAFE;
+ return res;
}
#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */