public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Florian Weimer <fw@deneb.enyo.de>,
	"H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Subject: V4 [PATCH] Add a C wrapper for prctl [BZ #25896]
Date: Thu, 30 Apr 2020 10:29:17 -0700	[thread overview]
Message-ID: <CAMe9rOpr0ibwUSdxDNGi9x=EGWJCbiG_S04+tg_hrcZuiukSTQ@mail.gmail.com> (raw)
In-Reply-To: <b89cd048-16f3-76e5-4251-bdc724b1e49b@linaro.org>

[-- 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


  reply	other threads:[~2020-04-30 17:29 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-29 20:52 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             ` H.J. Lu [this message]
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMe9rOpr0ibwUSdxDNGi9x=EGWJCbiG_S04+tg_hrcZuiukSTQ@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).