12
12
#include <windows.h>
13
13
#include "mono/metadata/w32file-win32-internals.h"
14
14
#include "mono/metadata/profiler-private.h"
15
+ #include "mono/metadata/w32error.h"
15
16
16
17
void
17
18
mono_w32file_init (void )
@@ -97,12 +98,17 @@ mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *
97
98
mono_thread_info_install_interrupt (cancel_w32_io , handle , & interrupted );
98
99
if (!interrupted )
99
100
{
101
+ guint32 last_error ;
100
102
MONO_ENTER_GC_SAFE ;
101
103
res = ReadFile (handle , buffer , numbytes , bytesread , NULL );
102
104
MONO_PROFILER_RAISE (fileio , (1 , * bytesread ));
103
105
MONO_EXIT_GC_SAFE ;
104
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 ();
105
110
mono_thread_info_uninstall_interrupt (& interrupted );
111
+ mono_w32error_set_last (last_error );
106
112
}
107
113
108
114
return res ;
@@ -117,12 +123,17 @@ mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, gui
117
123
mono_thread_info_install_interrupt (cancel_w32_io , handle , & interrupted );
118
124
if (!interrupted )
119
125
{
126
+ guint32 last_error ;
120
127
MONO_ENTER_GC_SAFE ;
121
128
res = WriteFile (handle , buffer , numbytes , byteswritten , NULL );
122
129
MONO_PROFILER_RAISE (fileio , (0 , * byteswritten ));
123
130
MONO_EXIT_GC_SAFE ;
124
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 ();
125
135
mono_thread_info_uninstall_interrupt (& interrupted );
136
+ mono_w32error_set_last (last_error );
126
137
}
127
138
128
139
return res ;
0 commit comments