git: a1c52e05f571 - main - CHERI: declare fueptr and suptr

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Mon, 29 Jun 2026 13:01:41 UTC
The branch main has been updated by brooks:

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

commit a1c52e05f571607db361f49993b36b0288f1d8f3
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-06-29 12:59:44 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-06-29 12:59:44 +0000

    CHERI: declare fueptr and suptr
    
    These should replace fueword and suword when manipulating pointers in
    memory.  On CHERI targets they will be implemented using capability
    aware instructions and otherwise they are defined to fueword and suword.
    
    Reviewed by:    kib, markj
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D57664
---
 share/man/man9/Makefile |  2 ++
 share/man/man9/fetch.9  | 14 +++++++++++++-
 share/man/man9/store.9  | 10 +++++++++-
 sys/sys/systm.h         | 10 ++++++++++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index fb9f5bca72c5..f465c7f49696 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1160,6 +1160,7 @@ MLINKS+=fetch.9 fubyte.9 \
 	fetch.9 fuword16.9 \
 	fetch.9 fuword32.9 \
 	fetch.9 fuword64.9 \
+	fetch.9 fueptr.9 \
 	fetch.9 fueword.9 \
 	fetch.9 fueword32.9 \
 	fetch.9 fueword64.9
@@ -2190,6 +2191,7 @@ MLINKS+=stack.9 stack_copy.9 \
 	stack.9 stack_sbuf_print_ddb.9 \
 	stack.9 stack_zero.9
 MLINKS+=store.9 subyte.9 \
+	store.9 suptr.9 \
 	store.9 suword.9 \
 	store.9 suword16.9 \
 	store.9 suword32.9 \
diff --git a/share/man/man9/fetch.9 b/share/man/man9/fetch.9
index c544ec802d68..a9dd90d81bfb 100644
--- a/share/man/man9/fetch.9
+++ b/share/man/man9/fetch.9
@@ -32,7 +32,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd July 22, 2021
+.Dd June 29, 2026
 .Dt FETCH 9
 .Os
 .Sh NAME
@@ -42,6 +42,7 @@
 .Nm fuword16 ,
 .Nm fuword32 ,
 .Nm fuword64 ,
+.Nm fueptr ,
 .Nm fueword ,
 .Nm fueword32 ,
 .Nm fueword64
@@ -60,6 +61,8 @@
 .Ft int64_t
 .Fn fuword64 "volatile const void *base"
 .Ft int
+.Fn fueptr "volatile const void *base" "intptr_t *val"
+.Ft int
 .Fn fueword "volatile const void *base" "long *val"
 .Ft int
 .Fn fueword32 "volatile const void *base" "int32_t *val"
@@ -96,6 +99,14 @@ Fetches 32 bits of data from the user-space address
 .It Fn fuword64
 Fetches 64 bits of data from the user-space address
 .Pa base .
+.It Fn fueptr
+Fetches a pointer from the user-space address
+.Pa base
+and stores the result in the variable pointed by
+.Pa val .
+.Fn fueptr
+preserves the provenance of pointers fetched from users-space
+.Pq see Xr memory_model 7 for further information .
 .It Fn fueword
 Fetches a word of data (long) from the user-space address
 .Pa base
@@ -130,6 +141,7 @@ and
 .Fn fuword64
 functions return the data fetched or -1 on failure.
 The
+.Fn fueptr ,
 .Fn fueword ,
 .Fn fueword32
 and
diff --git a/share/man/man9/store.9 b/share/man/man9/store.9
index 18fd646d609d..85128f17c005 100644
--- a/share/man/man9/store.9
+++ b/share/man/man9/store.9
@@ -32,12 +32,13 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd July 22, 2021
+.Dd June 29, 2026
 .Dt STORE 9
 .Os
 .Sh NAME
 .Nm store ,
 .Nm subyte ,
+.Nm suptr ,
 .Nm suword
 .Nd store data to user-space
 .Sh SYNOPSIS
@@ -47,6 +48,8 @@
 .Ft int
 .Fn subyte "volatile void *base" "int byte"
 .Ft int
+.Fn suptr "volatile void *base" "intptr_t ptr"
+.Ft int
 .Fn suword "volatile void *base" "long word"
 .Ft int
 .Fn suword16 "volatile void *base" "int word"
@@ -70,6 +73,11 @@ routines provide the following functionality:
 .It Fn subyte
 Stores a byte of data to the user-space address
 .Pa base .
+.It Fn suptr
+Stores a pointer to the user-space address
+.Pa base
+preserving the provenance of that pointer
+.Pq see Xr memory_model 7 for further information .
 .It Fn suword
 Stores a word of data to the user-space address
 .Pa base .
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index f2c5051ac03d..83023d24fe7d 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -350,11 +350,21 @@ int64_t	fuword64(volatile const void *base);
 __nodiscard int fueword(volatile const void *base, long *val);
 __nodiscard int fueword32(volatile const void *base, int32_t *val);
 __nodiscard int fueword64(volatile const void *base, int64_t *val);
+#ifdef __CHERI__
+__nodiscard int fueptr(volatile const void *base, intptr_t *val);
+#else
+#define	fueptr(base, val)	fueword((base), (long *)(val))
+#endif
 __nodiscard int subyte(volatile void *base, int byte);
 __nodiscard int suword(volatile void *base, long word);
 __nodiscard int suword16(volatile void *base, int word);
 __nodiscard int suword32(volatile void *base, int32_t word);
 __nodiscard int suword64(volatile void *base, int64_t word);
+#ifdef __CHERI__
+__nodiscard int suptr(volatile void *base, intptr_t ptr);
+#else
+#define	suptr(base, val)	suword((base), (val))
+#endif
 uint32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval);
 u_long	casuword(volatile u_long *p, u_long oldval, u_long newval);
 int	casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp,