[runtime] Remove unused MONO_ARCH_SAVE_REGS declarations.
[mono.git] / mono / metadata / console-unix.c
index 0808baabc2d15bfcc425cb593a5eff22e1397b87..6803eaf82e7454acb906a3bea308cdb3d7f685c4 100644 (file)
@@ -6,6 +6,9 @@
  *
  * Copyright (C) 2005-2009 Novell, Inc. (http://www.novell.com)
  */
+#if defined(__native_client__)
+#include "console-null.c"
+#else
 
 #include <config.h>
 #include <glib.h>
@@ -14,6 +17,9 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <signal.h>
+#ifdef HAVE_SYS_SELECT_H
+#    include <sys/select.h>
+#endif
 #ifdef HAVE_SYS_TIME_H
 #    include <sys/time.h>
 #endif
 #include <mono/metadata/object-internals.h>
 #include <mono/metadata/class-internals.h>
 #include <mono/metadata/domain-internals.h>
+#include <mono/metadata/gc-internal.h>
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/threadpool.h>
+#include <mono/utils/mono-signal-handler.h>
+#include <mono/utils/mono-proclib.h>
 
 /* On solaris, curses.h must come before both termios.h and term.h */
 #ifdef HAVE_CURSES_H
@@ -85,8 +94,6 @@ static struct termios initial_attr;
 MonoBoolean
 ves_icall_System_ConsoleDriver_Isatty (HANDLE handle)
 {
-       MONO_ARCH_SAVE_REGS;
-
        return isatty (GPOINTER_TO_INT (handle));
 }
 
@@ -97,8 +104,6 @@ set_property (gint property, gboolean value)
        gboolean callset = FALSE;
        gboolean check;
        
-       MONO_ARCH_SAVE_REGS;
-
        if (tcgetattr (STDIN_FILENO, &attr) == -1)
                return FALSE;
 
@@ -143,8 +148,6 @@ ves_icall_System_ConsoleDriver_InternalKeyAvailable (gint32 timeout)
        div_t divvy;
        int ret, nbytes;
 
-       MONO_ARCH_SAVE_REGS;
-
        do {
                FD_ZERO (&rfds);
                FD_SET (STDIN_FILENO, &rfds);
@@ -197,13 +200,13 @@ terminal_get_dimensions (void)
 static void
 tty_teardown (void)
 {
-       MONO_ARCH_SAVE_REGS;
+       int unused;
 
        if (!setup_finished)
                return;
 
        if (teardown_str != NULL) {
-               write (STDOUT_FILENO, teardown_str, strlen (teardown_str));
+               unused = write (STDOUT_FILENO, teardown_str, strlen (teardown_str));
                g_free (teardown_str);
                teardown_str = NULL;
        }
@@ -226,6 +229,7 @@ do_console_cancel_event (void)
        MonoMethod *im;
        MonoVTable *vtable;
 
+       /* FIXME: this should likely iterate all the domains, instead */
        if (!domain->domain)
                return;
 
@@ -253,43 +257,53 @@ do_console_cancel_event (void)
        mono_thread_pool_add ((MonoObject *) load_value, msg, NULL, NULL);
 }
 
+static int need_cancel = FALSE;
+/* this is executed from the finalizer thread */
+void
+mono_console_handle_async_ops (void)
+{
+       if (need_cancel) {
+               need_cancel = FALSE;
+               do_console_cancel_event ();
+       }
+}
+
 static gboolean in_sigint;
-static void
-sigint_handler (int signo)
+
+MONO_SIG_HANDLER_FUNC (static, sigint_handler)
 {
        int save_errno;
-       MONO_ARCH_SAVE_REGS;
 
        if (in_sigint)
                return;
 
        in_sigint = TRUE;
        save_errno = errno;
-       do_console_cancel_event ();
+       need_cancel = TRUE;
+       mono_gc_finalize_notify ();
        errno = save_errno;
        in_sigint = FALSE;
 }
 
 static struct sigaction save_sigcont, save_sigint, save_sigwinch;
 
-static void
-sigcont_handler (int signo, void *the_siginfo, void *data)
+MONO_SIG_HANDLER_FUNC (static, sigcont_handler)
 {
+       int unused;
        // Ignore error, there is not much we can do in the sigcont handler.
        tcsetattr (STDIN_FILENO, TCSANOW, &mono_attr);
 
        if (keypad_xmit_str != NULL)
-               write (STDOUT_FILENO, keypad_xmit_str, strlen (keypad_xmit_str));
+               unused = write (STDOUT_FILENO, keypad_xmit_str, strlen (keypad_xmit_str));
 
        // Call previous handler
        if (save_sigcont.sa_sigaction != NULL &&
            save_sigcont.sa_sigaction != (void *)SIG_DFL &&
            save_sigcont.sa_sigaction != (void *)SIG_IGN)
-               (*save_sigcont.sa_sigaction) (signo, the_siginfo, data);
+               (*save_sigcont.sa_sigaction) (MONO_SIG_HANDLER_PARAMS);
 }
 
-static void
-sigwinch_handler (int signo, void *the_siginfo, void *data)
+MONO_SIG_HANDLER_FUNC (static, sigwinch_handler)
 {
        int dims = terminal_get_dimensions ();
        if (dims != -1)
@@ -299,7 +313,7 @@ sigwinch_handler (int signo, void *the_siginfo, void *data)
        if (save_sigwinch.sa_sigaction != NULL &&
            save_sigwinch.sa_sigaction != (void *)SIG_DFL &&
            save_sigwinch.sa_sigaction != (void *)SIG_IGN)
-               (*save_sigwinch.sa_sigaction) (signo, the_siginfo, data);
+               (*save_sigwinch.sa_sigaction) (MONO_SIG_HANDLER_PARAMS);
 }
 
 /*
@@ -338,7 +352,7 @@ console_set_signal_handlers ()
        sigaction (SIGCONT, &sigcont, &save_sigcont);
        
        // Interrupt handler
-       sigint.sa_handler = sigint_handler;
+       sigint.sa_handler = (void *) sigint_handler;
        sigint.sa_flags = 0;
        sigemptyset (&sigint.sa_mask);
        sigaction (SIGINT, &sigint, &save_sigint);
@@ -426,16 +440,14 @@ ves_icall_System_ConsoleDriver_TtySetup (MonoString *keypad, MonoString *teardow
 {
        int dims;
 
-       MONO_ARCH_SAVE_REGS;
-
        dims = terminal_get_dimensions ();
        if (dims == -1){
                int cols = 0, rows = 0;
                                      
-               char *str = getenv ("COLUMNS");
+               const char *str = g_getenv ("COLUMNS");
                if (str != NULL)
                        cols = atoi (str);
-               str = getenv ("LINES");
+               str = g_getenv ("LINES");
                if (str != NULL)
                        rows = atoi (str);
 
@@ -480,8 +492,10 @@ ves_icall_System_ConsoleDriver_TtySetup (MonoString *keypad, MonoString *teardow
                if (teardown != NULL)
                        teardown_str = mono_string_to_utf8 (teardown);
 
-               atexit (tty_teardown);
+               mono_atexit (tty_teardown);
        }
 
        return TRUE;
 }
+#endif /* #if defined(__native_client__) */
+