From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1944) id B1B283856DE5; Fri, 5 Aug 2022 19:37:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1B283856DE5 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Szabolcs Nagy To: glibc-cvs@sourceware.org Subject: [glibc/arm/morello/main] TODO(morello): cheri: fix posix timers X-Act-Checkin: glibc X-Git-Author: Szabolcs Nagy X-Git-Refname: refs/heads/arm/morello/main X-Git-Oldrev: 989eb509545acde831502f16a8a86a95ecf5a84e X-Git-Newrev: bb648757f04e595b029be6ceaa6e2db66876c8cb Message-Id: <20220805193716.B1B283856DE5@sourceware.org> Date: Fri, 5 Aug 2022 19:37:16 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Aug 2022 19:37:16 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bb648757f04e595b029be6ceaa6e2db66876c8cb commit bb648757f04e595b029be6ceaa6e2db66876c8cb Author: Szabolcs Nagy Date: Tue Apr 19 15:18:56 2022 +0100 TODO(morello): 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). TODO: 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)