2006-01-10 Roland McGrath <roland@redhat.com>
[glibc-ports.git] / sysdeps / arm / eabi / find_exidx.c
blob9e4f4012ff202693aa4135c7d1ababd7761453d0
1 /* Copyright (C) 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <link.h>
20 #include <unwind.h>
22 struct unw_eh_callback_data
24 _Unwind_Ptr pc;
25 _Unwind_Ptr exidx_start;
26 int exidx_len;
30 /* Callback to determins if the PC lies within an object, and remember the
31 location of the exception index table if it does. */
33 static int
34 find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr)
36 struct unw_eh_callback_data * data;
37 const ElfW(Phdr) *phdr;
38 int i;
39 int match;
40 _Unwind_Ptr load_base;
42 data = (struct unw_eh_callback_data *) ptr;
43 load_base = info->dlpi_addr;
44 phdr = info->dlpi_phdr;
46 match = 0;
47 for (i = info->dlpi_phnum; i > 0; i--, phdr++)
49 if (phdr->p_type == PT_LOAD)
51 _Unwind_Ptr vaddr = phdr->p_vaddr + load_base;
52 if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz)
53 match = 1;
55 else if (phdr->p_type == PT_ARM_EXIDX)
57 data->exidx_start = (_Unwind_Ptr) (phdr->p_vaddr + load_base);
58 data->exidx_len = phdr->p_memsz;
62 return match;
66 /* Find the exception index table containing PC. */
68 _Unwind_Ptr
69 __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount)
71 struct unw_eh_callback_data data;
73 data.pc = pc;
74 data.exidx_start = 0;
75 if (dl_iterate_phdr (find_exidx_callback, &data) <= 0)
76 return 0;
78 *pcount = data.exidx_len / 8;
79 return data.exidx_start;