]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
TODO(api): cheri: misc: Implement new function getauxptr for CHERI capabilities
authorCarlos Eduardo Seo <carlos.seo@arm.com>
Wed, 18 May 2022 00:52:09 +0000 (00:52 +0000)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:55 +0000 (14:46 +0100)
New function to return values from the auxiliary vector as
capabilities. This is the same as implemented by other C libraries.

TODO: agree about exact semantics across libcs

include/sys/auxv.h
misc/Versions
misc/getauxval.c
misc/sys/auxv.h

index dd0602b08d881cd3bb75ec7f0042a88af6a8fdf8..0bd40bd835f4e479f080d81efdda34a9c3cd14cb 100644 (file)
@@ -10,4 +10,8 @@ libc_hidden_proto (__getauxval)
 _Bool __getauxval2 (unsigned long int type, unsigned long int *result);
 libc_hidden_proto (__getauxval2)
 
+/* Like getauxval, but for Arm Morello capabilities.  */
+extern __typeof (getauxptr) __getauxptr;
+libc_hidden_proto (__getauxptr)
+
 #endif  /* !_ISOMAC */
index d5b348e83ada03cd0f9e874666cb60f4f5cba6d0..669a03ffb326d2538b97bac3d10579fb58244667 100644 (file)
@@ -164,6 +164,9 @@ libc {
   GLIBC_2.32 {
     __libc_single_threaded;
   }
+  GLIBC_2.36 {
+    __getauxptr; getauxptr;
+  }
   GLIBC_PRIVATE {
     __madvise;
     __mktemp;
index 714ce5bd62ec33c38356b187e6ec067b72b77afb..a4625b8596fe550c40a508e5e6ab9fff13b52358 100644 (file)
 #include <ldsodefs.h>
 #include <stdbool.h>
 
+void *
+__getauxptr (unsigned long int type)
+{
+  /* error if asking for a non-pointer from getauxptr(). This list is not a
+     perfect enforcement as it currently supports both transitional and draft
+     ABIs, which have different capability entries.  */
+  switch (type) {
+    case AT_ENTRY:
+    case AT_PHDR:
+    case AT_BASE:
+    case AT_SYSINFO_EHDR:
+    case AT_EXECFN:
+    case AT_RANDOM:
+    case AT_PLATFORM:
+    case AT_CHERI_EXEC_RW_CAP:
+    case AT_CHERI_EXEC_RX_CAP:
+    case AT_CHERI_INTERP_RW_CAP:
+    case AT_CHERI_INTERP_RX_CAP:
+    case AT_CHERI_SEAL_CAP:
+    {
+      ElfW(auxv_t) *p;
+      for (p = GLRO(dl_auxv); p->a_type != AT_NULL; p++)
+        if (p->a_type == type)
+          return (void *) p->a_un.a_val;
+    }
+  }
+
+  __set_errno (ENOENT);
+  return 0;
+}
+weak_alias (__getauxptr, getauxptr)
+libc_hidden_def (__getauxptr)
+
 bool
 __getauxval2 (unsigned long int type, unsigned long int *result)
 {
index b5ab30ab777ec6d6aed94628db3d97534ad2e564..8446aeddd0c7400b9a4e1552dd4b65ce15157117 100644 (file)
@@ -31,6 +31,10 @@ __BEGIN_DECLS
 extern unsigned long int getauxval (unsigned long int __type)
   __THROW;
 
+/* Same as getauxval, but for Arm Morello capabilities.  */
+extern void * getauxptr (unsigned long int __type)
+  __THROW;
+
 __END_DECLS
 
 #endif /* sys/auxv.h */