find_exidx.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <link.h>
  15. #include <unwind.h>
  16. struct unw_eh_callback_data
  17. {
  18. _Unwind_Ptr pc;
  19. _Unwind_Ptr exidx_start;
  20. int exidx_len;
  21. };
  22. /* Callback to determins if the PC lies within an object, and remember the
  23. location of the exception index table if it does. */
  24. static int
  25. find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr)
  26. {
  27. struct unw_eh_callback_data * data;
  28. const ElfW(Phdr) *phdr;
  29. int i;
  30. int match;
  31. _Unwind_Ptr load_base;
  32. data = (struct unw_eh_callback_data *) ptr;
  33. load_base = info->dlpi_addr;
  34. phdr = info->dlpi_phdr;
  35. match = 0;
  36. for (i = info->dlpi_phnum; i > 0; i--, phdr++)
  37. {
  38. if (phdr->p_type == PT_LOAD)
  39. {
  40. _Unwind_Ptr vaddr = phdr->p_vaddr + load_base;
  41. if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz)
  42. match = 1;
  43. }
  44. else if (phdr->p_type == PT_ARM_EXIDX)
  45. {
  46. data->exidx_start = (_Unwind_Ptr) (phdr->p_vaddr + load_base);
  47. data->exidx_len = phdr->p_memsz;
  48. }
  49. }
  50. return match;
  51. }
  52. /* Find the exception index table containing PC. */
  53. _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount);
  54. _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount)
  55. {
  56. struct unw_eh_callback_data data;
  57. data.pc = pc;
  58. data.exidx_start = 0;
  59. if (dl_iterate_phdr (find_exidx_callback, &data) <= 0)
  60. return 0;
  61. *pcount = data.exidx_len / 8;
  62. return data.exidx_start;
  63. }