about summary refs log tree commit diff
path: root/sysdeps
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-27 14:46:52 +0100
commit016d45e980870f4a158e18c8e3fbf7d5e46e7f24 (patch)
tree7842943f6112052982adbcaf0cef03565d2ff28d /sysdeps
parentc511eea647f5f4ccf65a817da746bb10f4bbc2cf (diff)
downloadglibc-016d45e980870f4a158e18c8e3fbf7d5e46e7f24.tar.gz
glibc-016d45e980870f4a158e18c8e3fbf7d5e46e7f24.tar.xz
glibc-016d45e980870f4a158e18c8e3fbf7d5e46e7f24.zip
cheri: 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.
Diffstat (limited to 'sysdeps')
-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 6b256b8388..f8cd388e62 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)]