Back to index

glibc  2.9
find_exidx.c
Go to the documentation of this file.
00001 /* Copyright (C) 2005, 2008 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <link.h>
00020 #include <unwind.h>
00021 
00022 struct unw_eh_callback_data
00023 {
00024   _Unwind_Ptr pc;
00025   _Unwind_Ptr exidx_start;
00026   int exidx_len;
00027 };
00028 
00029 
00030 /* Callback to determins if the PC lies within an object, and remember the
00031    location of the exception index table if it does.  */
00032 
00033 static int
00034 find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr)
00035 {
00036   struct unw_eh_callback_data * data;
00037   const ElfW(Phdr) *phdr;
00038   int i;
00039   int match;
00040   _Unwind_Ptr load_base;
00041 
00042   data = (struct unw_eh_callback_data *) ptr;
00043   load_base = info->dlpi_addr;
00044   phdr = info->dlpi_phdr;
00045 
00046   match = 0;
00047   for (i = info->dlpi_phnum; i > 0; i--, phdr++)
00048     {
00049       if (phdr->p_type == PT_LOAD)
00050         {
00051           _Unwind_Ptr vaddr = phdr->p_vaddr + load_base;
00052           if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz)
00053             match = 1;
00054         }
00055       else if (phdr->p_type == PT_ARM_EXIDX)
00056        {
00057          data->exidx_start = (_Unwind_Ptr) (phdr->p_vaddr + load_base);
00058          data->exidx_len = phdr->p_memsz;
00059        }
00060     }
00061 
00062   return match;
00063 }
00064 
00065 
00066 /* Find the exception index table containing PC.  */
00067 
00068 _Unwind_Ptr
00069 __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount)
00070 {
00071   struct unw_eh_callback_data data;
00072 
00073   data.pc = pc;
00074   data.exidx_start = 0;
00075   if (__dl_iterate_phdr (find_exidx_callback, &data) <= 0)
00076     return 0;
00077 
00078   *pcount = data.exidx_len / 8;
00079   return data.exidx_start;
00080 }