V4 [PATCH] Add a C wrapper for prctl [BZ #25896]
Commit Message
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.
Comments
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. 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?
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
@@ -4,6 +4,7 @@
# ifndef _ISOMAC
extern int __prctl (int __option, ...);
+libc_hidden_proto (__prctl)
# endif /* !_ISOMAC */
#endif
@@ -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
new file mode 100644
@@ -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)
@@ -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