[reflection] Use coop handles for MonoMethod icalls (#4272)
[mono.git] / mono / io-layer / posix.c
index a7781bdd7bd544a80d58dad401d0f57a37eb5d11..995795bb32614fa12c11936e497f01991ef1c231 100644 (file)
@@ -6,6 +6,8 @@
  *
  * (C) 2002 Ximian, Inc.
  * Copyright (c) 2002-2009 Novell, Inc.
+ * Copyright 2011 Xamarin Inc
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
 
 #include <mono/io-layer/wapi.h>
 #include <mono/io-layer/wapi-private.h>
-#include <mono/io-layer/handles-private.h>
 #include <mono/io-layer/io-private.h>
+#include <mono/io-layer/io-trace.h>
+#include <mono/utils/mono-logger-internals.h>
+#include <mono/metadata/w32handle.h>
 
 static guint32
 convert_from_flags(int flags)
@@ -39,9 +43,7 @@ convert_from_flags(int flags)
        } else if ((flags & O_ACCMODE) == O_RDWR) {
                fileaccess=GENERIC_READ|GENERIC_WRITE;
        } else {
-#ifdef DEBUG
-               g_message("%s: Can't figure out flags 0x%x", __func__, flags);
-#endif
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Can't figure out flags 0x%x", __func__, flags);
        }
 
        /* Maybe sort out create mode too */
@@ -56,10 +58,8 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
        gpointer handle;
        int flags;
        
-#ifdef DEBUG
-       g_message("%s: creating standard handle type %s, fd %d", __func__,
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: creating standard handle type %s, fd %d", __func__,
                  name, fd);
-#endif
 
 #if !defined(__native_client__)        
        /* Check if fd is valid */
@@ -71,10 +71,8 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
                /* Invalid fd.  Not really much point checking for EBADF
                 * specifically
                 */
-#ifdef DEBUG
-               g_message("%s: fcntl error on fd %d: %s", __func__, fd,
+               MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: fcntl error on fd %d: %s", __func__, fd,
                          strerror(errno));
-#endif
 
                SetLastError (_wapi_get_win32_file_error (errno));
                return(INVALID_HANDLE_VALUE);
@@ -88,6 +86,7 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
        file_handle.fileaccess = (fd == STDIN_FILENO) ? GENERIC_READ : GENERIC_WRITE;
 #endif
 
+       file_handle.fd = fd;
        file_handle.filename = g_strdup(name);
        /* some default security attributes might be needed */
        file_handle.security_attributes=0;
@@ -102,16 +101,14 @@ gpointer _wapi_stdhandle_create (int fd, const gchar *name)
        file_handle.sharemode=0;
        file_handle.attrs=0;
 
-       handle = _wapi_handle_new_fd (WAPI_HANDLE_CONSOLE, fd, &file_handle);
-       if (handle == _WAPI_HANDLE_INVALID) {
+       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);
                return(INVALID_HANDLE_VALUE);
        }
        
-#ifdef DEBUG
-       g_message("%s: returning handle %p", __func__, handle);
-#endif
+       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning handle %p", __func__, handle);
 
        return(handle);
 }