[PATCH] x32: Switch back to assembly syscall wrapper for prctl

"H.J. Lu" <[email protected]> Sun, 7 Dec 2025 11:52:08 +0800
Newsgroups org.kernel.vger.util-linux
Message-ID <CAMe9rOpqX9cdhvMneHnfvJFG8ixJsdAyd6iK8mh_Th1Lpv4ahQ@mail.gmail.com>
On Thu, Dec 4, 2025 at 10:06 PM Adhemerval Zanella Netto
<[email protected]> wrote:
>
> The x32 and or1k (which also uses similar implementation) does seems broken
> without checking the 'option' argument to see which arg we can va_arg.
>
> The problem is adding this logic on libc will add some forward-compatibility
> that we try to avoid (newer kernel prctl additions might now work correctly).
>
> I am not sure why we haven't switch x32 back to the assembly wrappers
> with 6a04404521ac4119ae36827eeb288ea84eee7cf6 fix (BZ#29770).  H.J, can
> use remove the x32 C version (and also or1k as well)?

Since the variadic prctl function takes at most 5 integer arguments which
are passed in the same integer registers on x32 as the function with 5
integer arguments, we can safely use assembly syscall wrapper for prctl
for x32.

Tested on x32.  I leave or1k alone since I don't know if it is safe to
do the same.

-- 
H.J.
0001-x32-Switch-back-to-assembly-syscall-wrapper-for-prct.patch (text/x-patch, 2.5 KB)
From e6a14154e90e1e6ba2372340b62dae13667bc8ba Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Sun, 7 Dec 2025 11:33:33 +0800
Subject: [PATCH] x32: Switch back to assembly syscall wrapper for prctl

Since the variadic prctl function takes at most 5 integer arguments which
are passed in the same integer registers on x32 as the function with 5
integer arguments, we can safely use assembly syscall wrapper for prctl
for x32.

Signed-off-by: H.J. Lu <[email protected]>
---
 sysdeps/unix/sysv/linux/x86_64/x32/prctl.c | 42 ----------------------
 1 file changed, 42 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/prctl.c

diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/prctl.c b/sysdeps/unix/sysv/linux/x86_64/x32/prctl.c
deleted file mode 100644
index 714fd28837..0000000000
--- a/sysdeps/unix/sysv/linux/x86_64/x32/prctl.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/* prctl - Linux specific syscall.  x86-64 x32 version.
-   Copyright (C) 2020-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
-   <https://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-#include <stdarg.h>
-#include <sys/prctl.h>
-
-/* Unconditionally read all potential arguments.  This may pass
-   garbage values to the kernel, but avoids the need for teaching
-   glibc the argument counts of individual options (including ones
-   that are added to the kernel in the future).  */
-
-int
-__prctl (int option, ...)
-{
-  va_list arg;
-  va_start (arg, option);
-  unsigned long int arg2 = va_arg (arg, unsigned long int);
-  unsigned long int arg3 = va_arg (arg, unsigned long int);
-  unsigned long int arg4 = va_arg (arg, unsigned long int);
-  unsigned long int arg5 = va_arg (arg, unsigned long int);
-  va_end (arg);
-  return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
-}
-
-libc_hidden_def (__prctl)
-weak_alias (__prctl, prctl)
-- 
2.52.0