From nobody Wed Feb 11 08:33:41 2026 Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A3731CAB3 for ; Tue, 28 Jan 2025 21:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738099378; cv=none; b=Mizfuxit+s5xrg+zz8vF+HM0tey7CxWiQtv/PUnMyKvXrJJ7eEjf53BQUC5+Z1ySEj3KTLyrceLU4XyvtPgQ6w0y4UW11TmwgFRSVsTf+nVkzYHLxP7L/uOQqvLHMeXjKROm+K5TWLJV2AZpo8W+vdcVX2uU1QdPymgngl3KpBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738099378; c=relaxed/simple; bh=rJWIhJhidQnBKrP23NmIgi2K8ZYp15X2D2pJckioUYE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=WK0q0jGpbVP0mDMyGIIQxT9+MznB2E6YLhACdxaEBJNhDBHLzNUyzOte0H43nl9mvNQ1vkel+vo+qTcwn2GDS+9vW/gfJwBdGXHXDIJkv2NZNCXcxTqXWLAE2Vko5kOyUAzUyIjLbxJB9PfjqiuWHqs07QE3lNfiu3rS+LFL428= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=s3LYFxPT; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="s3LYFxPT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1738099373; bh=rJWIhJhidQnBKrP23NmIgi2K8ZYp15X2D2pJckioUYE=; h=From:Date:Subject:To:Cc:From; b=s3LYFxPTzfQb4+HyZd9WkXSDHZH1cnAcqHoIO2zzaj8EcGBqJtDqMGjH5m/95IzPi HEukDGAZx2LocMfPPttQTCK1oyPGKPkZr+/loJZO5neIBUDEh6DYG40UmNDBCfjqo5 1dtoTXOV59Cdu9H66cms1rPAzBnzUUdCCPwjBGSM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Tue, 28 Jan 2025 22:22:46 +0100 Subject: [PATCH v2] tools/nolibc: make signature of ioctl() more flexible Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250128-nolibc-ioctl-v2-1-4a07e91fd648@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAKVKmWcC/3XMyw6CMBCF4Vchs7amFzHUle9hWEAZ7CSkNZ2KG tJ3t7J3+Z/kfBswJkKGS7NBwpWYYqihDw04P4Q7Cppqg5a6lUobEeJCoxMUXV6ENNidnZbyZAe ol0fCmd47d+tre+Ic02fXV/Vb/0CrEkpYM3ejG6ydsL2+kJjZ+ac/BszQl1K+wqK/wq0AAAA= X-Change-ID: 20250123-nolibc-ioctl-03e86c20049a To: Willy Tarreau Cc: linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1738099372; l=2027; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=rJWIhJhidQnBKrP23NmIgi2K8ZYp15X2D2pJckioUYE=; b=LwiiVWUNAgVsKUVD44RcdxB+43LqLUi8unokFb8MA/bTvYe+3v7ABvFO8xF6lhaEqbsuev81D 9Z7Ho/DeGcXC7AEEpC99mCfIpxdAgzZPJmy2AOSNs+7Yp1dvlcAQb9M X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= POSIX defines the signature of ioctl() as follows, to allow passing a pointer or integer without casting: int ioctl(int fildes, int request, ... /* arg */); Nolibc ioctl() expects a pointer, forcing the user to manually cast. Using va_arg to make the signature more flexible would work but seems to prevent inlining of the function. Instead use a macro. "fd" and "req" will still be typechecked through sys_ioctl(). Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Willy Tarreau --- Changes in v2: - Handle integers of arbitrary sizes - Align with Linux syscall signature - Link to v1: https://lore.kernel.org/r/20250123-nolibc-ioctl-v1-1-93f8bca9= 9de5@weissschuh.net --- This is now not directly POSIX compatible. Instead it uses the signature of the Linux syscall. It should be close enough. --- tools/include/nolibc/sys.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index d4a5c2399a66b200ebf7ab249569cce2285481a5..8c0a55bc9dc3aacd110db019597= 5fe4f85480fc5 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -532,20 +532,16 @@ uid_t getuid(void) =20 =20 /* - * int ioctl(int fd, unsigned long req, void *value); + * int ioctl(int fd, unsigned long cmd, ... arg); */ =20 static __attribute__((unused)) -int sys_ioctl(int fd, unsigned long req, void *value) +long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) { - return my_syscall3(__NR_ioctl, fd, req, value); + return my_syscall3(__NR_ioctl, fd, cmd, arg); } =20 -static __attribute__((unused)) -int ioctl(int fd, unsigned long req, void *value) -{ - return __sysret(sys_ioctl(fd, req, value)); -} +#define ioctl(fd, cmd, arg) __sysret(sys_ioctl(fd, cmd, (unsigned long)(ar= g))) =20 /* * int kill(pid_t pid, int signal); --- base-commit: cd45f362fc1f2d81fa69a19e7f8eca058db3e320 change-id: 20250123-nolibc-ioctl-03e86c20049a Best regards, --=20 Thomas Wei=C3=9Fschuh