find_exidx.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* Copyright (C) 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <link.h>
  16. #include <unwind.h>
  17. struct unw_eh_callback_data
  18. {
  19. _Unwind_Ptr pc;
  20. _Unwind_Ptr exidx_start;
  21. int exidx_len;
  22. };
  23. /* Callback to determins if the PC lies within an object, and remember the
  24. location of the exception index table if it does. */
  25. static int
  26. find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr)
  27. {
  28. struct unw_eh_callback_data * data;
  29. const ElfW(Phdr) *phdr;
  30. int i;
  31. int match;
  32. _Unwind_Ptr load_base;
  33. data = (struct unw_eh_callback_data *) ptr;
  34. load_base = info->dlpi_addr;
  35. phdr = info->dlpi_phdr;
  36. match = 0;
  37. for (i = info->dlpi_phnum; i > 0; i--, phdr++)
  38. {
  39. if (phdr->p_type == PT_LOAD)
  40. {
  41. _Unwind_Ptr vaddr = phdr->p_vaddr + load_base;
  42. if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz)
  43. match = 1;
  44. }
  45. else if (phdr->p_type == PT_ARM_EXIDX)
  46. {
  47. data->exidx_start = (_Unwind_Ptr) (phdr->p_vaddr + load_base);
  48. data->exidx_len = phdr->p_memsz;
  49. }
  50. }
  51. return match;
  52. }
  53. /* Find the exception index table containing PC. */
  54. _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount);
  55. _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount)
  56. {
  57. struct unw_eh_callback_data data;
  58. data.pc = pc;
  59. data.exidx_start = 0;
  60. if (dl_iterate_phdr (find_exidx_callback, &data) <= 0)
  61. return 0;
  62. *pcount = data.exidx_len / 8;
  63. return data.exidx_start;
  64. }