Update mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
[mono.git] / mono / utils / mach-support-arm.c
1 /*
2  * mach-support-arm.c: mach support for ARM
3  *
4  * Authors:
5  *   Geoff Norton (gnorton@novell.com)
6  *   Rodrigo Kumpera (kumpera@gmail.com)
7  *
8  * (C) 2010 Novell, Inc.
9  * (C) 2011 Xamarin, Inc.
10  */
11
12 #include <config.h>
13
14 #if defined(__MACH__)
15 #include <stdint.h>
16 #include <glib.h>
17 #include <pthread.h>
18 #include "utils/mono-sigcontext.h"
19 #include "mach-support.h"
20
21 void *
22 mono_mach_arch_get_ip (thread_state_t state)
23 {
24         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
25
26         return (void *) arch_state->__pc;
27 }
28
29 void *
30 mono_mach_arch_get_sp (thread_state_t state)
31 {
32         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
33
34         return (void *) arch_state->__sp;
35 }
36
37 int
38 mono_mach_arch_get_mcontext_size ()
39 {
40         return sizeof (struct __darwin_mcontext);
41 }
42
43 void
44 mono_mach_arch_thread_state_to_mcontext (thread_state_t state, mcontext_t context)
45 {
46         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
47         struct __darwin_mcontext *ctx = (struct __darwin_mcontext *) context;
48
49         ctx->__ss = *arch_state;
50 }
51
52 void
53 mono_mach_arch_mcontext_to_thread_state (mcontext_t context, thread_state_t state)
54 {
55         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
56         struct __darwin_mcontext *ctx = (struct __darwin_mcontext *) context;
57
58         *arch_state = ctx->__ss;
59 }
60
61 int
62 mono_mach_arch_get_thread_state_size ()
63 {
64         return sizeof (arm_thread_state_t);
65 }
66
67 kern_return_t
68 mono_mach_arch_get_thread_state (thread_port_t thread, thread_state_t state, mach_msg_type_number_t *count)
69 {
70         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
71         kern_return_t ret;
72
73         *count = ARM_THREAD_STATE_COUNT;
74
75         ret = thread_get_state (thread, ARM_THREAD_STATE_COUNT, (thread_state_t) arch_state, count);
76
77         return ret;
78 }
79
80 kern_return_t
81 mono_mach_arch_set_thread_state (thread_port_t thread, thread_state_t state, mach_msg_type_number_t count)
82 {
83         return thread_set_state (thread, ARM_THREAD_STATE_COUNT, state, count);
84 }
85
86 void *
87 mono_mach_get_tls_address_from_thread (pthread_t thread, pthread_key_t key)
88 {
89         /* OSX stores TLS values in a hidden array inside the pthread_t structure
90          * They are keyed off a giant array offset 0x48 into the pointer.  This value
91          * is baked into their pthread_getspecific implementation
92          */
93         intptr_t *p = (intptr_t *) thread;
94         intptr_t **tsd = (intptr_t **) ((char*)p + 0x48 + (key << 2));
95
96         return (void *)tsd;
97 }
98
99 void *
100 mono_mach_arch_get_tls_value_from_thread (pthread_t thread, guint32 key)
101 {
102         return *(void**)mono_mach_get_tls_address_from_thread (thread, key);
103 }
104
105 #endif