1 // Copyright (C) 2012 The Android Open Source Project
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
6 // are met:
7 // 1. Redistributions of source code must retain the above copyright
8 //    notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 //    notice, this list of conditions and the following disclaimer in the
11 //    documentation and/or other materials provided with the distribution.
12 // 3. Neither the name of the project nor the names of its contributors
13 //    may be used to endorse or promote products derived from this software
14 //    without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
20 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 // SUCH DAMAGE.
27 
28 #ifndef __GABIXX_UNWIND_ITANIUM_H__
29 #define __GABIXX_UNWIND_ITANIUM_H__
30 
31 #include <stdint.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef enum {
38   _URC_NO_REASON = 0,
39   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
40   _URC_FATAL_PHASE2_ERROR = 2,
41   _URC_FATAL_PHASE1_ERROR = 3,
42   _URC_NORMAL_STOP = 4,
43   _URC_END_OF_STACK = 5,
44   _URC_HANDLER_FOUND = 6,
45   _URC_INSTALL_CONTEXT = 7,
46   _URC_CONTINUE_UNWIND = 8
47 } _Unwind_Reason_Code;
48 
49 typedef int _Unwind_Action;
50 static const _Unwind_Action _UA_SEARCH_PHASE  = 1;
51 static const _Unwind_Action _UA_CLEANUP_PHASE = 2;
52 static const _Unwind_Action _UA_HANDLER_FRAME = 4;
53 static const _Unwind_Action _UA_FORCE_UNWIND  = 8;
54 
55 struct _Unwind_Context; // system-specific opaque
56 struct _Unwind_Exception;
57 
58 typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code reason,
59                                               struct _Unwind_Exception* exc);
60 
61 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int version,
62                                                 _Unwind_Action actions,
63                                                 uint64_t exceptionClass,
64                                                 struct _Unwind_Exception*,
65                                                 struct _Unwind_Context*,
66                                                 void* stop_parameter);
67 
68 struct _Unwind_Exception {
69   uint64_t exception_class;
70   _Unwind_Exception_Cleanup_Fn exception_cleanup;
71   uint32_t private_1;
72   uint32_t private_2;
73 }
74 #if defined(__clang__) && defined(__mips__)
75 // FIXME: It seems that mipsel-linux-android-gcc will use 24 as the object size
76 // with or without the aligned attribute.  However, clang (mipsel) will align
77 // the object size to 32 when we specify the aligned attribute, which may
78 // result in some sort of incompatibility.  As a workaround, let's remove this
79 // attribute when we are compiling this file for MIPS architecture with clang.
80 // Add the attribute back when clang can have same behavior as gcc.
81 #else
82 __attribute__((__aligned__)) // must be double-word aligned
83 #endif
84 ;
85 
86 _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception*);
87 void _Unwind_Resume(struct _Unwind_Exception*);
88 void _Unwind_DeleteException(struct _Unwind_Exception*);
89 
90 uint64_t _Unwind_GetGR(struct _Unwind_Context*, int index);
91 void _Unwind_SetGR(struct _Unwind_Context*, int index, uint64_t new_value);
92 
93 uint64_t _Unwind_GetIP(struct _Unwind_Context*);
94 void _Unwind_SetIP(struct _Unwind_Context*, uintptr_t new_value);
95 
96 uint64_t _Unwind_GetRegionStart(struct _Unwind_Context*);
97 uint64_t _Unwind_GetLanguageSpecificData(struct _Unwind_Context*);
98 
99 _Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception*,
100                                          _Unwind_Stop_Fn stop,
101                                          void* stop_parameter);
102 
103 _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception*);
104 void _Unwind_Resume(struct _Unwind_Exception*);
105 void _Unwind_DeleteException(struct _Unwind_Exception*);
106 
107 #ifdef __cplusplus
108 } // extern "C"
109 #endif
110 
111 #endif  // __GABIXX_UNWIND_ITANIUM_H__
112