Match: Refactor the unsigned SAT_ADD match pattern [NFC]
[gcc.git] / libgcc / unwind-dw2.c
blob8ac0588a19dc17e5a4358a8d0339b5217da06c4f
1 /* DWARF2 exception handling and frame unwind runtime interface routines.
2 Copyright (C) 1997-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #include "tconfig.h"
26 #include "tsystem.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "libgcc_tm.h"
30 #include "dwarf2.h"
31 #include "unwind.h"
32 #ifdef __USING_SJLJ_EXCEPTIONS__
33 # define NO_SIZE_OF_ENCODED_VALUE
34 #endif
35 #include "unwind-pe.h"
36 #include "unwind-dw2-fde.h"
37 #include "gthr.h"
38 #include "unwind-dw2.h"
39 #include <stddef.h>
41 #ifdef HAVE_SYS_SDT_H
42 #include <sys/sdt.h>
43 #endif
45 #ifndef __USING_SJLJ_EXCEPTIONS__
47 #ifndef __LIBGCC_STACK_GROWS_DOWNWARD__
48 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 0
49 #else
50 #undef __LIBGCC_STACK_GROWS_DOWNWARD__
51 #define __LIBGCC_STACK_GROWS_DOWNWARD__ 1
52 #endif
54 /* Dwarf frame registers used for pre gcc 3.0 compiled glibc. */
55 #ifndef PRE_GCC3_DWARF_FRAME_REGISTERS
56 #define PRE_GCC3_DWARF_FRAME_REGISTERS __LIBGCC_DWARF_FRAME_REGISTERS__
57 #endif
59 /* ??? For the public function interfaces, we tend to gcc_assert that the
60 column numbers are in range. For the dwarf2 unwind info this does happen,
61 although so far in a case that doesn't actually matter.
63 See PR49146, in which a call from x86_64 ms abi to x86_64 unix abi stores
64 the call-saved xmm registers and annotates them. We havn't bothered
65 providing support for the xmm registers for the x86_64 port primarily
66 because the 64-bit windows targets don't use dwarf2 unwind, using sjlj or
67 SEH instead. Adding the support for unix targets would generally be a
68 waste. However, some runtime libraries supplied with ICC do contain such
69 an unorthodox transition, as well as the unwind info to match. This loss
70 of register restoration doesn't matter in practice, because the exception
71 is caught in the native unix abi, where all of the xmm registers are
72 call clobbered.
74 Ideally, we'd record some bit to notice when we're failing to restore some
75 register recorded in the unwind info, but to do that we need annotation on
76 the unix->ms abi edge, so that we know when the register data may be
77 discarded. And since this edge is also within the ICC library, we're
78 unlikely to be able to get the new annotation.
80 Barring a magic solution to restore the ms abi defined 128-bit xmm registers
81 (as distictly opposed to the full runtime width) without causing extra
82 overhead for normal unix abis, the best solution seems to be to simply
83 ignore unwind data for unknown columns. */
85 #define UNWIND_COLUMN_IN_RANGE(x) \
86 __builtin_expect((x) <= __LIBGCC_DWARF_FRAME_REGISTERS__, 1)
88 #ifdef REG_VALUE_IN_UNWIND_CONTEXT
89 typedef _Unwind_Word _Unwind_Context_Reg_Val;
91 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
92 #define ASSUME_EXTENDED_UNWIND_CONTEXT 1
93 #endif
95 static inline _Unwind_Word
96 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
98 return val;
101 static inline _Unwind_Context_Reg_Val
102 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
104 return val;
106 #else
107 typedef void *_Unwind_Context_Reg_Val;
109 static inline _Unwind_Word
110 _Unwind_Get_Unwind_Word (_Unwind_Context_Reg_Val val)
112 return (_Unwind_Word) (_Unwind_Internal_Ptr) val;
115 static inline _Unwind_Context_Reg_Val
116 _Unwind_Get_Unwind_Context_Reg_Val (_Unwind_Word val)
118 return (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) val;
120 #endif
122 #ifndef ASSUME_EXTENDED_UNWIND_CONTEXT
123 #define ASSUME_EXTENDED_UNWIND_CONTEXT 0
124 #endif
126 /* This is the register and unwind state for a particular frame. This
127 provides the information necessary to unwind up past a frame and return
128 to its caller. */
129 struct _Unwind_Context
131 _Unwind_Context_Reg_Val reg[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
132 void *cfa;
133 void *ra;
134 void *lsda;
135 struct dwarf_eh_bases bases;
136 /* Signal frame context. */
137 #define SIGNAL_FRAME_BIT ((~(_Unwind_Word) 0 >> 1) + 1)
138 /* Context which has version/args_size/by_value fields. */
139 #define EXTENDED_CONTEXT_BIT ((~(_Unwind_Word) 0 >> 2) + 1)
140 _Unwind_Word flags;
141 /* 0 for now, can be increased when further fields are added to
142 struct _Unwind_Context. */
143 _Unwind_Word version;
144 _Unwind_Word args_size;
145 char by_value[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
148 /* Byte size of every register managed by these routines. */
149 static unsigned char dwarf_reg_size_table[__LIBGCC_DWARF_FRAME_REGISTERS__+1];
152 /* Read unaligned data from the instruction buffer. */
154 union unaligned
156 void *p;
157 unsigned u2 __attribute__ ((mode (HI)));
158 unsigned u4 __attribute__ ((mode (SI)));
159 unsigned u8 __attribute__ ((mode (DI)));
160 signed s2 __attribute__ ((mode (HI)));
161 signed s4 __attribute__ ((mode (SI)));
162 signed s8 __attribute__ ((mode (DI)));
163 } __attribute__ ((packed));
165 static void uw_update_context (struct _Unwind_Context *, _Unwind_FrameState *);
166 static _Unwind_Reason_Code uw_frame_state_for (struct _Unwind_Context *,
167 _Unwind_FrameState *);
169 static inline void *
170 read_pointer (const void *p) { const union unaligned *up = p; return up->p; }
172 static inline int
173 read_1u (const void *p) { return *(const unsigned char *) p; }
175 static inline int
176 read_1s (const void *p) { return *(const signed char *) p; }
178 static inline int
179 read_2u (const void *p) { const union unaligned *up = p; return up->u2; }
181 static inline int
182 read_2s (const void *p) { const union unaligned *up = p; return up->s2; }
184 static inline unsigned int
185 read_4u (const void *p) { const union unaligned *up = p; return up->u4; }
187 static inline int
188 read_4s (const void *p) { const union unaligned *up = p; return up->s4; }
190 static inline unsigned long
191 read_8u (const void *p) { const union unaligned *up = p; return up->u8; }
193 static inline unsigned long
194 read_8s (const void *p) { const union unaligned *up = p; return up->s8; }
196 static inline _Unwind_Word
197 _Unwind_IsSignalFrame (struct _Unwind_Context *context)
199 return (context->flags & SIGNAL_FRAME_BIT) ? 1 : 0;
202 static inline void
203 _Unwind_SetSignalFrame (struct _Unwind_Context *context, int val)
205 if (val)
206 context->flags |= SIGNAL_FRAME_BIT;
207 else
208 context->flags &= ~SIGNAL_FRAME_BIT;
211 static inline _Unwind_Word
212 _Unwind_IsExtendedContext (struct _Unwind_Context *context)
214 return (ASSUME_EXTENDED_UNWIND_CONTEXT
215 || (context->flags & EXTENDED_CONTEXT_BIT));
218 /* Get the value of register REGNO as saved in CONTEXT. */
220 inline _Unwind_Word
221 _Unwind_GetGR (struct _Unwind_Context *context, int regno)
223 int size, index;
224 _Unwind_Context_Reg_Val val;
226 #ifdef DWARF_ZERO_REG
227 if (regno == DWARF_ZERO_REG)
228 return 0;
229 #endif
231 index = DWARF_REG_TO_UNWIND_COLUMN (regno);
232 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
233 size = dwarf_reg_size_table[index];
234 val = context->reg[index];
236 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
237 return _Unwind_Get_Unwind_Word (val);
239 #ifdef DWARF_LAZY_REGISTER_VALUE
241 _Unwind_Word value;
242 if (DWARF_LAZY_REGISTER_VALUE (regno, &value))
243 return value;
245 #endif
247 /* This will segfault if the register hasn't been saved. */
248 if (size == sizeof(_Unwind_Ptr))
249 return * (_Unwind_Ptr *) (_Unwind_Internal_Ptr) val;
250 else
252 gcc_assert (size == sizeof(_Unwind_Word));
253 return * (_Unwind_Word *) (_Unwind_Internal_Ptr) val;
257 static inline void *
258 _Unwind_GetPtr (struct _Unwind_Context *context, int index)
260 return (void *)(_Unwind_Ptr) _Unwind_GetGR (context, index);
263 /* Get the value of the CFA as saved in CONTEXT. */
265 _Unwind_Word
266 _Unwind_GetCFA (struct _Unwind_Context *context)
268 return (_Unwind_Ptr) context->cfa;
271 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
273 inline void
274 _Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val)
276 int size;
277 void *ptr;
279 index = DWARF_REG_TO_UNWIND_COLUMN (index);
280 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
281 size = dwarf_reg_size_table[index];
283 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
285 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
286 return;
289 ptr = (void *) (_Unwind_Internal_Ptr) context->reg[index];
291 if (size == sizeof(_Unwind_Ptr))
292 * (_Unwind_Ptr *) ptr = val;
293 else
295 gcc_assert (size == sizeof(_Unwind_Word));
296 * (_Unwind_Word *) ptr = val;
300 /* Get the pointer to a register INDEX as saved in CONTEXT. */
302 static inline void *
303 _Unwind_GetGRPtr (struct _Unwind_Context *context, int index)
305 index = DWARF_REG_TO_UNWIND_COLUMN (index);
306 if (_Unwind_IsExtendedContext (context) && context->by_value[index])
307 return &context->reg[index];
308 return (void *) (_Unwind_Internal_Ptr) context->reg[index];
311 /* Set the pointer to a register INDEX as saved in CONTEXT. */
313 static inline void
314 _Unwind_SetGRPtr (struct _Unwind_Context *context, int index, void *p)
316 index = DWARF_REG_TO_UNWIND_COLUMN (index);
317 if (_Unwind_IsExtendedContext (context))
318 context->by_value[index] = 0;
319 context->reg[index] = (_Unwind_Context_Reg_Val) (_Unwind_Internal_Ptr) p;
322 /* Overwrite the saved value for register INDEX in CONTEXT with VAL. */
324 static inline void
325 _Unwind_SetGRValue (struct _Unwind_Context *context, int index,
326 _Unwind_Word val)
328 index = DWARF_REG_TO_UNWIND_COLUMN (index);
329 gcc_assert (index < (int) sizeof(dwarf_reg_size_table));
330 /* Return column size may be smaller than _Unwind_Context_Reg_Val. */
331 gcc_assert (dwarf_reg_size_table[index] <= sizeof (_Unwind_Context_Reg_Val));
333 context->by_value[index] = 1;
334 context->reg[index] = _Unwind_Get_Unwind_Context_Reg_Val (val);
337 /* Return nonzero if register INDEX is stored by value rather than
338 by reference. */
340 static inline int
341 _Unwind_GRByValue (struct _Unwind_Context *context, int index)
343 index = DWARF_REG_TO_UNWIND_COLUMN (index);
344 return context->by_value[index];
347 /* Retrieve the return address for CONTEXT. */
349 inline _Unwind_Ptr
350 _Unwind_GetIP (struct _Unwind_Context *context)
352 return (_Unwind_Ptr) context->ra;
355 /* Retrieve the return address and flag whether that IP is before
356 or after first not yet fully executed instruction. */
358 inline _Unwind_Ptr
359 _Unwind_GetIPInfo (struct _Unwind_Context *context, int *ip_before_insn)
361 *ip_before_insn = _Unwind_IsSignalFrame (context);
362 return (_Unwind_Ptr) context->ra;
365 /* Overwrite the return address for CONTEXT with VAL. */
367 inline void
368 _Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val)
370 context->ra = (void *) val;
373 void *
374 _Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
376 return context->lsda;
379 _Unwind_Ptr
380 _Unwind_GetRegionStart (struct _Unwind_Context *context)
382 return (_Unwind_Ptr) context->bases.func;
385 void *
386 _Unwind_FindEnclosingFunction (void *pc)
388 struct dwarf_eh_bases bases;
389 const struct dwarf_fde *fde = _Unwind_Find_FDE (pc-1, &bases);
390 if (fde)
391 return bases.func;
392 else
393 return NULL;
396 #ifndef __ia64__
397 _Unwind_Ptr
398 _Unwind_GetDataRelBase (struct _Unwind_Context *context)
400 return (_Unwind_Ptr) context->bases.dbase;
403 _Unwind_Ptr
404 _Unwind_GetTextRelBase (struct _Unwind_Context *context)
406 return (_Unwind_Ptr) context->bases.tbase;
408 #endif
410 #include "md-unwind-support.h"
412 /* Extract any interesting information from the CIE for the translation
413 unit F belongs to. Return a pointer to the byte after the augmentation,
414 or NULL if we encountered an undecipherable augmentation. */
416 static const unsigned char *
417 extract_cie_info (const struct dwarf_cie *cie, struct _Unwind_Context *context,
418 _Unwind_FrameState *fs)
420 const unsigned char *aug = cie->augmentation;
421 const unsigned char *p = aug + strlen ((const char *)aug) + 1;
422 const unsigned char *ret = NULL;
423 _uleb128_t utmp;
424 _sleb128_t stmp;
426 /* g++ v2 "eh" has pointer immediately following augmentation string,
427 so it must be handled first. */
428 if (aug[0] == 'e' && aug[1] == 'h')
430 fs->eh_ptr = read_pointer (p);
431 p += sizeof (void *);
432 aug += 2;
435 /* After the augmentation resp. pointer for "eh" augmentation
436 follows for CIE version >= 4 address size byte and
437 segment size byte. */
438 if (__builtin_expect (cie->version >= 4, 0))
440 if (p[0] != sizeof (void *) || p[1] != 0)
441 return NULL;
442 p += 2;
444 /* Immediately following this are the code and
445 data alignment and return address column. */
446 p = read_uleb128 (p, &utmp);
447 fs->code_align = (_Unwind_Word)utmp;
448 p = read_sleb128 (p, &stmp);
449 fs->data_align = (_Unwind_Sword)stmp;
450 if (cie->version == 1)
451 fs->retaddr_column = *p++;
452 else
454 p = read_uleb128 (p, &utmp);
455 fs->retaddr_column = (_Unwind_Word)utmp;
457 fs->lsda_encoding = DW_EH_PE_omit;
459 /* If the augmentation starts with 'z', then a uleb128 immediately
460 follows containing the length of the augmentation field following
461 the size. */
462 if (*aug == 'z')
464 p = read_uleb128 (p, &utmp);
465 ret = p + utmp;
467 fs->saw_z = 1;
468 ++aug;
471 /* Iterate over recognized augmentation subsequences. */
472 while (*aug != '\0')
474 /* "L" indicates a byte showing how the LSDA pointer is encoded. */
475 if (aug[0] == 'L')
477 fs->lsda_encoding = *p++;
478 aug += 1;
481 /* "R" indicates a byte indicating how FDE addresses are encoded. */
482 else if (aug[0] == 'R')
484 fs->fde_encoding = *p++;
485 aug += 1;
488 /* "P" indicates a personality routine in the CIE augmentation. */
489 else if (aug[0] == 'P')
491 _Unwind_Ptr personality;
493 p = read_encoded_value (context, *p, p + 1, &personality);
494 fs->personality = (_Unwind_Personality_Fn) personality;
495 aug += 1;
498 /* "S" indicates a signal frame. */
499 else if (aug[0] == 'S')
501 fs->signal_frame = 1;
502 aug += 1;
505 #if defined(MD_ARCH_EXTENSION_CIE_AUG_HANDLER)
506 else if (MD_ARCH_EXTENSION_CIE_AUG_HANDLER (fs, aug[0]))
507 aug += 1;
508 #endif
510 /* Otherwise we have an unknown augmentation string.
511 Bail unless we saw a 'z' prefix. */
512 else
513 return ret;
516 return ret ? ret : p;
520 /* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
521 onto the stack to start. */
523 static _Unwind_Word
524 execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
525 struct _Unwind_Context *context, _Unwind_Word initial)
527 _Unwind_Word stack[64]; /* ??? Assume this is enough. */
528 int stack_elt;
530 stack[0] = initial;
531 stack_elt = 1;
533 while (op_ptr < op_end)
535 enum dwarf_location_atom op = *op_ptr++;
536 _Unwind_Word result;
537 _uleb128_t reg, utmp;
538 _sleb128_t offset, stmp;
540 switch (op)
542 case DW_OP_lit0:
543 case DW_OP_lit1:
544 case DW_OP_lit2:
545 case DW_OP_lit3:
546 case DW_OP_lit4:
547 case DW_OP_lit5:
548 case DW_OP_lit6:
549 case DW_OP_lit7:
550 case DW_OP_lit8:
551 case DW_OP_lit9:
552 case DW_OP_lit10:
553 case DW_OP_lit11:
554 case DW_OP_lit12:
555 case DW_OP_lit13:
556 case DW_OP_lit14:
557 case DW_OP_lit15:
558 case DW_OP_lit16:
559 case DW_OP_lit17:
560 case DW_OP_lit18:
561 case DW_OP_lit19:
562 case DW_OP_lit20:
563 case DW_OP_lit21:
564 case DW_OP_lit22:
565 case DW_OP_lit23:
566 case DW_OP_lit24:
567 case DW_OP_lit25:
568 case DW_OP_lit26:
569 case DW_OP_lit27:
570 case DW_OP_lit28:
571 case DW_OP_lit29:
572 case DW_OP_lit30:
573 case DW_OP_lit31:
574 result = op - DW_OP_lit0;
575 break;
577 case DW_OP_addr:
578 result = (_Unwind_Word) (_Unwind_Ptr) read_pointer (op_ptr);
579 op_ptr += sizeof (void *);
580 break;
582 case DW_OP_GNU_encoded_addr:
584 _Unwind_Ptr presult;
585 op_ptr = read_encoded_value (context, *op_ptr, op_ptr+1, &presult);
586 result = presult;
588 break;
590 case DW_OP_const1u:
591 result = read_1u (op_ptr);
592 op_ptr += 1;
593 break;
594 case DW_OP_const1s:
595 result = read_1s (op_ptr);
596 op_ptr += 1;
597 break;
598 case DW_OP_const2u:
599 result = read_2u (op_ptr);
600 op_ptr += 2;
601 break;
602 case DW_OP_const2s:
603 result = read_2s (op_ptr);
604 op_ptr += 2;
605 break;
606 case DW_OP_const4u:
607 result = read_4u (op_ptr);
608 op_ptr += 4;
609 break;
610 case DW_OP_const4s:
611 result = read_4s (op_ptr);
612 op_ptr += 4;
613 break;
614 case DW_OP_const8u:
615 result = read_8u (op_ptr);
616 op_ptr += 8;
617 break;
618 case DW_OP_const8s:
619 result = read_8s (op_ptr);
620 op_ptr += 8;
621 break;
622 case DW_OP_constu:
623 op_ptr = read_uleb128 (op_ptr, &utmp);
624 result = (_Unwind_Word)utmp;
625 break;
626 case DW_OP_consts:
627 op_ptr = read_sleb128 (op_ptr, &stmp);
628 result = (_Unwind_Sword)stmp;
629 break;
631 case DW_OP_reg0:
632 case DW_OP_reg1:
633 case DW_OP_reg2:
634 case DW_OP_reg3:
635 case DW_OP_reg4:
636 case DW_OP_reg5:
637 case DW_OP_reg6:
638 case DW_OP_reg7:
639 case DW_OP_reg8:
640 case DW_OP_reg9:
641 case DW_OP_reg10:
642 case DW_OP_reg11:
643 case DW_OP_reg12:
644 case DW_OP_reg13:
645 case DW_OP_reg14:
646 case DW_OP_reg15:
647 case DW_OP_reg16:
648 case DW_OP_reg17:
649 case DW_OP_reg18:
650 case DW_OP_reg19:
651 case DW_OP_reg20:
652 case DW_OP_reg21:
653 case DW_OP_reg22:
654 case DW_OP_reg23:
655 case DW_OP_reg24:
656 case DW_OP_reg25:
657 case DW_OP_reg26:
658 case DW_OP_reg27:
659 case DW_OP_reg28:
660 case DW_OP_reg29:
661 case DW_OP_reg30:
662 case DW_OP_reg31:
663 result = _Unwind_GetGR (context, op - DW_OP_reg0);
664 break;
665 case DW_OP_regx:
666 op_ptr = read_uleb128 (op_ptr, &reg);
667 result = _Unwind_GetGR (context, reg);
668 break;
670 case DW_OP_breg0:
671 case DW_OP_breg1:
672 case DW_OP_breg2:
673 case DW_OP_breg3:
674 case DW_OP_breg4:
675 case DW_OP_breg5:
676 case DW_OP_breg6:
677 case DW_OP_breg7:
678 case DW_OP_breg8:
679 case DW_OP_breg9:
680 case DW_OP_breg10:
681 case DW_OP_breg11:
682 case DW_OP_breg12:
683 case DW_OP_breg13:
684 case DW_OP_breg14:
685 case DW_OP_breg15:
686 case DW_OP_breg16:
687 case DW_OP_breg17:
688 case DW_OP_breg18:
689 case DW_OP_breg19:
690 case DW_OP_breg20:
691 case DW_OP_breg21:
692 case DW_OP_breg22:
693 case DW_OP_breg23:
694 case DW_OP_breg24:
695 case DW_OP_breg25:
696 case DW_OP_breg26:
697 case DW_OP_breg27:
698 case DW_OP_breg28:
699 case DW_OP_breg29:
700 case DW_OP_breg30:
701 case DW_OP_breg31:
702 op_ptr = read_sleb128 (op_ptr, &offset);
703 result = _Unwind_GetGR (context, op - DW_OP_breg0) + offset;
704 break;
705 case DW_OP_bregx:
706 op_ptr = read_uleb128 (op_ptr, &reg);
707 op_ptr = read_sleb128 (op_ptr, &offset);
708 result = _Unwind_GetGR (context, reg) + (_Unwind_Word)offset;
709 break;
711 case DW_OP_dup:
712 gcc_assert (stack_elt);
713 result = stack[stack_elt - 1];
714 break;
716 case DW_OP_drop:
717 gcc_assert (stack_elt);
718 stack_elt -= 1;
719 goto no_push;
721 case DW_OP_pick:
722 offset = *op_ptr++;
723 gcc_assert (offset < stack_elt - 1);
724 result = stack[stack_elt - 1 - offset];
725 break;
727 case DW_OP_over:
728 gcc_assert (stack_elt >= 2);
729 result = stack[stack_elt - 2];
730 break;
732 case DW_OP_swap:
734 _Unwind_Word t;
735 gcc_assert (stack_elt >= 2);
736 t = stack[stack_elt - 1];
737 stack[stack_elt - 1] = stack[stack_elt - 2];
738 stack[stack_elt - 2] = t;
739 goto no_push;
742 case DW_OP_rot:
744 _Unwind_Word t1, t2, t3;
746 gcc_assert (stack_elt >= 3);
747 t1 = stack[stack_elt - 1];
748 t2 = stack[stack_elt - 2];
749 t3 = stack[stack_elt - 3];
750 stack[stack_elt - 1] = t2;
751 stack[stack_elt - 2] = t3;
752 stack[stack_elt - 3] = t1;
753 goto no_push;
756 case DW_OP_deref:
757 case DW_OP_deref_size:
758 case DW_OP_abs:
759 case DW_OP_neg:
760 case DW_OP_not:
761 case DW_OP_plus_uconst:
762 /* Unary operations. */
763 gcc_assert (stack_elt);
764 stack_elt -= 1;
766 result = stack[stack_elt];
768 switch (op)
770 case DW_OP_deref:
772 void *ptr = (void *) (_Unwind_Ptr) result;
773 result = (_Unwind_Ptr) read_pointer (ptr);
775 break;
777 case DW_OP_deref_size:
779 void *ptr = (void *) (_Unwind_Ptr) result;
780 switch (*op_ptr++)
782 case 1:
783 result = read_1u (ptr);
784 break;
785 case 2:
786 result = read_2u (ptr);
787 break;
788 case 4:
789 result = read_4u (ptr);
790 break;
791 case 8:
792 result = read_8u (ptr);
793 break;
794 default:
795 gcc_unreachable ();
798 break;
800 case DW_OP_abs:
801 if ((_Unwind_Sword) result < 0)
802 result = -result;
803 break;
804 case DW_OP_neg:
805 result = -result;
806 break;
807 case DW_OP_not:
808 result = ~result;
809 break;
810 case DW_OP_plus_uconst:
811 op_ptr = read_uleb128 (op_ptr, &utmp);
812 result += (_Unwind_Word)utmp;
813 break;
815 default:
816 gcc_unreachable ();
818 break;
820 case DW_OP_and:
821 case DW_OP_div:
822 case DW_OP_minus:
823 case DW_OP_mod:
824 case DW_OP_mul:
825 case DW_OP_or:
826 case DW_OP_plus:
827 case DW_OP_shl:
828 case DW_OP_shr:
829 case DW_OP_shra:
830 case DW_OP_xor:
831 case DW_OP_le:
832 case DW_OP_ge:
833 case DW_OP_eq:
834 case DW_OP_lt:
835 case DW_OP_gt:
836 case DW_OP_ne:
838 /* Binary operations. */
839 _Unwind_Word first, second;
840 gcc_assert (stack_elt >= 2);
841 stack_elt -= 2;
843 second = stack[stack_elt];
844 first = stack[stack_elt + 1];
846 switch (op)
848 case DW_OP_and:
849 result = second & first;
850 break;
851 case DW_OP_div:
852 result = (_Unwind_Sword) second / (_Unwind_Sword) first;
853 break;
854 case DW_OP_minus:
855 result = second - first;
856 break;
857 case DW_OP_mod:
858 result = second % first;
859 break;
860 case DW_OP_mul:
861 result = second * first;
862 break;
863 case DW_OP_or:
864 result = second | first;
865 break;
866 case DW_OP_plus:
867 result = second + first;
868 break;
869 case DW_OP_shl:
870 result = second << first;
871 break;
872 case DW_OP_shr:
873 result = second >> first;
874 break;
875 case DW_OP_shra:
876 result = (_Unwind_Sword) second >> first;
877 break;
878 case DW_OP_xor:
879 result = second ^ first;
880 break;
881 case DW_OP_le:
882 result = (_Unwind_Sword) second <= (_Unwind_Sword) first;
883 break;
884 case DW_OP_ge:
885 result = (_Unwind_Sword) second >= (_Unwind_Sword) first;
886 break;
887 case DW_OP_eq:
888 result = (_Unwind_Sword) second == (_Unwind_Sword) first;
889 break;
890 case DW_OP_lt:
891 result = (_Unwind_Sword) second < (_Unwind_Sword) first;
892 break;
893 case DW_OP_gt:
894 result = (_Unwind_Sword) second > (_Unwind_Sword) first;
895 break;
896 case DW_OP_ne:
897 result = (_Unwind_Sword) second != (_Unwind_Sword) first;
898 break;
900 default:
901 gcc_unreachable ();
904 break;
906 case DW_OP_skip:
907 offset = read_2s (op_ptr);
908 op_ptr += 2;
909 op_ptr += offset;
910 goto no_push;
912 case DW_OP_bra:
913 gcc_assert (stack_elt);
914 stack_elt -= 1;
916 offset = read_2s (op_ptr);
917 op_ptr += 2;
918 if (stack[stack_elt] != 0)
919 op_ptr += offset;
920 goto no_push;
922 case DW_OP_nop:
923 goto no_push;
925 default:
926 gcc_unreachable ();
929 /* Most things push a result value. */
930 gcc_assert ((size_t) stack_elt < sizeof(stack)/sizeof(*stack));
931 stack[stack_elt++] = result;
932 no_push:;
935 /* We were executing this program to get a value. It should be
936 at top of stack. */
937 gcc_assert (stack_elt);
938 stack_elt -= 1;
939 return stack[stack_elt];
943 /* Decode DWARF 2 call frame information. Takes pointers the
944 instruction sequence to decode, current register information and
945 CIE info, and the PC range to evaluate. */
947 static void __attribute__ ((__noinline__))
948 execute_cfa_program_generic (const unsigned char *insn_ptr,
949 const unsigned char *insn_end,
950 struct _Unwind_Context *context,
951 _Unwind_FrameState *fs)
953 #define DATA_ALIGN fs->data_align
954 #define CODE_ALIGN fs->code_align
955 #include "unwind-dw2-execute_cfa.h"
958 static inline void
959 execute_cfa_program_specialized (const unsigned char *insn_ptr,
960 const unsigned char *insn_end,
961 struct _Unwind_Context *context,
962 _Unwind_FrameState *fs)
964 #define DATA_ALIGN __LIBGCC_DWARF_CIE_DATA_ALIGNMENT__
965 /* GCC always uses 1 even on architectures with a fixed instruction
966 width. */
967 #define CODE_ALIGN 1
968 #include "unwind-dw2-execute_cfa.h"
971 static void
972 execute_cfa_program (const unsigned char *insn_ptr,
973 const unsigned char *insn_end,
974 struct _Unwind_Context *context,
975 _Unwind_FrameState *fs)
977 if (fs->data_align == __LIBGCC_DWARF_CIE_DATA_ALIGNMENT__
978 && fs->code_align == 1)
979 execute_cfa_program_specialized (insn_ptr, insn_end, context, fs);
980 else
981 execute_cfa_program_generic (insn_ptr, insn_end, context, fs);
985 /* Given the _Unwind_Context CONTEXT for a stack frame, look up the FDE for
986 its caller and decode it into FS. This function also sets the
987 args_size and lsda members of CONTEXT, as they are really information
988 about the caller's frame. */
990 static _Unwind_Reason_Code
991 uw_frame_state_for (struct _Unwind_Context *context, _Unwind_FrameState *fs)
993 const struct dwarf_fde *fde;
994 const struct dwarf_cie *cie;
995 const unsigned char *aug, *insn, *end;
997 memset (&fs->regs.how[0], 0,
998 sizeof (*fs) - offsetof (_Unwind_FrameState, regs.how[0]));
999 #if defined(MD_ARCH_EXTENSION_FRAME_INIT)
1000 MD_ARCH_EXTENSION_FRAME_INIT (context, fs);
1001 #endif
1002 context->args_size = 0;
1003 context->lsda = 0;
1005 if (context->ra == 0)
1006 return _URC_END_OF_STACK;
1008 fde = _Unwind_Find_FDE (context->ra + _Unwind_IsSignalFrame (context) - 1,
1009 &context->bases);
1010 if (fde == NULL)
1012 #ifdef MD_FALLBACK_FRAME_STATE_FOR
1013 /* Couldn't find frame unwind info for this function. Try a
1014 target-specific fallback mechanism. This will necessarily
1015 not provide a personality routine or LSDA. */
1016 return MD_FALLBACK_FRAME_STATE_FOR (context, fs);
1017 #else
1018 return _URC_END_OF_STACK;
1019 #endif
1022 fs->pc = context->bases.func;
1024 cie = get_cie (fde);
1025 insn = extract_cie_info (cie, context, fs);
1026 if (insn == NULL)
1027 /* CIE contained unknown augmentation. */
1028 return _URC_FATAL_PHASE1_ERROR;
1030 /* First decode all the insns in the CIE. */
1031 end = (const unsigned char *) next_fde ((const struct dwarf_fde *) cie);
1032 execute_cfa_program (insn, end, context, fs);
1034 /* Locate augmentation for the fde. */
1035 aug = (const unsigned char *) fde + sizeof (*fde);
1036 aug += 2 * size_of_encoded_value (fs->fde_encoding);
1037 insn = NULL;
1038 if (fs->saw_z)
1040 _uleb128_t i;
1041 aug = read_uleb128 (aug, &i);
1042 insn = aug + i;
1044 if (fs->lsda_encoding != DW_EH_PE_omit)
1046 _Unwind_Ptr lsda;
1048 aug = read_encoded_value (context, fs->lsda_encoding, aug, &lsda);
1049 context->lsda = (void *) lsda;
1052 /* Then the insns in the FDE up to our target PC. */
1053 if (insn == NULL)
1054 insn = aug;
1055 end = (const unsigned char *) next_fde (fde);
1056 execute_cfa_program (insn, end, context, fs);
1058 return _URC_NO_REASON;
1061 typedef struct frame_state
1063 void *cfa;
1064 void *eh_ptr;
1065 long cfa_offset;
1066 long args_size;
1067 long reg_or_offset[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1068 unsigned short cfa_reg;
1069 unsigned short retaddr_column;
1070 char saved[PRE_GCC3_DWARF_FRAME_REGISTERS+1];
1071 } frame_state;
1073 struct frame_state * __frame_state_for (void *, struct frame_state *);
1075 /* Called from pre-G++ 3.0 __throw to find the registers to restore for
1076 a given PC_TARGET. The caller should allocate a local variable of
1077 `struct frame_state' and pass its address to STATE_IN. */
1079 struct frame_state *
1080 __frame_state_for (void *pc_target, struct frame_state *state_in)
1082 struct _Unwind_Context context;
1083 _Unwind_FrameState fs;
1084 int reg;
1086 memset (&context, 0, sizeof (struct _Unwind_Context));
1087 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1088 context.flags = EXTENDED_CONTEXT_BIT;
1089 context.ra = pc_target + 1;
1091 if (uw_frame_state_for (&context, &fs) != _URC_NO_REASON)
1092 return 0;
1094 /* We have no way to pass a location expression for the CFA to our
1095 caller. It wouldn't understand it anyway. */
1096 if (fs.regs.cfa_how == CFA_EXP)
1097 return 0;
1099 for (reg = 0; reg < PRE_GCC3_DWARF_FRAME_REGISTERS + 1; reg++)
1101 state_in->saved[reg] = fs.regs.how[reg];
1102 switch (state_in->saved[reg])
1104 case REG_SAVED_REG:
1105 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.reg;
1106 break;
1107 case REG_SAVED_OFFSET:
1108 state_in->reg_or_offset[reg] = fs.regs.reg[reg].loc.offset;
1109 break;
1110 default:
1111 state_in->reg_or_offset[reg] = 0;
1112 break;
1116 state_in->cfa_offset = fs.regs.cfa_offset;
1117 state_in->cfa_reg = fs.regs.cfa_reg;
1118 state_in->retaddr_column = fs.retaddr_column;
1119 state_in->args_size = context.args_size;
1120 state_in->eh_ptr = fs.eh_ptr;
1122 return state_in;
1125 typedef union { _Unwind_Ptr ptr; _Unwind_Word word; } _Unwind_SpTmp;
1127 static inline void
1128 _Unwind_SetSpColumn (struct _Unwind_Context *context, void *cfa,
1129 _Unwind_SpTmp *tmp_sp)
1131 int size = dwarf_reg_size_table[__builtin_dwarf_sp_column ()];
1133 if (size == sizeof(_Unwind_Ptr))
1134 tmp_sp->ptr = (_Unwind_Ptr) cfa;
1135 else
1137 gcc_assert (size == sizeof(_Unwind_Word));
1138 tmp_sp->word = (_Unwind_Ptr) cfa;
1140 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), tmp_sp);
1143 static void
1144 uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1146 struct _Unwind_Context orig_context = *context;
1147 void *cfa;
1148 long i;
1150 #ifdef __LIBGCC_EH_RETURN_STACKADJ_RTX__
1151 /* Special handling here: Many machines do not use a frame pointer,
1152 and track the CFA only through offsets from the stack pointer from
1153 one frame to the next. In this case, the stack pointer is never
1154 stored, so it has no saved address in the context. What we do
1155 have is the CFA from the previous stack frame.
1157 In very special situations (such as unwind info for signal return),
1158 there may be location expressions that use the stack pointer as well.
1160 Do this conditionally for one frame. This allows the unwind info
1161 for one frame to save a copy of the stack pointer from the previous
1162 frame, and be able to use much easier CFA mechanisms to do it.
1163 Always zap the saved stack pointer value for the next frame; carrying
1164 the value over from one frame to another doesn't make sense. */
1166 _Unwind_SpTmp tmp_sp;
1168 if (!_Unwind_GetGRPtr (&orig_context, __builtin_dwarf_sp_column ()))
1169 _Unwind_SetSpColumn (&orig_context, context->cfa, &tmp_sp);
1170 _Unwind_SetGRPtr (context, __builtin_dwarf_sp_column (), NULL);
1171 #endif
1173 /* Compute this frame's CFA. */
1174 switch (fs->regs.cfa_how)
1176 case CFA_REG_OFFSET:
1177 cfa = _Unwind_GetPtr (&orig_context, fs->regs.cfa_reg);
1178 cfa += fs->regs.cfa_offset;
1179 break;
1181 case CFA_EXP:
1183 const unsigned char *exp = fs->regs.cfa_exp;
1184 _uleb128_t len;
1186 exp = read_uleb128 (exp, &len);
1187 cfa = (void *) (_Unwind_Ptr)
1188 execute_stack_op (exp, exp + len, &orig_context, 0);
1189 break;
1192 default:
1193 gcc_unreachable ();
1195 context->cfa = cfa;
1197 /* Compute the addresses of all registers saved in this frame. */
1198 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__ + 1; ++i)
1199 switch (fs->regs.how[i])
1201 case REG_UNSAVED:
1202 case REG_UNDEFINED:
1203 /* If the value depends on an augmenter, then there is no processing
1204 to do here, and the value computation should be delayed until the
1205 architecture handler computes the value correctly based on the
1206 augmenter information. */
1207 case REG_ARCHEXT:
1208 break;
1210 case REG_SAVED_OFFSET:
1211 _Unwind_SetGRPtr (context, i,
1212 (void *) (cfa + fs->regs.reg[i].loc.offset));
1213 break;
1215 case REG_SAVED_REG:
1216 if (_Unwind_GRByValue (&orig_context, fs->regs.reg[i].loc.reg))
1217 _Unwind_SetGRValue (context, i,
1218 _Unwind_GetGR (&orig_context,
1219 fs->regs.reg[i].loc.reg));
1220 else
1221 _Unwind_SetGRPtr (context, i,
1222 _Unwind_GetGRPtr (&orig_context,
1223 fs->regs.reg[i].loc.reg));
1224 break;
1226 case REG_SAVED_EXP:
1228 const unsigned char *exp = fs->regs.reg[i].loc.exp;
1229 _uleb128_t len;
1230 _Unwind_Ptr val;
1232 exp = read_uleb128 (exp, &len);
1233 val = execute_stack_op (exp, exp + len, &orig_context,
1234 (_Unwind_Ptr) cfa);
1235 _Unwind_SetGRPtr (context, i, (void *) val);
1237 break;
1239 case REG_SAVED_VAL_OFFSET:
1240 _Unwind_SetGRValue (context, i,
1241 (_Unwind_Internal_Ptr)
1242 (cfa + fs->regs.reg[i].loc.offset));
1243 break;
1245 case REG_SAVED_VAL_EXP:
1247 const unsigned char *exp = fs->regs.reg[i].loc.exp;
1248 _uleb128_t len;
1249 _Unwind_Ptr val;
1251 exp = read_uleb128 (exp, &len);
1252 val = execute_stack_op (exp, exp + len, &orig_context,
1253 (_Unwind_Ptr) cfa);
1254 _Unwind_SetGRValue (context, i, val);
1256 break;
1259 _Unwind_SetSignalFrame (context, fs->signal_frame);
1261 #ifdef MD_FROB_UPDATE_CONTEXT
1262 MD_FROB_UPDATE_CONTEXT (context, fs);
1263 #endif
1266 /* CONTEXT describes the unwind state for a frame, and FS describes the FDE
1267 of its caller. Update CONTEXT to refer to the caller as well. Note
1268 that the args_size and lsda members are not updated here, but later in
1269 uw_frame_state_for. */
1271 static void
1272 uw_update_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1274 uw_update_context_1 (context, fs);
1276 /* In general this unwinder doesn't make any distinction between
1277 undefined and same_value rule. Call-saved registers are assumed
1278 to have same_value rule by default and explicit undefined
1279 rule is handled like same_value. The only exception is
1280 DW_CFA_undefined on retaddr_column which is supposed to
1281 mark outermost frame in DWARF 3. */
1282 if (fs->regs.how[DWARF_REG_TO_UNWIND_COLUMN (fs->retaddr_column)]
1283 == REG_UNDEFINED)
1284 /* uw_frame_state_for uses context->ra == 0 check to find outermost
1285 stack frame. */
1286 context->ra = 0;
1287 else
1289 /* Compute the return address now, since the return address column
1290 can change from frame to frame. */
1291 void *ret_addr;
1292 #ifdef MD_DEMANGLE_RETURN_ADDR
1293 _Unwind_Word ra = _Unwind_GetGR (context, fs->retaddr_column);
1294 ret_addr = MD_DEMANGLE_RETURN_ADDR (context, fs, ra);
1295 #else
1296 ret_addr = _Unwind_GetPtr (context, fs->retaddr_column);
1297 #endif
1298 context->ra = __builtin_extract_return_addr (ret_addr);
1302 static void
1303 uw_advance_context (struct _Unwind_Context *context, _Unwind_FrameState *fs)
1305 uw_update_context (context, fs);
1308 /* Fill in CONTEXT for top-of-stack. The only valid registers at this
1309 level will be the return address and the CFA. */
1311 #define uw_init_context(CONTEXT) \
1312 do \
1314 /* Do any necessary initialization to access arbitrary stack frames. \
1315 On the SPARC, this means flushing the register windows. */ \
1316 __builtin_unwind_init (); \
1317 uw_init_context_1 (CONTEXT, __builtin_dwarf_cfa (), \
1318 __builtin_return_address (0)); \
1320 while (0)
1322 static inline void
1323 init_dwarf_reg_size_table (void)
1325 __builtin_init_dwarf_reg_size_table (dwarf_reg_size_table);
1328 static void __attribute__((noinline))
1329 uw_init_context_1 (struct _Unwind_Context *context,
1330 void *outer_cfa, void *outer_ra)
1332 void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
1333 _Unwind_FrameState fs;
1334 _Unwind_SpTmp sp_slot;
1335 _Unwind_Reason_Code code;
1337 memset (context, 0, sizeof (struct _Unwind_Context));
1338 context->ra = ra;
1339 if (!ASSUME_EXTENDED_UNWIND_CONTEXT)
1340 context->flags = EXTENDED_CONTEXT_BIT;
1342 code = uw_frame_state_for (context, &fs);
1343 gcc_assert (code == _URC_NO_REASON);
1345 #if __GTHREADS
1347 static __gthread_once_t once_regsizes = __GTHREAD_ONCE_INIT;
1348 if (__gthread_once (&once_regsizes, init_dwarf_reg_size_table) != 0
1349 && dwarf_reg_size_table[0] == 0)
1350 init_dwarf_reg_size_table ();
1352 #else
1353 if (dwarf_reg_size_table[0] == 0)
1354 init_dwarf_reg_size_table ();
1355 #endif
1357 /* Force the frame state to use the known cfa value. */
1358 _Unwind_SetSpColumn (context, outer_cfa, &sp_slot);
1359 fs.regs.cfa_how = CFA_REG_OFFSET;
1360 fs.regs.cfa_reg = __builtin_dwarf_sp_column ();
1361 fs.regs.cfa_offset = 0;
1363 uw_update_context_1 (context, &fs);
1365 /* If the return address column was saved in a register in the
1366 initialization context, then we can't see it in the given
1367 call frame data. So have the initialization context tell us. */
1368 context->ra = __builtin_extract_return_addr (outer_ra);
1371 static void _Unwind_DebugHook (void *, void *)
1372 __attribute__ ((__noinline__, __used__, __noclone__));
1374 /* This function is called during unwinding. It is intended as a hook
1375 for a debugger to intercept exceptions. CFA is the CFA of the
1376 target frame. HANDLER is the PC to which control will be
1377 transferred. */
1378 static void
1379 _Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
1380 void *handler __attribute__ ((__unused__)))
1382 /* We only want to use stap probes starting with v3. Earlier
1383 versions added too much startup cost. */
1384 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
1385 STAP_PROBE2 (libgcc, unwind, cfa, handler);
1386 #else
1387 asm ("");
1388 #endif
1391 /* Install TARGET into CURRENT so that we can return to it. This is a
1392 macro because __builtin_eh_return must be invoked in the context of
1393 our caller. FRAMES is a number of frames to be unwind.
1394 _Unwind_Frames_Extra is a macro to do additional work during unwinding
1395 if needed, for example shadow stack pointer adjustment for Intel CET
1396 technology. */
1398 #define uw_install_context(CURRENT, TARGET, FRAMES) \
1399 do \
1401 long offset = uw_install_context_1 ((CURRENT), (TARGET)); \
1402 void *handler = __builtin_frob_return_addr ((TARGET)->ra); \
1403 _Unwind_DebugHook ((TARGET)->cfa, handler); \
1404 _Unwind_Frames_Extra (FRAMES); \
1405 __builtin_eh_return (offset, handler); \
1407 while (0)
1409 static long
1410 uw_install_context_1 (struct _Unwind_Context *current,
1411 struct _Unwind_Context *target)
1413 long i;
1414 _Unwind_SpTmp sp_slot;
1416 /* If the target frame does not have a saved stack pointer,
1417 then set up the target's CFA. */
1418 if (!_Unwind_GetGRPtr (target, __builtin_dwarf_sp_column ()))
1419 _Unwind_SetSpColumn (target, target->cfa, &sp_slot);
1421 for (i = 0; i < __LIBGCC_DWARF_FRAME_REGISTERS__; ++i)
1423 void *c = (void *) (_Unwind_Internal_Ptr) current->reg[i];
1424 void *t = (void *) (_Unwind_Internal_Ptr)target->reg[i];
1426 #ifdef MD_FRAME_LOCAL_REGISTER_P
1427 if (MD_FRAME_LOCAL_REGISTER_P (i))
1428 continue;
1429 #endif
1431 gcc_assert (current->by_value[i] == 0);
1432 if (target->by_value[i] && c)
1434 _Unwind_Word w;
1435 _Unwind_Ptr p;
1436 if (dwarf_reg_size_table[i] == sizeof (_Unwind_Word))
1438 w = (_Unwind_Internal_Ptr) t;
1439 memcpy (c, &w, sizeof (_Unwind_Word));
1441 else
1443 gcc_assert (dwarf_reg_size_table[i] == sizeof (_Unwind_Ptr));
1444 p = (_Unwind_Internal_Ptr) t;
1445 memcpy (c, &p, sizeof (_Unwind_Ptr));
1448 else if (t && c && t != c)
1449 memcpy (c, t, dwarf_reg_size_table[i]);
1452 /* If the current frame doesn't have a saved stack pointer, then we
1453 need to rely on EH_RETURN_STACKADJ_RTX to get our target stack
1454 pointer value reloaded. */
1455 if (!_Unwind_GetGRPtr (current, __builtin_dwarf_sp_column ()))
1457 void *target_cfa;
1459 target_cfa = _Unwind_GetPtr (target, __builtin_dwarf_sp_column ());
1461 /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
1462 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
1463 return target_cfa - current->cfa + target->args_size;
1464 else
1465 return current->cfa - target_cfa - target->args_size;
1467 return 0;
1470 static inline _Unwind_Ptr
1471 uw_identify_context (struct _Unwind_Context *context)
1473 /* The CFA is not sufficient to disambiguate the context of a function
1474 interrupted by a signal before establishing its frame and the context
1475 of the signal itself. */
1476 if (__LIBGCC_STACK_GROWS_DOWNWARD__)
1477 return _Unwind_GetCFA (context) - _Unwind_IsSignalFrame (context);
1478 else
1479 return _Unwind_GetCFA (context) + _Unwind_IsSignalFrame (context);
1483 #include "unwind.inc"
1485 #if defined (USE_GAS_SYMVER) && defined (SHARED) && defined (USE_LIBUNWIND_EXCEPTIONS)
1486 alias (_Unwind_Backtrace);
1487 alias (_Unwind_DeleteException);
1488 alias (_Unwind_FindEnclosingFunction);
1489 alias (_Unwind_ForcedUnwind);
1490 alias (_Unwind_GetDataRelBase);
1491 alias (_Unwind_GetTextRelBase);
1492 alias (_Unwind_GetCFA);
1493 alias (_Unwind_GetGR);
1494 alias (_Unwind_GetIP);
1495 alias (_Unwind_GetLanguageSpecificData);
1496 alias (_Unwind_GetRegionStart);
1497 alias (_Unwind_RaiseException);
1498 alias (_Unwind_Resume);
1499 alias (_Unwind_Resume_or_Rethrow);
1500 alias (_Unwind_SetGR);
1501 alias (_Unwind_SetIP);
1502 #endif
1504 #endif /* !USING_SJLJ_EXCEPTIONS */