1 #include <stddef.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "unwind.h"
5 
main()6 int main() {
7 #define CHECK_EQ(EXPECTED_VALUE, ACTUAL_VALUE) \
8   do { \
9     if ((int)(EXPECTED_VALUE) != (int)(ACTUAL_VALUE)) { \
10       fprintf(stderr, "ASSERTION FAILURE: %s %d\n", __FILE__, __LINE__); \
11       fprintf(stderr, "  expected value: %d (%s)\n", \
12               (int)(EXPECTED_VALUE), #EXPECTED_VALUE); \
13       fprintf(stderr, "  actual value: %d (%s)\n", \
14               (int)(ACTUAL_VALUE), #ACTUAL_VALUE); \
15       exit(EXIT_FAILURE); \
16     } \
17   } while (0)
18 
19 #if defined(__arm__)
20   CHECK_EQ(88, sizeof(struct _Unwind_Control_Block));
21   CHECK_EQ(0, offsetof(struct _Unwind_Control_Block, exception_class));
22   CHECK_EQ(8, offsetof(struct _Unwind_Control_Block, exception_cleanup));
23 #elif defined(__mips__)
24   CHECK_EQ(24, sizeof(struct _Unwind_Exception));
25   CHECK_EQ(0, offsetof(struct _Unwind_Exception, exception_class));
26   CHECK_EQ(8, offsetof(struct _Unwind_Exception, exception_cleanup));
27   CHECK_EQ(12, offsetof(struct _Unwind_Exception, private_1));
28   CHECK_EQ(16, offsetof(struct _Unwind_Exception, private_2));
29 #elif defined(__i386__)
30   CHECK_EQ(32, sizeof(struct _Unwind_Exception));
31   CHECK_EQ(0, offsetof(struct _Unwind_Exception, exception_class));
32   CHECK_EQ(8, offsetof(struct _Unwind_Exception, exception_cleanup));
33   CHECK_EQ(12, offsetof(struct _Unwind_Exception, private_1));
34   CHECK_EQ(16, offsetof(struct _Unwind_Exception, private_2));
35 #elif defined(__aarch64__) || defined(__x86_64__) || defined(__mips64__)
36   CHECK_EQ(32, sizeof(struct _Unwind_Exception));
37   CHECK_EQ(0, offsetof(struct _Unwind_Exception, exception_class));
38   CHECK_EQ(8, offsetof(struct _Unwind_Exception, exception_cleanup));
39   CHECK_EQ(16, offsetof(struct _Unwind_Exception, private_1));
40   CHECK_EQ(24, offsetof(struct _Unwind_Exception, private_2));
41 #elif defined(__le32__) || defined(__le64__)
42   // Should not check _Unwind_Exception since it is opaque conceptually
43 #else
44 #error "unsupported architecture"
45 #endif
46 
47   return EXIT_SUCCESS;
48 }
49