authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-01 16:39:13-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-01 16:39:31-07:00
logceb3819c42254c1d379d4a0416009d136bbb0385
treee54a495c392e190188ec55f5d48ebce8dcfb26e6
parentaa964bd555bf7d034b5bfea6275d6edddc35cb8c

update libunwind to llvm 14.0.6


29 files changed, 1105 insertions(+), 544 deletions(-)

lib/libunwind/include/__libunwind_config.h+8-7
......@@ -1,4 +1,4 @@
1//===------------------------- __libunwind_config.h -----------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -56,7 +56,7 @@
5656# define _LIBUNWIND_CONTEXT_SIZE 167
5757# define _LIBUNWIND_CURSOR_SIZE 179
5858# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64
59# elif defined(__ppc__)
59# elif defined(__powerpc__)
6060# define _LIBUNWIND_TARGET_PPC 1
6161# define _LIBUNWIND_CONTEXT_SIZE 117
6262# define _LIBUNWIND_CURSOR_SIZE 124
......@@ -126,11 +126,12 @@
126126# error "Unsupported MIPS ABI and/or environment"
127127# endif
128128# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS
129# elif defined(__sparc__) && defined(__arch64__)
130# define _LIBUNWIND_TARGET_SPARC64 1
131# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC64
132# define _LIBUNWIND_CONTEXT_SIZE 33
133# define _LIBUNWIND_CURSOR_SIZE 45
129#elif defined(__sparc__) && defined(__arch64__)
130#define _LIBUNWIND_TARGET_SPARC64 1
131#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
132 _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC64
133#define _LIBUNWIND_CONTEXT_SIZE 33
134#define _LIBUNWIND_CURSOR_SIZE 45
134135# elif defined(__sparc__)
135136 #define _LIBUNWIND_TARGET_SPARC 1
136137 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC
lib/libunwind/include/libunwind.h+146-72
......@@ -1,4 +1,4 @@
1//===---------------------------- libunwind.h -----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -493,77 +493,150 @@ enum {
493493
494494// 64-bit ARM64 registers
495495enum {
496 UNW_ARM64_X0 = 0,
497 UNW_ARM64_X1 = 1,
498 UNW_ARM64_X2 = 2,
499 UNW_ARM64_X3 = 3,
500 UNW_ARM64_X4 = 4,
501 UNW_ARM64_X5 = 5,
502 UNW_ARM64_X6 = 6,
503 UNW_ARM64_X7 = 7,
504 UNW_ARM64_X8 = 8,
505 UNW_ARM64_X9 = 9,
506 UNW_ARM64_X10 = 10,
507 UNW_ARM64_X11 = 11,
508 UNW_ARM64_X12 = 12,
509 UNW_ARM64_X13 = 13,
510 UNW_ARM64_X14 = 14,
511 UNW_ARM64_X15 = 15,
512 UNW_ARM64_X16 = 16,
513 UNW_ARM64_X17 = 17,
514 UNW_ARM64_X18 = 18,
515 UNW_ARM64_X19 = 19,
516 UNW_ARM64_X20 = 20,
517 UNW_ARM64_X21 = 21,
518 UNW_ARM64_X22 = 22,
519 UNW_ARM64_X23 = 23,
520 UNW_ARM64_X24 = 24,
521 UNW_ARM64_X25 = 25,
522 UNW_ARM64_X26 = 26,
523 UNW_ARM64_X27 = 27,
524 UNW_ARM64_X28 = 28,
525 UNW_ARM64_X29 = 29,
526 UNW_ARM64_FP = 29,
527 UNW_ARM64_X30 = 30,
528 UNW_ARM64_LR = 30,
529 UNW_ARM64_X31 = 31,
530 UNW_ARM64_SP = 31,
531 UNW_ARM64_PC = 32,
532 // reserved block
533 UNW_ARM64_RA_SIGN_STATE = 34,
496 UNW_AARCH64_X0 = 0,
497 UNW_AARCH64_X1 = 1,
498 UNW_AARCH64_X2 = 2,
499 UNW_AARCH64_X3 = 3,
500 UNW_AARCH64_X4 = 4,
501 UNW_AARCH64_X5 = 5,
502 UNW_AARCH64_X6 = 6,
503 UNW_AARCH64_X7 = 7,
504 UNW_AARCH64_X8 = 8,
505 UNW_AARCH64_X9 = 9,
506 UNW_AARCH64_X10 = 10,
507 UNW_AARCH64_X11 = 11,
508 UNW_AARCH64_X12 = 12,
509 UNW_AARCH64_X13 = 13,
510 UNW_AARCH64_X14 = 14,
511 UNW_AARCH64_X15 = 15,
512 UNW_AARCH64_X16 = 16,
513 UNW_AARCH64_X17 = 17,
514 UNW_AARCH64_X18 = 18,
515 UNW_AARCH64_X19 = 19,
516 UNW_AARCH64_X20 = 20,
517 UNW_AARCH64_X21 = 21,
518 UNW_AARCH64_X22 = 22,
519 UNW_AARCH64_X23 = 23,
520 UNW_AARCH64_X24 = 24,
521 UNW_AARCH64_X25 = 25,
522 UNW_AARCH64_X26 = 26,
523 UNW_AARCH64_X27 = 27,
524 UNW_AARCH64_X28 = 28,
525 UNW_AARCH64_X29 = 29,
526 UNW_AARCH64_FP = 29,
527 UNW_AARCH64_X30 = 30,
528 UNW_AARCH64_LR = 30,
529 UNW_AARCH64_X31 = 31,
530 UNW_AARCH64_SP = 31,
531 UNW_AARCH64_PC = 32,
532
534533 // reserved block
535 UNW_ARM64_D0 = 64,
536 UNW_ARM64_D1 = 65,
537 UNW_ARM64_D2 = 66,
538 UNW_ARM64_D3 = 67,
539 UNW_ARM64_D4 = 68,
540 UNW_ARM64_D5 = 69,
541 UNW_ARM64_D6 = 70,
542 UNW_ARM64_D7 = 71,
543 UNW_ARM64_D8 = 72,
544 UNW_ARM64_D9 = 73,
545 UNW_ARM64_D10 = 74,
546 UNW_ARM64_D11 = 75,
547 UNW_ARM64_D12 = 76,
548 UNW_ARM64_D13 = 77,
549 UNW_ARM64_D14 = 78,
550 UNW_ARM64_D15 = 79,
551 UNW_ARM64_D16 = 80,
552 UNW_ARM64_D17 = 81,
553 UNW_ARM64_D18 = 82,
554 UNW_ARM64_D19 = 83,
555 UNW_ARM64_D20 = 84,
556 UNW_ARM64_D21 = 85,
557 UNW_ARM64_D22 = 86,
558 UNW_ARM64_D23 = 87,
559 UNW_ARM64_D24 = 88,
560 UNW_ARM64_D25 = 89,
561 UNW_ARM64_D26 = 90,
562 UNW_ARM64_D27 = 91,
563 UNW_ARM64_D28 = 92,
564 UNW_ARM64_D29 = 93,
565 UNW_ARM64_D30 = 94,
566 UNW_ARM64_D31 = 95,
534 UNW_AARCH64_RA_SIGN_STATE = 34,
535
536 // FP/vector registers
537 UNW_AARCH64_V0 = 64,
538 UNW_AARCH64_V1 = 65,
539 UNW_AARCH64_V2 = 66,
540 UNW_AARCH64_V3 = 67,
541 UNW_AARCH64_V4 = 68,
542 UNW_AARCH64_V5 = 69,
543 UNW_AARCH64_V6 = 70,
544 UNW_AARCH64_V7 = 71,
545 UNW_AARCH64_V8 = 72,
546 UNW_AARCH64_V9 = 73,
547 UNW_AARCH64_V10 = 74,
548 UNW_AARCH64_V11 = 75,
549 UNW_AARCH64_V12 = 76,
550 UNW_AARCH64_V13 = 77,
551 UNW_AARCH64_V14 = 78,
552 UNW_AARCH64_V15 = 79,
553 UNW_AARCH64_V16 = 80,
554 UNW_AARCH64_V17 = 81,
555 UNW_AARCH64_V18 = 82,
556 UNW_AARCH64_V19 = 83,
557 UNW_AARCH64_V20 = 84,
558 UNW_AARCH64_V21 = 85,
559 UNW_AARCH64_V22 = 86,
560 UNW_AARCH64_V23 = 87,
561 UNW_AARCH64_V24 = 88,
562 UNW_AARCH64_V25 = 89,
563 UNW_AARCH64_V26 = 90,
564 UNW_AARCH64_V27 = 91,
565 UNW_AARCH64_V28 = 92,
566 UNW_AARCH64_V29 = 93,
567 UNW_AARCH64_V30 = 94,
568 UNW_AARCH64_V31 = 95,
569
570 // Compatibility aliases
571 UNW_ARM64_X0 = UNW_AARCH64_X0,
572 UNW_ARM64_X1 = UNW_AARCH64_X1,
573 UNW_ARM64_X2 = UNW_AARCH64_X2,
574 UNW_ARM64_X3 = UNW_AARCH64_X3,
575 UNW_ARM64_X4 = UNW_AARCH64_X4,
576 UNW_ARM64_X5 = UNW_AARCH64_X5,
577 UNW_ARM64_X6 = UNW_AARCH64_X6,
578 UNW_ARM64_X7 = UNW_AARCH64_X7,
579 UNW_ARM64_X8 = UNW_AARCH64_X8,
580 UNW_ARM64_X9 = UNW_AARCH64_X9,
581 UNW_ARM64_X10 = UNW_AARCH64_X10,
582 UNW_ARM64_X11 = UNW_AARCH64_X11,
583 UNW_ARM64_X12 = UNW_AARCH64_X12,
584 UNW_ARM64_X13 = UNW_AARCH64_X13,
585 UNW_ARM64_X14 = UNW_AARCH64_X14,
586 UNW_ARM64_X15 = UNW_AARCH64_X15,
587 UNW_ARM64_X16 = UNW_AARCH64_X16,
588 UNW_ARM64_X17 = UNW_AARCH64_X17,
589 UNW_ARM64_X18 = UNW_AARCH64_X18,
590 UNW_ARM64_X19 = UNW_AARCH64_X19,
591 UNW_ARM64_X20 = UNW_AARCH64_X20,
592 UNW_ARM64_X21 = UNW_AARCH64_X21,
593 UNW_ARM64_X22 = UNW_AARCH64_X22,
594 UNW_ARM64_X23 = UNW_AARCH64_X23,
595 UNW_ARM64_X24 = UNW_AARCH64_X24,
596 UNW_ARM64_X25 = UNW_AARCH64_X25,
597 UNW_ARM64_X26 = UNW_AARCH64_X26,
598 UNW_ARM64_X27 = UNW_AARCH64_X27,
599 UNW_ARM64_X28 = UNW_AARCH64_X28,
600 UNW_ARM64_X29 = UNW_AARCH64_X29,
601 UNW_ARM64_FP = UNW_AARCH64_FP,
602 UNW_ARM64_X30 = UNW_AARCH64_X30,
603 UNW_ARM64_LR = UNW_AARCH64_LR,
604 UNW_ARM64_X31 = UNW_AARCH64_X31,
605 UNW_ARM64_SP = UNW_AARCH64_SP,
606 UNW_ARM64_PC = UNW_AARCH64_PC,
607 UNW_ARM64_RA_SIGN_STATE = UNW_AARCH64_RA_SIGN_STATE,
608 UNW_ARM64_D0 = UNW_AARCH64_V0,
609 UNW_ARM64_D1 = UNW_AARCH64_V1,
610 UNW_ARM64_D2 = UNW_AARCH64_V2,
611 UNW_ARM64_D3 = UNW_AARCH64_V3,
612 UNW_ARM64_D4 = UNW_AARCH64_V4,
613 UNW_ARM64_D5 = UNW_AARCH64_V5,
614 UNW_ARM64_D6 = UNW_AARCH64_V6,
615 UNW_ARM64_D7 = UNW_AARCH64_V7,
616 UNW_ARM64_D8 = UNW_AARCH64_V8,
617 UNW_ARM64_D9 = UNW_AARCH64_V9,
618 UNW_ARM64_D10 = UNW_AARCH64_V10,
619 UNW_ARM64_D11 = UNW_AARCH64_V11,
620 UNW_ARM64_D12 = UNW_AARCH64_V12,
621 UNW_ARM64_D13 = UNW_AARCH64_V13,
622 UNW_ARM64_D14 = UNW_AARCH64_V14,
623 UNW_ARM64_D15 = UNW_AARCH64_V15,
624 UNW_ARM64_D16 = UNW_AARCH64_V16,
625 UNW_ARM64_D17 = UNW_AARCH64_V17,
626 UNW_ARM64_D18 = UNW_AARCH64_V18,
627 UNW_ARM64_D19 = UNW_AARCH64_V19,
628 UNW_ARM64_D20 = UNW_AARCH64_V20,
629 UNW_ARM64_D21 = UNW_AARCH64_V21,
630 UNW_ARM64_D22 = UNW_AARCH64_V22,
631 UNW_ARM64_D23 = UNW_AARCH64_V23,
632 UNW_ARM64_D24 = UNW_AARCH64_V24,
633 UNW_ARM64_D25 = UNW_AARCH64_V25,
634 UNW_ARM64_D26 = UNW_AARCH64_V26,
635 UNW_ARM64_D27 = UNW_AARCH64_V27,
636 UNW_ARM64_D28 = UNW_AARCH64_V28,
637 UNW_ARM64_D29 = UNW_AARCH64_V29,
638 UNW_ARM64_D30 = UNW_AARCH64_V30,
639 UNW_ARM64_D31 = UNW_AARCH64_V31,
567640};
568641
569642// 32-bit ARM registers. Numbers match DWARF for ARM spec #3.1 Table 1.
......@@ -645,7 +718,8 @@ enum {
645718 UNW_ARM_WR14 = 126,
646719 UNW_ARM_WR15 = 127,
647720 // 128-133 -- SPSR, SPSR_{FIQ|IRQ|ABT|UND|SVC}
648 // 134-143 -- Reserved
721 // 134-142 -- Reserved
722 UNW_ARM_RA_AUTH_CODE = 143,
649723 // 144-150 -- R8_USR-R14_USR
650724 // 151-157 -- R8_FIQ-R14_FIQ
651725 // 158-159 -- R13_IRQ-R14_IRQ
lib/libunwind/include/mach-o/compact_unwind_encoding.h+1-1
......@@ -1,4 +1,4 @@
1//===------------------ mach-o/compact_unwind_encoding.h ------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/include/unwind.h+5-193
......@@ -1,4 +1,4 @@
1//===------------------------------- unwind.h -----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -56,211 +56,23 @@ typedef enum {
5656typedef struct _Unwind_Context _Unwind_Context; // opaque
5757
5858#if defined(_LIBUNWIND_ARM_EHABI)
59typedef uint32_t _Unwind_State;
60
61static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0;
62static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1;
63static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2;
64static const _Unwind_State _US_ACTION_MASK = 3;
65/* Undocumented flag for force unwinding. */
66static const _Unwind_State _US_FORCE_UNWIND = 8;
67
68typedef uint32_t _Unwind_EHT_Header;
69
70struct _Unwind_Control_Block;
71typedef struct _Unwind_Control_Block _Unwind_Control_Block;
72typedef struct _Unwind_Control_Block _Unwind_Exception; /* Alias */
73
74struct _Unwind_Control_Block {
75 uint64_t exception_class;
76 void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*);
77
78 /* Unwinder cache, private fields for the unwinder's use */
79 struct {
80 uint32_t reserved1; /* init reserved1 to 0, then don't touch */
81 uint32_t reserved2;
82 uint32_t reserved3;
83 uint32_t reserved4;
84 uint32_t reserved5;
85 } unwinder_cache;
86
87 /* Propagation barrier cache (valid after phase 1): */
88 struct {
89 uint32_t sp;
90 uint32_t bitpattern[5];
91 } barrier_cache;
92
93 /* Cleanup cache (preserved over cleanup): */
94 struct {
95 uint32_t bitpattern[4];
96 } cleanup_cache;
97
98 /* Pr cache (for pr's benefit): */
99 struct {
100 uint32_t fnstart; /* function start address */
101 _Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */
102 uint32_t additional;
103 uint32_t reserved1;
104 } pr_cache;
105
106 long long int :0; /* Enforce the 8-byte alignment */
107} __attribute__((__aligned__(8)));
108
109typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
110 (_Unwind_State state,
111 _Unwind_Exception* exceptionObject,
112 struct _Unwind_Context* context);
113
114typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
115 _Unwind_State state, _Unwind_Exception *exceptionObject,
116 struct _Unwind_Context *context);
59#include "unwind_arm_ehabi.h"
11760#else
118struct _Unwind_Context; // opaque
119struct _Unwind_Exception; // forward declaration
120typedef struct _Unwind_Exception _Unwind_Exception;
121
122struct _Unwind_Exception {
123 uint64_t exception_class;
124 void (*exception_cleanup)(_Unwind_Reason_Code reason,
125 _Unwind_Exception *exc);
126#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
127 uintptr_t private_[6];
128#else
129 uintptr_t private_1; // non-zero means forced unwind
130 uintptr_t private_2; // holds sp that phase1 found for phase2 to use
61#include "unwind_itanium.h"
13162#endif
132#if __SIZEOF_POINTER__ == 4
133 // The implementation of _Unwind_Exception uses an attribute mode on the
134 // above fields which has the side effect of causing this whole struct to
135 // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
136 // pad fields added for binary compatibility.
137 uint32_t reserved[3];
138#endif
139 // The Itanium ABI requires that _Unwind_Exception objects are "double-word
140 // aligned". GCC has interpreted this to mean "use the maximum useful
141 // alignment for the target"; so do we.
142} __attribute__((__aligned__));
14363
14464typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
14565 (int version,
14666 _Unwind_Action actions,
147 uint64_t exceptionClass,
67 _Unwind_Exception_Class exceptionClass,
14868 _Unwind_Exception* exceptionObject,
14969 struct _Unwind_Context* context,
150 void* stop_parameter );
151
152typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
153 int version, _Unwind_Action actions, uint64_t exceptionClass,
154 _Unwind_Exception *exceptionObject, struct _Unwind_Context *context);
155#endif
70 void* stop_parameter);
15671
15772#ifdef __cplusplus
15873extern "C" {
15974#endif
16075
161//
162// The following are the base functions documented by the C++ ABI
163//
164#ifdef __USING_SJLJ_EXCEPTIONS__
165extern _Unwind_Reason_Code
166 _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);
167extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);
168#else
169extern _Unwind_Reason_Code
170 _Unwind_RaiseException(_Unwind_Exception *exception_object);
171extern void _Unwind_Resume(_Unwind_Exception *exception_object);
172#endif
173extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);
174
175#if defined(_LIBUNWIND_ARM_EHABI)
176typedef enum {
177 _UVRSC_CORE = 0, /* integer register */
178 _UVRSC_VFP = 1, /* vfp */
179 _UVRSC_WMMXD = 3, /* Intel WMMX data register */
180 _UVRSC_WMMXC = 4 /* Intel WMMX control register */
181} _Unwind_VRS_RegClass;
182
183typedef enum {
184 _UVRSD_UINT32 = 0,
185 _UVRSD_VFPX = 1,
186 _UVRSD_UINT64 = 3,
187 _UVRSD_FLOAT = 4,
188 _UVRSD_DOUBLE = 5
189} _Unwind_VRS_DataRepresentation;
190
191typedef enum {
192 _UVRSR_OK = 0,
193 _UVRSR_NOT_IMPLEMENTED = 1,
194 _UVRSR_FAILED = 2
195} _Unwind_VRS_Result;
196
197extern void _Unwind_Complete(_Unwind_Exception* exception_object);
198
199extern _Unwind_VRS_Result
200_Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
201 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
202 void *valuep);
203
204extern _Unwind_VRS_Result
205_Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
206 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
207 void *valuep);
208
209extern _Unwind_VRS_Result
210_Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
211 uint32_t discriminator,
212 _Unwind_VRS_DataRepresentation representation);
213#endif
214
215#if !defined(_LIBUNWIND_ARM_EHABI)
216
217extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index);
218extern void _Unwind_SetGR(struct _Unwind_Context *context, int index,
219 uintptr_t new_value);
220extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
221extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value);
222
223#else // defined(_LIBUNWIND_ARM_EHABI)
224
225#if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE)
226#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern
227#else
228#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__
229#endif
230
231// These are de facto helper functions for ARM, which delegate the function
232// calls to _Unwind_VRS_Get/Set(). These are not a part of ARM EHABI
233// specification, thus these function MUST be inlined. Please don't replace
234// these with the "extern" function declaration; otherwise, the program
235// including this <unwind.h> header won't be ABI compatible and will result in
236// link error when we are linking the program with libgcc.
237
238_LIBUNWIND_EXPORT_UNWIND_LEVEL1
239uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index) {
240 uintptr_t value = 0;
241 _Unwind_VRS_Get(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
242 return value;
243}
244
245_LIBUNWIND_EXPORT_UNWIND_LEVEL1
246void _Unwind_SetGR(struct _Unwind_Context *context, int index,
247 uintptr_t value) {
248 _Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
249}
250
251_LIBUNWIND_EXPORT_UNWIND_LEVEL1
252uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
253 // remove the thumb-bit before returning
254 return _Unwind_GetGR(context, 15) & (~(uintptr_t)0x1);
255}
256
257_LIBUNWIND_EXPORT_UNWIND_LEVEL1
258void _Unwind_SetIP(struct _Unwind_Context *context, uintptr_t value) {
259 uintptr_t thumb_bit = _Unwind_GetGR(context, 15) & ((uintptr_t)0x1);
260 _Unwind_SetGR(context, 15, value | thumb_bit);
261}
262#endif // defined(_LIBUNWIND_ARM_EHABI)
263
26476extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);
26577extern uintptr_t
26678 _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);
lib/libunwind/include/unwind_arm_ehabi.h created+170
......@@ -0,0 +1,170 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//
8// C++ ABI Level 1 ABI documented at:
9// https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef __ARM_EHABI_UNWIND_H__
14#define __ARM_EHABI_UNWIND_H__
15
16typedef uint32_t _Unwind_State;
17
18static const _Unwind_State _US_VIRTUAL_UNWIND_FRAME = 0;
19static const _Unwind_State _US_UNWIND_FRAME_STARTING = 1;
20static const _Unwind_State _US_UNWIND_FRAME_RESUME = 2;
21static const _Unwind_State _US_ACTION_MASK = 3;
22/* Undocumented flag for force unwinding. */
23static const _Unwind_State _US_FORCE_UNWIND = 8;
24
25typedef uint32_t _Unwind_EHT_Header;
26
27struct _Unwind_Control_Block;
28typedef struct _Unwind_Control_Block _Unwind_Control_Block;
29#define _Unwind_Exception _Unwind_Control_Block /* Alias */
30typedef uint8_t _Unwind_Exception_Class[8];
31
32struct _Unwind_Control_Block {
33 _Unwind_Exception_Class exception_class;
34 void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block*);
35
36 /* Unwinder cache, private fields for the unwinder's use */
37 struct {
38 uint32_t reserved1; /* init reserved1 to 0, then don't touch */
39 uint32_t reserved2;
40 uint32_t reserved3;
41 uint32_t reserved4;
42 uint32_t reserved5;
43 } unwinder_cache;
44
45 /* Propagation barrier cache (valid after phase 1): */
46 struct {
47 uint32_t sp;
48 uint32_t bitpattern[5];
49 } barrier_cache;
50
51 /* Cleanup cache (preserved over cleanup): */
52 struct {
53 uint32_t bitpattern[4];
54 } cleanup_cache;
55
56 /* Pr cache (for pr's benefit): */
57 struct {
58 uint32_t fnstart; /* function start address */
59 _Unwind_EHT_Header* ehtp; /* pointer to EHT entry header word */
60 uint32_t additional;
61 uint32_t reserved1;
62 } pr_cache;
63
64 long long int :0; /* Enforce the 8-byte alignment */
65} __attribute__((__aligned__(8)));
66
67typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
68 _Unwind_State state, _Unwind_Exception *exceptionObject,
69 struct _Unwind_Context *context);
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75//
76// The following are the base functions documented by the C++ ABI
77//
78#ifdef __USING_SJLJ_EXCEPTIONS__
79extern _Unwind_Reason_Code
80 _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);
81extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);
82#else
83extern _Unwind_Reason_Code
84 _Unwind_RaiseException(_Unwind_Exception *exception_object);
85extern void _Unwind_Resume(_Unwind_Exception *exception_object);
86#endif
87extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);
88
89typedef enum {
90 _UVRSC_CORE = 0, /* integer register */
91 _UVRSC_VFP = 1, /* vfp */
92 _UVRSC_WMMXD = 3, /* Intel WMMX data register */
93 _UVRSC_WMMXC = 4, /* Intel WMMX control register */
94 _UVRSC_PSEUDO = 5 /* Special purpose pseudo register */
95} _Unwind_VRS_RegClass;
96
97typedef enum {
98 _UVRSD_UINT32 = 0,
99 _UVRSD_VFPX = 1,
100 _UVRSD_UINT64 = 3,
101 _UVRSD_FLOAT = 4,
102 _UVRSD_DOUBLE = 5
103} _Unwind_VRS_DataRepresentation;
104
105typedef enum {
106 _UVRSR_OK = 0,
107 _UVRSR_NOT_IMPLEMENTED = 1,
108 _UVRSR_FAILED = 2
109} _Unwind_VRS_Result;
110
111extern void _Unwind_Complete(_Unwind_Exception* exception_object);
112
113extern _Unwind_VRS_Result
114_Unwind_VRS_Get(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
115 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
116 void *valuep);
117
118extern _Unwind_VRS_Result
119_Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
120 uint32_t regno, _Unwind_VRS_DataRepresentation representation,
121 void *valuep);
122
123extern _Unwind_VRS_Result
124_Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
125 uint32_t discriminator,
126 _Unwind_VRS_DataRepresentation representation);
127
128#if defined(_LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE)
129#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 extern
130#else
131#define _LIBUNWIND_EXPORT_UNWIND_LEVEL1 static __inline__
132#endif
133
134// These are de facto helper functions for ARM, which delegate the function
135// calls to _Unwind_VRS_Get/Set(). These are not a part of ARM EHABI
136// specification, thus these function MUST be inlined. Please don't replace
137// these with the "extern" function declaration; otherwise, the program
138// including this <unwind.h> header won't be ABI compatible and will result in
139// link error when we are linking the program with libgcc.
140
141_LIBUNWIND_EXPORT_UNWIND_LEVEL1
142uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index) {
143 uintptr_t value = 0;
144 _Unwind_VRS_Get(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
145 return value;
146}
147
148_LIBUNWIND_EXPORT_UNWIND_LEVEL1
149void _Unwind_SetGR(struct _Unwind_Context *context, int index,
150 uintptr_t value) {
151 _Unwind_VRS_Set(context, _UVRSC_CORE, (uint32_t)index, _UVRSD_UINT32, &value);
152}
153
154_LIBUNWIND_EXPORT_UNWIND_LEVEL1
155uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
156 // remove the thumb-bit before returning
157 return _Unwind_GetGR(context, 15) & (~(uintptr_t)0x1);
158}
159
160_LIBUNWIND_EXPORT_UNWIND_LEVEL1
161void _Unwind_SetIP(struct _Unwind_Context *context, uintptr_t value) {
162 uintptr_t thumb_bit = _Unwind_GetGR(context, 15) & ((uintptr_t)0x1);
163 _Unwind_SetGR(context, 15, value | thumb_bit);
164}
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif // __ARM_EHABI_UNWIND_H__
lib/libunwind/include/unwind_itanium.h created+76
......@@ -0,0 +1,76 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//
8// C++ ABI Level 1 ABI documented at:
9// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef __ITANIUM_UNWIND_H__
14#define __ITANIUM_UNWIND_H__
15
16struct _Unwind_Context; // opaque
17struct _Unwind_Exception; // forward declaration
18typedef struct _Unwind_Exception _Unwind_Exception;
19typedef uint64_t _Unwind_Exception_Class;
20
21struct _Unwind_Exception {
22 _Unwind_Exception_Class exception_class;
23 void (*exception_cleanup)(_Unwind_Reason_Code reason,
24 _Unwind_Exception *exc);
25#if defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
26 uintptr_t private_[6];
27#else
28 uintptr_t private_1; // non-zero means forced unwind
29 uintptr_t private_2; // holds sp that phase1 found for phase2 to use
30#endif
31#if __SIZEOF_POINTER__ == 4
32 // The implementation of _Unwind_Exception uses an attribute mode on the
33 // above fields which has the side effect of causing this whole struct to
34 // round up to 32 bytes in size (48 with SEH). To be more explicit, we add
35 // pad fields added for binary compatibility.
36 uint32_t reserved[3];
37#endif
38 // The Itanium ABI requires that _Unwind_Exception objects are "double-word
39 // aligned". GCC has interpreted this to mean "use the maximum useful
40 // alignment for the target"; so do we.
41} __attribute__((__aligned__));
42
43typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
44 int version, _Unwind_Action actions, uint64_t exceptionClass,
45 _Unwind_Exception *exceptionObject, struct _Unwind_Context *context);
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51//
52// The following are the base functions documented by the C++ ABI
53//
54#ifdef __USING_SJLJ_EXCEPTIONS__
55extern _Unwind_Reason_Code
56 _Unwind_SjLj_RaiseException(_Unwind_Exception *exception_object);
57extern void _Unwind_SjLj_Resume(_Unwind_Exception *exception_object);
58#else
59extern _Unwind_Reason_Code
60 _Unwind_RaiseException(_Unwind_Exception *exception_object);
61extern void _Unwind_Resume(_Unwind_Exception *exception_object);
62#endif
63extern void _Unwind_DeleteException(_Unwind_Exception *exception_object);
64
65
66extern uintptr_t _Unwind_GetGR(struct _Unwind_Context *context, int index);
67extern void _Unwind_SetGR(struct _Unwind_Context *context, int index,
68 uintptr_t new_value);
69extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *context);
70extern void _Unwind_SetIP(struct _Unwind_Context *, uintptr_t new_value);
71
72#ifdef __cplusplus
73}
74#endif
75
76#endif // __ITANIUM_UNWIND_H__
lib/libunwind/src/AddressSpace.hpp+13-13
......@@ -1,4 +1,4 @@
1//===------------------------- AddressSpace.hpp ---------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -121,23 +121,23 @@ struct UnwindInfoSections {
121121 uintptr_t dso_base;
122122#endif
123123#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
124 uintptr_t text_segment_length;
124 size_t text_segment_length;
125125#endif
126126#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
127127 uintptr_t dwarf_section;
128 uintptr_t dwarf_section_length;
128 size_t dwarf_section_length;
129129#endif
130130#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
131131 uintptr_t dwarf_index_section;
132 uintptr_t dwarf_index_section_length;
132 size_t dwarf_index_section_length;
133133#endif
134134#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
135135 uintptr_t compact_unwind_section;
136 uintptr_t compact_unwind_section_length;
136 size_t compact_unwind_section_length;
137137#endif
138138#if defined(_LIBUNWIND_ARM_EHABI)
139139 uintptr_t arm_section;
140 uintptr_t arm_section_length;
140 size_t arm_section_length;
141141#endif
142142};
143143
......@@ -430,7 +430,7 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base,
430430 // .eh_frame_hdr records the start of .eh_frame, but not its size.
431431 // Rely on a zero terminator to find the end of the section.
432432 cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
433 cbdata->sects->dwarf_section_length = UINTPTR_MAX;
433 cbdata->sects->dwarf_section_length = SIZE_MAX;
434434 return true;
435435 }
436436 }
......@@ -506,22 +506,22 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
506506 info.dso_base = (uintptr_t)dyldInfo.mh;
507507 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
508508 info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section;
509 info.dwarf_section_length = dyldInfo.dwarf_section_length;
509 info.dwarf_section_length = (size_t)dyldInfo.dwarf_section_length;
510510 #endif
511511 info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section;
512 info.compact_unwind_section_length = dyldInfo.compact_unwind_section_length;
512 info.compact_unwind_section_length = (size_t)dyldInfo.compact_unwind_section_length;
513513 return true;
514514 }
515515#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
516516 info.dso_base = 0;
517517 // Bare metal is statically linked, so no need to ask the dynamic loader
518 info.dwarf_section_length = (uintptr_t)(&__eh_frame_end - &__eh_frame_start);
518 info.dwarf_section_length = (size_t)(&__eh_frame_end - &__eh_frame_start);
519519 info.dwarf_section = (uintptr_t)(&__eh_frame_start);
520520 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",
521521 (void *)info.dwarf_section, (void *)info.dwarf_section_length);
522522#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
523523 info.dwarf_index_section = (uintptr_t)(&__eh_frame_hdr_start);
524 info.dwarf_index_section_length = (uintptr_t)(&__eh_frame_hdr_end - &__eh_frame_hdr_start);
524 info.dwarf_index_section_length = (size_t)(&__eh_frame_hdr_end - &__eh_frame_hdr_start);
525525 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: index section %p length %p",
526526 (void *)info.dwarf_index_section, (void *)info.dwarf_index_section_length);
527527#endif
......@@ -530,7 +530,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
530530#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
531531 // Bare metal is statically linked, so no need to ask the dynamic loader
532532 info.arm_section = (uintptr_t)(&__exidx_start);
533 info.arm_section_length = (uintptr_t)(&__exidx_end - &__exidx_start);
533 info.arm_section_length = (size_t)(&__exidx_end - &__exidx_start);
534534 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",
535535 (void *)info.arm_section, (void *)info.arm_section_length);
536536 if (info.arm_section && info.arm_section_length)
......@@ -584,7 +584,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
584584 int length = 0;
585585 info.arm_section =
586586 (uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length);
587 info.arm_section_length = (uintptr_t)length * sizeof(EHABIIndexEntry);
587 info.arm_section_length = (size_t)length * sizeof(EHABIIndexEntry);
588588 if (info.arm_section && info.arm_section_length)
589589 return true;
590590#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
lib/libunwind/src/CompactUnwinder.hpp+38-38
......@@ -1,4 +1,4 @@
1//===-------------------------- CompactUnwinder.hpp -----------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -537,65 +537,65 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrameless(
537537 uint64_t savedRegisterLoc = registers.getSP() + stackSize;
538538
539539 if (encoding & UNWIND_ARM64_FRAME_X19_X20_PAIR) {
540 registers.setRegister(UNW_ARM64_X19, addressSpace.get64(savedRegisterLoc));
540 registers.setRegister(UNW_AARCH64_X19, addressSpace.get64(savedRegisterLoc));
541541 savedRegisterLoc -= 8;
542 registers.setRegister(UNW_ARM64_X20, addressSpace.get64(savedRegisterLoc));
542 registers.setRegister(UNW_AARCH64_X20, addressSpace.get64(savedRegisterLoc));
543543 savedRegisterLoc -= 8;
544544 }
545545 if (encoding & UNWIND_ARM64_FRAME_X21_X22_PAIR) {
546 registers.setRegister(UNW_ARM64_X21, addressSpace.get64(savedRegisterLoc));
546 registers.setRegister(UNW_AARCH64_X21, addressSpace.get64(savedRegisterLoc));
547547 savedRegisterLoc -= 8;
548 registers.setRegister(UNW_ARM64_X22, addressSpace.get64(savedRegisterLoc));
548 registers.setRegister(UNW_AARCH64_X22, addressSpace.get64(savedRegisterLoc));
549549 savedRegisterLoc -= 8;
550550 }
551551 if (encoding & UNWIND_ARM64_FRAME_X23_X24_PAIR) {
552 registers.setRegister(UNW_ARM64_X23, addressSpace.get64(savedRegisterLoc));
552 registers.setRegister(UNW_AARCH64_X23, addressSpace.get64(savedRegisterLoc));
553553 savedRegisterLoc -= 8;
554 registers.setRegister(UNW_ARM64_X24, addressSpace.get64(savedRegisterLoc));
554 registers.setRegister(UNW_AARCH64_X24, addressSpace.get64(savedRegisterLoc));
555555 savedRegisterLoc -= 8;
556556 }
557557 if (encoding & UNWIND_ARM64_FRAME_X25_X26_PAIR) {
558 registers.setRegister(UNW_ARM64_X25, addressSpace.get64(savedRegisterLoc));
558 registers.setRegister(UNW_AARCH64_X25, addressSpace.get64(savedRegisterLoc));
559559 savedRegisterLoc -= 8;
560 registers.setRegister(UNW_ARM64_X26, addressSpace.get64(savedRegisterLoc));
560 registers.setRegister(UNW_AARCH64_X26, addressSpace.get64(savedRegisterLoc));
561561 savedRegisterLoc -= 8;
562562 }
563563 if (encoding & UNWIND_ARM64_FRAME_X27_X28_PAIR) {
564 registers.setRegister(UNW_ARM64_X27, addressSpace.get64(savedRegisterLoc));
564 registers.setRegister(UNW_AARCH64_X27, addressSpace.get64(savedRegisterLoc));
565565 savedRegisterLoc -= 8;
566 registers.setRegister(UNW_ARM64_X28, addressSpace.get64(savedRegisterLoc));
566 registers.setRegister(UNW_AARCH64_X28, addressSpace.get64(savedRegisterLoc));
567567 savedRegisterLoc -= 8;
568568 }
569569
570570 if (encoding & UNWIND_ARM64_FRAME_D8_D9_PAIR) {
571 registers.setFloatRegister(UNW_ARM64_D8,
571 registers.setFloatRegister(UNW_AARCH64_V8,
572572 addressSpace.getDouble(savedRegisterLoc));
573573 savedRegisterLoc -= 8;
574 registers.setFloatRegister(UNW_ARM64_D9,
574 registers.setFloatRegister(UNW_AARCH64_V9,
575575 addressSpace.getDouble(savedRegisterLoc));
576576 savedRegisterLoc -= 8;
577577 }
578578 if (encoding & UNWIND_ARM64_FRAME_D10_D11_PAIR) {
579 registers.setFloatRegister(UNW_ARM64_D10,
579 registers.setFloatRegister(UNW_AARCH64_V10,
580580 addressSpace.getDouble(savedRegisterLoc));
581581 savedRegisterLoc -= 8;
582 registers.setFloatRegister(UNW_ARM64_D11,
582 registers.setFloatRegister(UNW_AARCH64_V11,
583583 addressSpace.getDouble(savedRegisterLoc));
584584 savedRegisterLoc -= 8;
585585 }
586586 if (encoding & UNWIND_ARM64_FRAME_D12_D13_PAIR) {
587 registers.setFloatRegister(UNW_ARM64_D12,
587 registers.setFloatRegister(UNW_AARCH64_V12,
588588 addressSpace.getDouble(savedRegisterLoc));
589589 savedRegisterLoc -= 8;
590 registers.setFloatRegister(UNW_ARM64_D13,
590 registers.setFloatRegister(UNW_AARCH64_V13,
591591 addressSpace.getDouble(savedRegisterLoc));
592592 savedRegisterLoc -= 8;
593593 }
594594 if (encoding & UNWIND_ARM64_FRAME_D14_D15_PAIR) {
595 registers.setFloatRegister(UNW_ARM64_D14,
595 registers.setFloatRegister(UNW_AARCH64_V14,
596596 addressSpace.getDouble(savedRegisterLoc));
597597 savedRegisterLoc -= 8;
598 registers.setFloatRegister(UNW_ARM64_D15,
598 registers.setFloatRegister(UNW_AARCH64_V15,
599599 addressSpace.getDouble(savedRegisterLoc));
600600 savedRegisterLoc -= 8;
601601 }
......@@ -604,7 +604,7 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrameless(
604604 registers.setSP(savedRegisterLoc);
605605
606606 // set pc to be value in lr
607 registers.setIP(registers.getRegister(UNW_ARM64_LR));
607 registers.setIP(registers.getRegister(UNW_AARCH64_LR));
608608
609609 return UNW_STEP_SUCCESS;
610610}
......@@ -616,65 +616,65 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrame(
616616 uint64_t savedRegisterLoc = registers.getFP() - 8;
617617
618618 if (encoding & UNWIND_ARM64_FRAME_X19_X20_PAIR) {
619 registers.setRegister(UNW_ARM64_X19, addressSpace.get64(savedRegisterLoc));
619 registers.setRegister(UNW_AARCH64_X19, addressSpace.get64(savedRegisterLoc));
620620 savedRegisterLoc -= 8;
621 registers.setRegister(UNW_ARM64_X20, addressSpace.get64(savedRegisterLoc));
621 registers.setRegister(UNW_AARCH64_X20, addressSpace.get64(savedRegisterLoc));
622622 savedRegisterLoc -= 8;
623623 }
624624 if (encoding & UNWIND_ARM64_FRAME_X21_X22_PAIR) {
625 registers.setRegister(UNW_ARM64_X21, addressSpace.get64(savedRegisterLoc));
625 registers.setRegister(UNW_AARCH64_X21, addressSpace.get64(savedRegisterLoc));
626626 savedRegisterLoc -= 8;
627 registers.setRegister(UNW_ARM64_X22, addressSpace.get64(savedRegisterLoc));
627 registers.setRegister(UNW_AARCH64_X22, addressSpace.get64(savedRegisterLoc));
628628 savedRegisterLoc -= 8;
629629 }
630630 if (encoding & UNWIND_ARM64_FRAME_X23_X24_PAIR) {
631 registers.setRegister(UNW_ARM64_X23, addressSpace.get64(savedRegisterLoc));
631 registers.setRegister(UNW_AARCH64_X23, addressSpace.get64(savedRegisterLoc));
632632 savedRegisterLoc -= 8;
633 registers.setRegister(UNW_ARM64_X24, addressSpace.get64(savedRegisterLoc));
633 registers.setRegister(UNW_AARCH64_X24, addressSpace.get64(savedRegisterLoc));
634634 savedRegisterLoc -= 8;
635635 }
636636 if (encoding & UNWIND_ARM64_FRAME_X25_X26_PAIR) {
637 registers.setRegister(UNW_ARM64_X25, addressSpace.get64(savedRegisterLoc));
637 registers.setRegister(UNW_AARCH64_X25, addressSpace.get64(savedRegisterLoc));
638638 savedRegisterLoc -= 8;
639 registers.setRegister(UNW_ARM64_X26, addressSpace.get64(savedRegisterLoc));
639 registers.setRegister(UNW_AARCH64_X26, addressSpace.get64(savedRegisterLoc));
640640 savedRegisterLoc -= 8;
641641 }
642642 if (encoding & UNWIND_ARM64_FRAME_X27_X28_PAIR) {
643 registers.setRegister(UNW_ARM64_X27, addressSpace.get64(savedRegisterLoc));
643 registers.setRegister(UNW_AARCH64_X27, addressSpace.get64(savedRegisterLoc));
644644 savedRegisterLoc -= 8;
645 registers.setRegister(UNW_ARM64_X28, addressSpace.get64(savedRegisterLoc));
645 registers.setRegister(UNW_AARCH64_X28, addressSpace.get64(savedRegisterLoc));
646646 savedRegisterLoc -= 8;
647647 }
648648
649649 if (encoding & UNWIND_ARM64_FRAME_D8_D9_PAIR) {
650 registers.setFloatRegister(UNW_ARM64_D8,
650 registers.setFloatRegister(UNW_AARCH64_V8,
651651 addressSpace.getDouble(savedRegisterLoc));
652652 savedRegisterLoc -= 8;
653 registers.setFloatRegister(UNW_ARM64_D9,
653 registers.setFloatRegister(UNW_AARCH64_V9,
654654 addressSpace.getDouble(savedRegisterLoc));
655655 savedRegisterLoc -= 8;
656656 }
657657 if (encoding & UNWIND_ARM64_FRAME_D10_D11_PAIR) {
658 registers.setFloatRegister(UNW_ARM64_D10,
658 registers.setFloatRegister(UNW_AARCH64_V10,
659659 addressSpace.getDouble(savedRegisterLoc));
660660 savedRegisterLoc -= 8;
661 registers.setFloatRegister(UNW_ARM64_D11,
661 registers.setFloatRegister(UNW_AARCH64_V11,
662662 addressSpace.getDouble(savedRegisterLoc));
663663 savedRegisterLoc -= 8;
664664 }
665665 if (encoding & UNWIND_ARM64_FRAME_D12_D13_PAIR) {
666 registers.setFloatRegister(UNW_ARM64_D12,
666 registers.setFloatRegister(UNW_AARCH64_V12,
667667 addressSpace.getDouble(savedRegisterLoc));
668668 savedRegisterLoc -= 8;
669 registers.setFloatRegister(UNW_ARM64_D13,
669 registers.setFloatRegister(UNW_AARCH64_V13,
670670 addressSpace.getDouble(savedRegisterLoc));
671671 savedRegisterLoc -= 8;
672672 }
673673 if (encoding & UNWIND_ARM64_FRAME_D14_D15_PAIR) {
674 registers.setFloatRegister(UNW_ARM64_D14,
674 registers.setFloatRegister(UNW_AARCH64_V14,
675675 addressSpace.getDouble(savedRegisterLoc));
676676 savedRegisterLoc -= 8;
677 registers.setFloatRegister(UNW_ARM64_D15,
677 registers.setFloatRegister(UNW_AARCH64_V15,
678678 addressSpace.getDouble(savedRegisterLoc));
679679 savedRegisterLoc -= 8;
680680 }
lib/libunwind/src/DwarfInstructions.hpp+26-10
......@@ -1,4 +1,4 @@
1//===-------------------------- DwarfInstructions.hpp ---------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -67,14 +67,13 @@ private:
6767 return (pint_t)((sint_t)registers.getRegister((int)prolog.cfaRegister) +
6868 prolog.cfaRegisterOffset);
6969 if (prolog.cfaExpression != 0)
70 return evaluateExpression((pint_t)prolog.cfaExpression, addressSpace,
70 return evaluateExpression((pint_t)prolog.cfaExpression, addressSpace,
7171 registers, 0);
7272 assert(0 && "getCFA(): unknown location");
7373 __builtin_unreachable();
7474 }
7575};
7676
77
7877template <typename R>
7978auto getSparcWCookie(const R &r, int) -> decltype(r.getWCookie()) {
8079 return r.getWCookie();
......@@ -92,8 +91,8 @@ typename A::pint_t DwarfInstructions<A, R>::getSavedRegister(
9291 return (pint_t)addressSpace.getRegister(cfa + (pint_t)savedReg.value);
9392
9493 case CFI_Parser<A>::kRegisterInCFADecrypt: // sparc64 specific
95 return addressSpace.getP(cfa + (pint_t)savedReg.value) ^
96 getSparcWCookie(registers, 0);
94 return (pint_t)(addressSpace.getP(cfa + (pint_t)savedReg.value) ^
95 getSparcWCookie(registers, 0));
9796
9897 case CFI_Parser<A>::kRegisterAtExpression:
9998 return (pint_t)addressSpace.getRegister(evaluateExpression(
......@@ -127,12 +126,15 @@ double DwarfInstructions<A, R>::getSavedFloatRegister(
127126 return addressSpace.getDouble(
128127 evaluateExpression((pint_t)savedReg.value, addressSpace,
129128 registers, cfa));
130
129 case CFI_Parser<A>::kRegisterUndefined:
130 return 0.0;
131 case CFI_Parser<A>::kRegisterInRegister:
132#ifndef _LIBUNWIND_TARGET_ARM
133 return registers.getFloatRegister((int)savedReg.value);
134#endif
131135 case CFI_Parser<A>::kRegisterIsExpression:
132136 case CFI_Parser<A>::kRegisterUnused:
133 case CFI_Parser<A>::kRegisterUndefined:
134137 case CFI_Parser<A>::kRegisterOffsetFromCFA:
135 case CFI_Parser<A>::kRegisterInRegister:
136138 case CFI_Parser<A>::kRegisterInCFADecrypt:
137139 // FIX ME
138140 break;
......@@ -233,7 +235,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
233235 // restored. autia1716 is used instead of autia as autia1716 assembles
234236 // to a NOP on pre-v8.3a architectures.
235237 if ((R::getArch() == REGISTERS_ARM64) &&
236 prolog.savedRegisters[UNW_ARM64_RA_SIGN_STATE].value &&
238 prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value &&
237239 returnAddress != 0) {
238240#if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
239241 return UNW_ECROSSRASIGNING;
......@@ -253,6 +255,20 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
253255 }
254256#endif
255257
258#if defined(_LIBUNWIND_IS_NATIVE_ONLY) && defined(_LIBUNWIND_TARGET_ARM) && \
259 defined(__ARM_FEATURE_PAUTH)
260 if ((R::getArch() == REGISTERS_ARM) &&
261 prolog.savedRegisters[UNW_ARM_RA_AUTH_CODE].value) {
262 pint_t pac =
263 getSavedRegister(addressSpace, registers, cfa,
264 prolog.savedRegisters[UNW_ARM_RA_AUTH_CODE]);
265 __asm__ __volatile__("autg %0, %1, %2"
266 :
267 : "r"(pac), "r"(returnAddress), "r"(cfa)
268 :);
269 }
270#endif
271
256272#if defined(_LIBUNWIND_TARGET_SPARC)
257273 if (R::getArch() == REGISTERS_SPARC) {
258274 // Skip call site instruction and delay slot
......@@ -264,7 +280,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
264280#endif
265281
266282#if defined(_LIBUNWIND_TARGET_SPARC64)
267 // Skip call site instruction and delay slot
283 // Skip call site instruction and delay slot.
268284 if (R::getArch() == REGISTERS_SPARC64)
269285 returnAddress += 8;
270286#endif
lib/libunwind/src/DwarfParser.hpp+26-14
......@@ -1,4 +1,4 @@
1//===--------------------------- DwarfParser.hpp --------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -152,10 +152,11 @@ public:
152152 };
153153
154154 static bool findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
155 uintptr_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo,
155 size_t sectionLength, pint_t fdeHint, FDE_Info *fdeInfo,
156156 CIE_Info *cieInfo);
157157 static const char *decodeFDE(A &addressSpace, pint_t fdeStart,
158 FDE_Info *fdeInfo, CIE_Info *cieInfo);
158 FDE_Info *fdeInfo, CIE_Info *cieInfo,
159 bool useCIEInfo = false);
159160 static bool parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo,
160161 const CIE_Info &cieInfo, pint_t upToPC,
161162 int arch, PrologInfo *results);
......@@ -163,10 +164,14 @@ public:
163164 static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo);
164165};
165166
166/// Parse a FDE into a CIE_Info and an FDE_Info
167/// Parse a FDE into a CIE_Info and an FDE_Info. If useCIEInfo is
168/// true, treat cieInfo as already-parsed CIE_Info (whose start offset
169/// must match the one specified by the FDE) rather than parsing the
170/// one indicated within the FDE.
167171template <typename A>
168172const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,
169 FDE_Info *fdeInfo, CIE_Info *cieInfo) {
173 FDE_Info *fdeInfo, CIE_Info *cieInfo,
174 bool useCIEInfo) {
170175 pint_t p = fdeStart;
171176 pint_t cfiLength = (pint_t)addressSpace.get32(p);
172177 p += 4;
......@@ -182,9 +187,14 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,
182187 return "FDE is really a CIE"; // this is a CIE not an FDE
183188 pint_t nextCFI = p + cfiLength;
184189 pint_t cieStart = p - ciePointer;
185 const char *err = parseCIE(addressSpace, cieStart, cieInfo);
186 if (err != NULL)
187 return err;
190 if (useCIEInfo) {
191 if (cieInfo->cieStart != cieStart)
192 return "CIE start does not match";
193 } else {
194 const char *err = parseCIE(addressSpace, cieStart, cieInfo);
195 if (err != NULL)
196 return err;
197 }
188198 p += 4;
189199 // Parse pc begin and range.
190200 pint_t pcStart =
......@@ -221,11 +231,11 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,
221231/// Scan an eh_frame section to find an FDE for a pc
222232template <typename A>
223233bool CFI_Parser<A>::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,
224 uintptr_t sectionLength, pint_t fdeHint,
234 size_t sectionLength, pint_t fdeHint,
225235 FDE_Info *fdeInfo, CIE_Info *cieInfo) {
226236 //fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc);
227237 pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart;
228 const pint_t ehSectionEnd = (sectionLength == UINTPTR_MAX)
238 const pint_t ehSectionEnd = (sectionLength == SIZE_MAX)
229239 ? static_cast<pint_t>(-1)
230240 : (ehSectionStart + sectionLength);
231241 while (p < ehSectionEnd) {
......@@ -735,8 +745,8 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
735745#if defined(_LIBUNWIND_TARGET_AARCH64)
736746 case REGISTERS_ARM64: {
737747 int64_t value =
738 results->savedRegisters[UNW_ARM64_RA_SIGN_STATE].value ^ 0x1;
739 results->setRegisterValue(UNW_ARM64_RA_SIGN_STATE, value,
748 results->savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value ^ 0x1;
749 results->setRegisterValue(UNW_AARCH64_RA_SIGN_STATE, value,
740750 initialState);
741751 _LIBUNWIND_TRACE_DWARF("DW_CFA_AARCH64_negate_ra_state\n");
742752 } break;
......@@ -770,11 +780,13 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
770780 if (reg == UNW_SPARC_I7)
771781 results->setRegister(
772782 reg, kRegisterInCFADecrypt,
773 ((int64_t)reg - UNW_SPARC_L0) * sizeof(pint_t), initialState);
783 static_cast<int64_t>((reg - UNW_SPARC_L0) * sizeof(pint_t)),
784 initialState);
774785 else
775786 results->setRegister(
776787 reg, kRegisterInCFA,
777 ((int64_t)reg - UNW_SPARC_L0) * sizeof(pint_t), initialState);
788 static_cast<int64_t>((reg - UNW_SPARC_L0) * sizeof(pint_t)),
789 initialState);
778790 }
779791 _LIBUNWIND_TRACE_DWARF("DW_CFA_GNU_window_save\n");
780792 break;
lib/libunwind/src/EHHeaderParser.hpp+1-1
......@@ -1,4 +1,4 @@
1//===------------------------- EHHeaderParser.hpp -------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/RWMutex.hpp+1-1
......@@ -1,4 +1,4 @@
1//===----------------------------- Registers.hpp --------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/Registers.hpp+123-84
......@@ -1,4 +1,4 @@
1//===----------------------------- Registers.hpp --------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -15,8 +15,9 @@
1515#include <stdint.h>
1616#include <string.h>
1717
18#include "libunwind.h"
18#include "cet_unwind.h"
1919#include "config.h"
20#include "libunwind.h"
2021
2122namespace libunwind {
2223
......@@ -43,6 +44,13 @@ enum {
4344#if defined(_LIBUNWIND_TARGET_I386)
4445class _LIBUNWIND_HIDDEN Registers_x86;
4546extern "C" void __libunwind_Registers_x86_jumpto(Registers_x86 *);
47
48#if defined(_LIBUNWIND_USE_CET)
49extern "C" void *__libunwind_cet_get_jump_target() {
50 return reinterpret_cast<void *>(&__libunwind_Registers_x86_jumpto);
51}
52#endif
53
4654/// Registers_x86 holds the register state of a thread in a 32-bit intel
4755/// process.
4856class _LIBUNWIND_HIDDEN Registers_x86 {
......@@ -254,6 +262,13 @@ inline void Registers_x86::setVectorRegister(int, v128) {
254262/// process.
255263class _LIBUNWIND_HIDDEN Registers_x86_64;
256264extern "C" void __libunwind_Registers_x86_64_jumpto(Registers_x86_64 *);
265
266#if defined(_LIBUNWIND_USE_CET)
267extern "C" void *__libunwind_cet_get_jump_target() {
268 return reinterpret_cast<void *>(&__libunwind_Registers_x86_64_jumpto);
269}
270#endif
271
257272class _LIBUNWIND_HIDDEN Registers_x86_64 {
258273public:
259274 Registers_x86_64();
......@@ -340,7 +355,7 @@ inline bool Registers_x86_64::validRegister(int regNum) const {
340355 return true;
341356 if (regNum < 0)
342357 return false;
343 if (regNum > 15)
358 if (regNum > 16)
344359 return false;
345360 return true;
346361}
......@@ -348,6 +363,7 @@ inline bool Registers_x86_64::validRegister(int regNum) const {
348363inline uint64_t Registers_x86_64::getRegister(int regNum) const {
349364 switch (regNum) {
350365 case UNW_REG_IP:
366 case UNW_X86_64_RIP:
351367 return _registers.__rip;
352368 case UNW_REG_SP:
353369 return _registers.__rsp;
......@@ -390,6 +406,7 @@ inline uint64_t Registers_x86_64::getRegister(int regNum) const {
390406inline void Registers_x86_64::setRegister(int regNum, uint64_t value) {
391407 switch (regNum) {
392408 case UNW_REG_IP:
409 case UNW_X86_64_RIP:
393410 _registers.__rip = value;
394411 return;
395412 case UNW_REG_SP:
......@@ -450,6 +467,7 @@ inline void Registers_x86_64::setRegister(int regNum, uint64_t value) {
450467inline const char *Registers_x86_64::getRegisterName(int regNum) {
451468 switch (regNum) {
452469 case UNW_REG_IP:
470 case UNW_X86_64_RIP:
453471 return "rip";
454472 case UNW_REG_SP:
455473 return "rsp";
......@@ -1848,7 +1866,7 @@ inline bool Registers_arm64::validRegister(int regNum) const {
18481866 return false;
18491867 if (regNum > 95)
18501868 return false;
1851 if (regNum == UNW_ARM64_RA_SIGN_STATE)
1869 if (regNum == UNW_AARCH64_RA_SIGN_STATE)
18521870 return true;
18531871 if ((regNum > 32) && (regNum < 64))
18541872 return false;
......@@ -1856,15 +1874,15 @@ inline bool Registers_arm64::validRegister(int regNum) const {
18561874}
18571875
18581876inline uint64_t Registers_arm64::getRegister(int regNum) const {
1859 if (regNum == UNW_REG_IP || regNum == UNW_ARM64_PC)
1877 if (regNum == UNW_REG_IP || regNum == UNW_AARCH64_PC)
18601878 return _registers.__pc;
1861 if (regNum == UNW_REG_SP || regNum == UNW_ARM64_SP)
1879 if (regNum == UNW_REG_SP || regNum == UNW_AARCH64_SP)
18621880 return _registers.__sp;
1863 if (regNum == UNW_ARM64_RA_SIGN_STATE)
1881 if (regNum == UNW_AARCH64_RA_SIGN_STATE)
18641882 return _registers.__ra_sign_state;
1865 if (regNum == UNW_ARM64_FP)
1883 if (regNum == UNW_AARCH64_FP)
18661884 return _registers.__fp;
1867 if (regNum == UNW_ARM64_LR)
1885 if (regNum == UNW_AARCH64_LR)
18681886 return _registers.__lr;
18691887 if ((regNum >= 0) && (regNum < 29))
18701888 return _registers.__x[regNum];
......@@ -1872,15 +1890,15 @@ inline uint64_t Registers_arm64::getRegister(int regNum) const {
18721890}
18731891
18741892inline void Registers_arm64::setRegister(int regNum, uint64_t value) {
1875 if (regNum == UNW_REG_IP || regNum == UNW_ARM64_PC)
1893 if (regNum == UNW_REG_IP || regNum == UNW_AARCH64_PC)
18761894 _registers.__pc = value;
1877 else if (regNum == UNW_REG_SP || regNum == UNW_ARM64_SP)
1895 else if (regNum == UNW_REG_SP || regNum == UNW_AARCH64_SP)
18781896 _registers.__sp = value;
1879 else if (regNum == UNW_ARM64_RA_SIGN_STATE)
1897 else if (regNum == UNW_AARCH64_RA_SIGN_STATE)
18801898 _registers.__ra_sign_state = value;
1881 else if (regNum == UNW_ARM64_FP)
1899 else if (regNum == UNW_AARCH64_FP)
18821900 _registers.__fp = value;
1883 else if (regNum == UNW_ARM64_LR)
1901 else if (regNum == UNW_AARCH64_LR)
18841902 _registers.__lr = value;
18851903 else if ((regNum >= 0) && (regNum < 29))
18861904 _registers.__x[regNum] = value;
......@@ -1894,135 +1912,135 @@ inline const char *Registers_arm64::getRegisterName(int regNum) {
18941912 return "pc";
18951913 case UNW_REG_SP:
18961914 return "sp";
1897 case UNW_ARM64_X0:
1915 case UNW_AARCH64_X0:
18981916 return "x0";
1899 case UNW_ARM64_X1:
1917 case UNW_AARCH64_X1:
19001918 return "x1";
1901 case UNW_ARM64_X2:
1919 case UNW_AARCH64_X2:
19021920 return "x2";
1903 case UNW_ARM64_X3:
1921 case UNW_AARCH64_X3:
19041922 return "x3";
1905 case UNW_ARM64_X4:
1923 case UNW_AARCH64_X4:
19061924 return "x4";
1907 case UNW_ARM64_X5:
1925 case UNW_AARCH64_X5:
19081926 return "x5";
1909 case UNW_ARM64_X6:
1927 case UNW_AARCH64_X6:
19101928 return "x6";
1911 case UNW_ARM64_X7:
1929 case UNW_AARCH64_X7:
19121930 return "x7";
1913 case UNW_ARM64_X8:
1931 case UNW_AARCH64_X8:
19141932 return "x8";
1915 case UNW_ARM64_X9:
1933 case UNW_AARCH64_X9:
19161934 return "x9";
1917 case UNW_ARM64_X10:
1935 case UNW_AARCH64_X10:
19181936 return "x10";
1919 case UNW_ARM64_X11:
1937 case UNW_AARCH64_X11:
19201938 return "x11";
1921 case UNW_ARM64_X12:
1939 case UNW_AARCH64_X12:
19221940 return "x12";
1923 case UNW_ARM64_X13:
1941 case UNW_AARCH64_X13:
19241942 return "x13";
1925 case UNW_ARM64_X14:
1943 case UNW_AARCH64_X14:
19261944 return "x14";
1927 case UNW_ARM64_X15:
1945 case UNW_AARCH64_X15:
19281946 return "x15";
1929 case UNW_ARM64_X16:
1947 case UNW_AARCH64_X16:
19301948 return "x16";
1931 case UNW_ARM64_X17:
1949 case UNW_AARCH64_X17:
19321950 return "x17";
1933 case UNW_ARM64_X18:
1951 case UNW_AARCH64_X18:
19341952 return "x18";
1935 case UNW_ARM64_X19:
1953 case UNW_AARCH64_X19:
19361954 return "x19";
1937 case UNW_ARM64_X20:
1955 case UNW_AARCH64_X20:
19381956 return "x20";
1939 case UNW_ARM64_X21:
1957 case UNW_AARCH64_X21:
19401958 return "x21";
1941 case UNW_ARM64_X22:
1959 case UNW_AARCH64_X22:
19421960 return "x22";
1943 case UNW_ARM64_X23:
1961 case UNW_AARCH64_X23:
19441962 return "x23";
1945 case UNW_ARM64_X24:
1963 case UNW_AARCH64_X24:
19461964 return "x24";
1947 case UNW_ARM64_X25:
1965 case UNW_AARCH64_X25:
19481966 return "x25";
1949 case UNW_ARM64_X26:
1967 case UNW_AARCH64_X26:
19501968 return "x26";
1951 case UNW_ARM64_X27:
1969 case UNW_AARCH64_X27:
19521970 return "x27";
1953 case UNW_ARM64_X28:
1971 case UNW_AARCH64_X28:
19541972 return "x28";
1955 case UNW_ARM64_FP:
1973 case UNW_AARCH64_FP:
19561974 return "fp";
1957 case UNW_ARM64_LR:
1975 case UNW_AARCH64_LR:
19581976 return "lr";
1959 case UNW_ARM64_SP:
1977 case UNW_AARCH64_SP:
19601978 return "sp";
1961 case UNW_ARM64_PC:
1979 case UNW_AARCH64_PC:
19621980 return "pc";
1963 case UNW_ARM64_D0:
1981 case UNW_AARCH64_V0:
19641982 return "d0";
1965 case UNW_ARM64_D1:
1983 case UNW_AARCH64_V1:
19661984 return "d1";
1967 case UNW_ARM64_D2:
1985 case UNW_AARCH64_V2:
19681986 return "d2";
1969 case UNW_ARM64_D3:
1987 case UNW_AARCH64_V3:
19701988 return "d3";
1971 case UNW_ARM64_D4:
1989 case UNW_AARCH64_V4:
19721990 return "d4";
1973 case UNW_ARM64_D5:
1991 case UNW_AARCH64_V5:
19741992 return "d5";
1975 case UNW_ARM64_D6:
1993 case UNW_AARCH64_V6:
19761994 return "d6";
1977 case UNW_ARM64_D7:
1995 case UNW_AARCH64_V7:
19781996 return "d7";
1979 case UNW_ARM64_D8:
1997 case UNW_AARCH64_V8:
19801998 return "d8";
1981 case UNW_ARM64_D9:
1999 case UNW_AARCH64_V9:
19822000 return "d9";
1983 case UNW_ARM64_D10:
2001 case UNW_AARCH64_V10:
19842002 return "d10";
1985 case UNW_ARM64_D11:
2003 case UNW_AARCH64_V11:
19862004 return "d11";
1987 case UNW_ARM64_D12:
2005 case UNW_AARCH64_V12:
19882006 return "d12";
1989 case UNW_ARM64_D13:
2007 case UNW_AARCH64_V13:
19902008 return "d13";
1991 case UNW_ARM64_D14:
2009 case UNW_AARCH64_V14:
19922010 return "d14";
1993 case UNW_ARM64_D15:
2011 case UNW_AARCH64_V15:
19942012 return "d15";
1995 case UNW_ARM64_D16:
2013 case UNW_AARCH64_V16:
19962014 return "d16";
1997 case UNW_ARM64_D17:
2015 case UNW_AARCH64_V17:
19982016 return "d17";
1999 case UNW_ARM64_D18:
2017 case UNW_AARCH64_V18:
20002018 return "d18";
2001 case UNW_ARM64_D19:
2019 case UNW_AARCH64_V19:
20022020 return "d19";
2003 case UNW_ARM64_D20:
2021 case UNW_AARCH64_V20:
20042022 return "d20";
2005 case UNW_ARM64_D21:
2023 case UNW_AARCH64_V21:
20062024 return "d21";
2007 case UNW_ARM64_D22:
2025 case UNW_AARCH64_V22:
20082026 return "d22";
2009 case UNW_ARM64_D23:
2027 case UNW_AARCH64_V23:
20102028 return "d23";
2011 case UNW_ARM64_D24:
2029 case UNW_AARCH64_V24:
20122030 return "d24";
2013 case UNW_ARM64_D25:
2031 case UNW_AARCH64_V25:
20142032 return "d25";
2015 case UNW_ARM64_D26:
2033 case UNW_AARCH64_V26:
20162034 return "d26";
2017 case UNW_ARM64_D27:
2035 case UNW_AARCH64_V27:
20182036 return "d27";
2019 case UNW_ARM64_D28:
2037 case UNW_AARCH64_V28:
20202038 return "d28";
2021 case UNW_ARM64_D29:
2039 case UNW_AARCH64_V29:
20222040 return "d29";
2023 case UNW_ARM64_D30:
2041 case UNW_AARCH64_V30:
20242042 return "d30";
2025 case UNW_ARM64_D31:
2043 case UNW_AARCH64_V31:
20262044 return "d31";
20272045 default:
20282046 return "unknown register";
......@@ -2030,21 +2048,21 @@ inline const char *Registers_arm64::getRegisterName(int regNum) {
20302048}
20312049
20322050inline bool Registers_arm64::validFloatRegister(int regNum) const {
2033 if (regNum < UNW_ARM64_D0)
2051 if (regNum < UNW_AARCH64_V0)
20342052 return false;
2035 if (regNum > UNW_ARM64_D31)
2053 if (regNum > UNW_AARCH64_V31)
20362054 return false;
20372055 return true;
20382056}
20392057
20402058inline double Registers_arm64::getFloatRegister(int regNum) const {
20412059 assert(validFloatRegister(regNum));
2042 return _vectorHalfRegisters[regNum - UNW_ARM64_D0];
2060 return _vectorHalfRegisters[regNum - UNW_AARCH64_V0];
20432061}
20442062
20452063inline void Registers_arm64::setFloatRegister(int regNum, double value) {
20462064 assert(validFloatRegister(regNum));
2047 _vectorHalfRegisters[regNum - UNW_ARM64_D0] = value;
2065 _vectorHalfRegisters[regNum - UNW_AARCH64_V0] = value;
20482066}
20492067
20502068inline bool Registers_arm64::validVectorRegister(int) const {
......@@ -2123,6 +2141,10 @@ private:
21232141 uint32_t __pc; // Program counter r15
21242142 };
21252143
2144 struct PseudoRegisters {
2145 uint32_t __pac; // Return Authentication Code (PAC)
2146 };
2147
21262148 static void saveVFPWithFSTMD(void*);
21272149 static void saveVFPWithFSTMX(void*);
21282150 static void saveVFPv3(void*);
......@@ -2139,6 +2161,7 @@ private:
21392161
21402162 // ARM registers
21412163 GPRs _registers;
2164 PseudoRegisters _pseudo_registers;
21422165
21432166 // We save floating point registers lazily because we can't know ahead of
21442167 // time which ones are used. See EHABI #4.7.
......@@ -2176,6 +2199,7 @@ inline Registers_arm::Registers_arm(const void *registers)
21762199 "arm registers do not fit into unw_context_t");
21772200 // See __unw_getcontext() note about data.
21782201 memcpy(&_registers, registers, sizeof(_registers));
2202 memset(&_pseudo_registers, 0, sizeof(_pseudo_registers));
21792203 memset(&_vfp_d0_d15_pad, 0, sizeof(_vfp_d0_d15_pad));
21802204 memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));
21812205#if defined(__ARM_WMMX)
......@@ -2191,6 +2215,7 @@ inline Registers_arm::Registers_arm()
21912215 _saved_vfp_d0_d15(false),
21922216 _saved_vfp_d16_d31(false) {
21932217 memset(&_registers, 0, sizeof(_registers));
2218 memset(&_pseudo_registers, 0, sizeof(_pseudo_registers));
21942219 memset(&_vfp_d0_d15_pad, 0, sizeof(_vfp_d0_d15_pad));
21952220 memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));
21962221#if defined(__ARM_WMMX)
......@@ -2218,6 +2243,11 @@ inline bool Registers_arm::validRegister(int regNum) const {
22182243 return true;
22192244#endif
22202245
2246#ifdef __ARM_FEATURE_PAUTH
2247 if (regNum == UNW_ARM_RA_AUTH_CODE)
2248 return true;
2249#endif
2250
22212251 return false;
22222252}
22232253
......@@ -2244,6 +2274,11 @@ inline uint32_t Registers_arm::getRegister(int regNum) const {
22442274 }
22452275#endif
22462276
2277#ifdef __ARM_FEATURE_PAUTH
2278 if (regNum == UNW_ARM_RA_AUTH_CODE)
2279 return _pseudo_registers.__pac;
2280#endif
2281
22472282 _LIBUNWIND_ABORT("unsupported arm register");
22482283}
22492284
......@@ -2279,6 +2314,11 @@ inline void Registers_arm::setRegister(int regNum, uint32_t value) {
22792314 }
22802315#endif
22812316
2317 if (regNum == UNW_ARM_RA_AUTH_CODE) {
2318 _pseudo_registers.__pac = value;
2319 return;
2320 }
2321
22822322 _LIBUNWIND_ABORT("unsupported arm register");
22832323}
22842324
......@@ -3547,7 +3587,6 @@ inline const char *Registers_sparc::getRegisterName(int regNum) {
35473587}
35483588#endif // _LIBUNWIND_TARGET_SPARC
35493589
3550
35513590#if defined(_LIBUNWIND_TARGET_SPARC64)
35523591/// Registers_sparc64 holds the register state of a thread in a 64-bit
35533592/// sparc process.
lib/libunwind/src/Unwind-EHABI.cpp+212-10
......@@ -1,4 +1,4 @@
1//===--------------------------- Unwind-EHABI.cpp -------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -187,9 +187,14 @@ static _Unwind_Reason_Code unwindOneFrame(_Unwind_State state,
187187 if (result != _URC_CONTINUE_UNWIND)
188188 return result;
189189
190 if (__unw_step(reinterpret_cast<unw_cursor_t *>(context)) != UNW_STEP_SUCCESS)
190 switch (__unw_step(reinterpret_cast<unw_cursor_t *>(context))) {
191 case UNW_STEP_SUCCESS:
192 return _URC_CONTINUE_UNWIND;
193 case UNW_STEP_END:
194 return _URC_END_OF_STACK;
195 default:
191196 return _URC_FAILURE;
192 return _URC_CONTINUE_UNWIND;
197 }
193198}
194199
195200// Generates mask discriminator for _Unwind_VRS_Pop, e.g. for _UVRSC_CORE /
......@@ -256,6 +261,7 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
256261 size_t offset, size_t len) {
257262 bool wrotePC = false;
258263 bool finish = false;
264 bool hasReturnAddrAuthCode = false;
259265 while (offset < len && !finish) {
260266 uint8_t byte = getByte(data, offset++);
261267 if ((byte & 0x80) == 0) {
......@@ -342,6 +348,10 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
342348 break;
343349 }
344350 case 0xb4:
351 hasReturnAddrAuthCode = true;
352 _Unwind_VRS_Pop(context, _UVRSC_PSEUDO,
353 0 /* Return Address Auth Code */, _UVRSD_UINT32);
354 break;
345355 case 0xb5:
346356 case 0xb6:
347357 case 0xb7:
......@@ -417,6 +427,16 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
417427 if (!wrotePC) {
418428 uint32_t lr;
419429 _Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_LR, _UVRSD_UINT32, &lr);
430#ifdef __ARM_FEATURE_PAUTH
431 if (hasReturnAddrAuthCode) {
432 uint32_t sp;
433 uint32_t pac;
434 _Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, &sp);
435 _Unwind_VRS_Get(context, _UVRSC_PSEUDO, UNW_ARM_RA_AUTH_CODE,
436 _UVRSD_UINT32, &pac);
437 __asm__ __volatile__("autg %0, %1, %2" : : "r"(pac), "r"(lr), "r"(sp) :);
438 }
439#endif
420440 _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_IP, _UVRSD_UINT32, &lr);
421441 }
422442 return _URC_CONTINUE_UNWIND;
......@@ -463,6 +483,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
463483 return _URC_FATAL_PHASE1_ERROR;
464484 }
465485
486#ifndef NDEBUG
466487 // When tracing, print state information.
467488 if (_LIBUNWIND_TRACING_UNWINDING) {
468489 char functionBuf[512];
......@@ -481,6 +502,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
481502 frameInfo.start_ip, functionName,
482503 frameInfo.lsda, frameInfo.handler);
483504 }
505#endif
484506
485507 // If there is a personality routine, ask it if it will want to stop at
486508 // this frame.
......@@ -582,6 +604,7 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor
582604 return _URC_FATAL_PHASE2_ERROR;
583605 }
584606
607#ifndef NDEBUG
585608 // When tracing, print state information.
586609 if (_LIBUNWIND_TRACING_UNWINDING) {
587610 char functionBuf[512];
......@@ -598,11 +621,12 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor
598621 functionName, sp, frameInfo.lsda,
599622 frameInfo.handler);
600623 }
624#endif
601625
602626 // If there is a personality routine, tell it we are unwinding.
603627 if (frameInfo.handler != 0) {
604628 _Unwind_Personality_Fn p =
605 (_Unwind_Personality_Fn)(long)(frameInfo.handler);
629 (_Unwind_Personality_Fn)(intptr_t)(frameInfo.handler);
606630 struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor);
607631 // EHABI #7.2
608632 exception_object->pr_cache.fnstart = frameInfo.start_ip;
......@@ -670,6 +694,123 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor
670694 return _URC_FATAL_PHASE2_ERROR;
671695}
672696
697static _Unwind_Reason_Code
698unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
699 _Unwind_Exception *exception_object, _Unwind_Stop_Fn stop,
700 void *stop_parameter) {
701 bool endOfStack = false;
702 // See comment at the start of unwind_phase1 regarding VRS integrity.
703 __unw_init_local(cursor, uc);
704 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_force(ex_ojb=%p)",
705 static_cast<void *>(exception_object));
706 // Walk each frame until we reach where search phase said to stop
707 while (!endOfStack) {
708 // Update info about this frame.
709 unw_proc_info_t frameInfo;
710 if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
711 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_step "
712 "failed => _URC_END_OF_STACK",
713 (void *)exception_object);
714 return _URC_FATAL_PHASE2_ERROR;
715 }
716
717#ifndef NDEBUG
718 // When tracing, print state information.
719 if (_LIBUNWIND_TRACING_UNWINDING) {
720 char functionBuf[512];
721 const char *functionName = functionBuf;
722 unw_word_t offset;
723 if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
724 &offset) != UNW_ESUCCESS) ||
725 (frameInfo.start_ip + offset > frameInfo.end_ip))
726 functionName = ".anonymous.";
727 _LIBUNWIND_TRACE_UNWINDING(
728 "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR
729 ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR,
730 (void *)exception_object, frameInfo.start_ip, functionName,
731 frameInfo.lsda, frameInfo.handler);
732 }
733#endif
734
735 // Call stop function at each frame.
736 _Unwind_Action action =
737 (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE);
738 _Unwind_Reason_Code stopResult =
739 (*stop)(1, action, exception_object->exception_class, exception_object,
740 (_Unwind_Context *)(cursor), stop_parameter);
741 _LIBUNWIND_TRACE_UNWINDING(
742 "unwind_phase2_forced(ex_ojb=%p): stop function returned %d",
743 (void *)exception_object, stopResult);
744 if (stopResult != _URC_NO_REASON) {
745 _LIBUNWIND_TRACE_UNWINDING(
746 "unwind_phase2_forced(ex_ojb=%p): stopped by stop function",
747 (void *)exception_object);
748 return _URC_FATAL_PHASE2_ERROR;
749 }
750
751 // If there is a personality routine, tell it we are unwinding.
752 if (frameInfo.handler != 0) {
753 _Unwind_Personality_Fn p =
754 (_Unwind_Personality_Fn)(uintptr_t)(frameInfo.handler);
755 struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor);
756 // EHABI #7.2
757 exception_object->pr_cache.fnstart = frameInfo.start_ip;
758 exception_object->pr_cache.ehtp =
759 (_Unwind_EHT_Header *)frameInfo.unwind_info;
760 exception_object->pr_cache.additional = frameInfo.flags;
761 _Unwind_Reason_Code personalityResult =
762 (*p)(_US_FORCE_UNWIND | _US_UNWIND_FRAME_STARTING, exception_object,
763 context);
764 switch (personalityResult) {
765 case _URC_CONTINUE_UNWIND:
766 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
767 "personality returned "
768 "_URC_CONTINUE_UNWIND",
769 (void *)exception_object);
770 // Destructors called, continue unwinding
771 break;
772 case _URC_INSTALL_CONTEXT:
773 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
774 "personality returned "
775 "_URC_INSTALL_CONTEXT",
776 (void *)exception_object);
777 // We may get control back if landing pad calls _Unwind_Resume().
778 __unw_resume(cursor);
779 break;
780 case _URC_END_OF_STACK:
781 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
782 "personality returned "
783 "_URC_END_OF_STACK",
784 (void *)exception_object);
785 // Personalty routine did the step and it can't step forward.
786 endOfStack = true;
787 break;
788 default:
789 // Personality routine returned an unknown result code.
790 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
791 "personality returned %d, "
792 "_URC_FATAL_PHASE2_ERROR",
793 (void *)exception_object, personalityResult);
794 return _URC_FATAL_PHASE2_ERROR;
795 }
796 }
797 }
798
799 // Call stop function one last time and tell it we've reached the end
800 // of the stack.
801 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop "
802 "function with _UA_END_OF_STACK",
803 (void *)exception_object);
804 _Unwind_Action lastAction =
805 (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK);
806 (*stop)(1, lastAction, exception_object->exception_class, exception_object,
807 (struct _Unwind_Context *)(cursor), stop_parameter);
808
809 // Clean up phase did not resume at the frame that the search phase said it
810 // would.
811 return _URC_FATAL_PHASE2_ERROR;
812}
813
673814/// Called by __cxa_throw. Only returns if there is a fatal error.
674815_LIBUNWIND_EXPORT _Unwind_Reason_Code
675816_Unwind_RaiseException(_Unwind_Exception *exception_object) {
......@@ -717,10 +858,13 @@ _Unwind_Resume(_Unwind_Exception *exception_object) {
717858 unw_cursor_t cursor;
718859 __unw_getcontext(&uc);
719860
720 // _Unwind_RaiseException on EHABI will always set the reserved1 field to 0,
721 // which is in the same position as private_1 below.
722 // TODO(ajwong): Who wronte the above? Why is it true?
723 unwind_phase2(&uc, &cursor, exception_object, true);
861 if (exception_object->unwinder_cache.reserved1)
862 unwind_phase2_forced(
863 &uc, &cursor, exception_object,
864 (_Unwind_Stop_Fn)exception_object->unwinder_cache.reserved1,
865 (void *)exception_object->unwinder_cache.reserved3);
866 else
867 unwind_phase2(&uc, &cursor, exception_object, true);
724868
725869 // Clients assume _Unwind_Resume() does not return, so all we can do is abort.
726870 _LIBUNWIND_ABORT("_Unwind_Resume() can't return");
......@@ -812,6 +956,15 @@ _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
812956 case _UVRSC_WMMXD:
813957 break;
814958#endif
959 case _UVRSC_PSEUDO:
960 // There's only one pseudo-register, PAC, with regno == 0.
961 if (representation != _UVRSD_UINT32 || regno != 0)
962 return _UVRSR_FAILED;
963 return __unw_set_reg(cursor, (unw_regnum_t)(UNW_ARM_RA_AUTH_CODE),
964 *(unw_word_t *)valuep) == UNW_ESUCCESS
965 ? _UVRSR_OK
966 : _UVRSR_FAILED;
967 break;
815968 }
816969 _LIBUNWIND_ABORT("unsupported register class");
817970}
......@@ -866,6 +1019,15 @@ _Unwind_VRS_Get_Internal(_Unwind_Context *context,
8661019 case _UVRSC_WMMXD:
8671020 break;
8681021#endif
1022 case _UVRSC_PSEUDO:
1023 // There's only one pseudo-register, PAC, with regno == 0.
1024 if (representation != _UVRSD_UINT32 || regno != 0)
1025 return _UVRSR_FAILED;
1026 return __unw_get_reg(cursor, (unw_regnum_t)(UNW_ARM_RA_AUTH_CODE),
1027 (unw_word_t *)valuep) == UNW_ESUCCESS
1028 ? _UVRSR_OK
1029 : _UVRSR_FAILED;
1030 break;
8691031 }
8701032 _LIBUNWIND_ABORT("unsupported register class");
8711033}
......@@ -963,10 +1125,45 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
9631125 return _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32,
9641126 &sp);
9651127 }
1128 case _UVRSC_PSEUDO: {
1129 if (representation != _UVRSD_UINT32 || discriminator != 0)
1130 return _UVRSR_FAILED;
1131 // Return Address Authentication code (PAC) - discriminator 0
1132 uint32_t *sp;
1133 if (_Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32,
1134 &sp) != _UVRSR_OK) {
1135 return _UVRSR_FAILED;
1136 }
1137 uint32_t pac = *sp++;
1138 _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32, &sp);
1139 return _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_RA_AUTH_CODE,
1140 _UVRSD_UINT32, &pac);
1141 }
9661142 }
9671143 _LIBUNWIND_ABORT("unsupported register class");
9681144}
9691145
1146/// Not used by C++.
1147/// Unwinds stack, calling "stop" function at each frame.
1148/// Could be used to implement longjmp().
1149_LIBUNWIND_EXPORT _Unwind_Reason_Code
1150_Unwind_ForcedUnwind(_Unwind_Exception *exception_object, _Unwind_Stop_Fn stop,
1151 void *stop_parameter) {
1152 _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)",
1153 (void *)exception_object, (void *)(uintptr_t)stop);
1154 unw_context_t uc;
1155 unw_cursor_t cursor;
1156 __unw_getcontext(&uc);
1157
1158 // Mark that this is a forced unwind, so _Unwind_Resume() can do
1159 // the right thing.
1160 exception_object->unwinder_cache.reserved1 = (uintptr_t)stop;
1161 exception_object->unwinder_cache.reserved3 = (uintptr_t)stop_parameter;
1162
1163 return unwind_phase2_forced(&uc, &cursor, exception_object, stop,
1164 stop_parameter);
1165}
1166
9701167/// Called by personality handler during phase 2 to find the start of the
9711168/// function.
9721169_LIBUNWIND_EXPORT uintptr_t
......@@ -997,9 +1194,14 @@ extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code
9971194__gnu_unwind_frame(_Unwind_Exception *exception_object,
9981195 struct _Unwind_Context *context) {
9991196 unw_cursor_t *cursor = (unw_cursor_t *)context;
1000 if (__unw_step(cursor) != UNW_STEP_SUCCESS)
1197 switch (__unw_step(cursor)) {
1198 case UNW_STEP_SUCCESS:
1199 return _URC_OK;
1200 case UNW_STEP_END:
1201 return _URC_END_OF_STACK;
1202 default:
10011203 return _URC_FAILURE;
1002 return _URC_OK;
1204 }
10031205}
10041206
10051207#endif // defined(_LIBUNWIND_ARM_EHABI)
lib/libunwind/src/Unwind-EHABI.h+1-1
......@@ -1,4 +1,4 @@
1//===------------------------- Unwind-EHABI.hpp ---------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/Unwind-seh.cpp+5-5
......@@ -1,4 +1,4 @@
1//===--------------------------- Unwind-seh.cpp ---------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -28,8 +28,6 @@
2828#include "libunwind_ext.h"
2929#include "UnwindCursor.hpp"
3030
31#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
32
3331using namespace libunwind;
3432
3533#define STATUS_USER_DEFINED (1u << 29)
......@@ -171,8 +169,8 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
171169 __unw_get_reg(&cursor, UNW_ARM_R1, &exc->private_[3]);
172170#elif defined(__aarch64__)
173171 exc->private_[2] = disp->TargetPc;
174 __unw_get_reg(&cursor, UNW_ARM64_X0, &retval);
175 __unw_get_reg(&cursor, UNW_ARM64_X1, &exc->private_[3]);
172 __unw_get_reg(&cursor, UNW_AARCH64_X0, &retval);
173 __unw_get_reg(&cursor, UNW_AARCH64_X1, &exc->private_[3]);
176174#endif
177175 __unw_get_reg(&cursor, UNW_REG_IP, &target);
178176 ms_exc->ExceptionCode = STATUS_GCC_UNWIND;
......@@ -246,6 +244,7 @@ unwind_phase2_forced(unw_context_t *uc,
246244 return _URC_FATAL_PHASE2_ERROR;
247245 }
248246
247#ifndef NDEBUG
249248 // When tracing, print state information.
250249 if (_LIBUNWIND_TRACING_UNWINDING) {
251250 char functionBuf[512];
......@@ -261,6 +260,7 @@ unwind_phase2_forced(unw_context_t *uc,
261260 (void *)exception_object, frameInfo.start_ip, functionName,
262261 frameInfo.lsda, frameInfo.handler);
263262 }
263#endif
264264
265265 // Call stop function at each frame.
266266 _Unwind_Action action =
lib/libunwind/src/Unwind-sjlj.c+1-1
......@@ -1,4 +1,4 @@
1//===--------------------------- Unwind-sjlj.c ----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/UnwindCursor.hpp+61-43
......@@ -1,4 +1,4 @@
1//===------------------------- UnwindCursor.hpp ---------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -11,6 +11,7 @@
1111#ifndef __UNWINDCURSOR_HPP__
1212#define __UNWINDCURSOR_HPP__
1313
14#include "cet_unwind.h"
1415#include <stdint.h>
1516#include <stdio.h>
1617#include <stdlib.h>
......@@ -449,6 +450,12 @@ public:
449450#ifdef __arm__
450451 virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }
451452#endif
453
454#if defined(_LIBUNWIND_USE_CET)
455 virtual void *get_registers() {
456 _LIBUNWIND_ABORT("get_registers not implemented");
457 }
458#endif
452459};
453460
454461#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
......@@ -620,12 +627,12 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
620627 _msContext.D[i - UNW_ARM_D0] = d.w;
621628 }
622629#elif defined(_LIBUNWIND_TARGET_AARCH64)
623 for (int i = UNW_ARM64_X0; i <= UNW_ARM64_X30; ++i)
624 _msContext.X[i - UNW_ARM64_X0] = r.getRegister(i);
630 for (int i = UNW_AARCH64_X0; i <= UNW_ARM64_X30; ++i)
631 _msContext.X[i - UNW_AARCH64_X0] = r.getRegister(i);
625632 _msContext.Sp = r.getRegister(UNW_REG_SP);
626633 _msContext.Pc = r.getRegister(UNW_REG_IP);
627 for (int i = UNW_ARM64_D0; i <= UNW_ARM64_D31; ++i)
628 _msContext.V[i - UNW_ARM64_D0].D[0] = r.getFloatRegister(i);
634 for (int i = UNW_AARCH64_V0; i <= UNW_ARM64_D31; ++i)
635 _msContext.V[i - UNW_AARCH64_V0].D[0] = r.getFloatRegister(i);
629636#endif
630637}
631638
......@@ -648,9 +655,11 @@ bool UnwindCursor<A, R>::validReg(int regNum) {
648655#if defined(_LIBUNWIND_TARGET_X86_64)
649656 if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;
650657#elif defined(_LIBUNWIND_TARGET_ARM)
651 if (regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) return true;
658 if ((regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) ||
659 regNum == UNW_ARM_RA_AUTH_CODE)
660 return true;
652661#elif defined(_LIBUNWIND_TARGET_AARCH64)
653 if (regNum >= UNW_ARM64_X0 && regNum <= UNW_ARM64_X30) return true;
662 if (regNum >= UNW_AARCH64_X0 && regNum <= UNW_ARM64_X30) return true;
654663#endif
655664 return false;
656665}
......@@ -699,7 +708,7 @@ unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
699708#elif defined(_LIBUNWIND_TARGET_AARCH64)
700709 case UNW_REG_SP: return _msContext.Sp;
701710 case UNW_REG_IP: return _msContext.Pc;
702 default: return _msContext.X[regNum - UNW_ARM64_X0];
711 default: return _msContext.X[regNum - UNW_AARCH64_X0];
703712#endif
704713 }
705714 _LIBUNWIND_ABORT("unsupported register");
......@@ -749,37 +758,37 @@ void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
749758#elif defined(_LIBUNWIND_TARGET_AARCH64)
750759 case UNW_REG_SP: _msContext.Sp = value; break;
751760 case UNW_REG_IP: _msContext.Pc = value; break;
752 case UNW_ARM64_X0:
753 case UNW_ARM64_X1:
754 case UNW_ARM64_X2:
755 case UNW_ARM64_X3:
756 case UNW_ARM64_X4:
757 case UNW_ARM64_X5:
758 case UNW_ARM64_X6:
759 case UNW_ARM64_X7:
760 case UNW_ARM64_X8:
761 case UNW_ARM64_X9:
762 case UNW_ARM64_X10:
763 case UNW_ARM64_X11:
764 case UNW_ARM64_X12:
765 case UNW_ARM64_X13:
766 case UNW_ARM64_X14:
767 case UNW_ARM64_X15:
768 case UNW_ARM64_X16:
769 case UNW_ARM64_X17:
770 case UNW_ARM64_X18:
771 case UNW_ARM64_X19:
772 case UNW_ARM64_X20:
773 case UNW_ARM64_X21:
774 case UNW_ARM64_X22:
775 case UNW_ARM64_X23:
776 case UNW_ARM64_X24:
777 case UNW_ARM64_X25:
778 case UNW_ARM64_X26:
779 case UNW_ARM64_X27:
780 case UNW_ARM64_X28:
781 case UNW_ARM64_FP:
782 case UNW_ARM64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;
761 case UNW_AARCH64_X0:
762 case UNW_AARCH64_X1:
763 case UNW_AARCH64_X2:
764 case UNW_AARCH64_X3:
765 case UNW_AARCH64_X4:
766 case UNW_AARCH64_X5:
767 case UNW_AARCH64_X6:
768 case UNW_AARCH64_X7:
769 case UNW_AARCH64_X8:
770 case UNW_AARCH64_X9:
771 case UNW_AARCH64_X10:
772 case UNW_AARCH64_X11:
773 case UNW_AARCH64_X12:
774 case UNW_AARCH64_X13:
775 case UNW_AARCH64_X14:
776 case UNW_AARCH64_X15:
777 case UNW_AARCH64_X16:
778 case UNW_AARCH64_X17:
779 case UNW_AARCH64_X18:
780 case UNW_AARCH64_X19:
781 case UNW_AARCH64_X20:
782 case UNW_AARCH64_X21:
783 case UNW_AARCH64_X22:
784 case UNW_AARCH64_X23:
785 case UNW_AARCH64_X24:
786 case UNW_AARCH64_X25:
787 case UNW_AARCH64_X26:
788 case UNW_AARCH64_X27:
789 case UNW_AARCH64_X28:
790 case UNW_AARCH64_FP:
791 case UNW_AARCH64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;
783792#endif
784793 default:
785794 _LIBUNWIND_ABORT("unsupported register");
......@@ -792,7 +801,7 @@ bool UnwindCursor<A, R>::validFloatReg(int regNum) {
792801 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;
793802 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;
794803#elif defined(_LIBUNWIND_TARGET_AARCH64)
795 if (regNum >= UNW_ARM64_D0 && regNum <= UNW_ARM64_D31) return true;
804 if (regNum >= UNW_AARCH64_V0 && regNum <= UNW_ARM64_D31) return true;
796805#else
797806 (void)regNum;
798807#endif
......@@ -820,7 +829,7 @@ unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
820829 }
821830 _LIBUNWIND_ABORT("unsupported float register");
822831#elif defined(_LIBUNWIND_TARGET_AARCH64)
823 return _msContext.V[regNum - UNW_ARM64_D0].D[0];
832 return _msContext.V[regNum - UNW_AARCH64_V0].D[0];
824833#else
825834 (void)regNum;
826835 _LIBUNWIND_ABORT("float registers unimplemented");
......@@ -848,7 +857,7 @@ void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
848857 }
849858 _LIBUNWIND_ABORT("unsupported float register");
850859#elif defined(_LIBUNWIND_TARGET_AARCH64)
851 _msContext.V[regNum - UNW_ARM64_D0].D[0] = value;
860 _msContext.V[regNum - UNW_AARCH64_V0].D[0] = value;
852861#else
853862 (void)regNum;
854863 (void)value;
......@@ -901,6 +910,9 @@ public:
901910 virtual void saveVFPAsX();
902911#endif
903912
913#if defined(_LIBUNWIND_USE_CET)
914 virtual void *get_registers() { return &_registers; }
915#endif
904916 // libunwind does not and should not depend on C++ library which means that we
905917 // need our own defition of inline placement new.
906918 static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
......@@ -2077,7 +2089,7 @@ int UnwindCursor<A, R>::stepThroughSigReturn(Registers_arm64 &) {
20772089 for (int i = 0; i <= 30; ++i) {
20782090 uint64_t value = _addressSpace.get64(sigctx + kOffsetGprs +
20792091 static_cast<pint_t>(i * 8));
2080 _registers.setRegister(UNW_ARM64_X0 + i, value);
2092 _registers.setRegister(UNW_AARCH64_X0 + i, value);
20812093 }
20822094 _registers.setSP(_addressSpace.get64(sigctx + kOffsetSp));
20832095 _registers.setIP(_addressSpace.get64(sigctx + kOffsetPc));
......@@ -2141,6 +2153,12 @@ bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
21412153 buf, bufLen, offset);
21422154}
21432155
2156#if defined(_LIBUNWIND_USE_CET)
2157extern "C" void *__libunwind_cet_get_registers(unw_cursor_t *cursor) {
2158 AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
2159 return co->get_registers();
2160}
2161#endif
21442162} // namespace libunwind
21452163
21462164#endif // __UNWINDCURSOR_HPP__
lib/libunwind/src/UnwindLevel1-gcc-ext.c+11-22
......@@ -1,4 +1,4 @@
1//===--------------------- UnwindLevel1-gcc-ext.c -------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -22,36 +22,27 @@
2222#include "Unwind-EHABI.h"
2323#include "unwind.h"
2424
25#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
26
2725#if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS)
2826
2927#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)
30#define private_1 private_[0]
28#define PRIVATE_1 private_[0]
29#elif defined(_LIBUNWIND_ARM_EHABI)
30#define PRIVATE_1 unwinder_cache.reserved1
31#else
32#define PRIVATE_1 private_1
3133#endif
3234
3335/// Called by __cxa_rethrow().
3436_LIBUNWIND_EXPORT _Unwind_Reason_Code
3537_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
36#if defined(_LIBUNWIND_ARM_EHABI)
37 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",
38 (void *)exception_object,
39 (long)exception_object->unwinder_cache.reserved1);
40#else
41 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR,
42 (void *)exception_object,
43 (intptr_t)exception_object->private_1);
44#endif
38 _LIBUNWIND_TRACE_API(
39 "_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR,
40 (void *)exception_object, (intptr_t)exception_object->PRIVATE_1);
4541
46#if defined(_LIBUNWIND_ARM_EHABI)
47 // _Unwind_RaiseException on EHABI will always set the reserved1 field to 0,
48 // which is in the same position as private_1 below.
49 return _Unwind_RaiseException(exception_object);
50#else
5142 // If this is non-forced and a stopping place was found, then this is a
5243 // re-throw.
5344 // Call _Unwind_RaiseException() as if this was a new exception
54 if (exception_object->private_1 == 0) {
45 if (exception_object->PRIVATE_1 == 0) {
5546 return _Unwind_RaiseException(exception_object);
5647 // Will return if there is no catch clause, so that __cxa_rethrow can call
5748 // std::terminate().
......@@ -62,10 +53,8 @@ _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
6253 _Unwind_Resume(exception_object);
6354 _LIBUNWIND_ABORT("_Unwind_Resume_or_Rethrow() called _Unwind_RaiseException()"
6455 " which unexpectedly returned");
65#endif
6656}
6757
68
6958/// Called by personality handler during phase 2 to get base address for data
7059/// relative encodings.
7160_LIBUNWIND_EXPORT uintptr_t
......@@ -120,7 +109,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
120109 // Create a mock exception object for force unwinding.
121110 _Unwind_Exception ex;
122111 memset(&ex, '\0', sizeof(ex));
123 ex.exception_class = 0x434C4E47554E5700; // CLNGUNW\0
112 strcpy((char *)&ex.exception_class, "CLNGUNW");
124113#endif
125114
126115 // walk each frame
lib/libunwind/src/UnwindLevel1.c+52-6
......@@ -1,4 +1,4 @@
1//===------------------------- UnwindLevel1.c -----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -25,17 +25,48 @@
2525#include <stdio.h>
2626#include <string.h>
2727
28#include "cet_unwind.h"
2829#include "config.h"
2930#include "libunwind.h"
3031#include "libunwind_ext.h"
3132#include "unwind.h"
3233
33#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
34
3534#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
3635
3736#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
3837
38// When CET is enabled, each "call" instruction will push return address to
39// CET shadow stack, each "ret" instruction will pop current CET shadow stack
40// top and compare it with target address which program will return.
41// In exception handing, some stack frames will be skipped before jumping to
42// landing pad and we must adjust CET shadow stack accordingly.
43// _LIBUNWIND_POP_CET_SSP is used to adjust CET shadow stack pointer and we
44// directly jump to __libunwind_Registerts_x86/x86_64_jumpto instead of using
45// a regular function call to avoid pushing to CET shadow stack again.
46#if !defined(_LIBUNWIND_USE_CET)
47#define __unw_phase2_resume(cursor, fn) __unw_resume((cursor))
48#elif defined(_LIBUNWIND_TARGET_I386)
49#define __unw_phase2_resume(cursor, fn) \
50 do { \
51 _LIBUNWIND_POP_CET_SSP((fn)); \
52 void *cetRegContext = __libunwind_cet_get_registers((cursor)); \
53 void *cetJumpAddress = __libunwind_cet_get_jump_target(); \
54 __asm__ volatile("push %%edi\n\t" \
55 "sub $4, %%esp\n\t" \
56 "jmp *%%edx\n\t" :: "D"(cetRegContext), \
57 "d"(cetJumpAddress)); \
58 } while (0)
59#elif defined(_LIBUNWIND_TARGET_X86_64)
60#define __unw_phase2_resume(cursor, fn) \
61 do { \
62 _LIBUNWIND_POP_CET_SSP((fn)); \
63 void *cetRegContext = __libunwind_cet_get_registers((cursor)); \
64 void *cetJumpAddress = __libunwind_cet_get_jump_target(); \
65 __asm__ volatile("jmpq *%%rdx\n\t" :: "D"(cetRegContext), \
66 "d"(cetJumpAddress)); \
67 } while (0)
68#endif
69
3970static _Unwind_Reason_Code
4071unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
4172 __unw_init_local(cursor, uc);
......@@ -70,6 +101,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
70101 return _URC_FATAL_PHASE1_ERROR;
71102 }
72103
104#ifndef NDEBUG
73105 // When tracing, print state information.
74106 if (_LIBUNWIND_TRACING_UNWINDING) {
75107 char functionBuf[512];
......@@ -87,6 +119,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
87119 (void *)exception_object, pc, frameInfo.start_ip, functionName,
88120 frameInfo.lsda, frameInfo.handler);
89121 }
122#endif
90123
91124 // If there is a personality routine, ask it if it will want to stop at
92125 // this frame.
......@@ -137,6 +170,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
137170 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)",
138171 (void *)exception_object);
139172
173 // uc is initialized by __unw_getcontext in the parent frame. The first stack
174 // frame walked is unwind_phase2.
175 unsigned framesWalked = 1;
140176 // Walk each frame until we reach where search phase said to stop.
141177 while (true) {
142178
......@@ -169,6 +205,7 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
169205 return _URC_FATAL_PHASE2_ERROR;
170206 }
171207
208#ifndef NDEBUG
172209 // When tracing, print state information.
173210 if (_LIBUNWIND_TRACING_UNWINDING) {
174211 char functionBuf[512];
......@@ -185,7 +222,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
185222 functionName, sp, frameInfo.lsda,
186223 frameInfo.handler);
187224 }
225#endif
188226
227 ++framesWalked;
189228 // If there is a personality routine, tell it we are unwinding.
190229 if (frameInfo.handler != 0) {
191230 _Unwind_Personality_Fn p =
......@@ -225,8 +264,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
225264 ", sp=0x%" PRIxPTR,
226265 (void *)exception_object, pc, sp);
227266 }
228 __unw_resume(cursor);
229 // __unw_resume() only returns if there was an error.
267
268 __unw_phase2_resume(cursor, framesWalked);
269 // __unw_phase2_resume() only returns if there was an error.
230270 return _URC_FATAL_PHASE2_ERROR;
231271 default:
232272 // Personality routine returned an unknown result code.
......@@ -248,6 +288,9 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
248288 _Unwind_Stop_Fn stop, void *stop_parameter) {
249289 __unw_init_local(cursor, uc);
250290
291 // uc is initialized by __unw_getcontext in the parent frame. The first stack
292 // frame walked is unwind_phase2_forced.
293 unsigned framesWalked = 1;
251294 // Walk each frame until we reach where search phase said to stop
252295 while (__unw_step(cursor) > 0) {
253296
......@@ -260,6 +303,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
260303 return _URC_FATAL_PHASE2_ERROR;
261304 }
262305
306#ifndef NDEBUG
263307 // When tracing, print state information.
264308 if (_LIBUNWIND_TRACING_UNWINDING) {
265309 char functionBuf[512];
......@@ -275,6 +319,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
275319 (void *)exception_object, frameInfo.start_ip, functionName,
276320 frameInfo.lsda, frameInfo.handler);
277321 }
322#endif
278323
279324 // Call stop function at each frame.
280325 _Unwind_Action action =
......@@ -292,6 +337,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
292337 return _URC_FATAL_PHASE2_ERROR;
293338 }
294339
340 ++framesWalked;
295341 // If there is a personality routine, tell it we are unwinding.
296342 if (frameInfo.handler != 0) {
297343 _Unwind_Personality_Fn p =
......@@ -316,7 +362,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
316362 "_URC_INSTALL_CONTEXT",
317363 (void *)exception_object);
318364 // We may get control back if landing pad calls _Unwind_Resume().
319 __unw_resume(cursor);
365 __unw_phase2_resume(cursor, framesWalked);
320366 break;
321367 default:
322368 // Personality routine returned an unknown result code.
lib/libunwind/src/UnwindRegistersRestore.S+18-6
......@@ -1,4 +1,4 @@
1//===-------------------- UnwindRegistersRestore.S ------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -25,6 +25,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
2525# + return address +
2626# +-----------------------+ <-- SP
2727# + +
28
29 _LIBUNWIND_CET_ENDBR
2830 movl 4(%esp), %eax
2931 # set up eax and ret on new stack location
3032 movl 28(%eax), %edx # edx holds new stack pointer
......@@ -46,7 +48,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
4648 # skip ss
4749 # skip eflags
4850 pop %eax # eax was already pushed on new stack
49 ret # eip was already pushed on new stack
51 pop %ecx
52 jmp *%ecx
5053 # skip cs
5154 # skip ds
5255 # skip es
......@@ -70,6 +73,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
7073# On entry, thread_state pointer is in rdi
7174#endif
7275
76 _LIBUNWIND_CET_ENDBR
7377 movq 56(%rdi), %rax # rax holds new stack pointer
7478 subq $16, %rax
7579 movq %rax, 56(%rdi)
......@@ -119,7 +123,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
119123#endif
120124 movq 56(%rdi), %rsp # cut back rsp to new location
121125 pop %rdi # rdi was saved here earlier
122 ret # rip was saved here
126 pop %rcx
127 jmpq *%rcx
123128
124129
125130#elif defined(__powerpc64__)
......@@ -389,7 +394,7 @@ Lnovec:
389394 PPC64_LR(3)
390395 bctr
391396
392#elif defined(__ppc__)
397#elif defined(__powerpc__)
393398
394399DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_ppc6jumptoEv)
395400//
......@@ -655,7 +660,13 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv)
655660 ldr sp, [lr, #52]
656661 ldr lr, [lr, #60] @ restore pc into lr
657662#endif
663#if defined(__ARM_FEATURE_BTI_DEFAULT) && !defined(__ARM_ARCH_ISA_ARM)
664 // 'bx' is not BTI setting when used with lr, therefore r12 is used instead
665 mov r12, lr
666 JMP(r12)
667#else
658668 JMP(lr)
669#endif
659670
660671@
661672@ static void libunwind::Registers_arm::restoreVFPWithFLDMD(unw_fpreg_t* values)
......@@ -800,11 +811,12 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind14Registers_or1k6jumptoEv)
800811 l.lwz r30,120(r3)
801812 l.lwz r31,124(r3)
802813
814 # load new pc into ra
815 l.lwz r9, 128(r3)
816
803817 # at last, restore r3
804818 l.lwz r3, 12(r3)
805819
806 # load new pc into ra
807 l.lwz r9, 128(r3)
808820 # jump to pc
809821 l.jr r9
810822 l.nop
lib/libunwind/src/UnwindRegistersSave.S+8-3
......@@ -1,4 +1,4 @@
1//===------------------------ UnwindRegistersSave.S -----------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -27,6 +27,8 @@
2727# + +
2828#
2929DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
30
31 _LIBUNWIND_CET_ENDBR
3032 push %eax
3133 movl 8(%esp), %eax
3234 movl %ebx, 4(%eax)
......@@ -70,6 +72,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
7072#define TMP %rsi
7173#endif
7274
75 _LIBUNWIND_CET_ENDBR
7376 movq %rax, (PTR)
7477 movq %rbx, 8(PTR)
7578 movq %rcx, 16(PTR)
......@@ -556,7 +559,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
556559 blr
557560
558561
559#elif defined(__ppc__)
562#elif defined(__powerpc__)
560563
561564//
562565// extern int unw_getcontext(unw_context_t* thread_state)
......@@ -600,9 +603,11 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
600603 stw 30,128(3)
601604 stw 31,132(3)
602605
606#if defined(__ALTIVEC__)
603607 // save VRSave register
604608 mfspr 0, 256
605609 stw 0, 156(3)
610#endif
606611 // save CR registers
607612 mfcr 0
608613 stw 0, 136(3)
......@@ -766,7 +771,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
766771@
767772@ On entry:
768773@ thread_state pointer is in r0
769@
774@
770775@ Per EHABI #4.7 this only saves the core integer registers.
771776@ EHABI #7.4.5 notes that in general all VRS registers should be restored
772777@ however this is very hard to do for VFP registers because it is unknown
lib/libunwind/src/Unwind_AppleExtras.cpp+1-1
......@@ -1,4 +1,4 @@
1//===--------------------- Unwind_AppleExtras.cpp -------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/assembly.h+20-2
......@@ -15,6 +15,13 @@
1515#ifndef UNWIND_ASSEMBLY_H
1616#define UNWIND_ASSEMBLY_H
1717
18#if defined(__linux__) && defined(__CET__)
19#include <cet.h>
20#define _LIBUNWIND_CET_ENDBR _CET_ENDBR
21#else
22#define _LIBUNWIND_CET_ENDBR
23#endif
24
1825#if defined(__powerpc64__)
1926#define SEPARATOR ;
2027#define PPC64_OFFS_SRR0 0
......@@ -74,7 +81,7 @@
7481#define PPC64_OPD2
7582#endif
7683
77#if defined(__ARM_FEATURE_BTI_DEFAULT)
84#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
7885 .pushsection ".note.gnu.property", "a" SEPARATOR \
7986 .balign 8 SEPARATOR \
8087 .long 4 SEPARATOR \
......@@ -92,6 +99,17 @@
9299#define AARCH64_BTI
93100#endif
94101
102#if !defined(__aarch64__)
103#ifdef __ARM_FEATURE_PAC_DEFAULT
104 .eabi_attribute Tag_PAC_extension, 2
105 .eabi_attribute Tag_PACRET_use, 1
106#endif
107#ifdef __ARM_FEATURE_BTI_DEFAULT
108 .eabi_attribute Tag_BTI_extension, 1
109 .eabi_attribute Tag_BTI_use, 1
110#endif
111#endif
112
95113#define GLUE2(a, b) a ## b
96114#define GLUE(a, b) GLUE2(a, b)
97115#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
......@@ -216,7 +234,7 @@
216234#endif
217235#endif /* __arm__ */
218236
219#if defined(__ppc__) || defined(__powerpc64__)
237#if defined(__powerpc__)
220238#define PPC_LEFT_SHIFT(index) << (index)
221239#endif
222240
lib/libunwind/src/cet_unwind.h created+41
......@@ -0,0 +1,41 @@
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LIBUNWIND_CET_UNWIND_H
11#define LIBUNWIND_CET_UNWIND_H
12
13#include "libunwind.h"
14
15// Currently, CET is implemented on Linux x86 platforms.
16#if defined(_LIBUNWIND_TARGET_LINUX) && defined(__CET__) && defined(__SHSTK__)
17#define _LIBUNWIND_USE_CET 1
18#endif
19
20#if defined(_LIBUNWIND_USE_CET)
21#include <cet.h>
22#include <immintrin.h>
23
24#define _LIBUNWIND_POP_CET_SSP(x) \
25 do { \
26 unsigned long ssp = _get_ssp(); \
27 if (ssp != 0) { \
28 unsigned int tmp = (x); \
29 while (tmp > 255) { \
30 _inc_ssp(255); \
31 tmp -= 255; \
32 } \
33 _inc_ssp(tmp); \
34 } \
35 } while (0)
36#endif
37
38extern void *__libunwind_cet_get_registers(unw_cursor_t *);
39extern void *__libunwind_cet_get_jump_target();
40
41#endif
lib/libunwind/src/config.h+2-2
......@@ -1,4 +1,4 @@
1//===----------------------------- config.h -------------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -105,7 +105,7 @@
105105#define _LIBUNWIND_BUILD_SJLJ_APIS
106106#endif
107107
108#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__)
108#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
109109#define _LIBUNWIND_SUPPORT_FRAME_APIS
110110#endif
111111
lib/libunwind/src/dwarf2.h+1-1
......@@ -1,4 +1,4 @@
1//===------------------------------- dwarf2.h -----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/libunwind.cpp+33-6
......@@ -1,4 +1,4 @@
1//===--------------------------- libunwind.cpp ----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -11,8 +11,8 @@
1111
1212#include <libunwind.h>
1313
14#include "libunwind_ext.h"
1514#include "config.h"
15#include "libunwind_ext.h"
1616
1717#include <stdlib.h>
1818
......@@ -30,8 +30,6 @@
3030#include "AddressSpace.hpp"
3131#include "UnwindCursor.hpp"
3232
33#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
34
3533using namespace libunwind;
3634
3735/// internal object to represent this processes address space
......@@ -53,7 +51,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
5351# define REGISTER_KIND Registers_x86_64
5452#elif defined(__powerpc64__)
5553# define REGISTER_KIND Registers_ppc64
56#elif defined(__ppc__)
54#elif defined(__powerpc__)
5755# define REGISTER_KIND Registers_ppc
5856#elif defined(__aarch64__)
5957# define REGISTER_KIND Registers_arm64
......@@ -70,7 +68,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
7068#elif defined(__mips__)
7169# warning The MIPS architecture is not supported with this ABI and environment!
7270#elif defined(__sparc__) && defined(__arch64__)
73# define REGISTER_KIND Registers_sparc64
71#define REGISTER_KIND Registers_sparc64
7472#elif defined(__sparc__)
7573# define REGISTER_KIND Registers_sparc
7674#elif defined(__riscv)
......@@ -296,6 +294,35 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
296294 // fde is own mh_group
297295 DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);
298296}
297
298void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
299 // The eh_frame section start serves as the mh_group
300 unw_word_t mh_group = eh_frame_start;
301 CFI_Parser<LocalAddressSpace>::CIE_Info cieInfo;
302 CFI_Parser<LocalAddressSpace>::FDE_Info fdeInfo;
303 auto p = (LocalAddressSpace::pint_t)eh_frame_start;
304 while (true) {
305 if (CFI_Parser<LocalAddressSpace>::decodeFDE(
306 LocalAddressSpace::sThisAddressSpace, p, &fdeInfo, &cieInfo,
307 true) == NULL) {
308 DwarfFDECache<LocalAddressSpace>::add((LocalAddressSpace::pint_t)mh_group,
309 fdeInfo.pcStart, fdeInfo.pcEnd,
310 fdeInfo.fdeStart);
311 p += fdeInfo.fdeLength;
312 } else if (CFI_Parser<LocalAddressSpace>::parseCIE(
313 LocalAddressSpace::sThisAddressSpace, p, &cieInfo) == NULL) {
314 p += cieInfo.cieLength;
315 } else
316 return;
317 }
318}
319
320void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
321 // The eh_frame section start serves as the mh_group
322 DwarfFDECache<LocalAddressSpace>::removeAllIn(
323 (LocalAddressSpace::pint_t)eh_frame_start);
324}
325
299326#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
300327#endif // !defined(__USING_SJLJ_EXCEPTIONS__)
301328
lib/libunwind/src/libunwind_ext.h+4-1
......@@ -1,4 +1,4 @@
1//===------------------------ libunwind_ext.h -----------------------------===//
1//===----------------------------------------------------------------------===//
22//
33// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44// See https://llvm.org/LICENSE.txt for license information.
......@@ -51,6 +51,9 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
5151extern void __unw_add_dynamic_fde(unw_word_t fde);
5252extern void __unw_remove_dynamic_fde(unw_word_t fde);
5353
54extern void __unw_add_dynamic_eh_frame_section(unw_word_t eh_frame_start);
55extern void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start);
56
5457#if defined(_LIBUNWIND_ARM_EHABI)
5558extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*);
5659extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context,