Use lower-case names for Windows headers.
[mono.git] / mono / utils / mono-threads-mach-abort-syscall.c
1 /*
2  * mono-threads-mach-abort-syscall.c: Low-level syscall aborting
3  *
4  * Author:
5  *      Ludovic Henry (ludovic@xamarin.com)
6  *
7  * (C) 2015 Xamarin, Inc
8  */
9
10 #include "config.h"
11 #include <glib.h>
12
13 #if defined (__MACH__)
14 #define _DARWIN_C_SOURCE 1
15 #endif
16
17 #include <mono/utils/mono-threads.h>
18
19 #if defined(USE_MACH_BACKEND)
20
21 #if defined(HOST_WATCHOS) || defined(HOST_TVOS)
22
23 void
24 mono_threads_abort_syscall_init (void)
25 {
26 }
27
28 void
29 mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
30 {
31
32 }
33
34 gboolean
35 mono_threads_suspend_needs_abort_syscall (void)
36 {
37         return FALSE;
38 }
39
40 #else
41
42 void
43 mono_threads_abort_syscall_init (void)
44 {
45 }
46
47 void
48 mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
49 {
50         kern_return_t ret;
51
52         do {
53                 ret = thread_suspend (info->native_handle);
54         } while (ret == KERN_ABORTED);
55
56         if (ret != KERN_SUCCESS)
57                 return;
58
59         do {
60                 ret = thread_abort_safely (info->native_handle);
61         } while (ret == KERN_ABORTED);
62
63         /*
64          * We are doing thread_abort when thread_abort_safely returns KERN_SUCCESS because
65          * for some reason accept is not interrupted by thread_abort_safely.
66          * The risk of aborting non-atomic operations while calling thread_abort should not
67          * exist because by the time thread_abort_safely returns KERN_SUCCESS the target
68          * thread should have return from the kernel and should be waiting for thread_resume
69          * to resume the user code.
70          */
71         if (ret == KERN_SUCCESS)
72                 ret = thread_abort (info->native_handle);
73
74         do {
75                 ret = thread_resume (info->native_handle);
76         } while (ret == KERN_ABORTED);
77
78         g_assert (ret == KERN_SUCCESS);
79 }
80
81 gboolean
82 mono_threads_suspend_needs_abort_syscall (void)
83 {
84         return TRUE;
85 }
86
87 #endif
88
89 #endif