From bbb069a1a72d9d9508426a74b77aeb6026594d47 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 11 Nov 2024 13:28:50 -0500 Subject: [PATCH] libroot: Use use variable argument count macro for ioctl. Based on X512's original change, but with more modifications: * Don't use _ in macro parameter names to appease GCC 2. * Get rid of ioctl_args struct. We don't need it anymore, and just adding parameters of the same types has the exact same ABI on x86 and x86_64, so this doesn't break any existing compiled code. * Add (void*) cast to third parameter. * Enable for _KERNEL_MODE also. Change-Id: Id4ad8b85f54836fd26dc6278226954d0a081d5f0 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8533 Reviewed-by: waddlesplash --- headers/posix/unistd.h | 19 +++++++++---------- src/system/libroot/posix/unistd/ioctl.c | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/headers/posix/unistd.h b/headers/posix/unistd.h index e4427aba9c..940a357b1c 100644 --- a/headers/posix/unistd.h +++ b/headers/posix/unistd.h @@ -1,5 +1,5 @@ /* - * Copyright 2004-2015 Haiku, Inc. All Rights Reserved. + * Copyright 2004-2024, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. */ #ifndef _UNISTD_H_ @@ -361,21 +361,20 @@ extern int symlinkat(const char *toPath, int fd, const char *symlinkPath); extern int ftruncate(int fd, off_t newSize); extern int truncate(const char *path, off_t newSize); -struct ioctl_args { - void* argument; - size_t size; -}; -int __ioctl(int fd, ulong cmd, struct ioctl_args args); + +extern int __ioctl(int fd, ulong cmd, void* argument, size_t size); #ifndef __cplusplus extern int ioctl(int fd, unsigned long op, ...); -#ifndef _KERNEL_MODE -#define ioctl(a, b, c...) __ioctl(a, b, (struct ioctl_args){ c }) -#endif +#define _IOCTL2(a, b) __ioctl(a, b, NULL, 0) +#define _IOCTL3(a, b, c) __ioctl(a, b, (void*)c, 0) +#define _IOCTL4(a, b, c, d) __ioctl(a, b, (void*)c, d) +#define _IOCTL(ARG1, ARG2, ARG3, ARG4, NAME, ...) NAME +#define ioctl(...) _IOCTL(__VA_ARGS__, _IOCTL4, _IOCTL3, _IOCTL2)(__VA_ARGS__) #else inline int ioctl(int fd, unsigned long op, void* argument = NULL, size_t size = 0) { - return __ioctl(fd, op, (struct ioctl_args){ argument, size }); + return __ioctl(fd, op, argument, size); } #endif diff --git a/src/system/libroot/posix/unistd/ioctl.c b/src/system/libroot/posix/unistd/ioctl.c index 7182e5bfbe..5067421604 100644 --- a/src/system/libroot/posix/unistd/ioctl.c +++ b/src/system/libroot/posix/unistd/ioctl.c @@ -14,9 +14,9 @@ int -__ioctl(int fd, ulong cmd, struct ioctl_args args) +__ioctl(int fd, ulong cmd, void* argument, size_t size) { - RETURN_AND_SET_ERRNO(_kern_ioctl(fd, cmd, args.argument, args.size)); + RETURN_AND_SET_ERRNO(_kern_ioctl(fd, cmd, argument, size)); }