git: 62e53516f732 - main - lib/libthr: add helper to check valid clockid to use with _umtx_op(2)

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 10 Nov 2026 00:22:05 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=62e53516f73247d2ed80d8dc452f02d9a92575a0

commit 62e53516f73247d2ed80d8dc452f02d9a92575a0
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-05 20:39:40 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-10 00:21:18 +0000

    lib/libthr: add helper to check valid clockid to use with _umtx_op(2)
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D61253
---
 lib/libthr/thread/thr_private.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
index 9ea56b5b8a35..2a9592cdfe46 100644
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -996,6 +996,34 @@ _sleepq_first(struct sleepqueue *sq)
 	return TAILQ_FIRST(&sq->sq_blocked);
 }
 
+/*
+ * Must accept the same clocks as umtx_check_clockid() in
+ * sys/kern/kern_umtx.c.
+ */
+static inline int
+_thr_check_clockid(clockid_t clockid)
+{
+	switch (clockid) {
+	case CLOCK_REALTIME:
+	case CLOCK_REALTIME_PRECISE:
+	case CLOCK_REALTIME_FAST:
+	case CLOCK_MONOTONIC:
+	case CLOCK_MONOTONIC_PRECISE:
+	case CLOCK_MONOTONIC_FAST:
+	case CLOCK_UPTIME:
+	case CLOCK_UPTIME_PRECISE:
+	case CLOCK_UPTIME_FAST:
+	case CLOCK_SECOND:
+	case CLOCK_VIRTUAL:
+	case CLOCK_PROF:
+	case CLOCK_PROCESS_CPUTIME_ID:
+	case CLOCK_TAI:
+		return (0);
+	default:
+		return (EINVAL);
+	}
+}
+
 void	_sleepq_init(void) __hidden;
 struct sleepqueue *_sleepq_alloc(void) __hidden;
 void	_sleepq_free(struct sleepqueue *) __hidden;