[aot] Fix the emission of dwarf debug info.
[mono.git] / mono / metadata / attach.c
index c616d6df16f20dc64ba496f3d556b8741a3b1a29..0a053661b8e411892419e95a41ffa1bb3be6a0c0 100644 (file)
@@ -4,13 +4,13 @@
  * Author:
  *   Zoltan Varga (vargaz@gmail.com)
  *
- * (C) 2007-2008 Novell, Inc.
+ * Copyright 2007-2009 Novell, Inc (http://www.novell.com)
  */
 
 #include <config.h>
 #include <glib.h>
 
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
 #define DISABLE_ATTACH
 #endif
 #ifndef DISABLE_ATTACH
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <inttypes.h>
 #include <pwd.h>
 #include <errno.h>
 #include <netdb.h>
 #include <unistd.h>
 
-
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/threads-types.h>
 #include <mono/metadata/gc-internal.h>
+#include <mono/utils/mono-threads.h>
 #include "attach.h"
 
 /*
@@ -98,9 +99,9 @@ static gboolean stop_receiver_thread;
 
 static gboolean needs_to_start, started;
 
-#define agent_lock() EnterCriticalSection (&agent_mutex)
-#define agent_unlock() LeaveCriticalSection (&agent_mutex)
-static CRITICAL_SECTION agent_mutex;
+#define agent_lock() mono_mutex_lock (&agent_mutex)
+#define agent_unlock() mono_mutex_unlock (&agent_mutex)
+static mono_mutex_t agent_mutex;
 
 static void transport_connect (void);
 
@@ -192,7 +193,7 @@ mono_attach_parse_options (char *options)
 void
 mono_attach_init (void)
 {
-       InitializeCriticalSection (&agent_mutex);
+       mono_mutex_init_recursive (&agent_mutex);
 
        config.enabled = TRUE;
 }
@@ -220,7 +221,7 @@ mono_attach_start (void)
         * by creating it is to enable the attach mechanism if the process receives a 
         * SIGQUIT signal, which can only be sent by the owner/root.
         */
-       snprintf (path, sizeof (path), "/tmp/.mono_attach_pid%d", getpid ());
+       snprintf (path, sizeof (path), "/tmp/.mono_attach_pid%"PRIdMAX"", (intmax_t) getpid ());
        fd = open (path, O_RDONLY);
        if (fd == -1)
                return FALSE;
@@ -366,7 +367,12 @@ ipc_connect (void)
         */
        /* FIXME: Use TMP ? */
        pw = NULL;
+#ifdef HAVE_GETPWUID_R
        res = getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw);
+#else
+       pw = getpwuid(getuid ());
+       res = pw != NULL ? 0 : 1;
+#endif
        if (res != 0) {
                fprintf (stderr, "attach: getpwuid_r () failed.\n");
                return;
@@ -400,7 +406,7 @@ ipc_connect (void)
                }
        }
 
-       filename = g_strdup_printf ("%s/.mono-%d", directory, getpid ());
+       filename = g_strdup_printf ("%s/.mono-%"PRIdMAX"", directory, (intmax_t) getpid ());
        unlink (filename);
 
        /* Bind a name to the socket.   */
@@ -435,7 +441,7 @@ ipc_connect (void)
 
        ipc_filename = g_strdup (filename);
 
-       server_uri = g_strdup_printf ("unix://%s/.mono-%d?/vm", directory, getpid ());
+       server_uri = g_strdup_printf ("unix://%s/.mono-%"PRIdMAX"?/vm", directory, (intmax_t) getpid ());
 
        g_free (filename);
        g_free (directory);
@@ -468,14 +474,12 @@ transport_send (int fd, guint8 *data, int len)
 static void
 transport_start_receive (void)
 {
-       gsize tid;
-
        transport_connect ();
 
        if (!listen_fd)
                return;
 
-       receiver_thread_handle = CreateThread (NULL, 0, receiver_thread, NULL, 0, &tid);
+       receiver_thread_handle = mono_threads_create_thread (receiver_thread, NULL, 0, 0, NULL);
        g_assert (receiver_thread_handle);
 }
 
@@ -501,7 +505,7 @@ receiver_thread (void *arg)
                /* Ask the runtime to not abort this thread */
                //mono_thread_current ()->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
                /* Ask the runtime to not wait for this thread */
-               mono_thread_current ()->state |= ThreadState_Background;
+               mono_thread_internal_current ()->state |= ThreadState_Background;
 
                while (TRUE) {
                        char *cmd, *agent_name, *agent_args;