blob: 129238872b4c856b7b7213d7c3241090ec53f288 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/* Copyright (C) 2018 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <link.h>
#include <unwind.h>
#if __FDPIC__
#include <bits/elf-fdpic.h>
struct got_callback_data
{
_Unwind_Ptr pc;
_Unwind_Ptr got;
};
static __always_inline int
__dl_addr_in_loadaddr(void *p, struct elf32_fdpic_loadaddr loadaddr)
{
struct elf32_fdpic_loadmap *map = loadaddr.map;
int c;
for (c = 0; c < map->nsegs; c++)
if ((void *)map->segs[c].addr <= p &&
(char *)p < (char *)map->segs[c].addr + map->segs[c].p_memsz)
return 1;
return 0;
}
/* Callback to return the GOT value if the module contains PC. */
static int
find_got_callback (struct dl_phdr_info * info, size_t size, void * ptr)
{
int match = 0;
struct got_callback_data *data = (struct got_callback_data *) ptr;
if (__dl_addr_in_loadaddr((void *) data->pc, info->dlpi_addr)) {
match = 1;
data->got = (_Unwind_Ptr) info->dlpi_addr.got_value;
}
return match;
}
/* Find the GOT that corresponds to the module containing PC. */
_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc);
_Unwind_Ptr __gnu_Unwind_Find_got (_Unwind_Ptr pc)
{
struct got_callback_data data;
data.pc = pc;
if (dl_iterate_phdr (find_got_callback, &data) <= 0)
return 0;
return data.got;
}
#endif
|