From patchwork Mon Dec 7 21:27:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 41330 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 487C43896807; Mon, 7 Dec 2020 21:28:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 487C43896807 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1607376487; bh=3vQKv453aKDJ++ml5Jbl8mhmd9ip8QsRLHMpqEbibQ4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=xKby2kg71lnejOjE5kVlDPJkkdmc24MQOT40SNGJ5+TrXfjVxAz6sK3Q1k/y66V7f WghcivwOqJoGDSs1p9tyR3/H+uUVKo6XWYNcMoAWMXG2IO5oLMqgxhmn+/XOybeTIe a6Mn8lwZP2wNi3/ba9KJSiAEZ3wzddtFy50QyhLs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf42.google.com (mail-qv1-xf42.google.com [IPv6:2607:f8b0:4864:20::f42]) by sourceware.org (Postfix) with ESMTPS id 72D9B385782A for ; Mon, 7 Dec 2020 21:28:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 72D9B385782A Received: by mail-qv1-xf42.google.com with SMTP id n9so7299015qvp.5 for ; Mon, 07 Dec 2020 13:28:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3vQKv453aKDJ++ml5Jbl8mhmd9ip8QsRLHMpqEbibQ4=; b=rDRzolyhy7xkojNHlfVV1ZjzYfdtO3wondvS/dpIKfcH+4tM40glrPCxWQbzROBud+ Ha7H3JbughkH8tXnXye7mL72oqI1ByTPvMIArIouTgnE8VQOVi4GYEWeTp0DgOnvBrkI Zm9Dsgg1wyj03UCrTUwUCdWb8E0K3Pk3WUkNpaDlkn1SSvoMAkEQMouus04IFUvC5BK3 A551K++nx93XUIUzZBrDVec28R2osuzUrMxc1cXoo3Ecenckk9f09E3HDJ1RP8QX8kD0 MQSPuZnNEQ7dKMun8f1ot5T8XjUN9bK1ov0EUhiqssmR9J/Z8QbUaE+M4oU4rX3oe1pR GgFA== X-Gm-Message-State: AOAM5329u3NOsI7LbJCudfJ3UfQplanVooifmdfj5ri43SIBKHai5NB1 NJ4wOd8xw9G4ITgw2vXOzW9SYaCA9ML0+g== X-Google-Smtp-Source: ABdhPJxbcb2EZRdjJ2iHOCm0otidrm3+i9CS7AYnM/my69K2Ho5NoIVVQlSDfgsJ5ygk6lENrton/Q== X-Received: by 2002:a05:6214:aa1:: with SMTP id ew1mr22548253qvb.55.1607376482699; Mon, 07 Dec 2020 13:28:02 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id o29sm12832317qtl.7.2020.12.07.13.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 13:28:02 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/8] nptl: Move Linux pthread_kill to nptl Date: Mon, 7 Dec 2020 18:27:50 -0300 Message-Id: <20201207212757.3948164-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The nptl already expects a Linux syscall internally. Also __is_internal_signal is used and the DEBUGGING_P check is removed. Checked on x86_64-linux-gnu. --- nptl/pthread_kill.c | 28 ++++++++----- sysdeps/unix/sysv/linux/pthread_kill.c | 57 -------------------------- 2 files changed, 18 insertions(+), 67 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/pthread_kill.c diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index 73144a07ec..7ef68d1572 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -1,4 +1,4 @@ -/* Send a signal to a specific pthread. Stub version. +/* Send a signal to a specific pthread. Linux version. Copyright (C) 2014-2020 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -16,23 +16,31 @@ License along with the GNU C Library; if not, see . */ -#include -#include +#include #include - int __pthread_kill (pthread_t threadid, int signo) { + /* Disallow sending the signal we use for cancellation, timers, + for the setxid implementation. */ + if (__is_internal_signal (signo)) + return EINVAL; + + /* Force load of pd->tid into local variable or register. Otherwise + if a thread exits between ESRCH test and tgkill, we might return + EINVAL, because pd->tid would be cleared by the kernel. */ struct pthread *pd = (struct pthread *) threadid; - - /* Make sure the descriptor is valid. */ - if (DEBUGGING_P && INVALID_TD_P (pd)) + pid_t tid = atomic_forced_read (pd->tid); + if (__glibc_unlikely (tid <= 0)) /* Not a valid thread handle. */ return ESRCH; - return ENOSYS; + /* We have a special syscall to do the work. */ + pid_t pid = __getpid (); + + int val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo); + return (INTERNAL_SYSCALL_ERROR_P (val) + ? INTERNAL_SYSCALL_ERRNO (val) : 0); } strong_alias (__pthread_kill, pthread_kill) - -stub_warning (pthread_kill) diff --git a/sysdeps/unix/sysv/linux/pthread_kill.c b/sysdeps/unix/sysv/linux/pthread_kill.c deleted file mode 100644 index 4dfe08ffcd..0000000000 --- a/sysdeps/unix/sysv/linux/pthread_kill.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (C) 2002-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper , 2002. - - 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 -#include -#include -#include - - -int -__pthread_kill (pthread_t threadid, int signo) -{ - struct pthread *pd = (struct pthread *) threadid; - - /* Make sure the descriptor is valid. */ - if (DEBUGGING_P && INVALID_TD_P (pd)) - /* Not a valid thread handle. */ - return ESRCH; - - /* Force load of pd->tid into local variable or register. Otherwise - if a thread exits between ESRCH test and tgkill, we might return - EINVAL, because pd->tid would be cleared by the kernel. */ - pid_t tid = atomic_forced_read (pd->tid); - if (__glibc_unlikely (tid <= 0)) - /* Not a valid thread handle. */ - return ESRCH; - - /* Disallow sending the signal we use for cancellation, timers, - for the setxid implementation. */ - if (signo == SIGCANCEL || signo == SIGTIMER || signo == SIGSETXID) - return EINVAL; - - /* We have a special syscall to do the work. */ - pid_t pid = __getpid (); - - int val = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo); - return (INTERNAL_SYSCALL_ERROR_P (val) - ? INTERNAL_SYSCALL_ERRNO (val) : 0); -} -strong_alias (__pthread_kill, pthread_kill)