* 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"
/*
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);
static void transport_start_receive (void);
-static void maybe_start (gpointer user_data);
-
/*
* Functions to decode protocol data
*/
return (((int)buf [0]) << 0) | (((int)buf [1]) << 8) | (((int)buf [2]) << 16) | (((int)buf [3]) << 24);
}
-static inline int
-decode_short (guint8 *buf, guint8 **endbuf, guint8 *limit)
-{
- *endbuf = buf + 2;
- g_assert (*endbuf <= limit);
-
- return (((int)buf [0]) << 0) | (((int)buf [1]) << 8);
-}
-
static char*
decode_string_value (guint8 *buf, guint8 **endbuf, guint8 *limit)
{
void
mono_attach_parse_options (char *options)
{
- config.enabled = TRUE;
-
if (!options)
return;
if (!strcmp (options, "disable"))
void
mono_attach_init (void)
{
- InitializeCriticalSection (&agent_mutex);
+ mono_mutex_init_recursive (&agent_mutex);
-#ifndef HAVE_NULL_GC
- mono_gc_add_finalizer_thread_callback (maybe_start, NULL);
-#endif
+ config.enabled = TRUE;
}
/**
* 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;
* do the actual startup.
*/
needs_to_start = TRUE;
- // FIXME: This is not actually signal-safe
mono_gc_finalize_notify ();
return TRUE;
}
/* Called by the finalizer thread when it is woken up */
-static void
-maybe_start (gpointer user_data)
+void
+mono_attach_maybe_start (void)
{
if (!needs_to_start)
return;
*/
/* 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;
}
}
- 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. */
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);
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);
}
/* 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;
return FALSE;
}
+void
+mono_attach_maybe_start (void)
+{
+}
+
void
mono_attach_cleanup (void)
{