about summary refs log tree commit diff
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-11-22 14:31:25 +0000
commit055042833f84bad40aacb4f952eae63351cf5fb3 (patch)
treec453b1bcbe125b34d19a2ae9a2ade502993fc04c
parentf70a0f9a14ebb996d2d914b3067e6fcf4faf5ee0 (diff)
downloadglibc-055042833f84bad40aacb4f952eae63351cf5fb3.tar.gz
glibc-055042833f84bad40aacb4f952eae63351cf5fb3.tar.xz
glibc-055042833f84bad40aacb4f952eae63351cf5fb3.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.
-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)]