1e3feeaa7Smatt /*-
2e3feeaa7Smatt * Copyright (c) 2013 The NetBSD Foundation, Inc.
3e3feeaa7Smatt * All rights reserved.
4e3feeaa7Smatt *
5e3feeaa7Smatt * This code is derived from software contributed to The NetBSD Foundation
6e3feeaa7Smatt * by Matt Thomas of 3am Software Foundry.
7e3feeaa7Smatt *
8e3feeaa7Smatt * Redistribution and use in source and binary forms, with or without
9e3feeaa7Smatt * modification, are permitted provided that the following conditions
10e3feeaa7Smatt * are met:
11e3feeaa7Smatt * 1. Redistributions of source code must retain the above copyright
12e3feeaa7Smatt * notice, this list of conditions and the following disclaimer.
13e3feeaa7Smatt * 2. Redistributions in binary form must reproduce the above copyright
14e3feeaa7Smatt * notice, this list of conditions and the following disclaimer in the
15e3feeaa7Smatt * documentation and/or other materials provided with the distribution.
16e3feeaa7Smatt *
17e3feeaa7Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18e3feeaa7Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19e3feeaa7Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20e3feeaa7Smatt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21e3feeaa7Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22e3feeaa7Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23e3feeaa7Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24e3feeaa7Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25e3feeaa7Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26e3feeaa7Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27e3feeaa7Smatt * POSSIBILITY OF SUCH DAMAGE.
28e3feeaa7Smatt */
29e3feeaa7Smatt
30e3feeaa7Smatt #include <sys/cdefs.h>
31e3feeaa7Smatt #ifndef lint
32*243b0cceSmatt __RCSID("$NetBSD: find_exidx.c,v 1.4 2014/08/10 23:35:27 matt Exp $");
33e3feeaa7Smatt #endif /* not lint */
34e3feeaa7Smatt
35e3feeaa7Smatt #include "debug.h"
36e3feeaa7Smatt #include "rtld.h"
37e3feeaa7Smatt
38*243b0cceSmatt #if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
39*243b0cceSmatt
40e3feeaa7Smatt _Unwind_Ptr
__gnu_Unwind_Find_exidx(_Unwind_Ptr pc,int * pcount)41e3feeaa7Smatt __gnu_Unwind_Find_exidx(_Unwind_Ptr pc, int * pcount)
42e3feeaa7Smatt {
43e3feeaa7Smatt const Obj_Entry *obj;
44e3feeaa7Smatt _Unwind_Ptr start = NULL;
45e3feeaa7Smatt int count = 0;
46e3feeaa7Smatt
47e3feeaa7Smatt dbg(("__gnu_Unwind_Find_exidx"));
48e3feeaa7Smatt
49e3feeaa7Smatt _rtld_shared_enter();
50e3feeaa7Smatt
51e3feeaa7Smatt vaddr_t va = (vaddr_t)pc;
52e3feeaa7Smatt for (obj = _rtld_objlist; obj != NULL; obj = obj->next) {
53e3feeaa7Smatt /*
54e3feeaa7Smatt * If the address we are looking for is inside this object,
55e3feeaa7Smatt * we've found the object to inspect.
56e3feeaa7Smatt */
57e3feeaa7Smatt if ((vaddr_t)obj->mapbase <= va
58e3feeaa7Smatt && va < (vaddr_t)obj->mapbase + obj->mapsize)
59e3feeaa7Smatt break;
60e3feeaa7Smatt }
61e3feeaa7Smatt
62e3feeaa7Smatt /*
63e3feeaa7Smatt * If we found an object and it has some exception data, we
64e3feeaa7Smatt * need to see if the address matches a PT_LOAD section.
65e3feeaa7Smatt */
66e3feeaa7Smatt if (obj != NULL && obj->exidx_start != NULL) {
67e4c78a68Smatt va -= (vaddr_t)obj->relocbase;
68e3feeaa7Smatt const Elf_Phdr *ph = obj->phdr;
69e3feeaa7Smatt const Elf_Phdr * const phlimit = ph + obj->phsize / sizeof(*ph);
70e3feeaa7Smatt for (; ph < phlimit; ph++) {
71e3feeaa7Smatt if (ph->p_type == PT_LOAD
72e3feeaa7Smatt && ph->p_vaddr <= va
73e3feeaa7Smatt && va < ph->p_vaddr + ph->p_memsz) {
74e3feeaa7Smatt count = obj->exidx_sz / 8;
75e3feeaa7Smatt start = obj->exidx_start;
76e3feeaa7Smatt break;
77e3feeaa7Smatt }
78e3feeaa7Smatt }
79e3feeaa7Smatt }
80e3feeaa7Smatt
81e3feeaa7Smatt _rtld_shared_exit();
82e3feeaa7Smatt
83e3feeaa7Smatt /*
84e3feeaa7Smatt * deal with the return values.
85e3feeaa7Smatt */
86e3feeaa7Smatt *pcount = count;
87e3feeaa7Smatt return start;
88e3feeaa7Smatt }
89*243b0cceSmatt
90*243b0cceSmatt #endif
91