From patchwork Tue Jun 10 19:02:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114160 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E96D3858C98 for ; Tue, 10 Jun 2025 19:06:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E96D3858C98 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=D3sMOifN X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 417713858CD1 for ; Tue, 10 Jun 2025 19:03:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 417713858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 417713858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582180; cv=none; b=klVNA2tY98nEba13BTyy3AXFlNTmOixHHnwr9tXkoRFRByt2LcO4qK1hYVUVbvwXsmFSfx+QGMubsxhkDoQ/47IufObkwvS/IEFUA2VGHpbYhx8t0TeXbVYhAWzHk2J9PRG2vGPTFc2dyYdJ9H4Awsd2d7CrZwuVY4IlnEJTIyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582180; c=relaxed/simple; bh=qI+MTGIhnv9paRPfMWoChA5KQ0GkBIq6shEMupHK0t4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QXgbpARrcvIpcQ/3MLnA7bLPHLYvNQC7qutKErlePUBDGKzxvdNpx2R9SO0VZSt87Ojpn5Fi0Vrf+mHEI0511/ISB26gPO0XH0oKDppc5gdKYG7bzcWEsYDGx68xOQAGloDi2yzbmiXYcWt3qmrtp9Xp0PalPgzeowFXXBc1UBA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 417713858CD1 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2are2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:52 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2are2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582172; bh=g77Cz/ev/RFfVyjImCagbYPr86YieIkhxArJXKI6lTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D3sMOifNFFfyIfz5NqAbq7ho0ko3T+jnPQnIAmi+aAYrT+HKnweeFjDjJGCbAICoJ AVFKz7rfk4/R4z5U83giJx7h0jwbyNEueL9/N9aZdhV3pLpmn7ZuwRQTluuD9zKxCE pVuqX6doQjiapmr5MRaUVu9rVir+8dPDaDVtsYhtT5Qa3CZwmfZv4sdsiHVSDLk0sC SAxX9BYtzUIMkSsYwJh6E6M8q9NzIlVeohHcIZhZNtCAsCzXwEBTTCft4w7zH5BEPw FqnXlY2R/ZilJEVipuhNkYlz8FeiEWx1n5LpNsHGfX7l15MUlzDVbWUrPJ1BSDxafo oD7Mv9k1vIh5w== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 01/15] termios: make __tcsetattr() the internal interface Date: Tue, 10 Jun 2025 12:02:12 -0700 Message-ID: <20250610190228.1124149-2-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" There is a prototype for an internal __tcsetattr() function in include/termios.h, but tcsetattr without __ were still declared as the actual functions. Make this match the comment and make __tcsetattr() an internal interface. This will be required to version struct termios for Linux on MIPS and SPARC. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- include/termios.h | 2 +- login/openpty.c | 2 +- misc/getpass.c | 4 ++-- sysdeps/unix/bsd/tcsetattr.c | 6 ++++-- sysdeps/unix/sysv/linux/tcsetattr.c | 2 +- termios/tcsetattr.c | 5 +++-- 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/termios.h b/include/termios.h index e2c35ebbae09..a79da7a1f379 100644 --- a/include/termios.h +++ b/include/termios.h @@ -10,7 +10,7 @@ extern int __tcsetattr (int __fd, int __optional_actions, extern int __libc_tcdrain (int __fd); libc_hidden_proto (__tcgetattr) -libc_hidden_proto (tcsetattr) +libc_hidden_proto (__tcsetattr) libc_hidden_proto (cfsetispeed) libc_hidden_proto (cfsetospeed) diff --git a/login/openpty.c b/login/openpty.c index fc45add3df44..f7fd6b7384e6 100644 --- a/login/openpty.c +++ b/login/openpty.c @@ -124,7 +124,7 @@ __openpty (int *pptmx, int *pterminal, char *name, /* XXX Should we ignore errors here? */ if (termp) - tcsetattr (terminal, TCSAFLUSH, termp); + __tcsetattr (terminal, TCSAFLUSH, termp); #ifdef TIOCSWINSZ if (winp) __ioctl (terminal, TIOCSWINSZ, winp); diff --git a/misc/getpass.c b/misc/getpass.c index 4fe94537b926..a68acf483a20 100644 --- a/misc/getpass.c +++ b/misc/getpass.c @@ -83,7 +83,7 @@ getpass (const char *prompt) s = t; /* Tricky, tricky. */ t.c_lflag &= ~(ECHO|ISIG); - tty_changed = (tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0); + tty_changed = (__tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &t) == 0); } else tty_changed = 0; @@ -110,7 +110,7 @@ getpass (const char *prompt) /* Restore the original setting. */ if (tty_changed) - (void) tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s); + (void) __tcsetattr (fileno (in), TCSAFLUSH|TCSASOFT, &s); funlockfile (out); diff --git a/sysdeps/unix/bsd/tcsetattr.c b/sysdeps/unix/bsd/tcsetattr.c index 38b5f71da27e..8693d943e7fe 100644 --- a/sysdeps/unix/bsd/tcsetattr.c +++ b/sysdeps/unix/bsd/tcsetattr.c @@ -32,7 +32,7 @@ /* Set the state of FD to *TERMIOS_P. */ int -tcsetattr (int fd, int optional_actions, const struct termios *termios_p) +__tcsetattr (int fd, int optional_actions, const struct termios *termios_p) { struct termios myt; @@ -56,4 +56,6 @@ tcsetattr (int fd, int optional_actions, const struct termios *termios_p) return __ioctl (fd, TIOCSETAF, termios_p); } } -libc_hidden_def (tcsetattr) + +libc_hidden_def (__tcsetattr) +weak_alias (__tcsetattr, tcsetattr) diff --git a/sysdeps/unix/sysv/linux/tcsetattr.c b/sysdeps/unix/sysv/linux/tcsetattr.c index 5a13ad879047..49d9d245a067 100644 --- a/sysdeps/unix/sysv/linux/tcsetattr.c +++ b/sysdeps/unix/sysv/linux/tcsetattr.c @@ -77,5 +77,5 @@ __tcsetattr (int fd, int optional_actions, const struct termios *termios_p) return INLINE_SYSCALL (ioctl, 3, fd, cmd, &k_termios); } +libc_hidden_def (__tcsetattr) weak_alias (__tcsetattr, tcsetattr) -libc_hidden_def (tcsetattr) diff --git a/termios/tcsetattr.c b/termios/tcsetattr.c index 30bc6d64b95d..f0756be9fec3 100644 --- a/termios/tcsetattr.c +++ b/termios/tcsetattr.c @@ -23,7 +23,7 @@ static int bad_speed (speed_t speed); /* Set the state of FD to *TERMIOS_P. */ int -tcsetattr (int fd, int optional_actions, const struct termios *termios_p) +__tcsetattr (int fd, int optional_actions, const struct termios *termios_p) { if (fd < 0) { @@ -57,7 +57,8 @@ tcsetattr (int fd, int optional_actions, const struct termios *termios_p) __set_errno (ENOSYS); return -1; } -libc_hidden_def (tcsetattr) +libc_hidden_def (__tcsetattr) +weak_alias (__tcsetattr, tcsetattr) /* Strychnine checking. */ static int From patchwork Tue Jun 10 19:02:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114161 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9EF263858D37 for ; Tue, 10 Jun 2025 19:07:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9EF263858D37 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=KVXI9HGV X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 3BFB93858D37 for ; Tue, 10 Jun 2025 19:03:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BFB93858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3BFB93858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582180; cv=none; b=B4cX1fhsXDMgn4q8f6fXx3UGJq2hYjyaP/UXO1Ni54HbigXcGTXRnvZZq/erHhpuFe00zk37zyX8kZIH8SvjNVCzp8qfpSsb7NPSa6FDASPvrrPIvapUirFXH1IF+kg8s/Jmky+ezB7gv02g/ng9IsVhNYR+84s5f7dyrJRweXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582180; c=relaxed/simple; bh=o6HT34ZOWg33Y3i5PnuSyRyVZTFwdmCzldCnfdwrIq4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TCCkGgcmtpW9eIyrE/fb1bJZUkr0DDD1e7xqjRXk50WVeb6UMYTsB2/iFzsxBQg2yXumK1yW252q/pEyhAXOL9VQZDv1vBtigSr/RfIu2f2RxgW556LGyovH+Q7pIuTfY/bNli91YbMRq1b3k53rdO+0zE5Pfpyq4BHS/sRrUyI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3BFB93858D37 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arf2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:53 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arf2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582173; bh=R0DVaOGEVXEP1N5N9yDeNdZcFN5r43cppfjw9ueVt0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KVXI9HGVCk16m+wvMYxx3KjdjJuyiBxPzpMw/2S6EmuoalB6JZfmYTOp6jKPv0+ZH PeObGX2zMJI6edlIy0+G/UQ2nhNiGOue1HCV8cg6pZJKikkBtX8nVSSrTEPmLTPEzy hVlSBh/ZKySBHmY43l4SwQYhGBgCYGRAQM9zLH+vk71b9yrZL7YtYlVwGAtGqEcZqJ btqU7FoHXDiqvcFAhP2nsdg/QqokDXz3cj1zdzsLVPNlYfJcRXnWXz0eYIvX6Sp06s GQx2grD7mBisl+I75MbNf2sEa0T2AT/toUizfCVmrL2W3LHd4yKOGJFSY8aGa3zjJl lO2gAmwZeM9DA== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 02/15] io: replace local_isatty() with a proper function __isatty_nostatus() Date: Tue, 10 Jun 2025 12:02:13 -0700 Message-ID: <20250610190228.1124149-3-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Replace local_isatty() inlined in libio with a proper function __isatty_nostatus(). This allows simpler system-specific implementations that don't need to touch errno at all. Note: I left the prototype in include/unistd.h (the internal header file.) It didn't much make sense to me to put it in a different header (not-cancel.h), but perhaps someone can elucidate the need. Add such an implementation for Linux, with a generic fallback. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- include/unistd.h | 1 + io/Makefile | 1 + io/isatty_nostatus.c | 29 +++++++++++++++++++++++ libio/filedoalloc.c | 12 +--------- sysdeps/unix/sysv/linux/isatty_nostatus.c | 29 +++++++++++++++++++++++ 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 io/isatty_nostatus.c create mode 100644 sysdeps/unix/sysv/linux/isatty_nostatus.c diff --git a/include/unistd.h b/include/unistd.h index e241603b8131..376ab5a93688 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -152,6 +152,7 @@ libc_hidden_proto (__ttyname_r) extern __pid_t _Fork (void); libc_hidden_proto (_Fork); extern int __isatty (int __fd) attribute_hidden; +extern int __isatty_nostatus (int __fd) attribute_hidden; extern int __link (const char *__from, const char *__to); extern int __symlink (const char *__from, const char *__to); extern int __symlinkat (const char *__from, int __fd, const char *__to); diff --git a/io/Makefile b/io/Makefile index e06f3cb3dba1..edee38e233d8 100644 --- a/io/Makefile +++ b/io/Makefile @@ -92,6 +92,7 @@ routines := \ getdirname \ getwd \ isatty \ + isatty_nostatus \ lchmod \ lchown \ link \ diff --git a/io/isatty_nostatus.c b/io/isatty_nostatus.c new file mode 100644 index 000000000000..e8ee796f3ba2 --- /dev/null +++ b/io/isatty_nostatus.c @@ -0,0 +1,29 @@ +/* Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +/* Return 1 if FD is a terminal, 0 if not, without changing errno */ +int +__isatty_nostatus (int fd) +{ + int save_errno = errno; + int res = __isatty (fd); + __set_errno (save_errno); + return res; +} diff --git a/libio/filedoalloc.c b/libio/filedoalloc.c index 9ddd75b42923..f360d96a9b57 100644 --- a/libio/filedoalloc.c +++ b/libio/filedoalloc.c @@ -61,16 +61,6 @@ #include #include -/* Return the result of isatty, without changing errno. */ -static int -local_isatty (int fd) -{ - int save_errno = errno; - int res = __isatty (fd); - __set_errno (save_errno); - return res; -} - /* Allocate a file buffer, or switch to unbuffered I/O. Streams for TTY devices default to line buffered. */ int @@ -90,7 +80,7 @@ _IO_file_doallocate (FILE *fp) #ifdef DEV_TTY_P DEV_TTY_P (&st) || #endif - local_isatty (fp->_fileno)) + __isatty_nostatus (fp->_fileno)) fp->_flags |= _IO_LINE_BUF; } #if defined _STATBUF_ST_BLKSIZE diff --git a/sysdeps/unix/sysv/linux/isatty_nostatus.c b/sysdeps/unix/sysv/linux/isatty_nostatus.c new file mode 100644 index 000000000000..7f110be00c0a --- /dev/null +++ b/sysdeps/unix/sysv/linux/isatty_nostatus.c @@ -0,0 +1,29 @@ +/* Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* Return 1 if FD is a terminal, 0 if not, without changing errno */ +int +__isatty_nostatus (int fd) +{ + struct __kernel_termios k_termios; + return INTERNAL_SYSCALL_CALL (ioctl, fd, TCGETS, &k_termios) == 0; +} From patchwork Tue Jun 10 19:02:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114174 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6DDC385829B for ; Tue, 10 Jun 2025 19:25:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6DDC385829B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=mttq6wZB X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id D77303858D35 for ; Tue, 10 Jun 2025 19:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D77303858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D77303858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582210; cv=none; b=GjQREIFuHqEv2jE40rWfSja834AiRDLkoixAfeng7hSdlMEvwRR+idGQWkQK/S/cIbZDCdcgYbWPFxc5nDHxTMMFIcoSIit9zZ8o9RWFgI2oAqP5qK9CyJ7bu8IUz+a28cFf4PJVfNE7vyjbAgpzjH2En5ryWaIGsTeA/N7tg7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582210; c=relaxed/simple; bh=ijeJ36qC4D9RUAhPVnj1vaIHi1lT2/9kUvkB6R+wIlc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SjcyznowM2zUIZJy1dAks3aupfriVyJi+bi9Znq0gRJ/pmtrYohBvQpasl8PNaAvU8mIvmV94zTd9kGQTcOXTHHbNZerY9L7iAxeOqan5pe/FaNoEzoHKu/4N28TqwR+sIwyq1ZMHwSGYTLWLk6B+ui58z7LtCmg5sBRaSxZW4s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D77303858D35 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arg2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:53 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arg2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582174; bh=szPmPfwk4jPy+AF/BK7EtLDyN1IiLUw530rSkPdgrIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mttq6wZBIezZ12BTgy2s7pa3UNcclJOksNbYhexyFlvGVN4IBJtXZXCnFAE31vzU7 5Jdlr380KCwZQuv3JWFd6dtgtRXk5umtXKxO3TzLqqgdPMk6v+jJ1HiA0DSULztPRY kjt5rF1WrvtZNnQ7O/LhmowfAH9A1ICmYNbKQPWwnsz+4VxCp0utO0JpaRlgDFv6Gm WXB9SBQGN/Dab6lKjQVuVsFTc6Ij7BdWkE463TVDBN5HCiOHolA8AEpJwWXf7WOMaf Rf3vIdYn5TszuWsNBQoYO+AYdcOOjojHTO4Bjl/IW7s7YKR2fYj3oftYePnBeTZNK7 f1pLcfvnPc0Iw== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 03/15] linux/ioctls: use for sockios ioctls Date: Tue, 10 Jun 2025 12:02:14 -0700 Message-ID: <20250610190228.1124149-4-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" In the kernel, these are . The differences between and the copied data in are minor; mainly some #ifdefs, so try to use directly; it is hopefully clean enough these days to use directly. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/bits/ioctls.h | 85 +-------------------------- 1 file changed, 1 insertion(+), 84 deletions(-) diff --git a/sysdeps/unix/sysv/linux/bits/ioctls.h b/sysdeps/unix/sysv/linux/bits/ioctls.h index 7e226e4e8f13..1ddcd4f45aea 100644 --- a/sysdeps/unix/sysv/linux/bits/ioctls.h +++ b/sysdeps/unix/sysv/linux/bits/ioctls.h @@ -22,87 +22,4 @@ /* Use the definitions from the kernel header files. */ #include -/* Routing table calls. */ -#define SIOCADDRT 0x890B /* add routing table entry */ -#define SIOCDELRT 0x890C /* delete routing table entry */ -#define SIOCRTMSG 0x890D /* call to routing system */ - -/* Socket configuration controls. */ -#define SIOCGIFNAME 0x8910 /* get iface name */ -#define SIOCSIFLINK 0x8911 /* set iface channel */ -#define SIOCGIFCONF 0x8912 /* get iface list */ -#define SIOCGIFFLAGS 0x8913 /* get flags */ -#define SIOCSIFFLAGS 0x8914 /* set flags */ -#define SIOCGIFADDR 0x8915 /* get PA address */ -#define SIOCSIFADDR 0x8916 /* set PA address */ -#define SIOCGIFDSTADDR 0x8917 /* get remote PA address */ -#define SIOCSIFDSTADDR 0x8918 /* set remote PA address */ -#define SIOCGIFBRDADDR 0x8919 /* get broadcast PA address */ -#define SIOCSIFBRDADDR 0x891a /* set broadcast PA address */ -#define SIOCGIFNETMASK 0x891b /* get network PA mask */ -#define SIOCSIFNETMASK 0x891c /* set network PA mask */ -#define SIOCGIFMETRIC 0x891d /* get metric */ -#define SIOCSIFMETRIC 0x891e /* set metric */ -#define SIOCGIFMEM 0x891f /* get memory address (BSD) */ -#define SIOCSIFMEM 0x8920 /* set memory address (BSD) */ -#define SIOCGIFMTU 0x8921 /* get MTU size */ -#define SIOCSIFMTU 0x8922 /* set MTU size */ -#define SIOCSIFNAME 0x8923 /* set interface name */ -#define SIOCSIFHWADDR 0x8924 /* set hardware address */ -#define SIOCGIFENCAP 0x8925 /* get/set encapsulations */ -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 /* Get hardware address */ -#define SIOCGIFSLAVE 0x8929 /* Driver slaving support */ -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 /* Multicast address lists */ -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 /* name -> if_index mapping */ -#define SIOGIFINDEX SIOCGIFINDEX /* misprint compatibility :-) */ -#define SIOCSIFPFLAGS 0x8934 /* set/get extended flags set */ -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 /* delete PA address */ -#define SIOCSIFHWBROADCAST 0x8937 /* set hardware broadcast addr */ -#define SIOCGIFCOUNT 0x8938 /* get number of devices */ - -#define SIOCGIFBR 0x8940 /* Bridging support */ -#define SIOCSIFBR 0x8941 /* Set bridging options */ - -#define SIOCGIFTXQLEN 0x8942 /* Get the tx queue length */ -#define SIOCSIFTXQLEN 0x8943 /* Set the tx queue length */ - - -/* ARP cache control calls. */ - /* 0x8950 - 0x8952 * obsolete calls, don't re-use */ -#define SIOCDARP 0x8953 /* delete ARP table entry */ -#define SIOCGARP 0x8954 /* get ARP table entry */ -#define SIOCSARP 0x8955 /* set ARP table entry */ - -/* RARP cache control calls. */ -#define SIOCDRARP 0x8960 /* delete RARP table entry */ -#define SIOCGRARP 0x8961 /* get RARP table entry */ -#define SIOCSRARP 0x8962 /* set RARP table entry */ - -/* Driver configuration calls */ - -#define SIOCGIFMAP 0x8970 /* Get device parameters */ -#define SIOCSIFMAP 0x8971 /* Set device parameters */ - -/* DLCI configuration calls */ - -#define SIOCADDDLCI 0x8980 /* Create new DLCI device */ -#define SIOCDELDLCI 0x8981 /* Delete DLCI device */ - -/* Device private ioctl calls. */ - -/* These 16 ioctls are available to devices via the do_ioctl() device - vector. Each device should include this file and redefine these - names as their own. Because these are device dependent it is a good - idea _NOT_ to issue them to random objects and hope. */ - -#define SIOCDEVPRIVATE 0x89F0 /* to 89FF */ - -/* - * These 16 ioctl calls are protocol private - */ - -#define SIOCPROTOPRIVATE 0x89E0 /* to 89EF */ +#include From patchwork Tue Jun 10 19:02:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114159 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 384923858429 for ; Tue, 10 Jun 2025 19:06:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 384923858429 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=FT7Dxd2c X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 7CBF33858C98 for ; Tue, 10 Jun 2025 19:03:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7CBF33858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7CBF33858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582181; cv=none; b=A4NG90ngjSaJwJjJvVmPVtxulhcTw1wxs7rkWTi+fU01hrPRsv8CALHfN6zRFi9F45rQD/hVsJo7i9/5A3GYtKh52q7byC0VQdr4QHIjv3CJ5Y5JOq3Pnlm603DljpSxT229VqfHEq0k6b8/IQNc9MK3T4UZSJNcnU9tcz0JCbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582181; c=relaxed/simple; bh=Sbh3AAp1l6AmJm7nSpBFuH5WoeefkQ2mImyoEGerBRs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FEiNfXzYkcBUvcFmfUAlCGMbpo7AazTWQR9QXOviz3hQCT0PAbfp4WSyMU5xZyj8D1INH8jlCHb6D+PTlX/7tiyypsQKIFWUNmSZ5/e64nXBRMkGskDkewQo0Rom8GFc6aDOM7zEL3HAqeMIbnOJJaPNHpBg1gILfZHXSxnEX8Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CBF33858C98 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arh2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:54 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arh2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582174; bh=OhOfBI3kch55x0MvmfBFlNuAecsj43RbYsEopbFLhH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FT7Dxd2ciEsWHxHS2LO8U3lAGSOhXkUIxH2E6keuuebIAMcQGfOwkrHxyQaKG75aI oVDbTE+i05cBzZ/mo3FE8+Cd4r4d6AvMSEQGjGnPCUekgNrDTdTtbKheNq8yDafXgX e1lBdWDcx/+krowqMK6trthCli2v1/E4b5toHZK/3hnEvHD7UENQ1T9Y9e8GXY+S/Z JXxOnO10V75wrblozHLUuSOgtiF3jzs3wWosTvAte4zBg2flYCWV01S9vV3jpbPD6P XVLh2nGzfGn5d+ttPzLw6B633P/3ITpCk1t9ZbQSPnuWkHMaaOatx9+RyaZaI6n0kD Oel4zjHwOqffA== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 04/15] linux/termios/powerpc: deal with powerpc-unique ioctl emulation Date: Tue, 10 Jun 2025 12:02:15 -0700 Message-ID: <20250610190228.1124149-5-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" The powerpc architecture, only, emulates the termios ioctls using the glibc termios structure. Export the real kernel ones as the termios2 interface; although the kernel doesn't call it termios2, it is exactly the termios2 interface, and it avoids the namespace clash between the emulated ioctls and the real kernel ioctls. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h b/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h new file mode 100644 index 000000000000..e1921dfb86c0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/bits/ioctls.h @@ -0,0 +1,36 @@ +/* Copyright (C) 1996-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_IOCTL_H +# error "Never use directly; include instead." +#endif + +/* Use the definitions from the kernel header files. */ +#include + +/* PowerPC quirk: on PowerPC only, ioctl() emulates the TCGETS/TCSETS* + ioctls with tcgetattr/tcsetattr using the glibc struct termios. + As struct termios2 is the same as the kernel struct termios on PowerPC, + simply consider the kernel ones as the termios2 interface, even + though the kernel doesn't call it that. */ + +#define TCGETS2 _IOR ('t', 19, struct termios2) +#define TCSETS2 _IOW ('t', 20, struct termios2) +#define TCSETSW2 _IOW ('t', 21, struct termios2) +#define TCSETSF2 _IOW ('t', 22, struct termios2) + +#include From patchwork Tue Jun 10 19:02:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114173 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E3BF3858429 for ; Tue, 10 Jun 2025 19:24:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E3BF3858429 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=g0BMJf3p X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 299393858D3C for ; Tue, 10 Jun 2025 19:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 299393858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 299393858D3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582209; cv=none; b=MP8qub5ngOR89QotT/c+CpFfWXt4OY57gQdJ13SSsxtABbpXPlwHRavWe9cYuC/eWB3iWdYuFLPDDIoBy0DK8J7ANgNvhNrs4BM+G68dSNQ9FWp4gleBJiaLFz2fEU8PM1k5EHwNrEBMAtaukG+ON+D9A17bTXWXhbfcRiPASmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582209; c=relaxed/simple; bh=SPeTxRErXQ3JMHpPMS2xPVHKvxadCHEEk1j7bv0UR+A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iCoyja5D+mvlJVyfQbh9ZWFl8tl/zND6tIfFXK4joid87U0NCeiRpJp647JHK1hKpTcnVcgv9wePxN9lsi41JsZcwpZ6tFAuek5qKaqmSw9qlZuXmVXD1XCnQzxMIN68UVDNqJJ8hk2brhDvDp/9o17OarnjRpOmNy+Mgd6n32E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 299393858D3C Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2ari2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:54 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2ari2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582175; bh=zR6dI23o/W9RXvR+FywcPhq32RCf3C/VYeMShn1h9TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g0BMJf3pffxRtRkhJBtSZLSG+jYV1szFID9KVSmfGrof1S0OXLUQmAcQoVPFBPGPY 2hvzGSWpr6kBQGnOqdSk0ZXdWJ6SfrKPQqv8XTWpStrH5TucbIvsiRfaUiYZWB2sAW GlOgOZHUm4BSxxT4tF374rTxhBwFZE2Wu7B5vUFA598mMso8bGPaYqUXmAyFbyfTko siEBl3Z12YuGEPlM3QZCWXqtv8zXV3ZoJfMMkdxHKNuyihqay4H/AkM5u91K6tyCXC t4+nFWw1NYNgKUQN704KUeC/GzbaxyDklDwceaLVFQYTFgamVuPJYxidqMqv6mNADl gAeX/IRKhOfLg== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 05/15] linux: implement arbitrary and split speeds in termios Date: Tue, 10 Jun 2025 12:02:16 -0700 Message-ID: <20250610190228.1124149-6-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Linux has supported arbitrary speeds and split speeds in the kernel since 2008 on all platforms except Alpha (fixed in 2020), but glibc was never updated to match. This is further complicated by POSIX uses of macros for the cf[gs]et[io]speed interfaces, rather than plain numbers, as it really ought to have. On most platforms, the glibc ABI includes the c_[io]speed fields in struct termios, but they are incorrectly used. On MIPS and SPARC, they are entirely missing. For backwards compatibility, the kernel will still use the legacy speed fields unless they are set to BOTHER, and will use the legacy output speed as the input speed if the latter is 0 (== B0). However, the specific encoding used is visible to user space applications, including ones other than the one running. - SPARC and MIPS get a new struct termios, and tc[gs]etattr() is versioned accordingly. However, the new struct termios is set to be a strict extension of the old one, which means that cf* interfaces other than the speed-related ones do not need versioning. - The Bxxx constants are redefined as equivalent to their integer values and the legacy Bxxx constants are renamed __Bxxx. - cf[gs]et[io]speed() and cfsetspeed() are versioned accordingly. - tcgetattr() and cfset[io]speed() are adjusted to always keep the c_[io]speed fields correct (unlike earlier versions), but to canonicalize the representation to ALSO configure the legacy fields if a valid legacy representation exists. - tcsetattr(), too, canonicalizes the representation in this way before passing it to the kernel, to maximize compatibility with older applications/tools. - The old IBAUD0 hack is removed; it is no longer necessary since even the legacy c_cflag baud rate fields have had separate input values for a long time. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- NEWS | 4 + sysdeps/unix/sysv/linux/Versions | 7 + sysdeps/unix/sysv/linux/aarch64/libc.abilist | 5 + .../sysv/linux/alpha/bits/termios-c_cflag.h | 2 + .../bits/{termios-baud.h => termios-cbaud.h} | 43 +-- .../unix/sysv/linux/alpha/kernel-features.h | 11 + .../unix/sysv/linux/alpha/kernel_termios.h | 43 --- sysdeps/unix/sysv/linux/alpha/libc.abilist | 5 + sysdeps/unix/sysv/linux/arc/libc.abilist | 5 + sysdeps/unix/sysv/linux/arm/be/libc.abilist | 5 + sysdeps/unix/sysv/linux/arm/le/libc.abilist | 5 + sysdeps/unix/sysv/linux/bits/termios-baud.h | 65 ++-- .../unix/sysv/linux/bits/termios-c_cflag.h | 4 +- sysdeps/unix/sysv/linux/bits/termios-cbaud.h | 47 +++ sysdeps/unix/sysv/linux/bits/termios.h | 50 ++- sysdeps/unix/sysv/linux/cfsetspeed.c | 58 +++ sysdeps/unix/sysv/linux/csky/libc.abilist | 5 + sysdeps/unix/sysv/linux/hppa/libc.abilist | 5 + sysdeps/unix/sysv/linux/i386/libc.abilist | 5 + .../{sparc/kernel_termios.h => isatty.c} | 36 +- sysdeps/unix/sysv/linux/isatty_nostatus.c | 9 +- sysdeps/unix/sysv/linux/kernel-features.h | 4 + sysdeps/unix/sysv/linux/kernel_termios.h | 20 +- .../sysv/linux/loongarch/lp64/libc.abilist | 5 + .../sysv/linux/m68k/coldfire/libc.abilist | 5 + .../unix/sysv/linux/m68k/m680x0/libc.abilist | 5 + .../sysv/linux/microblaze/be/libc.abilist | 5 + .../sysv/linux/microblaze/le/libc.abilist | 5 + sysdeps/unix/sysv/linux/mips/Versions | 4 + .../sysv/linux/mips/mips32/fpu/libc.abilist | 7 + .../sysv/linux/mips/mips32/nofpu/libc.abilist | 7 + .../sysv/linux/mips/mips64/n32/libc.abilist | 7 + .../sysv/linux/mips/mips64/n64/libc.abilist | 7 + .../{bits/termios-struct.h => old_termios.h} | 22 +- .../bits/termios-struct.h => old_termios.h} | 27 +- sysdeps/unix/sysv/linux/or1k/libc.abilist | 5 + .../sysv/linux/powerpc/bits/termios-c_cflag.h | 4 +- .../bits/{termios-baud.h => termios-cbaud.h} | 42 +- .../unix/sysv/linux/powerpc/kernel_termios.h | 53 --- .../linux/powerpc/powerpc32/fpu/libc.abilist | 5 + .../powerpc/powerpc32/nofpu/libc.abilist | 5 + .../linux/powerpc/powerpc64/be/libc.abilist | 5 + .../linux/powerpc/powerpc64/le/libc.abilist | 5 + .../unix/sysv/linux/riscv/rv32/libc.abilist | 5 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 5 + .../unix/sysv/linux/s390/s390-32/libc.abilist | 5 + .../unix/sysv/linux/s390/s390-64/libc.abilist | 5 + sysdeps/unix/sysv/linux/sh/be/libc.abilist | 5 + sysdeps/unix/sysv/linux/sh/le/libc.abilist | 5 + sysdeps/unix/sysv/linux/sparc/Versions | 4 + .../bits/{termios-baud.h => termios-cbaud.h} | 39 +- .../kernel_termios.h => sparc/old_termios.h} | 25 +- .../sysv/linux/sparc/sparc32/libc.abilist | 7 + .../sysv/linux/sparc/sparc64/libc.abilist | 7 + sysdeps/unix/sysv/linux/speed.c | 359 +++++++++++++++--- sysdeps/unix/sysv/linux/tcgetattr.c | 85 ++--- sysdeps/unix/sysv/linux/tcsetattr.c | 123 +++--- sysdeps/unix/sysv/linux/termios_internals.h | 116 ++++++ .../unix/sysv/linux/x86_64/64/libc.abilist | 5 + .../unix/sysv/linux/x86_64/x32/libc.abilist | 5 + 60 files changed, 1044 insertions(+), 434 deletions(-) rename sysdeps/unix/sysv/linux/alpha/bits/{termios-baud.h => termios-cbaud.h} (58%) delete mode 100644 sysdeps/unix/sysv/linux/alpha/kernel_termios.h create mode 100644 sysdeps/unix/sysv/linux/bits/termios-cbaud.h create mode 100644 sysdeps/unix/sysv/linux/cfsetspeed.c rename sysdeps/unix/sysv/linux/{sparc/kernel_termios.h => isatty.c} (51%) rename sysdeps/unix/sysv/linux/mips/{bits/termios-struct.h => old_termios.h} (67%) rename sysdeps/unix/sysv/linux/{sparc/bits/termios-struct.h => old_termios.h} (50%) rename sysdeps/unix/sysv/linux/powerpc/bits/{termios-baud.h => termios-cbaud.h} (58%) delete mode 100644 sysdeps/unix/sysv/linux/powerpc/kernel_termios.h rename sysdeps/unix/sysv/linux/sparc/bits/{termios-baud.h => termios-cbaud.h} (57%) rename sysdeps/unix/sysv/linux/{mips/kernel_termios.h => sparc/old_termios.h} (67%) create mode 100644 sysdeps/unix/sysv/linux/termios_internals.h diff --git a/NEWS b/NEWS index afe8076dfc9d..cc668344c122 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,10 @@ Major new features: * The ISO C2Y family of unsigned abs functions, i.e. uabs, ulabs, ullabs and uimaxabs, are now supported. +* On Linux, the interface now supports arbitrary baud rates; + speed_t is redefined to simply be the baud rate specified as an + unsigned int, which matches the kernel interface. + Deprecated and removed features, and other changes affecting compatibility: * The glibc.rtld.execstack now supports a compatibility mode to allow diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index 55d565545ab3..b721331bf71d 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -332,6 +332,13 @@ libc { sched_getattr; sched_setattr; } + GLIBC_2.42 { + cfgetospeed; + cfgetispeed; + cfsetospeed; + cfsetispeed; + cfsetspeed; + } GLIBC_PRIVATE { # functions used in other libraries __syscall_rt_sigqueueinfo; diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index aa6bf483dd70..fdccf84d8f88 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2752,6 +2752,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/alpha/bits/termios-c_cflag.h b/sysdeps/unix/sysv/linux/alpha/bits/termios-c_cflag.h index 1f9f7f2680d1..d8308848c624 100644 --- a/sysdeps/unix/sysv/linux/alpha/bits/termios-c_cflag.h +++ b/sysdeps/unix/sysv/linux/alpha/bits/termios-c_cflag.h @@ -36,4 +36,6 @@ #ifdef __USE_MISC # define ADDRB 04000000000 +# define CMSPAR 010000000000 /* Mark or space (stick) parity. */ +# define CRTSCTS 020000000000 /* Flow control. */ #endif diff --git a/sysdeps/unix/sysv/linux/alpha/bits/termios-baud.h b/sysdeps/unix/sysv/linux/alpha/bits/termios-cbaud.h similarity index 58% rename from sysdeps/unix/sysv/linux/alpha/bits/termios-baud.h rename to sysdeps/unix/sysv/linux/alpha/bits/termios-cbaud.h index 324d5d8776d3..69421f679710 100644 --- a/sysdeps/unix/sysv/linux/alpha/bits/termios-baud.h +++ b/sysdeps/unix/sysv/linux/alpha/bits/termios-cbaud.h @@ -17,30 +17,29 @@ . */ #ifndef _TERMIOS_H -# error "Never include directly; use instead." +# error "Never include directly; use instead." #endif #ifdef __USE_MISC -# define CBAUD 0000037 -# define CBAUDEX 0000000 -# define CMSPAR 010000000000 /* mark or space (stick) parity */ -# define CRTSCTS 020000000000 /* flow control */ +# define CBAUD 000000037 +# define CBAUDEX 000000000 +# define CIBAUD 007600000 +# define IBSHIFT 16 #endif -#define B57600 00020 -#define B115200 00021 -#define B230400 00022 -#define B460800 00023 -#define B500000 00024 -#define B576000 00025 -#define B921600 00026 -#define B1000000 00027 -#define B1152000 00030 -#define B1500000 00031 -#define B2000000 00032 -#define B2500000 00033 -#define B3000000 00034 -#define B3500000 00035 -#define B4000000 00036 - -#define __MAX_BAUD B4000000 +#define __B57600 00020 +#define __B115200 00021 +#define __B230400 00022 +#define __B460800 00023 +#define __B500000 00024 +#define __B576000 00025 +#define __B921600 00026 +#define __B1000000 00027 +#define __B1152000 00030 +#define __B1500000 00031 +#define __B2000000 00032 +#define __B2500000 00033 +#define __B3000000 00034 +#define __B3500000 00035 +#define __B4000000 00036 +#define __BOTHER 00037 diff --git a/sysdeps/unix/sysv/linux/alpha/kernel-features.h b/sysdeps/unix/sysv/linux/alpha/kernel-features.h index 6eae48f13e74..83fdf91222a7 100644 --- a/sysdeps/unix/sysv/linux/alpha/kernel-features.h +++ b/sysdeps/unix/sysv/linux/alpha/kernel-features.h @@ -54,4 +54,15 @@ #undef __ASSUME_CLONE3 #define __ASSUME_CLONE3 0 +/* Alpha did not provide BOTHER, CIBAUD or the termios2 ioctls until + kernel 4.20. Even though struct __kernel_termios and struct + termios2 are the same on Alpha, Calling the legacy TCSETS* ioctls + with BOTHER set triggers a bug in these old kernels, so only use + the legacy TCSETS* ioctl numbers if neither BOTHER nor split speed is + needed; that way the code will fail gracefully. */ +#if __LINUX_KERNEL_VERSION < 0x041400 +# undef __ASSUME_TERMIOS2 +# define __ASSUME_TERMIOS2 0 +#endif + #endif /* _KERNEL_FEATURES_H */ diff --git a/sysdeps/unix/sysv/linux/alpha/kernel_termios.h b/sysdeps/unix/sysv/linux/alpha/kernel_termios.h deleted file mode 100644 index 6a777ddb6e77..000000000000 --- a/sysdeps/unix/sysv/linux/alpha/kernel_termios.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (C) 1997-2025 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#ifndef _KERNEL_TERMIOS_H -#define _KERNEL_TERMIOS_H 1 - -/* The following corresponds to the values from the Linux 2.1.20 kernel. */ - -/* We need the definition of tcflag_t, cc_t, and speed_t. */ -#include - -#define __KERNEL_NCCS 19 - -struct __kernel_termios - { - tcflag_t c_iflag; /* input mode flags */ - tcflag_t c_oflag; /* output mode flags */ - tcflag_t c_cflag; /* control mode flags */ - tcflag_t c_lflag; /* local mode flags */ - cc_t c_cc[__KERNEL_NCCS]; /* control characters */ - cc_t c_line; /* line discipline */ - speed_t c_ispeed; /* input speed */ - speed_t c_ospeed; /* output speed */ - }; - -#define _HAVE_C_ISPEED 1 -#define _HAVE_C_OSPEED 1 - -#endif /* kernel_termios.h */ diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index d5df9656a892..1e3f2781553e 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -3099,6 +3099,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index c46c08da85c9..7b7717d1d146 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -2513,6 +2513,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index 4df150c0f042..f64bf3f3278e 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -2805,6 +2805,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index be294783f685..c065fe80fcd0 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -2802,6 +2802,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/bits/termios-baud.h b/sysdeps/unix/sysv/linux/bits/termios-baud.h index e63a3eb4182e..1e41338b5739 100644 --- a/sysdeps/unix/sysv/linux/bits/termios-baud.h +++ b/sysdeps/unix/sysv/linux/bits/termios-baud.h @@ -20,29 +20,44 @@ # error "Never include directly; use instead." #endif -#ifdef __USE_MISC -# define CBAUD 000000010017 /* Baud speed mask (not in POSIX). */ -# define CBAUDEX 000000010000 /* Extra baud speed mask, included in CBAUD. - (not in POSIX). */ -# define CIBAUD 002003600000 /* Input baud rate (not used). */ -# define CMSPAR 010000000000 /* Mark or space (stick) parity. */ -# define CRTSCTS 020000000000 /* Flow control. */ -#endif +#define B0 0U +#define B50 50U +#define B75 75U +#define B110 110U +#define B134 134U +#define B150 150U +#define B200 200U +#define B300 300U +#define B600 600U +#define B1200 1200U +#define B1800 1800U +#define B2400 2400U +#define B4800 4800U +#define B7200 7200U +#define B9600 9600U +#define B14400 14400U +#define B19200 19200U +#define B28800 28800U +#define B33600 33600U +#define B38400 38400U +#define B57600 57600U +#define B76800 76800U +#define B115200 115200U +#define B153600 153600U +#define B230400 230400U +#define B307200 307200U +#define B460800 460800U +#define B500000 500000U +#define B576000 576000U +#define B614400 614400U +#define B921600 921600U +#define B1000000 1000000U +#define B1152000 1152000U +#define B1500000 1500000U +#define B2000000 2000000U +#define B2500000 2500000U +#define B3000000 3000000U +#define B3500000 3500000U +#define B4000000 4000000U -/* Extra output baud rates (not in POSIX). */ -#define B57600 0010001 -#define B115200 0010002 -#define B230400 0010003 -#define B460800 0010004 -#define B500000 0010005 -#define B576000 0010006 -#define B921600 0010007 -#define B1000000 0010010 -#define B1152000 0010011 -#define B1500000 0010012 -#define B2000000 0010013 -#define B2500000 0010014 -#define B3000000 0010015 -#define B3500000 0010016 -#define B4000000 0010017 -#define __MAX_BAUD B4000000 +#define __MAX_BAUD 4294967295U diff --git a/sysdeps/unix/sysv/linux/bits/termios-c_cflag.h b/sysdeps/unix/sysv/linux/bits/termios-c_cflag.h index bbbb621d4ef0..befd25a758dd 100644 --- a/sysdeps/unix/sysv/linux/bits/termios-c_cflag.h +++ b/sysdeps/unix/sysv/linux/bits/termios-c_cflag.h @@ -34,5 +34,7 @@ #define CLOCAL 0004000 #ifdef __USE_MISC -# define ADDRB 04000000000 +# define ADDRB 04000000000 +# define CMSPAR 010000000000 /* Mark or space (stick) parity. */ +# define CRTSCTS 020000000000 /* Flow control. */ #endif diff --git a/sysdeps/unix/sysv/linux/bits/termios-cbaud.h b/sysdeps/unix/sysv/linux/bits/termios-cbaud.h new file mode 100644 index 000000000000..bdc702074371 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/termios-cbaud.h @@ -0,0 +1,47 @@ +/* termios baud rate selection definitions. Linux/generic version. + Copyright (C) 2019-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + . */ + +#ifndef _TERMIOS_H +# error "Never include directly; use instead." +#endif + +#ifdef __USE_MISC +# define CBAUD 000000010017 /* Baud speed mask (not in POSIX). */ +# define CBAUDEX 000000010000 /* Extra baud speed mask, included in CBAUD. + (not in POSIX). */ +# define CIBAUD 002003600000 /* Input baud rate. */ +# define IBSHIFT 16 +#endif + +/* Extra output baud rates (not in POSIX). */ +#define __BOTHER 0010000 +#define __B57600 0010001 +#define __B115200 0010002 +#define __B230400 0010003 +#define __B460800 0010004 +#define __B500000 0010005 +#define __B576000 0010006 +#define __B921600 0010007 +#define __B1000000 0010010 +#define __B1152000 0010011 +#define __B1500000 0010012 +#define __B2000000 0010013 +#define __B2500000 0010014 +#define __B3000000 0010015 +#define __B3500000 0010016 +#define __B4000000 0010017 diff --git a/sysdeps/unix/sysv/linux/bits/termios.h b/sysdeps/unix/sysv/linux/bits/termios.h index 3bd1e228297c..14de3fcb5507 100644 --- a/sysdeps/unix/sysv/linux/bits/termios.h +++ b/sysdeps/unix/sysv/linux/bits/termios.h @@ -24,35 +24,41 @@ typedef unsigned char cc_t; typedef unsigned int speed_t; typedef unsigned int tcflag_t; -#include +#ifdef _TERMIOS_H +# include +#endif + #include #include #include /* c_cflag bit meaning */ -#define B0 0000000 /* hang up */ -#define B50 0000001 -#define B75 0000002 -#define B110 0000003 -#define B134 0000004 -#define B150 0000005 -#define B200 0000006 -#define B300 0000007 -#define B600 0000010 -#define B1200 0000011 -#define B1800 0000012 -#define B2400 0000013 -#define B4800 0000014 -#define B9600 0000015 -#define B19200 0000016 -#define B38400 0000017 +#include + +#define __B0 0000000 /* hang up */ +#define __B50 0000001 +#define __B75 0000002 +#define __B110 0000003 +#define __B134 0000004 +#define __B150 0000005 +#define __B200 0000006 +#define __B300 0000007 +#define __B600 0000010 +#define __B1200 0000011 +#define __B1800 0000012 +#define __B2400 0000013 +#define __B4800 0000014 +#define __B9600 0000015 +#define __B19200 0000016 +#define __B38400 0000017 +#include + #ifdef __USE_MISC -# define EXTA B19200 -# define EXTB B38400 +# define EXTA __B19200 +# define EXTB __B38400 +# define BOTHER __BOTHER #endif -#include -#include #include #ifdef __USE_MISC @@ -74,3 +80,5 @@ typedef unsigned int tcflag_t; #include #include + +#include diff --git a/sysdeps/unix/sysv/linux/cfsetspeed.c b/sysdeps/unix/sysv/linux/cfsetspeed.c new file mode 100644 index 000000000000..4a8f9b2ca186 --- /dev/null +++ b/sysdeps/unix/sysv/linux/cfsetspeed.c @@ -0,0 +1,58 @@ +/* cfsetspeed(), Linux version. + Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */ +int +__cfsetspeed (struct termios *termios_p, speed_t speed) +{ + tcflag_t cbaud = ___speed_to_cbaud (speed); + + termios_p->c_ospeed = speed; + termios_p->c_ispeed = speed; + termios_p->c_cflag &= ~(CBAUD | CIBAUD); + termios_p->c_cflag |= cbaud | (cbaud << IBSHIFT); + + return 0; +} +versioned_symbol (libc, __cfsetspeed, cfsetspeed, GLIBC_2_42); + +#if _TERMIOS_OLD_COMPAT + +int +attribute_compat_text_section +__old_cfsetspeed (old_termios_t *termios_p, speed_t speed) +{ + speed_t real_speed = ___cbaud_to_speed (speed, -1); + if (real_speed == (speed_t)-1) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + +#if !_HAVE_STRUCT_OLD_TERMIOS + /* Otherwise these fields don't exist in old_termios_t */ + termios_p->c_ospeed = real_speed; + termios_p->c_ispeed = real_speed; +#endif + termios_p->c_cflag &= ~(CBAUD | CIBAUD); + termios_p->c_cflag |= speed | (speed << IBSHIFT); + + return 0; +} +compat_symbol (libc, __old_cfsetspeed, cfsetspeed, GLIBC_2_0); + +#endif /* _TERMIOS_OLD_COMPAT */ diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index f123757134c6..69ba60ea093e 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2789,6 +2789,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index 2dc85b953303..dea7c09692bd 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2826,6 +2826,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 1e38217ec6ad..4c05ab1c6e07 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -3009,6 +3009,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sparc/kernel_termios.h b/sysdeps/unix/sysv/linux/isatty.c similarity index 51% rename from sysdeps/unix/sysv/linux/sparc/kernel_termios.h rename to sysdeps/unix/sysv/linux/isatty.c index 401079c4e55d..8828c0df93cf 100644 --- a/sysdeps/unix/sysv/linux/sparc/kernel_termios.h +++ b/sysdeps/unix/sysv/linux/isatty.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2025 Free Software Foundation, Inc. +/* Copyright (C) 1991-2025 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -15,26 +15,14 @@ License along with the GNU C Library; if not, see . */ -#ifndef _KERNEL_TERMIOS_H -#define _KERNEL_TERMIOS_H 1 -/* The following corresponds to the values from the Linux 2.1.20 kernel. */ - -/* We need the definition of tcflag_t, cc_t, and speed_t. */ -#include - -#define __KERNEL_NCCS 17 - -struct __kernel_termios - { - tcflag_t c_iflag; /* input mode flags */ - tcflag_t c_oflag; /* output mode flags */ - tcflag_t c_cflag; /* control mode flags */ - tcflag_t c_lflag; /* local mode flags */ - cc_t c_line; /* line discipline */ - cc_t c_cc[__KERNEL_NCCS]; /* control characters */ - }; - -#define _HAVE_C_ISPEED 0 -#define _HAVE_C_OSPEED 0 - -#endif /* kernel_termios.h */ +#include + +/* Return 1 if FD is a terminal, 0 if not. This simply does a + TCGETS2 ioctl into a dummy buffer without parsing the result. */ +int +__isatty (int fd) +{ + struct termios2 k_termios; + return INLINE_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios) == 0; +} +weak_alias (__isatty, isatty) diff --git a/sysdeps/unix/sysv/linux/isatty_nostatus.c b/sysdeps/unix/sysv/linux/isatty_nostatus.c index 7f110be00c0a..406decba62a1 100644 --- a/sysdeps/unix/sysv/linux/isatty_nostatus.c +++ b/sysdeps/unix/sysv/linux/isatty_nostatus.c @@ -15,15 +15,12 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include +#include /* Return 1 if FD is a terminal, 0 if not, without changing errno */ int __isatty_nostatus (int fd) { - struct __kernel_termios k_termios; - return INTERNAL_SYSCALL_CALL (ioctl, fd, TCGETS, &k_termios) == 0; + struct termios2 k_termios; + return INTERNAL_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios) == 0; } diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index 86b2d3ce5125..a49a9159cfa7 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -54,6 +54,10 @@ configurations). */ #define __ASSUME_SET_ROBUST_LIST 1 +/* The termios2 interface was introduced across all architectures except + Alpha in kernel 2.6.22. */ +#define __ASSUME_TERMIOS2 1 + /* Support for various CLOEXEC and NONBLOCK flags was added in 2.6.27. */ #define __ASSUME_IN_NONBLOCK 1 diff --git a/sysdeps/unix/sysv/linux/kernel_termios.h b/sysdeps/unix/sysv/linux/kernel_termios.h index f02a197518b5..8dbe9f2ba89f 100644 --- a/sysdeps/unix/sysv/linux/kernel_termios.h +++ b/sysdeps/unix/sysv/linux/kernel_termios.h @@ -17,21 +17,29 @@ #ifndef _KERNEL_TERMIOS_H #define _KERNEL_TERMIOS_H 1 -/* The following corresponds to the values from the Linux 2.1.20 kernel. */ +/* The following corresponds to the values from the Linux 2.6.23 kernel. */ -#define __KERNEL_NCCS 19 +#ifdef __mips__ +# define __KERNEL_NCCS 23 +#else +# define __KERNEL_NCCS 19 +#endif -struct __kernel_termios +struct termios2 { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ +#if defined(__alpha__) || defined(__powerpc__) + cc_t c_cc[__KERNEL_NCCS]; /* control characters */ + cc_t c_line; /* line discipline */ +#else cc_t c_line; /* line discipline */ cc_t c_cc[__KERNEL_NCCS]; /* control characters */ +#endif + speed_t c_ispeed; /* input speed */ + speed_t c_ospeed; /* output speed */ }; -#define _HAVE_C_ISPEED 0 -#define _HAVE_C_OSPEED 0 - #endif /* kernel_termios.h */ diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist index 927fc2144526..6ab4968d17ce 100644 --- a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist @@ -2273,6 +2273,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist index 74da49d9da42..e553bdc8a3b0 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist @@ -2785,6 +2785,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist index e5d678111f49..1239f0d7a029 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist @@ -2952,6 +2952,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist index 4dbd4b60450f..943e89a45fd4 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist @@ -2838,6 +2838,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist index c5965bb50cf5..9c303d9d9aa8 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist @@ -2835,6 +2835,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/mips/Versions b/sysdeps/unix/sysv/linux/mips/Versions index 9ea0fa65a4ac..48f0037fe62a 100644 --- a/sysdeps/unix/sysv/linux/mips/Versions +++ b/sysdeps/unix/sysv/linux/mips/Versions @@ -26,6 +26,10 @@ libc { pthread_attr_setstack; pthread_attr_setstacksize; } + GLIBC_2.42 { + tcgetattr; + tcsetattr; + } GLIBC_PRIVATE { # nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime). __vdso_clock_gettime; diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist index 10715e07779f..6eb6fd476b0d 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist @@ -2913,7 +2913,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F +GLIBC_2.42 tcgetattr F +GLIBC_2.42 tcsetattr F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F GLIBC_2.42 ulabs F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist index 3d229b9853f0..58a43bb9b3d3 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist @@ -2911,7 +2911,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F +GLIBC_2.42 tcgetattr F +GLIBC_2.42 tcsetattr F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F GLIBC_2.42 ulabs F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist index e4cb45275b98..abab2ad80758 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist @@ -2919,7 +2919,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F +GLIBC_2.42 tcgetattr F +GLIBC_2.42 tcsetattr F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F GLIBC_2.42 ulabs F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist index 8a32d2585dcc..2e31f6eed6b7 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist @@ -2821,7 +2821,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F +GLIBC_2.42 tcgetattr F +GLIBC_2.42 tcsetattr F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F GLIBC_2.42 ulabs F diff --git a/sysdeps/unix/sysv/linux/mips/bits/termios-struct.h b/sysdeps/unix/sysv/linux/mips/old_termios.h similarity index 67% rename from sysdeps/unix/sysv/linux/mips/bits/termios-struct.h rename to sysdeps/unix/sysv/linux/mips/old_termios.h index ef698218f3a2..33fc8e0aa8a2 100644 --- a/sysdeps/unix/sysv/linux/mips/bits/termios-struct.h +++ b/sysdeps/unix/sysv/linux/mips/old_termios.h @@ -1,5 +1,6 @@ -/* struct termios definition. Linux/mips version. - Copyright (C) 2019-2025 Free Software Foundation, Inc. +/* old_termios.h for Linux/MIPS + + Copyright (C) 1991-2025 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -13,22 +14,17 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see + License along with the GNU C Library; if not, see . */ +#define _HAVE_STRUCT_OLD_TERMIOS 1 -#ifndef _TERMIOS_H -# error "Never include directly; use instead." -#endif - -#define NCCS 32 -struct termios +#define OLD_NCCS 32 +typedef struct old_termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ - cc_t c_cc[NCCS]; /* control characters */ -#define _HAVE_STRUCT_TERMIOS_C_ISPEED 0 -#define _HAVE_STRUCT_TERMIOS_C_OSPEED 0 - }; + cc_t c_cc[OLD_NCCS]; /* control characters */ + } old_termios_t; diff --git a/sysdeps/unix/sysv/linux/sparc/bits/termios-struct.h b/sysdeps/unix/sysv/linux/old_termios.h similarity index 50% rename from sysdeps/unix/sysv/linux/sparc/bits/termios-struct.h rename to sysdeps/unix/sysv/linux/old_termios.h index 269ca9d67583..56d19baee235 100644 --- a/sysdeps/unix/sysv/linux/sparc/bits/termios-struct.h +++ b/sysdeps/unix/sysv/linux/old_termios.h @@ -1,5 +1,6 @@ -/* struct termios definition. Linux/sparc version. - Copyright (C) 2019-2025 Free Software Foundation, Inc. +/* old_termios.h for Linux other than MIPS and SPARC + + Copyright (C) 2025 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -13,22 +14,10 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see + License along with the GNU C Library; if not, see . */ -#ifndef _TERMIOS_H -# error "Never include directly; use instead." -#endif - -#define NCCS 17 -struct termios - { - tcflag_t c_iflag; /* input mode flags */ - tcflag_t c_oflag; /* output mode flags */ - tcflag_t c_cflag; /* control mode flags */ - tcflag_t c_lflag; /* local mode flags */ - cc_t c_line; /* line discipline */ - cc_t c_cc[NCCS]; /* control characters */ -#define _HAVE_STRUCT_TERMIOS_C_ISPEED 0 -#define _HAVE_STRUCT_TERMIOS_C_OSPEED 0 - }; +/* By default, no old termios structure */ +#define _HAVE_STRUCT_OLD_TERMIOS 0 +#define OLD_NCCS NCCS +typedef struct termios old_termios_t; diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist index 64dac95b2afd..b54c078b520c 100644 --- a/sysdeps/unix/sysv/linux/or1k/libc.abilist +++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist @@ -2263,6 +2263,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/termios-c_cflag.h b/sysdeps/unix/sysv/linux/powerpc/bits/termios-c_cflag.h index 9ea8cfbe725e..a90d581484ef 100644 --- a/sysdeps/unix/sysv/linux/powerpc/bits/termios-c_cflag.h +++ b/sysdeps/unix/sysv/linux/powerpc/bits/termios-c_cflag.h @@ -35,5 +35,7 @@ #define CLOCAL 00100000 #ifdef __USE_MISC -# define ADDRB 04000000000 +# define ADDRB 04000000000 +# define CMSPAR 010000000000 /* Mark or space (stick) parity. */ +# define CRTSCTS 020000000000 /* Flow control. */ #endif diff --git a/sysdeps/unix/sysv/linux/powerpc/bits/termios-baud.h b/sysdeps/unix/sysv/linux/powerpc/bits/termios-cbaud.h similarity index 58% rename from sysdeps/unix/sysv/linux/powerpc/bits/termios-baud.h rename to sysdeps/unix/sysv/linux/powerpc/bits/termios-cbaud.h index 374d9f89498f..7bcbba441ae8 100644 --- a/sysdeps/unix/sysv/linux/powerpc/bits/termios-baud.h +++ b/sysdeps/unix/sysv/linux/powerpc/bits/termios-cbaud.h @@ -17,29 +17,29 @@ . */ #ifndef _TERMIOS_H -# error "Never include directly; use instead." +# error "Never include directly; use instead." #endif #ifdef __USE_MISC -# define CBAUD 0000377 -# define CBAUDEX 0000020 -# define CMSPAR 010000000000 /* mark or space (stick) parity */ -# define CRTSCTS 020000000000 /* flow control */ +# define CBAUD 000000377 +# define CBAUDEX 000000020 +# define CIBAUD 077600000 +# define IBSHIFT 16 #endif -#define B57600 00020 -#define B115200 00021 -#define B230400 00022 -#define B460800 00023 -#define B500000 00024 -#define B576000 00025 -#define B921600 00026 -#define B1000000 00027 -#define B1152000 00030 -#define B1500000 00031 -#define B2000000 00032 -#define B2500000 00033 -#define B3000000 00034 -#define B3500000 00035 -#define B4000000 00036 -#define __MAX_BAUD B4000000 +#define __B57600 00020 +#define __B115200 00021 +#define __B230400 00022 +#define __B460800 00023 +#define __B500000 00024 +#define __B576000 00025 +#define __B921600 00026 +#define __B1000000 00027 +#define __B1152000 00030 +#define __B1500000 00031 +#define __B2000000 00032 +#define __B2500000 00033 +#define __B3000000 00034 +#define __B3500000 00035 +#define __B4000000 00036 +#define __BOTHER 00037 diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h b/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h deleted file mode 100644 index f6ea570ebea0..000000000000 --- a/sysdeps/unix/sysv/linux/powerpc/kernel_termios.h +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 1997-2025 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _KERNEL_TERMIOS_H -#define _KERNEL_TERMIOS_H 1 - -/* We need the definition of tcflag_t, cc_t, and speed_t. */ -#include - -#define __KERNEL_NCCS 19 - -struct __kernel_termios - { - tcflag_t c_iflag; /* input mode flags */ - tcflag_t c_oflag; /* output mode flags */ - tcflag_t c_cflag; /* control mode flags */ - tcflag_t c_lflag; /* local mode flags */ - cc_t c_cc[__KERNEL_NCCS]; /* control characters */ - cc_t c_line; /* line discipline */ - speed_t c_ispeed; /* input speed */ - speed_t c_ospeed; /* output speed */ - }; - -#define _HAVE_C_ISPEED 1 -#define _HAVE_C_OSPEED 1 - -/* We have the kernel termios structure, so we can presume this code knows - what it's doing... */ - -#undef TCGETS -#undef TCSETS -#undef TCSETSW -#undef TCSETSF -#define TCGETS _IOR ('t', 19, struct __kernel_termios) -#define TCSETS _IOW ('t', 20, struct __kernel_termios) -#define TCSETSW _IOW ('t', 21, struct __kernel_termios) -#define TCSETSF _IOW ('t', 22, struct __kernel_termios) - -#endif /* kernel_termios.h */ diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist index cc5e93c77c9d..c30e17cdfca2 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist @@ -3142,6 +3142,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist index 981499708367..f3c0c0205249 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist @@ -3187,6 +3187,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist index 7f46295c11fd..6e1d141ca7fd 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist @@ -2896,6 +2896,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist index f24f81bb5f33..441296c7e8ba 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist @@ -2972,6 +2972,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist index 9330c7ab762a..bcc0ed8d6a5f 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist @@ -2516,6 +2516,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist index ea4555d39e00..d55b553c0e39 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist @@ -2716,6 +2716,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist index 3e625fa4e928..a45b8874f0a3 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist @@ -3140,6 +3140,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist index 46b4a04f6507..17483dcc4895 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist @@ -2933,6 +2933,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist index 36a94c9210ce..cb62b6e083eb 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist @@ -2832,6 +2832,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist index f79aba6aab3d..ee6f2d017073 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist @@ -2829,6 +2829,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/sparc/Versions b/sysdeps/unix/sysv/linux/sparc/Versions index f127bdf0b88d..7dd61a54c447 100644 --- a/sysdeps/unix/sysv/linux/sparc/Versions +++ b/sysdeps/unix/sysv/linux/sparc/Versions @@ -29,6 +29,10 @@ libc { __getshmlba; } + GLIBC_2.42 { + tcgetattr; + tcsetattr; + } GLIBC_PRIVATE { # nptl/pthread_cond_timedwait.c uses INTERNAL_VSYSCALL(clock_gettime). __vdso_clock_gettime; diff --git a/sysdeps/unix/sysv/linux/sparc/bits/termios-baud.h b/sysdeps/unix/sysv/linux/sparc/bits/termios-cbaud.h similarity index 57% rename from sysdeps/unix/sysv/linux/sparc/bits/termios-baud.h rename to sysdeps/unix/sysv/linux/sparc/bits/termios-cbaud.h index 677db7ba116a..34eba1818449 100644 --- a/sysdeps/unix/sysv/linux/sparc/bits/termios-baud.h +++ b/sysdeps/unix/sysv/linux/sparc/bits/termios-cbaud.h @@ -17,30 +17,29 @@ . */ #ifndef _TERMIOS_H -# error "Never include directly; use instead." +# error "Never include directly; use instead." #endif #ifdef __USE_MISC # define CBAUD 0x0000100f # define CBAUDEX 0x00001000 -# define CIBAUD 0x100f0000 /* input baud rate (not used) */ -# define CMSPAR 0x40000000 /* mark or space (stick) parity */ -# define CRTSCTS 0x80000000 /* flow control */ +# define CIBAUD 0x100f0000 /* input baud rate */ +# define IBSHIFT 16 #endif -#define B57600 0x00001001 -#define B115200 0x00001002 -#define B230400 0x00001003 -#define B460800 0x00001004 -#define B76800 0x00001005 -#define B153600 0x00001006 -#define B307200 0x00001007 -#define B614400 0x00001008 -#define B921600 0x00001009 -#define B500000 0x0000100a -#define B576000 0x0000100b -#define B1000000 0x0000100c -#define B1152000 0x0000100d -#define B1500000 0x0000100e -#define B2000000 0x0000100f -#define __MAX_BAUD B2000000 +#define __B57600 0x00001001 +#define __B115200 0x00001002 +#define __B230400 0x00001003 +#define __B460800 0x00001004 +#define __B76800 0x00001005 +#define __B153600 0x00001006 +#define __B307200 0x00001007 +#define __B614400 0x00001008 +#define __B921600 0x00001009 +#define __B500000 0x0000100a +#define __B576000 0x0000100b +#define __B1000000 0x0000100c +#define __B1152000 0x0000100d +#define __B1500000 0x0000100e +#define __B2000000 0x0000100f +#define __BOTHER 0x00001000 diff --git a/sysdeps/unix/sysv/linux/mips/kernel_termios.h b/sysdeps/unix/sysv/linux/sparc/old_termios.h similarity index 67% rename from sysdeps/unix/sysv/linux/mips/kernel_termios.h rename to sysdeps/unix/sysv/linux/sparc/old_termios.h index fd8d35a93e68..44ff8d83c17e 100644 --- a/sysdeps/unix/sysv/linux/mips/kernel_termios.h +++ b/sysdeps/unix/sysv/linux/sparc/old_termios.h @@ -1,4 +1,6 @@ -/* Copyright (C) 1997-2025 Free Software Foundation, Inc. +/* old_termios.h for Linux/SPARC + + Copyright (C) 1991-2025 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -12,26 +14,17 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see + License along with the GNU C Library; if not, see . */ +#define _HAVE_STRUCT_OLD_TERMIOS 1 -#ifndef _KERNEL_TERMIOS_H -#define _KERNEL_TERMIOS_H 1 -/* The following corresponds to the values from the Linux 2.1.24 kernel. */ - -#define __KERNEL_NCCS 23 - -struct __kernel_termios +#define OLD_NCCS 17 +typedef struct old_termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ - cc_t c_cc[__KERNEL_NCCS]; /* control characters */ - }; - -#define _HAVE_C_ISPEED 0 -#define _HAVE_C_OSPEED 0 - -#endif /* kernel_termios.h */ + cc_t c_cc[OLD_NCCS]; /* control characters */ + } old_termios_t; diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist index 4a6acc08e047..943e130d3a8a 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist @@ -3161,7 +3161,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F +GLIBC_2.42 tcgetattr F +GLIBC_2.42 tcsetattr F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F GLIBC_2.42 ulabs F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist index 931109dab18a..1017babb1d59 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist @@ -2797,7 +2797,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F +GLIBC_2.42 tcgetattr F +GLIBC_2.42 tcsetattr F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F GLIBC_2.42 ulabs F diff --git a/sysdeps/unix/sysv/linux/speed.c b/sysdeps/unix/sysv/linux/speed.c index 017f74177f9b..c9f4bb9d3f63 100644 --- a/sysdeps/unix/sysv/linux/speed.c +++ b/sysdeps/unix/sysv/linux/speed.c @@ -16,82 +16,347 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include +#include -/* This is a gross hack around a kernel bug. If the cfsetispeed functions - is called with the SPEED argument set to zero this means use the same - speed as for output. But we don't have independent input and output - speeds and therefore cannot record this. +/* Conversions between legacy c_cflag fields and actual baud rates */ - We use an unused bit in the `c_iflag' field to keep track of this - use of `cfsetispeed'. The value here must correspond to the one used - in `tcsetattr.c'. */ -#define IBAUD0 020000000000 +/* These expressions may seem complicated; the _cbix() macro + compresses the CBAUD field into an index in the range 0-31. On most + Linux platforms, the CBAUD field is 5 bits, but the topmost bit + indicated by CBAUDEX, is discontinous with the rest. + + The resulting masks look like: + + Alpha PowerPC others + + CBAUD 0x001f 0x00ff 0x100f + CBAUDEX 0x0000 0x0010 0x1000 + + LOWCBAUD 0x001f 0x000f 0x000f + CBAUDMASK 0x001f 0x001f 0x100f + + CBAUDMASK is used to test for invalid values passed to the + compatibility functions or in termios::c_cflag on PowerPC. + + The divide-multiply sequence in the _cbix() macro gets converted + to shift and masks as necessary by the compiler. */ + +#define LOWCBAUD (CBAUD & (CBAUDEX-1)) +#define _cbix(x) (((x) & LOWCBAUD) | \ + (CBAUDEX ? ((x) & CBAUDEX)/CBAUDEX * (LOWCBAUD+1) : 0)) +#define CBAUDMASK (LOWCBAUD | CBAUDEX) + +/* Compile time sanity checks for broken CBAUD or CIBAUD definitions */ +#if CIBAUD != (CBAUD << IBSHIFT) +# error "CIBAUD should == CBAUD << IBSHIFT" +#elif CBAUDEX & (CBAUDEX-1) +# error "CBAUDEX should either be 0 or a single bit" +#elif !(CBAUD & 1) +# error "The CBAUD field should start at bit 0" +#elif CBAUDEX & ~CBAUD +# error "CBAUD should include the CBAUDEX bit" +#endif + +speed_t +___cbaud_to_speed (tcflag_t c_cflag, speed_t other) +{ + static const speed_t cbaudix_to_speed [] = + { + [0 ... _cbix(CBAUDMASK)] = -1, + [_cbix(__B0)] = 0, + [_cbix(__B50)] = 50, + [_cbix(__B75)] = 75, + [_cbix(__B110)] = 110, + [_cbix(__B134)] = 134, + [_cbix(__B150)] = 150, + [_cbix(__B200)] = 200, + [_cbix(__B300)] = 300, + [_cbix(__B600)] = 600, + [_cbix(__B1200)] = 1200, + [_cbix(__B1800)] = 1800, + [_cbix(__B2400)] = 2400, + [_cbix(__B4800)] = 4800, + [_cbix(__B9600)] = 9600, + [_cbix(__B19200)] = 19200, + [_cbix(__B38400)] = 38400, + [_cbix(__B57600)] = 57600, + [_cbix(__B115200)] = 115200, + [_cbix(__B230400)] = 230400, + [_cbix(__B460800)] = 460800, + [_cbix(__B500000)] = 500000, + [_cbix(__B576000)] = 576000, + [_cbix(__B921600)] = 921600, + [_cbix(__B1000000)] = 1000000, + [_cbix(__B1152000)] = 1152000, + [_cbix(__B1500000)] = 1500000, + [_cbix(__B2000000)] = 2000000, +#ifdef __B7200 + [_cbix(__B7200)] = 7200, +#endif +#ifdef __B14400 + [_cbix(__B14400)] = 14400, +#endif +#ifdef __B28800 + [_cbix(__B28800)] = 28800, +#endif +#ifdef __B76800 + [_cbix(__B76800)] = 76800, +#endif +#ifdef __B153600 + [_cbix(__B153600)] = 153600, +#endif +#ifdef __B307200 + [_cbix(__B307200)] = 307200, +#endif +#ifdef __B614400 + [_cbix(__B614400)] = 614400, +#endif +#ifdef __B2500000 + [_cbix(__B2500000)] = 2500000, +#endif +#ifdef __B3000000 + [_cbix(__B3000000)] = 3000000, +#endif +#ifdef __B3500000 + [_cbix(__B3500000)] = 3500000, +#endif +#ifdef __B4000000 + [_cbix(__B4000000)] = 4000000, +#endif + }; + speed_t speed; + + if (c_cflag & (tcflag_t)(~CBAUDMASK)) + return other; + + speed = cbaudix_to_speed[_cbix(c_cflag)]; + return speed == (speed_t)-1 ? other : speed; +} + +tcflag_t +___speed_to_cbaud (speed_t speed) +{ + switch (speed) { + case 0: + return __B0; + case 50: + return __B50; + case 75: + return __B75; + case 110: + return __B110; + case 134: + return __B134; + case 150: + return __B150; + case 200: + return __B200; + case 300: + return __B300; + case 600: + return __B600; + case 1200: + return __B1200; + case 1800: + return __B1800; + case 2400: + return __B2400; + case 4800: + return __B4800; + case 9600: + return __B9600; + case 19200: + return __B19200; + case 38400: + return __B38400; + case 57600: + return __B57600; + case 115200: + return __B115200; + case 230400: + return __B230400; + case 460800: + return __B460800; + case 500000: + return __B500000; + case 576000: + return __B576000; + case 921600: + return __B921600; + case 1000000: + return __B1000000; + case 1152000: + return __B1152000; + case 1500000: + return __B1500000; + case 2000000: + return __B2000000; +#ifdef __B76800 + case 76800: + return __B76800; +#endif +#ifdef __B153600 + case 153600: + return __B153600; +#endif +#ifdef __B307200 + case 307200: + return __B307200; +#endif +#ifdef __B614400 + case 614400: + return __B614400; +#endif +#ifdef __B2500000 + case 2500000: + return __B2500000; +#endif +#ifdef __B3000000 + case 3000000: + return __B3000000; +#endif +#ifdef __B3500000 + case 3500000: + return __B3500000; +#endif +#ifdef __B4000000 + case 4000000: + return __B4000000; +#endif + default: + return __BOTHER; + } +} + + +/* Canonicalize the representation of speed fields in a kernel + termios2 structure. Specifically, if there is a valid legacy cbaud + representation (not __BOTHER), use it and propagate the + corresponding speed value to ispeed/ospeed, otherwise the other way + around if possible. Finally, if the input speed is zero, copy the + output speed to the input speed. + + The kernel doesn't do this canonicalization, which can affect + legacy utilities, so do it here. + + This is used by tcgetattr() and tcsetattr(). */ +void +___termios2_canonicalize_speeds (struct termios2 *k_termios_p) +{ + k_termios_p->c_ospeed = + ___cbaud_to_speed (cbaud (k_termios_p->c_cflag), k_termios_p->c_ospeed); + k_termios_p->c_ispeed = + ___cbaud_to_speed (cibaud (k_termios_p->c_cflag), k_termios_p->c_ispeed); + + if (!k_termios_p->c_ispeed) + k_termios_p->c_ispeed = k_termios_p->c_ospeed; + + k_termios_p->c_cflag &= ~(CBAUD | CIBAUD); + k_termios_p->c_cflag |= ___speed_to_cbaud (k_termios_p->c_ospeed); + k_termios_p->c_cflag |= ___speed_to_cbaud (k_termios_p->c_ispeed) << IBSHIFT; +} /* Return the output baud rate stored in *TERMIOS_P. */ speed_t -cfgetospeed (const struct termios *termios_p) +__cfgetospeed (const struct termios *termios_p) { - return termios_p->c_cflag & (CBAUD | CBAUDEX); + return termios_p->c_ospeed; } +versioned_symbol (libc, __cfgetospeed, cfgetospeed, GLIBC_2_42); -/* Return the input baud rate stored in *TERMIOS_P. - Although for Linux there is no difference between input and output - speed, the numerical 0 is a special case for the input baud rate. It - should set the input baud rate to the output baud rate. */ +/* Return the input baud rate stored in *TERMIOS_P. */ speed_t -cfgetispeed (const struct termios *termios_p) +__cfgetispeed (const struct termios *termios_p) { - return ((termios_p->c_iflag & IBAUD0) - ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX)); + return termios_p->c_ispeed; } +versioned_symbol (libc, __cfgetispeed, cfgetispeed, GLIBC_2_42); /* Set the output baud rate stored in *TERMIOS_P to SPEED. */ int -cfsetospeed (struct termios *termios_p, speed_t speed) +__cfsetospeed (struct termios *termios_p, speed_t speed) { - if ((speed & ~CBAUD) != 0 - && (speed < B57600 || speed > __MAX_BAUD)) - return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + tcflag_t cbaud = ___speed_to_cbaud (speed); -#if _HAVE_STRUCT_TERMIOS_C_OSPEED termios_p->c_ospeed = speed; + termios_p->c_cflag &= ~CBAUD; + termios_p->c_cflag |= cbaud; + + return 0; +} +versioned_symbol (libc, __cfsetospeed, cfsetospeed, GLIBC_2_42); + +/* Set the input baud rate stored in *TERMIOS_P to SPEED. */ +int +__cfsetispeed (struct termios *termios_p, speed_t speed) +{ + tcflag_t cbaud = ___speed_to_cbaud (speed); + + termios_p->c_ispeed = speed; + termios_p->c_cflag &= ~CIBAUD; + termios_p->c_cflag |= cbaud << IBSHIFT; + + return 0; +} +versioned_symbol (libc, __cfsetispeed, cfsetispeed, GLIBC_2_42); + +#if _TERMIOS_OLD_COMPAT + +/* Legacy versions which returns cbaud-encoded speed_t values */ + +speed_t +attribute_compat_text_section +__old_cfgetospeed (const old_termios_t *termios_p) +{ + return cbaud (termios_p->c_cflag); +} +compat_symbol (libc, __old_cfgetospeed, cfgetospeed, GLIBC_2_0); + +speed_t +attribute_compat_text_section +__old_cfgetispeed (const old_termios_t *termios_p) +{ + return cibaud (termios_p->c_cflag); +} +compat_symbol (libc, __old_cfgetispeed, cfgetispeed, GLIBC_2_0); + +int +attribute_compat_text_section +__old_cfsetospeed (old_termios_t *termios_p, speed_t speed) +{ + speed_t real_speed = ___cbaud_to_speed (speed, -1); + if (real_speed == (speed_t)-1) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + +#if !_HAVE_STRUCT_OLD_TERMIOS + /* Otherwise this field doesn't exist in old_termios_t */ + termios_p->c_ospeed = real_speed; #endif - termios_p->c_cflag &= ~(CBAUD | CBAUDEX); + termios_p->c_cflag &= ~CBAUD; termios_p->c_cflag |= speed; return 0; } -libc_hidden_def (cfsetospeed) +compat_symbol (libc, __old_cfsetospeed, cfsetospeed, GLIBC_2_0); - -/* Set the input baud rate stored in *TERMIOS_P to SPEED. - Although for Linux there is no difference between input and output - speed, the numerical 0 is a special case for the input baud rate. It - should set the input baud rate to the output baud rate. */ int -cfsetispeed (struct termios *termios_p, speed_t speed) +attribute_compat_text_section +__old_cfsetispeed (old_termios_t *termios_p, speed_t speed) { - if ((speed & ~CBAUD) != 0 - && (speed < B57600 || speed > __MAX_BAUD)) + speed_t real_speed = ___cbaud_to_speed (speed, -1); + if (real_speed == (speed_t)-1) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); -#if _HAVE_STRUCT_TERMIOS_C_ISPEED - termios_p->c_ispeed = speed; +#if !_HAVE_STRUCT_OLD_TERMIOS + /* Otherwise this field doesn't exist in old_termios_t */ + termios_p->c_ispeed = real_speed; #endif - if (speed == 0) - termios_p->c_iflag |= IBAUD0; - else - { - termios_p->c_iflag &= ~IBAUD0; - termios_p->c_cflag &= ~(CBAUD | CBAUDEX); - termios_p->c_cflag |= speed; - } + termios_p->c_cflag &= ~CIBAUD; + termios_p->c_cflag |= speed << IBSHIFT; return 0; } -libc_hidden_def (cfsetispeed) +compat_symbol (libc, __old_cfsetispeed, cfsetispeed, GLIBC_2_0); + +#endif /* _TERMIOS_OLD_COMPAT */ diff --git a/sysdeps/unix/sysv/linux/tcgetattr.c b/sysdeps/unix/sysv/linux/tcgetattr.c index d672e0c3b1d8..dbeae739cc31 100644 --- a/sysdeps/unix/sysv/linux/tcgetattr.c +++ b/sysdeps/unix/sysv/linux/tcgetattr.c @@ -15,66 +15,55 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include -#include -#include - -/* The difference here is that the termios structure used in the - kernel is not the same as we use in the libc. Therefore we must - translate it here. */ -#include +#include /* Put the state of FD into *TERMIOS_P. */ int __tcgetattr (int fd, struct termios *termios_p) { - struct __kernel_termios k_termios; - int retval; - - retval = INLINE_SYSCALL (ioctl, 3, fd, TCGETS, &k_termios); + struct termios2 k_termios; + long int retval = INLINE_SYSCALL_CALL (ioctl, fd, TCGETS2, &k_termios); - if (__glibc_likely (retval == 0)) + if (__glibc_likely (retval != -1)) { - termios_p->c_iflag = k_termios.c_iflag; - termios_p->c_oflag = k_termios.c_oflag; - termios_p->c_cflag = k_termios.c_cflag; - termios_p->c_lflag = k_termios.c_lflag; - termios_p->c_line = k_termios.c_line; -#if _HAVE_STRUCT_TERMIOS_C_ISPEED -# if _HAVE_C_ISPEED - termios_p->c_ispeed = k_termios.c_ispeed; -# else - termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX); -# endif -#endif -#if _HAVE_STRUCT_TERMIOS_C_OSPEED -# if _HAVE_C_OSPEED + ___termios2_canonicalize_speeds (&k_termios); + + termios_p->c_iflag = k_termios.c_iflag; + termios_p->c_oflag = k_termios.c_oflag; + termios_p->c_cflag = k_termios.c_cflag; + termios_p->c_lflag = k_termios.c_lflag; + termios_p->c_line = k_termios.c_line; termios_p->c_ospeed = k_termios.c_ospeed; -# else - termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX); -# endif -#endif - if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0 - || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1) - memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], - __KERNEL_NCCS * sizeof (cc_t)), - _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t)); - else - { - memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], - __KERNEL_NCCS * sizeof (cc_t)); + termios_p->c_ispeed = k_termios.c_ispeed; - for (size_t cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt) - termios_p->c_cc[cnt] = _POSIX_VDISABLE; - } + copy_c_cc (termios_p->c_cc, NCCS, k_termios.c_cc, __KERNEL_NCCS); } return retval; } - libc_hidden_def (__tcgetattr) + +#if _TERMIOS_OLD_COMPAT && _HAVE_STRUCT_OLD_TERMIOS + +versioned_symbol (libc, __tcgetattr, tcgetattr, GLIBC_2_42); + +/* Legacy version for shorter struct termios */ +int +attribute_compat_text_section +__old_tcgetattr (int fd, old_termios_t *termios_p) +{ + struct termios new_termios; + int retval = __tcgetattr (fd, &new_termios); + if (__glibc_likely (retval != -1)) + { + memcpy (termios_p, &new_termios, sizeof (*termios_p)); + } + return retval; +} +compat_symbol (libc, __old_tcgetattr, tcgetattr, GLIBC_2_0); + +#else + weak_alias (__tcgetattr, tcgetattr) + +#endif diff --git a/sysdeps/unix/sysv/linux/tcsetattr.c b/sysdeps/unix/sysv/linux/tcsetattr.c index 49d9d245a067..7ec53e41937f 100644 --- a/sysdeps/unix/sysv/linux/tcsetattr.c +++ b/sysdeps/unix/sysv/linux/tcsetattr.c @@ -15,67 +15,94 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include -#include - -/* The difference here is that the termios structure used in the - kernel is not the same as we use in the libc. Therefore we must - translate it here. */ -#include - - -/* This is a gross hack around a kernel bug. If the cfsetispeed functions - is called with the SPEED argument set to zero this means use the same - speed as for output. But we don't have independent input and output - speeds and therefore cannot record this. - - We use an unused bit in the `c_iflag' field to keep track of this - use of `cfsetispeed'. The value here must correspond to the one used - in `speed.c'. */ -#define IBAUD0 020000000000 +#include +#define static_assert_equal(x,y) _Static_assert ((x) == (y), #x " != " #y) /* Set the state of FD to *TERMIOS_P. */ int __tcsetattr (int fd, int optional_actions, const struct termios *termios_p) { - struct __kernel_termios k_termios; - unsigned long int cmd; + struct termios2 k_termios; + unsigned long cmd; - switch (optional_actions) - { - case TCSANOW: - cmd = TCSETS; - break; - case TCSADRAIN: - cmd = TCSETSW; - break; - case TCSAFLUSH: - cmd = TCSETSF; - break; - default: - return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); - } + memset (&k_termios, 0, sizeof k_termios); - k_termios.c_iflag = termios_p->c_iflag & ~IBAUD0; + k_termios.c_iflag = termios_p->c_iflag; k_termios.c_oflag = termios_p->c_oflag; k_termios.c_cflag = termios_p->c_cflag; k_termios.c_lflag = termios_p->c_lflag; - k_termios.c_line = termios_p->c_line; -#if _HAVE_C_ISPEED && _HAVE_STRUCT_TERMIOS_C_ISPEED - k_termios.c_ispeed = termios_p->c_ispeed; -#endif -#if _HAVE_C_OSPEED && _HAVE_STRUCT_TERMIOS_C_OSPEED + k_termios.c_line = termios_p->c_line; + k_termios.c_ospeed = termios_p->c_ospeed; -#endif - memcpy (&k_termios.c_cc[0], &termios_p->c_cc[0], - __KERNEL_NCCS * sizeof (cc_t)); + k_termios.c_ispeed = termios_p->c_ispeed; + + ___termios2_canonicalize_speeds (&k_termios); - return INLINE_SYSCALL (ioctl, 3, fd, cmd, &k_termios); + copy_c_cc (k_termios.c_cc, __KERNEL_NCCS, termios_p->c_cc, NCCS); + + /* + * Choose the proper ioctl number to invoke. + * + * Alpha got TCSETS2 late (Linux 4.20), but has the same structure + * format, and it only needs TCSETS2 if either it needs to use + * __BOTHER or split speed. All other architectures have TCSETS2 as + * far back as the current glibc supports. Calling TCSETS with + * __BOTHER causes unpredictable results on old Alpha kernels and + * could even crash them. + */ + static_assert_equal(TCSADRAIN, TCSANOW + 1); + static_assert_equal(TCSAFLUSH, TCSANOW + 2); + static_assert_equal(TCSETSW2, TCSETS2 + 1); + static_assert_equal(TCSETSF2, TCSETS2 + 2); + static_assert_equal(TCSETSW, TCSETS + 1); + static_assert_equal(TCSETSF, TCSETS + 2); + + cmd = (long)optional_actions - TCSANOW; + if (cmd > 2) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + + if (__ASSUME_TERMIOS2 || + k_termios.c_ospeed != k_termios.c_ispeed || + cbaud (k_termios.c_cflag) == __BOTHER) + { + cmd += TCSETS2; + } + else + { + cmd += TCSETS; + k_termios.c_cflag &= ~CIBAUD; + } + + return INLINE_SYSCALL_CALL (ioctl, fd, cmd, &k_termios); } libc_hidden_def (__tcsetattr) + +#if _HAVE_STRUCT_OLD_TERMIOS && _TERMIOS_OLD_COMPAT + +versioned_symbol (libc, __tcsetattr, tcsetattr, GLIBC_2_42); + +/* Legacy version for shorter struct termios without speed fields */ +int +attribute_compat_text_section +__old_tcsetattr (int fd, int optional_actions, const old_termios_t *termios_p) +{ + struct termios new_termios; + new_termios.c_iflag = termios_p->c_iflag; + new_termios.c_oflag = termios_p->c_oflag; + new_termios.c_cflag = termios_p->c_cflag; + new_termios.c_lflag = termios_p->c_lflag; + new_termios.c_line = termios_p->c_line; + new_termios.c_ispeed = 0; + new_termios.c_ospeed = 0; + copy_c_cc(new_termios.c_cc, NCCS, termios_p->c_cc, OLD_NCCS); + + return __tcsetattr (fd, optional_actions, &new_termios); +} +compat_symbol (libc, __old_tcsetattr, tcsetattr, GLIBC_2_0); + +#else + weak_alias (__tcsetattr, tcsetattr) + +#endif diff --git a/sysdeps/unix/sysv/linux/termios_internals.h b/sysdeps/unix/sysv/linux/termios_internals.h new file mode 100644 index 000000000000..70e2fb04e3b5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/termios_internals.h @@ -0,0 +1,116 @@ +/* termios functions internal implementation header for Linux + + Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef TERMIOS_INTERNALS_H +#define TERMIOS_INTERNALS_H 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* The difference here is that the termios structure used in the + kernel is not the same as we use in the libc. Therefore we must + translate it here. */ +#include + +/* + * Should old speed_t and struct termios (if applicable) compatibility + * functions be included? + */ +#define _TERMIOS_OLD_COMPAT SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_42) + +/* + * Old struct termios (without c_ispeed and c_ospeed fields) if + * applicable. The new struct termios *must* be binary identical up to + * the sizeof the old structure. + * + * This only applies to SPARC and MIPS; for other architectures the + * new and old speed_t interfaces both use the same struct termios. + * + * This will define _HAVE_STRUCT_OLD_TERMIOS to either 0 or 1. + */ +#include + +/* Alpha got termios2 late, but TCGETS has exactly the same structure + format and function as TCGETS2. On all other platforms, the termios2 + interface exists as far back as this version of glibc supports. + + For TCGETS* it is more complicated; this is handled in tcsetattr.c. + + Some other architectures only have the equivalent of the termios2 + interface, in which case the old ioctl names are the only ones + presented, but are equivalent to the new ones. */ +#ifndef TCGETS2 +# define TCGETS2 TCGETS +# define TCSETS2 TCSETS +# define TCSETSW2 TCSETSW +# define TCSETSF2 TCSETSF +#elif !__ASSUME_TERMIOS2 +/* Hack for Alpha */ +# undef TCGETS2 +# define TCGETS2 TCGETS +#endif + +/* + * Copy a set of c_cc fields of possibly different width. If the target + * field is longer, then fill with _POSIX_VDISABLE == -1. + */ +static inline void +copy_c_cc (cc_t *to, size_t nto, const cc_t *from, size_t nfrom) +{ + if (nto < nfrom) + nfrom = nto; + + to = __mempcpy (to, from, nfrom * sizeof(cc_t)); + if (nto > nfrom) + memset (to, _POSIX_VDISABLE, (nto - nfrom) * sizeof(cc_t)); +} + +/* Extract the output and input legacy speed fields from c_cflag. */ +static inline tcflag_t +cbaud (tcflag_t c_cflag) +{ + return c_cflag & CBAUD; +} + +static inline tcflag_t +cibaud (tcflag_t c_cflag) +{ + return cbaud (c_cflag >> IBSHIFT); +} + +extern speed_t +___cbaud_to_speed (tcflag_t c_cflag, speed_t other) + __attribute_const__ attribute_hidden; + +extern tcflag_t +___speed_to_cbaud (speed_t speed) + __attribute_const__ attribute_hidden; + +extern void +___termios2_canonicalize_speeds (struct termios2 *k_termios_p) + attribute_hidden; + +#endif /* TERMIOS_INTERNALS_H */ diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index 7ab9073e3a24..ccf6ca2c8876 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -2748,6 +2748,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index e11876f6abc3..1e3e283954d5 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -2767,6 +2767,11 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetospeed F +GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F GLIBC_2.42 uabs F GLIBC_2.42 uimaxabs F From patchwork Tue Jun 10 19:02:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114167 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF32D385828E for ; Tue, 10 Jun 2025 19:16:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF32D385828E Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=VT9IUCHR X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id EFF063858C42 for ; Tue, 10 Jun 2025 19:03:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFF063858C42 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFF063858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582183; cv=none; b=Q+J/Zo1v5OxqChefG5upQySGfD4oAD5Dw4wC8QOlpJuC3qbgrtdq3m+3LzSdr/BmMNf+cAKWqVfNfSWZktbavEAORncNhN3mAFarlvU7kveKksv4frraU06hTluPDRY8wPdgYXmS+nAZeNWpFE+Iaj3rfNQpinwWP5Cvawb2f4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582183; c=relaxed/simple; bh=FqQpm8bqf7Cfh/OWDaj3aTFWiN2nGzDSCJLDYvLDqnM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=W8Ti3Ox5FA0aLCpEhSFQalBCZiMlSyPC/v46p6tFhXa3bMlRESOQXEoRBz9DZxJ1J+r9v1H0k0N08jda47hEpVv5GJk+dl/DVoivsRbFImDbbirVugRNBO7NENuNgyK5kmYa0wpQ2orR2V0wBzfm7Jd5RcU8o3qlRe0z5kpkwnU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFF063858C42 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arj2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:55 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arj2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582175; bh=Ytw1+Kgxks79gCcpWfHtdMyk+Rf55o+XtDuFJkrxps0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VT9IUCHRRU2oAi4cXTDFfyhwwK1+jPsilNTIbSqO4G7l9RNYx+y5ysZl2SKB1+g8R mf7+piH9eYJ6tPS7ON53i/63Lku9nahmQdH1Im5lG/6qY7fpoEf5Thm7lPyXXi8/j9 bH5Het6FGa6vbtWzbNuJSeT4yuSgrezVDPfY447FTe4pcK3BFv2GBY1JF1EIunWb4+ heO2w3ANbRiYgkXA9oX3Hk9NqYO0VF9jhOfOFOdaTukREb4vnZ9RURISxpxaCvyiLX 4EeUCkDSgTDW1wuHDZsyy39HVveQyQgxiITRTbCb3cXZ1fQaA2bGtCGwJfLVUt3f4o 9qk+eQfuSE/xQ== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 06/15] linux/termios: clear padding bytes in struct termios Date: Tue, 10 Jun 2025 12:02:17 -0700 Message-ID: <20250610190228.1124149-7-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org There is a 3-byte padding field (1 byte on m68k) in struct termios due to NCCS being set to 32 and there being one more byte-sized variable next to it (c_line). Make sure these padding bytes are zero by explicitly setting the structure to zero before populating it in tcgetattr() and __old_tcsetattr(). This may make future extensions easier, plus, it is bad practice to leave bytes uninitialized by an ABI. This patch leaves the actual field implicit, because of it having different size on m68k and others; m68k having a standard ABI alignment of only 2 bytes; this seems simpler than having to do something different on m68k -- especially if someone decides to build an m68k distribution with natural alignment enabled (-malign-int.) Even so, there is at least one byte on every architecture, which could be pressed into service in the future, e.g. as a flag field or to provide positive identification of a future extended termios format. Moral of the story: when designing a structure for an ABI, make sure all your members are naturally aligned without implict padding. However, fixing this would require adding m68k to the set of architectures which require a new struct termios, and that does not seem like a worthwhile engineering tradeoff at this time. Thanks to Adhemerval Zanella Netto for catching the m68k issue. Signed-off-by: "H. Peter Anvin" (Intel) --- sysdeps/unix/sysv/linux/tcgetattr.c | 1 + sysdeps/unix/sysv/linux/tcsetattr.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/tcgetattr.c b/sysdeps/unix/sysv/linux/tcgetattr.c index dbeae739cc31..7eed18b74b7d 100644 --- a/sysdeps/unix/sysv/linux/tcgetattr.c +++ b/sysdeps/unix/sysv/linux/tcgetattr.c @@ -28,6 +28,7 @@ __tcgetattr (int fd, struct termios *termios_p) { ___termios2_canonicalize_speeds (&k_termios); + memset (termios_p, 0, sizeof (*termios_p)); termios_p->c_iflag = k_termios.c_iflag; termios_p->c_oflag = k_termios.c_oflag; termios_p->c_cflag = k_termios.c_cflag; diff --git a/sysdeps/unix/sysv/linux/tcsetattr.c b/sysdeps/unix/sysv/linux/tcsetattr.c index 7ec53e41937f..ae4361a22bd3 100644 --- a/sysdeps/unix/sysv/linux/tcsetattr.c +++ b/sysdeps/unix/sysv/linux/tcsetattr.c @@ -88,13 +88,13 @@ attribute_compat_text_section __old_tcsetattr (int fd, int optional_actions, const old_termios_t *termios_p) { struct termios new_termios; + + memset (&new_termios, 0, sizeof (new_termios)); new_termios.c_iflag = termios_p->c_iflag; new_termios.c_oflag = termios_p->c_oflag; new_termios.c_cflag = termios_p->c_cflag; new_termios.c_lflag = termios_p->c_lflag; new_termios.c_line = termios_p->c_line; - new_termios.c_ispeed = 0; - new_termios.c_ospeed = 0; copy_c_cc(new_termios.c_cc, NCCS, termios_p->c_cc, OLD_NCCS); return __tcsetattr (fd, optional_actions, &new_termios); From patchwork Tue Jun 10 19:02:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114166 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2384B3858D3C for ; Tue, 10 Jun 2025 19:13:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2384B3858D3C Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=Kp7beW9v X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 532EB3858C48 for ; Tue, 10 Jun 2025 19:03:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 532EB3858C48 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 532EB3858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582183; cv=none; b=hqKTFMQ+Ccj/XCAKxkxE8qE7cKPDTXtEKFWHkI2q/Jxov23KB+PdsXzPJieu4x+ci+q6cbijqovl3I+Zr7MaCbD9p2ZArjRltxxgtAloHENEcYkxVlDzgKtnvVFm5WS/zNfukMr5+WANYrz9I8seAJFvH1Y7BmKEP+kZGfisi3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582183; c=relaxed/simple; bh=orbm1+DeIYlvDBnldPsgMfut+Bsqc4OHmTxRbOLq0io=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UwP1RNBg9iBg1LIjbAH3dW3Rd1O9mBTaYqRfma5nMEIMC/v0nI/D115/IpourQd7BmHgcBFCOfFGN8JAl4cZyDpf/0XfeTiekAQJRsnjyW1w1Az/Co1lNxaeBxs/bBYZrBdGngggZescjvNrVjNPajWi62JZXTldFwZ3If+TWcM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 532EB3858C48 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2ark2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:56 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2ark2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582176; bh=uOQ//YNZLJ76aoH5PUlKhJnrIctiNXizEmoqrhFmWvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kp7beW9v037HPE/rko6gmqzYbCf8rNOet5cFFGH2llH2eYj9zCAW07719smMzP6tM Eya7LrAeCbuEzsePR6+W7n0ur1tbO2Px5jQ7yz5gMN7v1BJ8YoWW5kSqGdqxAH/MLV lkOttuNZ0b7i4biQk4uMQ8/XU1ZD8p+PsSq657+ZEGuN/iB8c7sAYgzyw/r+esfspo UyAM4H504xxOWbnO/SZrd/1wey9bUNf8WlpwpQtbau61DyRbybFvh2jLWPiqkopmW0 CjXhnU9udKUmoFdgrTR4kDAmLjKckdWZWRMUCUeolsFiUfyt8UTWqwAjKdZ0K+/CGB 1GCX3Ekjumv0g== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 07/15] hurd/termios: remove USE_OLD_TTY Date: Tue, 10 Jun 2025 12:02:18 -0700 Message-ID: <20250610190228.1124149-8-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Hurd with USE_OLD_TTY was the only remaining platform with speed_t not containing a proper baud rate. From the looks of it, that code has long since bitrotted. Remove the vestiges of USE_OLD_TTY. Reviewed-by: Samuel Thibault Signed-off-by: H. Peter Anvin (Intel) --- sysdeps/mach/hurd/bits/ioctls.h | 31 ++----------------------------- termios/sys/ttychars.h | 4 ---- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/sysdeps/mach/hurd/bits/ioctls.h b/sysdeps/mach/hurd/bits/ioctls.h index f01316dbc603..faf1373dbf32 100644 --- a/sysdeps/mach/hurd/bits/ioctls.h +++ b/sysdeps/mach/hurd/bits/ioctls.h @@ -324,15 +324,8 @@ enum __ioctl_datum { IOC_8, IOC_16, IOC_32, IOC_64 }; From 4.4 . */ #ifdef __USE_MISC -#ifdef USE_OLD_TTY -# undef TIOCGETD -# define TIOCGETD _IOR('t', 0, int) /* get line discipline */ -# undef TIOCSETD -# define TIOCSETD _IOW('t', 1, int) /* set line discipline */ -#else -# define OTIOCGETD _IOR('t', 0, int) /* get line discipline */ -# define OTIOCSETD _IOW('t', 1, int) /* set line discipline */ -#endif +#define OTIOCGETD _IOR('t', 0, int) /* get line discipline */ +#define OTIOCSETD _IOW('t', 1, int) /* set line discipline */ #define TIOCHPCL _IO('t', 2) /* hang up on last close */ #define TIOCGETP _IOR('t', 8,struct sgttyb)/* get parameters -- gtty */ #define TIOCSETP _IOW('t', 9,struct sgttyb)/* set parameters -- stty */ @@ -411,26 +404,6 @@ enum __ioctl_datum { IOC_8, IOC_16, IOC_32, IOC_64 }; #define OTTYDISC 0 #define NETLDISC 1 #define NTTYDISC 2 - -/* From 4.4 . */ -#ifdef USE_OLD_TTY -# define B0 0 -# define B50 1 -# define B75 2 -# define B110 3 -# define B134 4 -# define B150 5 -# define B200 6 -# define B300 7 -# define B600 8 -# define B1200 9 -# define B1800 10 -# define B2400 11 -# define B4800 12 -# define B9600 13 -# define EXTA 14 -# define EXTB 15 -#endif /* USE_OLD_TTY */ #endif #endif /* bits/ioctls.h */ diff --git a/termios/sys/ttychars.h b/termios/sys/ttychars.h index 7043f60f81d2..eb1a815b60b8 100644 --- a/termios/sys/ttychars.h +++ b/termios/sys/ttychars.h @@ -54,8 +54,4 @@ struct ttychars { char tc_lnextc; /* literal next character */ }; -#ifdef __USE_OLD_TTY -#include /* to pick up character defaults */ -#endif - #endif /* sys/ttychars.h */ From patchwork Tue Jun 10 19:02:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114165 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1F3653858420 for ; Tue, 10 Jun 2025 19:12:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F3653858420 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=bnIrm+cj X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id CB128385829B for ; Tue, 10 Jun 2025 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB128385829B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB128385829B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582201; cv=none; b=OEXpBiX/3J8m/nQklX+IIpOFwM1RbK5nvUoBHZS4HIA/8AskSQRv3eDi9a4gzCIH79zzN2VpIGYpreqni6ArwY3k5KDH4RN0LzUFPQGbuFoXzJtnaGY0hSqQYF2cT+IK3VvmJd0C12s1fck4XmfNVL+RWCny2XMcFQgv3UG69SI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582201; c=relaxed/simple; bh=zJUlqG2ibbXy3FzKHfUnYtufOwrQ73cQKxe8ETlPMbc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=obarm4QhC8rvCnP5X42f7MMcKo0fSHtiPCwEKnhvYCoWKEM4rVvr2qRVBXrZvMzTZyaMYiYrDBHh5mUKMkiz90tAmcfY5sKdb9aNJJcNFj0OHQ6lA2t0Pjw3DcTAlaF2Ail4tO1bguXRj47DC+KIZOUAWuHZuImjiau/4+H8gDU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB128385829B Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arl2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:56 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arl2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582177; bh=BcOXVCmEAkYwcbZHyd5MfYhMZg3A/2oYAZJOUb0BQRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bnIrm+cjKLwYooGy0BNhstwnStzWEQ6e/HjGN7ZY279N2f3mE3H7+vzQ5bZDpH4uJ klYTK0CniOo9aVRqSNEK0Nk2m4OFzlWFSn6/wgDupWl46b6uuNb+sNvnLj3TLVKihM 3EI68g9LWCUoRCDeRltUd0DrVlg1Y/UfvuoadwymIxK/4AvQWXWy0apX1WimAi0t4F CpBw1GGWErKTUI2AnXEM7FJ8BB3fs0Xi4cetOC6Yz7yq1uP2G7ICuVwwOmw8MpPPbK mAqwwu5oE0HSuW33QXJHau/VkHulMkSfKGy6Uzvp6VzZvIfOOxCiu7z8/9jbYW0u9r 7T6LIsLjEhBNg== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 08/15] termios: change the generic cfsetspeed() to support arbitrary speeds Date: Tue, 10 Jun 2025 12:02:19 -0700 Message-ID: <20250610190228.1124149-9-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" The generic implementaion of cfsetspeed() had an internal table of permitted baud rates, which was enforced even on an implementation supporting arbitrary baud rates. This was to be able to *also* accept numeric constants as well as Bxxx values. This fundamentally makes no sense; not only does it go against the documented behavior of cfsetspeed() which is to take the same input as cfset[io]speed(), but it means cfsetspeed() is broken with regard to a platform supporting arbitrary speeds. With Linux converted to arbitrary baud rates, the only remaining case of non-arbitrary baud rates appears to be Hurd with USE_OLD_TTY, which one can presume being a legacy case that few if any people care about, and so simply strip out this code and make cfsetspeed() rely on cfsetospeed() to validate acceptable speed constants. If a new platform is introduced which does not have arbitrary baud rate support, using non-baud rate Bxxx constants (highly not recommended; should be abstracted at the glibc level) but such aliasing is desired, it should be supported by cfset[io]speed() as well, and belongs in the platform-specific code. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- termios/cfsetspeed.c | 138 ++----------------------------------------- 1 file changed, 5 insertions(+), 133 deletions(-) diff --git a/termios/cfsetspeed.c b/termios/cfsetspeed.c index 053e3945ea10..257c6387aaa0 100644 --- a/termios/cfsetspeed.c +++ b/termios/cfsetspeed.c @@ -19,143 +19,15 @@ #include #include -struct speed_struct -{ - speed_t value; - speed_t internal; -}; - -static const struct speed_struct speeds[] = - { -#ifdef B0 - { 0, B0 }, -#endif -#ifdef B50 - { 50, B50 }, -#endif -#ifdef B75 - { 75, B75 }, -#endif -#ifdef B110 - { 110, B110 }, -#endif -#ifdef B134 - { 134, B134 }, -#endif -#ifdef B150 - { 150, B150 }, -#endif -#ifdef B200 - { 200, B200 }, -#endif -#ifdef B300 - { 300, B300 }, -#endif -#ifdef B600 - { 600, B600 }, -#endif -#ifdef B1200 - { 1200, B1200 }, -#endif -#ifdef B1200 - { 1200, B1200 }, -#endif -#ifdef B1800 - { 1800, B1800 }, -#endif -#ifdef B2400 - { 2400, B2400 }, -#endif -#ifdef B4800 - { 4800, B4800 }, -#endif -#ifdef B9600 - { 9600, B9600 }, -#endif -#ifdef B19200 - { 19200, B19200 }, -#endif -#ifdef B38400 - { 38400, B38400 }, -#endif -#ifdef B57600 - { 57600, B57600 }, -#endif -#ifdef B76800 - { 76800, B76800 }, -#endif -#ifdef B115200 - { 115200, B115200 }, -#endif -#ifdef B153600 - { 153600, B153600 }, -#endif -#ifdef B230400 - { 230400, B230400 }, -#endif -#ifdef B307200 - { 307200, B307200 }, -#endif -#ifdef B460800 - { 460800, B460800 }, -#endif -#ifdef B500000 - { 500000, B500000 }, -#endif -#ifdef B576000 - { 576000, B576000 }, -#endif -#ifdef B921600 - { 921600, B921600 }, -#endif -#ifdef B1000000 - { 1000000, B1000000 }, -#endif -#ifdef B1152000 - { 1152000, B1152000 }, -#endif -#ifdef B1500000 - { 1500000, B1500000 }, -#endif -#ifdef B2000000 - { 2000000, B2000000 }, -#endif -#ifdef B2500000 - { 2500000, B2500000 }, -#endif -#ifdef B3000000 - { 3000000, B3000000 }, -#endif -#ifdef B3500000 - { 3500000, B3500000 }, -#endif -#ifdef B4000000 - { 4000000, B4000000 }, -#endif - }; - - /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */ int cfsetspeed (struct termios *termios_p, speed_t speed) { - size_t cnt; - - for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt) - if (speed == speeds[cnt].internal) - { - cfsetispeed (termios_p, speed); - cfsetospeed (termios_p, speed); - return 0; - } - else if (speed == speeds[cnt].value) - { - cfsetispeed (termios_p, speeds[cnt].internal); - cfsetospeed (termios_p, speeds[cnt].internal); - return 0; - } + int rv; - __set_errno (EINVAL); + rv = cfsetospeed (termios_p, speed); + if (rv) + return rv; - return -1; + return cfsetispeed (termios_p, speed); } From patchwork Tue Jun 10 19:02:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114163 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DAB83858C54 for ; Tue, 10 Jun 2025 19:11:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3DAB83858C54 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=Vwon6+ob X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id CB0DC3858431 for ; Tue, 10 Jun 2025 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB0DC3858431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB0DC3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582195; cv=none; b=OhThCrWa7ljna8r0oGvSaFh1MRKIy1uiiF8bNNk3Of45sHLJde0T9usxUO9MQMWwqlx62u2ft7J46vEV4FBo3KfolfFTmF1EKlhV/yTo9VsohJ8gLpNdMWpGDDyPQVWm8zoLMEgtuSquAf/iGLd2uMk+NO/p4qRqTpG4uJ/0YAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582195; c=relaxed/simple; bh=rzo8bjHatWAkrv+XCN4xx0Ds4l5lmknTaihe4LScUmc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pn1UX8+CKCLURCrzwh1C8Gbs6mDB+Qrld9vxNFb993xtSqF2Av4qP4j71uZGtyzRqL2Kr2niQ/4i7CYyAZ+k72yBhTqDrBByvUX8WJ+CycpWHTs7r/Yvz2Y6VMcHMwtiPxVvDm6TAsSanVq/0FTTQNoZc4eTyqgtC7q+SCr8q/0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB0DC3858431 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arm2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:57 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arm2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582177; bh=eYM6YwFfW+2CsEfjv+/5J06eSYSWaXKHi2K8OrHwo5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vwon6+obJeCSLkl5TvqY6cnv61scfAJpV+JJLCcmvPb5rkDoiaILiLcmLLErCwBPJ vrYke5Qbx9ezEKFcKTFYyWZO4XAaq1oioJtgRNjX+/gEu3EA93gVoAZfwcKavKCZkG sQw5tYV4jFsckrJqUM6AjrNmuYFt2HjMEMIebSAKwak4s6j6ABZL6kJzoM91iYRHXT ObiYjYhaUMS9p7g1pncXAQflpUiajtiK+Ru0rVLYiOT4ZSLTV5zNoZXsZFazJeCnds zcFFWimxGI62TWz2z9wjxRyeckDxO6UEih9EEDFi2dlerOLJisL4rHMr0EoqmYuQKR n/yRKrT+oVrgg== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 09/15] hurd+generic/termios: make speed_t an unsigned int Date: Tue, 10 Jun 2025 12:02:20 -0700 Message-ID: <20250610190228.1124149-10-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" POSIX requires that speed_t is an unsigned integer type, so change the generic speed_t definition to be an unsigned int instead of a plain int. Reviewed-by: Samuel Thibault Signed-off-by: H. Peter Anvin (Intel) --- bits/termios.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bits/termios.h b/bits/termios.h index 9e3ed8ee7a08..398efa5ddd2f 100644 --- a/bits/termios.h +++ b/bits/termios.h @@ -105,7 +105,7 @@ typedef unsigned int tcflag_t; typedef unsigned char cc_t; /* Type of baud rate specifiers. */ -typedef int speed_t; +typedef unsigned int speed_t; /* Terminal control structure. */ struct termios From patchwork Tue Jun 10 19:02:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114169 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38BB03858CD1 for ; Tue, 10 Jun 2025 19:19:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38BB03858CD1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=gzqH3yCT X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id CB097385842D for ; Tue, 10 Jun 2025 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB097385842D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB097385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582195; cv=none; b=ltTYyQQLCU4mKa4ke54B2dKN9E5c9HxLvrbRep1A6XK+eQ1aSicpmvkQiauhemmS/1gPNfk2aTbwJ0BrIR/6+aWrkILV2PtVdEACh6x2WvSXo2ZMwO3HZbXYqVxoHKLHmCG0o8s/QFlVgDVJsXxHGVgMuinHe+J6fYInoav+UBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582195; c=relaxed/simple; bh=BkmiysznVRtWLyX4BrgfsXPCGmJvga7a6QpUW6NH65s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ioll7KLwSDTSWUW9v6iuCAB4yZjiFPFrQSsjggRGBPgZj/gL4P2UhYj+1okCDa4K1wkC3woJl8FDMbz22EOY5/xkb2tggtg0MJyp063jUglU4RFic1OpYOG7tdGFm920BGWLTXmmz10Xm37ciQ4P9Lm6d6tcymg8WI9GZWO0JCg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB097385842D Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arn2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:58 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arn2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582178; bh=6e+hSh9Ouq5C4i0XFhqrf4jbquh/yDHI4c0qsjBTO44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gzqH3yCTrCGFmVu6GSqEUhUC4qJDOx3Hmgq3gkjG9VxRqE0m5Sd/D/wLknaiq9xn6 5+O9cMIgFODr4bNalpKcWB3Rw1WBr74S3TiGVqAJuGGrxd+lQugy29fwyBoDZY/mRk ndFVLBlHXoTfMzcMWB2zygW17CteFAkZZfP9aJb+2Hb2IFEtJfxvYOMeAfx9AR4Akf 9TlnrWT1XI67YUf+x07GHSuyXVhp5U9T7cIaucfmgFYtxDvB0ue/xW2ItkpRkhbxXY LLqveR/RhpTaHhfea55p5Obfo9PP993dT4q/ZEhi2zalWR245H/oICgr5mBDxnnoW4 Hoi08e39+e2fg== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 10/15] termios: merge the termios baud definitions Date: Tue, 10 Jun 2025 12:02:21 -0700 Message-ID: <20250610190228.1124149-11-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PROLO_LEO1, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Now all platforms unconditionally use the "sane" definitions of the termios baud constants. Unify them into a common file. Note: I have made them explicitly unsigned to avoid problems with compiler warnings for comparisons of unequal signedness or similar. These constants were historically octal on most platforms, and so unsigned by default. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- .../sysv/linux/bits => bits}/termios-baud.h | 73 +++++++++++-------- bits/termios.h | 41 +---------- sysdeps/unix/sysv/linux/Makefile | 1 - sysdeps/unix/sysv/linux/bits/termios.h | 6 +- termios/Makefile | 4 +- 5 files changed, 48 insertions(+), 77 deletions(-) rename {sysdeps/unix/sysv/linux/bits => bits}/termios-baud.h (51%) diff --git a/sysdeps/unix/sysv/linux/bits/termios-baud.h b/bits/termios-baud.h similarity index 51% rename from sysdeps/unix/sysv/linux/bits/termios-baud.h rename to bits/termios-baud.h index 1e41338b5739..bafde1a6505c 100644 --- a/sysdeps/unix/sysv/linux/bits/termios-baud.h +++ b/bits/termios-baud.h @@ -1,4 +1,4 @@ -/* termios baud rate selection definitions. Linux/generic version. +/* termios baud rate selection definitions. Universal version for sane speed_t. Copyright (C) 2019-2025 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -20,37 +20,44 @@ # error "Never include directly; use instead." #endif -#define B0 0U -#define B50 50U -#define B75 75U -#define B110 110U -#define B134 134U -#define B150 150U -#define B200 200U -#define B300 300U -#define B600 600U -#define B1200 1200U -#define B1800 1800U -#define B2400 2400U -#define B4800 4800U -#define B7200 7200U -#define B9600 9600U -#define B14400 14400U -#define B19200 19200U -#define B28800 28800U -#define B33600 33600U -#define B38400 38400U -#define B57600 57600U -#define B76800 76800U -#define B115200 115200U -#define B153600 153600U -#define B230400 230400U -#define B307200 307200U -#define B460800 460800U -#define B500000 500000U -#define B576000 576000U -#define B614400 614400U -#define B921600 921600U +/* POSIX required baud rates */ +#define B0 0U /* Hang up or ispeed == ospeed */ +#define B50 50U +#define B75 75U +#define B110 110U +#define B134 134U /* Really 134.5 baud by POSIX spec */ +#define B150 150U +#define B200 200U +#define B300 300U +#define B600 600U +#define B1200 1200U +#define B1800 1800U +#define B2400 2400U +#define B4800 4800U +#define B9600 9600U +#define B19200 19200U +#define B38400 38400U +#ifdef __USE_MISC +# define EXTA B19200 +# define EXTB B38400 +#endif + +/* Other baud rates, "nonstandard" but known to be used */ +#define B7200 7200U +#define B14400 14400U +#define B28800 28800U +#define B33600 33600U +#define B57600 57600U +#define B76800 76800U +#define B115200 115200U +#define B153600 153600U +#define B230400 230400U +#define B307200 307200U +#define B460800 460800U +#define B500000 500000U +#define B576000 576000U +#define B614400 614400U +#define B921600 921600U #define B1000000 1000000U #define B1152000 1152000U #define B1500000 1500000U @@ -59,5 +66,7 @@ #define B3000000 3000000U #define B3500000 3500000U #define B4000000 4000000U +#define B5000000 5000000U +#define B10000000 10000000U #define __MAX_BAUD 4294967295U diff --git a/bits/termios.h b/bits/termios.h index 398efa5ddd2f..8f0b817dbf4c 100644 --- a/bits/termios.h +++ b/bits/termios.h @@ -20,6 +20,8 @@ # error "Never include directly; use instead." #endif +#include + /* These macros are also defined in some files (with numerically identical values), but this serves to shut up cpp's complaining. */ @@ -285,45 +287,6 @@ struct termios /* Input and output baud rates. */ speed_t __ispeed, __ospeed; -#define B0 0 /* Hang up. */ -#define B50 50 /* 50 baud. */ -#define B75 75 /* 75 baud. */ -#define B110 110 /* 110 baud. */ -#define B134 134 /* 134.5 baud. */ -#define B150 150 /* 150 baud. */ -#define B200 200 /* 200 baud. */ -#define B300 300 /* 300 baud. */ -#define B600 600 /* 600 baud. */ -#define B1200 1200 /* 1200 baud. */ -#define B1800 1800 /* 1800 baud. */ -#define B2400 2400 /* 2400 baud. */ -#define B4800 4800 /* 4800 baud. */ -#define B9600 9600 /* 9600 baud. */ -#define B7200 7200 /* 7200 baud. */ -#define B14400 14400 /* 14400 baud. */ -#define B19200 19200 /* 19200 baud. */ -#define B28800 28800 /* 28800 baud. */ -#define B38400 38400 /* 38400 baud. */ -#ifdef __USE_MISC -# define EXTA 19200 -# define EXTB 38400 -#endif -#define B57600 57600 -#define B76800 76800 -#define B115200 115200 -#define B230400 230400 -#define B460800 460800 -#define B500000 500000 -#define B576000 576000 -#define B921600 921600 -#define B1000000 1000000 -#define B1152000 1152000 -#define B1500000 1500000 -#define B2000000 2000000 -#define B2500000 2500000 -#define B3000000 3000000 -#define B3500000 3500000 -#define B4000000 4000000 }; #define _IOT_termios /* Hurd ioctl type field. */ \ diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index ebcf820403ff..a14b8c1f6181 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -151,7 +151,6 @@ sysdep_headers += \ bits/struct_stat.h \ bits/struct_stat_time64_helper.h \ bits/syscall.h \ - bits/termios-baud.h \ bits/termios-c_cc.h \ bits/termios-c_cflag.h \ bits/termios-c_iflag.h \ diff --git a/sysdeps/unix/sysv/linux/bits/termios.h b/sysdeps/unix/sysv/linux/bits/termios.h index 14de3fcb5507..20746a072759 100644 --- a/sysdeps/unix/sysv/linux/bits/termios.h +++ b/sysdeps/unix/sysv/linux/bits/termios.h @@ -35,6 +35,7 @@ typedef unsigned int tcflag_t; /* c_cflag bit meaning */ #include +#ifdef __USE_MISC #define __B0 0000000 /* hang up */ #define __B50 0000001 #define __B75 0000002 @@ -53,9 +54,8 @@ typedef unsigned int tcflag_t; #define __B38400 0000017 #include -#ifdef __USE_MISC -# define EXTA __B19200 -# define EXTB __B38400 +# define __EXTA __B19200 +# define __EXTB __B38400 # define BOTHER __BOTHER #endif diff --git a/termios/Makefile b/termios/Makefile index 08075424cb8a..43235346f2db 100644 --- a/termios/Makefile +++ b/termios/Makefile @@ -22,8 +22,8 @@ subdir := termios include ../Makeconfig -headers := termios.h bits/termios.h sys/ttydefaults.h sys/termios.h \ - sys/ttychars.h +headers := termios.h bits/termios.h bits/termios-baud.h \ + sys/ttydefaults.h sys/termios.h sys/ttychars.h routines := speed cfsetspeed tcsetattr tcgetattr tcgetpgrp tcsetpgrp \ tcdrain tcflow tcflush tcsendbrk cfmakeraw tcgetsid From patchwork Tue Jun 10 19:02:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114170 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BBE903858D35 for ; Tue, 10 Jun 2025 19:20:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBE903858D35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=LPxKUYf3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id CB060385840E for ; Tue, 10 Jun 2025 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB060385840E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB060385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582195; cv=none; b=qk6q8NCGlNWjLTi80I+NSXah7LP0ozSWWc/exgdlt0mcxMPNA8HiTTqHY59MXh4rumB+KS71FmmZov4//tEFmDvapb1ABUofeIhqm2M9v7BC4CApaKpWCT73SbEDR2/N2Cxuw5Hj85X7nL1VZvTRpKixEPFBs3/26sK3wZyDXqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582195; c=relaxed/simple; bh=sK4z5s4YKrtoD6FkkiotzEsJ+FYA/HsCvaMvpZKWfa4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=X4ESgxObXWh/QkmvZXe10aGIghXRhiGyerDpBtpvywmsWt+Oq0Ic/otbe98DrNmyIorkqt3jE+t/5cnz0ln+JgO2cV7mxiZabnyeWbuVa4USKQ2XHV95Kso891sbsKrO5oDl8zWDE1TmUZUaHYFE2kCo6tp1wJrx5oLp/p9uiIM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB060385840E Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2aro2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:58 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2aro2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582179; bh=wsZX3O5DGnEmP33HjnmywzjR6y326wL49rjEOkTjVU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LPxKUYf3k1FRfmLjgk7PfY/uKApGRmII2avYN5Bi8rnnG04wCPQw1NKl2CoCZlfuQ IQZOsuHrKm1KcEZZkL4jtPLaZB+Mi+8n2+Y0O55Laocu5mV5Frqs3LOeImYtPf1e2M q1kHmGkk7LZtdRXqqYBRyfyAu64dOuJiigeTlteposqR3eiWIw2DTBfwBu11vijqF6 5l0MwfrEq0hmUBuXwemR2kC1V3vUpaufOsjLLdcWBJqlZ8DbfBcqwHwxF0Pbb3Ahkh XhYIjgpNVOHgbWqSbEl6jXPC5CyW3W/R1S+3CyaL+g0p6lPGLnX6AeBjqxfcJSnNOA Hgkd0VrduAazQ== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 11/15] manual: document all the termios Bxxx constants in the manual Date: Tue, 10 Jun 2025 12:02:22 -0700 Message-ID: <20250610190228.1124149-12-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Add all the Bxxx constants defined in the now-generic in the manual. Reviewed-by: Adhemerval Zanella Signed-off-by: H. Peter Anvin (Intel) --- manual/terminal.texi | 74 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/manual/terminal.texi b/manual/terminal.texi index b437cb53221c..72d0282efdbc 100644 --- a/manual/terminal.texi +++ b/manual/terminal.texi @@ -1106,12 +1106,24 @@ the only speeds that typical serial lines can support. @comment POSIX.1 @vindex B4800 @comment termios.h +@comment GNU +@vindex B7200 +@comment termios.h @comment POSIX.1 @vindex B9600 @comment termios.h +@comment GNU +@vindex B14400 +@comment termios.h @comment POSIX.1 @vindex B19200 @comment termios.h +@comment GNU +@vindex B28800 +@comment termios.h +@comment GNU +@vindex B33600 +@comment termios.h @comment POSIX.1 @vindex B38400 @comment termios.h @@ -1119,18 +1131,72 @@ the only speeds that typical serial lines can support. @vindex B57600 @comment termios.h @comment GNU +@vindex B76800 +@comment termios.h +@comment GNU @vindex B115200 @comment termios.h @comment GNU +@vindex B153600 +@comment termios.h +@comment GNU @vindex B230400 @comment termios.h @comment GNU +@vindex B307200 +@comment termios.h +@comment GNU @vindex B460800 +@comment termios.h +@comment GNU +@vindex B500000 +@comment termios.h +@comment GNU +@vindex B576000 +@comment termios.h +@comment GNU +@vindex B614400 +@comment termios.h +@comment GNU +@vindex B921600 +@comment termios.h +@comment GNU +@vindex B1000000 +@comment termios.h +@comment GNU +@vindex B1152000 +@comment termios.h +@comment GNU +@vindex B1500000 +@comment termios.h +@comment GNU +@vindex B2000000 +@comment termios.h +@comment GNU +@vindex B2500000 +@comment termios.h +@comment GNU +@vindex B3000000 +@comment termios.h +@comment GNU +@vindex B3500000 +@comment termios.h +@comment GNU +@vindex B4000000 +@comment termios.h +@comment GNU +@vindex B5000000 +@comment termios.h +@comment GNU +@vindex B10000000 @smallexample -B0 B50 B75 B110 B134 B150 B200 -B300 B600 B1200 B1800 B2400 B4800 -B9600 B19200 B38400 B57600 B115200 -B230400 B460800 +B0 B50 B75 B110 B134 B150 B200 B300 B600 B1200 +B1800 B2400 B4800 B7200 B9600 B14400 B19200 +B28800 B33600 B38400 B57600 B76800 B115200 +B153600 B230400 B307200 B460800 B500000 +B576000 B614400 B921600 B1000000 B1152000 +B1500000 B2000000 B2500000 B3000000 +B3500000 B4000000 B5000000 B10000000 @end smallexample @vindex EXTA From patchwork Tue Jun 10 19:02:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114172 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 894D4385829B for ; Tue, 10 Jun 2025 19:23:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 894D4385829B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=bKbLHa/d X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id B7D763857C58 for ; Tue, 10 Jun 2025 19:03:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B7D763857C58 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B7D763857C58 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582192; cv=none; b=cujlFNfl0/PD3Ww4OGs2ku1erhlWTeLvlhPee2+SLfq90PU+HvFkBOEz+BHoKkp56wf35l2Blg5Py1+g+FChhweMZM7fmiyQuihHBmVoF/7CDXJfD5nHCJtiFq8b0+QeMFhFhiEmG89GO3h/JfWXDZC7iXiNoFg+1y6t5hligX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582192; c=relaxed/simple; bh=jf2FWLrEvEU1zP9YFB87sLSej8ZPDd+urzo8yjRQlpU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bfdEtT/9tvGJ3qpyclZMpBkppaMkpjgmZwFkcuKs0urpNrS/oqLonjUjhHc4HmEkQdayRVRN18n/CyNFtfAyD2HEM/Pdfqj5JWFMXJy8aIaTbdCPrvM89Tm2BM7SdWNRJSRGSTN/vmkbeYgGCqNjlSD0XCCqDfPSx6++fKl+aW8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7D763857C58 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arp2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:59 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arp2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582179; bh=90JNWvUF4GeJVXP2+f4pplhL9cLpuOL+uFEuvCU2GZk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bKbLHa/diFR6g1qarKeCD8VZIQnye4QsEiVdGpowXjlb994BMlo77XMlTm2Agc5MA HBnkShLJp7Glej3C63gTt7VAX/KxE2BuqVAcCGPgZmzCfcNQ8zOwW3BgszzBxO2jCn o38jSOk/ga1xNVAdoWApO+MOVSNwVC2Vvqcsr4FrZ+z78oVErNJLQcWzMGycoq3Qav TRDgpYkPRDjclFEZX2Gq+f1tN2P2+OuYQkD/Z9QoIfhwB/DvDxEAjHs4JMNDo6Q6J6 JLGyFJkCt2ekJevV2htJbn1u5YMbUXcem9fb1SZaeUKndM+P+p0Ox8626aje4IIiSM zfaR0UXBXJdxw== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 12/15] termios: add new baud_t interface, defined to be explicitly numeric Date: Tue, 10 Jun 2025 12:02:23 -0700 Message-ID: <20250610190228.1124149-13-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Add an explicitly numeric interface for baudrate setting. For glibc, this only announces what is a fair accompli, but this is a plausible way forward for standardization, and may be possible to infill on non-compliant systems. The POSIX committee has stated: [https://www.austingroupbugs.net/view.php?id=1916#c7135] A future version of this standard is expected to add at least the following symbolic constants for use as values of objects of type speed_t: B57600, B115200, B230400, B460800, and B921600. Implementations are encouraged to propose additional interfaces which will make it possible to set and query a wider range of speeds than just those enumerated by the constants beginning with B. If a set of common interfaces emerges between several implementations, a future version of this standard will likely add those interfaces. This is exactly that interface. The use of the term "baud" is due to the need to have a term contrasting "speed", and it is already well established as a legacy term -- including in the names of the legacy Bxxx constants. Futhermore, it *is* valid from the point of view that the termios interface fundamentally emulates an RS-232 serial port as far as the application software is concerned. The documentation states that for the current version of glibc, speed_t == baud_t, but explicitly declares that this may not be the case in the future. Signed-off-by: H. Peter Anvin (Intel) Reviewed-by: Adhemerval Zanella --- include/termios.h | 25 +++++- manual/terminal.texi | 90 ++++++++++++++++--- sysdeps/mach/hurd/i386/libc.abilist | 5 ++ sysdeps/mach/hurd/x86_64/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/aarch64/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/alpha/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/arc/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/arm/be/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/arm/le/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/cfsetspeed.c | 1 + sysdeps/unix/sysv/linux/csky/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/hppa/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/i386/libc.abilist | 5 ++ .../sysv/linux/loongarch/lp64/libc.abilist | 5 ++ .../sysv/linux/m68k/coldfire/libc.abilist | 5 ++ .../unix/sysv/linux/m68k/m680x0/libc.abilist | 5 ++ .../sysv/linux/microblaze/be/libc.abilist | 5 ++ .../sysv/linux/microblaze/le/libc.abilist | 5 ++ .../sysv/linux/mips/mips32/fpu/libc.abilist | 5 ++ .../sysv/linux/mips/mips32/nofpu/libc.abilist | 5 ++ .../sysv/linux/mips/mips64/n32/libc.abilist | 5 ++ .../sysv/linux/mips/mips64/n64/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/or1k/libc.abilist | 5 ++ .../linux/powerpc/powerpc32/fpu/libc.abilist | 5 ++ .../powerpc/powerpc32/nofpu/libc.abilist | 5 ++ .../linux/powerpc/powerpc64/be/libc.abilist | 5 ++ .../linux/powerpc/powerpc64/le/libc.abilist | 5 ++ .../unix/sysv/linux/riscv/rv32/libc.abilist | 5 ++ .../unix/sysv/linux/riscv/rv64/libc.abilist | 5 ++ .../unix/sysv/linux/s390/s390-32/libc.abilist | 5 ++ .../unix/sysv/linux/s390/s390-64/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/sh/be/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/sh/le/libc.abilist | 5 ++ .../sysv/linux/sparc/sparc32/libc.abilist | 5 ++ .../sysv/linux/sparc/sparc64/libc.abilist | 5 ++ sysdeps/unix/sysv/linux/speed.c | 4 + .../unix/sysv/linux/x86_64/64/libc.abilist | 5 ++ .../unix/sysv/linux/x86_64/x32/libc.abilist | 5 ++ termios/Makefile | 3 +- termios/Versions | 4 + termios/baud.c | 56 ++++++++++++ termios/cfsetbaud.c | 29 ++++++ termios/cfsetspeed.c | 8 +- termios/speed.c | 18 ++-- termios/termios.h | 19 +++- 45 files changed, 400 insertions(+), 27 deletions(-) create mode 100644 termios/baud.c create mode 100644 termios/cfsetbaud.c diff --git a/include/termios.h b/include/termios.h index a79da7a1f379..d46608278fec 100644 --- a/include/termios.h +++ b/include/termios.h @@ -2,7 +2,18 @@ #include #ifndef _ISOMAC -/* Now define the internal interfaces. */ +extern speed_t __cfgetospeed (const struct termios *__termios_p); +extern speed_t __cfgetispeed (const struct termios *__termios_p); +extern int __cfsetospeed (struct termios *__termios_p, speed_t __speed); +extern int __cfsetispeed (struct termios *__termios_p, speed_t __speed); +extern int __cfsetspeed (struct termios *__termios_p, speed_t __speed); + +extern baud_t __cfgetobaud (const struct termios *__termios_p); +extern baud_t __cfgetibaud (const struct termios *__termios_p); +extern int __cfsetobaud (struct termios *__termios_p, baud_t __baud); +extern int __cfsetibaud (struct termios *__termios_p, baud_t __baud); +extern int __cfsetbaud (struct termios *__termios_p, baud_t __baud); + extern int __tcgetattr (int __fd, struct termios *__termios_p); extern int __tcsetattr (int __fd, int __optional_actions, const struct termios *__termios_p); @@ -11,8 +22,16 @@ extern int __libc_tcdrain (int __fd); libc_hidden_proto (__tcgetattr) libc_hidden_proto (__tcsetattr) -libc_hidden_proto (cfsetispeed) -libc_hidden_proto (cfsetospeed) +libc_hidden_proto (__cfgetispeed) +libc_hidden_proto (__cfgetospeed) +libc_hidden_proto (__cfsetispeed) +libc_hidden_proto (__cfsetospeed) +libc_hidden_proto (__cfsetspeed) +libc_hidden_proto (__cfgetibaud) +libc_hidden_proto (__cfgetobaud) +libc_hidden_proto (__cfsetibaud) +libc_hidden_proto (__cfsetobaud) +libc_hidden_proto (__cfsetbaud) #endif #endif diff --git a/manual/terminal.texi b/manual/terminal.texi index 72d0282efdbc..de9554d83757 100644 --- a/manual/terminal.texi +++ b/manual/terminal.texi @@ -771,11 +771,11 @@ If this bit is set, it says to ignore the control modes and line speed values entirely. This is only meaningful in a call to @code{tcsetattr}. The @code{c_cflag} member and the line speed values returned by -@code{cfgetispeed} and @code{cfgetospeed} will be unaffected by the -call. @code{CIGNORE} is useful if you want to set all the software -modes in the other members, but leave the hardware details in -@code{c_cflag} unchanged. (This is how the @code{TCSASOFT} flag to -@code{tcsettattr} works.) +@code{cfgetispeed}, @code{cfgetospeed}, @code{cfgetibaud} and +@code{cfsetibaud} will be unaffected by the call. @code{CIGNORE} is +useful if you want to set all the software modes in the other members, +but leave the hardware details in @code{c_cflag} unchanged. (This is +how the @code{TCSASOFT} flag to @code{tcsettattr} works.) This bit is never set in the structure filled in by @code{tcgetattr}. @end deftypevr @@ -1047,14 +1047,15 @@ The @code{speed_t} type is an unsigned integer data type used to represent line speeds. @end deftp -The functions @code{cfsetospeed} and @code{cfsetispeed} report errors -only for speed values that the system simply cannot handle. If you -specify a speed value that is basically acceptable, then those functions -will succeed. But they do not check that a particular hardware device -can actually support the specified speeds---in fact, they don't know -which device you plan to set the speed for. If you use @code{tcsetattr} -to set the speed of a particular device to a value that it cannot -handle, @code{tcsetattr} returns @math{-1}. +@deftypefun speed_t cfgetospeed (const struct termios *@var{termios-p}) +@standards{POSIX.1, termios.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +@c Direct access to a single termios field, except on Linux, where +@c multiple accesses may take place. No worries either way, callers +@c must ensure mutual exclusion on such non-opaque types. +This function returns the output line speed stored in the structure +@code{*@var{termios-p}}. +@end deftypefun @strong{Portability note:} In @theglibc{}, the functions above accept speeds measured in bits per second as input, and return speed @@ -1205,6 +1206,69 @@ BSD defines two additional speed symbols as aliases: @code{EXTA} is an alias for @code{B19200} and @code{EXTB} is an alias for @code{B38400}. These aliases are obsolete. +@deftypefun baud_t cfgetibaud (const struct termios *@var{termios-p}) +@standards{GNU, termios.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function returns the input line baud rate stored in the structure +@code{*@var{termios-p}}. +@end deftypefun + +@deftypefun int cfsetobaud (struct termios *@var{termios-p}, baud_t @var{baud}) +@standards{GNU, termios.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function stores @var{baud} in @code{*@var{termios-p}} as the output +baud rate. The normal return value is @math{0}; a value of @math{-1} +indicates an error. If @var{baud} is not a valid baud rate, @code{cfsetobaud} +returns @math{-1}. +@end deftypefun + +@deftypefun int cfsetibaud (struct termios *@var{termios-p}, baud_t @var{baud}) +@standards{GNU, termios.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +This function stores @var{baud} in @code{*@var{termios-p}} as the input +baud rate. The normal return value is @math{0}; a value of @math{-1} +indicates an error. If @var{baud} is not a valid baud rate, @code{cfsetobaud} +returns @math{-1}. +@end deftypefun + +@deftypefun int cfsetbaud (struct termios *@var{termios-p}, baud_t @var{baud}) +@standards{GNU, termios.h} +@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}} +@c There's no guarantee that the two calls are atomic, but since this is +@c not an opaque type, callers ought to ensure mutual exclusion to the +@c termios object. + +@c cfsetbaud ok +@c cfsetibaud ok +@c cfsetobaud ok +This function stores @var{baud} in @code{*@var{termios-p}} as both the +input and output baud rates. The normal return value is @math{0}; a value +of @math{-1} indicates an error. If @var{baud} is not a valid baud rate, +@code{cfsetbaud} returns @math{-1}. +@end deftypefun + +@deftp {Data Type} baud_t +@standards{GNU} +The @code{baud_t} type is a numeric data type used to represent line +baud rates. It will always represent the actual numeric value +representing the baud rate, unlike @code{speed_t}. In the current +version of @theglibc{} this is the same type as @code{speed_t}, but this +may not be the case in future versions, or on other implementations; it +may not even necessarily be an integer type. + +@end deftp + +The functions @code{cfsetospeed}, @code{cfsetispeed}, @code{cfsetobaud} +and @code{cfsetibaud} report errors only for speed values that the +system simply cannot handle. If you specify a speed value that is +basically acceptable, then those functions will succeed. But they do +not check that a particular hardware device can actually support the +specified speeds---in fact, they don't know which device you plan to set +the speed for. If you use @code{tcsetattr} to set the speed of a +particular device to a value that it cannot handle, either @code{tcsetattr} +returns @math{-1}, or the value is adjusted to the closest supported +value, depending on the policy of the kernel driver. + @node Special Characters @subsection Special Characters diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist index 3e183f5c02ea..564d51c6f9b5 100644 --- a/sysdeps/mach/hurd/i386/libc.abilist +++ b/sysdeps/mach/hurd/i386/libc.abilist @@ -2586,6 +2586,11 @@ GLIBC_2.41 pthread_mutexattr_settype F GLIBC_2.41 pthread_sigmask F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F +GLIBC_2.42 cfgetobaud F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 pthread_barrier_destroy F GLIBC_2.42 pthread_barrier_init F GLIBC_2.42 pthread_barrier_wait F diff --git a/sysdeps/mach/hurd/x86_64/libc.abilist b/sysdeps/mach/hurd/x86_64/libc.abilist index 688ee26f4b25..a5e31ad4a021 100644 --- a/sysdeps/mach/hurd/x86_64/libc.abilist +++ b/sysdeps/mach/hurd/x86_64/libc.abilist @@ -2269,6 +2269,11 @@ GLIBC_2.41 pthread_mutexattr_settype F GLIBC_2.41 pthread_sigmask F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F +GLIBC_2.42 cfgetobaud F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 pthread_barrier_destroy F GLIBC_2.42 pthread_barrier_init F GLIBC_2.42 pthread_barrier_wait F diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index fdccf84d8f88..a22e65143209 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2752,9 +2752,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index 1e3f2781553e..4b5736a3b6d3 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -3099,9 +3099,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index 7b7717d1d146..b8a44784bdc9 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -2513,9 +2513,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index f64bf3f3278e..959e44672f2a 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -2805,9 +2805,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index c065fe80fcd0..a930d1a52bbf 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -2802,9 +2802,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/cfsetspeed.c b/sysdeps/unix/sysv/linux/cfsetspeed.c index 4a8f9b2ca186..1d8bb63ee37f 100644 --- a/sysdeps/unix/sysv/linux/cfsetspeed.c +++ b/sysdeps/unix/sysv/linux/cfsetspeed.c @@ -31,6 +31,7 @@ __cfsetspeed (struct termios *termios_p, speed_t speed) return 0; } +libc_hidden_def (__cfsetspeed) versioned_symbol (libc, __cfsetspeed, cfsetspeed, GLIBC_2_42); #if _TERMIOS_OLD_COMPAT diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index 69ba60ea093e..6325fc12c4b4 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2789,9 +2789,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index dea7c09692bd..86b3fbdeec14 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2826,9 +2826,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 4c05ab1c6e07..6555592d86d9 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -3009,9 +3009,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist index 6ab4968d17ce..a6cab9612a4c 100644 --- a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist @@ -2273,9 +2273,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist index e553bdc8a3b0..7b7b72aa50f8 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist @@ -2785,9 +2785,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist index 1239f0d7a029..df398e43c62d 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist @@ -2952,9 +2952,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist index 943e89a45fd4..ca8df6f4b0c1 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist @@ -2838,9 +2838,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist index 9c303d9d9aa8..950815484752 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist @@ -2835,9 +2835,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist index 6eb6fd476b0d..4d51cc428f15 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist @@ -2913,9 +2913,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist index 58a43bb9b3d3..7f90fadc76ec 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist @@ -2911,9 +2911,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist index abab2ad80758..fc366d1bd0de 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist @@ -2919,9 +2919,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist index 2e31f6eed6b7..debd5c37c9af 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist @@ -2821,9 +2821,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist index b54c078b520c..b62d59f1afe9 100644 --- a/sysdeps/unix/sysv/linux/or1k/libc.abilist +++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist @@ -2263,9 +2263,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist index c30e17cdfca2..883e66f3ae6a 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist @@ -3142,9 +3142,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist index f3c0c0205249..84cd9e0e18c7 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist @@ -3187,9 +3187,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist index 6e1d141ca7fd..8832568ab3bf 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist @@ -2896,9 +2896,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist index 441296c7e8ba..b6ff8016e4b3 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist @@ -2972,9 +2972,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist index bcc0ed8d6a5f..1771a2370c5a 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist @@ -2516,9 +2516,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist index d55b553c0e39..4b48352fd99b 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist @@ -2716,9 +2716,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist index a45b8874f0a3..f0decc787bab 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist @@ -3140,9 +3140,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist index 17483dcc4895..da8a2bfb74aa 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist @@ -2933,9 +2933,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist index cb62b6e083eb..fb303418946b 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist @@ -2832,9 +2832,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist index ee6f2d017073..d71667343278 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist @@ -2829,9 +2829,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist index 943e130d3a8a..6deedf216dbe 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist @@ -3161,9 +3161,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist index 1017babb1d59..1ce22bf036b7 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist @@ -2797,9 +2797,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/speed.c b/sysdeps/unix/sysv/linux/speed.c index c9f4bb9d3f63..4efb0ded59ba 100644 --- a/sysdeps/unix/sysv/linux/speed.c +++ b/sysdeps/unix/sysv/linux/speed.c @@ -263,6 +263,7 @@ __cfgetospeed (const struct termios *termios_p) { return termios_p->c_ospeed; } +libc_hidden_def (__cfgetospeed) versioned_symbol (libc, __cfgetospeed, cfgetospeed, GLIBC_2_42); /* Return the input baud rate stored in *TERMIOS_P. */ @@ -271,6 +272,7 @@ __cfgetispeed (const struct termios *termios_p) { return termios_p->c_ispeed; } +libc_hidden_def (__cfgetispeed) versioned_symbol (libc, __cfgetispeed, cfgetispeed, GLIBC_2_42); /* Set the output baud rate stored in *TERMIOS_P to SPEED. */ @@ -285,6 +287,7 @@ __cfsetospeed (struct termios *termios_p, speed_t speed) return 0; } +libc_hidden_def (__cfsetospeed) versioned_symbol (libc, __cfsetospeed, cfsetospeed, GLIBC_2_42); /* Set the input baud rate stored in *TERMIOS_P to SPEED. */ @@ -299,6 +302,7 @@ __cfsetispeed (struct termios *termios_p, speed_t speed) return 0; } +libc_hidden_def (__cfsetispeed) versioned_symbol (libc, __cfsetispeed, cfsetispeed, GLIBC_2_42); #if _TERMIOS_OLD_COMPAT diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index ccf6ca2c8876..564877250b25 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -2748,9 +2748,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index 1e3e283954d5..25a39d094342 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -2767,9 +2767,14 @@ GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.42 __inet_ntop_chk F GLIBC_2.42 __inet_pton_chk F +GLIBC_2.42 cfgetibaud F GLIBC_2.42 cfgetispeed F +GLIBC_2.42 cfgetobaud F GLIBC_2.42 cfgetospeed F +GLIBC_2.42 cfsetbaud F +GLIBC_2.42 cfsetibaud F GLIBC_2.42 cfsetispeed F +GLIBC_2.42 cfsetobaud F GLIBC_2.42 cfsetospeed F GLIBC_2.42 cfsetspeed F GLIBC_2.42 pthread_gettid_np F diff --git a/termios/Makefile b/termios/Makefile index 43235346f2db..7dc3830ab6ef 100644 --- a/termios/Makefile +++ b/termios/Makefile @@ -26,7 +26,8 @@ headers := termios.h bits/termios.h bits/termios-baud.h \ sys/ttydefaults.h sys/termios.h sys/ttychars.h routines := speed cfsetspeed tcsetattr tcgetattr tcgetpgrp tcsetpgrp \ - tcdrain tcflow tcflush tcsendbrk cfmakeraw tcgetsid + tcdrain tcflow tcflush tcsendbrk cfmakeraw tcgetsid \ + baud cfsetbaud include ../Rules diff --git a/termios/Versions b/termios/Versions index 711ed0334b52..a5eec8325753 100644 --- a/termios/Versions +++ b/termios/Versions @@ -11,4 +11,8 @@ libc { # t* tcgetsid; } + GLIBC_2.42 { + # cf*baud + cfgetibaud; cfgetobaud; cfsetibaud; cfsetobaud; cfsetbaud; + } } diff --git a/termios/baud.c b/termios/baud.c new file mode 100644 index 000000000000..27c06e937fdb --- /dev/null +++ b/termios/baud.c @@ -0,0 +1,56 @@ +/* `struct termios' speed frobnication functions, baud rate wrappers. + Any platform which doesn't have Bxxx == xxx for all baud rate + constants will need to override this file. + + Copyright (C) 1991-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +baud_t +__cfgetobaud (const struct termios *termios_p) +{ + return __cfgetospeed (termios_p); +} +libc_hidden_def (__cfgetobaud) +weak_alias (__cfgetobaud, cfgetobaud) + +baud_t +__cfgetibaud (const struct termios *termios_p) +{ + return __cfgetispeed (termios_p); +} +libc_hidden_def (__cfgetibaud) +weak_alias (__cfgetibaud, cfgetibaud) + +int +__cfsetobaud (struct termios *termios_p, baud_t baud) +{ + return __cfsetospeed (termios_p, baud); +} +libc_hidden_def (__cfsetobaud) +weak_alias (__cfsetobaud, cfsetobaud) + +int +__cfsetibaud (struct termios *termios_p, baud_t baud) +{ + return __cfsetispeed (termios_p, baud); +} +libc_hidden_def (__cfsetibaud) +weak_alias (__cfsetibaud, cfsetibaud) diff --git a/termios/cfsetbaud.c b/termios/cfsetbaud.c new file mode 100644 index 000000000000..b76b51e4dd77 --- /dev/null +++ b/termios/cfsetbaud.c @@ -0,0 +1,29 @@ +/* Copyright (C) 1992-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +/* Set both the input and output baud rates stored in *TERMIOS_P to BAUD. */ +int +__cfsetbaud (struct termios *termios_p, baud_t baud) +{ + return __cfsetspeed (termios_p, baud); +} +libc_hidden_def (__cfsetbaud) +weak_alias (__cfsetbaud, cfsetbaud) diff --git a/termios/cfsetspeed.c b/termios/cfsetspeed.c index 257c6387aaa0..a68e63a9a0c3 100644 --- a/termios/cfsetspeed.c +++ b/termios/cfsetspeed.c @@ -21,13 +21,15 @@ /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */ int -cfsetspeed (struct termios *termios_p, speed_t speed) +__cfsetspeed (struct termios *termios_p, speed_t speed) { int rv; - rv = cfsetospeed (termios_p, speed); + rv = __cfsetospeed (termios_p, speed); if (rv) return rv; - return cfsetispeed (termios_p, speed); + return __cfsetispeed (termios_p, speed); } +libc_hidden_def (__cfsetspeed) +weak_alias (__cfsetspeed, cfsetspeed) diff --git a/termios/speed.c b/termios/speed.c index d65bf03567f3..5030621518fa 100644 --- a/termios/speed.c +++ b/termios/speed.c @@ -22,21 +22,25 @@ /* Return the output baud rate stored in *TERMIOS_P. */ speed_t -cfgetospeed (const struct termios *termios_p) +__cfgetospeed (const struct termios *termios_p) { return termios_p->__ospeed; } +libc_hidden_def (__cfgetospeed) +weak_alias (__cfgetospeed, cfgetospeed) /* Return the input baud rate stored in *TERMIOS_P. */ speed_t -cfgetispeed (const struct termios *termios_p) +__cfgetispeed (const struct termios *termios_p) { return termios_p->__ispeed; } +libc_hidden_def (__cfgetispeed) +weak_alias (__cfgetispeed, cfgetispeed) /* Set the output baud rate stored in *TERMIOS_P to SPEED. */ int -cfsetospeed (struct termios *termios_p, speed_t speed) +__cfsetospeed (struct termios *termios_p, speed_t speed) { if (termios_p == NULL) { @@ -47,11 +51,12 @@ cfsetospeed (struct termios *termios_p, speed_t speed) termios_p->__ospeed = speed; return 0; } -libc_hidden_def (cfsetospeed) +libc_hidden_def (__cfsetospeed) +weak_alias (__cfsetospeed, cfsetospeed) /* Set the input baud rate stored in *TERMIOS_P to SPEED. */ int -cfsetispeed (struct termios *termios_p, speed_t speed) +__cfsetispeed (struct termios *termios_p, speed_t speed) { if (termios_p == NULL) { @@ -62,4 +67,5 @@ cfsetispeed (struct termios *termios_p, speed_t speed) termios_p->__ispeed = speed; return 0; } -libc_hidden_def (cfsetispeed) +libc_hidden_def (__cfsetispeed) +weak_alias (__cfsetispeed, cfsetispeed) diff --git a/termios/termios.h b/termios/termios.h index 1755c505272f..788c98240596 100644 --- a/termios/termios.h +++ b/termios/termios.h @@ -59,8 +59,25 @@ extern int cfsetispeed (struct termios *__termios_p, speed_t __speed) __THROW; #ifdef __USE_MISC /* Set both the input and output baud rates in *TERMIOS_OP to SPEED. */ extern int cfsetspeed (struct termios *__termios_p, speed_t __speed) __THROW; -#endif +/* Interfaces that are explicitly numeric representations of baud rates */ +typedef speed_t baud_t; + +/* Return the output baud rate stored in *TERMIOS_P. */ +extern baud_t cfgetobaud (const struct termios *__termios_p) __THROW; + +/* Return the input baud rate stored in *TERMIOS_P. */ +extern baud_t cfgetibaud (const struct termios *__termios_p) __THROW; + +/* Set the output baud rate stored in *TERMIOS_P to BAUD. */ +extern int cfsetobaud (struct termios *__termios_p, baud_t __baud) __THROW; + +/* Set the input baud rate stored in *TERMIOS_P to BAUD. */ +extern int cfsetibaud (struct termios *__termios_p, baud_t __baud) __THROW; + +/* Set both the input and output baud rates in *TERMIOS_OP to BAUD. */ +extern int cfsetbaud (struct termios *__termios_p, baud_t __baud) __THROW; +#endif /* Put the state of FD into *TERMIOS_P. */ extern int tcgetattr (int __fd, struct termios *__termios_p) __THROW; From patchwork Tue Jun 10 19:02:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114162 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B38F3858D35 for ; Tue, 10 Jun 2025 19:07:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B38F3858D35 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=sYyZWxq7 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 12B043858417 for ; Tue, 10 Jun 2025 19:03:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12B043858417 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12B043858417 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582193; cv=none; b=ulH/dF0FqjFDDxGCokOHfy7NX8kn9eVK/J2dkXlfiR/Z3QAjJHaqKW8RH+NwK0CzC2g90t9illW+PXrBPx9l0qv4Z3Hjf/RgrZpz1n9hXMU4sz+TTsCBRuGFELjw1I6JM+g0GqsOGZzvPnMyY06Ata/SKn582zF+MMbT9L3zuqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582193; c=relaxed/simple; bh=EZ5dCITwj9ZQO4EGw0WwNk9/WMZRLmzdw2zQLCANb64=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ipc9KL8eWaIM6iN80o1u3obK5TRrq6+LtMCGWnfveuJHGWbX0MvlUJ8PSsgPtASi1K2xWjFU+VYiaRj/qZuJa+acoP7mxEa2T+DUTJy9CBHYqWdrX8HaACH2/A7n6nCoxj/jAIVE+hpV/3ARRsb4fxCE3X/u5SakijlG0VvVBrE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12B043858417 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arq2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:02:59 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arq2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582180; bh=q3N85CEkVwXn+RQtR2Fq7MfCplLtmod6yK13FLG8zBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYyZWxq7XkDbBvB8zPvenF7yTQmoDK6511Jb31ksuXwJTU2ihZ5yz8IBG6DGxx2Ix UF98yC2Vd0F5mijD6svzCibOTI9G6S+1ehlJyEhI1RmIAzFeVuEfY37tVejhHg/vTm DbEAtMsvh//FaoCiMBJZGqbyFPSCZGq5IXSMoe8EkMMqXuYEtSUSg8dH3hghidDM3/ x3U7CJjZ0Xzbc19oh17efJPyr2vJrQp9ThHivoptbWhGiWVwmPd04sMuXCAMo43lOY d73+J4DAU6UwFZSGAq7ebEKrwZiF8z85W0//RRS/PbTvKzVF+vMyWu/ihul60meKYQ mBOt+S/hfr8zQ== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 13/15] termios: unify the naming of the termios speed fields Date: Tue, 10 Jun 2025 12:02:24 -0700 Message-ID: <20250610190228.1124149-14-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" The generic code has __ispeed and __ospeed; Linux has c_ispeed and c_ospeed. Use an anonymous union member to allow both set of names on all platforms. Reviewed-by: Adhemerval Zanella Signed-off-by: H. Peter Anvin (Intel) --- bits/termios.h | 11 ++++++++++- sysdeps/unix/sysv/linux/bits/termios-struct.h | 11 +++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bits/termios.h b/bits/termios.h index 8f0b817dbf4c..798012cb8ebc 100644 --- a/bits/termios.h +++ b/bits/termios.h @@ -286,7 +286,16 @@ struct termios cc_t c_cc[NCCS]; /* Input and output baud rates. */ - speed_t __ispeed, __ospeed; + __extension__ union { + speed_t __ispeed; + speed_t c_ispeed; + }; +#define _HAVE_STRUCT_TERMIOS_C_ISPEED 1 + __extension__ union { + speed_t __ospeed; + speed_t c_ospeed; + }; +#define _HAVE_STRUCT_TERMIOS_C_OSPEED 1 }; #define _IOT_termios /* Hurd ioctl type field. */ \ diff --git a/sysdeps/unix/sysv/linux/bits/termios-struct.h b/sysdeps/unix/sysv/linux/bits/termios-struct.h index 4c501a54b058..0aba1a446e73 100644 --- a/sysdeps/unix/sysv/linux/bits/termios-struct.h +++ b/sysdeps/unix/sysv/linux/bits/termios-struct.h @@ -29,8 +29,15 @@ struct termios tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ - speed_t c_ispeed; /* input speed */ - speed_t c_ospeed; /* output speed */ + /* Input and output baud rates. */ + __extension__ union { + speed_t __ispeed; + speed_t c_ispeed; + }; #define _HAVE_STRUCT_TERMIOS_C_ISPEED 1 + __extension__ union { + speed_t __ospeed; + speed_t c_ospeed; + }; #define _HAVE_STRUCT_TERMIOS_C_OSPEED 1 }; From patchwork Tue Jun 10 19:02:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114164 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4307A3858C98 for ; Tue, 10 Jun 2025 19:12:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4307A3858C98 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=QNmHY2wr X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id 7E8253858C60 for ; Tue, 10 Jun 2025 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7E8253858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7E8253858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582193; cv=none; b=K72lhpdxnUk1wh3FxZYR+hwezRFVDHXcu9DsaubvtFBbzHJxCE5/KnjYktCg3UcrHKN8HqdF7S4dz5NbZPpMfSjiqCVxET8cC1A4KtFT22EtzjvmxxmwIGKoDRClBQiWsgGK66RR5mJ7zeK145lszQjkmhQGH5u4SqAiGQ8HLhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582193; c=relaxed/simple; bh=xcJ5bIL8O+Fo87gxggbsZwjMf2I0fDET3PUGOOVL30c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lVMKyEkA5aArlodPQq2r9KnvhOCe68tFxF32okV59rywFaB/U9oISJjTRDCsgoFgxKB10t2dD/VkULzP0ck93T36KWGEvwhDEqN1uvXkwPCLFxH1gDA9C6ixZjDDQNmsDuEuS/c6cSiqFsKLxz0wlizPTTPHvgfZvDBuURk11uA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E8253858C60 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2arr2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:03:00 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2arr2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582180; bh=cPVaAW6ffIRe2c0rxPbRPXBnoaYiqb/7RMWtStIKWek=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QNmHY2wr0w6cRcIFAnCbYgWx5go+2hLZLG3/ZXU7WIcDdUQs/ArCtMuHDLJEfdQfg RtKCDadjk71xJix+2uCbz91KNzD868hqbCf+dqqywkkf5UcvwjEl2XJ8JqXr6evLy6 rQL3gFLENZZO0Me1kzwgNkEwoJYreun07HHAC2RWVkKIzhPzUq5PWnclEnFH4mPSbd gsa2esFciMiE0vsLHQL2tYOm/vuwIWUn5/H3MbhgJd0hHWJoiMwhsbWju98lRBSVe/ fC+GwG2yWK+lsaJr2/c/1gnYPs9ZmIkg5KLWvqk2fR4sOvRocufXeN4wU6QNDb77UD 7pPsRkbwAYjtA== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 14/15] include/array_length.h: add array_foreach[_const] macros Date: Tue, 10 Jun 2025 12:02:25 -0700 Message-ID: <20250610190228.1124149-15-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Add simple-to-use iterator macros for arrays. They are used instead of explicit for statements, like: /* Test all common speeds */ array_foreach_const (ts, test_speeds) test (fd, *ts); In this case, ts will be a const pointer to each of the elements of test_speeds in turn. Named array_foreach*() to allow for other kinds of equivalent iterator macros in the future. Signed-off-by: "H. Peter Anvin" (Intel) --- include/array_length.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/array_length.h b/include/array_length.h index 2305e211b210..53e436b53387 100644 --- a/include/array_length.h +++ b/include/array_length.h @@ -33,4 +33,18 @@ VAR must evaluate to an array, not a pointer. */ #define array_end(var) (&(var)[array_length (var)]) +/* array_foreach (PTR, ARRAY) iterates over all the elements in an + array, assigning the locally defined pointer variable PTR to each + element in turn. + + array_foreach_const (PTR, ARRAY) does the same, but PTR is declared + const even if the array is not. */ +#define array_foreach(ptr, array) \ + for (__typeof ((array)[0]) *ptr = (array) ; \ + ptr < array_end(array) ; ptr++) + +#define array_foreach_const(ptr, array) \ + for (const __typeof ((array)[0]) *ptr = (array) ; \ + ptr < array_end(array) ; ptr++) + #endif /* _ARRAY_LENGTH_H */ From patchwork Tue Jun 10 19:02:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Peter Anvin" X-Patchwork-Id: 114171 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40F2B3858433 for ; Tue, 10 Jun 2025 19:22:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40F2B3858433 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=zytor.com header.i=@zytor.com header.a=rsa-sha256 header.s=2025052101 header.b=GSUZ1CLC X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3::136]) by sourceware.org (Postfix) with ESMTPS id CB16F3858019 for ; Tue, 10 Jun 2025 19:03:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB16F3858019 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zytor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB16F3858019 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:7c80:54:3::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582201; cv=none; b=KQpHqN8vtVhEXfW4VHswxUq4P94QMKrCJkwbCaauphuKUIMK//g5rWU0tphIW7yxOWVysVZwymf8owJi6q5ZBCZFsZFa5vEo1wKLu6GZeqKnzhssGgXNLypL+21enaUIi2pLeVhTiYwAywqupynYOxkVkj9TfoB8boxAGH0RsbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1749582201; c=relaxed/simple; bh=9UjlxcsTjlLqx3we0leFjrd/9Y5dEU4c/XOHjfAVQIw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Bve+a8s72NTf0M2diXjlkHwmOVtOBKdB9NsUtK7SeGCrjKIgfeVRUMtpoZC9ZTBH/Iorp0WPv9eEJU2gVbztj9udHsvEIiD6Pe9MStM+x1ZN7nUtmeOYz7F5+NyjS8BAs7qXfJqHbS4ZM/5L4+lrdCes8MBqzckV/OomXHLMDkY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB16F3858019 Received: from mail.zytor.com ([IPv6:2601:646:8081:9482:87c7:26da:5867:f3ca]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 55AJ2ars2667947 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 10 Jun 2025 12:03:01 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 55AJ2ars2667947 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025052101; t=1749582181; bh=xF1flGOvOHS6WscWiQOZFwkz1lEdiUyuzPl9j53PUbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GSUZ1CLCwuzr0hP+OdscfafSVy2xFcfKkybM3vd80l/UlreTatziy/yPxvejScHej 3pWko4jPcg88b56nFXWED2Sag5g550OGM8Z8v5LWNaM6HgajQALJIn1yTHunWDNJjI zlB3lCcl0bnTGB1BDK8Vp73MK1Q/8ddbYR+ZzreC6z09dTYMfInsf0RT/p0TCrkT3n BsN0p4Frlq47Xi3nbWZrcn/2wGposD0wpkFusMACCsc0u43IovpmuCMYnLi8I4ph5X dwXvfimPiEx3iFp2RV6MNm99pggYsHam43Dj1BNcm8rHb9Ok9lrreFUskm+TQYf7Zf PFG5L7u7z9irQ== From: "H. Peter Anvin" To: libc-alpha@sourceware.org Cc: "H. Peter Anvin" , Florian Weimer , Andreas Schwab , Samuel Thibault , "Maciej W. Rozycki" , Adhemerval Zanella Subject: [PATCH v8 15/15] linux/termios: regression test for termios speed functions Date: Tue, 10 Jun 2025 12:02:26 -0700 Message-ID: <20250610190228.1124149-16-hpa@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250610190228.1124149-1-hpa@zytor.com> References: <20250610190228.1124149-1-hpa@zytor.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: "H. Peter Anvin (Intel)" Test that runs through a fairly large combination of the various termios speed functions, for the new speed_t interface, for the old speed_t interface (if enabled), and for the new baud_t interface. Reviewed-by: Adhemerval Zanella Signed-off-by: H. Peter Anvin (Intel) --- sysdeps/unix/sysv/linux/Makefile | 1 + sysdeps/unix/sysv/linux/tst-termios-linux.c | 592 ++++++++++++++++++++ 2 files changed, 593 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/tst-termios-linux.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index a14b8c1f6181..913fe736bc18 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -236,6 +236,7 @@ tests += \ tst-sysvmsg-linux \ tst-sysvsem-linux \ tst-sysvshm-linux \ + tst-termios-linux \ tst-tgkill \ tst-timerfd \ tst-ttyname-direct \ diff --git a/sysdeps/unix/sysv/linux/tst-termios-linux.c b/sysdeps/unix/sysv/linux/tst-termios-linux.c new file mode 100644 index 000000000000..e4b0c8bcd6ed --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-termios-linux.c @@ -0,0 +1,592 @@ +/* Linux termios regression tests + + Copyright (C) 2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; see the file COPYING.LIB. If + not, see . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +/* Evaluate an expression and make sure errno did not get set; return + the value of the expression */ +#define CHECKERR(expr) \ + ({ \ + errno = 0; \ + const __typeof (expr) _val = (expr); \ + TEST_COMPARE(errno, 0); \ + _val; \ + }) + +/* Evaluate an expression and verify that is return a specific value, + as well as errno not having been set. */ +#define VERIFY(expr,val) TEST_COMPARE(CHECKERR(expr), val) +/* Check for zero and errno not set */ +#define CHECKZERO(expr) VERIFY(expr, 0) + +/* Table of legacy speed constants */ + +#define BOGUS ((speed_t)-1) +#define ANY ((speed_t)-2) + +struct cbaud_table +{ + speed_t speed; + speed_t cbaud; + const char *name; +}; + +static const struct cbaud_table cbaud_table [] = +{ + { 0, __B0, "__B0" }, + { 50, __B50, "__B50" }, + { 75, __B75, "__B75" }, + { 110, __B110, "__B110" }, + { 134, __B134, "__B134" }, + { 150, __B150, "__B150" }, + { 200, __B200, "__B200" }, + { 300, __B300, "__B300" }, + { 600, __B600, "__B600" }, + { 1200, __B1200, "__B1200" }, + { 1800, __B1800, "__B1800" }, + { 2400, __B2400, "__B2400" }, + { 4800, __B4800, "__B4800" }, +#ifdef __B7200 + { 7200, __B7200, "__B7200" }, +#endif + { 9600, __B9600, "__B9600" }, +#ifdef __B14400 + { 14400, __B14400, "__B14400" }, +#endif + { 19200, __B19200, "__B19200" }, +#ifdef __B28800 + { 28800, __B28800, "__B28800" }, +#endif + { 38400, __B38400, "__B38400" }, + { 57600, __B57600, "__B57600" }, +#ifdef __B76800 + { 76800, __B76800, "__B76800" }, +#endif + { 115200, __B115200, "__B115200" }, +#ifdef __B153600 + { 153600, __B153600, "__B153600" }, +#endif + { 230400, __B230400, "__B230400" }, +#ifdef __B307200 + { 307200, __B307200, "__B307200" }, +#endif + { 460800, __B460800, "__B460800" }, + { 500000, __B500000, "__B500000" }, + { 576000, __B576000, "__B576000" }, +#ifdef __B614400 + { 614400, __B614400, "__B614400" }, +#endif + { 921600, __B921600, "__B921600" }, + { 1000000, __B1000000, "__B1000000" }, + { 1152000, __B1152000, "__B1152000" }, + { 1500000, __B1500000, "__B1500000" }, + { 2000000, __B2000000, "__B2000000" }, +#ifdef __B2500000 + { 2500000, __B2500000, "__B2500000" }, +#endif +#ifdef __B3000000 + { 3000000, __B3000000, "__B3000000" }, +#endif +#ifdef __B3500000 + { 3500000, __B3500000, "__B3500000" }, +#endif +#ifdef __B4000000 + { 4000000, __B4000000, "__B4000000" }, +#endif + { ANY, __BOTHER, "__BOTHER" }, + { BOGUS, BOGUS, "invalid" } +}; + +/* List of common speeds to test */ + +static const speed_t test_speeds [] = +{ + 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, + 4800, 7200, 9600, 14400, 19200, 28800, 33600, 38400, 57600, + 76800, 115200, 153600, 230400, 307200, 460800, 500000, + 576000, 614400, 921600, 1000000, 1152000, 1500000, 2000000, + 2500000, 3000000, 3500000, 4000000, 5000000, 10000000 +}; + +/* Speed function tests */ + +/* These intentionally are a separate implementation from speed.c; + these should be "trivially correct" and don't need to be optimized + in any way */ + +/* Returns __BOTHER if there is no legacy value for this speed */ +static speed_t speed_to_cbaud (speed_t speed) +{ + const struct cbaud_table *ct; + for (ct = cbaud_table; ct->speed != ANY; ct++) + { + if (ct->speed == speed) + break; + } + return ct->cbaud; +} + +/* Returns ANY if cbaud is __BOTHER, or BOGUS if invalid */ +static speed_t cbaud_to_speed (speed_t cbaud) +{ + const struct cbaud_table *ct; + for (ct = cbaud_table; ct->cbaud != BOGUS; ct++) + { + if (ct->cbaud == cbaud) + break; + } + return ct->speed; +} + +static const char *cbaud_name (speed_t cbaud) +{ + const struct cbaud_table *ct; + for (ct = cbaud_table; ct->cbaud != BOGUS; ct++) + { + if (ct->cbaud == cbaud) + break; + } + return ct->name; +} + +static int check_speed (speed_t expected, speed_t speed, speed_t cbaud, + speed_t cfspeed, baud_t cfbaud, char io) +{ + speed_t want_cbaud; + cbaud &= CBAUD; + + if (expected != ANY && speed != expected) + FAIL_RET ("c_%cspeed = %u, expected %u", io, speed, expected); + + if (cfspeed != speed) + FAIL_RET ("cfget%cspeed = %u, expected %u", io, cfspeed, speed); + + if (cfbaud != cfspeed) + FAIL_RET ("cfget%cbaud = %u, but cfget%cspeed = %u", + io, cfbaud, io, cfspeed); + + want_cbaud = speed_to_cbaud (speed); + + if (cbaud != want_cbaud) + FAIL_RET ("c_%cspeed = %u: %s = %s (%06o), should be %s (%06o)", + io, speed, + io == 'o' ? "CBAUD" : "CIBAUD", cbaud_name (cbaud), cbaud, + cbaud_name (want_cbaud), want_cbaud); + + return 0; +} + +/* Validate that the speeds in the struct termios are properly normalized. + The difference is the handling of ispeed == 0. */ + +/* Use this after cfset* () */ +static void check_speeds_cf (const struct termios *tio_p, + speed_t ospeed, speed_t ispeed) +{ + check_speed (ospeed, tio_p->c_ospeed, tio_p->c_cflag, + CHECKERR (cfgetospeed (tio_p)), + CHECKERR (cfgetobaud (tio_p)), 'o'); + check_speed (ispeed, tio_p->c_ispeed, tio_p->c_cflag >> IBSHIFT, + CHECKERR (cfgetispeed (tio_p)), + CHECKERR (cfgetibaud (tio_p)), 'i'); +} + +/* Use this after tc[gs]etattr () */ +static void check_speeds_tc (int fd, speed_t ospeed, speed_t ispeed) +{ + struct termios tio; + + CHECKZERO (tcgetattr (fd, &tio)); + check_speeds_cf (&tio, ospeed, ispeed ? ispeed : ospeed); +} + +/* For search and replace convenience */ +#define check_bauds_cf check_speeds_cf +#define check_bauds_tc check_speeds_tc + +/* Common routine for setting speeds, with checking */ +static void +set_speeds (int fd, speed_t ospeed, speed_t ispeed) +{ + struct termios tio; + + CHECKZERO (tcgetattr (fd, &tio)); + CHECKZERO (cfsetospeed (&tio, ospeed)); + CHECKZERO (cfsetispeed (&tio, ispeed)); + check_speeds_cf (&tio, ospeed, ispeed); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, ospeed, ispeed ? ispeed : ospeed); +} + +/* Actual tests */ + +typedef void (*speed_test_t)(int ttyfd, speed_t speed); +static void +run_speed_test (int fd, speed_test_t test); + +/* New interface cfset*speed test */ +static void +new_cfspeed_test (int fd, speed_t speed) +{ + struct termios tio; + speed_t old_ospeed, old_ispeed; + + CHECKZERO (tcgetattr (fd, &tio)); + old_ospeed = CHECKERR (cfgetospeed (&tio)); + old_ispeed = CHECKERR (cfgetispeed (&tio)); + + /* Check initial normalization */ + check_speeds_cf (&tio, old_ospeed, old_ispeed); + + /* Check cfset*speed normalization */ + CHECKZERO (cfsetospeed (&tio, speed)); + check_speeds_cf (&tio, speed, old_ispeed); + CHECKZERO (cfsetispeed (&tio, speed)); + check_speeds_cf (&tio, speed, speed); + CHECKZERO (cfsetospeed (&tio, old_ospeed)); + check_speeds_cf (&tio, old_ospeed, speed); + CHECKZERO (cfsetispeed (&tio, B0)); + check_speeds_cf (&tio, old_ospeed, B0); + CHECKZERO (cfsetspeed (&tio, speed)); + check_speeds_cf (&tio, speed, speed); + CHECKZERO (cfsetospeed (&tio, old_ospeed)); + CHECKZERO (cfsetispeed (&tio, old_ispeed)); + check_speeds_cf (&tio, old_ospeed, old_ispeed); +} + +/* New interface cfset*speed test with tcsetattr */ +static void +new_tcspeed_test (int fd, speed_t speed) +{ + struct termios tio; + speed_t old_ospeed, old_ispeed; + + CHECKZERO (tcgetattr (fd, &tio)); + old_ospeed = CHECKERR (cfgetospeed (&tio)); + old_ispeed = CHECKERR (cfgetispeed (&tio)); + + /* Check initial normalization */ + check_speeds_cf (&tio, old_ospeed, old_ispeed); + + /* Check cfset*speed normalization */ + CHECKZERO (cfsetospeed (&tio, speed)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, speed, old_ispeed); + CHECKZERO (cfsetispeed (&tio, speed)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, speed, speed); + CHECKZERO (cfsetospeed (&tio, old_ospeed)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, old_ospeed, speed); + CHECKZERO (cfsetispeed (&tio, B0)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, old_ospeed, B0); + CHECKZERO (cfsetspeed (&tio, speed)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, speed, speed); + CHECKZERO (cfsetospeed (&tio, old_ospeed)); + CHECKZERO (cfsetispeed (&tio, old_ispeed)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_speeds_tc (fd, old_ospeed, old_ispeed); +} + +/* New interface cfset*baud test */ +static void +new_cfbaud_test (int fd, baud_t baud) +{ + struct termios tio; + baud_t old_obaud, old_ibaud; + + CHECKZERO (tcgetattr (fd, &tio)); + old_obaud = CHECKERR (cfgetobaud (&tio)); + old_ibaud = CHECKERR (cfgetibaud (&tio)); + + /* Check initial normalization */ + check_bauds_cf (&tio, old_obaud, old_ibaud); + + /* Check cfset*baud normalization */ + CHECKZERO (cfsetobaud (&tio, baud)); + check_bauds_cf (&tio, baud, old_ibaud); + CHECKZERO (cfsetibaud (&tio, baud)); + check_bauds_cf (&tio, baud, baud); + CHECKZERO (cfsetobaud (&tio, old_obaud)); + check_bauds_cf (&tio, old_obaud, baud); + CHECKZERO (cfsetibaud (&tio, B0)); + check_bauds_cf (&tio, old_obaud, B0); + CHECKZERO (cfsetbaud (&tio, baud)); + check_bauds_cf (&tio, baud, baud); + CHECKZERO (cfsetobaud (&tio, old_obaud)); + CHECKZERO (cfsetibaud (&tio, old_ibaud)); + check_bauds_cf (&tio, old_obaud, old_ibaud); +} + +/* New interface cfset*baud test with tcsetattr */ +static void +new_tcbaud_test (int fd, baud_t baud) +{ + struct termios tio; + baud_t old_obaud, old_ibaud; + + CHECKZERO (tcgetattr (fd, &tio)); + old_obaud = CHECKERR (cfgetobaud (&tio)); + old_ibaud = CHECKERR (cfgetibaud (&tio)); + + /* Check initial normalization */ + check_bauds_cf (&tio, old_obaud, old_ibaud); + + /* Check cfset*baud normalization */ + CHECKZERO (cfsetobaud (&tio, baud)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_bauds_tc (fd, baud, old_ibaud); + CHECKZERO (cfsetibaud (&tio, baud)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_bauds_tc (fd, baud, baud); + CHECKZERO (cfsetobaud (&tio, old_obaud)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_bauds_tc (fd, old_obaud, baud); + CHECKZERO (cfsetibaud (&tio, B0)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_bauds_tc (fd, old_obaud, B0); + CHECKZERO (cfsetbaud (&tio, baud)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_bauds_tc (fd, baud, baud); + CHECKZERO (cfsetobaud (&tio, old_obaud)); + CHECKZERO (cfsetibaud (&tio, old_ibaud)); + CHECKZERO (tcsetattr (fd, TCSANOW, &tio)); + check_bauds_tc (fd, old_obaud, old_ibaud); +} + +/* + * Old interface tests. This depends critically on the new struct + * termios being guaranteed to be a superset of the legacy struct + * termios. + */ +#if TEST_COMPAT (libc, GLIBC_2_0, GLIBC_2_42) +extern int __old_cfsetospeed (struct termios *tio_p, speed_t speed); +compat_symbol_reference (libc, __old_cfsetospeed, cfsetospeed, GLIBC_2_0); +extern int __old_cfsetispeed (struct termios *tio_p, speed_t speed); +compat_symbol_reference (libc, __old_cfsetispeed, cfsetispeed, GLIBC_2_0); +extern speed_t __old_cfgetospeed (const struct termios *tio_p); +compat_symbol_reference (libc, __old_cfgetospeed, cfgetospeed, GLIBC_2_0); +extern speed_t __old_cfgetispeed (const struct termios *tio_p); +compat_symbol_reference (libc, __old_cfgetispeed, cfgetispeed, GLIBC_2_0); +extern int __old_tcsetattr (int fd, int act, const struct termios *tio_p); +compat_symbol_reference (libc, __old_tcsetattr, tcsetattr, GLIBC_2_0); +extern int __old_tcgetattr (int fd, struct termios *tio_p); +compat_symbol_reference (libc, __old_tcgetattr, tcgetattr, GLIBC_2_0); + +static int old_tcsetattr (int fd, const struct termios *tio_p) +{ + struct termios old_tio = *tio_p; + + /* Deliberately corrupt c_ispeed and c_ospeed */ + old_tio.c_ispeed = 0xdeadbeef; + old_tio.c_ospeed = 0xfeedface; + return __old_tcsetattr (fd, TCSANOW, &old_tio); +} +static int old_tcgetattr (int fd, struct termios *tio_p) +{ + int rv; + memset (tio_p, 0xde, sizeof *tio_p); + rv = __old_tcgetattr (fd, tio_p); + if (rv) + return rv; + + /* Deliberately corrupt c_ispeed and c_ospeed */ + tio_p->c_ispeed = 0xdeadbeef; + tio_p->c_ospeed = 0xfeedface; + return 0; +} + +/* Old interface test. This relies on the new struct termios always + being a binary superset of the old one. + This doesn't bother testing split speed, since that never worked + on the old glibc. */ +static void +old_tcspeed_test (int fd, speed_t speed) +{ + struct termios tio; + speed_t cbaud; + + if (!speed) + return; /* Skip B0 for this test */ + + cbaud = speed_to_cbaud (speed); + if (cbaud == __BOTHER) + return; + + CHECKZERO (old_tcgetattr (fd, &tio)); + CHECKZERO (__old_cfsetospeed (&tio, cbaud)); + VERIFY (__old_cfgetospeed (&tio), cbaud); + CHECKZERO (__old_cfsetispeed (&tio, cbaud)); + VERIFY (__old_cfgetispeed (&tio), cbaud); + CHECKZERO (old_tcsetattr (fd, &tio)); + check_speeds_tc (fd, speed, speed); +} + +/* Verify that invalid CBAUD values return error for the old interfaces */ +static void +old_invalid_speeds_test (int fd) +{ + struct termios tio; + speed_t cbaud; + + for (cbaud = 0 ; cbaud ; cbaud > 0xffff ? (cbaud <<= 1) : cbaud++) { + speed_t realspeed; + realspeed = (cbaud & ~CBAUD) ? BOGUS : cbaud_to_speed (cbaud); + if (realspeed >= ANY) + { + int rv; + + errno = 0; + rv = __old_cfsetospeed (&tio, cbaud); + if (rv != -1 || errno != EINVAL) + FAIL("__old_cfsetospeed() accepted invalid value %06o", cbaud); + + errno = 0; + rv = __old_cfsetispeed (&tio, cbaud); + if (rv != -1 || errno != EINVAL) + FAIL("__old_cfsetispeed() accepted invalid value %06o", cbaud); + } + else + { + CHECKZERO (__old_cfsetospeed (&tio, cbaud)); + VERIFY (__old_cfgetospeed (&tio), cbaud); + CHECKZERO (__old_cfsetispeed (&tio, cbaud)); + VERIFY (__old_cfgetispeed (&tio), cbaud); + if (cbaud) + { + CHECKZERO (old_tcsetattr (fd, &tio)); + check_speeds_tc (fd, realspeed, realspeed); + } + } + } +} + +static void +compat_tests (int fd) +{ + run_speed_test (fd, old_tcspeed_test); + old_invalid_speeds_test (fd); +} +#else /* No TEST_COMPAT */ +#define compat_tests(fd) ((void)(fd)) +#endif + +static void +run_speed_test (int fd, speed_test_t test) +{ + unsigned short seed [3] = { 0x1234, 0x5678, 0x9abc }; + struct speeds { + speed_t ospeed, ispeed; + }; + static const struct speeds initial_speeds [] = { + { 2400, 2400 }, /* Standard speed, non-split */ + { 123456, 123456 }, /* Nonstandard speed, non-split */ + { 75, 1200 }, /* Standard split speeds */ + { 9600, 456789 }, /* One standard, one nonstandard */ + { 54321, 1234567890 } /* Nonstandard, one very high */ + }; + + array_foreach_const (is, initial_speeds) + { + /* Set up initial conditions */ + set_speeds (fd, is->ospeed, is->ispeed); + + /* Test all common speeds */ + array_foreach_const (ts, test_speeds) + test (fd, *ts); + + /* Test pseudorandom speeds; array_length(test_speeds) + here is an arbitrary value */ + const size_t random_test_count = array_length(test_speeds); + for (size_t i = 0 ; i < random_test_count ; i++) + test (fd, (speed_t) jrand48 (seed)); + + /* Test power-of-2 speeds */ + for (speed_t s = 1 ; s ; s <<= 1) + test (fd, s); + + /* Test power of 2 multiples of 75; 75 << 25 is the maximum below 2^32 */ + for (int i = 0 ; i < 26 ; i++) + test (fd, (speed_t)75 << i); + } +} + +static void +run_speed_tests (int fd) +{ + /* Test proper canonicalization using the new interface */ + run_speed_test (fd, new_cfspeed_test); + run_speed_test (fd, new_tcspeed_test); + + /* Try the new cfset*baud() functions */ + run_speed_test (fd, new_cfbaud_test); + run_speed_test (fd, new_tcbaud_test); + + /* Tests of the legacy functions */ + compat_tests (fd); +} + +/* test dispatch */ + +static void +run_in_chroot (void) +{ + /* Create a pty slave to use as a tty. Most of the termios settings, + including the speeds, have no impact on a pty, but they are still + settable like for any other tty, which makes them very convenient + for testing. */ + int ptmfd, ttyfd; + + support_openpty (&ptmfd, &ttyfd, NULL, NULL, NULL); + run_speed_tests (ttyfd); + close (ttyfd); + close (ptmfd); +} + +static int +do_test (void) +{ + support_become_root (); + run_in_chroot (); + + return 0; +} + +#include