Blame sysdeps/arm/find_exidx.c

Packit 6c4009
/* Copyright (C) 2005-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library.  If not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <link.h>
Packit 6c4009
#include <unwind.h>
Packit 6c4009
Packit 6c4009
struct unw_eh_callback_data
Packit 6c4009
{
Packit 6c4009
  _Unwind_Ptr pc;
Packit 6c4009
  _Unwind_Ptr exidx_start;
Packit 6c4009
  int exidx_len;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Callback to determins if the PC lies within an object, and remember the
Packit 6c4009
   location of the exception index table if it does.  */
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
find_exidx_callback (struct dl_phdr_info * info, size_t size, void * ptr)
Packit 6c4009
{
Packit 6c4009
  struct unw_eh_callback_data * data;
Packit 6c4009
  const ElfW(Phdr) *phdr;
Packit 6c4009
  int i;
Packit 6c4009
  int match;
Packit 6c4009
  _Unwind_Ptr load_base;
Packit 6c4009
Packit 6c4009
  data = (struct unw_eh_callback_data *) ptr;
Packit 6c4009
  load_base = info->dlpi_addr;
Packit 6c4009
  phdr = info->dlpi_phdr;
Packit 6c4009
Packit 6c4009
  match = 0;
Packit 6c4009
  for (i = info->dlpi_phnum; i > 0; i--, phdr++)
Packit 6c4009
    {
Packit 6c4009
      if (phdr->p_type == PT_LOAD)
Packit 6c4009
        {
Packit 6c4009
          _Unwind_Ptr vaddr = phdr->p_vaddr + load_base;
Packit 6c4009
          if (data->pc >= vaddr && data->pc < vaddr + phdr->p_memsz)
Packit 6c4009
            match = 1;
Packit 6c4009
        }
Packit 6c4009
      else if (phdr->p_type == PT_ARM_EXIDX)
Packit 6c4009
	{
Packit 6c4009
	  data->exidx_start = (_Unwind_Ptr) (phdr->p_vaddr + load_base);
Packit 6c4009
	  data->exidx_len = phdr->p_memsz;
Packit 6c4009
	}
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return match;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Find the exception index table containing PC.  */
Packit 6c4009
Packit 6c4009
_Unwind_Ptr
Packit 6c4009
__gnu_Unwind_Find_exidx (_Unwind_Ptr pc, int * pcount)
Packit 6c4009
{
Packit 6c4009
  struct unw_eh_callback_data data;
Packit 6c4009
Packit 6c4009
  data.pc = pc;
Packit 6c4009
  data.exidx_start = 0;
Packit 6c4009
  if (__dl_iterate_phdr (find_exidx_callback, &data) <= 0)
Packit 6c4009
    return 0;
Packit 6c4009
Packit 6c4009
  *pcount = data.exidx_len / 8;
Packit 6c4009
  return data.exidx_start;
Packit 6c4009
}