Skip to content

Commit

Permalink
Merge pull request #973 from Unity-Technologies/unity-master-fix-file…
Browse files Browse the repository at this point in the history
…-io-interrupt

Ensure last Win32 error is preserved for IO operations (case 1047186)
  • Loading branch information
joncham authored Jun 11, 2018
2 parents 8d92cae + b6f1ba8 commit 855f47c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mono/metadata/w32file-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <windows.h>
#include "mono/metadata/w32file-win32-internals.h"
#include "mono/metadata/profiler-private.h"
#include "mono/metadata/w32error.h"

void
mono_w32file_init (void)
Expand Down Expand Up @@ -97,12 +98,17 @@ mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *
mono_thread_info_install_interrupt (cancel_w32_io, handle, &interrupted);
if (!interrupted)
{
guint32 last_error;
MONO_ENTER_GC_SAFE;
res = ReadFile (handle, buffer, numbytes, bytesread, NULL);
MONO_PROFILER_RAISE (fileio, (1, *bytesread));
MONO_EXIT_GC_SAFE;

/* need to save and restore since clients expect error code set for
* failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
last_error = mono_w32error_get_last ();
mono_thread_info_uninstall_interrupt (&interrupted);
mono_w32error_set_last (last_error);
}

return res;
Expand All @@ -117,12 +123,17 @@ mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, gui
mono_thread_info_install_interrupt (cancel_w32_io, handle, &interrupted);
if (!interrupted)
{
guint32 last_error;
MONO_ENTER_GC_SAFE;
res = WriteFile (handle, buffer, numbytes, byteswritten, NULL);
MONO_PROFILER_RAISE (fileio, (0, *byteswritten));
MONO_EXIT_GC_SAFE;

/* need to save and restore since clients expect error code set for
* failed IO calls and mono_thread_info_uninstall_interrupt overwrites value */
last_error = mono_w32error_get_last ();
mono_thread_info_uninstall_interrupt (&interrupted);
mono_w32error_set_last (last_error);
}

return res;
Expand Down

0 comments on commit 855f47c

Please sign in to comment.