1 /* Determine if address is inside object load segments.
2 Copyright (C) 1996-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 /* Return non-zero if ADDR lies within one of L's loadable segments.
23 We have three cases we care about.
25 Case 1: addr is above a segment.
26 +==================+<- l_map_end
28 |------------------|<- l_addr + p_vaddr + p_memsz
31 |------------------|<- l_addr + p_vaddr
32 |------------------|<- l_addr
34 +==================+<- l_map_start
36 Case 2: addr is within a segments.
37 +==================+<- l_map_end
39 |------------------|<- l_addr + p_vaddr + p_memsz
42 |------------------|<- l_addr + p_vaddr
43 |------------------|<- l_addr
45 +==================+<- l_map_start
47 Case 3: addr is below a segments.
48 +==================+<- l_map_end
50 |------------------|<- l_addr + p_vaddr + p_memsz
53 |------------------|<- l_addr + p_vaddr
54 |------------------|<- l_addr
56 +==================+<- l_map_start
58 All the arithmetic is unsigned and we shift all the values down by
59 l_addr + p_vaddr and then compare the normalized addr to the range
60 of interest i.e. 0 <= addr < p_memsz.
64 _dl_addr_inside_object (struct link_map
*l
, const ElfW(Addr
) addr
)
67 const ElfW(Addr
) reladdr
= addr
- l
->l_addr
;
70 if (l
->l_phdr
[n
].p_type
== PT_LOAD
71 && reladdr
- l
->l_phdr
[n
].p_vaddr
< l
->l_phdr
[n
].p_memsz
)