@@ -92,49 +92,46 @@ cancel_w32_io (HANDLE file_handle)
9292gboolean
9393mono_w32file_read (gpointer handle , gpointer buffer , guint32 numbytes , guint32 * bytesread )
9494{
95- gboolean res = FALSE;
95+
9696 gboolean interrupted ;
97+ guint32 last_error ;
98+ gboolean res ;
99+
100+ MonoThreadInfo * info = mono_thread_info_current ();
101+
102+ mono_win32_enter_blocking_io_call (info , (HANDLE )handle );
103+ MONO_ENTER_GC_SAFE ;
104+ res = ReadFile ((HANDLE )handle , buffer , numbytes , (PDWORD )bytesread , NULL );
105+ /* need to save and restore since clients expect error code set for
106+ * failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
107+ last_error = mono_w32error_get_last ();
108+
109+ MONO_EXIT_GC_SAFE ;
110+ mono_win32_leave_blocking_io_call (info , (HANDLE )handle );
111+ mono_w32error_set_last (last_error );
97112
98- mono_thread_info_install_interrupt (cancel_w32_io , handle , & interrupted );
99- if (!interrupted )
100- {
101- guint32 last_error ;
102- MONO_ENTER_GC_SAFE ;
103- res = ReadFile (handle , buffer , numbytes , bytesread , NULL );
104- MONO_PROFILER_RAISE (fileio , (1 , * bytesread ));
105- MONO_EXIT_GC_SAFE ;
106-
107- /* need to save and restore since clients expect error code set for
108- * failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
109- last_error = mono_w32error_get_last ();
110- mono_thread_info_uninstall_interrupt (& interrupted );
111- mono_w32error_set_last (last_error );
112- }
113113
114114 return res ;
115115}
116116
117117gboolean
118118mono_w32file_write (gpointer handle , gconstpointer buffer , guint32 numbytes , guint32 * byteswritten )
119119{
120- gboolean res = FALSE;
121120 gboolean interrupted ;
121+ guint32 last_error ;
122+ gboolean res ;
123+
124+ MonoThreadInfo * info = mono_thread_info_current ();
122125
123- mono_thread_info_install_interrupt (cancel_w32_io , handle , & interrupted );
124- if (!interrupted )
125- {
126- guint32 last_error ;
127- MONO_ENTER_GC_SAFE ;
128- res = WriteFile (handle , buffer , numbytes , byteswritten , NULL );
129- MONO_PROFILER_RAISE (fileio , (0 , * byteswritten ));
130- MONO_EXIT_GC_SAFE ;
131-
132- /* need to save and restore since clients expect error code set for
133- * failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
134- last_error = mono_w32error_get_last ();
135- mono_thread_info_uninstall_interrupt (& interrupted );
136- mono_w32error_set_last (last_error );
137- }
126+ mono_win32_enter_blocking_io_call (info , (HANDLE )handle );
127+ MONO_ENTER_GC_SAFE ;
128+ res = WriteFile ((HANDLE )handle , buffer , numbytes , (PDWORD )byteswritten , NULL );
129+ /* need to save and restore since clients expect error code set for
130+ * failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
131+ last_error = mono_w32error_get_last ();
132+ MONO_EXIT_GC_SAFE ;
133+ mono_win32_leave_blocking_io_call (info , (HANDLE )handle );
134+ mono_w32error_set_last (last_error );
138135
139136 return res ;
140137}
0 commit comments