1 /* Subroutines needed for unwinding stack frames for exception handling. */
2 /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Jason Merrill <jason@cygnus.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
21 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
22 WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 You should have received a copy of the GNU General Public License
27 along with GCC; see the file COPYING. If not, write to the Free
28 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
35 #define NO_BASE_OF_ENCODED_VALUE
36 #include "unwind-pe.h"
37 #include "unwind-dw2-fde.h"
40 /* The unseen_objects list contains objects that have been registered
41 but not yet categorized in any way. The seen_objects list has had
42 it's pc_begin and count fields initialized at minimum, and is sorted
43 by decreasing value of pc_begin. */
44 static struct object
*unseen_objects
;
45 static struct object
*seen_objects
;
47 #ifdef __GTHREAD_MUTEX_INIT
48 static __gthread_mutex_t object_mutex
= __GTHREAD_MUTEX_INIT
;
50 static __gthread_mutex_t object_mutex
;
53 #ifdef __GTHREAD_MUTEX_INIT_FUNCTION
55 init_object_mutex (void)
57 __GTHREAD_MUTEX_INIT_FUNCTION (&object_mutex
);
61 init_object_mutex_once (void)
63 static __gthread_once_t once
= __GTHREAD_ONCE_INIT
;
64 __gthread_once (&once
, init_object_mutex
);
67 #define init_object_mutex_once()
70 /* Called from crtbegin.o to register the unwind info for an object. */
73 __register_frame_info_bases (void *begin
, struct object
*ob
,
74 void *tbase
, void *dbase
)
76 /* If .eh_frame is empty, don't register at all. */
77 if (*(uword
*)begin
== 0)
80 ob
->pc_begin
= (void *)-1;
85 ob
->s
.b
.encoding
= DW_EH_PE_omit
;
87 init_object_mutex_once ();
88 __gthread_mutex_lock (&object_mutex
);
90 ob
->next
= unseen_objects
;
93 __gthread_mutex_unlock (&object_mutex
);
97 __register_frame_info (void *begin
, struct object
*ob
)
99 __register_frame_info_bases (begin
, ob
, 0, 0);
103 __register_frame (void *begin
)
107 /* If .eh_frame is empty, don't register at all. */
108 if (*(uword
*)begin
== 0)
111 ob
= (struct object
*) malloc (sizeof (struct object
));
112 __register_frame_info (begin
, ob
);
115 /* Similar, but BEGIN is actually a pointer to a table of unwind entries
116 for different translation units. Called from the file generated by
120 __register_frame_info_table_bases (void *begin
, struct object
*ob
,
121 void *tbase
, void *dbase
)
123 ob
->pc_begin
= (void *)-1;
128 ob
->s
.b
.from_array
= 1;
129 ob
->s
.b
.encoding
= DW_EH_PE_omit
;
131 init_object_mutex_once ();
132 __gthread_mutex_lock (&object_mutex
);
134 ob
->next
= unseen_objects
;
137 __gthread_mutex_unlock (&object_mutex
);
141 __register_frame_info_table (void *begin
, struct object
*ob
)
143 __register_frame_info_table_bases (begin
, ob
, 0, 0);
147 __register_frame_table (void *begin
)
149 struct object
*ob
= (struct object
*) malloc (sizeof (struct object
));
150 __register_frame_info_table (begin
, ob
);
153 /* Called from crtbegin.o to deregister the unwind info for an object. */
154 /* ??? Glibc has for a while now exported __register_frame_info and
155 __deregister_frame_info. If we call __register_frame_info_bases
156 from crtbegin (wherein it is declared weak), and this object does
157 not get pulled from libgcc.a for other reasons, then the
158 invocation of __deregister_frame_info will be resolved from glibc.
159 Since the registration did not happen there, we'll abort.
161 Therefore, declare a new deregistration entry point that does the
162 exact same thing, but will resolve to the same library as
163 implements __register_frame_info_bases. */
166 __deregister_frame_info_bases (void *begin
)
169 struct object
*ob
= 0;
171 /* If .eh_frame is empty, we haven't registered. */
172 if (*(uword
*)begin
== 0)
175 init_object_mutex_once ();
176 __gthread_mutex_lock (&object_mutex
);
178 for (p
= &unseen_objects
; *p
; p
= &(*p
)->next
)
179 if ((*p
)->u
.single
== begin
)
186 for (p
= &seen_objects
; *p
; p
= &(*p
)->next
)
187 if ((*p
)->s
.b
.sorted
)
189 if ((*p
)->u
.sort
->orig_data
== begin
)
199 if ((*p
)->u
.single
== begin
)
207 __gthread_mutex_unlock (&object_mutex
);
211 __gthread_mutex_unlock (&object_mutex
);
216 __deregister_frame_info (void *begin
)
218 return __deregister_frame_info_bases (begin
);
222 __deregister_frame (void *begin
)
224 /* If .eh_frame is empty, we haven't registered. */
225 if (*(uword
*)begin
!= 0)
226 free (__deregister_frame_info (begin
));
230 /* Like base_of_encoded_value, but take the base from a struct object
231 instead of an _Unwind_Context. */
234 base_from_object (unsigned char encoding
, struct object
*ob
)
236 if (encoding
== DW_EH_PE_omit
)
239 switch (encoding
& 0x70)
241 case DW_EH_PE_absptr
:
243 case DW_EH_PE_aligned
:
246 case DW_EH_PE_textrel
:
247 return (_Unwind_Ptr
) ob
->tbase
;
248 case DW_EH_PE_datarel
:
249 return (_Unwind_Ptr
) ob
->dbase
;
254 /* Return the FDE pointer encoding from the CIE. */
255 /* ??? This is a subset of extract_cie_info from unwind-dw2.c. */
258 get_cie_encoding (struct dwarf_cie
*cie
)
260 const unsigned char *aug
, *p
;
265 aug
= cie
->augmentation
;
267 return DW_EH_PE_absptr
;
269 p
= aug
+ strlen (aug
) + 1; /* Skip the augmentation string. */
270 p
= read_uleb128 (p
, &utmp
); /* Skip code alignment. */
271 p
= read_sleb128 (p
, &stmp
); /* Skip data alignment. */
272 p
++; /* Skip return address column. */
274 aug
++; /* Skip 'z' */
275 p
= read_uleb128 (p
, &utmp
); /* Skip augmentation length. */
278 /* This is what we're looking for. */
281 /* Personality encoding and pointer. */
282 else if (*aug
== 'P')
284 /* ??? Avoid dereferencing indirect pointers, since we're
285 faking the base address. Gotta keep DW_EH_PE_aligned
287 p
= read_encoded_value_with_base (*p
& 0x7F, 0, p
+ 1, &dummy
);
290 else if (*aug
== 'L')
292 /* Otherwise end of string, or unknown augmentation. */
294 return DW_EH_PE_absptr
;
300 get_fde_encoding (struct dwarf_fde
*f
)
302 return get_cie_encoding (get_cie (f
));
306 /* Sorting an array of FDEs by address.
307 (Ideally we would have the linker sort the FDEs so we don't have to do
308 it at run time. But the linkers are not yet prepared for this.) */
310 /* Comparison routines. Three variants of increasing complexity. */
313 fde_unencoded_compare (struct object
*ob
__attribute__((unused
)),
316 _Unwind_Ptr x_ptr
= *(_Unwind_Ptr
*) x
->pc_begin
;
317 _Unwind_Ptr y_ptr
= *(_Unwind_Ptr
*) y
->pc_begin
;
327 fde_single_encoding_compare (struct object
*ob
, fde
*x
, fde
*y
)
329 _Unwind_Ptr base
, x_ptr
, y_ptr
;
331 base
= base_from_object (ob
->s
.b
.encoding
, ob
);
332 read_encoded_value_with_base (ob
->s
.b
.encoding
, base
, x
->pc_begin
, &x_ptr
);
333 read_encoded_value_with_base (ob
->s
.b
.encoding
, base
, y
->pc_begin
, &y_ptr
);
343 fde_mixed_encoding_compare (struct object
*ob
, fde
*x
, fde
*y
)
345 int x_encoding
, y_encoding
;
346 _Unwind_Ptr x_ptr
, y_ptr
;
348 x_encoding
= get_fde_encoding (x
);
349 read_encoded_value_with_base (x_encoding
, base_from_object (x_encoding
, ob
),
350 x
->pc_begin
, &x_ptr
);
352 y_encoding
= get_fde_encoding (y
);
353 read_encoded_value_with_base (y_encoding
, base_from_object (y_encoding
, ob
),
354 y
->pc_begin
, &y_ptr
);
363 typedef int (*fde_compare_t
) (struct object
*, fde
*, fde
*);
366 /* This is a special mix of insertion sort and heap sort, optimized for
367 the data sets that actually occur. They look like
368 101 102 103 127 128 105 108 110 190 111 115 119 125 160 126 129 130.
369 I.e. a linearly increasing sequence (coming from functions in the text
370 section), with additionally a few unordered elements (coming from functions
371 in gnu_linkonce sections) whose values are higher than the values in the
372 surrounding linear sequence (but not necessarily higher than the values
373 at the end of the linear sequence!).
374 The worst-case total run time is O(N) + O(n log (n)), where N is the
375 total number of FDEs and n is the number of erratic ones. */
377 struct fde_accumulator
379 struct fde_vector
*linear
;
380 struct fde_vector
*erratic
;
384 start_fde_sort (struct fde_accumulator
*accu
, size_t count
)
390 size
= sizeof (struct fde_vector
) + sizeof (fde
*) * count
;
391 if ((accu
->linear
= (struct fde_vector
*) malloc (size
)))
393 accu
->linear
->count
= 0;
394 if ((accu
->erratic
= (struct fde_vector
*) malloc (size
)))
395 accu
->erratic
->count
= 0;
403 fde_insert (struct fde_accumulator
*accu
, fde
*this_fde
)
406 accu
->linear
->array
[accu
->linear
->count
++] = this_fde
;
409 /* Split LINEAR into a linear sequence with low values and an erratic
410 sequence with high values, put the linear one (of longest possible
411 length) into LINEAR and the erratic one into ERRATIC. This is O(N).
413 Because the longest linear sequence we are trying to locate within the
414 incoming LINEAR array can be interspersed with (high valued) erratic
415 entries. We construct a chain indicating the sequenced entries.
416 To avoid having to allocate this chain, we overlay it onto the space of
417 the ERRATIC array during construction. A final pass iterates over the
418 chain to determine what should be placed in the ERRATIC array, and
419 what is the linear sequence. This overlay is safe from aliasing. */
422 fde_split (struct object
*ob
, fde_compare_t fde_compare
,
423 struct fde_vector
*linear
, struct fde_vector
*erratic
)
426 size_t count
= linear
->count
;
427 fde
**chain_end
= &marker
;
430 /* This should optimize out, but it is wise to make sure this assumption
431 is correct. Should these have different sizes, we cannot cast between
432 them and the overlaying onto ERRATIC will not work. */
433 if (sizeof (fde
*) != sizeof (fde
**))
436 for (i
= 0; i
< count
; i
++)
440 for (probe
= chain_end
;
441 probe
!= &marker
&& fde_compare (ob
, linear
->array
[i
], *probe
) < 0;
444 chain_end
= (fde
**)erratic
->array
[probe
- linear
->array
];
445 erratic
->array
[probe
- linear
->array
] = NULL
;
447 erratic
->array
[i
] = (fde
*)chain_end
;
448 chain_end
= &linear
->array
[i
];
451 /* Each entry in LINEAR which is part of the linear sequence we have
452 discovered will correspond to a non-NULL entry in the chain we built in
453 the ERRATIC array. */
454 for (i
= j
= k
= 0; i
< count
; i
++)
455 if (erratic
->array
[i
])
456 linear
->array
[j
++] = linear
->array
[i
];
458 erratic
->array
[k
++] = linear
->array
[i
];
463 /* This is O(n log(n)). BSD/OS defines heapsort in stdlib.h, so we must
464 use a name that does not conflict. */
467 frame_heapsort (struct object
*ob
, fde_compare_t fde_compare
,
468 struct fde_vector
*erratic
)
470 /* For a description of this algorithm, see:
471 Samuel P. Harbison, Guy L. Steele Jr.: C, a reference manual, 2nd ed.,
473 fde
** a
= erratic
->array
;
474 /* A portion of the array is called a "heap" if for all i>=0:
475 If i and 2i+1 are valid indices, then a[i] >= a[2i+1].
476 If i and 2i+2 are valid indices, then a[i] >= a[2i+2]. */
477 #define SWAP(x,y) do { fde * tmp = x; x = y; y = tmp; } while (0)
478 size_t n
= erratic
->count
;
484 /* Invariant: a[m..n-1] is a heap. */
486 for (i
= m
; 2*i
+1 < n
; )
489 && fde_compare (ob
, a
[2*i
+2], a
[2*i
+1]) > 0
490 && fde_compare (ob
, a
[2*i
+2], a
[i
]) > 0)
492 SWAP (a
[i
], a
[2*i
+2]);
495 else if (fde_compare (ob
, a
[2*i
+1], a
[i
]) > 0)
497 SWAP (a
[i
], a
[2*i
+1]);
506 /* Invariant: a[0..n-1] is a heap. */
509 for (i
= 0; 2*i
+1 < n
; )
512 && fde_compare (ob
, a
[2*i
+2], a
[2*i
+1]) > 0
513 && fde_compare (ob
, a
[2*i
+2], a
[i
]) > 0)
515 SWAP (a
[i
], a
[2*i
+2]);
518 else if (fde_compare (ob
, a
[2*i
+1], a
[i
]) > 0)
520 SWAP (a
[i
], a
[2*i
+1]);
530 /* Merge V1 and V2, both sorted, and put the result into V1. */
532 fde_merge (struct object
*ob
, fde_compare_t fde_compare
,
533 struct fde_vector
*v1
, struct fde_vector
*v2
)
544 fde2
= v2
->array
[i2
];
545 while (i1
> 0 && fde_compare (ob
, v1
->array
[i1
-1], fde2
) > 0)
547 v1
->array
[i1
+i2
] = v1
->array
[i1
-1];
550 v1
->array
[i1
+i2
] = fde2
;
552 v1
->count
+= v2
->count
;
557 end_fde_sort (struct object
*ob
, struct fde_accumulator
*accu
, size_t count
)
559 fde_compare_t fde_compare
;
561 if (accu
->linear
&& accu
->linear
->count
!= count
)
564 if (ob
->s
.b
.mixed_encoding
)
565 fde_compare
= fde_mixed_encoding_compare
;
566 else if (ob
->s
.b
.encoding
== DW_EH_PE_absptr
)
567 fde_compare
= fde_unencoded_compare
;
569 fde_compare
= fde_single_encoding_compare
;
573 fde_split (ob
, fde_compare
, accu
->linear
, accu
->erratic
);
574 if (accu
->linear
->count
+ accu
->erratic
->count
!= count
)
576 frame_heapsort (ob
, fde_compare
, accu
->erratic
);
577 fde_merge (ob
, fde_compare
, accu
->linear
, accu
->erratic
);
578 free (accu
->erratic
);
582 /* We've not managed to malloc an erratic array,
583 so heap sort in the linear one. */
584 frame_heapsort (ob
, fde_compare
, accu
->linear
);
589 /* Update encoding, mixed_encoding, and pc_begin for OB for the
590 fde array beginning at THIS_FDE. Return the number of fdes
591 encountered along the way. */
594 classify_object_over_fdes (struct object
*ob
, fde
*this_fde
)
596 struct dwarf_cie
*last_cie
= 0;
598 int encoding
= DW_EH_PE_absptr
;
599 _Unwind_Ptr base
= 0;
601 for (; this_fde
->length
!= 0; this_fde
= next_fde (this_fde
))
603 struct dwarf_cie
*this_cie
;
604 _Unwind_Ptr mask
, pc_begin
;
607 if (this_fde
->CIE_delta
== 0)
610 /* Determine the encoding for this FDE. Note mixed encoded
611 objects for later. */
612 this_cie
= get_cie (this_fde
);
613 if (this_cie
!= last_cie
)
616 encoding
= get_cie_encoding (this_cie
);
617 base
= base_from_object (encoding
, ob
);
618 if (ob
->s
.b
.encoding
== DW_EH_PE_omit
)
619 ob
->s
.b
.encoding
= encoding
;
620 else if (ob
->s
.b
.encoding
!= encoding
)
621 ob
->s
.b
.mixed_encoding
= 1;
624 read_encoded_value_with_base (encoding
, base
, this_fde
->pc_begin
,
627 /* Take care to ignore link-once functions that were removed.
628 In these cases, the function address will be NULL, but if
629 the encoding is smaller than a pointer a true NULL may not
630 be representable. Assume 0 in the representable bits is NULL. */
631 mask
= size_of_encoded_value (encoding
);
632 if (mask
< sizeof (void *))
633 mask
= (1L << (mask
<< 3)) - 1;
637 if ((pc_begin
& mask
) == 0)
641 if ((void *)pc_begin
< ob
->pc_begin
)
642 ob
->pc_begin
= (void *)pc_begin
;
649 add_fdes (struct object
*ob
, struct fde_accumulator
*accu
, fde
*this_fde
)
651 struct dwarf_cie
*last_cie
= 0;
652 int encoding
= ob
->s
.b
.encoding
;
653 _Unwind_Ptr base
= base_from_object (ob
->s
.b
.encoding
, ob
);
655 for (; this_fde
->length
!= 0; this_fde
= next_fde (this_fde
))
657 struct dwarf_cie
*this_cie
;
660 if (this_fde
->CIE_delta
== 0)
663 if (ob
->s
.b
.mixed_encoding
)
665 /* Determine the encoding for this FDE. Note mixed encoded
666 objects for later. */
667 this_cie
= get_cie (this_fde
);
668 if (this_cie
!= last_cie
)
671 encoding
= get_cie_encoding (this_cie
);
672 base
= base_from_object (encoding
, ob
);
676 if (encoding
== DW_EH_PE_absptr
)
678 if (*(_Unwind_Ptr
*)this_fde
->pc_begin
== 0)
683 _Unwind_Ptr pc_begin
, mask
;
685 read_encoded_value_with_base (encoding
, base
, this_fde
->pc_begin
,
688 /* Take care to ignore link-once functions that were removed.
689 In these cases, the function address will be NULL, but if
690 the encoding is smaller than a pointer a true NULL may not
691 be representable. Assume 0 in the representable bits is NULL. */
692 mask
= size_of_encoded_value (encoding
);
693 if (mask
< sizeof (void *))
694 mask
= (1L << (mask
<< 3)) - 1;
698 if ((pc_begin
& mask
) == 0)
702 fde_insert (accu
, this_fde
);
706 /* Set up a sorted array of pointers to FDEs for a loaded object. We
707 count up the entries before allocating the array because it's likely to
708 be faster. We can be called multiple times, should we have failed to
709 allocate a sorted fde array on a previous occasion. */
712 init_object (struct object
* ob
)
714 struct fde_accumulator accu
;
717 count
= ob
->s
.b
.count
;
720 if (ob
->s
.b
.from_array
)
722 fde
**p
= ob
->u
.array
;
723 for (count
= 0; *p
; ++p
)
724 count
+= classify_object_over_fdes (ob
, *p
);
727 count
= classify_object_over_fdes (ob
, ob
->u
.single
);
729 /* The count field we have in the main struct object is somewhat
730 limited, but should suffice for virtually all cases. If the
731 counted value doesn't fit, re-write a zero. The worst that
732 happens is that we re-count next time -- admittedly non-trivial
733 in that this implies some 2M fdes, but at least we function. */
734 ob
->s
.b
.count
= count
;
735 if (ob
->s
.b
.count
!= count
)
739 if (!start_fde_sort (&accu
, count
))
742 if (ob
->s
.b
.from_array
)
745 for (p
= ob
->u
.array
; *p
; ++p
)
746 add_fdes (ob
, &accu
, *p
);
749 add_fdes (ob
, &accu
, ob
->u
.single
);
751 end_fde_sort (ob
, &accu
, count
);
753 /* Save the original fde pointer, since this is the key by which the
754 DSO will deregister the object. */
755 accu
.linear
->orig_data
= ob
->u
.single
;
756 ob
->u
.sort
= accu
.linear
;
761 /* A linear search through a set of FDEs for the given PC. This is
762 used when there was insufficient memory to allocate and sort an
766 linear_search_fdes (struct object
*ob
, fde
*this_fde
, void *pc
)
768 struct dwarf_cie
*last_cie
= 0;
769 int encoding
= ob
->s
.b
.encoding
;
770 _Unwind_Ptr base
= base_from_object (ob
->s
.b
.encoding
, ob
);
772 for (; this_fde
->length
!= 0; this_fde
= next_fde (this_fde
))
774 struct dwarf_cie
*this_cie
;
775 _Unwind_Ptr pc_begin
, pc_range
;
778 if (this_fde
->CIE_delta
== 0)
781 if (ob
->s
.b
.mixed_encoding
)
783 /* Determine the encoding for this FDE. Note mixed encoded
784 objects for later. */
785 this_cie
= get_cie (this_fde
);
786 if (this_cie
!= last_cie
)
789 encoding
= get_cie_encoding (this_cie
);
790 base
= base_from_object (encoding
, ob
);
794 if (encoding
== DW_EH_PE_absptr
)
796 pc_begin
= ((_Unwind_Ptr
*)this_fde
->pc_begin
)[0];
797 pc_range
= ((_Unwind_Ptr
*)this_fde
->pc_begin
)[1];
806 p
= read_encoded_value_with_base (encoding
, base
,
807 this_fde
->pc_begin
, &pc_begin
);
808 read_encoded_value_with_base (encoding
& 0x0F, 0, p
, &pc_range
);
810 /* Take care to ignore link-once functions that were removed.
811 In these cases, the function address will be NULL, but if
812 the encoding is smaller than a pointer a true NULL may not
813 be representable. Assume 0 in the representable bits is NULL. */
814 mask
= size_of_encoded_value (encoding
);
815 if (mask
< sizeof (void *))
816 mask
= (1L << (mask
<< 3)) - 1;
820 if ((pc_begin
& mask
) == 0)
824 if ((_Unwind_Ptr
)pc
- pc_begin
< pc_range
)
831 /* Binary search for an FDE containing the given PC. Here are three
832 implementations of increasing complexity. */
835 binary_search_unencoded_fdes (struct object
*ob
, void *pc
)
837 struct fde_vector
*vec
= ob
->u
.sort
;
840 for (lo
= 0, hi
= vec
->count
; lo
< hi
; )
842 size_t i
= (lo
+ hi
) / 2;
843 fde
*f
= vec
->array
[i
];
847 pc_begin
= ((void **)f
->pc_begin
)[0];
848 pc_range
= ((uaddr
*)f
->pc_begin
)[1];
852 else if (pc
>= pc_begin
+ pc_range
)
862 binary_search_single_encoding_fdes (struct object
*ob
, void *pc
)
864 struct fde_vector
*vec
= ob
->u
.sort
;
865 int encoding
= ob
->s
.b
.encoding
;
866 _Unwind_Ptr base
= base_from_object (encoding
, ob
);
869 for (lo
= 0, hi
= vec
->count
; lo
< hi
; )
871 size_t i
= (lo
+ hi
) / 2;
872 fde
*f
= vec
->array
[i
];
873 _Unwind_Ptr pc_begin
, pc_range
;
876 p
= read_encoded_value_with_base (encoding
, base
, f
->pc_begin
,
878 read_encoded_value_with_base (encoding
& 0x0F, 0, p
, &pc_range
);
880 if ((_Unwind_Ptr
)pc
< pc_begin
)
882 else if ((_Unwind_Ptr
)pc
>= pc_begin
+ pc_range
)
892 binary_search_mixed_encoding_fdes (struct object
*ob
, void *pc
)
894 struct fde_vector
*vec
= ob
->u
.sort
;
897 for (lo
= 0, hi
= vec
->count
; lo
< hi
; )
899 size_t i
= (lo
+ hi
) / 2;
900 fde
*f
= vec
->array
[i
];
901 _Unwind_Ptr pc_begin
, pc_range
;
905 encoding
= get_fde_encoding (f
);
906 p
= read_encoded_value_with_base (encoding
,
907 base_from_object (encoding
, ob
),
908 f
->pc_begin
, &pc_begin
);
909 read_encoded_value_with_base (encoding
& 0x0F, 0, p
, &pc_range
);
911 if ((_Unwind_Ptr
)pc
< pc_begin
)
913 else if ((_Unwind_Ptr
)pc
>= pc_begin
+ pc_range
)
923 search_object (struct object
* ob
, void *pc
)
925 /* If the data hasn't been sorted, try to do this now. We may have
926 more memory available than last time we tried. */
927 if (! ob
->s
.b
.sorted
)
931 /* Despite the above comment, the normal reason to get here is
932 that we've not processed this object before. A quick range
933 check is in order. */
934 if (pc
< ob
->pc_begin
)
940 if (ob
->s
.b
.mixed_encoding
)
941 return binary_search_mixed_encoding_fdes (ob
, pc
);
942 else if (ob
->s
.b
.encoding
== DW_EH_PE_absptr
)
943 return binary_search_unencoded_fdes (ob
, pc
);
945 return binary_search_single_encoding_fdes (ob
, pc
);
949 /* Long slow labourious linear search, cos we've no memory. */
950 if (ob
->s
.b
.from_array
)
953 for (p
= ob
->u
.array
; *p
; p
++)
955 fde
*f
= linear_search_fdes (ob
, *p
, pc
);
962 return linear_search_fdes (ob
, ob
->u
.single
, pc
);
967 _Unwind_Find_FDE (void *pc
, struct dwarf_eh_bases
*bases
)
972 init_object_mutex_once ();
973 __gthread_mutex_lock (&object_mutex
);
975 /* Linear search through the classified objects, to find the one
976 containing the pc. Note that pc_begin is sorted descending, and
977 we expect objects to be non-overlapping. */
978 for (ob
= seen_objects
; ob
; ob
= ob
->next
)
979 if (pc
>= ob
->pc_begin
)
981 f
= search_object (ob
, pc
);
987 /* Classify and search the objects we've not yet processed. */
988 while ((ob
= unseen_objects
))
992 unseen_objects
= ob
->next
;
993 f
= search_object (ob
, pc
);
995 /* Insert the object into the classified list. */
996 for (p
= &seen_objects
; *p
; p
= &(*p
)->next
)
997 if ((*p
)->pc_begin
< ob
->pc_begin
)
1007 __gthread_mutex_unlock (&object_mutex
);
1013 bases
->tbase
= ob
->tbase
;
1014 bases
->dbase
= ob
->dbase
;
1016 encoding
= ob
->s
.b
.encoding
;
1017 if (ob
->s
.b
.mixed_encoding
)
1018 encoding
= get_fde_encoding (f
);
1019 read_encoded_value_with_base (encoding
, base_from_object (encoding
, ob
),
1020 f
->pc_begin
, (_Unwind_Ptr
*)&bases
->func
);