From patchwork Thu Apr 30 17:29:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 38880 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 591D33898517; Thu, 30 Apr 2020 17:30:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 591D33898517 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1588267805; bh=npbbTEuGDzXS4B0qoNMeWQmXtUjN3sm++BoOlw/8pks=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=I3OT/yOTg/4SE+qKDP6RPF+BF9PAu1n/N0skfEasxubnBMsObSWDXZAGb7SWccrjn 1NBvoAHeiKc0jHG23T/Ak+sugbIgp2KAiE/+4hgM08oVlzNrUnSEVeME8Qr3QxivTD 5UNLaQQpHYZG2aWmxu8xDTfFnLpDf5WZBaT5QjX0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by sourceware.org (Postfix) with ESMTPS id DB26B3894E6C for ; Thu, 30 Apr 2020 17:29:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DB26B3894E6C Received: by mail-il1-x142.google.com with SMTP id m5so2120190ilj.10 for ; Thu, 30 Apr 2020 10:29:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=npbbTEuGDzXS4B0qoNMeWQmXtUjN3sm++BoOlw/8pks=; b=nKQTp+8coWsHUTbAcJowXOVhZXlY0dadWedgizeEx4pS6QsOE+1lHjtTW7GTolphxS VGlXXBWNbuFmNvkRfC4IAQkPJ3Y7eCzYXb1wNPOwjhQF7xYQGygYHiJ8+IChh6SFalcU OcElXVqh9WPGPmPih+t7hsSEEnBxk/5OiO+StnNWp7g4ukfTWMWbI6kO+wKpxMaW7BPW IPDtSN5XTsXS0QMmS3JZd9JO8xRk/licUBvcPCn5hYjNTl8iGV3cxuHe0eaJ5X0c1SsI X+yOXE52flg+JiSxVNnM18Yrh+Meg5Vhh7nkhzbxMmC4rB8sX2c3lUyLGk+sSQIiFnu+ WSDQ== X-Gm-Message-State: AGi0PuadBO3Vwb0gA4VUsY68C82geEqN8eCiSxkRRcZEH5vIsfUn5kzS VIKOz7ksUBe3ub+VDGRSymFtDKueTmbKOScW7+/PkQ== X-Google-Smtp-Source: APiQypJMdYt6V/i/7chGxAXqFciv3FZ+0s8bvZVzjnVUBIzRj1yOo6x/vUGa+EguEDumGZLSLGQNWz7JwPRG1Jlkj0c= X-Received: by 2002:a92:c794:: with SMTP id c20mr3105421ilk.273.1588267793371; Thu, 30 Apr 2020 10:29:53 -0700 (PDT) MIME-Version: 1.0 References: <20200429205217.2435607-1-hjl.tools@gmail.com> <87wo5xa0yt.fsf@mid.deneb.enyo.de> <20200430130333.GA254612@gmail.com> <39a57354-4ca8-53f5-bb89-dadf25f3671a@linaro.org> <871ro49atj.fsf@mid.deneb.enyo.de> In-Reply-To: Date: Thu, 30 Apr 2020 10:29:17 -0700 Message-ID: Subject: V4 [PATCH] Add a C wrapper for prctl [BZ #25896] To: Adhemerval Zanella X-Spam-Status: No, score=-20.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer , "H.J. Lu via Libc-alpha" Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Thu, Apr 30, 2020 at 10:24 AM Adhemerval Zanella 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 > >> 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 > >>> > >>> 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. From bd66a4111db106249d6f16fba7c55bd6cec1d779 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" 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 + . */ + +#include +#include +#include + +/* 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