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,4 +1,4 @@
1//===------------------------- __libunwind_config.h -----------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -56,7 +56,7 @@...@@ -56,7 +56,7 @@
56# define _LIBUNWIND_CONTEXT_SIZE 16756# define _LIBUNWIND_CONTEXT_SIZE 167
57# define _LIBUNWIND_CURSOR_SIZE 17957# define _LIBUNWIND_CURSOR_SIZE 179
58# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC6458# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64
59# elif defined(__ppc__)59# elif defined(__powerpc__)
60# define _LIBUNWIND_TARGET_PPC 160# define _LIBUNWIND_TARGET_PPC 1
61# define _LIBUNWIND_CONTEXT_SIZE 11761# define _LIBUNWIND_CONTEXT_SIZE 117
62# define _LIBUNWIND_CURSOR_SIZE 12462# define _LIBUNWIND_CURSOR_SIZE 124
...@@ -126,11 +126,12 @@...@@ -126,11 +126,12 @@
126# error "Unsupported MIPS ABI and/or environment"126# error "Unsupported MIPS ABI and/or environment"
127# endif127# endif
128# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS128# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_MIPS
129# elif defined(__sparc__) && defined(__arch64__)129#elif defined(__sparc__) && defined(__arch64__)
130# define _LIBUNWIND_TARGET_SPARC64 1130#define _LIBUNWIND_TARGET_SPARC64 1
131# define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC64131#define _LIBUNWIND_HIGHEST_DWARF_REGISTER \
132# define _LIBUNWIND_CONTEXT_SIZE 33132 _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC64
133# define _LIBUNWIND_CURSOR_SIZE 45133#define _LIBUNWIND_CONTEXT_SIZE 33
134#define _LIBUNWIND_CURSOR_SIZE 45
134# elif defined(__sparc__)135# elif defined(__sparc__)
135 #define _LIBUNWIND_TARGET_SPARC 1136 #define _LIBUNWIND_TARGET_SPARC 1
136 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC137 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER _LIBUNWIND_HIGHEST_DWARF_REGISTER_SPARC
lib/libunwind/include/libunwind.h+146-72
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===---------------------------- libunwind.h -----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -493,77 +493,150 @@ enum {...@@ -493,77 +493,150 @@ enum {
493493
494// 64-bit ARM64 registers494// 64-bit ARM64 registers
495enum {495enum {
496 UNW_ARM64_X0 = 0,496 UNW_AARCH64_X0 = 0,
497 UNW_ARM64_X1 = 1,497 UNW_AARCH64_X1 = 1,
498 UNW_ARM64_X2 = 2,498 UNW_AARCH64_X2 = 2,
499 UNW_ARM64_X3 = 3,499 UNW_AARCH64_X3 = 3,
500 UNW_ARM64_X4 = 4,500 UNW_AARCH64_X4 = 4,
501 UNW_ARM64_X5 = 5,501 UNW_AARCH64_X5 = 5,
502 UNW_ARM64_X6 = 6,502 UNW_AARCH64_X6 = 6,
503 UNW_ARM64_X7 = 7,503 UNW_AARCH64_X7 = 7,
504 UNW_ARM64_X8 = 8,504 UNW_AARCH64_X8 = 8,
505 UNW_ARM64_X9 = 9,505 UNW_AARCH64_X9 = 9,
506 UNW_ARM64_X10 = 10,506 UNW_AARCH64_X10 = 10,
507 UNW_ARM64_X11 = 11,507 UNW_AARCH64_X11 = 11,
508 UNW_ARM64_X12 = 12,508 UNW_AARCH64_X12 = 12,
509 UNW_ARM64_X13 = 13,509 UNW_AARCH64_X13 = 13,
510 UNW_ARM64_X14 = 14,510 UNW_AARCH64_X14 = 14,
511 UNW_ARM64_X15 = 15,511 UNW_AARCH64_X15 = 15,
512 UNW_ARM64_X16 = 16,512 UNW_AARCH64_X16 = 16,
513 UNW_ARM64_X17 = 17,513 UNW_AARCH64_X17 = 17,
514 UNW_ARM64_X18 = 18,514 UNW_AARCH64_X18 = 18,
515 UNW_ARM64_X19 = 19,515 UNW_AARCH64_X19 = 19,
516 UNW_ARM64_X20 = 20,516 UNW_AARCH64_X20 = 20,
517 UNW_ARM64_X21 = 21,517 UNW_AARCH64_X21 = 21,
518 UNW_ARM64_X22 = 22,518 UNW_AARCH64_X22 = 22,
519 UNW_ARM64_X23 = 23,519 UNW_AARCH64_X23 = 23,
520 UNW_ARM64_X24 = 24,520 UNW_AARCH64_X24 = 24,
521 UNW_ARM64_X25 = 25,521 UNW_AARCH64_X25 = 25,
522 UNW_ARM64_X26 = 26,522 UNW_AARCH64_X26 = 26,
523 UNW_ARM64_X27 = 27,523 UNW_AARCH64_X27 = 27,
524 UNW_ARM64_X28 = 28,524 UNW_AARCH64_X28 = 28,
525 UNW_ARM64_X29 = 29,525 UNW_AARCH64_X29 = 29,
526 UNW_ARM64_FP = 29,526 UNW_AARCH64_FP = 29,
527 UNW_ARM64_X30 = 30,527 UNW_AARCH64_X30 = 30,
528 UNW_ARM64_LR = 30,528 UNW_AARCH64_LR = 30,
529 UNW_ARM64_X31 = 31,529 UNW_AARCH64_X31 = 31,
530 UNW_ARM64_SP = 31,530 UNW_AARCH64_SP = 31,
531 UNW_ARM64_PC = 32,531 UNW_AARCH64_PC = 32,
532 // reserved block532
533 UNW_ARM64_RA_SIGN_STATE = 34,
534 // reserved block533 // reserved block
535 UNW_ARM64_D0 = 64,534 UNW_AARCH64_RA_SIGN_STATE = 34,
536 UNW_ARM64_D1 = 65,535
537 UNW_ARM64_D2 = 66,536 // FP/vector registers
538 UNW_ARM64_D3 = 67,537 UNW_AARCH64_V0 = 64,
539 UNW_ARM64_D4 = 68,538 UNW_AARCH64_V1 = 65,
540 UNW_ARM64_D5 = 69,539 UNW_AARCH64_V2 = 66,
541 UNW_ARM64_D6 = 70,540 UNW_AARCH64_V3 = 67,
542 UNW_ARM64_D7 = 71,541 UNW_AARCH64_V4 = 68,
543 UNW_ARM64_D8 = 72,542 UNW_AARCH64_V5 = 69,
544 UNW_ARM64_D9 = 73,543 UNW_AARCH64_V6 = 70,
545 UNW_ARM64_D10 = 74,544 UNW_AARCH64_V7 = 71,
546 UNW_ARM64_D11 = 75,545 UNW_AARCH64_V8 = 72,
547 UNW_ARM64_D12 = 76,546 UNW_AARCH64_V9 = 73,
548 UNW_ARM64_D13 = 77,547 UNW_AARCH64_V10 = 74,
549 UNW_ARM64_D14 = 78,548 UNW_AARCH64_V11 = 75,
550 UNW_ARM64_D15 = 79,549 UNW_AARCH64_V12 = 76,
551 UNW_ARM64_D16 = 80,550 UNW_AARCH64_V13 = 77,
552 UNW_ARM64_D17 = 81,551 UNW_AARCH64_V14 = 78,
553 UNW_ARM64_D18 = 82,552 UNW_AARCH64_V15 = 79,
554 UNW_ARM64_D19 = 83,553 UNW_AARCH64_V16 = 80,
555 UNW_ARM64_D20 = 84,554 UNW_AARCH64_V17 = 81,
556 UNW_ARM64_D21 = 85,555 UNW_AARCH64_V18 = 82,
557 UNW_ARM64_D22 = 86,556 UNW_AARCH64_V19 = 83,
558 UNW_ARM64_D23 = 87,557 UNW_AARCH64_V20 = 84,
559 UNW_ARM64_D24 = 88,558 UNW_AARCH64_V21 = 85,
560 UNW_ARM64_D25 = 89,559 UNW_AARCH64_V22 = 86,
561 UNW_ARM64_D26 = 90,560 UNW_AARCH64_V23 = 87,
562 UNW_ARM64_D27 = 91,561 UNW_AARCH64_V24 = 88,
563 UNW_ARM64_D28 = 92,562 UNW_AARCH64_V25 = 89,
564 UNW_ARM64_D29 = 93,563 UNW_AARCH64_V26 = 90,
565 UNW_ARM64_D30 = 94,564 UNW_AARCH64_V27 = 91,
566 UNW_ARM64_D31 = 95,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,
567};640};
568641
569// 32-bit ARM registers. Numbers match DWARF for ARM spec #3.1 Table 1.642// 32-bit ARM registers. Numbers match DWARF for ARM spec #3.1 Table 1.
...@@ -645,7 +718,8 @@ enum {...@@ -645,7 +718,8 @@ enum {
645 UNW_ARM_WR14 = 126,718 UNW_ARM_WR14 = 126,
646 UNW_ARM_WR15 = 127,719 UNW_ARM_WR15 = 127,
647 // 128-133 -- SPSR, SPSR_{FIQ|IRQ|ABT|UND|SVC}720 // 128-133 -- SPSR, SPSR_{FIQ|IRQ|ABT|UND|SVC}
648 // 134-143 -- Reserved721 // 134-142 -- Reserved
722 UNW_ARM_RA_AUTH_CODE = 143,
649 // 144-150 -- R8_USR-R14_USR723 // 144-150 -- R8_USR-R14_USR
650 // 151-157 -- R8_FIQ-R14_FIQ724 // 151-157 -- R8_FIQ-R14_FIQ
651 // 158-159 -- R13_IRQ-R14_IRQ725 // 158-159 -- R13_IRQ-R14_IRQ
lib/libunwind/include/mach-o/compact_unwind_encoding.h+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------ mach-o/compact_unwind_encoding.h ------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/include/unwind.h+5-193
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------------- unwind.h -----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -56,211 +56,23 @@ typedef enum {...@@ -56,211 +56,23 @@ typedef enum {
56typedef struct _Unwind_Context _Unwind_Context; // opaque56typedef struct _Unwind_Context _Unwind_Context; // opaque
5757
58#if defined(_LIBUNWIND_ARM_EHABI)58#if defined(_LIBUNWIND_ARM_EHABI)
59typedef uint32_t _Unwind_State;59#include "unwind_arm_ehabi.h"
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);
117#else60#else
118struct _Unwind_Context; // opaque61#include "unwind_itanium.h"
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
131#endif62#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
144typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)64typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
145 (int version,65 (int version,
146 _Unwind_Action actions,66 _Unwind_Action actions,
147 uint64_t exceptionClass,67 _Unwind_Exception_Class exceptionClass,
148 _Unwind_Exception* exceptionObject,68 _Unwind_Exception* exceptionObject,
149 struct _Unwind_Context* context,69 struct _Unwind_Context* context,
150 void* stop_parameter );70 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
15671
157#ifdef __cplusplus72#ifdef __cplusplus
158extern "C" {73extern "C" {
159#endif74#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
264extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);76extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context *context);
265extern uintptr_t77extern uintptr_t
266 _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context);78 _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,4 +1,4 @@
1//===------------------------- AddressSpace.hpp ---------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -121,23 +121,23 @@ struct UnwindInfoSections {...@@ -121,23 +121,23 @@ struct UnwindInfoSections {
121 uintptr_t dso_base;121 uintptr_t dso_base;
122#endif122#endif
123#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)123#if defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
124 uintptr_t text_segment_length;124 size_t text_segment_length;
125#endif125#endif
126#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)126#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
127 uintptr_t dwarf_section;127 uintptr_t dwarf_section;
128 uintptr_t dwarf_section_length;128 size_t dwarf_section_length;
129#endif129#endif
130#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)130#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
131 uintptr_t dwarf_index_section;131 uintptr_t dwarf_index_section;
132 uintptr_t dwarf_index_section_length;132 size_t dwarf_index_section_length;
133#endif133#endif
134#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)134#if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
135 uintptr_t compact_unwind_section;135 uintptr_t compact_unwind_section;
136 uintptr_t compact_unwind_section_length;136 size_t compact_unwind_section_length;
137#endif137#endif
138#if defined(_LIBUNWIND_ARM_EHABI)138#if defined(_LIBUNWIND_ARM_EHABI)
139 uintptr_t arm_section;139 uintptr_t arm_section;
140 uintptr_t arm_section_length;140 size_t arm_section_length;
141#endif141#endif
142};142};
143143
...@@ -430,7 +430,7 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base,...@@ -430,7 +430,7 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base,
430 // .eh_frame_hdr records the start of .eh_frame, but not its size.430 // .eh_frame_hdr records the start of .eh_frame, but not its size.
431 // Rely on a zero terminator to find the end of the section.431 // Rely on a zero terminator to find the end of the section.
432 cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;432 cbdata->sects->dwarf_section = hdrInfo.eh_frame_ptr;
433 cbdata->sects->dwarf_section_length = UINTPTR_MAX;433 cbdata->sects->dwarf_section_length = SIZE_MAX;
434 return true;434 return true;
435 }435 }
436 }436 }
...@@ -506,22 +506,22 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,...@@ -506,22 +506,22 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
506 info.dso_base = (uintptr_t)dyldInfo.mh;506 info.dso_base = (uintptr_t)dyldInfo.mh;
507 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)507 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
508 info.dwarf_section = (uintptr_t)dyldInfo.dwarf_section;508 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;
510 #endif510 #endif
511 info.compact_unwind_section = (uintptr_t)dyldInfo.compact_unwind_section;511 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;
513 return true;513 return true;
514 }514 }
515#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)515#elif defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) && defined(_LIBUNWIND_IS_BAREMETAL)
516 info.dso_base = 0;516 info.dso_base = 0;
517 // Bare metal is statically linked, so no need to ask the dynamic loader517 // 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);
519 info.dwarf_section = (uintptr_t)(&__eh_frame_start);519 info.dwarf_section = (uintptr_t)(&__eh_frame_start);
520 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",520 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",
521 (void *)info.dwarf_section, (void *)info.dwarf_section_length);521 (void *)info.dwarf_section, (void *)info.dwarf_section_length);
522#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)522#if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
523 info.dwarf_index_section = (uintptr_t)(&__eh_frame_hdr_start);523 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);
525 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: index section %p length %p",525 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: index section %p length %p",
526 (void *)info.dwarf_index_section, (void *)info.dwarf_index_section_length);526 (void *)info.dwarf_index_section, (void *)info.dwarf_index_section_length);
527#endif527#endif
...@@ -530,7 +530,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,...@@ -530,7 +530,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
530#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)530#elif defined(_LIBUNWIND_ARM_EHABI) && defined(_LIBUNWIND_IS_BAREMETAL)
531 // Bare metal is statically linked, so no need to ask the dynamic loader531 // Bare metal is statically linked, so no need to ask the dynamic loader
532 info.arm_section = (uintptr_t)(&__exidx_start);532 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);
534 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",534 _LIBUNWIND_TRACE_UNWINDING("findUnwindSections: section %p length %p",
535 (void *)info.arm_section, (void *)info.arm_section_length);535 (void *)info.arm_section, (void *)info.arm_section_length);
536 if (info.arm_section && info.arm_section_length)536 if (info.arm_section && info.arm_section_length)
...@@ -584,7 +584,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,...@@ -584,7 +584,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr,
584 int length = 0;584 int length = 0;
585 info.arm_section =585 info.arm_section =
586 (uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length);586 (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);
588 if (info.arm_section && info.arm_section_length)588 if (info.arm_section && info.arm_section_length)
589 return true;589 return true;
590#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)590#elif defined(_LIBUNWIND_USE_DL_ITERATE_PHDR)
lib/libunwind/src/CompactUnwinder.hpp+38-38
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===-------------------------- CompactUnwinder.hpp -----------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -537,65 +537,65 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrameless(...@@ -537,65 +537,65 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrameless(
537 uint64_t savedRegisterLoc = registers.getSP() + stackSize;537 uint64_t savedRegisterLoc = registers.getSP() + stackSize;
538538
539 if (encoding & UNWIND_ARM64_FRAME_X19_X20_PAIR) {539 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));
541 savedRegisterLoc -= 8;541 savedRegisterLoc -= 8;
542 registers.setRegister(UNW_ARM64_X20, addressSpace.get64(savedRegisterLoc));542 registers.setRegister(UNW_AARCH64_X20, addressSpace.get64(savedRegisterLoc));
543 savedRegisterLoc -= 8;543 savedRegisterLoc -= 8;
544 }544 }
545 if (encoding & UNWIND_ARM64_FRAME_X21_X22_PAIR) {545 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));
547 savedRegisterLoc -= 8;547 savedRegisterLoc -= 8;
548 registers.setRegister(UNW_ARM64_X22, addressSpace.get64(savedRegisterLoc));548 registers.setRegister(UNW_AARCH64_X22, addressSpace.get64(savedRegisterLoc));
549 savedRegisterLoc -= 8;549 savedRegisterLoc -= 8;
550 }550 }
551 if (encoding & UNWIND_ARM64_FRAME_X23_X24_PAIR) {551 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));
553 savedRegisterLoc -= 8;553 savedRegisterLoc -= 8;
554 registers.setRegister(UNW_ARM64_X24, addressSpace.get64(savedRegisterLoc));554 registers.setRegister(UNW_AARCH64_X24, addressSpace.get64(savedRegisterLoc));
555 savedRegisterLoc -= 8;555 savedRegisterLoc -= 8;
556 }556 }
557 if (encoding & UNWIND_ARM64_FRAME_X25_X26_PAIR) {557 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));
559 savedRegisterLoc -= 8;559 savedRegisterLoc -= 8;
560 registers.setRegister(UNW_ARM64_X26, addressSpace.get64(savedRegisterLoc));560 registers.setRegister(UNW_AARCH64_X26, addressSpace.get64(savedRegisterLoc));
561 savedRegisterLoc -= 8;561 savedRegisterLoc -= 8;
562 }562 }
563 if (encoding & UNWIND_ARM64_FRAME_X27_X28_PAIR) {563 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));
565 savedRegisterLoc -= 8;565 savedRegisterLoc -= 8;
566 registers.setRegister(UNW_ARM64_X28, addressSpace.get64(savedRegisterLoc));566 registers.setRegister(UNW_AARCH64_X28, addressSpace.get64(savedRegisterLoc));
567 savedRegisterLoc -= 8;567 savedRegisterLoc -= 8;
568 }568 }
569569
570 if (encoding & UNWIND_ARM64_FRAME_D8_D9_PAIR) {570 if (encoding & UNWIND_ARM64_FRAME_D8_D9_PAIR) {
571 registers.setFloatRegister(UNW_ARM64_D8,571 registers.setFloatRegister(UNW_AARCH64_V8,
572 addressSpace.getDouble(savedRegisterLoc));572 addressSpace.getDouble(savedRegisterLoc));
573 savedRegisterLoc -= 8;573 savedRegisterLoc -= 8;
574 registers.setFloatRegister(UNW_ARM64_D9,574 registers.setFloatRegister(UNW_AARCH64_V9,
575 addressSpace.getDouble(savedRegisterLoc));575 addressSpace.getDouble(savedRegisterLoc));
576 savedRegisterLoc -= 8;576 savedRegisterLoc -= 8;
577 }577 }
578 if (encoding & UNWIND_ARM64_FRAME_D10_D11_PAIR) {578 if (encoding & UNWIND_ARM64_FRAME_D10_D11_PAIR) {
579 registers.setFloatRegister(UNW_ARM64_D10,579 registers.setFloatRegister(UNW_AARCH64_V10,
580 addressSpace.getDouble(savedRegisterLoc));580 addressSpace.getDouble(savedRegisterLoc));
581 savedRegisterLoc -= 8;581 savedRegisterLoc -= 8;
582 registers.setFloatRegister(UNW_ARM64_D11,582 registers.setFloatRegister(UNW_AARCH64_V11,
583 addressSpace.getDouble(savedRegisterLoc));583 addressSpace.getDouble(savedRegisterLoc));
584 savedRegisterLoc -= 8;584 savedRegisterLoc -= 8;
585 }585 }
586 if (encoding & UNWIND_ARM64_FRAME_D12_D13_PAIR) {586 if (encoding & UNWIND_ARM64_FRAME_D12_D13_PAIR) {
587 registers.setFloatRegister(UNW_ARM64_D12,587 registers.setFloatRegister(UNW_AARCH64_V12,
588 addressSpace.getDouble(savedRegisterLoc));588 addressSpace.getDouble(savedRegisterLoc));
589 savedRegisterLoc -= 8;589 savedRegisterLoc -= 8;
590 registers.setFloatRegister(UNW_ARM64_D13,590 registers.setFloatRegister(UNW_AARCH64_V13,
591 addressSpace.getDouble(savedRegisterLoc));591 addressSpace.getDouble(savedRegisterLoc));
592 savedRegisterLoc -= 8;592 savedRegisterLoc -= 8;
593 }593 }
594 if (encoding & UNWIND_ARM64_FRAME_D14_D15_PAIR) {594 if (encoding & UNWIND_ARM64_FRAME_D14_D15_PAIR) {
595 registers.setFloatRegister(UNW_ARM64_D14,595 registers.setFloatRegister(UNW_AARCH64_V14,
596 addressSpace.getDouble(savedRegisterLoc));596 addressSpace.getDouble(savedRegisterLoc));
597 savedRegisterLoc -= 8;597 savedRegisterLoc -= 8;
598 registers.setFloatRegister(UNW_ARM64_D15,598 registers.setFloatRegister(UNW_AARCH64_V15,
599 addressSpace.getDouble(savedRegisterLoc));599 addressSpace.getDouble(savedRegisterLoc));
600 savedRegisterLoc -= 8;600 savedRegisterLoc -= 8;
601 }601 }
...@@ -604,7 +604,7 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrameless(...@@ -604,7 +604,7 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrameless(
604 registers.setSP(savedRegisterLoc);604 registers.setSP(savedRegisterLoc);
605605
606 // set pc to be value in lr606 // set pc to be value in lr
607 registers.setIP(registers.getRegister(UNW_ARM64_LR));607 registers.setIP(registers.getRegister(UNW_AARCH64_LR));
608608
609 return UNW_STEP_SUCCESS;609 return UNW_STEP_SUCCESS;
610}610}
...@@ -616,65 +616,65 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrame(...@@ -616,65 +616,65 @@ int CompactUnwinder_arm64<A>::stepWithCompactEncodingFrame(
616 uint64_t savedRegisterLoc = registers.getFP() - 8;616 uint64_t savedRegisterLoc = registers.getFP() - 8;
617617
618 if (encoding & UNWIND_ARM64_FRAME_X19_X20_PAIR) {618 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));
620 savedRegisterLoc -= 8;620 savedRegisterLoc -= 8;
621 registers.setRegister(UNW_ARM64_X20, addressSpace.get64(savedRegisterLoc));621 registers.setRegister(UNW_AARCH64_X20, addressSpace.get64(savedRegisterLoc));
622 savedRegisterLoc -= 8;622 savedRegisterLoc -= 8;
623 }623 }
624 if (encoding & UNWIND_ARM64_FRAME_X21_X22_PAIR) {624 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));
626 savedRegisterLoc -= 8;626 savedRegisterLoc -= 8;
627 registers.setRegister(UNW_ARM64_X22, addressSpace.get64(savedRegisterLoc));627 registers.setRegister(UNW_AARCH64_X22, addressSpace.get64(savedRegisterLoc));
628 savedRegisterLoc -= 8;628 savedRegisterLoc -= 8;
629 }629 }
630 if (encoding & UNWIND_ARM64_FRAME_X23_X24_PAIR) {630 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));
632 savedRegisterLoc -= 8;632 savedRegisterLoc -= 8;
633 registers.setRegister(UNW_ARM64_X24, addressSpace.get64(savedRegisterLoc));633 registers.setRegister(UNW_AARCH64_X24, addressSpace.get64(savedRegisterLoc));
634 savedRegisterLoc -= 8;634 savedRegisterLoc -= 8;
635 }635 }
636 if (encoding & UNWIND_ARM64_FRAME_X25_X26_PAIR) {636 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));
638 savedRegisterLoc -= 8;638 savedRegisterLoc -= 8;
639 registers.setRegister(UNW_ARM64_X26, addressSpace.get64(savedRegisterLoc));639 registers.setRegister(UNW_AARCH64_X26, addressSpace.get64(savedRegisterLoc));
640 savedRegisterLoc -= 8;640 savedRegisterLoc -= 8;
641 }641 }
642 if (encoding & UNWIND_ARM64_FRAME_X27_X28_PAIR) {642 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));
644 savedRegisterLoc -= 8;644 savedRegisterLoc -= 8;
645 registers.setRegister(UNW_ARM64_X28, addressSpace.get64(savedRegisterLoc));645 registers.setRegister(UNW_AARCH64_X28, addressSpace.get64(savedRegisterLoc));
646 savedRegisterLoc -= 8;646 savedRegisterLoc -= 8;
647 }647 }
648648
649 if (encoding & UNWIND_ARM64_FRAME_D8_D9_PAIR) {649 if (encoding & UNWIND_ARM64_FRAME_D8_D9_PAIR) {
650 registers.setFloatRegister(UNW_ARM64_D8,650 registers.setFloatRegister(UNW_AARCH64_V8,
651 addressSpace.getDouble(savedRegisterLoc));651 addressSpace.getDouble(savedRegisterLoc));
652 savedRegisterLoc -= 8;652 savedRegisterLoc -= 8;
653 registers.setFloatRegister(UNW_ARM64_D9,653 registers.setFloatRegister(UNW_AARCH64_V9,
654 addressSpace.getDouble(savedRegisterLoc));654 addressSpace.getDouble(savedRegisterLoc));
655 savedRegisterLoc -= 8;655 savedRegisterLoc -= 8;
656 }656 }
657 if (encoding & UNWIND_ARM64_FRAME_D10_D11_PAIR) {657 if (encoding & UNWIND_ARM64_FRAME_D10_D11_PAIR) {
658 registers.setFloatRegister(UNW_ARM64_D10,658 registers.setFloatRegister(UNW_AARCH64_V10,
659 addressSpace.getDouble(savedRegisterLoc));659 addressSpace.getDouble(savedRegisterLoc));
660 savedRegisterLoc -= 8;660 savedRegisterLoc -= 8;
661 registers.setFloatRegister(UNW_ARM64_D11,661 registers.setFloatRegister(UNW_AARCH64_V11,
662 addressSpace.getDouble(savedRegisterLoc));662 addressSpace.getDouble(savedRegisterLoc));
663 savedRegisterLoc -= 8;663 savedRegisterLoc -= 8;
664 }664 }
665 if (encoding & UNWIND_ARM64_FRAME_D12_D13_PAIR) {665 if (encoding & UNWIND_ARM64_FRAME_D12_D13_PAIR) {
666 registers.setFloatRegister(UNW_ARM64_D12,666 registers.setFloatRegister(UNW_AARCH64_V12,
667 addressSpace.getDouble(savedRegisterLoc));667 addressSpace.getDouble(savedRegisterLoc));
668 savedRegisterLoc -= 8;668 savedRegisterLoc -= 8;
669 registers.setFloatRegister(UNW_ARM64_D13,669 registers.setFloatRegister(UNW_AARCH64_V13,
670 addressSpace.getDouble(savedRegisterLoc));670 addressSpace.getDouble(savedRegisterLoc));
671 savedRegisterLoc -= 8;671 savedRegisterLoc -= 8;
672 }672 }
673 if (encoding & UNWIND_ARM64_FRAME_D14_D15_PAIR) {673 if (encoding & UNWIND_ARM64_FRAME_D14_D15_PAIR) {
674 registers.setFloatRegister(UNW_ARM64_D14,674 registers.setFloatRegister(UNW_AARCH64_V14,
675 addressSpace.getDouble(savedRegisterLoc));675 addressSpace.getDouble(savedRegisterLoc));
676 savedRegisterLoc -= 8;676 savedRegisterLoc -= 8;
677 registers.setFloatRegister(UNW_ARM64_D15,677 registers.setFloatRegister(UNW_AARCH64_V15,
678 addressSpace.getDouble(savedRegisterLoc));678 addressSpace.getDouble(savedRegisterLoc));
679 savedRegisterLoc -= 8;679 savedRegisterLoc -= 8;
680 }680 }
lib/libunwind/src/DwarfInstructions.hpp+26-10
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===-------------------------- DwarfInstructions.hpp ---------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -67,14 +67,13 @@ private:...@@ -67,14 +67,13 @@ private:
67 return (pint_t)((sint_t)registers.getRegister((int)prolog.cfaRegister) +67 return (pint_t)((sint_t)registers.getRegister((int)prolog.cfaRegister) +
68 prolog.cfaRegisterOffset);68 prolog.cfaRegisterOffset);
69 if (prolog.cfaExpression != 0)69 if (prolog.cfaExpression != 0)
70 return evaluateExpression((pint_t)prolog.cfaExpression, addressSpace,70 return evaluateExpression((pint_t)prolog.cfaExpression, addressSpace,
71 registers, 0);71 registers, 0);
72 assert(0 && "getCFA(): unknown location");72 assert(0 && "getCFA(): unknown location");
73 __builtin_unreachable();73 __builtin_unreachable();
74 }74 }
75};75};
7676
77
78template <typename R>77template <typename R>
79auto getSparcWCookie(const R &r, int) -> decltype(r.getWCookie()) {78auto getSparcWCookie(const R &r, int) -> decltype(r.getWCookie()) {
80 return r.getWCookie();79 return r.getWCookie();
...@@ -92,8 +91,8 @@ typename A::pint_t DwarfInstructions<A, R>::getSavedRegister(...@@ -92,8 +91,8 @@ typename A::pint_t DwarfInstructions<A, R>::getSavedRegister(
92 return (pint_t)addressSpace.getRegister(cfa + (pint_t)savedReg.value);91 return (pint_t)addressSpace.getRegister(cfa + (pint_t)savedReg.value);
9392
94 case CFI_Parser<A>::kRegisterInCFADecrypt: // sparc64 specific93 case CFI_Parser<A>::kRegisterInCFADecrypt: // sparc64 specific
95 return addressSpace.getP(cfa + (pint_t)savedReg.value) ^94 return (pint_t)(addressSpace.getP(cfa + (pint_t)savedReg.value) ^
96 getSparcWCookie(registers, 0);95 getSparcWCookie(registers, 0));
9796
98 case CFI_Parser<A>::kRegisterAtExpression:97 case CFI_Parser<A>::kRegisterAtExpression:
99 return (pint_t)addressSpace.getRegister(evaluateExpression(98 return (pint_t)addressSpace.getRegister(evaluateExpression(
...@@ -127,12 +126,15 @@ double DwarfInstructions<A, R>::getSavedFloatRegister(...@@ -127,12 +126,15 @@ double DwarfInstructions<A, R>::getSavedFloatRegister(
127 return addressSpace.getDouble(126 return addressSpace.getDouble(
128 evaluateExpression((pint_t)savedReg.value, addressSpace,127 evaluateExpression((pint_t)savedReg.value, addressSpace,
129 registers, cfa));128 registers, cfa));
130129 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
131 case CFI_Parser<A>::kRegisterIsExpression:135 case CFI_Parser<A>::kRegisterIsExpression:
132 case CFI_Parser<A>::kRegisterUnused:136 case CFI_Parser<A>::kRegisterUnused:
133 case CFI_Parser<A>::kRegisterUndefined:
134 case CFI_Parser<A>::kRegisterOffsetFromCFA:137 case CFI_Parser<A>::kRegisterOffsetFromCFA:
135 case CFI_Parser<A>::kRegisterInRegister:
136 case CFI_Parser<A>::kRegisterInCFADecrypt:138 case CFI_Parser<A>::kRegisterInCFADecrypt:
137 // FIX ME139 // FIX ME
138 break;140 break;
...@@ -233,7 +235,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,...@@ -233,7 +235,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
233 // restored. autia1716 is used instead of autia as autia1716 assembles235 // restored. autia1716 is used instead of autia as autia1716 assembles
234 // to a NOP on pre-v8.3a architectures.236 // to a NOP on pre-v8.3a architectures.
235 if ((R::getArch() == REGISTERS_ARM64) &&237 if ((R::getArch() == REGISTERS_ARM64) &&
236 prolog.savedRegisters[UNW_ARM64_RA_SIGN_STATE].value &&238 prolog.savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value &&
237 returnAddress != 0) {239 returnAddress != 0) {
238#if !defined(_LIBUNWIND_IS_NATIVE_ONLY)240#if !defined(_LIBUNWIND_IS_NATIVE_ONLY)
239 return UNW_ECROSSRASIGNING;241 return UNW_ECROSSRASIGNING;
...@@ -253,6 +255,20 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,...@@ -253,6 +255,20 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
253 }255 }
254#endif256#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
256#if defined(_LIBUNWIND_TARGET_SPARC)272#if defined(_LIBUNWIND_TARGET_SPARC)
257 if (R::getArch() == REGISTERS_SPARC) {273 if (R::getArch() == REGISTERS_SPARC) {
258 // Skip call site instruction and delay slot274 // Skip call site instruction and delay slot
...@@ -264,7 +280,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,...@@ -264,7 +280,7 @@ int DwarfInstructions<A, R>::stepWithDwarf(A &addressSpace, pint_t pc,
264#endif280#endif
265281
266#if defined(_LIBUNWIND_TARGET_SPARC64)282#if defined(_LIBUNWIND_TARGET_SPARC64)
267 // Skip call site instruction and delay slot283 // Skip call site instruction and delay slot.
268 if (R::getArch() == REGISTERS_SPARC64)284 if (R::getArch() == REGISTERS_SPARC64)
269 returnAddress += 8;285 returnAddress += 8;
270#endif286#endif
lib/libunwind/src/DwarfParser.hpp+26-14
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===--------------------------- DwarfParser.hpp --------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -152,10 +152,11 @@ public:...@@ -152,10 +152,11 @@ public:
152 };152 };
153153
154 static bool findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,154 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,
156 CIE_Info *cieInfo);156 CIE_Info *cieInfo);
157 static const char *decodeFDE(A &addressSpace, pint_t fdeStart,157 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);
159 static bool parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo,160 static bool parseFDEInstructions(A &addressSpace, const FDE_Info &fdeInfo,
160 const CIE_Info &cieInfo, pint_t upToPC,161 const CIE_Info &cieInfo, pint_t upToPC,
161 int arch, PrologInfo *results);162 int arch, PrologInfo *results);
...@@ -163,10 +164,14 @@ public:...@@ -163,10 +164,14 @@ public:
163 static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo);164 static const char *parseCIE(A &addressSpace, pint_t cie, CIE_Info *cieInfo);
164};165};
165166
166/// Parse a FDE into a CIE_Info and an FDE_Info167/// 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.
167template <typename A>171template <typename A>
168const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,172const 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) {
170 pint_t p = fdeStart;175 pint_t p = fdeStart;
171 pint_t cfiLength = (pint_t)addressSpace.get32(p);176 pint_t cfiLength = (pint_t)addressSpace.get32(p);
172 p += 4;177 p += 4;
...@@ -182,9 +187,14 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,...@@ -182,9 +187,14 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,
182 return "FDE is really a CIE"; // this is a CIE not an FDE187 return "FDE is really a CIE"; // this is a CIE not an FDE
183 pint_t nextCFI = p + cfiLength;188 pint_t nextCFI = p + cfiLength;
184 pint_t cieStart = p - ciePointer;189 pint_t cieStart = p - ciePointer;
185 const char *err = parseCIE(addressSpace, cieStart, cieInfo);190 if (useCIEInfo) {
186 if (err != NULL)191 if (cieInfo->cieStart != cieStart)
187 return err;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 }
188 p += 4;198 p += 4;
189 // Parse pc begin and range.199 // Parse pc begin and range.
190 pint_t pcStart =200 pint_t pcStart =
...@@ -221,11 +231,11 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,...@@ -221,11 +231,11 @@ const char *CFI_Parser<A>::decodeFDE(A &addressSpace, pint_t fdeStart,
221/// Scan an eh_frame section to find an FDE for a pc231/// Scan an eh_frame section to find an FDE for a pc
222template <typename A>232template <typename A>
223bool CFI_Parser<A>::findFDE(A &addressSpace, pint_t pc, pint_t ehSectionStart,233bool 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,
225 FDE_Info *fdeInfo, CIE_Info *cieInfo) {235 FDE_Info *fdeInfo, CIE_Info *cieInfo) {
226 //fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc);236 //fprintf(stderr, "findFDE(0x%llX)\n", (long long)pc);
227 pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart;237 pint_t p = (fdeHint != 0) ? fdeHint : ehSectionStart;
228 const pint_t ehSectionEnd = (sectionLength == UINTPTR_MAX)238 const pint_t ehSectionEnd = (sectionLength == SIZE_MAX)
229 ? static_cast<pint_t>(-1)239 ? static_cast<pint_t>(-1)
230 : (ehSectionStart + sectionLength);240 : (ehSectionStart + sectionLength);
231 while (p < ehSectionEnd) {241 while (p < ehSectionEnd) {
...@@ -735,8 +745,8 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,...@@ -735,8 +745,8 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
735#if defined(_LIBUNWIND_TARGET_AARCH64)745#if defined(_LIBUNWIND_TARGET_AARCH64)
736 case REGISTERS_ARM64: {746 case REGISTERS_ARM64: {
737 int64_t value =747 int64_t value =
738 results->savedRegisters[UNW_ARM64_RA_SIGN_STATE].value ^ 0x1;748 results->savedRegisters[UNW_AARCH64_RA_SIGN_STATE].value ^ 0x1;
739 results->setRegisterValue(UNW_ARM64_RA_SIGN_STATE, value,749 results->setRegisterValue(UNW_AARCH64_RA_SIGN_STATE, value,
740 initialState);750 initialState);
741 _LIBUNWIND_TRACE_DWARF("DW_CFA_AARCH64_negate_ra_state\n");751 _LIBUNWIND_TRACE_DWARF("DW_CFA_AARCH64_negate_ra_state\n");
742 } break;752 } break;
...@@ -770,11 +780,13 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,...@@ -770,11 +780,13 @@ bool CFI_Parser<A>::parseFDEInstructions(A &addressSpace,
770 if (reg == UNW_SPARC_I7)780 if (reg == UNW_SPARC_I7)
771 results->setRegister(781 results->setRegister(
772 reg, kRegisterInCFADecrypt,782 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);
774 else785 else
775 results->setRegister(786 results->setRegister(
776 reg, kRegisterInCFA,787 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);
778 }790 }
779 _LIBUNWIND_TRACE_DWARF("DW_CFA_GNU_window_save\n");791 _LIBUNWIND_TRACE_DWARF("DW_CFA_GNU_window_save\n");
780 break;792 break;
lib/libunwind/src/EHHeaderParser.hpp+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------- EHHeaderParser.hpp -------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/RWMutex.hpp+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===----------------------------- Registers.hpp --------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/Registers.hpp+123-84
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===----------------------------- Registers.hpp --------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -15,8 +15,9 @@...@@ -15,8 +15,9 @@
15#include <stdint.h>15#include <stdint.h>
16#include <string.h>16#include <string.h>
1717
18#include "libunwind.h"18#include "cet_unwind.h"
19#include "config.h"19#include "config.h"
20#include "libunwind.h"
2021
21namespace libunwind {22namespace libunwind {
2223
...@@ -43,6 +44,13 @@ enum {...@@ -43,6 +44,13 @@ enum {
43#if defined(_LIBUNWIND_TARGET_I386)44#if defined(_LIBUNWIND_TARGET_I386)
44class _LIBUNWIND_HIDDEN Registers_x86;45class _LIBUNWIND_HIDDEN Registers_x86;
45extern "C" void __libunwind_Registers_x86_jumpto(Registers_x86 *);46extern "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
46/// Registers_x86 holds the register state of a thread in a 32-bit intel54/// Registers_x86 holds the register state of a thread in a 32-bit intel
47/// process.55/// process.
48class _LIBUNWIND_HIDDEN Registers_x86 {56class _LIBUNWIND_HIDDEN Registers_x86 {
...@@ -254,6 +262,13 @@ inline void Registers_x86::setVectorRegister(int, v128) {...@@ -254,6 +262,13 @@ inline void Registers_x86::setVectorRegister(int, v128) {
254/// process.262/// process.
255class _LIBUNWIND_HIDDEN Registers_x86_64;263class _LIBUNWIND_HIDDEN Registers_x86_64;
256extern "C" void __libunwind_Registers_x86_64_jumpto(Registers_x86_64 *);264extern "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
257class _LIBUNWIND_HIDDEN Registers_x86_64 {272class _LIBUNWIND_HIDDEN Registers_x86_64 {
258public:273public:
259 Registers_x86_64();274 Registers_x86_64();
...@@ -340,7 +355,7 @@ inline bool Registers_x86_64::validRegister(int regNum) const {...@@ -340,7 +355,7 @@ inline bool Registers_x86_64::validRegister(int regNum) const {
340 return true;355 return true;
341 if (regNum < 0)356 if (regNum < 0)
342 return false;357 return false;
343 if (regNum > 15)358 if (regNum > 16)
344 return false;359 return false;
345 return true;360 return true;
346}361}
...@@ -348,6 +363,7 @@ inline bool Registers_x86_64::validRegister(int regNum) const {...@@ -348,6 +363,7 @@ inline bool Registers_x86_64::validRegister(int regNum) const {
348inline uint64_t Registers_x86_64::getRegister(int regNum) const {363inline uint64_t Registers_x86_64::getRegister(int regNum) const {
349 switch (regNum) {364 switch (regNum) {
350 case UNW_REG_IP:365 case UNW_REG_IP:
366 case UNW_X86_64_RIP:
351 return _registers.__rip;367 return _registers.__rip;
352 case UNW_REG_SP:368 case UNW_REG_SP:
353 return _registers.__rsp;369 return _registers.__rsp;
...@@ -390,6 +406,7 @@ inline uint64_t Registers_x86_64::getRegister(int regNum) const {...@@ -390,6 +406,7 @@ inline uint64_t Registers_x86_64::getRegister(int regNum) const {
390inline void Registers_x86_64::setRegister(int regNum, uint64_t value) {406inline void Registers_x86_64::setRegister(int regNum, uint64_t value) {
391 switch (regNum) {407 switch (regNum) {
392 case UNW_REG_IP:408 case UNW_REG_IP:
409 case UNW_X86_64_RIP:
393 _registers.__rip = value;410 _registers.__rip = value;
394 return;411 return;
395 case UNW_REG_SP:412 case UNW_REG_SP:
...@@ -450,6 +467,7 @@ inline void Registers_x86_64::setRegister(int regNum, uint64_t value) {...@@ -450,6 +467,7 @@ inline void Registers_x86_64::setRegister(int regNum, uint64_t value) {
450inline const char *Registers_x86_64::getRegisterName(int regNum) {467inline const char *Registers_x86_64::getRegisterName(int regNum) {
451 switch (regNum) {468 switch (regNum) {
452 case UNW_REG_IP:469 case UNW_REG_IP:
470 case UNW_X86_64_RIP:
453 return "rip";471 return "rip";
454 case UNW_REG_SP:472 case UNW_REG_SP:
455 return "rsp";473 return "rsp";
...@@ -1848,7 +1866,7 @@ inline bool Registers_arm64::validRegister(int regNum) const {...@@ -1848,7 +1866,7 @@ inline bool Registers_arm64::validRegister(int regNum) const {
1848 return false;1866 return false;
1849 if (regNum > 95)1867 if (regNum > 95)
1850 return false;1868 return false;
1851 if (regNum == UNW_ARM64_RA_SIGN_STATE)1869 if (regNum == UNW_AARCH64_RA_SIGN_STATE)
1852 return true;1870 return true;
1853 if ((regNum > 32) && (regNum < 64))1871 if ((regNum > 32) && (regNum < 64))
1854 return false;1872 return false;
...@@ -1856,15 +1874,15 @@ inline bool Registers_arm64::validRegister(int regNum) const {...@@ -1856,15 +1874,15 @@ inline bool Registers_arm64::validRegister(int regNum) const {
1856}1874}
18571875
1858inline uint64_t Registers_arm64::getRegister(int regNum) const {1876inline 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)
1860 return _registers.__pc;1878 return _registers.__pc;
1861 if (regNum == UNW_REG_SP || regNum == UNW_ARM64_SP)1879 if (regNum == UNW_REG_SP || regNum == UNW_AARCH64_SP)
1862 return _registers.__sp;1880 return _registers.__sp;
1863 if (regNum == UNW_ARM64_RA_SIGN_STATE)1881 if (regNum == UNW_AARCH64_RA_SIGN_STATE)
1864 return _registers.__ra_sign_state;1882 return _registers.__ra_sign_state;
1865 if (regNum == UNW_ARM64_FP)1883 if (regNum == UNW_AARCH64_FP)
1866 return _registers.__fp;1884 return _registers.__fp;
1867 if (regNum == UNW_ARM64_LR)1885 if (regNum == UNW_AARCH64_LR)
1868 return _registers.__lr;1886 return _registers.__lr;
1869 if ((regNum >= 0) && (regNum < 29))1887 if ((regNum >= 0) && (regNum < 29))
1870 return _registers.__x[regNum];1888 return _registers.__x[regNum];
...@@ -1872,15 +1890,15 @@ inline uint64_t Registers_arm64::getRegister(int regNum) const {...@@ -1872,15 +1890,15 @@ inline uint64_t Registers_arm64::getRegister(int regNum) const {
1872}1890}
18731891
1874inline void Registers_arm64::setRegister(int regNum, uint64_t value) {1892inline 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)
1876 _registers.__pc = value;1894 _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)
1878 _registers.__sp = value;1896 _registers.__sp = value;
1879 else if (regNum == UNW_ARM64_RA_SIGN_STATE)1897 else if (regNum == UNW_AARCH64_RA_SIGN_STATE)
1880 _registers.__ra_sign_state = value;1898 _registers.__ra_sign_state = value;
1881 else if (regNum == UNW_ARM64_FP)1899 else if (regNum == UNW_AARCH64_FP)
1882 _registers.__fp = value;1900 _registers.__fp = value;
1883 else if (regNum == UNW_ARM64_LR)1901 else if (regNum == UNW_AARCH64_LR)
1884 _registers.__lr = value;1902 _registers.__lr = value;
1885 else if ((regNum >= 0) && (regNum < 29))1903 else if ((regNum >= 0) && (regNum < 29))
1886 _registers.__x[regNum] = value;1904 _registers.__x[regNum] = value;
...@@ -1894,135 +1912,135 @@ inline const char *Registers_arm64::getRegisterName(int regNum) {...@@ -1894,135 +1912,135 @@ inline const char *Registers_arm64::getRegisterName(int regNum) {
1894 return "pc";1912 return "pc";
1895 case UNW_REG_SP:1913 case UNW_REG_SP:
1896 return "sp";1914 return "sp";
1897 case UNW_ARM64_X0:1915 case UNW_AARCH64_X0:
1898 return "x0";1916 return "x0";
1899 case UNW_ARM64_X1:1917 case UNW_AARCH64_X1:
1900 return "x1";1918 return "x1";
1901 case UNW_ARM64_X2:1919 case UNW_AARCH64_X2:
1902 return "x2";1920 return "x2";
1903 case UNW_ARM64_X3:1921 case UNW_AARCH64_X3:
1904 return "x3";1922 return "x3";
1905 case UNW_ARM64_X4:1923 case UNW_AARCH64_X4:
1906 return "x4";1924 return "x4";
1907 case UNW_ARM64_X5:1925 case UNW_AARCH64_X5:
1908 return "x5";1926 return "x5";
1909 case UNW_ARM64_X6:1927 case UNW_AARCH64_X6:
1910 return "x6";1928 return "x6";
1911 case UNW_ARM64_X7:1929 case UNW_AARCH64_X7:
1912 return "x7";1930 return "x7";
1913 case UNW_ARM64_X8:1931 case UNW_AARCH64_X8:
1914 return "x8";1932 return "x8";
1915 case UNW_ARM64_X9:1933 case UNW_AARCH64_X9:
1916 return "x9";1934 return "x9";
1917 case UNW_ARM64_X10:1935 case UNW_AARCH64_X10:
1918 return "x10";1936 return "x10";
1919 case UNW_ARM64_X11:1937 case UNW_AARCH64_X11:
1920 return "x11";1938 return "x11";
1921 case UNW_ARM64_X12:1939 case UNW_AARCH64_X12:
1922 return "x12";1940 return "x12";
1923 case UNW_ARM64_X13:1941 case UNW_AARCH64_X13:
1924 return "x13";1942 return "x13";
1925 case UNW_ARM64_X14:1943 case UNW_AARCH64_X14:
1926 return "x14";1944 return "x14";
1927 case UNW_ARM64_X15:1945 case UNW_AARCH64_X15:
1928 return "x15";1946 return "x15";
1929 case UNW_ARM64_X16:1947 case UNW_AARCH64_X16:
1930 return "x16";1948 return "x16";
1931 case UNW_ARM64_X17:1949 case UNW_AARCH64_X17:
1932 return "x17";1950 return "x17";
1933 case UNW_ARM64_X18:1951 case UNW_AARCH64_X18:
1934 return "x18";1952 return "x18";
1935 case UNW_ARM64_X19:1953 case UNW_AARCH64_X19:
1936 return "x19";1954 return "x19";
1937 case UNW_ARM64_X20:1955 case UNW_AARCH64_X20:
1938 return "x20";1956 return "x20";
1939 case UNW_ARM64_X21:1957 case UNW_AARCH64_X21:
1940 return "x21";1958 return "x21";
1941 case UNW_ARM64_X22:1959 case UNW_AARCH64_X22:
1942 return "x22";1960 return "x22";
1943 case UNW_ARM64_X23:1961 case UNW_AARCH64_X23:
1944 return "x23";1962 return "x23";
1945 case UNW_ARM64_X24:1963 case UNW_AARCH64_X24:
1946 return "x24";1964 return "x24";
1947 case UNW_ARM64_X25:1965 case UNW_AARCH64_X25:
1948 return "x25";1966 return "x25";
1949 case UNW_ARM64_X26:1967 case UNW_AARCH64_X26:
1950 return "x26";1968 return "x26";
1951 case UNW_ARM64_X27:1969 case UNW_AARCH64_X27:
1952 return "x27";1970 return "x27";
1953 case UNW_ARM64_X28:1971 case UNW_AARCH64_X28:
1954 return "x28";1972 return "x28";
1955 case UNW_ARM64_FP:1973 case UNW_AARCH64_FP:
1956 return "fp";1974 return "fp";
1957 case UNW_ARM64_LR:1975 case UNW_AARCH64_LR:
1958 return "lr";1976 return "lr";
1959 case UNW_ARM64_SP:1977 case UNW_AARCH64_SP:
1960 return "sp";1978 return "sp";
1961 case UNW_ARM64_PC:1979 case UNW_AARCH64_PC:
1962 return "pc";1980 return "pc";
1963 case UNW_ARM64_D0:1981 case UNW_AARCH64_V0:
1964 return "d0";1982 return "d0";
1965 case UNW_ARM64_D1:1983 case UNW_AARCH64_V1:
1966 return "d1";1984 return "d1";
1967 case UNW_ARM64_D2:1985 case UNW_AARCH64_V2:
1968 return "d2";1986 return "d2";
1969 case UNW_ARM64_D3:1987 case UNW_AARCH64_V3:
1970 return "d3";1988 return "d3";
1971 case UNW_ARM64_D4:1989 case UNW_AARCH64_V4:
1972 return "d4";1990 return "d4";
1973 case UNW_ARM64_D5:1991 case UNW_AARCH64_V5:
1974 return "d5";1992 return "d5";
1975 case UNW_ARM64_D6:1993 case UNW_AARCH64_V6:
1976 return "d6";1994 return "d6";
1977 case UNW_ARM64_D7:1995 case UNW_AARCH64_V7:
1978 return "d7";1996 return "d7";
1979 case UNW_ARM64_D8:1997 case UNW_AARCH64_V8:
1980 return "d8";1998 return "d8";
1981 case UNW_ARM64_D9:1999 case UNW_AARCH64_V9:
1982 return "d9";2000 return "d9";
1983 case UNW_ARM64_D10:2001 case UNW_AARCH64_V10:
1984 return "d10";2002 return "d10";
1985 case UNW_ARM64_D11:2003 case UNW_AARCH64_V11:
1986 return "d11";2004 return "d11";
1987 case UNW_ARM64_D12:2005 case UNW_AARCH64_V12:
1988 return "d12";2006 return "d12";
1989 case UNW_ARM64_D13:2007 case UNW_AARCH64_V13:
1990 return "d13";2008 return "d13";
1991 case UNW_ARM64_D14:2009 case UNW_AARCH64_V14:
1992 return "d14";2010 return "d14";
1993 case UNW_ARM64_D15:2011 case UNW_AARCH64_V15:
1994 return "d15";2012 return "d15";
1995 case UNW_ARM64_D16:2013 case UNW_AARCH64_V16:
1996 return "d16";2014 return "d16";
1997 case UNW_ARM64_D17:2015 case UNW_AARCH64_V17:
1998 return "d17";2016 return "d17";
1999 case UNW_ARM64_D18:2017 case UNW_AARCH64_V18:
2000 return "d18";2018 return "d18";
2001 case UNW_ARM64_D19:2019 case UNW_AARCH64_V19:
2002 return "d19";2020 return "d19";
2003 case UNW_ARM64_D20:2021 case UNW_AARCH64_V20:
2004 return "d20";2022 return "d20";
2005 case UNW_ARM64_D21:2023 case UNW_AARCH64_V21:
2006 return "d21";2024 return "d21";
2007 case UNW_ARM64_D22:2025 case UNW_AARCH64_V22:
2008 return "d22";2026 return "d22";
2009 case UNW_ARM64_D23:2027 case UNW_AARCH64_V23:
2010 return "d23";2028 return "d23";
2011 case UNW_ARM64_D24:2029 case UNW_AARCH64_V24:
2012 return "d24";2030 return "d24";
2013 case UNW_ARM64_D25:2031 case UNW_AARCH64_V25:
2014 return "d25";2032 return "d25";
2015 case UNW_ARM64_D26:2033 case UNW_AARCH64_V26:
2016 return "d26";2034 return "d26";
2017 case UNW_ARM64_D27:2035 case UNW_AARCH64_V27:
2018 return "d27";2036 return "d27";
2019 case UNW_ARM64_D28:2037 case UNW_AARCH64_V28:
2020 return "d28";2038 return "d28";
2021 case UNW_ARM64_D29:2039 case UNW_AARCH64_V29:
2022 return "d29";2040 return "d29";
2023 case UNW_ARM64_D30:2041 case UNW_AARCH64_V30:
2024 return "d30";2042 return "d30";
2025 case UNW_ARM64_D31:2043 case UNW_AARCH64_V31:
2026 return "d31";2044 return "d31";
2027 default:2045 default:
2028 return "unknown register";2046 return "unknown register";
...@@ -2030,21 +2048,21 @@ inline const char *Registers_arm64::getRegisterName(int regNum) {...@@ -2030,21 +2048,21 @@ inline const char *Registers_arm64::getRegisterName(int regNum) {
2030}2048}
20312049
2032inline bool Registers_arm64::validFloatRegister(int regNum) const {2050inline bool Registers_arm64::validFloatRegister(int regNum) const {
2033 if (regNum < UNW_ARM64_D0)2051 if (regNum < UNW_AARCH64_V0)
2034 return false;2052 return false;
2035 if (regNum > UNW_ARM64_D31)2053 if (regNum > UNW_AARCH64_V31)
2036 return false;2054 return false;
2037 return true;2055 return true;
2038}2056}
20392057
2040inline double Registers_arm64::getFloatRegister(int regNum) const {2058inline double Registers_arm64::getFloatRegister(int regNum) const {
2041 assert(validFloatRegister(regNum));2059 assert(validFloatRegister(regNum));
2042 return _vectorHalfRegisters[regNum - UNW_ARM64_D0];2060 return _vectorHalfRegisters[regNum - UNW_AARCH64_V0];
2043}2061}
20442062
2045inline void Registers_arm64::setFloatRegister(int regNum, double value) {2063inline void Registers_arm64::setFloatRegister(int regNum, double value) {
2046 assert(validFloatRegister(regNum));2064 assert(validFloatRegister(regNum));
2047 _vectorHalfRegisters[regNum - UNW_ARM64_D0] = value;2065 _vectorHalfRegisters[regNum - UNW_AARCH64_V0] = value;
2048}2066}
20492067
2050inline bool Registers_arm64::validVectorRegister(int) const {2068inline bool Registers_arm64::validVectorRegister(int) const {
...@@ -2123,6 +2141,10 @@ private:...@@ -2123,6 +2141,10 @@ private:
2123 uint32_t __pc; // Program counter r152141 uint32_t __pc; // Program counter r15
2124 };2142 };
21252143
2144 struct PseudoRegisters {
2145 uint32_t __pac; // Return Authentication Code (PAC)
2146 };
2147
2126 static void saveVFPWithFSTMD(void*);2148 static void saveVFPWithFSTMD(void*);
2127 static void saveVFPWithFSTMX(void*);2149 static void saveVFPWithFSTMX(void*);
2128 static void saveVFPv3(void*);2150 static void saveVFPv3(void*);
...@@ -2139,6 +2161,7 @@ private:...@@ -2139,6 +2161,7 @@ private:
21392161
2140 // ARM registers2162 // ARM registers
2141 GPRs _registers;2163 GPRs _registers;
2164 PseudoRegisters _pseudo_registers;
21422165
2143 // We save floating point registers lazily because we can't know ahead of2166 // We save floating point registers lazily because we can't know ahead of
2144 // time which ones are used. See EHABI #4.7.2167 // time which ones are used. See EHABI #4.7.
...@@ -2176,6 +2199,7 @@ inline Registers_arm::Registers_arm(const void *registers)...@@ -2176,6 +2199,7 @@ inline Registers_arm::Registers_arm(const void *registers)
2176 "arm registers do not fit into unw_context_t");2199 "arm registers do not fit into unw_context_t");
2177 // See __unw_getcontext() note about data.2200 // See __unw_getcontext() note about data.
2178 memcpy(&_registers, registers, sizeof(_registers));2201 memcpy(&_registers, registers, sizeof(_registers));
2202 memset(&_pseudo_registers, 0, sizeof(_pseudo_registers));
2179 memset(&_vfp_d0_d15_pad, 0, sizeof(_vfp_d0_d15_pad));2203 memset(&_vfp_d0_d15_pad, 0, sizeof(_vfp_d0_d15_pad));
2180 memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));2204 memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));
2181#if defined(__ARM_WMMX)2205#if defined(__ARM_WMMX)
...@@ -2191,6 +2215,7 @@ inline Registers_arm::Registers_arm()...@@ -2191,6 +2215,7 @@ inline Registers_arm::Registers_arm()
2191 _saved_vfp_d0_d15(false),2215 _saved_vfp_d0_d15(false),
2192 _saved_vfp_d16_d31(false) {2216 _saved_vfp_d16_d31(false) {
2193 memset(&_registers, 0, sizeof(_registers));2217 memset(&_registers, 0, sizeof(_registers));
2218 memset(&_pseudo_registers, 0, sizeof(_pseudo_registers));
2194 memset(&_vfp_d0_d15_pad, 0, sizeof(_vfp_d0_d15_pad));2219 memset(&_vfp_d0_d15_pad, 0, sizeof(_vfp_d0_d15_pad));
2195 memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));2220 memset(&_vfp_d16_d31, 0, sizeof(_vfp_d16_d31));
2196#if defined(__ARM_WMMX)2221#if defined(__ARM_WMMX)
...@@ -2218,6 +2243,11 @@ inline bool Registers_arm::validRegister(int regNum) const {...@@ -2218,6 +2243,11 @@ inline bool Registers_arm::validRegister(int regNum) const {
2218 return true;2243 return true;
2219#endif2244#endif
22202245
2246#ifdef __ARM_FEATURE_PAUTH
2247 if (regNum == UNW_ARM_RA_AUTH_CODE)
2248 return true;
2249#endif
2250
2221 return false;2251 return false;
2222}2252}
22232253
...@@ -2244,6 +2274,11 @@ inline uint32_t Registers_arm::getRegister(int regNum) const {...@@ -2244,6 +2274,11 @@ inline uint32_t Registers_arm::getRegister(int regNum) const {
2244 }2274 }
2245#endif2275#endif
22462276
2277#ifdef __ARM_FEATURE_PAUTH
2278 if (regNum == UNW_ARM_RA_AUTH_CODE)
2279 return _pseudo_registers.__pac;
2280#endif
2281
2247 _LIBUNWIND_ABORT("unsupported arm register");2282 _LIBUNWIND_ABORT("unsupported arm register");
2248}2283}
22492284
...@@ -2279,6 +2314,11 @@ inline void Registers_arm::setRegister(int regNum, uint32_t value) {...@@ -2279,6 +2314,11 @@ inline void Registers_arm::setRegister(int regNum, uint32_t value) {
2279 }2314 }
2280#endif2315#endif
22812316
2317 if (regNum == UNW_ARM_RA_AUTH_CODE) {
2318 _pseudo_registers.__pac = value;
2319 return;
2320 }
2321
2282 _LIBUNWIND_ABORT("unsupported arm register");2322 _LIBUNWIND_ABORT("unsupported arm register");
2283}2323}
22842324
...@@ -3547,7 +3587,6 @@ inline const char *Registers_sparc::getRegisterName(int regNum) {...@@ -3547,7 +3587,6 @@ inline const char *Registers_sparc::getRegisterName(int regNum) {
3547}3587}
3548#endif // _LIBUNWIND_TARGET_SPARC3588#endif // _LIBUNWIND_TARGET_SPARC
35493589
3550
3551#if defined(_LIBUNWIND_TARGET_SPARC64)3590#if defined(_LIBUNWIND_TARGET_SPARC64)
3552/// Registers_sparc64 holds the register state of a thread in a 64-bit3591/// Registers_sparc64 holds the register state of a thread in a 64-bit
3553/// sparc process.3592/// sparc process.
lib/libunwind/src/Unwind-EHABI.cpp+212-10
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===--------------------------- Unwind-EHABI.cpp -------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -187,9 +187,14 @@ static _Unwind_Reason_Code unwindOneFrame(_Unwind_State state,...@@ -187,9 +187,14 @@ static _Unwind_Reason_Code unwindOneFrame(_Unwind_State state,
187 if (result != _URC_CONTINUE_UNWIND)187 if (result != _URC_CONTINUE_UNWIND)
188 return result;188 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:
191 return _URC_FAILURE;196 return _URC_FAILURE;
192 return _URC_CONTINUE_UNWIND;197 }
193}198}
194199
195// Generates mask discriminator for _Unwind_VRS_Pop, e.g. for _UVRSC_CORE /200// 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,...@@ -256,6 +261,7 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
256 size_t offset, size_t len) {261 size_t offset, size_t len) {
257 bool wrotePC = false;262 bool wrotePC = false;
258 bool finish = false;263 bool finish = false;
264 bool hasReturnAddrAuthCode = false;
259 while (offset < len && !finish) {265 while (offset < len && !finish) {
260 uint8_t byte = getByte(data, offset++);266 uint8_t byte = getByte(data, offset++);
261 if ((byte & 0x80) == 0) {267 if ((byte & 0x80) == 0) {
...@@ -342,6 +348,10 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,...@@ -342,6 +348,10 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
342 break;348 break;
343 }349 }
344 case 0xb4:350 case 0xb4:
351 hasReturnAddrAuthCode = true;
352 _Unwind_VRS_Pop(context, _UVRSC_PSEUDO,
353 0 /* Return Address Auth Code */, _UVRSD_UINT32);
354 break;
345 case 0xb5:355 case 0xb5:
346 case 0xb6:356 case 0xb6:
347 case 0xb7:357 case 0xb7:
...@@ -417,6 +427,16 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,...@@ -417,6 +427,16 @@ _Unwind_VRS_Interpret(_Unwind_Context *context, const uint32_t *data,
417 if (!wrotePC) {427 if (!wrotePC) {
418 uint32_t lr;428 uint32_t lr;
419 _Unwind_VRS_Get(context, _UVRSC_CORE, UNW_ARM_LR, _UVRSD_UINT32, &lr);429 _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
420 _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_IP, _UVRSD_UINT32, &lr);440 _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_IP, _UVRSD_UINT32, &lr);
421 }441 }
422 return _URC_CONTINUE_UNWIND;442 return _URC_CONTINUE_UNWIND;
...@@ -463,6 +483,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -463,6 +483,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
463 return _URC_FATAL_PHASE1_ERROR;483 return _URC_FATAL_PHASE1_ERROR;
464 }484 }
465485
486#ifndef NDEBUG
466 // When tracing, print state information.487 // When tracing, print state information.
467 if (_LIBUNWIND_TRACING_UNWINDING) {488 if (_LIBUNWIND_TRACING_UNWINDING) {
468 char functionBuf[512];489 char functionBuf[512];
...@@ -481,6 +502,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -481,6 +502,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
481 frameInfo.start_ip, functionName,502 frameInfo.start_ip, functionName,
482 frameInfo.lsda, frameInfo.handler);503 frameInfo.lsda, frameInfo.handler);
483 }504 }
505#endif
484506
485 // If there is a personality routine, ask it if it will want to stop at507 // If there is a personality routine, ask it if it will want to stop at
486 // this frame.508 // this frame.
...@@ -582,6 +604,7 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor...@@ -582,6 +604,7 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor
582 return _URC_FATAL_PHASE2_ERROR;604 return _URC_FATAL_PHASE2_ERROR;
583 }605 }
584606
607#ifndef NDEBUG
585 // When tracing, print state information.608 // When tracing, print state information.
586 if (_LIBUNWIND_TRACING_UNWINDING) {609 if (_LIBUNWIND_TRACING_UNWINDING) {
587 char functionBuf[512];610 char functionBuf[512];
...@@ -598,11 +621,12 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor...@@ -598,11 +621,12 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor
598 functionName, sp, frameInfo.lsda,621 functionName, sp, frameInfo.lsda,
599 frameInfo.handler);622 frameInfo.handler);
600 }623 }
624#endif
601625
602 // If there is a personality routine, tell it we are unwinding.626 // If there is a personality routine, tell it we are unwinding.
603 if (frameInfo.handler != 0) {627 if (frameInfo.handler != 0) {
604 _Unwind_Personality_Fn p =628 _Unwind_Personality_Fn p =
605 (_Unwind_Personality_Fn)(long)(frameInfo.handler);629 (_Unwind_Personality_Fn)(intptr_t)(frameInfo.handler);
606 struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor);630 struct _Unwind_Context *context = (struct _Unwind_Context *)(cursor);
607 // EHABI #7.2631 // EHABI #7.2
608 exception_object->pr_cache.fnstart = frameInfo.start_ip;632 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...@@ -670,6 +694,123 @@ static _Unwind_Reason_Code unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor
670 return _URC_FATAL_PHASE2_ERROR;694 return _URC_FATAL_PHASE2_ERROR;
671}695}
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
673/// Called by __cxa_throw. Only returns if there is a fatal error.814/// Called by __cxa_throw. Only returns if there is a fatal error.
674_LIBUNWIND_EXPORT _Unwind_Reason_Code815_LIBUNWIND_EXPORT _Unwind_Reason_Code
675_Unwind_RaiseException(_Unwind_Exception *exception_object) {816_Unwind_RaiseException(_Unwind_Exception *exception_object) {
...@@ -717,10 +858,13 @@ _Unwind_Resume(_Unwind_Exception *exception_object) {...@@ -717,10 +858,13 @@ _Unwind_Resume(_Unwind_Exception *exception_object) {
717 unw_cursor_t cursor;858 unw_cursor_t cursor;
718 __unw_getcontext(&uc);859 __unw_getcontext(&uc);
719860
720 // _Unwind_RaiseException on EHABI will always set the reserved1 field to 0,861 if (exception_object->unwinder_cache.reserved1)
721 // which is in the same position as private_1 below.862 unwind_phase2_forced(
722 // TODO(ajwong): Who wronte the above? Why is it true?863 &uc, &cursor, exception_object,
723 unwind_phase2(&uc, &cursor, exception_object, true);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
725 // Clients assume _Unwind_Resume() does not return, so all we can do is abort.869 // Clients assume _Unwind_Resume() does not return, so all we can do is abort.
726 _LIBUNWIND_ABORT("_Unwind_Resume() can't return");870 _LIBUNWIND_ABORT("_Unwind_Resume() can't return");
...@@ -812,6 +956,15 @@ _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,...@@ -812,6 +956,15 @@ _Unwind_VRS_Set(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
812 case _UVRSC_WMMXD:956 case _UVRSC_WMMXD:
813 break;957 break;
814#endif958#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;
815 }968 }
816 _LIBUNWIND_ABORT("unsupported register class");969 _LIBUNWIND_ABORT("unsupported register class");
817}970}
...@@ -866,6 +1019,15 @@ _Unwind_VRS_Get_Internal(_Unwind_Context *context,...@@ -866,6 +1019,15 @@ _Unwind_VRS_Get_Internal(_Unwind_Context *context,
866 case _UVRSC_WMMXD:1019 case _UVRSC_WMMXD:
867 break;1020 break;
868#endif1021#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;
869 }1031 }
870 _LIBUNWIND_ABORT("unsupported register class");1032 _LIBUNWIND_ABORT("unsupported register class");
871}1033}
...@@ -963,10 +1125,45 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,...@@ -963,10 +1125,45 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass,
963 return _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32,1125 return _Unwind_VRS_Set(context, _UVRSC_CORE, UNW_ARM_SP, _UVRSD_UINT32,
964 &sp);1126 &sp);
965 }1127 }
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 }
966 }1142 }
967 _LIBUNWIND_ABORT("unsupported register class");1143 _LIBUNWIND_ABORT("unsupported register class");
968}1144}
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
970/// Called by personality handler during phase 2 to find the start of the1167/// Called by personality handler during phase 2 to find the start of the
971/// function.1168/// function.
972_LIBUNWIND_EXPORT uintptr_t1169_LIBUNWIND_EXPORT uintptr_t
...@@ -997,9 +1194,14 @@ extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code...@@ -997,9 +1194,14 @@ extern "C" _LIBUNWIND_EXPORT _Unwind_Reason_Code
997__gnu_unwind_frame(_Unwind_Exception *exception_object,1194__gnu_unwind_frame(_Unwind_Exception *exception_object,
998 struct _Unwind_Context *context) {1195 struct _Unwind_Context *context) {
999 unw_cursor_t *cursor = (unw_cursor_t *)context;1196 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:
1001 return _URC_FAILURE;1203 return _URC_FAILURE;
1002 return _URC_OK;1204 }
1003}1205}
10041206
1005#endif // defined(_LIBUNWIND_ARM_EHABI)1207#endif // defined(_LIBUNWIND_ARM_EHABI)
lib/libunwind/src/Unwind-EHABI.h+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------- Unwind-EHABI.hpp ---------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/Unwind-seh.cpp+5-5
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===--------------------------- Unwind-seh.cpp ---------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -28,8 +28,6 @@...@@ -28,8 +28,6 @@
28#include "libunwind_ext.h"28#include "libunwind_ext.h"
29#include "UnwindCursor.hpp"29#include "UnwindCursor.hpp"
3030
31#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
32
33using namespace libunwind;31using namespace libunwind;
3432
35#define STATUS_USER_DEFINED (1u << 29)33#define STATUS_USER_DEFINED (1u << 29)
...@@ -171,8 +169,8 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,...@@ -171,8 +169,8 @@ _GCC_specific_handler(PEXCEPTION_RECORD ms_exc, PVOID frame, PCONTEXT ms_ctx,
171 __unw_get_reg(&cursor, UNW_ARM_R1, &exc->private_[3]);169 __unw_get_reg(&cursor, UNW_ARM_R1, &exc->private_[3]);
172#elif defined(__aarch64__)170#elif defined(__aarch64__)
173 exc->private_[2] = disp->TargetPc;171 exc->private_[2] = disp->TargetPc;
174 __unw_get_reg(&cursor, UNW_ARM64_X0, &retval);172 __unw_get_reg(&cursor, UNW_AARCH64_X0, &retval);
175 __unw_get_reg(&cursor, UNW_ARM64_X1, &exc->private_[3]);173 __unw_get_reg(&cursor, UNW_AARCH64_X1, &exc->private_[3]);
176#endif174#endif
177 __unw_get_reg(&cursor, UNW_REG_IP, &target);175 __unw_get_reg(&cursor, UNW_REG_IP, &target);
178 ms_exc->ExceptionCode = STATUS_GCC_UNWIND;176 ms_exc->ExceptionCode = STATUS_GCC_UNWIND;
...@@ -246,6 +244,7 @@ unwind_phase2_forced(unw_context_t *uc,...@@ -246,6 +244,7 @@ unwind_phase2_forced(unw_context_t *uc,
246 return _URC_FATAL_PHASE2_ERROR;244 return _URC_FATAL_PHASE2_ERROR;
247 }245 }
248246
247#ifndef NDEBUG
249 // When tracing, print state information.248 // When tracing, print state information.
250 if (_LIBUNWIND_TRACING_UNWINDING) {249 if (_LIBUNWIND_TRACING_UNWINDING) {
251 char functionBuf[512];250 char functionBuf[512];
...@@ -261,6 +260,7 @@ unwind_phase2_forced(unw_context_t *uc,...@@ -261,6 +260,7 @@ unwind_phase2_forced(unw_context_t *uc,
261 (void *)exception_object, frameInfo.start_ip, functionName,260 (void *)exception_object, frameInfo.start_ip, functionName,
262 frameInfo.lsda, frameInfo.handler);261 frameInfo.lsda, frameInfo.handler);
263 }262 }
263#endif
264264
265 // Call stop function at each frame.265 // Call stop function at each frame.
266 _Unwind_Action action =266 _Unwind_Action action =
lib/libunwind/src/Unwind-sjlj.c+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===--------------------------- Unwind-sjlj.c ----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/UnwindCursor.hpp+61-43
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------- UnwindCursor.hpp ---------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -11,6 +11,7 @@...@@ -11,6 +11,7 @@
11#ifndef __UNWINDCURSOR_HPP__11#ifndef __UNWINDCURSOR_HPP__
12#define __UNWINDCURSOR_HPP__12#define __UNWINDCURSOR_HPP__
1313
14#include "cet_unwind.h"
14#include <stdint.h>15#include <stdint.h>
15#include <stdio.h>16#include <stdio.h>
16#include <stdlib.h>17#include <stdlib.h>
...@@ -449,6 +450,12 @@ public:...@@ -449,6 +450,12 @@ public:
449#ifdef __arm__450#ifdef __arm__
450 virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }451 virtual void saveVFPAsX() { _LIBUNWIND_ABORT("saveVFPAsX not implemented"); }
451#endif452#endif
453
454#if defined(_LIBUNWIND_USE_CET)
455 virtual void *get_registers() {
456 _LIBUNWIND_ABORT("get_registers not implemented");
457 }
458#endif
452};459};
453460
454#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)461#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) && defined(_WIN32)
...@@ -620,12 +627,12 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)...@@ -620,12 +627,12 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A &as)
620 _msContext.D[i - UNW_ARM_D0] = d.w;627 _msContext.D[i - UNW_ARM_D0] = d.w;
621 }628 }
622#elif defined(_LIBUNWIND_TARGET_AARCH64)629#elif defined(_LIBUNWIND_TARGET_AARCH64)
623 for (int i = UNW_ARM64_X0; i <= UNW_ARM64_X30; ++i)630 for (int i = UNW_AARCH64_X0; i <= UNW_ARM64_X30; ++i)
624 _msContext.X[i - UNW_ARM64_X0] = r.getRegister(i);631 _msContext.X[i - UNW_AARCH64_X0] = r.getRegister(i);
625 _msContext.Sp = r.getRegister(UNW_REG_SP);632 _msContext.Sp = r.getRegister(UNW_REG_SP);
626 _msContext.Pc = r.getRegister(UNW_REG_IP);633 _msContext.Pc = r.getRegister(UNW_REG_IP);
627 for (int i = UNW_ARM64_D0; i <= UNW_ARM64_D31; ++i)634 for (int i = UNW_AARCH64_V0; i <= UNW_ARM64_D31; ++i)
628 _msContext.V[i - UNW_ARM64_D0].D[0] = r.getFloatRegister(i);635 _msContext.V[i - UNW_AARCH64_V0].D[0] = r.getFloatRegister(i);
629#endif636#endif
630}637}
631638
...@@ -648,9 +655,11 @@ bool UnwindCursor<A, R>::validReg(int regNum) {...@@ -648,9 +655,11 @@ bool UnwindCursor<A, R>::validReg(int regNum) {
648#if defined(_LIBUNWIND_TARGET_X86_64)655#if defined(_LIBUNWIND_TARGET_X86_64)
649 if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;656 if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_R15) return true;
650#elif defined(_LIBUNWIND_TARGET_ARM)657#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;
652#elif defined(_LIBUNWIND_TARGET_AARCH64)661#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;
654#endif663#endif
655 return false;664 return false;
656}665}
...@@ -699,7 +708,7 @@ unw_word_t UnwindCursor<A, R>::getReg(int regNum) {...@@ -699,7 +708,7 @@ unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
699#elif defined(_LIBUNWIND_TARGET_AARCH64)708#elif defined(_LIBUNWIND_TARGET_AARCH64)
700 case UNW_REG_SP: return _msContext.Sp;709 case UNW_REG_SP: return _msContext.Sp;
701 case UNW_REG_IP: return _msContext.Pc;710 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];
703#endif712#endif
704 }713 }
705 _LIBUNWIND_ABORT("unsupported register");714 _LIBUNWIND_ABORT("unsupported register");
...@@ -749,37 +758,37 @@ void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {...@@ -749,37 +758,37 @@ void UnwindCursor<A, R>::setReg(int regNum, unw_word_t value) {
749#elif defined(_LIBUNWIND_TARGET_AARCH64)758#elif defined(_LIBUNWIND_TARGET_AARCH64)
750 case UNW_REG_SP: _msContext.Sp = value; break;759 case UNW_REG_SP: _msContext.Sp = value; break;
751 case UNW_REG_IP: _msContext.Pc = value; break;760 case UNW_REG_IP: _msContext.Pc = value; break;
752 case UNW_ARM64_X0:761 case UNW_AARCH64_X0:
753 case UNW_ARM64_X1:762 case UNW_AARCH64_X1:
754 case UNW_ARM64_X2:763 case UNW_AARCH64_X2:
755 case UNW_ARM64_X3:764 case UNW_AARCH64_X3:
756 case UNW_ARM64_X4:765 case UNW_AARCH64_X4:
757 case UNW_ARM64_X5:766 case UNW_AARCH64_X5:
758 case UNW_ARM64_X6:767 case UNW_AARCH64_X6:
759 case UNW_ARM64_X7:768 case UNW_AARCH64_X7:
760 case UNW_ARM64_X8:769 case UNW_AARCH64_X8:
761 case UNW_ARM64_X9:770 case UNW_AARCH64_X9:
762 case UNW_ARM64_X10:771 case UNW_AARCH64_X10:
763 case UNW_ARM64_X11:772 case UNW_AARCH64_X11:
764 case UNW_ARM64_X12:773 case UNW_AARCH64_X12:
765 case UNW_ARM64_X13:774 case UNW_AARCH64_X13:
766 case UNW_ARM64_X14:775 case UNW_AARCH64_X14:
767 case UNW_ARM64_X15:776 case UNW_AARCH64_X15:
768 case UNW_ARM64_X16:777 case UNW_AARCH64_X16:
769 case UNW_ARM64_X17:778 case UNW_AARCH64_X17:
770 case UNW_ARM64_X18:779 case UNW_AARCH64_X18:
771 case UNW_ARM64_X19:780 case UNW_AARCH64_X19:
772 case UNW_ARM64_X20:781 case UNW_AARCH64_X20:
773 case UNW_ARM64_X21:782 case UNW_AARCH64_X21:
774 case UNW_ARM64_X22:783 case UNW_AARCH64_X22:
775 case UNW_ARM64_X23:784 case UNW_AARCH64_X23:
776 case UNW_ARM64_X24:785 case UNW_AARCH64_X24:
777 case UNW_ARM64_X25:786 case UNW_AARCH64_X25:
778 case UNW_ARM64_X26:787 case UNW_AARCH64_X26:
779 case UNW_ARM64_X27:788 case UNW_AARCH64_X27:
780 case UNW_ARM64_X28:789 case UNW_AARCH64_X28:
781 case UNW_ARM64_FP:790 case UNW_AARCH64_FP:
782 case UNW_ARM64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;791 case UNW_AARCH64_LR: _msContext.X[regNum - UNW_ARM64_X0] = value; break;
783#endif792#endif
784 default:793 default:
785 _LIBUNWIND_ABORT("unsupported register");794 _LIBUNWIND_ABORT("unsupported register");
...@@ -792,7 +801,7 @@ bool UnwindCursor<A, R>::validFloatReg(int regNum) {...@@ -792,7 +801,7 @@ bool UnwindCursor<A, R>::validFloatReg(int regNum) {
792 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;801 if (regNum >= UNW_ARM_S0 && regNum <= UNW_ARM_S31) return true;
793 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;802 if (regNum >= UNW_ARM_D0 && regNum <= UNW_ARM_D31) return true;
794#elif defined(_LIBUNWIND_TARGET_AARCH64)803#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;
796#else805#else
797 (void)regNum;806 (void)regNum;
798#endif807#endif
...@@ -820,7 +829,7 @@ unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {...@@ -820,7 +829,7 @@ unw_fpreg_t UnwindCursor<A, R>::getFloatReg(int regNum) {
820 }829 }
821 _LIBUNWIND_ABORT("unsupported float register");830 _LIBUNWIND_ABORT("unsupported float register");
822#elif defined(_LIBUNWIND_TARGET_AARCH64)831#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];
824#else833#else
825 (void)regNum;834 (void)regNum;
826 _LIBUNWIND_ABORT("float registers unimplemented");835 _LIBUNWIND_ABORT("float registers unimplemented");
...@@ -848,7 +857,7 @@ void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {...@@ -848,7 +857,7 @@ void UnwindCursor<A, R>::setFloatReg(int regNum, unw_fpreg_t value) {
848 }857 }
849 _LIBUNWIND_ABORT("unsupported float register");858 _LIBUNWIND_ABORT("unsupported float register");
850#elif defined(_LIBUNWIND_TARGET_AARCH64)859#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;
852#else861#else
853 (void)regNum;862 (void)regNum;
854 (void)value;863 (void)value;
...@@ -901,6 +910,9 @@ public:...@@ -901,6 +910,9 @@ public:
901 virtual void saveVFPAsX();910 virtual void saveVFPAsX();
902#endif911#endif
903912
913#if defined(_LIBUNWIND_USE_CET)
914 virtual void *get_registers() { return &_registers; }
915#endif
904 // libunwind does not and should not depend on C++ library which means that we916 // libunwind does not and should not depend on C++ library which means that we
905 // need our own defition of inline placement new.917 // need our own defition of inline placement new.
906 static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }918 static void *operator new(size_t, UnwindCursor<A, R> *p) { return p; }
...@@ -2077,7 +2089,7 @@ int UnwindCursor<A, R>::stepThroughSigReturn(Registers_arm64 &) {...@@ -2077,7 +2089,7 @@ int UnwindCursor<A, R>::stepThroughSigReturn(Registers_arm64 &) {
2077 for (int i = 0; i <= 30; ++i) {2089 for (int i = 0; i <= 30; ++i) {
2078 uint64_t value = _addressSpace.get64(sigctx + kOffsetGprs +2090 uint64_t value = _addressSpace.get64(sigctx + kOffsetGprs +
2079 static_cast<pint_t>(i * 8));2091 static_cast<pint_t>(i * 8));
2080 _registers.setRegister(UNW_ARM64_X0 + i, value);2092 _registers.setRegister(UNW_AARCH64_X0 + i, value);
2081 }2093 }
2082 _registers.setSP(_addressSpace.get64(sigctx + kOffsetSp));2094 _registers.setSP(_addressSpace.get64(sigctx + kOffsetSp));
2083 _registers.setIP(_addressSpace.get64(sigctx + kOffsetPc));2095 _registers.setIP(_addressSpace.get64(sigctx + kOffsetPc));
...@@ -2141,6 +2153,12 @@ bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,...@@ -2141,6 +2153,12 @@ bool UnwindCursor<A, R>::getFunctionName(char *buf, size_t bufLen,
2141 buf, bufLen, offset);2153 buf, bufLen, offset);
2142}2154}
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
2144} // namespace libunwind2162} // namespace libunwind
21452163
2146#endif // __UNWINDCURSOR_HPP__2164#endif // __UNWINDCURSOR_HPP__
lib/libunwind/src/UnwindLevel1-gcc-ext.c+11-22
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===--------------------- UnwindLevel1-gcc-ext.c -------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -22,36 +22,27 @@...@@ -22,36 +22,27 @@
22#include "Unwind-EHABI.h"22#include "Unwind-EHABI.h"
23#include "unwind.h"23#include "unwind.h"
2424
25#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
26
27#if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS)25#if defined(_LIBUNWIND_BUILD_ZERO_COST_APIS)
2826
29#if defined(_LIBUNWIND_SUPPORT_SEH_UNWIND)27#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
31#endif33#endif
3234
33/// Called by __cxa_rethrow().35/// Called by __cxa_rethrow().
34_LIBUNWIND_EXPORT _Unwind_Reason_Code36_LIBUNWIND_EXPORT _Unwind_Reason_Code
35_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {37_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
36#if defined(_LIBUNWIND_ARM_EHABI)38 _LIBUNWIND_TRACE_API(
37 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",39 "_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%" PRIdPTR,
38 (void *)exception_object,40 (void *)exception_object, (intptr_t)exception_object->PRIVATE_1);
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
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
51 // If this is non-forced and a stopping place was found, then this is a42 // If this is non-forced and a stopping place was found, then this is a
52 // re-throw.43 // re-throw.
53 // Call _Unwind_RaiseException() as if this was a new exception44 // Call _Unwind_RaiseException() as if this was a new exception
54 if (exception_object->private_1 == 0) {45 if (exception_object->PRIVATE_1 == 0) {
55 return _Unwind_RaiseException(exception_object);46 return _Unwind_RaiseException(exception_object);
56 // Will return if there is no catch clause, so that __cxa_rethrow can call47 // Will return if there is no catch clause, so that __cxa_rethrow can call
57 // std::terminate().48 // std::terminate().
...@@ -62,10 +53,8 @@ _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {...@@ -62,10 +53,8 @@ _Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
62 _Unwind_Resume(exception_object);53 _Unwind_Resume(exception_object);
63 _LIBUNWIND_ABORT("_Unwind_Resume_or_Rethrow() called _Unwind_RaiseException()"54 _LIBUNWIND_ABORT("_Unwind_Resume_or_Rethrow() called _Unwind_RaiseException()"
64 " which unexpectedly returned");55 " which unexpectedly returned");
65#endif
66}56}
6757
68
69/// Called by personality handler during phase 2 to get base address for data58/// Called by personality handler during phase 2 to get base address for data
70/// relative encodings.59/// relative encodings.
71_LIBUNWIND_EXPORT uintptr_t60_LIBUNWIND_EXPORT uintptr_t
...@@ -120,7 +109,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {...@@ -120,7 +109,7 @@ _Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
120 // Create a mock exception object for force unwinding.109 // Create a mock exception object for force unwinding.
121 _Unwind_Exception ex;110 _Unwind_Exception ex;
122 memset(&ex, '\0', sizeof(ex));111 memset(&ex, '\0', sizeof(ex));
123 ex.exception_class = 0x434C4E47554E5700; // CLNGUNW\0112 strcpy((char *)&ex.exception_class, "CLNGUNW");
124#endif113#endif
125114
126 // walk each frame115 // walk each frame
lib/libunwind/src/UnwindLevel1.c+52-6
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------- UnwindLevel1.c -----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -25,17 +25,48 @@...@@ -25,17 +25,48 @@
25#include <stdio.h>25#include <stdio.h>
26#include <string.h>26#include <string.h>
2727
28#include "cet_unwind.h"
28#include "config.h"29#include "config.h"
29#include "libunwind.h"30#include "libunwind.h"
30#include "libunwind_ext.h"31#include "libunwind_ext.h"
31#include "unwind.h"32#include "unwind.h"
3233
33#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
34
35#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)34#if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
3635
37#ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND36#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
39static _Unwind_Reason_Code70static _Unwind_Reason_Code
40unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {71unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
41 __unw_init_local(cursor, uc);72 __unw_init_local(cursor, uc);
...@@ -70,6 +101,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -70,6 +101,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
70 return _URC_FATAL_PHASE1_ERROR;101 return _URC_FATAL_PHASE1_ERROR;
71 }102 }
72103
104#ifndef NDEBUG
73 // When tracing, print state information.105 // When tracing, print state information.
74 if (_LIBUNWIND_TRACING_UNWINDING) {106 if (_LIBUNWIND_TRACING_UNWINDING) {
75 char functionBuf[512];107 char functionBuf[512];
...@@ -87,6 +119,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -87,6 +119,7 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
87 (void *)exception_object, pc, frameInfo.start_ip, functionName,119 (void *)exception_object, pc, frameInfo.start_ip, functionName,
88 frameInfo.lsda, frameInfo.handler);120 frameInfo.lsda, frameInfo.handler);
89 }121 }
122#endif
90123
91 // If there is a personality routine, ask it if it will want to stop at124 // If there is a personality routine, ask it if it will want to stop at
92 // this frame.125 // this frame.
...@@ -137,6 +170,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -137,6 +170,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
137 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)",170 _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)",
138 (void *)exception_object);171 (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;
140 // Walk each frame until we reach where search phase said to stop.176 // Walk each frame until we reach where search phase said to stop.
141 while (true) {177 while (true) {
142178
...@@ -169,6 +205,7 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -169,6 +205,7 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
169 return _URC_FATAL_PHASE2_ERROR;205 return _URC_FATAL_PHASE2_ERROR;
170 }206 }
171207
208#ifndef NDEBUG
172 // When tracing, print state information.209 // When tracing, print state information.
173 if (_LIBUNWIND_TRACING_UNWINDING) {210 if (_LIBUNWIND_TRACING_UNWINDING) {
174 char functionBuf[512];211 char functionBuf[512];
...@@ -185,7 +222,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -185,7 +222,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
185 functionName, sp, frameInfo.lsda,222 functionName, sp, frameInfo.lsda,
186 frameInfo.handler);223 frameInfo.handler);
187 }224 }
225#endif
188226
227 ++framesWalked;
189 // If there is a personality routine, tell it we are unwinding.228 // If there is a personality routine, tell it we are unwinding.
190 if (frameInfo.handler != 0) {229 if (frameInfo.handler != 0) {
191 _Unwind_Personality_Fn p =230 _Unwind_Personality_Fn p =
...@@ -225,8 +264,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except...@@ -225,8 +264,9 @@ unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *except
225 ", sp=0x%" PRIxPTR,264 ", sp=0x%" PRIxPTR,
226 (void *)exception_object, pc, sp);265 (void *)exception_object, pc, sp);
227 }266 }
228 __unw_resume(cursor);267
229 // __unw_resume() only returns if there was an error.268 __unw_phase2_resume(cursor, framesWalked);
269 // __unw_phase2_resume() only returns if there was an error.
230 return _URC_FATAL_PHASE2_ERROR;270 return _URC_FATAL_PHASE2_ERROR;
231 default:271 default:
232 // Personality routine returned an unknown result code.272 // Personality routine returned an unknown result code.
...@@ -248,6 +288,9 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,...@@ -248,6 +288,9 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
248 _Unwind_Stop_Fn stop, void *stop_parameter) {288 _Unwind_Stop_Fn stop, void *stop_parameter) {
249 __unw_init_local(cursor, uc);289 __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;
251 // Walk each frame until we reach where search phase said to stop294 // Walk each frame until we reach where search phase said to stop
252 while (__unw_step(cursor) > 0) {295 while (__unw_step(cursor) > 0) {
253296
...@@ -260,6 +303,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,...@@ -260,6 +303,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
260 return _URC_FATAL_PHASE2_ERROR;303 return _URC_FATAL_PHASE2_ERROR;
261 }304 }
262305
306#ifndef NDEBUG
263 // When tracing, print state information.307 // When tracing, print state information.
264 if (_LIBUNWIND_TRACING_UNWINDING) {308 if (_LIBUNWIND_TRACING_UNWINDING) {
265 char functionBuf[512];309 char functionBuf[512];
...@@ -275,6 +319,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,...@@ -275,6 +319,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
275 (void *)exception_object, frameInfo.start_ip, functionName,319 (void *)exception_object, frameInfo.start_ip, functionName,
276 frameInfo.lsda, frameInfo.handler);320 frameInfo.lsda, frameInfo.handler);
277 }321 }
322#endif
278323
279 // Call stop function at each frame.324 // Call stop function at each frame.
280 _Unwind_Action action =325 _Unwind_Action action =
...@@ -292,6 +337,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,...@@ -292,6 +337,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
292 return _URC_FATAL_PHASE2_ERROR;337 return _URC_FATAL_PHASE2_ERROR;
293 }338 }
294339
340 ++framesWalked;
295 // If there is a personality routine, tell it we are unwinding.341 // If there is a personality routine, tell it we are unwinding.
296 if (frameInfo.handler != 0) {342 if (frameInfo.handler != 0) {
297 _Unwind_Personality_Fn p =343 _Unwind_Personality_Fn p =
...@@ -316,7 +362,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,...@@ -316,7 +362,7 @@ unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
316 "_URC_INSTALL_CONTEXT",362 "_URC_INSTALL_CONTEXT",
317 (void *)exception_object);363 (void *)exception_object);
318 // We may get control back if landing pad calls _Unwind_Resume().364 // We may get control back if landing pad calls _Unwind_Resume().
319 __unw_resume(cursor);365 __unw_phase2_resume(cursor, framesWalked);
320 break;366 break;
321 default:367 default:
322 // Personality routine returned an unknown result code.368 // Personality routine returned an unknown result code.
lib/libunwind/src/UnwindRegistersRestore.S+18-6
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===-------------------- UnwindRegistersRestore.S ------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -25,6 +25,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)...@@ -25,6 +25,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
25# + return address +25# + return address +
26# +-----------------------+ <-- SP26# +-----------------------+ <-- SP
27# + +27# + +
28
29 _LIBUNWIND_CET_ENDBR
28 movl 4(%esp), %eax30 movl 4(%esp), %eax
29 # set up eax and ret on new stack location31 # set up eax and ret on new stack location
30 movl 28(%eax), %edx # edx holds new stack pointer32 movl 28(%eax), %edx # edx holds new stack pointer
...@@ -46,7 +48,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)...@@ -46,7 +48,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
46 # skip ss48 # skip ss
47 # skip eflags49 # skip eflags
48 pop %eax # eax was already pushed on new stack50 pop %eax # eax was already pushed on new stack
49 ret # eip was already pushed on new stack51 pop %ecx
52 jmp *%ecx
50 # skip cs53 # skip cs
51 # skip ds54 # skip ds
52 # skip es55 # skip es
...@@ -70,6 +73,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)...@@ -70,6 +73,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
70# On entry, thread_state pointer is in rdi73# On entry, thread_state pointer is in rdi
71#endif74#endif
7275
76 _LIBUNWIND_CET_ENDBR
73 movq 56(%rdi), %rax # rax holds new stack pointer77 movq 56(%rdi), %rax # rax holds new stack pointer
74 subq $16, %rax78 subq $16, %rax
75 movq %rax, 56(%rdi)79 movq %rax, 56(%rdi)
...@@ -119,7 +123,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)...@@ -119,7 +123,8 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
119#endif123#endif
120 movq 56(%rdi), %rsp # cut back rsp to new location124 movq 56(%rdi), %rsp # cut back rsp to new location
121 pop %rdi # rdi was saved here earlier125 pop %rdi # rdi was saved here earlier
122 ret # rip was saved here126 pop %rcx
127 jmpq *%rcx
123128
124129
125#elif defined(__powerpc64__)130#elif defined(__powerpc64__)
...@@ -389,7 +394,7 @@ Lnovec:...@@ -389,7 +394,7 @@ Lnovec:
389 PPC64_LR(3)394 PPC64_LR(3)
390 bctr395 bctr
391396
392#elif defined(__ppc__)397#elif defined(__powerpc__)
393398
394DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_ppc6jumptoEv)399DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_ppc6jumptoEv)
395//400//
...@@ -655,7 +660,13 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv)...@@ -655,7 +660,13 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv)
655 ldr sp, [lr, #52]660 ldr sp, [lr, #52]
656 ldr lr, [lr, #60] @ restore pc into lr661 ldr lr, [lr, #60] @ restore pc into lr
657#endif662#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
658 JMP(lr)668 JMP(lr)
669#endif
659670
660@671@
661@ static void libunwind::Registers_arm::restoreVFPWithFLDMD(unw_fpreg_t* values)672@ static void libunwind::Registers_arm::restoreVFPWithFLDMD(unw_fpreg_t* values)
...@@ -800,11 +811,12 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind14Registers_or1k6jumptoEv)...@@ -800,11 +811,12 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind14Registers_or1k6jumptoEv)
800 l.lwz r30,120(r3)811 l.lwz r30,120(r3)
801 l.lwz r31,124(r3)812 l.lwz r31,124(r3)
802813
814 # load new pc into ra
815 l.lwz r9, 128(r3)
816
803 # at last, restore r3817 # at last, restore r3
804 l.lwz r3, 12(r3)818 l.lwz r3, 12(r3)
805819
806 # load new pc into ra
807 l.lwz r9, 128(r3)
808 # jump to pc820 # jump to pc
809 l.jr r9821 l.jr r9
810 l.nop822 l.nop
lib/libunwind/src/UnwindRegistersSave.S+8-3
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------ UnwindRegistersSave.S -----------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -27,6 +27,8 @@...@@ -27,6 +27,8 @@
27# + +27# + +
28#28#
29DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)29DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
30
31 _LIBUNWIND_CET_ENDBR
30 push %eax32 push %eax
31 movl 8(%esp), %eax33 movl 8(%esp), %eax
32 movl %ebx, 4(%eax)34 movl %ebx, 4(%eax)
...@@ -70,6 +72,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)...@@ -70,6 +72,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
70#define TMP %rsi72#define TMP %rsi
71#endif73#endif
7274
75 _LIBUNWIND_CET_ENDBR
73 movq %rax, (PTR)76 movq %rax, (PTR)
74 movq %rbx, 8(PTR)77 movq %rbx, 8(PTR)
75 movq %rcx, 16(PTR)78 movq %rcx, 16(PTR)
...@@ -556,7 +559,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)...@@ -556,7 +559,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
556 blr559 blr
557560
558561
559#elif defined(__ppc__)562#elif defined(__powerpc__)
560563
561//564//
562// extern int unw_getcontext(unw_context_t* thread_state)565// extern int unw_getcontext(unw_context_t* thread_state)
...@@ -600,9 +603,11 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)...@@ -600,9 +603,11 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
600 stw 30,128(3)603 stw 30,128(3)
601 stw 31,132(3)604 stw 31,132(3)
602605
606#if defined(__ALTIVEC__)
603 // save VRSave register607 // save VRSave register
604 mfspr 0, 256608 mfspr 0, 256
605 stw 0, 156(3)609 stw 0, 156(3)
610#endif
606 // save CR registers611 // save CR registers
607 mfcr 0612 mfcr 0
608 stw 0, 136(3)613 stw 0, 136(3)
...@@ -766,7 +771,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)...@@ -766,7 +771,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
766@771@
767@ On entry:772@ On entry:
768@ thread_state pointer is in r0773@ thread_state pointer is in r0
769@774@
770@ Per EHABI #4.7 this only saves the core integer registers.775@ Per EHABI #4.7 this only saves the core integer registers.
771@ EHABI #7.4.5 notes that in general all VRS registers should be restored776@ EHABI #7.4.5 notes that in general all VRS registers should be restored
772@ however this is very hard to do for VFP registers because it is unknown777@ 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,4 +1,4 @@
1//===--------------------- Unwind_AppleExtras.cpp -------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/assembly.h+20-2
...@@ -15,6 +15,13 @@...@@ -15,6 +15,13 @@
15#ifndef UNWIND_ASSEMBLY_H15#ifndef UNWIND_ASSEMBLY_H
16#define UNWIND_ASSEMBLY_H16#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
18#if defined(__powerpc64__)25#if defined(__powerpc64__)
19#define SEPARATOR ;26#define SEPARATOR ;
20#define PPC64_OFFS_SRR0 027#define PPC64_OFFS_SRR0 0
...@@ -74,7 +81,7 @@...@@ -74,7 +81,7 @@
74#define PPC64_OPD281#define PPC64_OPD2
75#endif82#endif
7683
77#if defined(__ARM_FEATURE_BTI_DEFAULT)84#if defined(__aarch64__) && defined(__ARM_FEATURE_BTI_DEFAULT)
78 .pushsection ".note.gnu.property", "a" SEPARATOR \85 .pushsection ".note.gnu.property", "a" SEPARATOR \
79 .balign 8 SEPARATOR \86 .balign 8 SEPARATOR \
80 .long 4 SEPARATOR \87 .long 4 SEPARATOR \
...@@ -92,6 +99,17 @@...@@ -92,6 +99,17 @@
92#define AARCH64_BTI99#define AARCH64_BTI
93#endif100#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
95#define GLUE2(a, b) a ## b113#define GLUE2(a, b) a ## b
96#define GLUE(a, b) GLUE2(a, b)114#define GLUE(a, b) GLUE2(a, b)
97#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)115#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
...@@ -216,7 +234,7 @@...@@ -216,7 +234,7 @@
216#endif234#endif
217#endif /* __arm__ */235#endif /* __arm__ */
218236
219#if defined(__ppc__) || defined(__powerpc64__)237#if defined(__powerpc__)
220#define PPC_LEFT_SHIFT(index) << (index)238#define PPC_LEFT_SHIFT(index) << (index)
221#endif239#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,4 +1,4 @@
1//===----------------------------- config.h -------------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -105,7 +105,7 @@...@@ -105,7 +105,7 @@
105#define _LIBUNWIND_BUILD_SJLJ_APIS105#define _LIBUNWIND_BUILD_SJLJ_APIS
106#endif106#endif
107107
108#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__ppc64__) || defined(__powerpc64__)108#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__)
109#define _LIBUNWIND_SUPPORT_FRAME_APIS109#define _LIBUNWIND_SUPPORT_FRAME_APIS
110#endif110#endif
111111
lib/libunwind/src/dwarf2.h+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------------- dwarf2.h -----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
lib/libunwind/src/libunwind.cpp+33-6
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===--------------------------- libunwind.cpp ----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -11,8 +11,8 @@...@@ -11,8 +11,8 @@
1111
12#include <libunwind.h>12#include <libunwind.h>
1313
14#include "libunwind_ext.h"
15#include "config.h"14#include "config.h"
15#include "libunwind_ext.h"
1616
17#include <stdlib.h>17#include <stdlib.h>
1818
...@@ -30,8 +30,6 @@...@@ -30,8 +30,6 @@
30#include "AddressSpace.hpp"30#include "AddressSpace.hpp"
31#include "UnwindCursor.hpp"31#include "UnwindCursor.hpp"
3232
33#pragma clang diagnostic ignored "-Wdll-attribute-on-redeclaration"
34
35using namespace libunwind;33using namespace libunwind;
3634
37/// internal object to represent this processes address space35/// internal object to represent this processes address space
...@@ -53,7 +51,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,...@@ -53,7 +51,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
53# define REGISTER_KIND Registers_x86_6451# define REGISTER_KIND Registers_x86_64
54#elif defined(__powerpc64__)52#elif defined(__powerpc64__)
55# define REGISTER_KIND Registers_ppc6453# define REGISTER_KIND Registers_ppc64
56#elif defined(__ppc__)54#elif defined(__powerpc__)
57# define REGISTER_KIND Registers_ppc55# define REGISTER_KIND Registers_ppc
58#elif defined(__aarch64__)56#elif defined(__aarch64__)
59# define REGISTER_KIND Registers_arm6457# define REGISTER_KIND Registers_arm64
...@@ -70,7 +68,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,...@@ -70,7 +68,7 @@ _LIBUNWIND_HIDDEN int __unw_init_local(unw_cursor_t *cursor,
70#elif defined(__mips__)68#elif defined(__mips__)
71# warning The MIPS architecture is not supported with this ABI and environment!69# warning The MIPS architecture is not supported with this ABI and environment!
72#elif defined(__sparc__) && defined(__arch64__)70#elif defined(__sparc__) && defined(__arch64__)
73# define REGISTER_KIND Registers_sparc6471#define REGISTER_KIND Registers_sparc64
74#elif defined(__sparc__)72#elif defined(__sparc__)
75# define REGISTER_KIND Registers_sparc73# define REGISTER_KIND Registers_sparc
76#elif defined(__riscv)74#elif defined(__riscv)
...@@ -296,6 +294,35 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {...@@ -296,6 +294,35 @@ void __unw_remove_dynamic_fde(unw_word_t fde) {
296 // fde is own mh_group294 // fde is own mh_group
297 DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);295 DwarfFDECache<LocalAddressSpace>::removeAllIn((LocalAddressSpace::pint_t)fde);
298}296}
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
299#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)326#endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
300#endif // !defined(__USING_SJLJ_EXCEPTIONS__)327#endif // !defined(__USING_SJLJ_EXCEPTIONS__)
301328
lib/libunwind/src/libunwind_ext.h+4-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//===------------------------ libunwind_ext.h -----------------------------===//1//===----------------------------------------------------------------------===//
2//2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.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.4// See https://llvm.org/LICENSE.txt for license information.
...@@ -51,6 +51,9 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(...@@ -51,6 +51,9 @@ extern void __unw_iterate_dwarf_unwind_cache(void (*func)(
51extern void __unw_add_dynamic_fde(unw_word_t fde);51extern void __unw_add_dynamic_fde(unw_word_t fde);
52extern void __unw_remove_dynamic_fde(unw_word_t fde);52extern 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
54#if defined(_LIBUNWIND_ARM_EHABI)57#if defined(_LIBUNWIND_ARM_EHABI)
55extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*);58extern const uint32_t* decode_eht_entry(const uint32_t*, size_t*, size_t*);
56extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context,59extern _Unwind_Reason_Code _Unwind_VRS_Interpret(_Unwind_Context *context,