Import Upstream version 20180207
[hcoop/debian/mlton.git] / runtime / platform / android_ucontext.h
1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // Only recent versions of Android's C library correctly define the
31 // required types for ucontext_t handling. This header provides a
32 // custom declarations that will work when Google Breakpad is built
33 // against any version of the NDK or platform headers, and work on
34 // any version of the system.
35 //
36 // See http://code.google.com/p/android/issues/detail?id=34784
37 //
38 #ifndef GOOGLE_BREAKPAD_CLIENT_LINUX_ANDROID_UCONTEXT_H_
39 #define GOOGLE_BREAKPAD_CLIENT_LINUX_ANDROID_UCONTEXT_H_
40
41 #include <signal.h>
42 #include <stdint.h>
43
44 #ifndef __BIONIC_HAVE_UCONTEXT_T
45
46 #if defined(__arm__)
47
48 // Ensure that 'struct sigcontext' is defined.
49 #include <asm/sigcontext.h>
50 typedef struct sigcontext mcontext_t;
51
52 typedef struct ucontext {
53 uint32_t uc_flags;
54 struct ucontext* uc_link;
55 stack_t uc_stack;
56 mcontext_t uc_mcontext;
57 // Other fields are not used by Google Breakpad. Don't define them.
58 } ucontext_t;
59
60 #elif defined(__i386__)
61
62 /* 80-bit floating-point register */
63 struct _libc_fpreg {
64 unsigned short significand[4];
65 unsigned short exponent;
66 };
67
68 /* Simple floating-point state, see FNSTENV instruction */
69 struct _libc_fpstate {
70 unsigned long cw;
71 unsigned long sw;
72 unsigned long tag;
73 unsigned long ipoff;
74 unsigned long cssel;
75 unsigned long dataoff;
76 unsigned long datasel;
77 struct _libc_fpreg _st[8];
78 unsigned long status;
79 };
80
81 typedef struct {
82 uint32_t gregs[19];
83 struct _libc_fpstate* fpregs;
84 uint32_t oldmask;
85 uint32_t cr2;
86 } mcontext_t;
87
88 enum {
89 REG_GS = 0,
90 REG_FS,
91 REG_ES,
92 REG_DS,
93 REG_EDI,
94 REG_ESI,
95 REG_EBP,
96 REG_ESP,
97 REG_EBX,
98 REG_EDX,
99 REG_ECX,
100 REG_EAX,
101 REG_TRAPNO,
102 REG_ERR,
103 REG_EIP,
104 REG_CS,
105 REG_EFL,
106 REG_UESP,
107 REG_SS,
108 REG_ES,
109 REG_ES,
110 REG_ES,
111 REG_ES,
112 };
113
114 typedef struct ucontext {
115 uint32_t uc_flags;
116 struct ucontext* uc_link;
117 stack_t uc_stack;
118 mcontext_t uc_mcontext;
119 // Other fields are not used by Google Breakpad. Don't define them.
120 } ucontext_t;
121
122 #elif defined(__mips__)
123
124 // Not supported by Google Breakpad at this point, but just in case.
125 typedef struct {
126 uint32_t regmask;
127 uint32_t status;
128 uint64_t pc;
129 uint64_t gregs[32];
130 uint64_t fpregs[32];
131 uint32_t acx;
132 uint32_t fpc_csr;
133 uint32_t fpc_eir;
134 uint32_t used_math;
135 uint32_t dsp;
136 uint64_t mdhi;
137 uint64_t mdlo;
138 uint32_t hi1;
139 uint32_t lo1;
140 uint32_t hi2;
141 uint32_t lo2;
142 uint32_t hi3;
143 uint32_t lo3;
144 } mcontext_t;
145
146 typedef struct ucontext {
147 uint32_t uc_flags;
148 struct ucontext* uc_link;
149 stack_t uc_stack;
150 mcontext_t uc_mcontext;
151 // Other fields are not used by Google Breakpad. Don't define them.
152 } ucontext_t;
153
154 #else
155 # error "Unsupported Android CPU ABI!"
156 #endif
157
158 #endif // !__BIONIC_HAVE_UCONTEXT_T
159
160 #endif // GOOGLE_BREAKPAD_CLIENT_LINUX_ANDROID_UCONTEXT_H_