[w32file] transition to GC unsafe in file handle close callbacks.
authorAleksey Kliger <aleksey@xamarin.com>
Tue, 14 Feb 2017 17:39:59 +0000 (12:39 -0500)
committerAleksey Kliger <aleksey@xamarin.com>
Tue, 14 Feb 2017 17:39:59 +0000 (12:39 -0500)
Followup to last commit (f238640c9ff855bc5c2ab812cf21fd747a624dc9).
We need to transition to unsafe to call file_share_release and the _wapi_
functions, and then back to safe to call close(2).

mono/metadata/w32file-unix.c

index 4d9e256aca6f470db4a0494d5cf68197f3af8c44..2333d7e4a7f228a7ca1a852189c1059c59311530 100644 (file)
@@ -1100,6 +1100,7 @@ static void _wapi_set_last_path_error_from_errno (const gchar *dir,
 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 */
+       MONO_ENTER_GC_UNSAFE;
        MonoW32HandleFile *file_handle = (MonoW32HandleFile *)data;
        gint fd = file_handle->fd;
        
@@ -1114,7 +1115,10 @@ static void file_close (gpointer handle, gpointer data)
        if (file_handle->share_info)
                file_share_release (file_handle->share_info);
        
+       MONO_ENTER_GC_SAFE;
        close (fd);
+       MONO_EXIT_GC_SAFE;
+       MONO_EXIT_GC_UNSAFE;
 }
 
 static void file_details (gpointer data)
@@ -1836,6 +1840,7 @@ static gboolean file_setfiletime(gpointer handle,
 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 */
+       MONO_ENTER_GC_UNSAFE;
        MonoW32HandleFile *console_handle = (MonoW32HandleFile *)data;
        gint fd = console_handle->fd;
        
@@ -1846,8 +1851,11 @@ static void console_close (gpointer handle, gpointer data)
        if (fd > 2) {
                if (console_handle->share_info)
                        file_share_release (console_handle->share_info);
+               MONO_ENTER_GC_SAFE;
                close (fd);
+               MONO_EXIT_GC_SAFE;
        }
+       MONO_EXIT_GC_UNSAFE;
 }
 
 static void console_details (gpointer data)
@@ -1991,6 +1999,7 @@ static gsize find_typesize (void)
 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 */
+       MONO_ENTER_GC_UNSAFE;
        MonoW32HandleFile *pipe_handle = (MonoW32HandleFile*)data;
        gint fd = pipe_handle->fd;
 
@@ -2001,7 +2010,10 @@ static void pipe_close (gpointer handle, gpointer data)
        if (pipe_handle->share_info)
                file_share_release (pipe_handle->share_info);
 
+       MONO_ENTER_GC_SAFE;
        close (fd);
+       MONO_EXIT_GC_SAFE;
+       MONO_EXIT_GC_UNSAFE;
 }
 
 static void pipe_details (gpointer data)