public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add a C wrapper for prctl [BZ #25896]
@ 2020-04-29 20:52 H.J. Lu
  2020-04-30  7:26 ` Florian Weimer
  0 siblings, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-04-29 20:52 UTC (permalink / raw)
  To: libc-alpha

Add a C wrapper to pass arguments in

/* Control process execution.  */
extern int prctl (int __option, ...) __THROW;

to prctl syscall:

extern int prctl (int, unsigned long int, unsigned long int,
		  unsigned long int, unsigned long int);
---
 include/sys/prctl.h                   |  2 ++
 sysdeps/unix/sysv/linux/Makefile      |  2 +-
 sysdeps/unix/sysv/linux/prctl.c       | 38 +++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/syscalls.list |  1 -
 4 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/prctl.c

diff --git a/include/sys/prctl.h b/include/sys/prctl.h
index 0920ed642b..1a74d83879 100644
--- a/include/sys/prctl.h
+++ b/include/sys/prctl.h
@@ -4,6 +4,8 @@
 # ifndef _ISOMAC
 
 extern int __prctl (int __option, ...);
+libc_hidden_proto (__prctl)
+libc_hidden_proto (prctl)
 
 # endif /* !_ISOMAC */
 #endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index db78eeadd1..0326f92c40 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality epoll_wait tee vmsplice splice \
 		   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
-		   timerfd_gettime timerfd_settime \
+		   timerfd_gettime timerfd_settime prctl \
 		   process_vm_readv process_vm_writev
 
 CFLAGS-gethostid.c = -fexceptions
diff --git a/sysdeps/unix/sysv/linux/prctl.c b/sysdeps/unix/sysv/linux/prctl.c
new file mode 100644
index 0000000000..b3fc12ccf5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/prctl.c
@@ -0,0 +1,38 @@
+/* prctl - Linux specific syscall.
+   Copyright (C) 2020 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>
+
+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)
+hidden_weak (prctl)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index ced77d49fa..1d8893d1b8 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -43,7 +43,6 @@ nfsservctl	EXTRA	nfsservctl	i:ipp	__compat_nfsservctl	nfsservctl@GLIBC_2.0:GLIBC
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2
 pivot_root	EXTRA	pivot_root	i:ss	pivot_root
-prctl		EXTRA	prctl		i:iiiii	__prctl		prctl
 query_module	EXTRA	query_module	i:sipip	__compat_query_module	query_module@GLIBC_2.0:GLIBC_2.23
 quotactl	EXTRA	quotactl	i:isip	quotactl
 remap_file_pages -	remap_file_pages i:pUiUi	__remap_file_pages remap_file_pages
-- 
2.25.4


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-29 20:52 [PATCH] Add a C wrapper for prctl [BZ #25896] H.J. Lu
@ 2020-04-30  7:26 ` Florian Weimer
  2020-04-30 13:03   ` V2 " H.J. Lu
  0 siblings, 1 reply; 30+ messages in thread
From: Florian Weimer @ 2020-04-30  7:26 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha

* H. J. Lu via Libc-alpha:

> Add a C wrapper to pass arguments in
>
> /* Control process execution.  */
> extern int prctl (int __option, ...) __THROW;
>
> to prctl syscall:
>
> extern int prctl (int, unsigned long int, unsigned long int,
> 		  unsigned long int, unsigned long int);
> ---
>  include/sys/prctl.h                   |  2 ++
>  sysdeps/unix/sysv/linux/Makefile      |  2 +-
>  sysdeps/unix/sysv/linux/prctl.c       | 38 +++++++++++++++++++++++++++
>  sysdeps/unix/sysv/linux/syscalls.list |  1 -
>  4 files changed, 41 insertions(+), 2 deletions(-)
>  create mode 100644 sysdeps/unix/sysv/linux/prctl.c
>
> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
> index 0920ed642b..1a74d83879 100644
> --- a/include/sys/prctl.h
> +++ b/include/sys/prctl.h
> @@ -4,6 +4,8 @@
>  # ifndef _ISOMAC
>  
>  extern int __prctl (int __option, ...);
> +libc_hidden_proto (__prctl)
> +libc_hidden_proto (prctl)

I see we have some internal callers of prctl.  I will clean this up
later.

> diff --git a/sysdeps/unix/sysv/linux/prctl.c b/sysdeps/unix/sysv/linux/prctl.c
> new file mode 100644
> index 0000000000..b3fc12ccf5
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/prctl.c
> @@ -0,0 +1,38 @@
> +/* prctl - Linux specific syscall.
> +   Copyright (C) 2020 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>
> +
> +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);
> +}

Please add a comment that this over-reads arguments for some option
values, something like:

/* 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).  */

Rest looks fine.  Generated code is quite a bit worse, but I don't
think this matter here.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30  7:26 ` Florian Weimer
@ 2020-04-30 13:03   ` H.J. Lu
  2020-04-30 13:41     ` Andreas Schwab
  2020-04-30 14:51     ` Adhemerval Zanella
  0 siblings, 2 replies; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 13:03 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu via Libc-alpha

On Thu, Apr 30, 2020 at 09:26:18AM +0200, Florian Weimer wrote:
> * H. J. Lu via Libc-alpha:
> 
> > Add a C wrapper to pass arguments in
> >
> > /* Control process execution.  */
> > extern int prctl (int __option, ...) __THROW;
> >
> > to prctl syscall:
> >
> > extern int prctl (int, unsigned long int, unsigned long int,
> > 		  unsigned long int, unsigned long int);
> > ---
> >  include/sys/prctl.h                   |  2 ++
> >  sysdeps/unix/sysv/linux/Makefile      |  2 +-
> >  sysdeps/unix/sysv/linux/prctl.c       | 38 +++++++++++++++++++++++++++
> >  sysdeps/unix/sysv/linux/syscalls.list |  1 -
> >  4 files changed, 41 insertions(+), 2 deletions(-)
> >  create mode 100644 sysdeps/unix/sysv/linux/prctl.c
> >
> > diff --git a/include/sys/prctl.h b/include/sys/prctl.h
> > index 0920ed642b..1a74d83879 100644
> > --- a/include/sys/prctl.h
> > +++ b/include/sys/prctl.h
> > @@ -4,6 +4,8 @@
> >  # ifndef _ISOMAC
> >  
> >  extern int __prctl (int __option, ...);
> > +libc_hidden_proto (__prctl)
> > +libc_hidden_proto (prctl)
> 
> I see we have some internal callers of prctl.  I will clean this up
> later.
> 
> 
> Please add a comment that this over-reads arguments for some option
> values, something like:
> 
> /* 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).  */
> 
> Rest looks fine.  Generated code is quite a bit worse, but I don't
> think this matter here.

Here is the updated patch.  I added the assembly version for x86.  Other
arches can do

#include <sysdeps/unix/sysv/linux/x86/prctl.S>

if they are similar.

OK for master?

Thanks.

H.J.
---
Add a C wrapper to pass arguments in

/* Control process execution.  */
extern int prctl (int __option, ...) __THROW;

to prctl syscall:

extern int prctl (int, unsigned long int, unsigned long int,
		  unsigned long int, unsigned long int);

On Linux/x86, since the prctl syscall interface:

extern int prctl (int, unsigned long int, unsigned long int,
		  unsigned long int, unsigned long int);

and the glibc prctl interface:

extern int prctl (int option, ...);

pass the arguments identically, the assembly verion:

PSEUDO (__prctl, prctl, 5)
	ret
PSEUDO_END (__prctl)

is used.
---
 include/sys/prctl.h                        |  2 +
 sysdeps/unix/sysv/linux/Makefile           |  2 +-
 sysdeps/unix/sysv/linux/prctl.c            | 43 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/syscalls.list      |  1 -
 sysdeps/unix/sysv/linux/x86/prctl.S        | 38 +++++++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/x32/prctl.S | 28 ++++++++++++++
 6 files changed, 112 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/prctl.c
 create mode 100644 sysdeps/unix/sysv/linux/x86/prctl.S
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/prctl.S

diff --git a/include/sys/prctl.h b/include/sys/prctl.h
index 0920ed642b..1a74d83879 100644
--- a/include/sys/prctl.h
+++ b/include/sys/prctl.h
@@ -4,6 +4,8 @@
 # ifndef _ISOMAC
 
 extern int __prctl (int __option, ...);
+libc_hidden_proto (__prctl)
+libc_hidden_proto (prctl)
 
 # endif /* !_ISOMAC */
 #endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index db78eeadd1..0326f92c40 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality epoll_wait tee vmsplice splice \
 		   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
-		   timerfd_gettime timerfd_settime \
+		   timerfd_gettime timerfd_settime prctl \
 		   process_vm_readv process_vm_writev
 
 CFLAGS-gethostid.c = -fexceptions
diff --git a/sysdeps/unix/sysv/linux/prctl.c b/sysdeps/unix/sysv/linux/prctl.c
new file mode 100644
index 0000000000..49049fd85f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/prctl.c
@@ -0,0 +1,43 @@
+/* prctl - Linux specific syscall.
+   Copyright (C) 2020 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)
+hidden_weak (prctl)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index ced77d49fa..1d8893d1b8 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -43,7 +43,6 @@ nfsservctl	EXTRA	nfsservctl	i:ipp	__compat_nfsservctl	nfsservctl@GLIBC_2.0:GLIBC
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2
 pivot_root	EXTRA	pivot_root	i:ss	pivot_root
-prctl		EXTRA	prctl		i:iiiii	__prctl		prctl
 query_module	EXTRA	query_module	i:sipip	__compat_query_module	query_module@GLIBC_2.0:GLIBC_2.23
 quotactl	EXTRA	quotactl	i:isip	quotactl
 remap_file_pages -	remap_file_pages i:pUiUi	__remap_file_pages remap_file_pages
diff --git a/sysdeps/unix/sysv/linux/x86/prctl.S b/sysdeps/unix/sysv/linux/x86/prctl.S
new file mode 100644
index 0000000000..99bb62ad39
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86/prctl.S
@@ -0,0 +1,38 @@
+/* prctl - Linux specific syscall.  Linux/x86 version.
+   Copyright (C) 2020 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>
+
+/* On Linux/x86, the prctl syscall interface:
+
+   extern int prctl (int, unsigned long int, unsigned long int,
+		     unsigned long int, unsigned long int);
+
+   and the glibc prctl interface:
+
+   extern int prctl (int option, ...);
+
+   pass the arguments identically.  */
+
+PSEUDO (__prctl, prctl, 5)
+	ret
+PSEUDO_END (__prctl)
+
+hidden_def (__prctl)
+weak_alias (__prctl, prctl)
+hidden_weak (prctl)
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/prctl.S b/sysdeps/unix/sysv/linux/x86_64/x32/prctl.S
new file mode 100644
index 0000000000..5acf5406a8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/prctl.S
@@ -0,0 +1,28 @@
+/* prctl - Linux specific syscall.  Linux/x32 version.
+   Copyright (C) 2020 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>
+
+/* On Linux/x32, we need to zero-extend from 32 bits to 64 bits for the
+   last 4 arguments.  */
+
+#undef DOARGS_5
+#define DOARGS_5 \
+  movl %esi, %esi; movl %edx, %edx; movl %ecx, %r10d; movl %r8d, %r8d;
+
+#include <sysdeps/unix/sysv/linux/x86/prctl.S>
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:03   ` V2 " H.J. Lu
@ 2020-04-30 13:41     ` Andreas Schwab
  2020-04-30 13:43       ` Florian Weimer
  2020-04-30 14:51     ` Adhemerval Zanella
  1 sibling, 1 reply; 30+ messages in thread
From: Andreas Schwab @ 2020-04-30 13:41 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha; +Cc: Florian Weimer, H.J. Lu

On Apr 30 2020, H.J. Lu via Libc-alpha wrote:

> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
> index 0920ed642b..1a74d83879 100644
> --- a/include/sys/prctl.h
> +++ b/include/sys/prctl.h
> @@ -4,6 +4,8 @@
>  # ifndef _ISOMAC
>  
>  extern int __prctl (int __option, ...);
> +libc_hidden_proto (__prctl)
> +libc_hidden_proto (prctl)

Why do you need the hidden alias for prctl?  All references inside
libc.so should use __prctl.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:41     ` Andreas Schwab
@ 2020-04-30 13:43       ` Florian Weimer
  2020-04-30 13:50         ` H.J. Lu
  2020-04-30 13:51         ` Andreas Schwab
  0 siblings, 2 replies; 30+ messages in thread
From: Florian Weimer @ 2020-04-30 13:43 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: H.J. Lu via Libc-alpha, H.J. Lu

* Andreas Schwab:

> On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
>
>> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
>> index 0920ed642b..1a74d83879 100644
>> --- a/include/sys/prctl.h
>> +++ b/include/sys/prctl.h
>> @@ -4,6 +4,8 @@
>>  # ifndef _ISOMAC
>>  
>>  extern int __prctl (int __option, ...);
>> +libc_hidden_proto (__prctl)
>> +libc_hidden_proto (prctl)
>
> Why do you need the hidden alias for prctl?  All references inside
> libc.so should use __prctl.

Right.  I want to clean this up in a separate patch.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:43       ` Florian Weimer
@ 2020-04-30 13:50         ` H.J. Lu
  2020-04-30 13:51         ` Andreas Schwab
  1 sibling, 0 replies; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 13:50 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Andreas Schwab, H.J. Lu via Libc-alpha

On Thu, Apr 30, 2020 at 6:43 AM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * Andreas Schwab:
>
> > On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
> >
> >> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
> >> index 0920ed642b..1a74d83879 100644
> >> --- a/include/sys/prctl.h
> >> +++ b/include/sys/prctl.h
> >> @@ -4,6 +4,8 @@
> >>  # ifndef _ISOMAC
> >>
> >>  extern int __prctl (int __option, ...);
> >> +libc_hidden_proto (__prctl)
> >> +libc_hidden_proto (prctl)
> >
> > Why do you need the hidden alias for prctl?  All references inside
> > libc.so should use __prctl.
>
> Right.  I want to clean this up in a separate patch.

I will wait for your cleanup patch and remove the hidden alias for prctl.

-- 
H.J.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:43       ` Florian Weimer
  2020-04-30 13:50         ` H.J. Lu
@ 2020-04-30 13:51         ` Andreas Schwab
  2020-04-30 13:53           ` H.J. Lu
  2020-04-30 13:54           ` V2 " Florian Weimer
  1 sibling, 2 replies; 30+ messages in thread
From: Andreas Schwab @ 2020-04-30 13:51 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu via Libc-alpha, H.J. Lu

On Apr 30 2020, Florian Weimer wrote:

> * Andreas Schwab:
>
>> On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
>>
>>> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
>>> index 0920ed642b..1a74d83879 100644
>>> --- a/include/sys/prctl.h
>>> +++ b/include/sys/prctl.h
>>> @@ -4,6 +4,8 @@
>>>  # ifndef _ISOMAC
>>>  
>>>  extern int __prctl (int __option, ...);
>>> +libc_hidden_proto (__prctl)
>>> +libc_hidden_proto (prctl)
>>
>> Why do you need the hidden alias for prctl?  All references inside
>> libc.so should use __prctl.
>
> Right.  I want to clean this up in a separate patch.

??? Why adding it in the first place?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:51         ` Andreas Schwab
@ 2020-04-30 13:53           ` H.J. Lu
  2020-04-30 14:04             ` Andreas Schwab
  2020-04-30 13:54           ` V2 " Florian Weimer
  1 sibling, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 13:53 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer, H.J. Lu via Libc-alpha

On Thu, Apr 30, 2020 at 6:51 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Apr 30 2020, Florian Weimer wrote:
>
> > * Andreas Schwab:
> >
> >> On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
> >>
> >>> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
> >>> index 0920ed642b..1a74d83879 100644
> >>> --- a/include/sys/prctl.h
> >>> +++ b/include/sys/prctl.h
> >>> @@ -4,6 +4,8 @@
> >>>  # ifndef _ISOMAC
> >>>
> >>>  extern int __prctl (int __option, ...);
> >>> +libc_hidden_proto (__prctl)
> >>> +libc_hidden_proto (prctl)
> >>
> >> Why do you need the hidden alias for prctl?  All references inside
> >> libc.so should use __prctl.
> >
> > Right.  I want to clean this up in a separate patch.
>
> ??? Why adding it in the first place?
>
> Andreas.
>

It was there before my patch:

0000000000000000 T __GI___prctl
0000000000000000 T __GI_prctl
                 U _GLOBAL_OFFSET_TABLE_
                 U __libc_errno
0000000000000000 T __prctl
0000000000000000 W prctl

-- 
H.J.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:51         ` Andreas Schwab
  2020-04-30 13:53           ` H.J. Lu
@ 2020-04-30 13:54           ` Florian Weimer
  1 sibling, 0 replies; 30+ messages in thread
From: Florian Weimer @ 2020-04-30 13:54 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: H.J. Lu via Libc-alpha, H.J. Lu

* Andreas Schwab:

> On Apr 30 2020, Florian Weimer wrote:
>
>> * Andreas Schwab:
>>
>>> On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
>>>
>>>> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
>>>> index 0920ed642b..1a74d83879 100644
>>>> --- a/include/sys/prctl.h
>>>> +++ b/include/sys/prctl.h
>>>> @@ -4,6 +4,8 @@
>>>>  # ifndef _ISOMAC
>>>>  
>>>>  extern int __prctl (int __option, ...);
>>>> +libc_hidden_proto (__prctl)
>>>> +libc_hidden_proto (prctl)
>>>
>>> Why do you need the hidden alias for prctl?  All references inside
>>> libc.so should use __prctl.
>>
>> Right.  I want to clean this up in a separate patch.
>
> ??? Why adding it in the first place?

I thought pthread_getname was linked into libc, but looks like it's in
libpthread, so its use of prctl (not __prctl) should be fine.

H.J., what happens if you drop the hidden alias for prctl?

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:53           ` H.J. Lu
@ 2020-04-30 14:04             ` Andreas Schwab
  2020-04-30 15:27               ` V3 " H.J. Lu
  0 siblings, 1 reply; 30+ messages in thread
From: Andreas Schwab @ 2020-04-30 14:04 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Florian Weimer, H.J. Lu via Libc-alpha

On Apr 30 2020, H.J. Lu wrote:

> On Thu, Apr 30, 2020 at 6:51 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>> On Apr 30 2020, Florian Weimer wrote:
>>
>> > * Andreas Schwab:
>> >
>> >> On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
>> >>
>> >>> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
>> >>> index 0920ed642b..1a74d83879 100644
>> >>> --- a/include/sys/prctl.h
>> >>> +++ b/include/sys/prctl.h
>> >>> @@ -4,6 +4,8 @@
>> >>>  # ifndef _ISOMAC
>> >>>
>> >>>  extern int __prctl (int __option, ...);
>> >>> +libc_hidden_proto (__prctl)
>> >>> +libc_hidden_proto (prctl)
>> >>
>> >> Why do you need the hidden alias for prctl?  All references inside
>> >> libc.so should use __prctl.
>> >
>> > Right.  I want to clean this up in a separate patch.
>>
>> ??? Why adding it in the first place?
>>
>> Andreas.
>>
>
> It was there before my patch:

That doesn't matter, the syscall template adds it blindly to all names.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 13:03   ` V2 " H.J. Lu
  2020-04-30 13:41     ` Andreas Schwab
@ 2020-04-30 14:51     ` Adhemerval Zanella
  2020-04-30 16:35       ` H.J. Lu
  1 sibling, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2020-04-30 14:51 UTC (permalink / raw)
  To: libc-alpha



On 30/04/2020 10:03, H.J. Lu via Libc-alpha wrote:

> Here is the updated patch.  I added the assembly version for x86.  Other
> arches can do
> 
> #include <sysdeps/unix/sysv/linux/x86/prctl.S>

Do we really an assembly optimization for this? I hardly think this
a hotstop symbol.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 14:04             ` Andreas Schwab
@ 2020-04-30 15:27               ` H.J. Lu
  2020-04-30 16:53                 ` Florian Weimer
                                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 15:27 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Florian Weimer, H.J. Lu via Libc-alpha

[-- Attachment #1: Type: text/plain, Size: 1192 bytes --]

On Thu, Apr 30, 2020 at 7:04 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Apr 30 2020, H.J. Lu wrote:
>
> > On Thu, Apr 30, 2020 at 6:51 AM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >>
> >> On Apr 30 2020, Florian Weimer wrote:
> >>
> >> > * Andreas Schwab:
> >> >
> >> >> On Apr 30 2020, H.J. Lu via Libc-alpha wrote:
> >> >>
> >> >>> diff --git a/include/sys/prctl.h b/include/sys/prctl.h
> >> >>> index 0920ed642b..1a74d83879 100644
> >> >>> --- a/include/sys/prctl.h
> >> >>> +++ b/include/sys/prctl.h
> >> >>> @@ -4,6 +4,8 @@
> >> >>>  # ifndef _ISOMAC
> >> >>>
> >> >>>  extern int __prctl (int __option, ...);
> >> >>> +libc_hidden_proto (__prctl)
> >> >>> +libc_hidden_proto (prctl)
> >> >>
> >> >> Why do you need the hidden alias for prctl?  All references inside
> >> >> libc.so should use __prctl.
> >> >
> >> > Right.  I want to clean this up in a separate patch.
> >>
> >> ??? Why adding it in the first place?
> >>
> >> Andreas.
> >>
> >
> > It was there before my patch:
>
> That doesn't matter, the syscall template adds it blindly to all names.
>
> Andreas.
>

Here is the updated patch without

libc_hidden_proto (prctl)

OK for master?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-Add-a-C-wrapper-for-prctl-BZ-25896.patch --]
[-- Type: text/x-patch, Size: 7659 bytes --]

From ee8672af3ef5f3db438c0abb39b2673944181292 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 29 Apr 2020 07:38:49 -0700
Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]

Add a C wrapper to pass arguments in

/* Control process execution.  */
extern int prctl (int __option, ...) __THROW;

to prctl syscall:

extern int prctl (int, unsigned long int, unsigned long int,
		  unsigned long int, unsigned long int);

On Linux/x86, since the prctl syscall interface:

extern int prctl (int, unsigned long int, unsigned long int,
		  unsigned long int, unsigned long int);

and the glibc prctl interface:

extern int prctl (int option, ...);

pass the arguments identically, the assembly verion:

PSEUDO (__prctl, prctl, 5)
	ret
PSEUDO_END (__prctl)

is used.
---
 include/sys/prctl.h                        |  1 +
 sysdeps/unix/sysv/linux/Makefile           |  2 +-
 sysdeps/unix/sysv/linux/prctl.c            | 42 ++++++++++++++++++++++
 sysdeps/unix/sysv/linux/syscalls.list      |  1 -
 sysdeps/unix/sysv/linux/x86/prctl.S        | 37 +++++++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/x32/prctl.S | 28 +++++++++++++++
 6 files changed, 109 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/prctl.c
 create mode 100644 sysdeps/unix/sysv/linux/x86/prctl.S
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/x32/prctl.S

diff --git a/include/sys/prctl.h b/include/sys/prctl.h
index 0920ed642b..d33f3a290e 100644
--- a/include/sys/prctl.h
+++ b/include/sys/prctl.h
@@ -4,6 +4,7 @@
 # ifndef _ISOMAC
 
 extern int __prctl (int __option, ...);
+libc_hidden_proto (__prctl)
 
 # endif /* !_ISOMAC */
 #endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index db78eeadd1..0326f92c40 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality epoll_wait tee vmsplice splice \
 		   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
-		   timerfd_gettime timerfd_settime \
+		   timerfd_gettime timerfd_settime prctl \
 		   process_vm_readv process_vm_writev
 
 CFLAGS-gethostid.c = -fexceptions
diff --git a/sysdeps/unix/sysv/linux/prctl.c b/sysdeps/unix/sysv/linux/prctl.c
new file mode 100644
index 0000000000..d5725f14cf
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/prctl.c
@@ -0,0 +1,42 @@
+/* prctl - Linux specific syscall.
+   Copyright (C) 2020 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)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index ced77d49fa..1d8893d1b8 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -43,7 +43,6 @@ nfsservctl	EXTRA	nfsservctl	i:ipp	__compat_nfsservctl	nfsservctl@GLIBC_2.0:GLIBC
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2
 pivot_root	EXTRA	pivot_root	i:ss	pivot_root
-prctl		EXTRA	prctl		i:iiiii	__prctl		prctl
 query_module	EXTRA	query_module	i:sipip	__compat_query_module	query_module@GLIBC_2.0:GLIBC_2.23
 quotactl	EXTRA	quotactl	i:isip	quotactl
 remap_file_pages -	remap_file_pages i:pUiUi	__remap_file_pages remap_file_pages
diff --git a/sysdeps/unix/sysv/linux/x86/prctl.S b/sysdeps/unix/sysv/linux/x86/prctl.S
new file mode 100644
index 0000000000..ce9903ab15
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86/prctl.S
@@ -0,0 +1,37 @@
+/* prctl - Linux specific syscall.  Linux/x86 version.
+   Copyright (C) 2020 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>
+
+/* On Linux/x86, the prctl syscall interface:
+
+   extern int prctl (int, unsigned long int, unsigned long int,
+		     unsigned long int, unsigned long int);
+
+   and the glibc prctl interface:
+
+   extern int prctl (int option, ...);
+
+   pass the arguments identically.  */
+
+PSEUDO (__prctl, prctl, 5)
+	ret
+PSEUDO_END (__prctl)
+
+hidden_def (__prctl)
+weak_alias (__prctl, prctl)
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/prctl.S b/sysdeps/unix/sysv/linux/x86_64/x32/prctl.S
new file mode 100644
index 0000000000..5acf5406a8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/prctl.S
@@ -0,0 +1,28 @@
+/* prctl - Linux specific syscall.  Linux/x32 version.
+   Copyright (C) 2020 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>
+
+/* On Linux/x32, we need to zero-extend from 32 bits to 64 bits for the
+   last 4 arguments.  */
+
+#undef DOARGS_5
+#define DOARGS_5 \
+  movl %esi, %esi; movl %edx, %edx; movl %ecx, %r10d; movl %r8d, %r8d;
+
+#include <sysdeps/unix/sysv/linux/x86/prctl.S>
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 14:51     ` Adhemerval Zanella
@ 2020-04-30 16:35       ` H.J. Lu
  2020-04-30 16:51         ` Florian Weimer
  0 siblings, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 16:35 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

On Thu, Apr 30, 2020 at 9:06 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
>
>
> On 30/04/2020 10:03, H.J. Lu via Libc-alpha wrote:
>
> > Here is the updated patch.  I added the assembly version for x86.  Other
> > arches can do
> >
> > #include <sysdeps/unix/sysv/linux/x86/prctl.S>
>
> Do we really an assembly optimization for this? I hardly think this
> a hotstop symbol.

I have no strong opinion on this.

-- 
H.J.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 16:35       ` H.J. Lu
@ 2020-04-30 16:51         ` Florian Weimer
  2020-04-30 17:24           ` Adhemerval Zanella
  0 siblings, 1 reply; 30+ messages in thread
From: Florian Weimer @ 2020-04-30 16:51 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha

* H. J. Lu via Libc-alpha:

> On Thu, Apr 30, 2020 at 9:06 AM Adhemerval Zanella via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
>>
>>
>>
>> On 30/04/2020 10:03, H.J. Lu via Libc-alpha wrote:
>>
>> > Here is the updated patch.  I added the assembly version for x86.  Other
>> > arches can do
>> >
>> > #include <sysdeps/unix/sysv/linux/x86/prctl.S>
>>
>> Do we really an assembly optimization for this? I hardly think this
>> a hotstop symbol.
>
> I have no strong opinion on this.

Me neither.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 15:27               ` V3 " H.J. Lu
@ 2020-04-30 16:53                 ` Florian Weimer
  2020-04-30 17:20                   ` [PATCH] Add a " H.J. Lu
  2020-04-30 20:01                 ` V3 [PATCH] Add a C " Florian Weimer
  2022-11-10  8:33                 ` Florian Weimer
  2 siblings, 1 reply; 30+ messages in thread
From: Florian Weimer @ 2020-04-30 16:53 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha; +Cc: Andreas Schwab, H.J. Lu

* H. J. Lu via Libc-alpha:

> From ee8672af3ef5f3db438c0abb39b2673944181292 Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Wed, 29 Apr 2020 07:38:49 -0700
> Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]
>
> Add a C wrapper to pass arguments in

The commit message is only correct if you drop the .S files.

> /* Control process execution.  */
> extern int prctl (int __option, ...) __THROW;
>
> to prctl syscall:
>
> extern int prctl (int, unsigned long int, unsigned long int,
> 		  unsigned long int, unsigned long int);
>
> On Linux/x86, since the prctl syscall interface:
>
> extern int prctl (int, unsigned long int, unsigned long int,
> 		  unsigned long int, unsigned long int);
>
> and the glibc prctl interface:
>
> extern int prctl (int option, ...);
>
> pass the arguments identically, the assembly verion:
>
> PSEUDO (__prctl, prctl, 5)
> 	ret
> PSEUDO_END (__prctl)
>
> is used.

Doesn't x86 include x32?

Apart from these nits, the patch looks good.  Please settle the matter
of the .S files with Adhemerval. 8-)

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] Add a wrapper for prctl [BZ #25896]
  2020-04-30 16:53                 ` Florian Weimer
@ 2020-04-30 17:20                   ` H.J. Lu
  0 siblings, 0 replies; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 17:20 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella; +Cc: H.J. Lu via Libc-alpha, Andreas Schwab

[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]

On Thu, Apr 30, 2020 at 9:53 AM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > From ee8672af3ef5f3db438c0abb39b2673944181292 Mon Sep 17 00:00:00 2001
> > From: "H.J. Lu" <hjl.tools@gmail.com>
> > Date: Wed, 29 Apr 2020 07:38:49 -0700
> > Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]
> >
> > Add a C wrapper to pass arguments in
>
> The commit message is only correct if you drop the .S files.
>
> > /* Control process execution.  */
> > extern int prctl (int __option, ...) __THROW;
> >
> > to prctl syscall:
> >
> > extern int prctl (int, unsigned long int, unsigned long int,
> >                 unsigned long int, unsigned long int);
> >
> > On Linux/x86, since the prctl syscall interface:
> >
> > extern int prctl (int, unsigned long int, unsigned long int,
> >                 unsigned long int, unsigned long int);
> >
> > and the glibc prctl interface:
> >
> > extern int prctl (int option, ...);
> >
> > pass the arguments identically, the assembly verion:
> >
> > PSEUDO (__prctl, prctl, 5)
> >       ret
> > PSEUDO_END (__prctl)
> >
> > is used.
>
> Doesn't x86 include x32?

Yes.

> Apart from these nits, the patch looks good.  Please settle the matter
> of the .S files with Adhemerval. 8-)

Since the C version is so much worse than the assembler version,
I prefer to include the assembler wrapper.  But I won't insist.

Adhemerval, please comment.

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-Add-a-wrapper-for-prctl-BZ-25896.patch --]
[-- Type: application/x-patch, Size: 9212 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V2 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 16:51         ` Florian Weimer
@ 2020-04-30 17:24           ` Adhemerval Zanella
  2020-04-30 17:29             ` V4 " H.J. Lu
  0 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella @ 2020-04-30 17:24 UTC (permalink / raw)
  To: Florian Weimer, H.J. Lu via Libc-alpha



On 30/04/2020 13:51, Florian Weimer wrote:
> * H. J. Lu via Libc-alpha:
> 
>> On Thu, Apr 30, 2020 at 9:06 AM Adhemerval Zanella via Libc-alpha
>> <libc-alpha@sourceware.org> wrote:
>>>
>>>
>>>
>>> On 30/04/2020 10:03, H.J. Lu via Libc-alpha wrote:
>>>
>>>> Here is the updated patch.  I added the assembly version for x86.  Other
>>>> arches can do
>>>>
>>>> #include <sysdeps/unix/sysv/linux/x86/prctl.S>
>>>
>>> Do we really an assembly optimization for this? I hardly think this
>>> a hotstop symbol.
>>
>> I have no strong opinion on this.
> 
> Me neither.
> 
I would prefer to push for an assembly optimization for symbol that
performance is paramount and usually might appear as a hotspot. 
My understanding is usually prctl is used scarcely and I think
it would be better to use the C generic.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* V4 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 17:24           ` Adhemerval Zanella
@ 2020-04-30 17:29             ` H.J. Lu
       [not found]               ` <c2a821bf-fd2a-0ed9-2ad9-c4bd1231b2a7@linux.ibm.com>
  0 siblings, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 17:29 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: Florian Weimer, H.J. Lu via Libc-alpha

[-- Attachment #1: Type: text/plain, Size: 994 bytes --]

On Thu, Apr 30, 2020 at 10:24 AM Adhemerval Zanella
<adhemerval.zanella@linaro.org> wrote:
>
>
>
> On 30/04/2020 13:51, Florian Weimer wrote:
> > * H. J. Lu via Libc-alpha:
> >
> >> On Thu, Apr 30, 2020 at 9:06 AM Adhemerval Zanella via Libc-alpha
> >> <libc-alpha@sourceware.org> wrote:
> >>>
> >>>
> >>>
> >>> On 30/04/2020 10:03, H.J. Lu via Libc-alpha wrote:
> >>>
> >>>> Here is the updated patch.  I added the assembly version for x86.  Other
> >>>> arches can do
> >>>>
> >>>> #include <sysdeps/unix/sysv/linux/x86/prctl.S>
> >>>
> >>> Do we really an assembly optimization for this? I hardly think this
> >>> a hotstop symbol.
> >>
> >> I have no strong opinion on this.
> >
> > Me neither.
> >
> I would prefer to push for an assembly optimization for symbol that
> performance is paramount and usually might appear as a hotspot.
> My understanding is usually prctl is used scarcely and I think
> it would be better to use the C generic.

This is the patch I am checking in.

-- 
H.J.

[-- Attachment #2: 0001-Add-a-C-wrapper-for-prctl-BZ-25896.patch --]
[-- Type: text/x-patch, Size: 4192 bytes --]

From bd66a4111db106249d6f16fba7c55bd6cec1d779 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 29 Apr 2020 07:38:49 -0700
Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]

Add a C wrapper to pass arguments in

/* Control process execution.  */
extern int prctl (int __option, ...) __THROW;

to prctl syscall:

extern int prctl (int, unsigned long int, unsigned long int,
		  unsigned long int, unsigned long int);
---
 include/sys/prctl.h                   |  1 +
 sysdeps/unix/sysv/linux/Makefile      |  2 +-
 sysdeps/unix/sysv/linux/prctl.c       | 42 +++++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/syscalls.list |  1 -
 4 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/prctl.c

diff --git a/include/sys/prctl.h b/include/sys/prctl.h
index 0920ed642b..d33f3a290e 100644
--- a/include/sys/prctl.h
+++ b/include/sys/prctl.h
@@ -4,6 +4,7 @@
 # ifndef _ISOMAC
 
 extern int __prctl (int __option, ...);
+libc_hidden_proto (__prctl)
 
 # endif /* !_ISOMAC */
 #endif
diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile
index db78eeadd1..0326f92c40 100644
--- a/sysdeps/unix/sysv/linux/Makefile
+++ b/sysdeps/unix/sysv/linux/Makefile
@@ -59,7 +59,7 @@ sysdep_routines += adjtimex clone umount umount2 readahead sysctl \
 		   eventfd eventfd_read eventfd_write prlimit \
 		   personality epoll_wait tee vmsplice splice \
 		   open_by_handle_at mlock2 pkey_mprotect pkey_set pkey_get \
-		   timerfd_gettime timerfd_settime \
+		   timerfd_gettime timerfd_settime prctl \
 		   process_vm_readv process_vm_writev
 
 CFLAGS-gethostid.c = -fexceptions
diff --git a/sysdeps/unix/sysv/linux/prctl.c b/sysdeps/unix/sysv/linux/prctl.c
new file mode 100644
index 0000000000..d5725f14cf
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/prctl.c
@@ -0,0 +1,42 @@
+/* prctl - Linux specific syscall.
+   Copyright (C) 2020 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)
diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
index ced77d49fa..1d8893d1b8 100644
--- a/sysdeps/unix/sysv/linux/syscalls.list
+++ b/sysdeps/unix/sysv/linux/syscalls.list
@@ -43,7 +43,6 @@ nfsservctl	EXTRA	nfsservctl	i:ipp	__compat_nfsservctl	nfsservctl@GLIBC_2.0:GLIBC
 pipe		-	pipe		i:f	__pipe		pipe
 pipe2		-	pipe2		i:fi	__pipe2		pipe2
 pivot_root	EXTRA	pivot_root	i:ss	pivot_root
-prctl		EXTRA	prctl		i:iiiii	__prctl		prctl
 query_module	EXTRA	query_module	i:sipip	__compat_query_module	query_module@GLIBC_2.0:GLIBC_2.23
 quotactl	EXTRA	quotactl	i:isip	quotactl
 remap_file_pages -	remap_file_pages i:pUiUi	__remap_file_pages remap_file_pages
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 15:27               ` V3 " H.J. Lu
  2020-04-30 16:53                 ` Florian Weimer
@ 2020-04-30 20:01                 ` Florian Weimer
  2022-11-10  8:33                 ` Florian Weimer
  2 siblings, 0 replies; 30+ messages in thread
From: Florian Weimer @ 2020-04-30 20:01 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Andreas Schwab, H.J. Lu via Libc-alpha

* H. J. Lu:

> Here is the updated patch without
>
> libc_hidden_proto (prctl)
>
> OK for master?

Looks good to me.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Bad LOADARGS_N on PPC
       [not found]                 ` <CAMe9rOq60aAKujxFF=bSyN5yPZVWSa-KWKWXKHpB8uOKu5V-7w@mail.gmail.com>
@ 2020-04-30 22:57                   ` H.J. Lu
  2020-05-01  2:03                     ` Tulio Magno Quites Machado Filho
  0 siblings, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-04-30 22:57 UTC (permalink / raw)
  To: Matheus Castanho, GNU C Library

On Thu, Apr 30, 2020 at 2:07 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Apr 30, 2020 at 1:29 PM Matheus Castanho <msc@linux.ibm.com> wrote:
> >
> > I see failures on all builds for all ppc* targets after this commit:
> >
> > ../sysdeps/unix/sysv/linux/prctl.c: In function ‘__prctl’:
> > ../sysdeps/unix/sysv/linux/prctl.c:36:21: error: unused variable ‘arg5’
> > [-Werror=unused-variable]
> >    36 |   unsigned long int arg5 = va_arg (arg, unsigned long int);
> >       |                     ^~~~
> > ../sysdeps/unix/sysv/linux/prctl.c:35:21: error: unused variable ‘arg4’
> > [-Werror=unused-variable]
> >    35 |   unsigned long int arg4 = va_arg (arg, unsigned long int);
> >       |                     ^~~~
> > ../sysdeps/unix/sysv/linux/prctl.c:34:21: error: unused variable ‘arg3’
> > [-Werror=unused-variable]
> >    34 |   unsigned long int arg3 = va_arg (arg, unsigned long int);
> >       |                     ^~~~
> > ../sysdeps/unix/sysv/linux/prctl.c:33:21: error: unused variable ‘arg2’
> > [-Werror=unused-variable]
> >    33 |   unsigned long int arg2 = va_arg (arg, unsigned long int);
> >       |
>
> II am not familiar with ppc. There are:
>
> return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
>
> Why are arg2, arg3, arg4, arg5 unused?  What are passed to kernel
> on ppc?
>

See:

https://sourceware.org/bugzilla/show_bug.cgi?id=25902

with a patch.   But I can't test it natively.

-- 
H.J.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Bad LOADARGS_N on PPC
  2020-04-30 22:57                   ` Bad LOADARGS_N on PPC H.J. Lu
@ 2020-05-01  2:03                     ` Tulio Magno Quites Machado Filho
  2020-05-01  2:18                       ` [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902] H.J. Lu
  0 siblings, 1 reply; 30+ messages in thread
From: Tulio Magno Quites Machado Filho @ 2020-05-01  2:03 UTC (permalink / raw)
  To: H.J. Lu, Matheus Castanho, GNU C Library

"H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org> writes:

> See:
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=25902
>
> with a patch.   But I can't test it natively.

Tested.  LGTM.

Could you push it, please?

-- 
Tulio Magno

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902]
  2020-05-01  2:03                     ` Tulio Magno Quites Machado Filho
@ 2020-05-01  2:18                       ` H.J. Lu
  2020-05-01 23:11                         ` Please test: [2.31/2.30] " H.J. Lu
  0 siblings, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-05-01  2:18 UTC (permalink / raw)
  To: Tulio Magno Quites Machado Filho, Libc-stable Mailing List
  Cc: Matheus Castanho, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 598 bytes --]

On Thu, Apr 30, 2020 at 7:03 PM Tulio Magno Quites Machado Filho
<tuliom@ascii.art.br> wrote:
>
> "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org> writes:
>
> > See:
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=25902
> >
> > with a patch.   But I can't test it natively.
>
> Tested.  LGTM.
>
> Could you push it, please?

This is I am checking in.  I will backport it to 2.30/2.31 branches
together with

commit ff026950e280bc3e9487b41b460fb31bc5b57721
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Apr 30 10:42:43 2020 -0700

    Add a C wrapper for prctl [BZ #25896]

-- 
H.J.

[-- Attachment #2: 0001-powerpc-Rename-argN-to-_argN-in-LOADARGS_N-BZ-25902.patch --]
[-- Type: text/x-patch, Size: 3257 bytes --]

From 14f43dd34dcf1ba29386c01cd0b286dffb37412d Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 30 Apr 2020 15:49:47 -0700
Subject: [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902]

LOADARGS_N in powerpc/sysdep.h uses argN as local variables.  It breaks
when argN is also a function argument.  Rename argN to _argN to avoid
conflict.
---
 sysdeps/unix/sysv/linux/powerpc/sysdep.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/powerpc/sysdep.h b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
index fd79bbcf3c..b2bca598b9 100644
--- a/sysdeps/unix/sysv/linux/powerpc/sysdep.h
+++ b/sysdeps/unix/sysv/linux/powerpc/sysdep.h
@@ -100,53 +100,53 @@
 #define LOADARGS_0(name, dummy) \
 	r0 = name
 #define LOADARGS_1(name, __arg1) \
-	long int arg1 = (long int) (__arg1); \
+	long int _arg1 = (long int) (__arg1); \
 	LOADARGS_0(name, 0); \
 	extern void __illegally_sized_syscall_arg1 (void); \
 	if (__builtin_classify_type (__arg1) != 5 \
 	    && sizeof (__arg1) > SYSCALL_ARG_SIZE) \
 	  __illegally_sized_syscall_arg1 (); \
-	r3 = arg1
+	r3 = _arg1
 #define LOADARGS_2(name, __arg1, __arg2) \
-	long int arg2 = (long int) (__arg2); \
+	long int _arg2 = (long int) (__arg2); \
 	LOADARGS_1(name, __arg1); \
 	extern void __illegally_sized_syscall_arg2 (void); \
 	if (__builtin_classify_type (__arg2) != 5 \
 	    && sizeof (__arg2) > SYSCALL_ARG_SIZE) \
 	  __illegally_sized_syscall_arg2 (); \
-	r4 = arg2
+	r4 = _arg2
 #define LOADARGS_3(name, __arg1, __arg2, __arg3) \
-	long int arg3 = (long int) (__arg3); \
+	long int _arg3 = (long int) (__arg3); \
 	LOADARGS_2(name, __arg1, __arg2); \
 	extern void __illegally_sized_syscall_arg3 (void); \
 	if (__builtin_classify_type (__arg3) != 5 \
 	    && sizeof (__arg3) > SYSCALL_ARG_SIZE) \
 	  __illegally_sized_syscall_arg3 (); \
-	r5 = arg3
+	r5 = _arg3
 #define LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4) \
-	long int arg4 = (long int) (__arg4); \
+	long int _arg4 = (long int) (__arg4); \
 	LOADARGS_3(name, __arg1, __arg2, __arg3); \
 	extern void __illegally_sized_syscall_arg4 (void); \
 	if (__builtin_classify_type (__arg4) != 5 \
 	    && sizeof (__arg4) > SYSCALL_ARG_SIZE) \
 	  __illegally_sized_syscall_arg4 (); \
-	r6 = arg4
+	r6 = _arg4
 #define LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5) \
-	long int arg5 = (long int) (__arg5); \
+	long int _arg5 = (long int) (__arg5); \
 	LOADARGS_4(name, __arg1, __arg2, __arg3, __arg4); \
 	extern void __illegally_sized_syscall_arg5 (void); \
 	if (__builtin_classify_type (__arg5) != 5 \
 	    && sizeof (__arg5) > SYSCALL_ARG_SIZE) \
 	  __illegally_sized_syscall_arg5 (); \
-	r7 = arg5
+	r7 = _arg5
 #define LOADARGS_6(name, __arg1, __arg2, __arg3, __arg4, __arg5, __arg6) \
-	long int arg6 = (long int) (__arg6); \
+	long int _arg6 = (long int) (__arg6); \
 	LOADARGS_5(name, __arg1, __arg2, __arg3, __arg4, __arg5); \
 	extern void __illegally_sized_syscall_arg6 (void); \
 	if (__builtin_classify_type (__arg6) != 5 \
 	    && sizeof (__arg6) > SYSCALL_ARG_SIZE) \
 	  __illegally_sized_syscall_arg6 (); \
-	r8 = arg6
+	r8 = _arg6
 
 #define ASM_INPUT_0 "0" (r0)
 #define ASM_INPUT_1 ASM_INPUT_0, "1" (r3)
-- 
2.26.2


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Please test: [2.31/2.30] [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902]
  2020-05-01  2:18                       ` [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902] H.J. Lu
@ 2020-05-01 23:11                         ` H.J. Lu
  2020-05-04 16:00                           ` Matheus Castanho
  0 siblings, 1 reply; 30+ messages in thread
From: H.J. Lu @ 2020-05-01 23:11 UTC (permalink / raw)
  To: Tulio Magno Quites Machado Filho, Libc-stable Mailing List
  Cc: Matheus Castanho, GNU C Library

[-- Attachment #1: Type: text/plain, Size: 921 bytes --]

On Thu, Apr 30, 2020 at 7:18 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Apr 30, 2020 at 7:03 PM Tulio Magno Quites Machado Filho
> <tuliom@ascii.art.br> wrote:
> >
> > "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org> writes:
> >
> > > See:
> > >
> > > https://sourceware.org/bugzilla/show_bug.cgi?id=25902
> > >
> > > with a patch.   But I can't test it natively.
> >
> > Tested.  LGTM.
> >
> > Could you push it, please?
>
> This is I am checking in.  I will backport it to 2.30/2.31 branches
> together with
>
> commit ff026950e280bc3e9487b41b460fb31bc5b57721
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date:   Thu Apr 30 10:42:43 2020 -0700
>
>     Add a C wrapper for prctl [BZ #25896]
>

I need to update both  powerpc32/sysdep.h and powerpc64/sysdep.h
on 2.30 and 2.31 branches, instead of just powerpc/sysdep.h.   Can
someone please test this patch on 2.30 and 2.31 branches on PPC?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-powerpc-Rename-argN-to-_argN-in-LOADARGS_N-BZ-25902.patch --]
[-- Type: application/x-patch, Size: 5975 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Please test: [2.31/2.30] [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902]
  2020-05-01 23:11                         ` Please test: [2.31/2.30] " H.J. Lu
@ 2020-05-04 16:00                           ` Matheus Castanho
  2020-05-04 19:11                             ` H.J. Lu
  0 siblings, 1 reply; 30+ messages in thread
From: Matheus Castanho @ 2020-05-04 16:00 UTC (permalink / raw)
  To: H.J. Lu, Tulio Magno Quites Machado Filho, Libc-stable Mailing List
  Cc: GNU C Library

On 5/1/20 8:11 PM, H.J. Lu wrote:
> On Thu, Apr 30, 2020 at 7:18 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> On Thu, Apr 30, 2020 at 7:03 PM Tulio Magno Quites Machado Filho
>> <tuliom@ascii.art.br> wrote:
>>>
>>> "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org> writes:
>>>
>>>> See:
>>>>
>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=25902
>>>>
>>>> with a patch.   But I can't test it natively.
>>>
>>> Tested.  LGTM.
>>>
>>> Could you push it, please?
>>
>> This is I am checking in.  I will backport it to 2.30/2.31 branches
>> together with
>>
>> commit ff026950e280bc3e9487b41b460fb31bc5b57721
>> Author: H.J. Lu <hjl.tools@gmail.com>
>> Date:   Thu Apr 30 10:42:43 2020 -0700
>>
>>     Add a C wrapper for prctl [BZ #25896]
>>
> 
> I need to update both  powerpc32/sysdep.h and powerpc64/sysdep.h
> on 2.30 and 2.31 branches, instead of just powerpc/sysdep.h.   Can
> someone please test this patch on 2.30 and 2.31 branches on PPC?
> 

- Cherry-picked "ff026950e2 Add a C wrapper for prctl [BZ #25896]" on
top of current release/2.30/master and release/2.31/master
- Fixed minor merge conflicts
- Applied the patch you sent

Tested on ppc, ppc64 and ppc64le. Both branches built fine and all tests
passed on all arch variants.

Thanks.

> Thanks.
> 

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: Please test: [2.31/2.30] [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902]
  2020-05-04 16:00                           ` Matheus Castanho
@ 2020-05-04 19:11                             ` H.J. Lu
  0 siblings, 0 replies; 30+ messages in thread
From: H.J. Lu @ 2020-05-04 19:11 UTC (permalink / raw)
  To: Matheus Castanho
  Cc: Tulio Magno Quites Machado Filho, Libc-stable Mailing List,
	GNU C Library

On Mon, May 4, 2020 at 9:00 AM Matheus Castanho <msc@linux.ibm.com> wrote:
>
> On 5/1/20 8:11 PM, H.J. Lu wrote:
> > On Thu, Apr 30, 2020 at 7:18 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>
> >> On Thu, Apr 30, 2020 at 7:03 PM Tulio Magno Quites Machado Filho
> >> <tuliom@ascii.art.br> wrote:
> >>>
> >>> "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org> writes:
> >>>
> >>>> See:
> >>>>
> >>>> https://sourceware.org/bugzilla/show_bug.cgi?id=25902
> >>>>
> >>>> with a patch.   But I can't test it natively.
> >>>
> >>> Tested.  LGTM.
> >>>
> >>> Could you push it, please?
> >>
> >> This is I am checking in.  I will backport it to 2.30/2.31 branches
> >> together with
> >>
> >> commit ff026950e280bc3e9487b41b460fb31bc5b57721
> >> Author: H.J. Lu <hjl.tools@gmail.com>
> >> Date:   Thu Apr 30 10:42:43 2020 -0700
> >>
> >>     Add a C wrapper for prctl [BZ #25896]
> >>
> >
> > I need to update both  powerpc32/sysdep.h and powerpc64/sysdep.h
> > on 2.30 and 2.31 branches, instead of just powerpc/sysdep.h.   Can
> > someone please test this patch on 2.30 and 2.31 branches on PPC?
> >
>
> - Cherry-picked "ff026950e2 Add a C wrapper for prctl [BZ #25896]" on
> top of current release/2.30/master and release/2.31/master
> - Fixed minor merge conflicts
> - Applied the patch you sent
>
> Tested on ppc, ppc64 and ppc64le. Both branches built fine and all tests
> passed on all arch variants.

Thanks.

> Thanks.
>
> > Thanks.
> >



-- 
H.J.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2020-04-30 15:27               ` V3 " H.J. Lu
  2020-04-30 16:53                 ` Florian Weimer
  2020-04-30 20:01                 ` V3 [PATCH] Add a C " Florian Weimer
@ 2022-11-10  8:33                 ` Florian Weimer
  2022-11-10 11:49                   ` Adhemerval Zanella Netto
  2 siblings, 1 reply; 30+ messages in thread
From: Florian Weimer @ 2022-11-10  8:33 UTC (permalink / raw)
  To: H.J. Lu via Libc-alpha; +Cc: Andreas Schwab, H.J. Lu

* H. J. Lu via Libc-alpha:

> From ee8672af3ef5f3db438c0abb39b2673944181292 Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Wed, 29 Apr 2020 07:38:49 -0700
> Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]
>
> Add a C wrapper to pass arguments in
>
> /* Control process execution.  */
> extern int prctl (int __option, ...) __THROW;
>
> to prctl syscall:
>
> extern int prctl (int, unsigned long int, unsigned long int,
> 		  unsigned long int, unsigned long int);
>
> On Linux/x86, since the prctl syscall interface:
>
> extern int prctl (int, unsigned long int, unsigned long int,
> 		  unsigned long int, unsigned long int);
>
> and the glibc prctl interface:
>
> extern int prctl (int option, ...);
>
> pass the arguments identically, the assembly verion:
>
> PSEUDO (__prctl, prctl, 5)
> 	ret
> PSEUDO_END (__prctl)
>
> is used.

This broke ABI on powerpc64le-linux-gnu because the calling convention
is not identical.  The manual page specifies the second prototype.

I filed a GCC RFE so that we can deal with this in a more elegant
manner:

  rs6000: Option not to use parameter save area in variadic function
  implementations
  <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107606>

I don't know whether we should restrict the C prctl wrapper to x86 x32,
or if we should add an assembler wrapper on powerpc64le-linux-gnu.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2022-11-10  8:33                 ` Florian Weimer
@ 2022-11-10 11:49                   ` Adhemerval Zanella Netto
  2022-11-10 12:03                     ` Florian Weimer
  0 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-10 11:49 UTC (permalink / raw)
  To: Florian Weimer, H.J. Lu via Libc-alpha; +Cc: Andreas Schwab, H.J. Lu



On 10/11/22 05:33, Florian Weimer via Libc-alpha wrote:
> * H. J. Lu via Libc-alpha:
> 
>> From ee8672af3ef5f3db438c0abb39b2673944181292 Mon Sep 17 00:00:00 2001
>> From: "H.J. Lu" <hjl.tools@gmail.com>
>> Date: Wed, 29 Apr 2020 07:38:49 -0700
>> Subject: [PATCH] Add a C wrapper for prctl [BZ #25896]
>>
>> Add a C wrapper to pass arguments in
>>
>> /* Control process execution.  */
>> extern int prctl (int __option, ...) __THROW;
>>
>> to prctl syscall:
>>
>> extern int prctl (int, unsigned long int, unsigned long int,
>> 		  unsigned long int, unsigned long int);
>>
>> On Linux/x86, since the prctl syscall interface:
>>
>> extern int prctl (int, unsigned long int, unsigned long int,
>> 		  unsigned long int, unsigned long int);
>>
>> and the glibc prctl interface:
>>
>> extern int prctl (int option, ...);
>>
>> pass the arguments identically, the assembly verion:
>>
>> PSEUDO (__prctl, prctl, 5)
>> 	ret
>> PSEUDO_END (__prctl)
>>
>> is used.
> 
> This broke ABI on powerpc64le-linux-gnu because the calling convention
> is not identical.  The manual page specifies the second prototype.
> 
> I filed a GCC RFE so that we can deal with this in a more elegant
> manner:
> 
>   rs6000: Option not to use parameter save area in variadic function
>   implementations
>   <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107606>
> 
> I don't know whether we should restrict the C prctl wrapper to x86 x32,
> or if we should add an assembler wrapper on powerpc64le-linux-gnu.
> 
> Thanks,
> Florian
> 

The previous syscalls.list entry marked the function as 5 argument one
instead of variadic, so I think it would be better to add a way each
ABI to use this instead of the variadic one. Something like:

  #if PRCTL_VARIADIC_OK
  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);
  }
  #else
  int
  __prctl (int option, int arg1, int arg2, int arg3, int arg4, int arg5)
  {
    return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
  }
  #endif

Or if powerpc64le is the only affected add a specific C implementation for
it.  I think we should really move away from assembler wrappers.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2022-11-10 11:49                   ` Adhemerval Zanella Netto
@ 2022-11-10 12:03                     ` Florian Weimer
  2022-11-10 12:25                       ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 30+ messages in thread
From: Florian Weimer @ 2022-11-10 12:03 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: H.J. Lu via Libc-alpha, Andreas Schwab, H.J. Lu

* Adhemerval Zanella Netto:

> The previous syscalls.list entry marked the function as 5 argument one
> instead of variadic, so I think it would be better to add a way each
> ABI to use this instead of the variadic one. Something like:
>
>   #if PRCTL_VARIADIC_OK
>   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);
>   }
>   #else
>   int
>   __prctl (int option, int arg1, int arg2, int arg3, int arg4, int arg5)
>   {
>     return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
>   }
>   #endif

(The arguments need to be unsigned long int.)

This is not easy to do in C because the GCC aliasing machinery performs
type checking (as it should).

We can probably use

#define prctl prctl_XXX
#define __prctl __prctl_XXX

before including <sys/prctl.h>, but that's quite ugly.  Do you still
want me to proceed with the C version?

Thanks,
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2022-11-10 12:03                     ` Florian Weimer
@ 2022-11-10 12:25                       ` Adhemerval Zanella Netto
  2022-11-10 13:17                         ` Florian Weimer
  0 siblings, 1 reply; 30+ messages in thread
From: Adhemerval Zanella Netto @ 2022-11-10 12:25 UTC (permalink / raw)
  To: Florian Weimer; +Cc: H.J. Lu via Libc-alpha, Andreas Schwab, H.J. Lu



On 10/11/22 09:03, Florian Weimer wrote:
> * Adhemerval Zanella Netto:
> 
>> The previous syscalls.list entry marked the function as 5 argument one
>> instead of variadic, so I think it would be better to add a way each
>> ABI to use this instead of the variadic one. Something like:
>>
>>   #if PRCTL_VARIADIC_OK
>>   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);
>>   }
>>   #else
>>   int
>>   __prctl (int option, int arg1, int arg2, int arg3, int arg4, int arg5)
>>   {
>>     return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
>>   }
>>   #endif
> 
> (The arguments need to be unsigned long int.)
> 
> This is not easy to do in C because the GCC aliasing machinery performs
> type checking (as it should).
> 
> We can probably use
> 
> #define prctl prctl_XXX
> #define __prctl __prctl_XXX

Yes, I did not include it but we already do it for non-LFS to LFS alias.

> 
> before including <sys/prctl.h>, but that's quite ugly.  Do you still
> want me to proceed with the C version?

I would, although it is not the simplest solution.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: V3 [PATCH] Add a C wrapper for prctl [BZ #25896]
  2022-11-10 12:25                       ` Adhemerval Zanella Netto
@ 2022-11-10 13:17                         ` Florian Weimer
  0 siblings, 0 replies; 30+ messages in thread
From: Florian Weimer @ 2022-11-10 13:17 UTC (permalink / raw)
  To: Adhemerval Zanella Netto; +Cc: H.J. Lu via Libc-alpha, Andreas Schwab, H.J. Lu

* Adhemerval Zanella Netto:

> On 10/11/22 09:03, Florian Weimer wrote:
>> * Adhemerval Zanella Netto:
>> 
>>> The previous syscalls.list entry marked the function as 5 argument one
>>> instead of variadic, so I think it would be better to add a way each
>>> ABI to use this instead of the variadic one. Something like:
>>>
>>>   #if PRCTL_VARIADIC_OK
>>>   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);
>>>   }
>>>   #else
>>>   int
>>>   __prctl (int option, int arg1, int arg2, int arg3, int arg4, int arg5)
>>>   {
>>>     return INLINE_SYSCALL_CALL (prctl, option, arg2, arg3, arg4, arg5);
>>>   }
>>>   #endif
>> 
>> (The arguments need to be unsigned long int.)
>> 
>> This is not easy to do in C because the GCC aliasing machinery performs
>> type checking (as it should).
>> 
>> We can probably use
>> 
>> #define prctl prctl_XXX
>> #define __prctl __prctl_XXX
>
> Yes, I did not include it but we already do it for non-LFS to LFS alias.
>
>> 
>> before including <sys/prctl.h>, but that's quite ugly.  Do you still
>> want me to proceed with the C version?
>
> I would, although it is not the simplest solution.

It's not too bad.  I'm going to make the internal __prctl prototype
non-variadic.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2022-11-10 13:18 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-29 20:52 [PATCH] Add a C wrapper for prctl [BZ #25896] H.J. Lu
2020-04-30  7:26 ` Florian Weimer
2020-04-30 13:03   ` V2 " H.J. Lu
2020-04-30 13:41     ` Andreas Schwab
2020-04-30 13:43       ` Florian Weimer
2020-04-30 13:50         ` H.J. Lu
2020-04-30 13:51         ` Andreas Schwab
2020-04-30 13:53           ` H.J. Lu
2020-04-30 14:04             ` Andreas Schwab
2020-04-30 15:27               ` V3 " H.J. Lu
2020-04-30 16:53                 ` Florian Weimer
2020-04-30 17:20                   ` [PATCH] Add a " H.J. Lu
2020-04-30 20:01                 ` V3 [PATCH] Add a C " Florian Weimer
2022-11-10  8:33                 ` Florian Weimer
2022-11-10 11:49                   ` Adhemerval Zanella Netto
2022-11-10 12:03                     ` Florian Weimer
2022-11-10 12:25                       ` Adhemerval Zanella Netto
2022-11-10 13:17                         ` Florian Weimer
2020-04-30 13:54           ` V2 " Florian Weimer
2020-04-30 14:51     ` Adhemerval Zanella
2020-04-30 16:35       ` H.J. Lu
2020-04-30 16:51         ` Florian Weimer
2020-04-30 17:24           ` Adhemerval Zanella
2020-04-30 17:29             ` V4 " H.J. Lu
     [not found]               ` <c2a821bf-fd2a-0ed9-2ad9-c4bd1231b2a7@linux.ibm.com>
     [not found]                 ` <CAMe9rOq60aAKujxFF=bSyN5yPZVWSa-KWKWXKHpB8uOKu5V-7w@mail.gmail.com>
2020-04-30 22:57                   ` Bad LOADARGS_N on PPC H.J. Lu
2020-05-01  2:03                     ` Tulio Magno Quites Machado Filho
2020-05-01  2:18                       ` [PATCH] powerpc: Rename argN to _argN in LOADARGS_N [BZ #25902] H.J. Lu
2020-05-01 23:11                         ` Please test: [2.31/2.30] " H.J. Lu
2020-05-04 16:00                           ` Matheus Castanho
2020-05-04 19:11                             ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).