aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2022-08-08 10:56:14 +0100
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2022-10-12 14:22:03 +0100
commit1b0716e08364e9b9985cd801e0f35edb6550e501 (patch)
treed0ded3b1c848cfa8b094a5128266a8541cabd7f6
parent55ada9157de78b614f56169643942f31d36b0035 (diff)
downloadglibc-1b0716e08364e9b9985cd801e0f35edb6550e501.zip
glibc-1b0716e08364e9b9985cd801e0f35edb6550e501.tar.gz
glibc-1b0716e08364e9b9985cd801e0f35edb6550e501.tar.bz2
elf: add dl_{rx,rw}_ptr to derive addresses within a map
To derive pointers within a module from the per module RX and RW caps.
-rw-r--r--sysdeps/generic/ldsodefs.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index d3fdf9f..9cded5f 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -80,6 +80,34 @@ dl_relocate_ld (const struct link_map *l)
return !(l->l_ld_readonly || DL_RO_DYN_SECTION);
}
+static inline elfptr_t __attribute__ ((unused))
+dl_get_ptr (elfptr_t cap, ElfW(Addr) base, ElfW(Addr) vaddr)
+{
+#ifdef __CHERI_PURE_CAPABILITY__
+ return __builtin_cheri_address_set (cap, base + vaddr);
+#else
+ return base + vaddr;
+#endif
+}
+
+static inline elfptr_t __attribute__ ((unused))
+dl_rx_ptr (const struct link_map *l, ElfW(Addr) vaddr)
+{
+ return dl_get_ptr (l->l_map_start, l->l_addr, vaddr);
+}
+
+static inline elfptr_t __attribute__ ((unused))
+dl_rw_ptr (const struct link_map *l, ElfW(Addr) vaddr)
+{
+ elfptr_t cap;
+#ifdef __CHERI_PURE_CAPABILITY__
+ cap = l->l_rw_start;
+#else
+ cap = 0; /* Avoid uninitialized warning. */
+#endif
+ return dl_get_ptr (cap, l->l_addr, vaddr);
+}
+
/* All references to the value of l_info[DT_PLTGOT],
l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]