Merge pull request #778 from cmorris98/master
[mono.git] / mono / mini / mini-posix.c
1 /*
2  * mini-posix.c: POSIX signal handling support for Mono.
3  *
4  * Authors:
5  *   Mono Team (mono-list@lists.ximian.com)
6  *
7  * Copyright 2001-2003 Ximian, Inc.
8  * Copyright 2003-2008 Ximian, Inc.
9  * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
10  *
11  * See LICENSE for licensing information.
12  */
13 #include <config.h>
14 #include <signal.h>
15 #ifdef HAVE_ALLOCA_H
16 #include <alloca.h>
17 #endif
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #include <math.h>
22 #ifdef HAVE_SYS_TIME_H
23 #include <sys/time.h>
24 #endif
25 #ifdef HAVE_SYS_SYSCALL_H
26 #include <sys/syscall.h>
27 #endif
28
29 #include <mono/metadata/assembly.h>
30 #include <mono/metadata/loader.h>
31 #include <mono/metadata/tabledefs.h>
32 #include <mono/metadata/class.h>
33 #include <mono/metadata/object.h>
34 #include <mono/metadata/tokentype.h>
35 #include <mono/metadata/tabledefs.h>
36 #include <mono/metadata/threads.h>
37 #include <mono/metadata/appdomain.h>
38 #include <mono/metadata/debug-helpers.h>
39 #include <mono/io-layer/io-layer.h>
40 #include "mono/metadata/profiler.h"
41 #include <mono/metadata/profiler-private.h>
42 #include <mono/metadata/mono-config.h>
43 #include <mono/metadata/environment.h>
44 #include <mono/metadata/mono-debug.h>
45 #include <mono/metadata/gc-internal.h>
46 #include <mono/metadata/threads-types.h>
47 #include <mono/metadata/verify.h>
48 #include <mono/metadata/verify-internals.h>
49 #include <mono/metadata/mempool-internals.h>
50 #include <mono/metadata/attach.h>
51 #include <mono/utils/mono-math.h>
52 #include <mono/utils/mono-compiler.h>
53 #include <mono/utils/mono-counters.h>
54 #include <mono/utils/mono-logger-internal.h>
55 #include <mono/utils/mono-mmap.h>
56 #include <mono/utils/dtrace.h>
57 #include <mono/utils/mono-signal-handler.h>
58
59 #include "mini.h"
60 #include <string.h>
61 #include <ctype.h>
62 #include "trace.h"
63 #include "version.h"
64 #include "debugger-agent.h"
65
66 #include "jit-icalls.h"
67
68 #if defined(__native_client__)
69
70 void
71 mono_runtime_setup_stat_profiler (void)
72 {
73         printf("WARNING: mono_runtime_setup_stat_profiler() called!\n");
74 }
75
76
77 void
78 mono_runtime_shutdown_stat_profiler (void)
79 {
80 }
81
82
83 gboolean
84 SIG_HANDLER_SIGNATURE (mono_chain_signal)
85 {
86         return FALSE;
87 }
88
89 void
90 mono_runtime_install_handlers (void)
91 {
92 }
93
94 void
95 mono_runtime_shutdown_handlers (void)
96 {
97 }
98
99 void
100 mono_runtime_cleanup_handlers (void)
101 {
102 }
103
104 pid_t
105 mono_runtime_syscall_fork (void)
106 {
107         g_assert_not_reached();
108         return 0;
109 }
110
111 void
112 mono_gdb_render_native_backtraces (pid_t crashed_pid)
113 {
114 }
115
116 #else
117
118 static GHashTable *mono_saved_signal_handlers = NULL;
119
120 static gpointer
121 get_saved_signal_handler (int signo)
122 {
123         if (mono_saved_signal_handlers)
124                 /* The hash is only modified during startup, so no need for locking */
125                 return g_hash_table_lookup (mono_saved_signal_handlers, GINT_TO_POINTER (signo));
126         return NULL;
127 }
128
129 static void
130 save_old_signal_handler (int signo, struct sigaction *old_action)
131 {
132         struct sigaction *handler_to_save = g_malloc (sizeof (struct sigaction));
133
134         mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_CONFIG,
135                                 "Saving old signal handler for signal %d.", signo);
136
137         if (! (old_action->sa_flags & SA_SIGINFO)) {
138                 handler_to_save->sa_handler = old_action->sa_handler;
139         } else {
140 #ifdef MONO_ARCH_USE_SIGACTION
141                 handler_to_save->sa_sigaction = old_action->sa_sigaction;
142 #endif /* MONO_ARCH_USE_SIGACTION */
143         }
144         handler_to_save->sa_mask = old_action->sa_mask;
145         handler_to_save->sa_flags = old_action->sa_flags;
146         
147         if (!mono_saved_signal_handlers)
148                 mono_saved_signal_handlers = g_hash_table_new (NULL, NULL);
149         g_hash_table_insert (mono_saved_signal_handlers, GINT_TO_POINTER (signo), handler_to_save);
150 }
151
152 static void
153 free_saved_sig_handler_func (gpointer key, gpointer value, gpointer user_data)
154 {
155         g_free (value);
156 }
157
158 static void
159 free_saved_signal_handlers (void)
160 {
161         if (mono_saved_signal_handlers) {
162                 g_hash_table_foreach (mono_saved_signal_handlers, free_saved_sig_handler_func, NULL);
163                 g_hash_table_destroy (mono_saved_signal_handlers);
164                 mono_saved_signal_handlers = NULL;
165         }
166 }
167
168 /*
169  * mono_chain_signal:
170  *
171  *   Call the original signal handler for the signal given by the arguments, which
172  * should be the same as for a signal handler. Returns TRUE if the original handler
173  * was called, false otherwise.
174  */
175 gboolean
176 SIG_HANDLER_SIGNATURE (mono_chain_signal)
177 {
178         int signal = _dummy;
179         struct sigaction *saved_handler = get_saved_signal_handler (signal);
180
181         GET_CONTEXT;
182
183         if (saved_handler && saved_handler->sa_handler) {
184                 if (!(saved_handler->sa_flags & SA_SIGINFO)) {
185                         saved_handler->sa_handler (signal);
186                 } else {
187 #ifdef MONO_ARCH_USE_SIGACTION
188                         saved_handler->sa_sigaction (signal, info, ctx);
189 #endif /* MONO_ARCH_USE_SIGACTION */
190                 }
191                 return TRUE;
192         }
193         return FALSE;
194 }
195
196 SIG_HANDLER_FUNC (static, sigabrt_signal_handler)
197 {
198         MonoJitInfo *ji = NULL;
199         GET_CONTEXT;
200
201         if (mono_thread_internal_current ())
202                 ji = mono_jit_info_table_find (mono_domain_get (), mono_arch_ip_from_context(ctx));
203         if (!ji) {
204         if (mono_chain_signal (SIG_HANDLER_PARAMS))
205                         return;
206                 mono_handle_native_sigsegv (SIGABRT, ctx);
207         }
208 }
209
210 SIG_HANDLER_FUNC (static, sigusr1_signal_handler)
211 {
212         gboolean running_managed;
213         MonoException *exc;
214         MonoInternalThread *thread = mono_thread_internal_current ();
215         MonoDomain *domain = mono_domain_get ();
216         void *ji;
217         
218         GET_CONTEXT;
219
220         if (!thread || !domain) {
221                 /* The thread might not have started up yet */
222                 /* FIXME: Specify the synchronization with start_wrapper () in threads.c */
223                 mono_debugger_agent_thread_interrupt (ctx, NULL);
224                 return;
225         }
226
227         if (thread->ignore_next_signal) {
228                 thread->ignore_next_signal = FALSE;
229                 return;
230         }
231
232         if (thread->thread_dump_requested) {
233                 thread->thread_dump_requested = FALSE;
234
235                 mono_print_thread_dump (ctx);
236         }
237
238         /*
239          * This is an async signal, so the code below must not call anything which
240          * is not async safe. That includes the pthread locking functions. If we
241          * know that we interrupted managed code, then locking is safe.
242          */
243         /*
244          * On OpenBSD, ctx can be NULL if we are interrupting poll ().
245          */
246         if (ctx) {
247                 ji = mono_jit_info_table_find (mono_domain_get (), mono_arch_ip_from_context(ctx));
248                 running_managed = ji != NULL;
249
250                 if (mono_debugger_agent_thread_interrupt (ctx, ji))
251                         return;
252         } else {
253                 running_managed = FALSE;
254         }
255
256         /* We can't do handler block checking from metadata since it requires doing
257          * a stack walk with context.
258          *
259          * FIXME add full-aot support.
260          */
261 #ifdef MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX
262         if (!mono_aot_only && ctx) {
263                 MonoThreadUnwindState unwind_state;
264                 if (mono_thread_state_init_from_sigctx (&unwind_state, ctx)) {
265                         if (mono_install_handler_block_guard (&unwind_state)) {
266 #ifndef HOST_WIN32
267                                 /*Clear current thread from been wapi interrupted otherwise things can go south*/
268                                 wapi_clear_interruption ();
269 #endif
270                                 return;
271                         }
272                 }
273         }
274 #endif
275
276         exc = mono_thread_request_interruption (running_managed); 
277         if (!exc)
278                 return;
279
280         mono_arch_handle_exception (ctx, exc);
281 }
282
283
284 #if defined(__i386__) || defined(__x86_64__)
285 #define FULL_STAT_PROFILER_BACKTRACE 1
286 #define CURRENT_FRAME_GET_BASE_POINTER(f) (* (gpointer*)(f))
287 #define CURRENT_FRAME_GET_RETURN_ADDRESS(f) (* (((gpointer*)(f)) + 1))
288 #if MONO_ARCH_STACK_GROWS_UP
289 #define IS_BEFORE_ON_STACK <
290 #define IS_AFTER_ON_STACK >
291 #else
292 #define IS_BEFORE_ON_STACK >
293 #define IS_AFTER_ON_STACK <
294 #endif
295 #else
296 #define FULL_STAT_PROFILER_BACKTRACE 0
297 #endif
298
299 #if defined(__ia64__) || defined(__sparc__) || defined(sparc) || defined(__s390__) || defined(s390)
300
301 SIG_HANDLER_FUNC (static, sigprof_signal_handler)
302 {
303         if (mono_chain_signal (SIG_HANDLER_PARAMS))
304                 return;
305
306         NOT_IMPLEMENTED;
307 }
308
309 #else
310
311 SIG_HANDLER_FUNC (static, sigprof_signal_handler)
312 {
313         int call_chain_depth = mono_profiler_stat_get_call_chain_depth ();
314         MonoProfilerCallChainStrategy call_chain_strategy = mono_profiler_stat_get_call_chain_strategy ();
315         GET_CONTEXT;
316         
317         if (call_chain_depth == 0) {
318                 mono_profiler_stat_hit (mono_arch_ip_from_context (ctx), ctx);
319         } else {
320                 MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
321                 int current_frame_index = 1;
322                 MonoContext mono_context;
323                 guchar *ips [call_chain_depth + 1];
324
325                 mono_arch_sigctx_to_monoctx (ctx, &mono_context);
326                 ips [0] = MONO_CONTEXT_GET_IP (&mono_context);
327                 
328                 if (jit_tls != NULL) {
329                         if (call_chain_strategy == MONO_PROFILER_CALL_CHAIN_NATIVE) {
330 #if FULL_STAT_PROFILER_BACKTRACE
331                         guchar *current_frame;
332                         guchar *stack_bottom;
333                         guchar *stack_top;
334                         
335                         stack_bottom = jit_tls->end_of_stack;
336                         stack_top = MONO_CONTEXT_GET_SP (&mono_context);
337                         current_frame = MONO_CONTEXT_GET_BP (&mono_context);
338                         
339                         while ((current_frame_index <= call_chain_depth) &&
340                                         (stack_bottom IS_BEFORE_ON_STACK (guchar*) current_frame) &&
341                                         ((guchar*) current_frame IS_BEFORE_ON_STACK stack_top)) {
342                                 ips [current_frame_index] = CURRENT_FRAME_GET_RETURN_ADDRESS (current_frame);
343                                 current_frame_index ++;
344                                 stack_top = current_frame;
345                                 current_frame = CURRENT_FRAME_GET_BASE_POINTER (current_frame);
346                         }
347 #else
348                                 call_chain_strategy = MONO_PROFILER_CALL_CHAIN_GLIBC;
349 #endif
350                         }
351                         
352                         if (call_chain_strategy == MONO_PROFILER_CALL_CHAIN_GLIBC) {
353 #if GLIBC_PROFILER_BACKTRACE
354                                 current_frame_index = backtrace ((void**) & ips [1], call_chain_depth);
355 #else
356                                 call_chain_strategy = MONO_PROFILER_CALL_CHAIN_MANAGED;
357 #endif
358                         }
359
360                         if (call_chain_strategy == MONO_PROFILER_CALL_CHAIN_MANAGED) {
361                                 MonoDomain *domain = mono_domain_get ();
362                                 if (domain != NULL) {
363                                         MonoLMF *lmf = NULL;
364                                         MonoJitInfo *ji;
365                                         MonoJitInfo res;
366                                         MonoContext new_mono_context;
367                                         int native_offset;
368                                         ji = mono_find_jit_info (domain, jit_tls, &res, NULL, &mono_context,
369                                                         &new_mono_context, NULL, &lmf, &native_offset, NULL);
370                                         while ((ji != NULL) && (current_frame_index <= call_chain_depth)) {
371                                                 ips [current_frame_index] = MONO_CONTEXT_GET_IP (&new_mono_context);
372                                                 current_frame_index ++;
373                                                 mono_context = new_mono_context;
374                                                 ji = mono_find_jit_info (domain, jit_tls, &res, NULL, &mono_context,
375                                                                 &new_mono_context, NULL, &lmf, &native_offset, NULL);
376                                         }
377                                 }
378                         }
379                 }
380                 
381                 mono_profiler_stat_call_chain (current_frame_index, & ips [0], ctx);
382         }
383
384         mono_chain_signal (SIG_HANDLER_PARAMS);
385 }
386
387 #endif
388
389 SIG_HANDLER_FUNC (static, sigquit_signal_handler)
390 {
391         gboolean res;
392
393         GET_CONTEXT;
394
395         /* We use this signal to start the attach agent too */
396         res = mono_attach_start ();
397         if (res)
398                 return;
399
400         if (mono_thread_info_new_interrupt_enabled ()) {
401                 mono_threads_request_thread_dump ();
402         } else {
403                 printf ("Full thread dump:\n");
404
405                 mono_threads_request_thread_dump ();
406
407                 /*
408                  * print_thread_dump () skips the current thread, since sending a signal
409                  * to it would invoke the signal handler below the sigquit signal handler,
410                  * and signal handlers don't create an lmf, so the stack walk could not
411                  * be performed.
412                  */
413                 mono_print_thread_dump (ctx);
414         }
415
416         mono_chain_signal (SIG_HANDLER_PARAMS);
417 }
418
419 SIG_HANDLER_FUNC (static, sigusr2_signal_handler)
420 {
421         gboolean enabled = mono_trace_is_enabled ();
422
423         mono_trace_enable (!enabled);
424
425         mono_chain_signal (SIG_HANDLER_PARAMS);
426 }
427
428 static void
429 add_signal_handler (int signo, gpointer handler)
430 {
431         struct sigaction sa;
432         struct sigaction previous_sa;
433
434 #ifdef MONO_ARCH_USE_SIGACTION
435         sa.sa_sigaction = handler;
436         sigemptyset (&sa.sa_mask);
437         sa.sa_flags = SA_SIGINFO;
438 #ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
439
440 /*Apple likes to deliver SIGBUS for *0 */
441 #ifdef __APPLE__
442         if (signo == SIGSEGV || signo == SIGBUS) {
443 #else
444         if (signo == SIGSEGV) {
445 #endif
446                 sa.sa_flags |= SA_ONSTACK;
447
448                 /* 
449                  * libgc will crash when trying to do stack marking for threads which are on
450                  * an altstack, so delay the suspend signal after the signal handler has
451                  * executed.
452                  */
453                 if (mono_gc_get_suspend_signal () != -1)
454                         sigaddset (&sa.sa_mask, mono_gc_get_suspend_signal ());
455         }
456 #endif
457         if (signo == SIGSEGV) {
458                 /* 
459                  * Delay abort signals while handling SIGSEGVs since they could go unnoticed.
460                  */
461                 sigset_t block_mask;
462      
463                 sigemptyset (&block_mask);
464                 sigaddset (&sa.sa_mask, mono_thread_get_abort_signal ());
465         }
466 #else
467         sa.sa_handler = handler;
468         sigemptyset (&sa.sa_mask);
469         sa.sa_flags = 0;
470 #endif
471         g_assert (sigaction (signo, &sa, &previous_sa) != -1);
472
473         /* if there was already a handler in place for this signal, store it */
474         if (! (previous_sa.sa_flags & SA_SIGINFO) &&
475                         (SIG_DFL == previous_sa.sa_handler)) { 
476                 /* it there is no sa_sigaction function and the sa_handler is default, we can safely ignore this */
477         } else {
478                 if (mono_do_signal_chaining)
479                         save_old_signal_handler (signo, &previous_sa);
480         }
481 }
482
483 static void
484 remove_signal_handler (int signo)
485 {
486         struct sigaction sa;
487         struct sigaction *saved_action = get_saved_signal_handler (signo);
488
489         if (!saved_action) {
490                 sa.sa_handler = SIG_DFL;
491                 sigemptyset (&sa.sa_mask);
492                 sa.sa_flags = 0;
493
494                 sigaction (signo, &sa, NULL);
495         } else {
496                 g_assert (sigaction (signo, saved_action, NULL) != -1);
497         }
498 }
499
500 void
501 mono_runtime_posix_install_handlers (void)
502 {
503
504         sigset_t signal_set;
505
506         if (mini_get_debug_options ()->handle_sigint)
507                 add_signal_handler (SIGINT, mono_sigint_signal_handler);
508
509         add_signal_handler (SIGFPE, mono_sigfpe_signal_handler);
510         add_signal_handler (SIGQUIT, sigquit_signal_handler);
511         add_signal_handler (SIGILL, mono_sigill_signal_handler);
512         add_signal_handler (SIGBUS, mono_sigsegv_signal_handler);
513         if (mono_jit_trace_calls != NULL)
514                 add_signal_handler (SIGUSR2, sigusr2_signal_handler);
515
516         if (!mono_thread_info_new_interrupt_enabled ())
517                 add_signal_handler (mono_thread_get_abort_signal (), sigusr1_signal_handler);
518         /* it seems to have become a common bug for some programs that run as parents
519          * of many processes to block signal delivery for real time signals.
520          * We try to detect and work around their breakage here.
521          */
522         sigemptyset (&signal_set);
523         sigaddset (&signal_set, mono_thread_get_abort_signal ());
524         sigprocmask (SIG_UNBLOCK, &signal_set, NULL);
525
526         signal (SIGPIPE, SIG_IGN);
527
528         add_signal_handler (SIGABRT, sigabrt_signal_handler);
529
530         /* catch SIGSEGV */
531         add_signal_handler (SIGSEGV, mono_sigsegv_signal_handler);
532 }
533
534 #ifndef PLATFORM_MACOSX
535 void
536 mono_runtime_install_handlers (void)
537 {
538         mono_runtime_posix_install_handlers ();
539 }
540 #endif
541
542 void
543 mono_runtime_cleanup_handlers (void)
544 {
545         if (mini_get_debug_options ()->handle_sigint)
546                 remove_signal_handler (SIGINT);
547
548         remove_signal_handler (SIGFPE);
549         remove_signal_handler (SIGQUIT);
550         remove_signal_handler (SIGILL);
551         remove_signal_handler (SIGBUS);
552         if (mono_jit_trace_calls != NULL)
553                 remove_signal_handler (SIGUSR2);
554
555         remove_signal_handler (mono_thread_get_abort_signal ());
556
557         remove_signal_handler (SIGABRT);
558
559         remove_signal_handler (SIGSEGV);
560
561         free_saved_signal_handlers ();
562 }
563
564 #ifdef HAVE_LINUX_RTC_H
565 #include <linux/rtc.h>
566 #include <sys/ioctl.h>
567 #include <fcntl.h>
568 static int rtc_fd = -1;
569
570 static int
571 enable_rtc_timer (gboolean enable)
572 {
573         int flags;
574         flags = fcntl (rtc_fd, F_GETFL);
575         if (flags < 0) {
576                 perror ("getflags");
577                 return 0;
578         }
579         if (enable)
580                 flags |= FASYNC;
581         else
582                 flags &= ~FASYNC;
583         if (fcntl (rtc_fd, F_SETFL, flags) == -1) {
584                 perror ("setflags");
585                 return 0;
586         }
587         return 1;
588 }
589 #endif
590
591 void
592 mono_runtime_shutdown_stat_profiler (void)
593 {
594 #ifdef HAVE_LINUX_RTC_H
595         if (rtc_fd >= 0)
596                 enable_rtc_timer (FALSE);
597 #endif
598 }
599
600 void
601 mono_runtime_setup_stat_profiler (void)
602 {
603 #ifdef ITIMER_PROF
604         struct itimerval itval;
605         static int inited = 0;
606 #ifdef HAVE_LINUX_RTC_H
607         const char *rtc_freq;
608         if (!inited && (rtc_freq = g_getenv ("MONO_RTC"))) {
609                 int freq = 0;
610                 inited = 1;
611                 if (*rtc_freq)
612                         freq = atoi (rtc_freq);
613                 if (!freq)
614                         freq = 1024;
615                 rtc_fd = open ("/dev/rtc", O_RDONLY);
616                 if (rtc_fd == -1) {
617                         perror ("open /dev/rtc");
618                         return;
619                 }
620                 add_signal_handler (SIGPROF, sigprof_signal_handler);
621                 if (ioctl (rtc_fd, RTC_IRQP_SET, freq) == -1) {
622                         perror ("set rtc freq");
623                         return;
624                 }
625                 if (ioctl (rtc_fd, RTC_PIE_ON, 0) == -1) {
626                         perror ("start rtc");
627                         return;
628                 }
629                 if (fcntl (rtc_fd, F_SETSIG, SIGPROF) == -1) {
630                         perror ("setsig");
631                         return;
632                 }
633                 if (fcntl (rtc_fd, F_SETOWN, getpid ()) == -1) {
634                         perror ("setown");
635                         return;
636                 }
637                 enable_rtc_timer (TRUE);
638                 return;
639         }
640         if (rtc_fd >= 0)
641                 return;
642 #endif
643
644         itval.it_interval.tv_usec = 999;
645         itval.it_interval.tv_sec = 0;
646         itval.it_value = itval.it_interval;
647         setitimer (ITIMER_PROF, &itval, NULL);
648         if (inited)
649                 return;
650         inited = 1;
651         add_signal_handler (SIGPROF, sigprof_signal_handler);
652 #endif
653 }
654
655 #if !defined(__APPLE__)
656 pid_t
657 mono_runtime_syscall_fork ()
658 {
659 #if defined(SYS_fork)
660         return (pid_t) syscall (SYS_fork);
661 #else
662         g_assert_not_reached ();
663         return 0;
664 #endif
665 }
666
667 void
668 mono_gdb_render_native_backtraces (pid_t crashed_pid)
669 {
670         const char *argv [9];
671         char template [] = "/tmp/mono-lldb-commands.XXXXXX";
672         char buf1 [128];
673         FILE *commands;
674         gboolean using_lldb = FALSE;
675
676         argv [0] = g_find_program_in_path ("gdb");
677         if (argv [0] == NULL) {
678                 argv [0] = g_find_program_in_path ("lldb");
679                 using_lldb = TRUE;
680         }
681
682         if (argv [0] == NULL)
683                 return;
684
685         if (using_lldb) {
686                 if (mkstemp (template) == -1)
687                         return;
688
689                 commands = fopen (template, "w");
690
691                 fprintf (commands, "process attach --pid %ld\n", (long) crashed_pid);
692                 fprintf (commands, "script lldb.debugger.HandleCommand (\"thread list\")\n");
693                 fprintf (commands, "script lldb.debugger.HandleCommand (\"thread backtrace all\")\n");
694                 fprintf (commands, "detach\n");
695                 fprintf (commands, "quit\n");
696
697                 fflush (commands);
698                 fclose (commands);
699
700                 argv [1] = "--source";
701                 argv [2] = template;
702                 argv [3] = 0;
703         } else {
704                 argv [1] = "-ex";
705                 sprintf (buf1, "attach %ld", (long) crashed_pid);
706                 argv [2] = buf1;
707                 argv [3] = "--ex";
708                 argv [4] = "info threads";
709                 argv [5] = "--ex";
710                 argv [6] = "thread apply all bt";
711                 argv [7] = "--batch";
712                 argv [8] = 0;
713         }
714
715         execv (argv [0], (char**)argv);
716
717         if (using_lldb)
718                 unlink (template);
719 }
720 #endif
721 #endif /* __native_client__ */
722
723 #if !defined (__MACH__)
724
725 gboolean
726 mono_thread_state_init_from_handle (MonoThreadUnwindState *tctx, MonoNativeThreadId thread_id, MonoNativeThreadHandle thread_handle)
727 {
728         g_error ("Posix systems don't support mono_thread_state_init_from_handle");
729         return FALSE;
730 }
731
732 #endif