public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/arm/morello/main] cheri: fix posix timers
@ 2022-10-27 13:59 Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2022-10-27 13:59 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=52d4224dd26a601b13e41467703c784e1b14ad9d

commit 52d4224dd26a601b13e41467703c784e1b14ad9d
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Apr 19 15:18:56 2022 +0100

    cheri: fix posix timers
    
    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.

Diff:
---
 sysdeps/unix/sysv/linux/kernel-posix-timers.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/sysdeps/unix/sysv/linux/kernel-posix-timers.h
index 82ce92f2ae..371e328258 100644
--- a/sysdeps/unix/sysv/linux/kernel-posix-timers.h
+++ b/sysdeps/unix/sysv/linux/kernel-posix-timers.h
@@ -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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/arm/morello/main] cheri: fix posix timers
@ 2022-11-23 14:49 Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2022-11-23 14:49 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=abb1d6bb4114b95391d9e50de5bda4302bca950a

commit abb1d6bb4114b95391d9e50de5bda4302bca950a
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Apr 19 15:18:56 2022 +0100

    cheri: fix posix timers
    
    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.

Diff:
---
 sysdeps/unix/sysv/linux/kernel-posix-timers.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/sysdeps/unix/sysv/linux/kernel-posix-timers.h
index 82ce92f2ae..371e328258 100644
--- a/sysdeps/unix/sysv/linux/kernel-posix-timers.h
+++ b/sysdeps/unix/sysv/linux/kernel-posix-timers.h
@@ -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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [glibc/arm/morello/main] cheri: fix posix timers
@ 2022-10-26 15:21 Szabolcs Nagy
  0 siblings, 0 replies; 3+ messages in thread
From: Szabolcs Nagy @ 2022-10-26 15:21 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=03b5c19d67bab9abb0223601a4f0928936fb9ab0

commit 03b5c19d67bab9abb0223601a4f0928936fb9ab0
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Apr 19 15:18:56 2022 +0100

    cheri: fix posix timers
    
    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.

Diff:
---
 sysdeps/unix/sysv/linux/kernel-posix-timers.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/sysdeps/unix/sysv/linux/kernel-posix-timers.h b/sysdeps/unix/sysv/linux/kernel-posix-timers.h
index 82ce92f2ae..371e328258 100644
--- a/sysdeps/unix/sysv/linux/kernel-posix-timers.h
+++ b/sysdeps/unix/sysv/linux/kernel-posix-timers.h
@@ -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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-23 14:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 13:59 [glibc/arm/morello/main] cheri: fix posix timers Szabolcs Nagy
  -- strict thread matches above, loose matches on Subject: below --
2022-11-23 14:49 Szabolcs Nagy
2022-10-26 15:21 Szabolcs Nagy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).