git: 887eddca598a - stable/13 - stand: Make ioctl declaration consistent

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 24 Jan 2023 22:14:09 UTC
The branch stable/13 has been updated by imp:

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

commit 887eddca598afeb678d06cb997961c248da47c6e
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-12-13 04:46:05 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-01-24 21:49:44 +0000

    stand: Make ioctl declaration consistent
    
    It typically had two args with an optional third from the userland
    declaration in sys/ioccom.h. However, the funciton definition used a
    non-optional char * argument. This mismatch is UB behavior (but worked
    due to the calling convetions of all our machines).
    
    Instead, add a declaration for ioctl to stand.h, make the third arg
    'void *' which is a better match to the ... declaration before. This
    prevents the convert int * -> char * errors as well. Make the ioctl
    user-space declaration truly user-space specific (omit it in the
    stand-alone build).
    
    No functional change intended.
    
    Sponsored by:           Netflix
    Reviewed by:            emaste
    Differential Revision:  https://reviews.freebsd.org/D37680
    
    (cherry picked from commit 2e1e68cbaee3e74a89e9b63fdb180974a2bf4292)
---
 stand/libsa/ioctl.c | 2 +-
 stand/libsa/stand.h | 1 +
 sys/sys/ioccom.h    | 2 +-
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/stand/libsa/ioctl.c b/stand/libsa/ioctl.c
index 7363236ada0e..5d38d73bf106 100644
--- a/stand/libsa/ioctl.c
+++ b/stand/libsa/ioctl.c
@@ -66,7 +66,7 @@ __FBSDID("$FreeBSD$");
 #include "stand.h"
 
 int
-ioctl(int fd, u_long cmd, char *arg)
+ioctl(int fd, u_long cmd, void *arg)
 {
 	struct open_file *f;
 
diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h
index b1c48bd88b39..c0550104bca0 100644
--- a/stand/libsa/stand.h
+++ b/stand/libsa/stand.h
@@ -315,6 +315,7 @@ extern int	close(int);
 extern void	closeall(void);
 extern ssize_t	read(int, void *, size_t);
 extern ssize_t	write(int, const void *, size_t);
+extern int	ioctl(int, u_long, void *);
 extern struct	dirent *readdirfd(int);
 extern void	preload(int);
 
diff --git a/sys/sys/ioccom.h b/sys/sys/ioccom.h
index 13faba046719..7eb5c323d886 100644
--- a/sys/sys/ioccom.h
+++ b/sys/sys/ioccom.h
@@ -82,7 +82,7 @@
 #define	_IOC_INVALID	(_IOC_VOID|_IOC_INOUT)	/* Never valid cmd value,
 						   use as filler */
 
-#else
+#elif !defined(_STANDALONE)
 
 #include <sys/cdefs.h>