[xbuild] Add new reserved properties $(MSBuildThisFile*).
[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  *
7  * (C) 2010 Novell, Inc.
8  */
9
10 #include <config.h>
11
12 #if defined(__MACH__)
13 #include <stdint.h>
14 #include <glib.h>
15 #include <pthread.h>
16 #include "utils/mono-sigcontext.h"
17 #include "mach-support.h"
18
19 void *
20 mono_mach_arch_get_ip (thread_state_t state)
21 {
22         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
23
24         return (void *) arch_state->__eip;
25 }
26
27 void *
28 mono_mach_arch_get_sp (thread_state_t state)
29 {
30         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
31
32         return (void *) arch_state->__esp;
33 }
34
35 int
36 mono_mach_arch_get_mcontext_size ()
37 {
38         return sizeof (struct __darwin_mcontext);
39 }
40
41 void
42 mono_mach_arch_thread_state_to_mcontext (thread_state_t state, mcontext_t context)
43 {
44         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
45         struct __darwin_mcontext *ctx = (struct __darwin_mcontext *) context;
46
47         ctx->__ss = *arch_state;
48 }
49
50 int
51 mono_mach_arch_get_thread_state_size ()
52 {
53         return sizeof (arm_thread_state_t);
54 }
55
56 kern_return_t
57 mono_mach_arch_get_thread_state (thread_port_t thread, thread_state_t state, mach_msg_type_number_t *count)
58 {
59         arm_thread_state_t *arch_state = (arm_thread_state_t *) state;
60         kern_return_t ret;
61
62         *count = ARM_THREAD_STATE_COUNT;
63
64         ret = thread_get_state (thread, ARM_THREAD_STATE_COUNT, (thread_state_t) arch_state, count);
65
66         return ret;
67 }
68
69 void *
70 mono_mach_arch_get_tls_value_from_thread (thread_port_t thread, guint32 key)
71 {
72         /* OSX stores TLS values in a hidden array inside the pthread_t structure
73          * They are keyed off a giant array offset 0x48 into the pointer.  This value
74          * is baked into their pthread_getspecific implementation
75          */
76         intptr_t *p = (intptr_t *) pthread_from_mach_thread_np (thread);
77         intptr_t **tsd = (intptr_t **) (p + 0x48 + (key << 2));
78
79         return (void *) *tsd;
80 }
81 #endif