git: d0efabdf15d9 - main - syscalls.master: make __sys_fcntl take an intptr_t

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Tue, 19 Mar 2024 23:15:57 UTC
The branch main has been updated by brooks:

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

commit d0efabdf15d956e9bc0414356ed798ca3c846e08
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2024-03-19 21:52:39 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2024-03-19 23:13:26 +0000

    syscalls.master: make __sys_fcntl take an intptr_t
    
    The (optional) third argument of fcntl is sometimes a pointer so change
    the type to intptr_t.  Update the libc-internal defintion (actually used
    by libthr) to take a fixed intptr_t argument rather than pretending it's
    a variadic function.  (That worked because all supported architectures
    pass variadic arguments as though the function was declared with those
    types.  In CheriBSD that changes because variadic arguments are passed
    via a bounded array.)
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D44381
---
 lib/libc/include/libc_private.h       |  2 +-
 lib/libthr/thread/thr_syscalls.c      |  4 ++--
 sys/compat/freebsd32/freebsd32_misc.c |  2 +-
 sys/kern/kern_descrip.c               | 10 +++++-----
 sys/kern/syscalls.master              |  2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index b3f31f6e4e87..629889a6ff17 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -344,7 +344,7 @@ int		__sys_clock_nanosleep(__clockid_t, int,
 int		__sys_close(int);
 int		__sys_close_range(unsigned, unsigned, int);
 int		__sys_connect(int, const struct sockaddr *, __socklen_t);
-int		__sys_fcntl(int, int, ...);
+int		__sys_fcntl(int, int, __intptr_t);
 int		__sys_fdatasync(int);
 int		__sys_fstat(int fd, struct stat *);
 int		__sys_fstatfs(int fd, struct statfs *);
diff --git a/lib/libthr/thread/thr_syscalls.c b/lib/libthr/thread/thr_syscalls.c
index c931f2cc310e..348825cd6198 100644
--- a/lib/libthr/thread/thr_syscalls.c
+++ b/lib/libthr/thread/thr_syscalls.c
@@ -198,10 +198,10 @@ __thr_fcntl(int fd, int cmd, ...)
 	va_start(ap, cmd);
 	if (cmd == F_OSETLKW || cmd == F_SETLKW) {
 		_thr_cancel_enter(curthread);
-		ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
+		ret = __sys_fcntl(fd, cmd, (intptr_t)va_arg(ap, void *));
 		_thr_cancel_leave(curthread, ret == -1);
 	} else {
-		ret = __sys_fcntl(fd, cmd, va_arg(ap, void *));
+		ret = __sys_fcntl(fd, cmd, (intptr_t)va_arg(ap, void *));
 	}
 	va_end(ap);
 
diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c
index 6c703f14e408..e6aea3acdecd 100644
--- a/sys/compat/freebsd32/freebsd32_misc.c
+++ b/sys/compat/freebsd32/freebsd32_misc.c
@@ -3942,7 +3942,7 @@ freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
 int
 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
 {
-	long tmp;
+	intptr_t tmp;
 
 	switch (uap->cmd) {
 	/*
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 65b1f74d310b..7f9318a7ceda 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -414,7 +414,7 @@ sys_fcntl(struct thread *td, struct fcntl_args *uap)
 }
 
 int
-kern_fcntl_freebsd(struct thread *td, int fd, int cmd, long arg)
+kern_fcntl_freebsd(struct thread *td, int fd, int cmd, intptr_t arg)
 {
 	struct flock fl;
 	struct __oflock ofl;
@@ -430,7 +430,7 @@ kern_fcntl_freebsd(struct thread *td, int fd, int cmd, long arg)
 		/*
 		 * Convert old flock structure to new.
 		 */
-		error = copyin((void *)(intptr_t)arg, &ofl, sizeof(ofl));
+		error = copyin((void *)arg, &ofl, sizeof(ofl));
 		fl.l_start = ofl.l_start;
 		fl.l_len = ofl.l_len;
 		fl.l_pid = ofl.l_pid;
@@ -455,7 +455,7 @@ kern_fcntl_freebsd(struct thread *td, int fd, int cmd, long arg)
 	case F_SETLK:
 	case F_SETLKW:
 	case F_SETLK_REMOTE:
-		error = copyin((void *)(intptr_t)arg, &fl, sizeof(fl));
+		error = copyin((void *)arg, &fl, sizeof(fl));
 		arg1 = (intptr_t)&fl;
 		break;
 	default:
@@ -473,9 +473,9 @@ kern_fcntl_freebsd(struct thread *td, int fd, int cmd, long arg)
 		ofl.l_pid = fl.l_pid;
 		ofl.l_type = fl.l_type;
 		ofl.l_whence = fl.l_whence;
-		error = copyout(&ofl, (void *)(intptr_t)arg, sizeof(ofl));
+		error = copyout(&ofl, (void *)arg, sizeof(ofl));
 	} else if (cmd == F_GETLK) {
-		error = copyout(&fl, (void *)(intptr_t)arg, sizeof(fl));
+		error = copyout(&fl, (void *)arg, sizeof(fl));
 	}
 	return (error);
 }
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 874223f6f238..c5485294dcd0 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -616,7 +616,7 @@
 		int fcntl(
 		    int fd,
 		    int cmd,
-		    long arg
+		    intptr_t arg
 		);
 	}
 ; XXX should be { int fcntl(int fd, int cmd, ...); }