git: 230d581d4e8c - main - fstat(2): add user_fstat

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Sat, 07 Nov 2026 12:11:04 UTC
The branch main has been updated by brooks:

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

commit 230d581d4e8c3017d4e711dc97f2b53ebe1ea7ee
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-07 12:10:46 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-07 12:10:46 +0000

    fstat(2): add user_fstat
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_descrip.c | 15 ++++++++-------
 sys/sys/syscallsubr.h   |  1 +
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 0fa8210b71c0..400996f6f32a 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -374,7 +374,6 @@ struct dup2_args {
 int
 sys_dup2(struct thread *td, struct dup2_args *uap)
 {
-
 	return (kern_dup(td, FDDUP_FIXED, 0, (int)uap->from, (int)uap->to));
 }
 
@@ -390,7 +389,6 @@ struct dup_args {
 int
 sys_dup(struct thread *td, struct dup_args *uap)
 {
-
 	return (kern_dup(td, FDDUP_NORMAL, 0, (int)uap->fd, 0));
 }
 
@@ -408,7 +406,6 @@ struct fcntl_args {
 int
 sys_fcntl(struct thread *td, struct fcntl_args *uap)
 {
-
 	return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, uap->arg));
 }
 
@@ -1493,7 +1490,6 @@ struct close_args {
 int
 sys_close(struct thread *td, struct close_args *uap)
 {
-
 	return (kern_close(td, uap->fd));
 }
 
@@ -1610,7 +1606,6 @@ struct close_range_args {
 int
 sys_close_range(struct thread *td, struct close_range_args *uap)
 {
-
 	AUDIT_ARG_FD(uap->lowfd);
 	AUDIT_ARG_CMD(uap->highfd);
 	AUDIT_ARG_FFLAGS(uap->flags);
@@ -1703,13 +1698,19 @@ struct fstat_args {
 /* ARGSUSED */
 int
 sys_fstat(struct thread *td, struct fstat_args *uap)
+{
+	return (user_fstat(td, uap->fd, uap->sb));
+}
+
+int
+user_fstat(struct thread *td, int fd, struct stat *sb)
 {
 	struct stat ub;
 	int error;
 
-	error = kern_fstat(td, uap->fd, &ub);
+	error = kern_fstat(td, fd, &ub);
 	if (error == 0)
-		error = copyout(&ub, uap->sb, sizeof(ub));
+		error = copyout(&ub, sb, sizeof(ub));
 	return (error);
 }
 
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 7f07e200ec58..7c53dcc2d658 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -472,6 +472,7 @@ int	user_cpuset_getaffinity(struct thread *td, cpulevel_t level,
 int	user_cpuset_setaffinity(struct thread *td, cpulevel_t level,
 	    cpuwhich_t which, id_t id, size_t cpusetsize,
 	    const cpuset_t *maskp, const struct cpuset_copy_cb *cb);
+int	user_fstat(struct thread *td, int fd, struct stat *sb);
 int	user_jail_get(struct thread *td, struct iovec *iovp,
 	    unsigned int iovcnt, int flags, copyinuio_t *copyinuio_f,
 	    updateiov_t *updateiov_f);