[io-layer] Extract error (#4279)
authorLudovic Henry <ludovic@xamarin.com>
Sat, 21 Jan 2017 01:15:19 +0000 (20:15 -0500)
committerGitHub <noreply@github.com>
Sat, 21 Jan 2017 01:15:19 +0000 (20:15 -0500)
* [file] Remove dead field

* [process] Remove wapi_getpid

* [process] Remove CloseHandle

* [io-layer] Remove dead MONO_TRACE

* [io-layer] Extract error

* [io-layer] Extract wapi.h

* [io-layer] Remove the io-layer

82 files changed:
configure.ac
mono/Makefile.am
mono/dis/Makefile.am
mono/io-layer/.gitignore [deleted file]
mono/io-layer/Makefile.am [deleted file]
mono/io-layer/error.c [deleted file]
mono/io-layer/error.h [deleted file]
mono/io-layer/io-layer-dummy.c [deleted file]
mono/io-layer/io-layer.h [deleted file]
mono/io-layer/wapi-remap.h [deleted file]
mono/io-layer/wapi.c [deleted file]
mono/io-layer/wapi.h [deleted file]
mono/metadata/Makefile.am
mono/metadata/appdomain.c
mono/metadata/assembly.c
mono/metadata/attach.c
mono/metadata/cominterop.c
mono/metadata/console-unix.c
mono/metadata/coree.c
mono/metadata/coree.h
mono/metadata/domain.c
mono/metadata/environment.c
mono/metadata/filewatcher.c
mono/metadata/gc.c
mono/metadata/icall.c
mono/metadata/image.c
mono/metadata/lock-tracer.c
mono/metadata/monitor.c
mono/metadata/mono-perfcounters.c
mono/metadata/mono-security.c
mono/metadata/object.c
mono/metadata/profiler.c
mono/metadata/sre-save.c
mono/metadata/sre.c
mono/metadata/threadpool-io.c
mono/metadata/threadpool-worker-default.c
mono/metadata/threadpool.c
mono/metadata/threads.c
mono/metadata/w32error-unix.c [new file with mode: 0644]
mono/metadata/w32error-win32.c [new file with mode: 0644]
mono/metadata/w32error.h [new file with mode: 0644]
mono/metadata/w32event-unix.c
mono/metadata/w32event-win32.c
mono/metadata/w32event.h
mono/metadata/w32file-unix.c
mono/metadata/w32file-win32.c
mono/metadata/w32file.c
mono/metadata/w32file.h
mono/metadata/w32handle-namespace.c
mono/metadata/w32handle.c
mono/metadata/w32handle.h
mono/metadata/w32mutex-unix.c
mono/metadata/w32process-unix.c
mono/metadata/w32process-win32.c
mono/metadata/w32process.c
mono/metadata/w32process.h
mono/metadata/w32semaphore-unix.c
mono/metadata/w32socket-internals.h
mono/metadata/w32socket-unix.c
mono/metadata/w32socket-win32.c
mono/metadata/w32socket.c
mono/mini/Makefile.am.in
mono/mini/aot-compiler.c
mono/mini/debugger-agent.c
mono/mini/driver.c
mono/mini/mini-darwin.c
mono/mini/mini-posix.c
mono/mini/mini-runtime.c
mono/mini/mini-windows.c
mono/mini/mini.c
mono/unit-tests/Makefile.am
mono/utils/hazard-pointer.c
mono/utils/mono-codeman.c
mono/utils/mono-threads.c
mono/utils/w32api.h [new file with mode: 0644]
msvc/libmonoruntime.vcxproj
msvc/libmonoruntime.vcxproj.filters
msvc/pedump.vcxproj
msvc/pedump.vcxproj.filters
support/supportw.c
tools/monograph/Makefile.am
tools/pedump/Makefile.am

index aed81dc091df6eab9c5dc8235980cdf55b46023b..632983d0c1171c45bec5a9da86d4a4af8b9c6efd 100644 (file)
@@ -4349,7 +4349,6 @@ mono/tests/assemblyresolve/Makefile
 mono/tests/gc-descriptors/Makefile
 mono/unit-tests/Makefile
 mono/benchmark/Makefile
-mono/io-layer/Makefile
 mono/mini/Makefile
 mono/profiler/Makefile
 m4/Makefile
index 651271c25f895fe4a332287feba54f1eed76833f..8c9c2cbac2f6ef09407d2aa29ad319471b20cb44 100644 (file)
@@ -7,10 +7,10 @@ btls_dirs = btls
 endif
 
 if CROSS_COMPILING
-SUBDIRS = $(btls_dirs) arch utils io-layer cil metadata $(sgen_dirs) mini dis profiler
+SUBDIRS = $(btls_dirs) arch utils cil metadata $(sgen_dirs) mini dis profiler
 else
 if INSTALL_MONOTOUCH
-SUBDIRS = $(btls_dirs) arch utils io-layer metadata $(sgen_dirs) mini profiler
+SUBDIRS = $(btls_dirs) arch utils metadata $(sgen_dirs) mini profiler
 
 monotouch-do-build:
        @list='$(SUBDIRS)'; for subdir in $$list; do \
@@ -34,7 +34,7 @@ monotouch-do-clean:
          (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$target); \
     done;
 else
-SUBDIRS = $(btls_dirs) arch utils io-layer cil metadata $(sgen_dirs) mini dis tests unit-tests benchmark profiler
+SUBDIRS = $(btls_dirs) arch utils cil metadata $(sgen_dirs) mini dis tests unit-tests benchmark profiler
 endif
 endif
-DIST_SUBDIRS = btls arch utils io-layer cil metadata $(sgen_dirs) mini dis tests unit-tests benchmark profiler
+DIST_SUBDIRS = btls arch utils cil metadata $(sgen_dirs) mini dis tests unit-tests benchmark profiler
index 40f0dbf95524a9372405cbce3eef665f45f8da8f..14090d8c3ecc5d60c50a5d2225e23b0a559b3e47 100644 (file)
@@ -15,7 +15,6 @@ endif
 runtime_lib=   \
        $(metadata_lib) \
        $(gc_lib)       \
-       $(top_builddir)/mono/io-layer/libwapi.la        \
        $(top_builddir)/mono/utils/libmonoutils.la \
        $(GLIB_LIBS) $(LIBICONV)
 
diff --git a/mono/io-layer/.gitignore b/mono/io-layer/.gitignore
deleted file mode 100644 (file)
index 9fda7d3..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-/semantic.cache
-/.deps
-/.libs
-/Makefile
-/Makefile.in
-/mono-handle-d
-/*.lo
-/*.la
-/*.o
-/.project
-/.cproject
-/TAGS
diff --git a/mono/io-layer/Makefile.am b/mono/io-layer/Makefile.am
deleted file mode 100644 (file)
index 48e48ba..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-
-noinst_LTLIBRARIES = libwapi.la
-
-AM_CPPFLAGS = \
-       $(GLIB_CFLAGS)          \
-       $(LIBGC_CPPFLAGS)       \
-       -DMONO_BINDIR=\""$(bindir)"\"   \
-       -I$(top_srcdir) \
-       $(SHARED_CFLAGS)
-
-libwapiincludedir = $(includedir)/mono-$(API_VER)/mono/io-layer
-
-OTHER_H = \
-       error.h         \
-       io-layer.h      \
-       wapi.h          \
-       wapi-remap.h
-
-OTHER_SRC = \
-       error.c                 \
-       error.h                 \
-       io-layer.h              \
-       wapi.h                  \
-       wapi.c
-
-
-WINDOWS_H = \
-       io-layer.h
-
-WINDOWS_SRC = \
-       io-layer.h              \
-       io-layer-dummy.c
-
-if HOST_WIN32
-libwapi_la_SOURCES = $(WINDOWS_SRC) $(WINDOWS_H)
-else
-libwapi_la_SOURCES = $(OTHER_SRC) $(OTHER_H)
-endif
-if PLATFORM_DARWIN
-libwapi_la_LIBADD = -lproc
-endif
-
-EXTRA_DIST =   \
-       $(WINDOWS_SRC)
-       $(OTHER_SRC)
-
-
diff --git a/mono/io-layer/error.c b/mono/io-layer/error.c
deleted file mode 100644 (file)
index 38a9141..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * error.c:  Error reporting
- *
- * Author:
- *     Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- */
-
-#include <config.h>
-#include <glib.h>
-#include <pthread.h>
-#include <string.h>
-#include <errno.h>
-
-#include "mono/io-layer/wapi.h"
-#include "mono/utils/mono-lazy-init.h"
-
-static pthread_key_t error_key;
-static mono_lazy_init_t error_key_once = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
-
-static void error_init(void)
-{
-       int ret;
-       
-       ret = pthread_key_create(&error_key, NULL);
-       g_assert (ret == 0);
-}
-
-/**
- * GetLastError:
- *
- * Retrieves the last error that occurred in the calling thread.
- *
- * Return value: The error code for the last error that happened on
- * the calling thread.
- */
-guint32 GetLastError(void)
-{
-       guint32 err;
-       void *errptr;
-
-       mono_lazy_initialize(&error_key_once, error_init);
-       errptr=pthread_getspecific(error_key);
-       err=GPOINTER_TO_UINT(errptr);
-       
-       return(err);
-}
-
-/**
- * SetLastError:
- * @code: The error code.
- *
- * Sets the error code in the calling thread.
- */
-void SetLastError(guint32 code)
-{
-       int ret;
-       
-       /* Set the thread-local error code */
-       mono_lazy_initialize(&error_key_once, error_init);
-       ret = pthread_setspecific(error_key, GUINT_TO_POINTER(code));
-       g_assert (ret == 0);
-}
-
-gint
-_wapi_get_win32_file_error (gint err)
-{
-       gint ret;
-       /* mapping ideas borrowed from wine. they may need some work */
-
-       switch (err) {
-       case EACCES: case EPERM: case EROFS:
-               ret = ERROR_ACCESS_DENIED;
-               break;
-       
-       case EAGAIN:
-               ret = ERROR_SHARING_VIOLATION;
-               break;
-       
-       case EBUSY:
-               ret = ERROR_LOCK_VIOLATION;
-               break;
-       
-       case EEXIST:
-               ret = ERROR_FILE_EXISTS;
-               break;
-       
-       case EINVAL: case ESPIPE:
-               ret = ERROR_SEEK;
-               break;
-       
-       case EISDIR:
-               ret = ERROR_CANNOT_MAKE;
-               break;
-       
-       case ENFILE: case EMFILE:
-               ret = ERROR_TOO_MANY_OPEN_FILES;
-               break;
-
-       case ENOENT: case ENOTDIR:
-               ret = ERROR_FILE_NOT_FOUND;
-               break;
-       
-       case ENOSPC:
-               ret = ERROR_HANDLE_DISK_FULL;
-               break;
-       
-       case ENOTEMPTY:
-               ret = ERROR_DIR_NOT_EMPTY;
-               break;
-
-       case ENOEXEC:
-               ret = ERROR_BAD_FORMAT;
-               break;
-
-       case ENAMETOOLONG:
-               ret = ERROR_FILENAME_EXCED_RANGE;
-               break;
-       
-#ifdef EINPROGRESS
-       case EINPROGRESS:
-               ret = ERROR_IO_PENDING;
-               break;
-#endif
-       
-       case ENOSYS:
-               ret = ERROR_NOT_SUPPORTED;
-               break;
-       
-       case EBADF:
-               ret = ERROR_INVALID_HANDLE;
-               break;
-               
-       case EIO:
-               ret = ERROR_INVALID_HANDLE;
-               break;
-               
-       case EINTR:
-               ret = ERROR_IO_PENDING;         /* best match I could find */
-               break;
-               
-       case EPIPE:
-               ret = ERROR_WRITE_FAULT;
-               break;
-               
-       default:
-               g_message ("Unknown errno: %s\n", g_strerror (err));
-               ret = ERROR_GEN_FAILURE;
-               break;
-       }
-
-       return ret;
-}
-
diff --git a/mono/io-layer/error.h b/mono/io-layer/error.h
deleted file mode 100644 (file)
index 9f6c640..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * error.h:  Error reporting
- *
- * Author:
- *     Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- */
-
-#ifndef _WAPI_ERROR_H_
-#define _WAPI_ERROR_H_
-
-typedef enum {
-       ERROR_SUCCESS              = 0,
-       ERROR_FILE_NOT_FOUND       = 2,
-       ERROR_PATH_NOT_FOUND       = 3,
-       ERROR_TOO_MANY_OPEN_FILES  = 4,
-       ERROR_ACCESS_DENIED        = 5,
-       ERROR_INVALID_HANDLE       = 6,
-       ERROR_NOT_ENOUGH_MEMORY    = 8,
-       ERROR_BAD_FORMAT           = 11,
-       ERROR_INVALID_ACCESS       = 12,
-       ERROR_INVALID_DATA         = 13,
-       ERROR_OUTOFMEMORY          = 14,
-       ERROR_NOT_SAME_DEVICE      = 17,
-       ERROR_NO_MORE_FILES        = 18,
-       ERROR_BAD_LENGTH           = 24,
-       ERROR_SEEK                 = 25,
-       ERROR_WRITE_FAULT          = 29,
-       ERROR_GEN_FAILURE          = 31,
-       ERROR_SHARING_VIOLATION    = 32,
-       ERROR_LOCK_VIOLATION       = 33,
-       ERROR_HANDLE_DISK_FULL     = 39,
-       ERROR_NOT_SUPPORTED        = 50,
-       ERROR_FILE_EXISTS          = 80,
-       ERROR_CANNOT_MAKE          = 82,
-       ERROR_INVALID_PARAMETER    = 87,
-       ERROR_INVALID_NAME         = 123,
-       ERROR_PROC_NOT_FOUND       = 127,
-       ERROR_DIR_NOT_EMPTY        = 145,
-       ERROR_ALREADY_EXISTS       = 183,
-       ERROR_BAD_EXE_FORMAT       = 193,
-       ERROR_FILENAME_EXCED_RANGE = 206,
-       ERROR_DIRECTORY            = 267,
-       ERROR_IO_PENDING           = 997,
-       ERROR_ENCRYPTION_FAILED    = 6000,
-       WSAEINTR                   = 10004,
-       WSAEBADF                   = 10009,
-       WSAEACCES                  = 10013,
-       WSAEFAULT                  = 10014,
-       WSAEINVAL                  = 10022,
-       WSAEMFILE                  = 10024,
-       WSAEWOULDBLOCK             = 10035,
-       WSAEINPROGRESS             = 10036,
-       WSAEALREADY                = 10037,
-       WSAENOTSOCK                = 10038,
-       WSAEDESTADDRREQ            = 10039,
-       WSAEMSGSIZE                = 10040,
-       WSAENOPROTOOPT             = 10042,
-       WSAEPROTONOSUPPORT         = 10043,
-       WSAESOCKTNOSUPPORT         = 10044,
-       WSAEOPNOTSUPP              = 10045,
-       WSAEAFNOSUPPORT            = 10047,
-       WSAEADDRINUSE              = 10048,
-       WSAEADDRNOTAVAIL           = 10049,
-       WSAENETDOWN                = 10050,
-       WSAENETUNREACH             = 10051,
-       WSAECONNRESET              = 10054,
-       WSAENOBUFS                 = 10055,
-       WSAEISCONN                 = 10056,
-       WSAENOTCONN                = 10057,
-       WSAESHUTDOWN               = 10058,
-       WSAETIMEDOUT               = 10060,
-       WSAECONNREFUSED            = 10061,
-       WSAEHOSTDOWN               = 10064,
-       WSAEHOSTUNREACH            = 10065,
-       WSASYSCALLFAILURE          = 10107,
-} WapiError;
-
-G_BEGIN_DECLS
-
-guint32 GetLastError (void);
-void SetLastError (guint32 code);
-gint _wapi_get_win32_file_error (gint err);
-
-G_END_DECLS
-
-#endif /* _WAPI_ERROR_H_ */
diff --git a/mono/io-layer/io-layer-dummy.c b/mono/io-layer/io-layer-dummy.c
deleted file mode 100644 (file)
index f6e150a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * io-layer-dummy.c:  Dummy file to fill the library on windows
- *
- * Author:
- *     Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- */
-
-extern char *_mono_iolayer_dummylib;
-char *_mono_iolayer_dummylib="This is a dummy library that isn't needed on Windows";
diff --git a/mono/io-layer/io-layer.h b/mono/io-layer/io-layer.h
deleted file mode 100755 (executable)
index f1d2e05..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * io-layer.h: Include the right files depending on platform.  This
- * file is the only entry point into the io-layer library.
- *
- * Author:
- *     Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- */
-
-#ifndef _MONO_IOLAYER_IOLAYER_H_
-#define _MONO_IOLAYER_IOLAYER_H_
-
-#include <config.h>
-#include <glib.h>
-
-#if defined(__WIN32__) || defined(_WIN32)
-/* Native win32 */
-#define __USE_W32_SOCKETS
-#include <winsock2.h>
-#include <windows.h>
-#include <winbase.h>
-/*
- * The mingw version says:
- * /usr/i686-pc-mingw32/sys-root/mingw/include/ws2tcpip.h:38:2: error: #error "ws2tcpip.h is not compatible with winsock.h. Include winsock2.h instead."
- */
-#ifdef _MSC_VER
-#include <ws2tcpip.h>
-#endif
-#include <psapi.h>
-
- /*
- * Workaround for missing WSAPOLLFD typedef in mingw's winsock2.h that is required for mswsock.h below.
- * Remove once http://sourceforge.net/p/mingw/bugs/1980/ is fixed.
- */
-#if defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION == 4 
-typedef struct pollfd {
-  SOCKET fd;
-  short  events;
-  short  revents;
-} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;
-#endif
-
-#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
-#include <mswsock.h>
-#endif
-
-#else  /* EVERYONE ELSE */
-#include "mono/io-layer/wapi.h"
-#endif /* HOST_WIN32 */
-
-#ifdef __native_client__
-#include "mono/metadata/nacl-stub.h"
-#endif
-
-#endif /* _MONO_IOLAYER_IOLAYER_H_ */
diff --git a/mono/io-layer/wapi-remap.h b/mono/io-layer/wapi-remap.h
deleted file mode 100644 (file)
index 80034f5..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * wapi-remap.h: io-layer symbol remapping support
- *
- * (C) 2014 Xamarin, Inc.
- */
-
-#ifndef __WAPI_REMAP_H__
-#define __WAPI_REMAP_H__
-
-/*
- * The windows function names used by the io-layer can collide with symbols in system and 3rd party libs, esp. on osx/ios. So remap them to
- * wapi_<funcname>.
- */
-
-#define GetLastError wapi_GetLastError
-#define SetLastError wapi_SetLastError
-#define CloseHandle wapi_CloseHandle 
-
-#endif /* __WAPI_REMAP_H__ */
diff --git a/mono/io-layer/wapi.c b/mono/io-layer/wapi.c
deleted file mode 100644 (file)
index 14dc672..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-
-#include "wapi.h"
-
-#include "mono/utils/mono-lazy-init.h"
-#include "mono/metadata/w32handle.h"
-
-/* Use this instead of getpid(), to cope with linuxthreads.  It's a
- * function rather than a variable lookup because we need to get at
- * this before share_init() might have been called. */
-static mono_lazy_init_t _wapi_pid_init_lazy = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
-static pid_t _wapi_pid;
-
-static void
-_wapi_pid_init (void)
-{
-       _wapi_pid = getpid ();
-}
-
-pid_t
-wapi_getpid (void)
-{
-       mono_lazy_initialize (&_wapi_pid_init_lazy, _wapi_pid_init);
-       return _wapi_pid;
-}
-
-/**
- * CloseHandle:
- * @handle: The handle to release
- *
- * Closes and invalidates @handle, releasing any resources it
- * consumes.  When the last handle to a temporary or non-persistent
- * object is closed, that object can be deleted.  Closing the same
- * handle twice is an error.
- *
- * Return value: %TRUE on success, %FALSE otherwise.
- */
-gboolean CloseHandle(gpointer handle)
-{
-       if (handle == INVALID_HANDLE_VALUE){
-               SetLastError (ERROR_INVALID_PARAMETER);
-               return FALSE;
-       }
-       if (handle == (gpointer)0 && mono_w32handle_get_type (handle) != MONO_W32HANDLE_CONSOLE) {
-               /* Problem: because we map file descriptors to the
-                * same-numbered handle we can't tell the difference
-                * between a bogus handle and the handle to stdin.
-                * Assume that it's the console handle if that handle
-                * exists...
-                */
-               SetLastError (ERROR_INVALID_PARAMETER);
-               return FALSE;
-       }
-
-       mono_w32handle_unref (handle);
-       return TRUE;
-}
diff --git a/mono/io-layer/wapi.h b/mono/io-layer/wapi.h
deleted file mode 100644 (file)
index 4409210..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * wapi.h:  Public include files
- *
- * Author:
- *     Dick Porter (dick@ximian.com)
- *
- * (C) 2002 Ximian, Inc.
- */
-
-#ifndef _WAPI_WAPI_H_
-#define _WAPI_WAPI_H_
-
-#include <config.h>
-#include <glib.h>
-
-#ifdef HAVE_DIRENT_H
-#include <dirent.h>
-#endif
-#include <unistd.h>
-#include <utime.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <mono/io-layer/wapi-remap.h>
-#include <mono/io-layer/error.h>
-#include <mono/utils/mono-logger-internals.h>
-
-G_BEGIN_DECLS
-
-#define WAIT_FAILED        ((gint) 0xFFFFFFFF)
-#define WAIT_OBJECT_0      ((gint) 0x00000000)
-#define WAIT_ABANDONED_0   ((gint) 0x00000080)
-#define WAIT_TIMEOUT       ((gint) 0x00000102)
-#define WAIT_IO_COMPLETION ((gint) 0x000000C0)
-
-#ifdef DISABLE_IO_LAYER_TRACE
-#define MONO_TRACE(...)
-#else
-#define MONO_TRACE(...) mono_trace (__VA_ARGS__)
-#endif
-
-#define WINAPI
-
-typedef guint32 DWORD;
-typedef gboolean BOOL;
-typedef gint32 LONG;
-typedef guint32 ULONG;
-typedef guint UINT;
-
-typedef gpointer HANDLE;
-typedef gpointer HMODULE;
-
-gboolean
-CloseHandle (gpointer handle);
-
-pid_t
-wapi_getpid (void);
-
-G_END_DECLS
-
-#endif /* _WAPI_WAPI_H_ */
index 4a997d3fc4c072affba54f944099c505451deb6c..751eabbb1b613b8020795eb57541ebf53b2aee99 100644 (file)
@@ -16,7 +16,8 @@ win32_sources = \
        w32event-win32.c \
        w32process-win32.c \
        w32process-win32-internals.h \
-       w32socket-win32.c
+       w32socket-win32.c \
+       w32error-win32.c
 
 platform_sources = $(win32_sources)
 
@@ -52,7 +53,8 @@ unix_sources = \
        w32socket-unix.c \
        w32file-unix.c \
        w32file-unix-glob.c \
-       w32file-unix-glob.h
+       w32file-unix-glob.h \
+       w32error-unix.c
 
 platform_sources = $(unix_sources)
 endif
@@ -267,7 +269,8 @@ common_sources = \
        w32handle-namespace.h   \
        w32handle-namespace.c   \
        w32handle.h     \
-       w32handle.c
+       w32handle.c     \
+       w32error.h
 
 # These source files have compile time dependencies on GC code
 gc_dependent_sources = \
index a2c8c353fd3a1d11c502f2901f5d015198047b97..dc17ecc71c06a5786d8ee68ab4dd8cc402998ec2 100644 (file)
@@ -70,7 +70,8 @@
 #include <mono/utils/mono-memory-model.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/metadata/w32handle.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/metadata/w32error.h>
+#include <mono/utils/w32api.h>
 #ifdef HOST_WIN32
 #include <direct.h>
 #endif
@@ -1598,7 +1599,7 @@ shadow_copy_create_ini (const char *shadow, const char *filename)
        full_path = mono_path_resolve_symlinks (filename);
        result = mono_w32file_write (handle, full_path, strlen (full_path), &n);
        g_free (full_path);
-       CloseHandle (handle);
+       mono_w32file_close (handle);
        return result;
 }
 
@@ -1762,7 +1763,7 @@ mono_make_shadow_copy (const char *filename, MonoError *oerror)
                g_free (shadow);
 
                /* Fix for bug #17251 - if file not found try finding assembly by other means (it is not fatal error) */
-               if (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND)
+               if (mono_w32error_get_last() == ERROR_FILE_NOT_FOUND || mono_w32error_get_last() == ERROR_PATH_NOT_FOUND)
                        return NULL; /* file not found, shadow copy failed */
 
                mono_error_set_execution_engine (oerror, "Failed to create shadow copy (mono_w32file_copy).");
index 61b4c3416523eb3a19ba77dc0ae51ad0e1a181ce..e909833e7c7231cfb6091c143768ab8234e8c549 100644 (file)
@@ -30,7 +30,6 @@
 #include <mono/metadata/reflection-internals.h>
 #include <mono/metadata/mono-endian.h>
 #include <mono/metadata/mono-debug.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/mono-uri.h>
 #include <mono/metadata/mono-config.h>
 #include <mono/metadata/mono-config-dirs.h>
index 6fc81e0898495bc1f2d608290859ea3daa4d1a2e..13f03abf48535462f6b94fb5f912c6ab3d16183c 100644 (file)
@@ -42,7 +42,7 @@
 #include <mono/utils/mono-threads.h>
 #include "attach.h"
 
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 /*
  * This module enables other processes to attach to a running mono process and
index f3beb972401bc99e6190c69ff1f5ee9b3835799b..769e06867deb7316cc06babd87de69c0efef84b9 100644 (file)
@@ -38,9 +38,9 @@
 #include "mono/utils/atomic.h"
 #include "mono/utils/mono-error.h"
 #include "mono/utils/mono-error-internals.h"
-#include "mono/io-layer/io-layer.h"
 #include <string.h>
 #include <errno.h>
+#include <mono/utils/w32api.h>
 
 #if defined(HOST_WIN32)
 #include <oleauto.h>
index 7d1e9a1ec000ec99ff42e70c68be63c7c9057e76..7d60b770fe57a3999f7c0ba60b19ed292b2c157a 100644 (file)
@@ -37,7 +37,7 @@
 #include <mono/metadata/threadpool.h>
 #include <mono/utils/mono-signal-handler.h>
 #include <mono/utils/mono-proclib.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 /* On solaris, curses.h must come before both termios.h and term.h */
 #ifdef HAVE_CURSES_H
index 428fb9b989f80b6fea16ac5b54aad5cdf52cceb3..0ce8810d4c224354306cb72cd01cf6d64f573da1 100644 (file)
@@ -14,8 +14,8 @@
 
 #include <glib.h>
 #include <string.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/mono-path.h>
+#include "utils/w32api.h"
 #include "cil-coff.h"
 #include "metadata-internals.h"
 #include "image.h"
index ade821af5e316c1830aabb6e9096bf58a6179682..1b139b692026ed0aa35e7a8f83f73997785223b7 100644 (file)
@@ -16,8 +16,8 @@
 
 #ifdef HOST_WIN32
 
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/mono-compiler.h>
+#include <mono/utils/w32api.h>
 #include "image.h"
 
 #define STATUS_SUCCESS 0x00000000L
index 908f572a5ff33369610201492ca721aa7ca93297..12f778fa1ad29865db7371cf79c7446f3492630e 100644 (file)
@@ -48,7 +48,6 @@
 #include <metadata/threads.h>
 #include <metadata/profiler-private.h>
 #include <mono/metadata/coree.h>
-#include <mono/io-layer/io-layer.h>
 
 //#define DEBUG_DOMAIN_UNLOAD 1
 
index 4726f9ba703db888ea33078bd842e31ccb88e294..f0fbef9174f111f8ea652c53ea8aa56c050104ce 100644 (file)
@@ -17,7 +17,7 @@
 #include <mono/metadata/environment.h>
 #include <mono/metadata/exception.h>
 #include <mono/utils/mono-compiler.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
 
index 90a54d5050ad6aaea8545a0f8e7379f32d63eced..9d154e1ecd60a5cf7b8c6bc94bf93c7a657cdcf7 100644 (file)
@@ -28,7 +28,7 @@
 #include <mono/metadata/marshal.h>
 #include <mono/utils/mono-dl.h>
 #include <mono/utils/mono-io-portability.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/metadata/w32error.h>
 
 #ifdef HOST_WIN32
 
index 1a452c083ee0384a7dedfc9a4dc5d6d06b6c033e..9060cf400e012cdd756af2fa2de2b9ada65f71b3 100644 (file)
@@ -42,7 +42,7 @@
 #include <mono/utils/atomic.h>
 #include <mono/utils/mono-coop-semaphore.h>
 #include <mono/utils/hazard-pointer.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 #ifndef HOST_WIN32
 #include <pthread.h>
index f0dc4ef12388e9e8d7c8225536fbe2167062c753..3e87be6daf94477e3de8824cdcf2ca0a7f128956 100644 (file)
@@ -85,7 +85,6 @@
 #include <mono/metadata/w32mutex.h>
 #include <mono/metadata/w32semaphore.h>
 #include <mono/metadata/w32event.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/monobitset.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-proclib.h>
@@ -97,6 +96,8 @@
 #include <mono/utils/bsearch.h>
 #include <mono/utils/mono-os-mutex.h>
 #include <mono/utils/mono-threads.h>
+#include <mono/metadata/w32error.h>
+#include <mono/utils/w32api.h>
 
 #include "decimal-ms.h"
 #include "number-ms.h"
@@ -7031,7 +7032,7 @@ ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (MonoString *path_name, guint64 *
 
        result = mono_w32file_get_disk_free_space (mono_string_chars (path_name), free_bytes_avail, total_number_of_bytes, total_number_of_free_bytes);
        if (!result)
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
 
        return result;
 }
index 5bcd6e90adc75fd8b5629834716d20c6b6302173..84204ec073ba277e07f8d97f470945f943786297 100644 (file)
@@ -27,7 +27,6 @@
 #include "loader.h"
 #include "marshal.h"
 #include "coree.h"
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/checked-build.h>
 #include <mono/utils/mono-logger-internals.h>
 #include <mono/utils/mono-path.h>
@@ -46,6 +45,7 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#include <mono/metadata/w32error.h>
 
 #define INVALID_ADDRESS 0xffffffff
 
@@ -1544,7 +1544,7 @@ mono_image_open_full (const char *fname, MonoImageOpenStatus *status, gboolean r
                fname_utf16 = g_utf8_to_utf16 (absfname, -1, NULL, NULL, NULL);
                module_handle = MonoLoadImage (fname_utf16);
                if (status && module_handle == NULL)
-                       last_error = GetLastError ();
+                       last_error = mono_w32error_get_last ();
 
                /* mono_image_open_from_module_handle is called by _CorDllMain. */
                image = g_hash_table_lookup (loaded_images, absfname);
index 8ca4a27ab8211ed592ba4f0cbbe4d7f78d4ad91f..16fcbdb0618c251bb1b90d3bfbf8e4b22cf8ee7a 100644 (file)
@@ -20,7 +20,6 @@
 #include <execinfo.h>
 #endif
 
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/mono-compiler.h>
 
 #include "lock-tracer.h"
index 0b1e938f3d857069e9a5a47bf10127b297de6fac..dd2cc0eb9a7186b6a6d77471adeb1a914570bef9 100644 (file)
@@ -18,7 +18,6 @@
 #include <mono/metadata/threads-types.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/threads.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/gc-internals.h>
@@ -31,6 +30,7 @@
 #include <mono/metadata/profiler-private.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/atomic.h>
+#include <mono/utils/w32api.h>
 
 /*
  * Pull the list of opcodes
@@ -396,7 +396,7 @@ mon_new (gsize id)
                                                /* Orphaned events left by aborted threads */
                                                while (new_->wait_list) {
                                                        LOCK_DEBUG (g_message (G_GNUC_PRETTY_FUNCTION ": (%d): Closing orphaned event %d", mono_thread_info_get_small_id (), new_->wait_list->data));
-                                                       CloseHandle (new_->wait_list->data);
+                                                       mono_w32event_close (new_->wait_list->data);
                                                        new_->wait_list = g_slist_remove (new_->wait_list, new_->wait_list->data);
                                                }
                                        }
@@ -1352,7 +1352,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
 
        /* This looks superfluous */
        if (mono_thread_current_check_pending_interrupt ()) {
-               CloseHandle (event);
+               mono_w32event_close (event);
                return FALSE;
        }
        
@@ -1431,7 +1431,7 @@ ves_icall_System_Threading_Monitor_Monitor_wait (MonoObject *obj, guint32 ms)
                 */
                mon->wait_list = g_slist_remove (mon->wait_list, event);
        }
-       CloseHandle (event);
+       mono_w32event_close (event);
        
        return success;
 }
index cd2c622a89d19f0f1054157a3b8795f696415a40..57c01f411e33ffb0ec34c3f0b04b436de297680b 100644 (file)
@@ -48,7 +48,6 @@
 #include "utils/mono-networkinterfaces.h"
 #include "utils/mono-error-internals.h"
 #include "utils/atomic.h"
-#include <mono/io-layer/io-layer.h>
 
 /* map of CounterSample.cs */
 struct _MonoCounterSample {
index cd1a9ad0aecf2c980b244c5a1058838a536cc1ef..a1d3c9d0e4fe22e880944a855475c09b7ad09a00 100644 (file)
@@ -19,7 +19,6 @@
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/security.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/utils/strenc.h>
 
 #ifndef HOST_WIN32
index 29103437bbd0efb1c9213b355c8bec0a95dfd2d2..699c7d225fb78b8e5899d38738fef4b01619464a 100644 (file)
@@ -50,7 +50,7 @@
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-threads-coop.h>
 #include "cominterop.h"
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 static void
 get_default_field_value (MonoDomain* domain, MonoClassField *field, void *value, MonoError *error);
index 0fd162dd98a86884d77a104587973a79cd5549a0..a880ec9330068672aeae59a614df7bf7759d6041 100644 (file)
@@ -22,7 +22,6 @@
 #include "mono/metadata/domain-internals.h"
 #include "mono/metadata/gc-internals.h"
 #include "mono/metadata/mono-config-dirs.h"
-#include "mono/io-layer/io-layer.h"
 #include "mono/utils/mono-dl.h"
 #include <mono/utils/mono-logger-internals.h>
 #include <string.h>
index 4d94b5524b9cc102c17ec41b9bd4ab487e0698f2..20d9e47a4a3945453e3fdd0d96653f273a3722c2 100644 (file)
 #include "mono/metadata/tabledefs.h"
 #include "mono/metadata/tokentype.h"
 #include "mono/metadata/w32file.h"
+#include "mono/metadata/w32error.h"
 
 #include "mono/utils/checked-build.h"
 #include "mono/utils/mono-digest.h"
 #include "mono/utils/mono-error-internals.h"
-
-#include "mono/io-layer/io-layer.h"
+#include "mono/utils/w32api.h"
 
 #define TEXT_OFFSET 512
 #define CLI_H_SIZE 136
@@ -2739,7 +2739,7 @@ checked_write_file (HANDLE f, gconstpointer buffer, guint32 numbytes)
 {
        guint32 dummy;
        if (!mono_w32file_write (f, buffer, numbytes, &dummy))
-               g_error ("mono_w32file_write returned %d\n", GetLastError ());
+               g_error ("mono_w32file_write returned %d\n", mono_w32error_get_last ());
 }
 
 /*
@@ -3034,7 +3034,7 @@ mono_image_create_pefile (MonoReflectionModuleBuilder *mb, HANDLE file, MonoErro
                        continue;
                
                if (mono_w32file_seek (file, assembly->sections [i].offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
-                       g_error ("mono_w32file_seek returned %d\n", GetLastError ());
+                       g_error ("mono_w32file_seek returned %d\n", mono_w32error_get_last ());
                
                switch (i) {
                case MONO_SECTION_TEXT:
@@ -3094,9 +3094,9 @@ mono_image_create_pefile (MonoReflectionModuleBuilder *mb, HANDLE file, MonoErro
        
        /* check that the file is properly padded */
        if (mono_w32file_seek (file, file_offset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
-               g_error ("mono_w32file_seek returned %d\n", GetLastError ());
+               g_error ("mono_w32file_seek returned %d\n", mono_w32error_get_last ());
        if (! mono_w32file_truncate (file))
-               g_error ("mono_w32file_truncate returned %d\n", GetLastError ());
+               g_error ("mono_w32file_truncate returned %d\n", mono_w32error_get_last ());
        
        mono_dynamic_stream_reset (&assembly->code);
        mono_dynamic_stream_reset (&assembly->us);
index e7545f4172421532ea520373808e3e7cefdf9978..df218b3ea045edbf6c8503505e955a9315082d19 100644 (file)
@@ -34,7 +34,7 @@
 #include "mono/metadata/tokentype.h"
 #include "mono/utils/checked-build.h"
 #include "mono/utils/mono-digest.h"
-#include "mono/io-layer/io-layer.h"
+#include "mono/utils/w32api.h"
 
 static GENERATE_GET_CLASS_WITH_CACHE (marshal_as_attribute, System.Runtime.InteropServices, MarshalAsAttribute);
 static GENERATE_GET_CLASS_WITH_CACHE (module_builder, System.Reflection.Emit, ModuleBuilder);
index 4b59150832a71ed77980c966e1a2d0c9ccb747a2..ace9a00bf6a8adb9bd83bcf6944f01bf84cfb882 100644 (file)
@@ -29,7 +29,7 @@
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-lazy-init.h>
 #include <mono/utils/mono-logger-internals.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 typedef struct {
        gboolean (*init) (gint wakeup_pipe_fd);
index f78ccf68b2a19822f7aa464e6d3320861fc4e59d..e882574ab15b10b5dbf188256f7e6c015094c421 100644 (file)
@@ -33,7 +33,7 @@
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-rand.h>
 #include <mono/utils/refcount.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 #define CPU_USAGE_LOW 80
 #define CPU_USAGE_HIGH 95
index 75de23a393c84f22bcd12730204933c9b73458d6..dfd61ea3f589177a1aa7c7f9cd877e85488a6052 100644 (file)
@@ -45,7 +45,6 @@
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/refcount.h>
-#include <mono/io-layer/io-layer.h>
 
 typedef struct {
        MonoDomain *domain;
@@ -567,7 +566,7 @@ mono_threadpool_end_invoke (MonoAsyncResult *ares, MonoArray **out_args, MonoObj
                        g_assert(wait_event);
                        MonoWaitHandle *wait_handle = mono_wait_handle_new (mono_object_domain (ares), wait_event, error);
                        if (!is_ok (error)) {
-                               CloseHandle (wait_event);
+                               mono_w32event_close (wait_event);
                                return NULL;
                        }
                        MONO_OBJECT_SETREF (ares, handle, (MonoObject*) wait_handle);
index b5ffc0202314853e9c36d478c6eab0df86575253..abc29bf0022c3d70c33af64cac939df00c980834 100644 (file)
@@ -28,7 +28,6 @@
 #include <mono/metadata/gc-internals.h>
 #include <mono/metadata/marshal.h>
 #include <mono/metadata/runtime.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/mono-debug-debugger.h>
 #include <mono/utils/monobitset.h>
@@ -53,6 +52,8 @@
 #include <mono/metadata/gc-internals.h>
 #include <mono/metadata/reflection-internals.h>
 #include <mono/metadata/abi-details.h>
+#include <mono/metadata/w32error.h>
+#include <mono/utils/w32api.h>
 
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
@@ -795,7 +796,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, MonoObject *sta
                mono_threads_lock ();
                mono_g_hash_table_remove (threads_starting_up, thread);
                mono_threads_unlock ();
-               mono_error_set_execution_engine (error, "Couldn't create thread. Error 0x%x", GetLastError());
+               mono_error_set_execution_engine (error, "Couldn't create thread. Error 0x%x", mono_w32error_get_last());
                /* ref is not going to be decremented in start_wrapper_internal */
                InterlockedDecrement (&start_info->ref);
                ret = FALSE;
diff --git a/mono/metadata/w32error-unix.c b/mono/metadata/w32error-unix.c
new file mode 100644 (file)
index 0000000..6192d88
--- /dev/null
@@ -0,0 +1,68 @@
+
+#include "w32error.h"
+
+#include "utils/mono-lazy-init.h"
+
+static mono_lazy_init_t error_key_once = MONO_LAZY_INIT_STATUS_NOT_INITIALIZED;
+
+static pthread_key_t error_key;
+
+static void
+error_key_init (void)
+{
+       gint ret;
+       ret = pthread_key_create (&error_key, NULL);
+       g_assert (ret == 0);
+}
+
+guint32
+mono_w32error_get_last (void)
+{
+       mono_lazy_initialize (&error_key_once, error_key_init);
+       return GPOINTER_TO_UINT (pthread_getspecific (error_key));
+}
+
+void
+mono_w32error_set_last (guint32 error)
+{
+       gint ret;
+       mono_lazy_initialize (&error_key_once, error_key_init);
+       ret = pthread_setspecific (error_key, GUINT_TO_POINTER (error));
+       g_assert (ret == 0);
+}
+
+guint32
+mono_w32error_unix_to_win32 (guint32 error)
+{
+       /* mapping ideas borrowed from wine. they may need some work */
+
+       switch (error) {
+       case EACCES:
+       case EPERM:
+       case EROFS: return ERROR_ACCESS_DENIED;
+       case EAGAIN: return ERROR_SHARING_VIOLATION;
+       case EBUSY: return ERROR_LOCK_VIOLATION;
+       case EEXIST: return ERROR_FILE_EXISTS;
+       case EINVAL:
+       case ESPIPE: return ERROR_SEEK;
+       case EISDIR: return ERROR_CANNOT_MAKE;
+       case ENFILE:
+       case EMFILE: return ERROR_TOO_MANY_OPEN_FILES;
+       case ENOENT:
+       case ENOTDIR: return ERROR_FILE_NOT_FOUND;
+       case ENOSPC: return ERROR_HANDLE_DISK_FULL;
+       case ENOTEMPTY: return ERROR_DIR_NOT_EMPTY;
+       case ENOEXEC: return ERROR_BAD_FORMAT;
+       case ENAMETOOLONG: return ERROR_FILENAME_EXCED_RANGE;
+#ifdef EINPROGRESS
+       case EINPROGRESS: return ERROR_IO_PENDING;
+#endif
+       case ENOSYS: return ERROR_NOT_SUPPORTED;
+       case EBADF: return ERROR_INVALID_HANDLE;
+       case EIO: return ERROR_INVALID_HANDLE;
+       case EINTR: return ERROR_IO_PENDING; /* best match I could find */
+       case EPIPE: return ERROR_WRITE_FAULT;
+       default:
+               g_error ("%s: unknown error (%d) \"%s\"", error, g_strerror (error));
+       }
+}
diff --git a/mono/metadata/w32error-win32.c b/mono/metadata/w32error-win32.c
new file mode 100644 (file)
index 0000000..8b83039
--- /dev/null
@@ -0,0 +1,22 @@
+
+#include <windows.h>
+
+#include "w32error.h"
+
+guint32
+mono_w32error_get_last (void)
+{
+       return GetLastError ();
+}
+
+void
+mono_w32error_set_last (guint32 error)
+{
+       SetLastError (error);
+}
+
+guint32
+mono_w32error_unix_to_win32 (guint32 error)
+{
+       g_assert_not_reached ();
+}
diff --git a/mono/metadata/w32error.h b/mono/metadata/w32error.h
new file mode 100644 (file)
index 0000000..990ba3b
--- /dev/null
@@ -0,0 +1,86 @@
+
+#ifndef _MONO_METADATA_W32ERROR_H_
+#define _MONO_METADATA_W32ERROR_H_
+
+#include <config.h>
+#include <glib.h>
+
+#if !defined(HOST_WIN32)
+
+#define ERROR_SUCCESS              0
+#define ERROR_FILE_NOT_FOUND       2
+#define ERROR_PATH_NOT_FOUND       3
+#define ERROR_TOO_MANY_OPEN_FILES  4
+#define ERROR_ACCESS_DENIED        5
+#define ERROR_INVALID_HANDLE       6
+#define ERROR_NOT_ENOUGH_MEMORY    8
+#define ERROR_BAD_FORMAT           11
+#define ERROR_INVALID_ACCESS       12
+#define ERROR_INVALID_DATA         13
+#define ERROR_OUTOFMEMORY          14
+#define ERROR_NOT_SAME_DEVICE      17
+#define ERROR_NO_MORE_FILES        18
+#define ERROR_BAD_LENGTH           24
+#define ERROR_SEEK                 25
+#define ERROR_WRITE_FAULT          29
+#define ERROR_GEN_FAILURE          31
+#define ERROR_SHARING_VIOLATION    32
+#define ERROR_LOCK_VIOLATION       33
+#define ERROR_HANDLE_DISK_FULL     39
+#define ERROR_NOT_SUPPORTED        50
+#define ERROR_FILE_EXISTS          80
+#define ERROR_CANNOT_MAKE          82
+#define ERROR_INVALID_PARAMETER    87
+#define ERROR_INVALID_NAME         123
+#define ERROR_PROC_NOT_FOUND       127
+#define ERROR_DIR_NOT_EMPTY        145
+#define ERROR_ALREADY_EXISTS       183
+#define ERROR_BAD_EXE_FORMAT       193
+#define ERROR_FILENAME_EXCED_RANGE 206
+#define ERROR_DIRECTORY            267
+#define ERROR_IO_PENDING           997
+#define ERROR_ENCRYPTION_FAILED    6000
+#define WSAEINTR                   10004
+#define WSAEBADF                   10009
+#define WSAEACCES                  10013
+#define WSAEFAULT                  10014
+#define WSAEINVAL                  10022
+#define WSAEMFILE                  10024
+#define WSAEWOULDBLOCK             10035
+#define WSAEINPROGRESS             10036
+#define WSAEALREADY                10037
+#define WSAENOTSOCK                10038
+#define WSAEDESTADDRREQ            10039
+#define WSAEMSGSIZE                10040
+#define WSAENOPROTOOPT             10042
+#define WSAEPROTONOSUPPORT         10043
+#define WSAESOCKTNOSUPPORT         10044
+#define WSAEOPNOTSUPP              10045
+#define WSAEAFNOSUPPORT            10047
+#define WSAEADDRINUSE              10048
+#define WSAEADDRNOTAVAIL           10049
+#define WSAENETDOWN                10050
+#define WSAENETUNREACH             10051
+#define WSAECONNRESET              10054
+#define WSAENOBUFS                 10055
+#define WSAEISCONN                 10056
+#define WSAENOTCONN                10057
+#define WSAESHUTDOWN               10058
+#define WSAETIMEDOUT               10060
+#define WSAECONNREFUSED            10061
+#define WSAEHOSTDOWN               10064
+#define WSAEHOSTUNREACH            10065
+#define WSASYSCALLFAILURE          10107
+
+#endif
+
+guint32
+mono_w32error_get_last (void);
+
+void
+mono_w32error_set_last (guint32 error);
+
+guint32
+mono_w32error_unix_to_win32 (guint32 error);
+
+#endif /* _MONO_METADATA_W32ERROR_H_ */
index 8c9b1b1f765c5342dc35c9272c6f9339ff5ae555..50e9a6abad471f205cca5cef0cc66dd9a39bcaa2 100644 (file)
@@ -9,8 +9,8 @@
 
 #include "w32event.h"
 
+#include "w32error.h"
 #include "w32handle-namespace.h"
-#include "mono/io-layer/io-layer.h"
 #include "mono/utils/mono-logger-internals.h"
 #include "mono/metadata/w32handle.h"
 
@@ -158,6 +158,12 @@ mono_w32event_create (gboolean manual, gboolean initial)
        return handle;
 }
 
+gboolean
+mono_w32event_close (gpointer handle)
+{
+       return mono_w32handle_close (handle);
+}
+
 void
 mono_w32event_set (gpointer handle)
 {
@@ -181,7 +187,7 @@ static gpointer event_handle_create (MonoW32HandleEvent *event_handle, MonoW32Ha
        if (handle == INVALID_HANDLE_VALUE) {
                g_warning ("%s: error creating %s handle",
                        __func__, mono_w32handle_get_typename (type));
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                return NULL;
        }
 
@@ -223,10 +229,10 @@ static gpointer namedevent_create (gboolean manual, gboolean initial, const guni
        if (handle == INVALID_HANDLE_VALUE) {
                /* The name has already been used for a different object. */
                handle = NULL;
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
        } else if (handle) {
                /* Not an error, but this is how the caller is informed that the event wasn't freshly created */
-               SetLastError (ERROR_ALREADY_EXISTS);
+               mono_w32error_set_last (ERROR_ALREADY_EXISTS);
 
                /* mono_w32handle_namespace_search_handle already adds a ref to the handle */
        } else {
@@ -254,11 +260,11 @@ ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, Mono
        /* Need to blow away any old errors here, because code tests
         * for ERROR_ALREADY_EXISTS on success (!) to see if an event
         * was freshly created */
-       SetLastError (ERROR_SUCCESS);
+       mono_w32error_set_last (ERROR_SUCCESS);
 
        event = name ? namedevent_create (manual, initial, mono_string_chars (name)) : event_create (manual, initial);
 
-       *error = GetLastError ();
+       *error = mono_w32error_get_last ();
 
        return event;
 }
@@ -270,7 +276,7 @@ ves_icall_System_Threading_Events_SetEvent_internal (gpointer handle)
        MonoW32HandleEvent *event_handle;
 
        if (handle == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -279,7 +285,7 @@ ves_icall_System_Threading_Events_SetEvent_internal (gpointer handle)
        case MONO_W32HANDLE_NAMEDEVENT:
                break;
        default:
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
@@ -312,10 +318,10 @@ ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
        MonoW32HandleType type;
        MonoW32HandleEvent *event_handle;
 
-       SetLastError (ERROR_SUCCESS);
+       mono_w32error_set_last (ERROR_SUCCESS);
 
        if (handle == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -324,7 +330,7 @@ ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
        case MONO_W32HANDLE_NAMEDEVENT:
                break;
        default:
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
@@ -359,7 +365,7 @@ ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
 void
 ves_icall_System_Threading_Events_CloseEvent_internal (gpointer handle)
 {
-       CloseHandle (handle);
+       mono_w32handle_close (handle);
 }
 
 gpointer
index 86590217c4d35bdcdbce1c6397f5fb849c88f10d..343347da362baca44d1d2a7998f38213c2739ff5 100644 (file)
@@ -23,6 +23,12 @@ mono_w32event_create (gboolean manual, gboolean initial)
        return CreateEvent (NULL, manual, initial, NULL);
 }
 
+gboolean
+mono_w32event_close (gpointer handle)
+{
+       return CloseHandle (handle);
+}
+
 void
 mono_w32event_set (gpointer handle)
 {
index 1f41b1a455530366aed57acb8e75347ccccbf93b..f1fbd702872e7912a66264241abb6305a60e855a 100644 (file)
@@ -14,6 +14,9 @@ mono_w32event_init (void);
 gpointer
 mono_w32event_create (gboolean manual, gboolean initial);
 
+gboolean
+mono_w32event_close (gpointer handle);
+
 void
 mono_w32event_set (gpointer handle);
 
index ecca05ec6aa9bfecb911522876e2ae1b6f751a0d..be8b5f70502c4777e5e428c943e711ad8856c64d 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "w32file-unix-glob.h"
 #include "w32handle.h"
+#include "w32error.h"
 #include "utils/mono-io-portability.h"
 #include "utils/mono-logger-internals.h"
 #include "utils/mono-os-mutex.h"
@@ -46,7 +47,6 @@
 typedef struct {
        guint64 device;
        guint64 inode;
-       pid_t opened_by_pid;
        guint32 sharemode;
        guint32 access;
        guint32 handle_refs;
@@ -160,7 +160,6 @@ file_share_get (guint64 device, guint64 inode, guint32 new_sharemode, guint32 ne
 
                file_share->device = device;
                file_share->inode = inode;
-               file_share->opened_by_pid = wapi_getpid ();
                file_share->sharemode = new_sharemode;
                file_share->access = new_access;
                file_share->handle_refs = 1;
@@ -672,7 +671,7 @@ _wapi_lock_file_region (gint fd, off_t offset, off_t length)
        gint ret;
 
        if (offset < 0 || length < 0) {
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return FALSE;
        }
 
@@ -703,7 +702,7 @@ _wapi_lock_file_region (gint fd, off_t offset, off_t length)
                        return TRUE;
                }
 
-               SetLastError (ERROR_LOCK_VIOLATION);
+               mono_w32error_set_last (ERROR_LOCK_VIOLATION);
                return FALSE;
        }
 
@@ -748,7 +747,7 @@ _wapi_unlock_file_region (gint fd, off_t offset, off_t length)
                        return TRUE;
                }
 
-               SetLastError (ERROR_LOCK_VIOLATION);
+               mono_w32error_set_last (ERROR_LOCK_VIOLATION);
                return FALSE;
        }
 
@@ -1009,7 +1008,7 @@ static guint32 _wapi_stat_to_file_attributes (const gchar *pathname,
 static void
 _wapi_set_last_error_from_errno (void)
 {
-       SetLastError (_wapi_get_win32_file_error (errno));
+       mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
 }
 
 static void _wapi_set_last_path_error_from_errno (const gchar *dir,
@@ -1029,9 +1028,9 @@ static void _wapi_set_last_path_error_from_errno (const gchar *dir,
                }
                
                if (_wapi_access (dirname, F_OK) == 0) {
-                       SetLastError (ERROR_FILE_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
                } else {
-                       SetLastError (ERROR_PATH_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
                }
 
                g_free (dirname);
@@ -1104,7 +1103,7 @@ file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -1118,7 +1117,7 @@ file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u",
                          __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
 
@@ -1132,7 +1131,7 @@ file_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesread
 
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: read of handle %p error: %s", __func__,
                          handle, strerror(err));
-               SetLastError (_wapi_get_win32_file_error (err));
+               mono_w32error_set_last (mono_w32error_unix_to_win32 (err));
                return(FALSE);
        }
                
@@ -1157,7 +1156,7 @@ file_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byt
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -1171,7 +1170,7 @@ file_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byt
           !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
@@ -1233,7 +1232,7 @@ static gboolean file_flush(gpointer handle)
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -1243,7 +1242,7 @@ static gboolean file_flush(gpointer handle)
           !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
 
@@ -1273,7 +1272,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(INVALID_SET_FILE_POINTER);
        }
        
@@ -1284,7 +1283,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
           !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(INVALID_SET_FILE_POINTER);
        }
 
@@ -1301,7 +1300,7 @@ static guint32 file_seek(gpointer handle, gint32 movedistance,
        default:
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: invalid seek type %d", __func__, method);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(INVALID_SET_FILE_POINTER);
        }
 
@@ -1371,7 +1370,7 @@ static gboolean file_setendoffile(gpointer handle)
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = file_handle->fd;
@@ -1380,7 +1379,7 @@ static gboolean file_setendoffile(gpointer handle)
           !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
 
@@ -1481,7 +1480,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(INVALID_FILE_SIZE);
        }
        fd = file_handle->fd;
@@ -1491,7 +1490,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
           !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(INVALID_FILE_SIZE);
        }
 
@@ -1499,7 +1498,7 @@ static guint32 file_getfilesize(gpointer handle, guint32 *highsize)
         * caller can't tell if this is an error, so clear the error
         * value
         */
-       SetLastError (ERROR_SUCCESS);
+       mono_w32error_set_last (ERROR_SUCCESS);
        
        ret = fstat(fd, &statbuf);
        if (ret == -1) {
@@ -1567,7 +1566,7 @@ static gboolean file_getfiletime(gpointer handle, FILETIME *create_time,
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = file_handle->fd;
@@ -1577,7 +1576,7 @@ static gboolean file_getfiletime(gpointer handle, FILETIME *create_time,
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u",
                          __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
@@ -1649,7 +1648,7 @@ static gboolean file_setfiletime(gpointer handle,
        if(ok==FALSE) {
                g_warning ("%s: error looking up file handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = file_handle->fd;
@@ -1658,14 +1657,14 @@ static gboolean file_setfiletime(gpointer handle,
           !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
 
        if(file_handle->filename == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p unknown filename", __func__, handle);
 
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -1677,7 +1676,7 @@ static gboolean file_setfiletime(gpointer handle,
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p fstat failed: %s", __func__, handle,
                          strerror(errno));
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
 
@@ -1690,14 +1689,14 @@ static gboolean file_setfiletime(gpointer handle,
                if (access_ticks < 116444736000000000ULL) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set access time too early",
                                   __func__);
-                       SetLastError (ERROR_INVALID_PARAMETER);
+                       mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                        return(FALSE);
                }
 
                if (sizeof (utbuf.actime) == 4 && ((access_ticks - 116444736000000000ULL) / 10000000) > INT_MAX) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time that is too big for a 32bits time_t",
                                   __func__);
-                       SetLastError (ERROR_INVALID_PARAMETER);
+                       mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                        return(FALSE);
                }
 
@@ -1715,13 +1714,13 @@ static gboolean file_setfiletime(gpointer handle,
                if (write_ticks < 116444736000000000ULL) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time too early",
                                   __func__);
-                       SetLastError (ERROR_INVALID_PARAMETER);
+                       mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                        return(FALSE);
                }
                if (sizeof (utbuf.modtime) == 4 && ((write_ticks - 116444736000000000ULL) / 10000000) > INT_MAX) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: attempt to set write time that is too big for a 32bits time_t",
                                   __func__);
-                       SetLastError (ERROR_INVALID_PARAMETER);
+                       mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                        return(FALSE);
                }
                
@@ -1738,7 +1737,7 @@ static gboolean file_setfiletime(gpointer handle,
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p [%s] utime failed: %s", __func__,
                           handle, file_handle->filename, strerror(errno));
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
        
@@ -1794,7 +1793,7 @@ console_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesr
        if(ok==FALSE) {
                g_warning ("%s: error looking up console handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = console_handle->fd;
@@ -1808,7 +1807,7 @@ console_read(gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesr
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u",
                           __func__, handle, console_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
@@ -1844,7 +1843,7 @@ console_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *
        if(ok==FALSE) {
                g_warning ("%s: error looking up console handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = console_handle->fd;
@@ -1857,7 +1856,7 @@ console_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *
           !(console_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, console_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
@@ -1943,7 +1942,7 @@ pipe_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesrea
        if(ok==FALSE) {
                g_warning ("%s: error looking up pipe handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = pipe_handle->fd;
@@ -1957,7 +1956,7 @@ pipe_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *bytesrea
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ access: %u",
                          __func__, handle, pipe_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
@@ -2003,7 +2002,7 @@ pipe_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byt
        if(ok==FALSE) {
                g_warning ("%s: error looking up pipe handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        fd = pipe_handle->fd;
@@ -2016,7 +2015,7 @@ pipe_write(gpointer handle, gconstpointer buffer, guint32 numbytes, guint32 *byt
           !(pipe_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, pipe_handle->fileaccess);
 
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return(FALSE);
        }
        
@@ -2220,14 +2219,14 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
                perms = 0600;
        
        if (attrs & FILE_ATTRIBUTE_ENCRYPTED){
-               SetLastError (ERROR_ENCRYPTION_FAILED);
+               mono_w32error_set_last (ERROR_ENCRYPTION_FAILED);
                return INVALID_HANDLE_VALUE;
        }
        
        if (name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(INVALID_HANDLE_VALUE);
        }
 
@@ -2235,7 +2234,7 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
        if (filename == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(INVALID_HANDLE_VALUE);
        }
        
@@ -2270,7 +2269,7 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
        if (fd >= mono_w32handle_fd_reserve) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__);
 
-               SetLastError (ERROR_TOO_MANY_OPEN_FILES);
+               mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
                
                close (fd);
                g_free (filename);
@@ -2298,7 +2297,7 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
 
        if (share_allows_open (&statbuf, sharemode, fileaccess,
                         &file_handle.share_info) == FALSE) {
-               SetLastError (ERROR_SHARING_VIOLATION);
+               mono_w32error_set_last (ERROR_SHARING_VIOLATION);
                g_free (filename);
                close (fd);
                
@@ -2308,7 +2307,7 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
                /* No space, so no more files can be opened */
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: No space in the share table", __func__);
 
-               SetLastError (ERROR_TOO_MANY_OPEN_FILES);
+               mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
                close (fd);
                g_free (filename);
                
@@ -2355,7 +2354,7 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
                g_free (filename);
                close (fd);
                
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                return(INVALID_HANDLE_VALUE);
        }
        
@@ -2364,6 +2363,12 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
        return(handle);
 }
 
+gboolean
+mono_w32file_close (gpointer handle)
+{
+       return mono_w32handle_close (handle);
+}
+
 gboolean mono_w32file_delete(const gunichar2 *name)
 {
        gchar *filename;
@@ -2378,7 +2383,7 @@ gboolean mono_w32file_delete(const gunichar2 *name)
        if(name==NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -2386,7 +2391,7 @@ gboolean mono_w32file_delete(const gunichar2 *name)
        if(filename==NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -2414,7 +2419,7 @@ gboolean mono_w32file_delete(const gunichar2 *name)
        
        if (share_allows_open (&statbuf, 0, GENERIC_WRITE,
                               &shareinfo) == FALSE) {
-               SetLastError (ERROR_SHARING_VIOLATION);
+               mono_w32error_set_last (ERROR_SHARING_VIOLATION);
                g_free (filename);
                return FALSE;
        }
@@ -2447,7 +2452,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
        if(name==NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -2455,7 +2460,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
        if (utf8_name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
                
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return FALSE;
        }
        
@@ -2463,7 +2468,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
                g_free (utf8_name);
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -2472,7 +2477,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
                g_free (utf8_name);
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return FALSE;
        }
 
@@ -2495,7 +2500,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
                    stat_dest.st_ino != stat_src.st_ino) {
                        g_free (utf8_name);
                        g_free (utf8_dest_name);
-                       SetLastError (ERROR_ALREADY_EXISTS);
+                       mono_w32error_set_last (ERROR_ALREADY_EXISTS);
                        return FALSE;
                }
        }
@@ -2508,7 +2513,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
         * then we can implement that later.
         */
        if (share_allows_delete (&stat_src, &shareinfo) == FALSE) {
-               SetLastError (ERROR_SHARING_VIOLATION);
+               mono_w32error_set_last (ERROR_SHARING_VIOLATION);
                return FALSE;
        }
        if (shareinfo)
@@ -2520,7 +2525,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
        if (result == -1) {
                switch(errno_copy) {
                case EEXIST:
-                       SetLastError (ERROR_ALREADY_EXISTS);
+                       mono_w32error_set_last (ERROR_ALREADY_EXISTS);
                        break;
 
                case EXDEV:
@@ -2544,7 +2549,7 @@ MoveFile (gunichar2 *name, gunichar2 *dest_name)
                gint32 copy_error;
 
                if (S_ISDIR (stat_src.st_mode)) {
-                       SetLastError (ERROR_NOT_SAME_DEVICE);
+                       mono_w32error_set_last (ERROR_NOT_SAME_DEVICE);
                        return FALSE;
                }
                /* Try a copy to the new location, and delete the source */
@@ -2625,7 +2630,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
        if(name==NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
        
@@ -2634,7 +2639,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of source returned NULL",
                           __func__);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
        
@@ -2642,7 +2647,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: dest is NULL", __func__);
 
                g_free (utf8_src);
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
        
@@ -2651,7 +2656,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of dest returned NULL",
                           __func__);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
 
                g_free (utf8_src);
                
@@ -2688,7 +2693,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
                g_free (utf8_dest);
                close (src_fd);
 
-               SetLastError (ERROR_SHARING_VIOLATION);
+               mono_w32error_set_last (ERROR_SHARING_VIOLATION);
                return (FALSE);
        }
        
@@ -2696,7 +2701,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
                dest_fd = _wapi_open (utf8_dest, O_WRONLY | O_CREAT | O_EXCL, st.st_mode);
        } else {
                /* FIXME: it kinda sucks that this code path potentially scans
-                * the directory twice due to the weird SetLastError()
+                * the directory twice due to the weird mono_w32error_set_last()
                 * behavior. */
                dest_fd = _wapi_open (utf8_dest, O_WRONLY | O_TRUNC, st.st_mode);
                if (dest_fd < 0) {
@@ -2706,7 +2711,7 @@ CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_ex
                        /* Apparently this error is set if we
                         * overwrite the dest file
                         */
-                       SetLastError (ERROR_ALREADY_EXISTS);
+                       mono_w32error_set_last (ERROR_ALREADY_EXISTS);
                }
        }
        if (dest_fd < 0) {
@@ -2744,7 +2749,7 @@ convert_arg_to_utf8 (const gunichar2 *arg, const gchar *arg_name)
 
        if (arg == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: %s is NULL", __func__, arg_name);
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return NULL;
        }
 
@@ -2752,7 +2757,7 @@ convert_arg_to_utf8 (const gunichar2 *arg, const gchar *arg_name)
        if (utf8_ret == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion of %s returned NULL",
                           __func__, arg_name);
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return NULL;
        }
 
@@ -2837,7 +2842,7 @@ _wapi_stdhandle_create (gint fd, const gchar *name)
                 */
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl error on fd %d: %s", __func__, fd, strerror(errno));
 
-               SetLastError (_wapi_get_win32_file_error (errno));
+               mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
                return INVALID_HANDLE_VALUE;
        }
 
@@ -2881,7 +2886,7 @@ _wapi_stdhandle_create (gint fd, const gchar *name)
        handle = mono_w32handle_new_fd (MONO_W32HANDLE_CONSOLE, fd, &file_handle);
        if (handle == INVALID_HANDLE_VALUE) {
                g_warning ("%s: error creating file handle", __func__);
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                return INVALID_HANDLE_VALUE;
        }
 
@@ -2936,7 +2941,7 @@ mono_w32file_get_std_handle (gint stdhandle)
                handle = _wapi_stdhandle_create (fd, name);
                
                if (handle == INVALID_HANDLE_VALUE) {
-                       SetLastError (ERROR_NO_MORE_FILES);
+                       mono_w32error_set_last (ERROR_NO_MORE_FILES);
                        goto done;
                }
        } else {
@@ -2958,7 +2963,7 @@ mono_w32file_read (gpointer handle, gpointer buffer, guint32 numbytes, guint32 *
        type = mono_w32handle_get_type (handle);
        
        if(io_ops[type].readfile==NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -2973,7 +2978,7 @@ mono_w32file_write (gpointer handle, gconstpointer buffer, guint32 numbytes, gui
        type = mono_w32handle_get_type (handle);
        
        if(io_ops[type].writefile==NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -2988,7 +2993,7 @@ mono_w32file_flush (gpointer handle)
        type = mono_w32handle_get_type (handle);
        
        if(io_ops[type].flushfile==NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -3003,7 +3008,7 @@ mono_w32file_truncate (gpointer handle)
        type = mono_w32handle_get_type (handle);
        
        if (io_ops[type].setendoffile == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -3018,7 +3023,7 @@ mono_w32file_seek (gpointer handle, gint32 movedistance, gint32 *highmovedistanc
        type = mono_w32handle_get_type (handle);
        
        if (io_ops[type].seek == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(INVALID_SET_FILE_POINTER);
        }
        
@@ -3034,7 +3039,7 @@ mono_w32file_get_type(gpointer handle)
        type = mono_w32handle_get_type (handle);
        
        if (io_ops[type].getfiletype == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FILE_TYPE_UNKNOWN);
        }
        
@@ -3049,7 +3054,7 @@ GetFileSize(gpointer handle, guint32 *highsize)
        type = mono_w32handle_get_type (handle);
        
        if (io_ops[type].getfilesize == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(INVALID_FILE_SIZE);
        }
        
@@ -3064,7 +3069,7 @@ mono_w32file_get_times(gpointer handle, FILETIME *create_time, FILETIME *access_
        type = mono_w32handle_get_type (handle);
        
        if (io_ops[type].getfiletime == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -3080,7 +3085,7 @@ mono_w32file_set_times(gpointer handle, const FILETIME *create_time, const FILET
        type = mono_w32handle_get_type (handle);
        
        if (io_ops[type].setfiletime == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -3114,7 +3119,7 @@ mono_w32file_filetime_to_systemtime(const FILETIME *file_time, SYSTEMTIME *syste
        if(system_time==NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: system_time NULL", __func__);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
        
@@ -3128,7 +3133,7 @@ mono_w32file_filetime_to_systemtime(const FILETIME *file_time, SYSTEMTIME *syste
        if(file_ticks<0) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: file_time too big", __func__);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
 
@@ -3215,7 +3220,7 @@ mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
        if (pattern == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: pattern is NULL", __func__);
 
-               SetLastError (ERROR_PATH_NOT_FOUND);
+               mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
                return(INVALID_HANDLE_VALUE);
        }
 
@@ -3223,7 +3228,7 @@ mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
        if (utf8_pattern == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
                
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(INVALID_HANDLE_VALUE);
        }
 
@@ -3239,7 +3244,7 @@ mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
         * FIXME: Figure out a better solution to keep some checks...
         */
        if (strchr (dir_part, '*') || strchr (dir_part, '?')) {
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                g_free (dir_part);
                g_free (entry_part);
                g_free (utf8_pattern);
@@ -3275,7 +3280,7 @@ mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
                /* No files, which windows seems to call
                 * FILE_NOT_FOUND
                 */
-               SetLastError (ERROR_FILE_NOT_FOUND);
+               mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
                g_free (utf8_pattern);
                g_free (entry_part);
                g_free (dir_part);
@@ -3306,7 +3311,7 @@ mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
                g_free (dir_part);
                g_free (entry_part);
                g_free (utf8_pattern);
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                
                return(INVALID_HANDLE_VALUE);
        }
@@ -3314,7 +3319,7 @@ mono_w32file_find_first (const gunichar2 *pattern, WIN32_FIND_DATA *find_data)
        if (handle != INVALID_HANDLE_VALUE &&
            !mono_w32file_find_next (handle, find_data)) {
                mono_w32file_find_close (handle);
-               SetLastError (ERROR_NO_MORE_FILES);
+               mono_w32error_set_last (ERROR_NO_MORE_FILES);
                handle = INVALID_HANDLE_VALUE;
        }
 
@@ -3340,7 +3345,7 @@ mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data)
        if(ok==FALSE) {
                g_warning ("%s: error looking up find handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -3348,7 +3353,7 @@ mono_w32file_find_next (gpointer handle, WIN32_FIND_DATA *find_data)
        
 retry:
        if (find_handle->count >= find_handle->num) {
-               SetLastError (ERROR_NO_MORE_FILES);
+               mono_w32error_set_last (ERROR_NO_MORE_FILES);
                goto cleanup;
        }
 
@@ -3462,7 +3467,7 @@ mono_w32file_find_close (gpointer handle)
        gboolean ok;
 
        if (handle == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
        
@@ -3471,7 +3476,7 @@ mono_w32file_find_close (gpointer handle)
        if(ok==FALSE) {
                g_warning ("%s: error looking up find handle %p", __func__,
                           handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return(FALSE);
        }
 
@@ -3496,7 +3501,7 @@ mono_w32file_create_directory (const gunichar2 *name)
        if (name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
        
@@ -3504,7 +3509,7 @@ mono_w32file_create_directory (const gunichar2 *name)
        if (utf8_name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
        
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return FALSE;
        }
 
@@ -3529,7 +3534,7 @@ mono_w32file_remove_directory (const gunichar2 *name)
        if (name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -3537,7 +3542,7 @@ mono_w32file_remove_directory (const gunichar2 *name)
        if (utf8_name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
                
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return FALSE;
        }
 
@@ -3564,7 +3569,7 @@ mono_w32file_get_attributes (const gunichar2 *name)
        if (name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
        
@@ -3572,7 +3577,7 @@ mono_w32file_get_attributes (const gunichar2 *name)
        if (utf8_name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return (INVALID_FILE_ATTRIBUTES);
        }
 
@@ -3619,7 +3624,7 @@ mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat)
        if (name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -3627,7 +3632,7 @@ mono_w32file_get_attributes_ex (const gunichar2 *name, MonoIOStat *stat)
        if (utf8_name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return FALSE;
        }
 
@@ -3678,7 +3683,7 @@ mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
        if (name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: name is NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(FALSE);
        }
 
@@ -3686,7 +3691,7 @@ mono_w32file_set_attributes (const gunichar2 *name, guint32 attrs)
        if (utf8_name == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return FALSE;
        }
 
@@ -3785,7 +3790,7 @@ mono_w32file_set_cwd (const gunichar2 *path)
        gboolean result;
 
        if (path == NULL) {
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return(FALSE);
        }
        
@@ -3826,7 +3831,7 @@ mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
            filedes[1] >= mono_w32handle_fd_reserve) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__);
 
-               SetLastError (ERROR_TOO_MANY_OPEN_FILES);
+               mono_w32error_set_last (ERROR_TOO_MANY_OPEN_FILES);
                
                close (filedes[0]);
                close (filedes[1]);
@@ -3844,7 +3849,7 @@ mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
                g_warning ("%s: error creating pipe read handle", __func__);
                close (filedes[0]);
                close (filedes[1]);
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                
                return(FALSE);
        }
@@ -3859,7 +3864,7 @@ mono_w32file_create_pipe (gpointer *readpipe, gpointer *writepipe, guint32 size)
                
                close (filedes[0]);
                close (filedes[1]);
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                
                return(FALSE);
        }
@@ -4338,7 +4343,7 @@ mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_byte
        if (path_name == NULL) {
                utf8_path_name = g_strdup (g_get_current_dir());
                if (utf8_path_name == NULL) {
-                       SetLastError (ERROR_DIRECTORY);
+                       mono_w32error_set_last (ERROR_DIRECTORY);
                        return(FALSE);
                }
        }
@@ -4347,7 +4352,7 @@ mono_w32file_get_disk_free_space (const gunichar2 *path_name, guint64 *free_byte
                if (utf8_path_name == NULL) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-                       SetLastError (ERROR_INVALID_NAME);
+                       mono_w32error_set_last (ERROR_INVALID_NAME);
                        return(FALSE);
                }
        }
@@ -4745,13 +4750,13 @@ LockFile (gpointer handle, guint32 offset_low, guint32 offset_high, guint32 leng
 
        if (!mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle)) {
                g_warning ("%s: error looking up file handle %p", __func__, handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
        if (!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return FALSE;
        }
 
@@ -4762,7 +4767,7 @@ LockFile (gpointer handle, guint32 offset_low, guint32 offset_high, guint32 leng
        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Locking handle %p, offset %lld, length %lld", __func__, handle, offset, length);
 #else
        if (offset_high > 0 || length_high > 0) {
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return FALSE;
        }
        offset = offset_low;
@@ -4782,13 +4787,13 @@ UnlockFile (gpointer handle, guint32 offset_low, guint32 offset_high, guint32 le
 
        if (!mono_w32handle_lookup (handle, MONO_W32HANDLE_FILE, (gpointer *)&file_handle)) {
                g_warning ("%s: error looking up file handle %p", __func__, handle);
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
        if (!(file_handle->fileaccess & GENERIC_READ) && !(file_handle->fileaccess & GENERIC_WRITE) && !(file_handle->fileaccess & GENERIC_ALL)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: handle %p doesn't have GENERIC_READ or GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
-               SetLastError (ERROR_ACCESS_DENIED);
+               mono_w32error_set_last (ERROR_ACCESS_DENIED);
                return FALSE;
        }
 
@@ -4845,7 +4850,7 @@ mono_w32file_move (gunichar2 *path, gunichar2 *dest, gint32 *error)
 
        result = MoveFile (path, dest);
        if (!result)
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
 
        MONO_EXIT_GC_SAFE;
 
@@ -4861,7 +4866,7 @@ mono_w32file_copy (gunichar2 *path, gunichar2 *dest, gboolean overwrite, gint32
 
        result = CopyFile (path, dest, !overwrite);
        if (!result)
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
 
        MONO_EXIT_GC_SAFE;
 
@@ -4877,7 +4882,7 @@ mono_w32file_replace (gunichar2 *destinationFileName, gunichar2 *sourceFileName,
 
        result = ReplaceFile (destinationFileName, sourceFileName, destinationBackupFileName, flags, NULL, NULL);
        if (!result)
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
 
        MONO_EXIT_GC_SAFE;
 
@@ -4894,7 +4899,7 @@ mono_w32file_get_file_size (gpointer handle, gint32 *error)
 
        length = GetFileSize (handle, &length_hi);
        if(length==INVALID_FILE_SIZE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
 
        MONO_EXIT_GC_SAFE;
@@ -4911,7 +4916,7 @@ mono_w32file_lock (gpointer handle, gint64 position, gint64 length, gint32 *erro
 
        result = LockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
        if (!result)
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
 
        MONO_EXIT_GC_SAFE;
 
@@ -4927,7 +4932,7 @@ mono_w32file_unlock (gpointer handle, gint64 position, gint64 length, gint32 *er
 
        result = UnlockFile (handle, position & 0xFFFFFFFF, position >> 32, length & 0xFFFFFFFF, length >> 32);
        if (!result)
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
 
        MONO_EXIT_GC_SAFE;
 
index 7a5478cf2e55b31c314bb05fc8b25c57e27208fb..953f7926c76a72175b3fef48d6eee9f0efbb344a 100644 (file)
@@ -56,6 +56,12 @@ mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode
        return CreateFile (name, fileaccess, sharemode, NULL, createmode, attrs, NULL);
 }
 
+gboolean
+mono_w32file_close (gpointer handle)
+{
+       return CloseHandle (handle);
+}
+
 gboolean
 mono_w32file_delete (const gunichar2 *name)
 {
index 8aabbc57537b5ff43a0ce55a56ece6b6628f00ad..d24506afd4ee1a71b1a8096c1f6f790e466d9412 100644 (file)
@@ -27,8 +27,8 @@
 #endif
 
 #include <mono/metadata/object.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/w32file.h>
+#include <mono/metadata/w32error.h>
 #include <mono/metadata/w32file-internals.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/appdomain.h>
@@ -36,6 +36,7 @@
 #include <mono/utils/strenc.h>
 #include <utils/mono-io-portability.h>
 #include <mono/metadata/w32handle.h>
+#include <mono/utils/w32api.h>
 
 #undef DEBUG
 
@@ -205,7 +206,7 @@ get_file_attributes (const gunichar2 *path)
        if (res != -1)
                return res;
 
-       error = GetLastError ();
+       error = mono_w32error_get_last ();
 
        if (error != ERROR_SHARING_VIOLATION)
                return res;
@@ -232,7 +233,7 @@ get_file_attributes_ex (const gunichar2 *path, MonoIOStat *stat)
        if (res)
                return TRUE;
 
-       error = GetLastError ();
+       error = mono_w32error_get_last ();
        if (error != ERROR_SHARING_VIOLATION)
                return FALSE;
 
@@ -263,7 +264,7 @@ ves_icall_System_IO_MonoIO_CreateDirectory (MonoString *path, gint32 *error)
        
        ret=mono_w32file_create_directory (mono_string_chars (path));
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
 
        MONO_EXIT_GC_SAFE;
@@ -280,7 +281,7 @@ ves_icall_System_IO_MonoIO_RemoveDirectory (MonoString *path, gint32 *error)
        
        ret=mono_w32file_remove_directory (mono_string_chars (path));
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
 
        MONO_EXIT_GC_SAFE;
@@ -320,13 +321,13 @@ get_filesystem_entries (const gunichar2 *path,
                        goto fail;
                }
        } else {
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
                goto fail;
        }
        
        find_handle = mono_w32file_find_first (path_with_pattern, &data);
        if (find_handle == INVALID_HANDLE_VALUE) {
-               gint32 find_error = GetLastError ();
+               gint32 find_error = mono_w32error_get_last ();
                
                if (find_error == ERROR_FILE_NOT_FOUND || find_error == ERROR_NO_MORE_FILES) {
                        /* No files, so just return an empty array */
@@ -360,7 +361,7 @@ get_filesystem_entries (const gunichar2 *path,
        } while(mono_w32file_find_next (find_handle, &data));
 
        if (mono_w32file_find_close (find_handle) == FALSE) {
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
                goto fail;
        }
 
@@ -456,7 +457,7 @@ ves_icall_System_IO_MonoIO_FindFirstFile (MonoString *path_with_pattern, MonoStr
        if (hnd == INVALID_HANDLE_VALUE) {
                *file_name = NULL;
                *file_attr = 0;
-               *ioerror = GetLastError ();
+               *ioerror = mono_w32error_get_last ();
                return hnd;
        }
 
@@ -481,7 +482,7 @@ ves_icall_System_IO_MonoIO_FindNextFile (HANDLE hnd, MonoString **file_name, gin
        if (res == FALSE) {
                *file_name = NULL;
                *file_attr = 0;
-               *ioerror = GetLastError ();
+               *ioerror = mono_w32error_get_last ();
                return res;
        }
 
@@ -518,7 +519,7 @@ ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
        find_handle = mono_w32file_find_first (mono_string_chars (path_with_pattern), &data);
        
        if (find_handle == INVALID_HANDLE_VALUE) {
-               gint32 find_error = GetLastError ();
+               gint32 find_error = mono_w32error_get_last ();
                *handle = NULL;
                
                if (find_error == ERROR_FILE_NOT_FOUND) 
@@ -543,7 +544,7 @@ ves_icall_System_IO_MonoIO_FindFirst (MonoString *path,
 
        while (incremental_find_check_match (ifh, &data, &result) == 0){
                if (mono_w32file_find_next (find_handle, &data) == FALSE){
-                       int e = GetLastError ();
+                       int e = mono_w32error_get_last ();
                        if (e != ERROR_NO_MORE_FILES)
                                *ioerror = e;
                        return NULL;
@@ -565,7 +566,7 @@ ves_icall_System_IO_MonoIO_FindNext (gpointer handle, gint32 *result_attr, gint3
        *error = ERROR_SUCCESS;
        do {
                if (mono_w32file_find_next (ifh->find_handle, &data) == FALSE){
-                       int e = GetLastError ();
+                       int e = mono_w32error_get_last ();
                        if (e != ERROR_NO_MORE_FILES)
                                *error = e;
                        return NULL;
@@ -584,7 +585,7 @@ ves_icall_System_IO_MonoIO_FindClose (gpointer handle)
 
        MONO_ENTER_GC_SAFE;
        if (mono_w32file_find_close (ifh->find_handle) == FALSE){
-               error = GetLastError ();
+               error = mono_w32error_get_last ();
        } else
                error = ERROR_SUCCESS;
        g_free (ifh->utf8_path);
@@ -624,7 +625,7 @@ ves_icall_System_IO_MonoIO_GetCurrentDirectory (gint32 *io_error)
 
                result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
        } else {
-               *io_error=GetLastError ();
+               *io_error=mono_w32error_get_last ();
        }
 
        g_free (buf);
@@ -642,7 +643,7 @@ ves_icall_System_IO_MonoIO_SetCurrentDirectory (MonoString *path,
        
        ret=mono_w32file_set_cwd (mono_string_chars (path));
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
        
        return(ret);
@@ -697,7 +698,7 @@ ves_icall_System_IO_MonoIO_DeleteFile (MonoString *path, gint32 *error)
        
        ret=mono_w32file_delete (mono_string_chars (path));
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
        
        MONO_EXIT_GC_SAFE;
@@ -722,7 +723,7 @@ ves_icall_System_IO_MonoIO_GetFileAttributes (MonoString *path, gint32 *error)
         */
        if (ret==-1) {
          /* if(ret==INVALID_FILE_ATTRIBUTES) { */
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
        
        MONO_EXIT_GC_SAFE;
@@ -741,7 +742,7 @@ ves_icall_System_IO_MonoIO_SetFileAttributes (MonoString *path, gint32 attrs,
        ret=mono_w32file_set_attributes (mono_string_chars (path),
                convert_attrs ((MonoFileAttributes)attrs));
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
 
        MONO_EXIT_GC_SAFE;
@@ -761,7 +762,7 @@ ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
                /* Not necessarily an error, but the caller will have
                 * to decide based on the error value.
                 */
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
        
        MONO_EXIT_GC_SAFE;
@@ -779,7 +780,7 @@ ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat, gint
        result = get_file_attributes_ex (mono_string_chars (path), stat);
 
        if (!result) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                memset (stat, 0, sizeof (MonoIOStat));
        }
 
@@ -831,7 +832,7 @@ ves_icall_System_IO_MonoIO_Open (MonoString *filename, gint32 mode,
        
        ret=mono_w32file_create (chars, convert_access ((MonoFileAccess)access_mode), convert_share ((MonoFileShare)share), convert_mode ((MonoFileMode)mode), attributes);
        if(ret==INVALID_HANDLE_VALUE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        } 
        
        MONO_EXIT_GC_SAFE;
@@ -846,9 +847,9 @@ ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error)
 
        *error=ERROR_SUCCESS;
        
-       ret=CloseHandle (handle);
+       ret=mono_w32file_close (handle);
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
        
        MONO_EXIT_GC_SAFE;
@@ -880,7 +881,7 @@ ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
        MONO_EXIT_GC_SAFE;
 
        if (!result) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                return -1;
        }
 
@@ -911,7 +912,7 @@ ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
        MONO_EXIT_GC_SAFE;
 
        if (!result) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                return -1;
        }
 
@@ -932,7 +933,7 @@ ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
                                 convert_seekorigin ((MonoSeekOrigin)origin));
 
        if(offset==INVALID_SET_FILE_POINTER) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
 
        MONO_EXIT_GC_SAFE;
@@ -949,7 +950,7 @@ ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
        
        ret=mono_w32file_flush (handle);
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
        
        MONO_EXIT_GC_SAFE;
@@ -980,7 +981,7 @@ ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
        offset_hi = 0;
        offset = mono_w32file_seek (handle, 0, &offset_hi, FILE_CURRENT);
        if(offset==INVALID_SET_FILE_POINTER) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                return(FALSE);
        }
 
@@ -990,13 +991,13 @@ ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
        offset_set=mono_w32file_seek (handle, length & 0xFFFFFFFF, &length_hi,
                                   FILE_BEGIN);
        if(offset_set==INVALID_SET_FILE_POINTER) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                return(FALSE);
        }
 
        result = mono_w32file_truncate (handle);
        if(result==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                return(FALSE);
        }
 
@@ -1005,7 +1006,7 @@ ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
        offset_set=mono_w32file_seek (handle, offset & 0xFFFFFFFF, &offset_hi,
                                   FILE_BEGIN);
        if(offset_set==INVALID_SET_FILE_POINTER) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
                return(FALSE);
        }
 
@@ -1042,7 +1043,7 @@ ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
 
        ret=mono_w32file_set_times (handle, creation_filetime, access_filetime, write_filetime);
        if(ret==FALSE) {
-               *error=GetLastError ();
+               *error=mono_w32error_get_last ();
        }
 
        MONO_EXIT_GC_SAFE;
@@ -1077,7 +1078,7 @@ ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle
        MONO_EXIT_GC_SAFE;
 
        if(ret==FALSE) {
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
                /* FIXME: throw an exception? */
                return(FALSE);
        }
@@ -1103,7 +1104,7 @@ ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE
        MONO_EXIT_GC_SAFE;
 
        if(ret==FALSE) {
-               *error = GetLastError ();
+               *error = mono_w32error_get_last ();
                /* FIXME: throw an exception? */
                return(FALSE);
        }
index 05bfe9fc9293ed9238d837559d2f827dc7cdfaca..b2cf4f63c0c9b24d801b5229fe74b91d1bddf2f2 100644 (file)
@@ -16,7 +16,6 @@
 #include <config.h>
 #include <glib.h>
 
-#include "io-layer/io-layer.h"
 #include <mono/metadata/object-internals.h>
 #include <mono/utils/mono-compiler.h>
 
@@ -390,6 +389,9 @@ mono_w32file_cleanup (void);
 gpointer
 mono_w32file_create(const gunichar2 *name, guint32 fileaccess, guint32 sharemode, guint32 createmode, guint32 attrs);
 
+gboolean
+mono_w32file_close (gpointer handle);
+
 gboolean
 mono_w32file_delete (const gunichar2 *name);
 
index 2eb2145533b6d804c6e285cc7848803e38e1e8cf..2441f9526185f088956b540e4c010174d26b72e1 100644 (file)
@@ -16,7 +16,6 @@
 #include "w32mutex.h"
 #include "w32semaphore.h"
 #include "w32event.h"
-#include "mono/io-layer/io-layer.h"
 #include "mono/utils/mono-logger-internals.h"
 #include "mono/utils/mono-coop-mutex.h"
 
index 248bf1b316f00a7920a2f7618d15fe152b5af99b..7563c2cd7f0935936def6bc6bc0fa0aea1344947 100644 (file)
@@ -249,11 +249,6 @@ mono_w32handle_unlock_handle (gpointer handle)
        mono_w32handle_unref (handle);
 }
 
-/*
- * mono_w32handle_init:
- *
- *   Initialize the io-layer.
- */
 void
 mono_w32handle_init (void)
 {
@@ -482,6 +477,24 @@ gpointer mono_w32handle_new_fd (MonoW32HandleType type, int fd,
        return(GUINT_TO_POINTER(fd));
 }
 
+gboolean
+mono_w32handle_close (gpointer handle)
+{
+       if (handle == INVALID_HANDLE_VALUE)
+               return FALSE;
+       if (handle == (gpointer) 0 && mono_w32handle_get_type (handle) != MONO_W32HANDLE_CONSOLE) {
+               /* Problem: because we map file descriptors to the
+                * same-numbered handle we can't tell the difference
+                * between a bogus handle and the handle to stdin.
+                * Assume that it's the console handle if that handle
+                * exists... */
+               return FALSE;
+       }
+
+       mono_w32handle_unref (handle);
+       return TRUE;
+}
+
 gboolean
 mono_w32handle_lookup (gpointer handle, MonoW32HandleType type,
                              gpointer *handle_specific)
index db536d40805d17767439c3e886a92d14adb80ef4..f3f546c10a98626a934696e3868b5dd91ef2afe0 100644 (file)
@@ -113,6 +113,9 @@ mono_w32handle_new (MonoW32HandleType type, gpointer handle_specific);
 gpointer
 mono_w32handle_new_fd (MonoW32HandleType type, int fd, gpointer handle_specific);
 
+gboolean
+mono_w32handle_close (gpointer handle);
+
 MonoW32HandleType
 mono_w32handle_get_type (gpointer handle);
 
index faf8ac6eea97da61a84fa9d36b6c5c3051ee6782..acde96a791b5de5568b91fce5bfe00edeb9c76d0 100644 (file)
@@ -11,8 +11,8 @@
 
 #include <pthread.h>
 
+#include "w32error.h"
 #include "w32handle-namespace.h"
-#include "mono/io-layer/io-layer.h"
 #include "mono/metadata/object-internals.h"
 #include "mono/utils/mono-logger-internals.h"
 #include "mono/utils/mono-threads.h"
@@ -276,7 +276,7 @@ static gpointer mutex_handle_create (MonoW32HandleMutex *mutex_handle, MonoW32Ha
        if (handle == INVALID_HANDLE_VALUE) {
                g_warning ("%s: error creating %s handle",
                        __func__, mono_w32handle_get_typename (type));
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                return NULL;
        }
 
@@ -320,10 +320,10 @@ static gpointer namedmutex_create (gboolean owned, const gunichar2 *name)
        if (handle == INVALID_HANDLE_VALUE) {
                /* The name has already been used for a different object. */
                handle = NULL;
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
        } else if (handle) {
                /* Not an error, but this is how the caller is informed that the mutex wasn't freshly created */
-               SetLastError (ERROR_ALREADY_EXISTS);
+               mono_w32error_set_last (ERROR_ALREADY_EXISTS);
 
                /* mono_w32handle_namespace_search_handle already adds a ref to the handle */
        } else {
@@ -353,14 +353,14 @@ ves_icall_System_Threading_Mutex_CreateMutex_internal (MonoBoolean owned, MonoSt
        /* Need to blow away any old errors here, because code tests
         * for ERROR_ALREADY_EXISTS on success (!) to see if a mutex
         * was freshly created */
-       SetLastError (ERROR_SUCCESS);
+       mono_w32error_set_last (ERROR_SUCCESS);
 
        if (!name) {
                mutex = mutex_create (owned);
        } else {
                mutex = namedmutex_create (owned, mono_string_chars (name));
 
-               if (GetLastError () == ERROR_ALREADY_EXISTS)
+               if (mono_w32error_get_last () == ERROR_ALREADY_EXISTS)
                        *created = FALSE;
        }
 
@@ -376,7 +376,7 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle)
        gboolean ret;
 
        if (handle == NULL) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
@@ -385,7 +385,7 @@ ves_icall_System_Threading_Mutex_ReleaseMutex_internal (gpointer handle)
        case MONO_W32HANDLE_NAMEDMUTEX:
                break;
        default:
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
index e81b50a1acfebfd7e4ec759ecb0068639626b606..4b463886f7b067b6e9df464932cdb0e6ff41d766 100644 (file)
@@ -49,6 +49,7 @@
 #include <mono/metadata/w32process.h>
 #include <mono/metadata/w32process-internals.h>
 #include <mono/metadata/w32process-unix-internals.h>
+#include <mono/metadata/w32error.h>
 #include <mono/metadata/class.h>
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/object.h>
@@ -56,7 +57,6 @@
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/metadata-internals.h>
 #include <mono/metadata/exception.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/w32handle.h>
 #include <mono/metadata/w32file.h>
 #include <mono/utils/mono-membar.h>
@@ -70,6 +70,7 @@
 #include <mono/utils/mono-mmap.h>
 #include <mono/utils/strenc.h>
 #include <mono/utils/mono-io-portability.h>
+#include <mono/utils/w32api.h>
 
 #ifndef MAXPATHLEN
 #define MAXPATHLEN 242
@@ -554,6 +555,7 @@ static gchar *cli_launcher;
 static Process *processes;
 static mono_mutex_t processes_mutex;
 
+static pid_t current_pid;
 static gpointer current_process;
 
 static const gunichar2 utf16_space_bytes [2] = { 0x20, 0 };
@@ -844,8 +846,10 @@ mono_w32process_init (void)
        mono_w32handle_register_capabilities (MONO_W32HANDLE_PROCESS,
                (MonoW32HandleCapability)(MONO_W32HANDLE_CAP_WAIT | MONO_W32HANDLE_CAP_SPECIAL_WAIT));
 
+       current_pid = getpid ();
+
        memset (&process_handle, 0, sizeof (process_handle));
-       process_handle.pid = wapi_getpid ();
+       process_handle.pid = current_pid;
        process_set_defaults (&process_handle);
        process_set_name (&process_handle);
 
@@ -943,7 +947,7 @@ mono_w32process_get_pid (gpointer handle)
 
        res = mono_w32handle_lookup (handle, MONO_W32HANDLE_PROCESS, (gpointer*) &process_handle);
        if (!res) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return 0;
        }
 
@@ -1014,7 +1018,7 @@ ves_icall_System_Diagnostics_Process_GetProcess_internal (guint32 pid)
 
        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find pid %d", __func__, pid);
 
-       SetLastError (ERROR_PROC_NOT_FOUND);
+       mono_w32error_set_last (ERROR_PROC_NOT_FOUND);
        return NULL;
 }
 
@@ -1633,7 +1637,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL",
                                   __func__);
 
-                       SetLastError (ERROR_PATH_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
                }
 
@@ -1645,7 +1649,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                if (args == NULL) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-                       SetLastError (ERROR_PATH_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
                }
        }
@@ -1655,7 +1659,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                if (dir == NULL) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-                       SetLastError (ERROR_PATH_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
                }
 
@@ -1686,7 +1690,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Couldn't find executable %s",
                                           __func__, prog);
                                g_free (unquoted);
-                               SetLastError (ERROR_FILE_NOT_FOUND);
+                               mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
                                goto free_strings;
                        }
                } else {
@@ -1703,7 +1707,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Couldn't find executable %s",
                                           __func__, prog);
                                g_free (unquoted);
-                               SetLastError (ERROR_FILE_NOT_FOUND);
+                               mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
                                goto free_strings;
                        }
                }
@@ -1767,7 +1771,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                        /* Give up */
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Couldn't find what to exec", __func__);
 
-                       SetLastError (ERROR_PATH_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PATH_NOT_FOUND);
                        goto free_strings;
                }
 
@@ -1794,7 +1798,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Couldn't find executable %s",
                                           __func__, token);
                                g_free (token);
-                               SetLastError (ERROR_FILE_NOT_FOUND);
+                               mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
                                goto free_strings;
                        }
                } else {
@@ -1821,7 +1825,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Couldn't find executable %s", __func__, token);
 
                                        g_free (token);
-                                       SetLastError (ERROR_FILE_NOT_FOUND);
+                                       mono_w32error_set_last (ERROR_FILE_NOT_FOUND);
                                        goto free_strings;
                                }
                        }
@@ -1860,7 +1864,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
        } else {
                if (!is_executable (prog)) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Executable permisson not set on %s", __func__, prog);
-                       SetLastError (ERROR_ACCESS_DENIED);
+                       mono_w32error_set_last (ERROR_ACCESS_DENIED);
                        goto free_strings;
                }
        }
@@ -1956,7 +1960,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
 
        switch (pid = fork ()) {
        case -1: /* Error */ {
-               SetLastError (ERROR_OUTOFMEMORY);
+               mono_w32error_set_last (ERROR_OUTOFMEMORY);
                ret = FALSE;
                break;
        }
@@ -2027,7 +2031,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                        mono_os_sem_destroy (&process->exit_sem);
                        g_free (process);
 
-                       SetLastError (ERROR_OUTOFMEMORY);
+                       mono_w32error_set_last (ERROR_OUTOFMEMORY);
                        ret = FALSE;
                        break;
                }
@@ -2086,7 +2090,7 @@ free_strings:
 
        return ret;
 #else
-       SetLastError (ERROR_NOT_SUPPORTED);
+       mono_w32error_set_last (ERROR_NOT_SUPPORTED);
        return FALSE;
 #endif // defined (HAVE_FORK) && defined (HAVE_EXECVE)
 }
@@ -2118,14 +2122,14 @@ ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStar
         */
        args = utf16_concat (utf16_quote, lpFile, utf16_quote, lpParameters == NULL ? NULL : utf16_space, lpParameters, NULL);
        if (args == NULL) {
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                ret = FALSE;
                goto done;
        }
        ret = process_create (NULL, args, lpDirectory, NULL, process_info);
        g_free (args);
 
-       if (!ret && GetLastError () == ERROR_OUTOFMEMORY)
+       if (!ret && mono_w32error_get_last () == ERROR_OUTOFMEMORY)
                goto done;
 
        if (!ret) {
@@ -2175,26 +2179,26 @@ ves_icall_System_Diagnostics_Process_ShellExecuteEx_internal (MonoW32ProcessStar
                args = utf16_concat (handler_utf16, utf16_space, utf16_quote, lpFile, utf16_quote,
                        lpParameters == NULL ? NULL : utf16_space, lpParameters, NULL);
                if (args == NULL) {
-                       SetLastError (ERROR_INVALID_DATA);
+                       mono_w32error_set_last (ERROR_INVALID_DATA);
                        ret = FALSE;
                        goto done;
                }
                ret = process_create (NULL, args, lpDirectory, NULL, process_info);
                g_free (args);
                if (!ret) {
-                       if (GetLastError () != ERROR_OUTOFMEMORY)
-                               SetLastError (ERROR_INVALID_DATA);
+                       if (mono_w32error_get_last () != ERROR_OUTOFMEMORY)
+                               mono_w32error_set_last (ERROR_INVALID_DATA);
                        ret = FALSE;
                        goto done;
                }
                /* Shell exec should not return a process handle when it spawned a GUI thing, like a browser. */
-               CloseHandle (process_info->process_handle);
+               mono_w32handle_close (process_info->process_handle);
                process_info->process_handle = NULL;
        }
 
 done:
        if (ret == FALSE) {
-               process_info->pid = -GetLastError ();
+               process_info->pid = -mono_w32error_get_last ();
        } else {
                process_info->thread_handle = NULL;
 #if !defined(MONO_CROSS_COMPILE)
@@ -2290,7 +2294,7 @@ ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoW32ProcessStart
                g_free (shell_path);
 
        if (!ret)
-               process_info->pid = -GetLastError ();
+               process_info->pid = -mono_w32error_get_last ();
 
        return ret;
 }
@@ -2368,7 +2372,7 @@ ves_icall_Microsoft_Win32_NativeMethods_GetExitCodeProcess (gpointer handle, gin
                return FALSE;
        }
 
-       if (process_handle->pid == wapi_getpid ()) {
+       if (process_handle->pid == current_pid) {
                *exitcode = STILL_ACTIVE;
                return TRUE;
        }
@@ -2388,7 +2392,7 @@ ves_icall_Microsoft_Win32_NativeMethods_CloseProcess (gpointer handle)
 {
        if (WAPI_IS_PSEUDO_PROCESS_HANDLE (handle))
                return TRUE;
-       return CloseHandle (handle);
+       return mono_w32handle_close (handle);
 }
 
 MonoBoolean
@@ -2408,7 +2412,7 @@ ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess (gpointer handle, gint3
                res = mono_w32handle_lookup (handle, MONO_W32HANDLE_PROCESS, (gpointer*) &process_handle);
                if (!res) {
                        mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find process %p", __func__, handle);
-                       SetLastError (ERROR_INVALID_HANDLE);
+                       mono_w32error_set_last (ERROR_INVALID_HANDLE);
                        return FALSE;
                }
 
@@ -2420,10 +2424,10 @@ ves_icall_Microsoft_Win32_NativeMethods_TerminateProcess (gpointer handle, gint3
                return TRUE;
 
        switch (errno) {
-       case EINVAL: SetLastError (ERROR_INVALID_PARAMETER); break;
-       case EPERM:  SetLastError (ERROR_ACCESS_DENIED);     break;
-       case ESRCH:  SetLastError (ERROR_PROC_NOT_FOUND);    break;
-       default:     SetLastError (ERROR_GEN_FAILURE);       break;
+       case EINVAL: mono_w32error_set_last (ERROR_INVALID_PARAMETER); break;
+       case EPERM:  mono_w32error_set_last (ERROR_ACCESS_DENIED);     break;
+       case ESRCH:  mono_w32error_set_last (ERROR_PROC_NOT_FOUND);    break;
+       default:     mono_w32error_set_last (ERROR_GEN_FAILURE);       break;
        }
 
        return FALSE;
@@ -2491,7 +2495,7 @@ ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
 
                res = mono_w32handle_lookup (handle, MONO_W32HANDLE_PROCESS, (gpointer*) &process_handle);
                if (!res) {
-                       SetLastError (ERROR_INVALID_HANDLE);
+                       mono_w32error_set_last (ERROR_INVALID_HANDLE);
                        return 0;
                }
 
@@ -2504,13 +2508,13 @@ ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
                switch (errno) {
                case EPERM:
                case EACCES:
-                       SetLastError (ERROR_ACCESS_DENIED);
+                       mono_w32error_set_last (ERROR_ACCESS_DENIED);
                        break;
                case ESRCH:
-                       SetLastError (ERROR_PROC_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PROC_NOT_FOUND);
                        break;
                default:
-                       SetLastError (ERROR_GEN_FAILURE);
+                       mono_w32error_set_last (ERROR_GEN_FAILURE);
                }
                return 0;
        }
@@ -2530,7 +2534,7 @@ ves_icall_Microsoft_Win32_NativeMethods_GetPriorityClass (gpointer handle)
 
        return MONO_W32PROCESS_PRIORITY_CLASS_NORMAL;
 #else
-       SetLastError (ERROR_NOT_SUPPORTED);
+       mono_w32error_set_last (ERROR_NOT_SUPPORTED);
        return 0;
 #endif
 }
@@ -2552,7 +2556,7 @@ ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint3
 
                res = mono_w32handle_lookup (handle, MONO_W32HANDLE_PROCESS, (gpointer*) &process_handle);
                if (!res) {
-                       SetLastError (ERROR_INVALID_HANDLE);
+                       mono_w32error_set_last (ERROR_INVALID_HANDLE);
                        return FALSE;
                }
 
@@ -2579,7 +2583,7 @@ ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint3
                prio = -20;
                break;
        default:
-               SetLastError (ERROR_INVALID_PARAMETER);
+               mono_w32error_set_last (ERROR_INVALID_PARAMETER);
                return FALSE;
        }
 
@@ -2588,19 +2592,19 @@ ves_icall_Microsoft_Win32_NativeMethods_SetPriorityClass (gpointer handle, gint3
                switch (errno) {
                case EPERM:
                case EACCES:
-                       SetLastError (ERROR_ACCESS_DENIED);
+                       mono_w32error_set_last (ERROR_ACCESS_DENIED);
                        break;
                case ESRCH:
-                       SetLastError (ERROR_PROC_NOT_FOUND);
+                       mono_w32error_set_last (ERROR_PROC_NOT_FOUND);
                        break;
                default:
-                       SetLastError (ERROR_GEN_FAILURE);
+                       mono_w32error_set_last (ERROR_GEN_FAILURE);
                }
        }
 
        return ret == 0;
 #else
-       SetLastError (ERROR_NOT_SUPPORTED);
+       mono_w32error_set_last (ERROR_NOT_SUPPORTED);
        return FALSE;
 #endif
 }
@@ -2798,14 +2802,14 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Bad dos signature 0x%x", __func__, dos_header->e_magic);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
        if (map_size < sizeof(IMAGE_NT_HEADERS32) + GUINT32_FROM_LE (dos_header->e_lfanew)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File is too small: %d", __func__, map_size);
 
-               SetLastError (ERROR_BAD_LENGTH);
+               mono_w32error_set_last (ERROR_BAD_LENGTH);
                return(NULL);
        }
 
@@ -2813,7 +2817,7 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (nt_headers->Signature != IMAGE_NT_SIGNATURE) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Bad NT signature 0x%x", __func__, nt_headers->Signature);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
@@ -2827,7 +2831,7 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (resource_rva == 0) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: No resources in file!", __func__);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
@@ -2835,7 +2839,7 @@ find_pe_file_resources32 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (resource_dir == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find resource directory", __func__);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
@@ -2870,14 +2874,14 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Bad dos signature 0x%x", __func__, dos_header->e_magic);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
        if (map_size < sizeof(IMAGE_NT_HEADERS64) + GUINT32_FROM_LE (dos_header->e_lfanew)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File is too small: %d", __func__, map_size);
 
-               SetLastError (ERROR_BAD_LENGTH);
+               mono_w32error_set_last (ERROR_BAD_LENGTH);
                return(NULL);
        }
 
@@ -2886,7 +2890,7 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size, guint32 res_id, g
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Bad NT signature 0x%x", __func__,
                           nt_headers->Signature);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
@@ -2900,7 +2904,7 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (resource_rva == 0) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: No resources in file!", __func__);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
@@ -2908,7 +2912,7 @@ find_pe_file_resources64 (gpointer file_map, guint32 map_size, guint32 res_id, g
        if (resource_dir == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't find resource directory", __func__);
 
-               SetLastError (ERROR_INVALID_DATA);
+               mono_w32error_set_last (ERROR_INVALID_DATA);
                return(NULL);
        }
 
@@ -2959,7 +2963,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        if (filename_ext == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: unicode conversion returned NULL", __func__);
 
-               SetLastError (ERROR_INVALID_NAME);
+               mono_w32error_set_last (ERROR_INVALID_NAME);
                return(NULL);
        }
 
@@ -2978,7 +2982,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
 
                        g_free (filename_ext);
 
-                       SetLastError (_wapi_get_win32_file_error (errno));
+                       mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
                        return NULL;
                }
 
@@ -2989,7 +2993,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
                        g_free (filename_ext);
                        g_free (located_filename);
 
-                       SetLastError (_wapi_get_win32_file_error (errno));
+                       mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
                        return NULL;
                }
 
@@ -2999,7 +3003,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        if (fstat (fd, &statbuf) == -1) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error stat()ing file %s: %s", __func__, filename_ext, strerror (errno));
 
-               SetLastError (_wapi_get_win32_file_error (errno));
+               mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
                g_free (filename_ext);
                close (fd);
                return(NULL);
@@ -3010,7 +3014,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        if (statbuf.st_size < sizeof(IMAGE_DOS_HEADER)) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File %s is too small: %lld", __func__, filename_ext, statbuf.st_size);
 
-               SetLastError (ERROR_BAD_LENGTH);
+               mono_w32error_set_last (ERROR_BAD_LENGTH);
                g_free (filename_ext);
                close (fd);
                return(NULL);
@@ -3020,7 +3024,7 @@ map_pe_file (gunichar2 *filename, gint32 *map_size, void **handle)
        if (file_map == NULL) {
                mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error mmap()int file %s: %s", __func__, filename_ext, strerror (errno));
 
-               SetLastError (_wapi_get_win32_file_error (errno));
+               mono_w32error_set_last (mono_w32error_unix_to_win32 (errno));
                g_free (filename_ext);
                close (fd);
                return(NULL);
index d7276546f5ed35da66dd032c52bb7ffccf6ccfd9..ae8afd434373e708abe7002e72d127f52bb5b303 100644 (file)
 #include <mono/metadata/threadpool-io.h>
 #include <mono/utils/strenc.h>
 #include <mono/utils/mono-proclib.h>
-#include <mono/io-layer/io-layer.h>
 /* FIXME: fix this code to not depend so much on the internals */
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/w32handle.h>
+#include <mono/utils/w32api.h>
 
 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
 #include <shellapi.h>
index 78a622af6531296c1e25710931a85a77c00742ca..affa016604dae8b8162ae0b86452a1e3ed513c83 100644 (file)
@@ -11,7 +11,7 @@
 #include "class-internals.h"
 #include "image.h"
 #include "utils/mono-proclib.h"
-#include "io-layer/io-layer.h"
+#include "utils/w32api.h"
 
 #define LOGDEBUG(...)
 /* define LOGDEBUG(...) g_message(__VA_ARGS__)  */
index af283182a907617f3ebe9b13482b271dd452e5df..2a1efc79efa117186028678eb0bcb9ec11d51837 100644 (file)
@@ -34,7 +34,7 @@ typedef struct
 {
        gpointer process_handle;
        gpointer thread_handle;
-       guint32 pid; /* Contains GetLastError () on failure */
+       guint32 pid; /* Contains mono_w32error_get_last () on failure */
        guint32 tid;
        MonoArray *env_variables;
        MonoString *username;
index 0e88d94abe7de1618f94469f6f30486657a9e84c..2537853943d81bb831a755c881cab5fb8b2f908a 100644 (file)
@@ -9,8 +9,8 @@
 
 #include "w32semaphore.h"
 
+#include "w32error.h"
 #include "w32handle-namespace.h"
-#include "mono/io-layer/io-layer.h"
 #include "mono/utils/mono-logger-internals.h"
 #include "mono/metadata/w32handle.h"
 
@@ -150,7 +150,7 @@ sem_handle_create (MonoW32HandleSemaphore *sem_handle, MonoW32HandleType type, g
        if (handle == INVALID_HANDLE_VALUE) {
                g_warning ("%s: error creating %s handle",
                        __func__, mono_w32handle_get_typename (type));
-               SetLastError (ERROR_GEN_FAILURE);
+               mono_w32error_set_last (ERROR_GEN_FAILURE);
                return NULL;
        }
 
@@ -196,10 +196,10 @@ namedsem_create (gint32 initial, gint32 max, const gunichar2 *name)
        if (handle == INVALID_HANDLE_VALUE) {
                /* The name has already been used for a different object. */
                handle = NULL;
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
        } else if (handle) {
                /* Not an error, but this is how the caller is informed that the semaphore wasn't freshly created */
-               SetLastError (ERROR_ALREADY_EXISTS);
+               mono_w32error_set_last (ERROR_ALREADY_EXISTS);
 
                /* mono_w32handle_namespace_search_handle already adds a ref to the handle */
        } else {
@@ -242,14 +242,14 @@ ves_icall_System_Threading_Semaphore_CreateSemaphore_internal (gint32 initialCou
         * for ERROR_ALREADY_EXISTS on success (!) to see if a
         * semaphore was freshly created
         */
-       SetLastError (ERROR_SUCCESS);
+       mono_w32error_set_last (ERROR_SUCCESS);
 
        if (!name)
                sem = sem_create (initialCount, maximumCount);
        else
                sem = namedsem_create (initialCount, maximumCount, mono_string_chars (name));
 
-       *error = GetLastError ();
+       *error = mono_w32error_get_last ();
 
        return sem;
 }
@@ -262,7 +262,7 @@ ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (gpointer handle,
        MonoBoolean ret;
 
        if (!handle) {
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
@@ -271,7 +271,7 @@ ves_icall_System_Threading_Semaphore_ReleaseSemaphore_internal (gpointer handle,
        case MONO_W32HANDLE_NAMEDSEM:
                break;
        default:
-               SetLastError (ERROR_INVALID_HANDLE);
+               mono_w32error_set_last (ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
index 02f5fe108443eb9b61a4b1e79d203c7fe9cecff9..be189389bf5470ae36cd014afd21e59b0c14f2d5 100644 (file)
@@ -17,7 +17,7 @@
 #include <sys/socket.h>
 #endif
 
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 #ifndef HAVE_SOCKLEN_T
 #define socklen_t int
 typedef struct {
        guint32 len;
        gpointer buf;
-} WSABUF;
+} WSABUF, *LPWSABUF;
 
 typedef struct {
        gpointer Head;
        guint32 HeadLength;
        gpointer Tail;
        guint32 TailLength;
-} TRANSMIT_FILE_BUFFERS;
+} TRANSMIT_FILE_BUFFERS, *LPTRANSMIT_FILE_BUFFERS;
 
 typedef struct {
        guint32 Data1;
@@ -57,9 +57,6 @@ typedef struct {
        gpointer handle2;
 } OVERLAPPED;
 
-typedef BOOL (WINAPI *LPFN_DISCONNECTEX)(SOCKET, OVERLAPPED*, guint32, guint32);
-typedef BOOL (WINAPI *LPFN_TRANSMITFILE)(SOCKET, HANDLE, guint32, guint32, OVERLAPPED*, TRANSMIT_FILE_BUFFERS*, guint32);
-
 #endif
 
 void
@@ -81,7 +78,7 @@ int
 mono_w32socket_recvfrom (SOCKET s, char *buf, int len, int flags, struct sockaddr *from, socklen_t *fromlen, gboolean blocking);
 
 int
-mono_w32socket_recvbuffers (SOCKET s, WSABUF *lpBuffers, guint32 dwBufferCount, guint32 *lpNumberOfBytesRecvd, guint32 *lpFlags, gpointer lpOverlapped, gpointer lpCompletionRoutine, gboolean blocking);
+mono_w32socket_recvbuffers (SOCKET s, LPWSABUF lpBuffers, guint32 dwBufferCount, guint32 *lpNumberOfBytesRecvd, guint32 *lpFlags, gpointer lpOverlapped, gpointer lpCompletionRoutine, gboolean blocking);
 
 int
 mono_w32socket_send (SOCKET s, char *buf, int len, int flags, gboolean blocking);
@@ -90,12 +87,12 @@ int
 mono_w32socket_sendto (SOCKET s, const char *buf, int len, int flags, const struct sockaddr *to, int tolen, gboolean blocking);
 
 int
-mono_w32socket_sendbuffers (SOCKET s, WSABUF *lpBuffers, guint32 dwBufferCount, guint32 *lpNumberOfBytesRecvd, guint32 lpFlags, gpointer lpOverlapped, gpointer lpCompletionRoutine, gboolean blocking);
+mono_w32socket_sendbuffers (SOCKET s, LPWSABUF lpBuffers, guint32 dwBufferCount, guint32 *lpNumberOfBytesRecvd, guint32 lpFlags, gpointer lpOverlapped, gpointer lpCompletionRoutine, gboolean blocking);
 
 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_UWP_WINAPI_SUPPORT)
 
 BOOL
-mono_w32socket_transmit_file (SOCKET hSocket, gpointer hFile, TRANSMIT_FILE_BUFFERS *lpTransmitBuffers, guint32 dwReserved, gboolean blocking);
+mono_w32socket_transmit_file (SOCKET hSocket, gpointer hFile, LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers, guint32 dwReserved, gboolean blocking);
 
 #endif
 
@@ -128,6 +125,9 @@ mono_w32socket_shutdown (SOCKET sock, gint how);
 gint
 mono_w32socket_ioctl (SOCKET sock, gint32 command, gchar *input, gint inputlen, gchar *output, gint outputlen, glong *written);
 
+gboolean
+mono_w32socket_close (SOCKET sock);
+
 #endif /* HOST_WIN32 */
 
 gint
index 4b3d863e7462966aab904acaa4b56d3c38e2b0e1..b4e3069d6400ea315c6073912a9b6e426e92d175 100644 (file)
 #ifdef HAVE_SYS_SENDFILE_H
 #include <sys/sendfile.h>
 #endif
+#include <sys/stat.h>
 
 #include "w32socket.h"
 #include "w32socket-internals.h"
+#include "w32error.h"
 #include "w32handle.h"
 #include "utils/mono-logger-internals.h"
 #include "utils/mono-poll.h"
@@ -606,7 +608,7 @@ mono_w32socket_transmit_file (SOCKET sock, gpointer file_handle, TRANSMIT_FILE_B
        }
 
        if ((flags & TF_DISCONNECT) == TF_DISCONNECT)
-               CloseHandle (handle);
+               mono_w32handle_close (handle);
 
        return TRUE;
 }
@@ -1123,6 +1125,12 @@ mono_w32socket_ioctl (SOCKET sock, gint32 command, gchar *input, gint inputlen,
        return 0;
 }
 
+gboolean
+mono_w32socket_close (SOCKET sock)
+{
+       return mono_w32handle_close (GINT_TO_POINTER (sock));
+}
+
 gint
 mono_w32socket_set_blocking (SOCKET socket, gboolean blocking)
 {
@@ -1196,13 +1204,13 @@ mono_w32socket_get_available (SOCKET socket, guint64 *amount)
 void
 mono_w32socket_set_last_error (gint32 error)
 {
-       SetLastError (error);
+       mono_w32error_set_last (error);
 }
 
 gint32
 mono_w32socket_get_last_error (void)
 {
-       return GetLastError ();
+       return mono_w32error_get_last ();
 }
 
 gint32
index 9a2d4522167a7d5eb8ddceb85906ff11cd77d5fd..0d5a3143a869876faf734e30f0093814f0abf756 100644 (file)
@@ -21,6 +21,8 @@
 #include "w32socket.h"
 #include "w32socket-internals.h"
 
+#include "utils/w32api.h"
+
 #define LOGDEBUG(...)  
 
 void
index ba9156eb48b8042374b532fc05d6ec6774e5d845..d8851e8b70fab5b23fb1384f53314098e81fc2b9 100644 (file)
@@ -46,7 +46,6 @@
 #include <sys/types.h>
 
 #include <mono/metadata/object.h>
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/appdomain.h>
@@ -64,6 +63,7 @@
 #include <mono/metadata/w32handle.h>
 #include <mono/metadata/w32socket.h>
 #include <mono/metadata/w32socket-internals.h>
+#include <mono/metadata/w32error.h>
 
 #include <time.h>
 #ifdef HAVE_SYS_TIME_H
@@ -157,6 +157,12 @@ mono_w32socket_ioctl (SOCKET sock, gint32 command, gchar *input, gint inputlen,
        return WSAIoctl (sock, command, input, inputlen, output, outputlen, written, NULL, NULL);
 }
 
+static gboolean
+mono_w32socket_close (SOCKET sock)
+{
+       return CloseHandle (sock);
+}
+
 #endif /* HOST_WIN32 */
 
 static void
@@ -702,7 +708,7 @@ ves_icall_System_Net_Sockets_Socket_Close_internal (gsize sock, gint32 *werror)
        mono_threadpool_io_remove_socket (GPOINTER_TO_INT (sock));
 
        MONO_ENTER_GC_SAFE;
-       CloseHandle (GINT_TO_POINTER (sock));
+       mono_w32socket_close ((SOCKET) sock);
        MONO_EXIT_GC_SAFE;
 }
 
@@ -2637,10 +2643,9 @@ ves_icall_System_Net_Sockets_Socket_SendFile_internal (gsize sock, MonoString *f
 
        /* FIXME: replace file by a proper fd that we can call open and close on, as they are interruptible */
 
-       file = ves_icall_System_IO_MonoIO_Open (filename, FileMode_Open, FileAccess_Read, FileShare_Read, 0, werror);
-
+       file = mono_w32file_create (mono_string_chars (filename), OPEN_EXISTING, GENERIC_READ, FILE_SHARE_READ, 0);
        if (file == INVALID_HANDLE_VALUE) {
-               SetLastError (*werror);
+               *werror = mono_w32error_get_last ();
                return FALSE;
        }
 
@@ -2656,8 +2661,8 @@ ves_icall_System_Net_Sockets_Socket_SendFile_internal (gsize sock, MonoString *f
 
        mono_thread_info_install_interrupt (abort_syscall, (gpointer) (gsize) mono_native_thread_id_get (), &interrupted);
        if (interrupted) {
-               CloseHandle (file);
-               SetLastError (WSAEINTR);
+               mono_w32file_close (file);
+               mono_w32error_set_last (WSAEINTR);
                return FALSE;
        }
 
@@ -2670,14 +2675,14 @@ ves_icall_System_Net_Sockets_Socket_SendFile_internal (gsize sock, MonoString *f
 
        mono_thread_info_uninstall_interrupt (&interrupted);
        if (interrupted) {
-               CloseHandle (file);
+               mono_w32file_close (file);
                *werror = WSAEINTR;
                return FALSE;
        }
 
        MONO_ENTER_GC_SAFE;
 
-       CloseHandle (file);
+       mono_w32file_close (file);
 
        MONO_EXIT_GC_SAFE;
 
index 745d0a52f55c45c0669a61a29db0bfb826e48b25..4f1e38b0735c72f4e22df2c2802735b617ac1301 100755 (executable)
@@ -15,7 +15,6 @@ libgc_static_libs=$(monodir)/libgc/libmonogc-static.la
 
 boehm_libs=    \
        $(monodir)/mono/metadata/libmonoruntime.la      \
-       $(monodir)/mono/io-layer/libwapi.la     \
        $(monodir)/mono/utils/libmonoutils.la \
        $(GLIB_LIBS) $(LIBICONV) \
        $(libgc_libs)
@@ -23,13 +22,11 @@ boehm_libs= \
 sgen_libs = \
        $(monodir)/mono/metadata/libmonoruntimesgen.la  \
        $(monodir)/mono/sgen/libmonosgen.la     \
-       $(monodir)/mono/io-layer/libwapi.la     \
        $(monodir)/mono/utils/libmonoutils.la \
        $(GLIB_LIBS) $(LIBICONV)
 
 boehm_static_libs=     \
        $(monodir)/mono/metadata/libmonoruntime-static.la       \
-       $(monodir)/mono/io-layer/libwapi.la     \
        $(monodir)/mono/utils/libmonoutils.la \
        $(GLIB_LIBS) $(LIBICONV) \
        $(libgc_static_libs)
@@ -37,7 +34,6 @@ boehm_static_libs=    \
 sgen_static_libs = \
        $(monodir)/mono/metadata/libmonoruntimesgen-static.la   \
        $(monodir)/mono/sgen/libmonosgen-static.la      \
-       $(monodir)/mono/io-layer/libwapi.la     \
        $(monodir)/mono/utils/libmonoutils.la \
        $(GLIB_LIBS) $(LIBICONV)
 
index 630ab56ded71c0777a41df7cb559e2cf7ea54a31..0d24eeb924d4bf9588ed4cd1e1515bf4d31b960b 100644 (file)
@@ -56,7 +56,7 @@
 #include <mono/utils/json.h>
 #include <mono/utils/mono-threads-coop.h>
 #include <mono/profiler/mono-profiler-aot.h>
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 #include "aot-compiler.h"
 #include "seq-points.h"
index ce2656126b6d1750e130ee034779a0be7664e87b..dd0e7353bd5ed0a6b6ef34835370eed6b5f37409 100644 (file)
@@ -75,7 +75,7 @@
 #include "debugger-agent.h"
 #include "mini.h"
 #include "seq-points.h"
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 /*
  * On iOS we can't use System.Environment.Exit () as it will do the wrong
index 40de446bc05907dfe1468965c7c7e47e9e3d8745..3385ad1e7eea6f67242ffac0058a8184ae9fdacd 100644 (file)
@@ -35,7 +35,6 @@
 #include <mono/metadata/marshal.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
-#include <mono/io-layer/io-layer.h>
 #include "mono/metadata/profiler.h"
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/mono-config.h>
index d40d6dc873698caecf32b06d8c8888ceaad3e974..779bde4da366632a69a5a1a0421861351162f8f2 100644 (file)
@@ -33,7 +33,6 @@
 #include <mono/metadata/threads.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
-#include <mono/io-layer/io-layer.h>
 #include "mono/metadata/profiler.h"
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/mono-config.h>
index d3d48d45a974a972b833f4af2530424c11cad3a1..5e574b376097aac3209254f2a36a3c4a5211152f 100644 (file)
@@ -39,7 +39,6 @@
 #include <mono/metadata/threads.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
-#include <mono/io-layer/io-layer.h>
 #include "mono/metadata/profiler.h"
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/mono-config.h>
index 3c006958f96ec51fad025b1cc88a52361fc6535d..cf3444c19343dd23247d87ecd2b2af2a83395306 100644 (file)
@@ -66,7 +66,6 @@
 #include <mono/utils/mono-threads-coop.h>
 #include <mono/utils/checked-build.h>
 #include <mono/metadata/w32handle.h>
-#include <mono/io-layer/io-layer.h>
 
 #include "mini.h"
 #include "seq-points.h"
index 69d7cbeec25ac9cb13e998bfd4d7460b18dfb018..9983e27d1b3b5913a0c5eb28b21bc3b3f289c477 100644 (file)
@@ -26,7 +26,6 @@
 #include <mono/metadata/threads.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/debug-helpers.h>
-#include <mono/io-layer/io-layer.h>
 #include "mono/metadata/profiler.h"
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/mono-config.h>
index e770092c95a5225e86fc49a19f6544909194af33..dd83dab383128373a8e23668f07e810803c4dc79 100644 (file)
@@ -60,7 +60,6 @@
 #include <mono/utils/dtrace.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-threads-coop.h>
-#include <mono/io-layer/io-layer.h>
 
 #include "mini.h"
 #include "seq-points.h"
index 9db0e0c98230823e073ea57b46454c647c01272f..b2c969ba0bd0cbfd5a79ecebc4eeb6f8732856cb 100644 (file)
@@ -13,7 +13,7 @@ if SUPPORT_BOEHM
 
 noinst_LTLIBRARIES = libtestlib.la
 libtestlib_la_SOURCES =
-libtestlib_la_LIBADD = ../metadata/libmonoruntimesgen.la ../sgen/libmonosgen.la ../utils/libmonoutils.la ../io-layer/libwapi.la 
+libtestlib_la_LIBADD = ../metadata/libmonoruntimesgen.la ../sgen/libmonosgen.la ../utils/libmonoutils.la
 
 test_sgen_qsort_SOURCES = test-sgen-qsort.c
 test_sgen_qsort_CFLAGS = $(test_cflags)
index cc00f5c8eba8b3d44318745c735ec03ce4abae32..e2c4c96843d15b251e04cf254b875ec95b2e97e7 100644 (file)
@@ -23,7 +23,6 @@
 #include <mono/utils/mono-mmap.h>
 #include <mono/utils/mono-threads.h>
 #include <mono/utils/mono-counters.h>
-#include <mono/io-layer/io-layer.h>
 #endif
 
 typedef struct {
index ba3ec4ea132a8e8acd7d9c4ab62f53ec0ac88c14..15b96e564f9de1f068521df3ec3948a36915ebaa 100644 (file)
@@ -15,7 +15,6 @@
 #include "mono-mmap.h"
 #include "mono-counters.h"
 #include "dlmalloc.h"
-#include <mono/io-layer/io-layer.h>
 #include <mono/metadata/profiler-private.h>
 #ifdef HAVE_VALGRIND_MEMCHECK_H
 #include <valgrind/memcheck.h>
index e8893039fbf2eb2a89a828c4c4b7607f6a50ac44..401d3b7e3b1e806a3889d7457c66db1ca46eded3 100644 (file)
@@ -31,8 +31,7 @@
 #include <mono/utils/mono-threads-coop.h>
 #include <mono/utils/mono-threads-debug.h>
 #include <mono/utils/os-event.h>
-
-#include <mono/io-layer/io-layer.h>
+#include <mono/utils/w32api.h>
 
 #include <errno.h>
 
diff --git a/mono/utils/w32api.h b/mono/utils/w32api.h
new file mode 100644 (file)
index 0000000..fa0bc87
--- /dev/null
@@ -0,0 +1,59 @@
+
+#ifndef __MONO_UTILS_W32API_H__
+#define __MONO_UTILS_W32API_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#ifndef HOST_WIN32
+
+#define WAIT_FAILED        ((gint) 0xFFFFFFFF)
+#define WAIT_OBJECT_0      ((gint) 0x00000000)
+#define WAIT_ABANDONED_0   ((gint) 0x00000080)
+#define WAIT_TIMEOUT       ((gint) 0x00000102)
+#define WAIT_IO_COMPLETION ((gint) 0x000000C0)
+
+#define WINAPI
+
+typedef guint32 DWORD;
+typedef gboolean BOOL;
+typedef gint32 LONG;
+typedef guint32 ULONG;
+typedef guint UINT;
+
+typedef gpointer HANDLE;
+typedef gpointer HMODULE;
+
+#else
+
+#define __USE_W32_SOCKETS
+#include <winsock2.h>
+#include <windows.h>
+#include <winbase.h>
+/* The mingw version says: /usr/i686-pc-mingw32/sys-root/mingw/include/ws2tcpip.h:38:2: error: #error "ws2tcpip.h is not compatible with winsock.h. Include winsock2.h instead." */
+#ifdef _MSC_VER
+#include <ws2tcpip.h>
+#endif
+#include <psapi.h>
+
+/* Workaround for missing WSAPOLLFD typedef in mingw's winsock2.h
+ * that is required for mswsock.h below. Remove once
+ * http://sourceforge.net/p/mingw/bugs/1980/ is fixed. */
+#if defined(__MINGW_MAJOR_VERSION) && __MINGW_MAJOR_VERSION == 4
+typedef struct pollfd {
+       SOCKET fd;
+       short  events;
+       short  revents;
+} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;
+#endif
+
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
+#include <mswsock.h>
+#endif
+
+#endif /* HOST_WIN32 */
+
+G_END_DECLS
+
+#endif /* __MONO_UTILS_W32API_H__ */
index 0f4d0703b7b097bf9ddc053b4bd34d5d2e287748..2305bfe66a1f8a5e6c4a6194596c7338cb93953d 100644 (file)
@@ -30,6 +30,7 @@
     <ClCompile Include="..\mono\metadata\property-bag.c" />\r
     <ClCompile Include="..\mono\metadata\w32socket-win32.c" />\r
     <ClCompile Include="..\mono\metadata\w32file-win32.c" />\r
+    <ClCompile Include="..\mono\metadata\w32error-win32.c" />\r
     <ClCompile Include="..\mono\metadata\icall-windows.c" />\r
     <ClCompile Include="..\mono\metadata\marshal-windows.c" />\r
     <ClCompile Include="..\mono\metadata\mono-security-windows.c" />\r
     <ClInclude Include="..\mono\metadata\w32file-internals.h" />\r
     <ClInclude Include="..\mono\metadata\w32file-win32-internals.h" />\r
     <ClInclude Include="..\mono\metadata\w32file.h" />\r
+    <ClInclude Include="..\mono\metadata\w32error.h" />\r
+    <ClInclude Include="..\mono\metadata\w32api.h" />\r
     <ClInclude Include="..\mono\metadata\filewatcher.h" />\r
     <ClInclude Include="..\mono\metadata\gc-internals.h" />\r
     <ClInclude Include="..\mono\metadata\handle.h" />\r
index bc9a0c35fb6b1e791ff78fc70dcc1577a393ec02..62ffe0bef5f03ce4a2ccae1d11bcf84d256b2595 100644 (file)
     <ClCompile Include="..\mono\metadata\w32file-win32.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\mono\metadata\w32error-win32.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
     <ClCompile Include="..\mono\metadata\icall-windows.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
     <ClInclude Include="..\mono\metadata\w32file.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="..\mono\metadata\w32error.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="..\mono\metadata\w32api.h">\r
+      <Filter>Header Files</Filter>\r
+    </ClInclude>\r
     <ClInclude Include="..\mono\metadata\filewatcher.h">\r
       <Filter>Header Files</Filter>\r
     </ClInclude>\r
index 57b84fab14f852b834a27a8e7aaa201d7820348e..fded8b5ffe6fd80e8ce98e63f991baabc2e5c38b 100644 (file)
     <ClCompile Include="..\mono\metadata\environment.c" />\r
     <ClCompile Include="..\mono\metadata\w32file-win32.c" />\r
     <ClCompile Include="..\mono\metadata\w32file.c" />\r
+    <ClCompile Include="..\mono\metadata\w32error-win32.c" />\r
     <ClCompile Include="..\mono\metadata\filewatcher.c" />\r
     <ClCompile Include="..\mono\metadata\gc.c" />\r
     <ClCompile Include="..\mono\metadata\icall-windows.c" />\r
index 9f25b8211b54c2eb19c449415c191d7e0399619c..5b01ceb1a56351c4e3e9c3904203ecd8f42654d4 100644 (file)
     <ClCompile Include="..\mono\metadata\w32file-win32.c">\r
       <Filter>Source Files</Filter>\r
     </ClCompile>\r
+    <ClCompile Include="..\mono\metadata\w32error-win32.c">\r
+      <Filter>Source Files</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Filter Include="Header Files">\r
index 51b49697152b36ac93cedb5ba9ea741231deedd7..247f310c23b95a26c7fd1ae7460fe672766ab1a6 100644 (file)
@@ -18,7 +18,6 @@
 #include "mono/metadata/class.h"
 #include "mono/metadata/object.h"
 #include "mono/metadata/tabledefs.h"
-#include "mono/io-layer/wapi.h"
 
 typedef struct {
        const char *fname;
index 3c52afc663451226a7b6b16a459081eec5e1bb7b..1a53e3772b7a01686881710930f90104034ccfda 100644 (file)
@@ -8,7 +8,6 @@ runtime_lib=$(top_builddir)/mono/mini/$(LIBMONO_LA) $(static_libs)
 else
 static_libs=   \
        $(top_builddir)/mono/metadata/libmonoruntimesgen-static.la      \
-       $(top_builddir)/mono/io-layer/libwapi.la        \
        $(top_builddir)/mono/utils/libmonoutils.la \
        $(GLIB_LIBS) $(LIBICONV) \
        $(LIBGC_STATIC_LIBS)
index d329d1fa9b1ef53418183e0197558dbd0f999187..4fb8260abdb5eabf4910592d391487d1e3310721 100644 (file)
@@ -19,7 +19,6 @@ pedump_SOURCES =              \
 pedump_LDADD =                         \
        $(top_builddir)/mono/metadata/libmonoruntimesgen-static.la \
        $(top_builddir)/mono/sgen/libmonosgen-static.la \
-       $(top_builddir)/mono/io-layer/libwapi.la        \
        $(top_builddir)/mono/utils/libmonoutils.la \
        $(LLVM_LIBS)                    \
        $(LLVM_LDFLAGS)                 \