From: Ludovic Henry Date: Sat, 21 Jan 2017 01:15:19 +0000 (-0500) Subject: [io-layer] Extract error (#4279) X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=56edb3357c0af9eae94a01dd72c7623bd6322dd8 [io-layer] Extract error (#4279) * [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 --- diff --git a/configure.ac b/configure.ac index aed81dc091d..632983d0c11 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/mono/Makefile.am b/mono/Makefile.am index 651271c25f8..8c9c2cbac2f 100644 --- a/mono/Makefile.am +++ b/mono/Makefile.am @@ -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 diff --git a/mono/dis/Makefile.am b/mono/dis/Makefile.am index 40f0dbf9552..14090d8c3ec 100644 --- a/mono/dis/Makefile.am +++ b/mono/dis/Makefile.am @@ -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 index 9fda7d340a6..00000000000 --- a/mono/io-layer/.gitignore +++ /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 index 48e48baada2..00000000000 --- a/mono/io-layer/Makefile.am +++ /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 index 38a9141d2e1..00000000000 --- a/mono/io-layer/error.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * error.c: Error reporting - * - * Author: - * Dick Porter (dick@ximian.com) - * - * (C) 2002 Ximian, Inc. - */ - -#include -#include -#include -#include -#include - -#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 index 9f6c640cc5e..00000000000 --- a/mono/io-layer/error.h +++ /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 index f6e150a37ec..00000000000 --- a/mono/io-layer/io-layer-dummy.c +++ /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 index f1d2e05344e..00000000000 --- a/mono/io-layer/io-layer.h +++ /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 -#include - -#if defined(__WIN32__) || defined(_WIN32) -/* Native win32 */ -#define __USE_W32_SOCKETS -#include -#include -#include -/* - * 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 -#endif -#include - - /* - * 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 -#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 index 80034f50be7..00000000000 --- a/mono/io-layer/wapi-remap.h +++ /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_. - */ - -#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 index 14dc672e8ee..00000000000 --- a/mono/io-layer/wapi.c +++ /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 index 4409210db2d..00000000000 --- a/mono/io-layer/wapi.h +++ /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 -#include - -#ifdef HAVE_DIRENT_H -#include -#endif -#include -#include -#include -#include - -#include -#include -#include - -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_ */ diff --git a/mono/metadata/Makefile.am b/mono/metadata/Makefile.am index 4a997d3fc4c..751eabbb1b6 100644 --- a/mono/metadata/Makefile.am +++ b/mono/metadata/Makefile.am @@ -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 = \ diff --git a/mono/metadata/appdomain.c b/mono/metadata/appdomain.c index a2c8c353fd3..dc17ecc71c0 100644 --- a/mono/metadata/appdomain.c +++ b/mono/metadata/appdomain.c @@ -70,7 +70,8 @@ #include #include #include -#include +#include +#include #ifdef HOST_WIN32 #include #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)."); diff --git a/mono/metadata/assembly.c b/mono/metadata/assembly.c index 61b4c341652..e909833e7c7 100644 --- a/mono/metadata/assembly.c +++ b/mono/metadata/assembly.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include diff --git a/mono/metadata/attach.c b/mono/metadata/attach.c index 6fc81e08984..13f03abf485 100644 --- a/mono/metadata/attach.c +++ b/mono/metadata/attach.c @@ -42,7 +42,7 @@ #include #include "attach.h" -#include +#include /* * This module enables other processes to attach to a running mono process and diff --git a/mono/metadata/cominterop.c b/mono/metadata/cominterop.c index f3beb972401..769e06867de 100644 --- a/mono/metadata/cominterop.c +++ b/mono/metadata/cominterop.c @@ -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 #include +#include #if defined(HOST_WIN32) #include diff --git a/mono/metadata/console-unix.c b/mono/metadata/console-unix.c index 7d1e9a1ec00..7d60b770fe5 100644 --- a/mono/metadata/console-unix.c +++ b/mono/metadata/console-unix.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include /* On solaris, curses.h must come before both termios.h and term.h */ #ifdef HAVE_CURSES_H diff --git a/mono/metadata/coree.c b/mono/metadata/coree.c index 428fb9b989f..0ce8810d4c2 100644 --- a/mono/metadata/coree.c +++ b/mono/metadata/coree.c @@ -14,8 +14,8 @@ #include #include -#include #include +#include "utils/w32api.h" #include "cil-coff.h" #include "metadata-internals.h" #include "image.h" diff --git a/mono/metadata/coree.h b/mono/metadata/coree.h index ade821af5e3..1b139b69202 100644 --- a/mono/metadata/coree.h +++ b/mono/metadata/coree.h @@ -16,8 +16,8 @@ #ifdef HOST_WIN32 -#include #include +#include #include "image.h" #define STATUS_SUCCESS 0x00000000L diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c index 908f572a5ff..12f778fa1ad 100644 --- a/mono/metadata/domain.c +++ b/mono/metadata/domain.c @@ -48,7 +48,6 @@ #include #include #include -#include //#define DEBUG_DOMAIN_UNLOAD 1 diff --git a/mono/metadata/environment.c b/mono/metadata/environment.c index 4726f9ba703..f0fbef9174f 100644 --- a/mono/metadata/environment.c +++ b/mono/metadata/environment.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include extern MonoString* ves_icall_System_Environment_GetOSVersionString (void); diff --git a/mono/metadata/filewatcher.c b/mono/metadata/filewatcher.c index 90a54d5050a..9d154e1ecd6 100644 --- a/mono/metadata/filewatcher.c +++ b/mono/metadata/filewatcher.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #ifdef HOST_WIN32 diff --git a/mono/metadata/gc.c b/mono/metadata/gc.c index 1a452c083ee..9060cf400e0 100644 --- a/mono/metadata/gc.c +++ b/mono/metadata/gc.c @@ -42,7 +42,7 @@ #include #include #include -#include +#include #ifndef HOST_WIN32 #include diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index f0dc4ef1238..3e87be6daf9 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -85,7 +85,6 @@ #include #include #include -#include #include #include #include @@ -97,6 +96,8 @@ #include #include #include +#include +#include #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; } diff --git a/mono/metadata/image.c b/mono/metadata/image.c index 5bcd6e90adc..84204ec073b 100644 --- a/mono/metadata/image.c +++ b/mono/metadata/image.c @@ -27,7 +27,6 @@ #include "loader.h" #include "marshal.h" #include "coree.h" -#include #include #include #include @@ -46,6 +45,7 @@ #ifdef HAVE_UNISTD_H #include #endif +#include #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); diff --git a/mono/metadata/lock-tracer.c b/mono/metadata/lock-tracer.c index 8ca4a27ab82..16fcbdb0618 100644 --- a/mono/metadata/lock-tracer.c +++ b/mono/metadata/lock-tracer.c @@ -20,7 +20,6 @@ #include #endif -#include #include #include "lock-tracer.h" diff --git a/mono/metadata/monitor.c b/mono/metadata/monitor.c index 0b1e938f3d8..dd2cc0eb9a7 100644 --- a/mono/metadata/monitor.c +++ b/mono/metadata/monitor.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -31,6 +30,7 @@ #include #include #include +#include /* * 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; } diff --git a/mono/metadata/mono-perfcounters.c b/mono/metadata/mono-perfcounters.c index cd2c622a89d..57c01f411e3 100644 --- a/mono/metadata/mono-perfcounters.c +++ b/mono/metadata/mono-perfcounters.c @@ -48,7 +48,6 @@ #include "utils/mono-networkinterfaces.h" #include "utils/mono-error-internals.h" #include "utils/atomic.h" -#include /* map of CounterSample.cs */ struct _MonoCounterSample { diff --git a/mono/metadata/mono-security.c b/mono/metadata/mono-security.c index cd1a9ad0aec..a1d3c9d0e4f 100644 --- a/mono/metadata/mono-security.c +++ b/mono/metadata/mono-security.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #ifndef HOST_WIN32 diff --git a/mono/metadata/object.c b/mono/metadata/object.c index 29103437bbd..699c7d225fb 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -50,7 +50,7 @@ #include #include #include "cominterop.h" -#include +#include static void get_default_field_value (MonoDomain* domain, MonoClassField *field, void *value, MonoError *error); diff --git a/mono/metadata/profiler.c b/mono/metadata/profiler.c index 0fd162dd98a..a880ec93300 100644 --- a/mono/metadata/profiler.c +++ b/mono/metadata/profiler.c @@ -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 #include diff --git a/mono/metadata/sre-save.c b/mono/metadata/sre-save.c index 4d94b5524b9..20d9e47a4a3 100644 --- a/mono/metadata/sre-save.c +++ b/mono/metadata/sre-save.c @@ -25,12 +25,12 @@ #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); diff --git a/mono/metadata/sre.c b/mono/metadata/sre.c index e7545f41724..df218b3ea04 100644 --- a/mono/metadata/sre.c +++ b/mono/metadata/sre.c @@ -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); diff --git a/mono/metadata/threadpool-io.c b/mono/metadata/threadpool-io.c index 4b59150832a..ace9a00bf6a 100644 --- a/mono/metadata/threadpool-io.c +++ b/mono/metadata/threadpool-io.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include typedef struct { gboolean (*init) (gint wakeup_pipe_fd); diff --git a/mono/metadata/threadpool-worker-default.c b/mono/metadata/threadpool-worker-default.c index f78ccf68b2a..e882574ab15 100644 --- a/mono/metadata/threadpool-worker-default.c +++ b/mono/metadata/threadpool-worker-default.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #define CPU_USAGE_LOW 80 #define CPU_USAGE_HIGH 95 diff --git a/mono/metadata/threadpool.c b/mono/metadata/threadpool.c index 75de23a393c..dfd61ea3f58 100644 --- a/mono/metadata/threadpool.c +++ b/mono/metadata/threadpool.c @@ -45,7 +45,6 @@ #include #include #include -#include 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); diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index b5ffc020231..abc29bf0022 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -53,6 +52,8 @@ #include #include #include +#include +#include #ifdef HAVE_SIGNAL_H #include @@ -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 index 00000000000..6192d880d47 --- /dev/null +++ b/mono/metadata/w32error-unix.c @@ -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 index 00000000000..8b8303968fa --- /dev/null +++ b/mono/metadata/w32error-win32.c @@ -0,0 +1,22 @@ + +#include + +#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 index 00000000000..990ba3b3894 --- /dev/null +++ b/mono/metadata/w32error.h @@ -0,0 +1,86 @@ + +#ifndef _MONO_METADATA_W32ERROR_H_ +#define _MONO_METADATA_W32ERROR_H_ + +#include +#include + +#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_ */ diff --git a/mono/metadata/w32event-unix.c b/mono/metadata/w32event-unix.c index 8c9b1b1f765..50e9a6abad4 100644 --- a/mono/metadata/w32event-unix.c +++ b/mono/metadata/w32event-unix.c @@ -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 diff --git a/mono/metadata/w32event-win32.c b/mono/metadata/w32event-win32.c index 86590217c4d..343347da362 100644 --- a/mono/metadata/w32event-win32.c +++ b/mono/metadata/w32event-win32.c @@ -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) { diff --git a/mono/metadata/w32event.h b/mono/metadata/w32event.h index 1f41b1a4555..f1fbd702872 100644 --- a/mono/metadata/w32event.h +++ b/mono/metadata/w32event.h @@ -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); diff --git a/mono/metadata/w32file-unix.c b/mono/metadata/w32file-unix.c index ecca05ec6aa..be8b5f70502 100644 --- a/mono/metadata/w32file-unix.c +++ b/mono/metadata/w32file-unix.c @@ -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; diff --git a/mono/metadata/w32file-win32.c b/mono/metadata/w32file-win32.c index 7a5478cf2e5..953f7926c76 100644 --- a/mono/metadata/w32file-win32.c +++ b/mono/metadata/w32file-win32.c @@ -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) { diff --git a/mono/metadata/w32file.c b/mono/metadata/w32file.c index 8aabbc57537..d24506afd4e 100644 --- a/mono/metadata/w32file.c +++ b/mono/metadata/w32file.c @@ -27,8 +27,8 @@ #endif #include -#include #include +#include #include #include #include @@ -36,6 +36,7 @@ #include #include #include +#include #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); } diff --git a/mono/metadata/w32file.h b/mono/metadata/w32file.h index 05bfe9fc929..b2cf4f63c0c 100644 --- a/mono/metadata/w32file.h +++ b/mono/metadata/w32file.h @@ -16,7 +16,6 @@ #include #include -#include "io-layer/io-layer.h" #include #include @@ -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); diff --git a/mono/metadata/w32handle-namespace.c b/mono/metadata/w32handle-namespace.c index 2eb2145533b..2441f952618 100644 --- a/mono/metadata/w32handle-namespace.c +++ b/mono/metadata/w32handle-namespace.c @@ -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" diff --git a/mono/metadata/w32handle.c b/mono/metadata/w32handle.c index 248bf1b316f..7563c2cd7f0 100644 --- a/mono/metadata/w32handle.c +++ b/mono/metadata/w32handle.c @@ -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) diff --git a/mono/metadata/w32handle.h b/mono/metadata/w32handle.h index db536d40805..f3f546c10a9 100644 --- a/mono/metadata/w32handle.h +++ b/mono/metadata/w32handle.h @@ -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); diff --git a/mono/metadata/w32mutex-unix.c b/mono/metadata/w32mutex-unix.c index faf8ac6eea9..acde96a791b 100644 --- a/mono/metadata/w32mutex-unix.c +++ b/mono/metadata/w32mutex-unix.c @@ -11,8 +11,8 @@ #include +#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; } diff --git a/mono/metadata/w32process-unix.c b/mono/metadata/w32process-unix.c index e81b50a1acf..4b463886f7b 100644 --- a/mono/metadata/w32process-unix.c +++ b/mono/metadata/w32process-unix.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,6 @@ #include #include #include -#include #include #include #include @@ -70,6 +70,7 @@ #include #include #include +#include #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); diff --git a/mono/metadata/w32process-win32.c b/mono/metadata/w32process-win32.c index d7276546f5e..ae8afd43437 100644 --- a/mono/metadata/w32process-win32.c +++ b/mono/metadata/w32process-win32.c @@ -28,10 +28,10 @@ #include #include #include -#include /* FIXME: fix this code to not depend so much on the internals */ #include #include +#include #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) #include diff --git a/mono/metadata/w32process.c b/mono/metadata/w32process.c index 78a622af653..affa016604d 100644 --- a/mono/metadata/w32process.c +++ b/mono/metadata/w32process.c @@ -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__) */ diff --git a/mono/metadata/w32process.h b/mono/metadata/w32process.h index af283182a90..2a1efc79efa 100644 --- a/mono/metadata/w32process.h +++ b/mono/metadata/w32process.h @@ -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; diff --git a/mono/metadata/w32semaphore-unix.c b/mono/metadata/w32semaphore-unix.c index 0e88d94abe7..2537853943d 100644 --- a/mono/metadata/w32semaphore-unix.c +++ b/mono/metadata/w32semaphore-unix.c @@ -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; } diff --git a/mono/metadata/w32socket-internals.h b/mono/metadata/w32socket-internals.h index 02f5fe10844..be189389bf5 100644 --- a/mono/metadata/w32socket-internals.h +++ b/mono/metadata/w32socket-internals.h @@ -17,7 +17,7 @@ #include #endif -#include +#include #ifndef HAVE_SOCKLEN_T #define socklen_t int @@ -31,14 +31,14 @@ 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 diff --git a/mono/metadata/w32socket-unix.c b/mono/metadata/w32socket-unix.c index 4b3d863e746..b4e3069d640 100644 --- a/mono/metadata/w32socket-unix.c +++ b/mono/metadata/w32socket-unix.c @@ -45,9 +45,11 @@ #ifdef HAVE_SYS_SENDFILE_H #include #endif +#include #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 diff --git a/mono/metadata/w32socket-win32.c b/mono/metadata/w32socket-win32.c index 9a2d4522167..0d5a3143a86 100644 --- a/mono/metadata/w32socket-win32.c +++ b/mono/metadata/w32socket-win32.c @@ -21,6 +21,8 @@ #include "w32socket.h" #include "w32socket-internals.h" +#include "utils/w32api.h" + #define LOGDEBUG(...) void diff --git a/mono/metadata/w32socket.c b/mono/metadata/w32socket.c index ba9156eb48b..d8851e8b70f 100644 --- a/mono/metadata/w32socket.c +++ b/mono/metadata/w32socket.c @@ -46,7 +46,6 @@ #include #include -#include #include #include #include @@ -64,6 +63,7 @@ #include #include #include +#include #include #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; diff --git a/mono/mini/Makefile.am.in b/mono/mini/Makefile.am.in index 745d0a52f55..4f1e38b0735 100755 --- a/mono/mini/Makefile.am.in +++ b/mono/mini/Makefile.am.in @@ -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) diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index 630ab56ded7..0d24eeb924d 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include "aot-compiler.h" #include "seq-points.h" diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index ce2656126b6..dd0e7353bd5 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -75,7 +75,7 @@ #include "debugger-agent.h" #include "mini.h" #include "seq-points.h" -#include +#include /* * On iOS we can't use System.Environment.Exit () as it will do the wrong diff --git a/mono/mini/driver.c b/mono/mini/driver.c index 40de446bc05..3385ad1e7ee 100644 --- a/mono/mini/driver.c +++ b/mono/mini/driver.c @@ -35,7 +35,6 @@ #include #include #include -#include #include "mono/metadata/profiler.h" #include #include diff --git a/mono/mini/mini-darwin.c b/mono/mini/mini-darwin.c index d40d6dc8736..779bde4da36 100644 --- a/mono/mini/mini-darwin.c +++ b/mono/mini/mini-darwin.c @@ -33,7 +33,6 @@ #include #include #include -#include #include "mono/metadata/profiler.h" #include #include diff --git a/mono/mini/mini-posix.c b/mono/mini/mini-posix.c index d3d48d45a97..5e574b37609 100644 --- a/mono/mini/mini-posix.c +++ b/mono/mini/mini-posix.c @@ -39,7 +39,6 @@ #include #include #include -#include #include "mono/metadata/profiler.h" #include #include diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c index 3c006958f96..cf3444c1934 100644 --- a/mono/mini/mini-runtime.c +++ b/mono/mini/mini-runtime.c @@ -66,7 +66,6 @@ #include #include #include -#include #include "mini.h" #include "seq-points.h" diff --git a/mono/mini/mini-windows.c b/mono/mini/mini-windows.c index 69d7cbeec25..9983e27d1b3 100644 --- a/mono/mini/mini-windows.c +++ b/mono/mini/mini-windows.c @@ -26,7 +26,6 @@ #include #include #include -#include #include "mono/metadata/profiler.h" #include #include diff --git a/mono/mini/mini.c b/mono/mini/mini.c index e770092c95a..dd83dab3831 100644 --- a/mono/mini/mini.c +++ b/mono/mini/mini.c @@ -60,7 +60,6 @@ #include #include #include -#include #include "mini.h" #include "seq-points.h" diff --git a/mono/unit-tests/Makefile.am b/mono/unit-tests/Makefile.am index 9db0e0c9823..b2c969ba0bd 100644 --- a/mono/unit-tests/Makefile.am +++ b/mono/unit-tests/Makefile.am @@ -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) diff --git a/mono/utils/hazard-pointer.c b/mono/utils/hazard-pointer.c index cc00f5c8eba..e2c4c96843d 100644 --- a/mono/utils/hazard-pointer.c +++ b/mono/utils/hazard-pointer.c @@ -23,7 +23,6 @@ #include #include #include -#include #endif typedef struct { diff --git a/mono/utils/mono-codeman.c b/mono/utils/mono-codeman.c index ba3ec4ea132..15b96e564f9 100644 --- a/mono/utils/mono-codeman.c +++ b/mono/utils/mono-codeman.c @@ -15,7 +15,6 @@ #include "mono-mmap.h" #include "mono-counters.h" #include "dlmalloc.h" -#include #include #ifdef HAVE_VALGRIND_MEMCHECK_H #include diff --git a/mono/utils/mono-threads.c b/mono/utils/mono-threads.c index e8893039fbf..401d3b7e3b1 100644 --- a/mono/utils/mono-threads.c +++ b/mono/utils/mono-threads.c @@ -31,8 +31,7 @@ #include #include #include - -#include +#include #include diff --git a/mono/utils/w32api.h b/mono/utils/w32api.h new file mode 100644 index 00000000000..fa0bc87fd6b --- /dev/null +++ b/mono/utils/w32api.h @@ -0,0 +1,59 @@ + +#ifndef __MONO_UTILS_W32API_H__ +#define __MONO_UTILS_W32API_H__ + +#include + +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 +#include +#include +/* 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 +#endif +#include + +/* 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 +#endif + +#endif /* HOST_WIN32 */ + +G_END_DECLS + +#endif /* __MONO_UTILS_W32API_H__ */ diff --git a/msvc/libmonoruntime.vcxproj b/msvc/libmonoruntime.vcxproj index 0f4d0703b7b..2305bfe66a1 100644 --- a/msvc/libmonoruntime.vcxproj +++ b/msvc/libmonoruntime.vcxproj @@ -30,6 +30,7 @@ + @@ -137,6 +138,8 @@ + + diff --git a/msvc/libmonoruntime.vcxproj.filters b/msvc/libmonoruntime.vcxproj.filters index bc9a0c35fb6..62ffe0bef5f 100644 --- a/msvc/libmonoruntime.vcxproj.filters +++ b/msvc/libmonoruntime.vcxproj.filters @@ -253,6 +253,9 @@ Source Files + + Source Files + Source Files @@ -324,6 +327,12 @@ Header Files + + Header Files + + + Header Files + Header Files diff --git a/msvc/pedump.vcxproj b/msvc/pedump.vcxproj index 57b84fab14f..fded8b5ffe6 100644 --- a/msvc/pedump.vcxproj +++ b/msvc/pedump.vcxproj @@ -214,6 +214,7 @@ + diff --git a/msvc/pedump.vcxproj.filters b/msvc/pedump.vcxproj.filters index 9f25b8211b5..5b01ceb1a56 100644 --- a/msvc/pedump.vcxproj.filters +++ b/msvc/pedump.vcxproj.filters @@ -103,6 +103,9 @@ Source Files + + Source Files + diff --git a/support/supportw.c b/support/supportw.c index 51b49697152..247f310c23b 100644 --- a/support/supportw.c +++ b/support/supportw.c @@ -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; diff --git a/tools/monograph/Makefile.am b/tools/monograph/Makefile.am index 3c52afc6634..1a53e3772b7 100644 --- a/tools/monograph/Makefile.am +++ b/tools/monograph/Makefile.am @@ -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) diff --git a/tools/pedump/Makefile.am b/tools/pedump/Makefile.am index d329d1fa9b1..4fb8260abdb 100644 --- a/tools/pedump/Makefile.am +++ b/tools/pedump/Makefile.am @@ -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) \