1 // Copyright (c) 2012, 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 #ifndef GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_SYS_USER_H
31 #define GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_SYS_USER_H
32 
33 // The purpose of this file is to glue the mismatching headers (Android NDK vs
34 // glibc) and therefore avoid doing otherwise awkward #ifdefs in the code.
35 // The following quirks are currently handled by this file:
36 // - MIPS: Keep using forked definitions of user.h structs. The definition in
37 //     the NDK is completely different. Internal bug b/18097715
38 // - i386: Use the Android NDK but alias user_fxsr_struct > user_fpxregs_struct.
39 // - x86_64: Override a typo in user_fpregs_struct (mxcsr_mask -> mxcr_mask).
40 //     The typo has been fixed in NDK r10d, but a preprocessor workaround is
41 //     required to make breakpad build with r10c and lower (more details below).
42 // - Other platforms: Just use the Android NDK unchanged.
43 
44 #ifdef __mips__
45 #ifdef __cplusplus
46 extern "C" {
47 #endif  // __cplusplus
48 
49 #define EF_REG0 6
50 #define EF_REG1 7
51 #define EF_REG2 8
52 #define EF_REG3 9
53 #define EF_REG4 10
54 #define EF_REG5 11
55 #define EF_REG6 12
56 #define EF_REG7 13
57 #define EF_REG8 14
58 #define EF_REG9 15
59 #define EF_REG10 16
60 #define EF_REG11 17
61 #define EF_REG12 18
62 #define EF_REG13 19
63 #define EF_REG14 20
64 #define EF_REG15 21
65 #define EF_REG16 22
66 #define EF_REG17 23
67 #define EF_REG18 24
68 #define EF_REG19 25
69 #define EF_REG20 26
70 #define EF_REG21 27
71 #define EF_REG22 28
72 #define EF_REG23 29
73 #define EF_REG24 30
74 #define EF_REG25 31
75 
76 /*
77  * k0/k1 unsaved
78  */
79 #define EF_REG26 32
80 #define EF_REG27 33
81 #define EF_REG28 34
82 #define EF_REG29 35
83 #define EF_REG30 36
84 #define EF_REG31 37
85 
86 /*
87  * Saved special registers
88  */
89 #define EF_LO 38
90 #define EF_HI 39
91 #define EF_CP0_EPC 40
92 #define EF_CP0_BADVADDR 41
93 #define EF_CP0_STATUS 42
94 #define EF_CP0_CAUSE 43
95 
96 struct user_regs_struct {
97   unsigned long long regs[32];
98   unsigned long long lo;
99   unsigned long long hi;
100   unsigned long long epc;
101   unsigned long long badvaddr;
102   unsigned long long status;
103   unsigned long long cause;
104 };
105 
106 struct user_fpregs_struct {
107   unsigned long long regs[32];
108   unsigned int fpcsr;
109   unsigned int fir;
110 };
111 
112 #ifdef __cplusplus
113 }  // extern "C"
114 #endif  // __cplusplus
115 
116 #else  //  __mips__
117 
118 // TODO(primiano): remove this after Chromium has stably rolled to NDK r10d.
119 // Historical context: NDK releases < r10d had a typo in sys/user.h (mxcsr_mask
120 // instead of mxcr_mask), which is fixed in r10d. However, just switching to use
121 // the correct one (mxcr_mask) would put Breakpad in a state where it can be
122 // rolled in chromium only atomically with the r10d NDK. A revert of either
123 // project (android_tools, breakpad) would make the other one unrollable.
124 // This hack makes breakpad code compatible with both r10c and r10d NDKs,
125 // reducing the dependency entangling with android_tools.
126 #if defined(__x86_64__)
127 #define mxcsr_mask mxcr_mask
128 #endif
129 
130 #include_next <sys/user.h>
131 
132 #if defined(__x86_64__)
133 #undef mxcsr_mask
134 #endif
135 
136 #endif  // __mips__
137 
138 #endif  // GOOGLE_BREAKPAD_COMMON_ANDROID_INCLUDE_SYS_USER_H
139