]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
cheri: fix posix timers
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Tue, 19 Apr 2022 14:18:56 +0000 (15:18 +0100)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 27 Oct 2022 13:46:54 +0000 (14:46 +0100)
We need to distinguish timerids that are small integers returned by
the kernel and timerids that are pointers to struct timer. The existing
pointer tagging does not work for CHERI because of the pointer shift.

Simply use the top bit without shift to tag pointers. This still relies
on the top byte ignore of aarch64 (the top byte does not affect the
capability representation) and that pointers are not tagged for other
reasons (like HWASAN).

Note: this is morello specific and does not work for generic cheri.

sysdeps/unix/sysv/linux/kernel-posix-timers.h

index 82ce92f2ae70360e4eb8105dd4678fb8ca3e1e10..371e3282589480a6f44bd8e4c65e684f7e4b0aa1 100644 (file)
@@ -79,6 +79,25 @@ kernel_timer_to_timerid (kernel_timer_t ktimerid)
   return (timer_t) ((intptr_t) ktimerid);
 }
 
+#ifdef __CHERI_PURE_CAPABILITY__
+static inline timer_t
+timer_to_timerid (struct timer *ptr)
+{
+  return (timer_t) ((uintptr_t) ptr | ~(-1UL/2));
+}
+
+static inline bool
+timer_is_sigev_thread (timer_t timerid)
+{
+  return ((uintptr_t) timerid & ~(-1UL/2)) != 0;
+}
+
+static inline struct timer *
+timerid_to_timer (timer_t timerid)
+{
+  return (struct timer *)((uintptr_t) timerid & (-1UL/2));
+}
+#else
 static inline timer_t
 timer_to_timerid (struct timer *ptr)
 {
@@ -96,6 +115,7 @@ timerid_to_timer (timer_t timerid)
 {
   return (struct timer *)((uintptr_t) timerid << 1);
 }
+#endif
 
 static inline kernel_timer_t
 timerid_to_kernel_timer (timer_t timerid)