From patchwork Fri Dec 4 18:09:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1411208 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=bQPb7a0s; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cngj05BzFz9sW0 for ; Sat, 5 Dec 2020 05:09:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE22239730E9; Fri, 4 Dec 2020 18:09:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE22239730E9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1607105394; bh=oW17Wvl/uOqWCdA3ZrjCtxnHj+V4hu8eu6YiaZts9o8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=bQPb7a0slDDcwT5kGFjsVWCyjsz2baTPgRDateduAvHTUNV+SghKKPzTZhIkk+8Kr XoLKn502QQurCy6D1FmyiSPy3ecU6bEZiPnKPla/IRqyWwzIb2Aa/2yMyWb87zh6Wn duqBU5Y5Kg/ZXRFuWkI2zDbnIzZk6KNExiqbLKdE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by sourceware.org (Postfix) with ESMTPS id C48FB384A026 for ; Fri, 4 Dec 2020 18:09:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C48FB384A026 Received: by mail-qk1-x743.google.com with SMTP id y197so6256745qkb.7 for ; Fri, 04 Dec 2020 10:09:50 -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=oW17Wvl/uOqWCdA3ZrjCtxnHj+V4hu8eu6YiaZts9o8=; b=nPjUMzHlfY1+kzdk8u9N2lTwKLG9WWtk44Oqyrxs/KLAjhOOqik0H1Vy4onMHmYpaR 0Q+2GLaN/QfA2Vy8JKMjpjcuWBj8AaDH9odgr2pLna7QOe6i6zI0mn4LIe3+WQQIWoGv CwrAngeA6W9U0JeISKc5SsX0JLHTFLeb0/mRXiemsSPvYCa88Z57VQd8ugkIgMPn6fuQ fFC5Nr0GSKFS7grqdHXUjw2AT/tkAQZDd/dqKqpXNWSlrbb678QGEkyCG6tdZ3TTxXsb 2Aon7eCCdwF303s8wfz0ywAJxX2joi8OlIjDEWqhBuoAtY2cDeqrOnXbjNKlcs0tWMb2 /tlw== X-Gm-Message-State: AOAM532acP4SYCpwGYCmBvchijx1eCSDVsuzIUFL9WQsFibyeSG8zb4U dkwc6GJcvCk9W2LdhmF4mKJeOq9oiQ/AyA== X-Google-Smtp-Source: ABdhPJzpZRHnQ2LDoOwE5u9+nu28cpmBrAy5IAHj0bUgppm3JR6aPYO9M/xGz3tZg42FPkOAWUJOtA== X-Received: by 2002:a37:b384:: with SMTP id c126mr2424986qkf.418.1607105390015; Fri, 04 Dec 2020 10:09:50 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id b33sm6179827qta.62.2020.12.04.10.09.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 10:09:49 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 1/6] nptl: Move Linux pthread_kill to nptl Date: Fri, 4 Dec 2020 15:09:39 -0300 Message-Id: <20201204180944.3774769-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 Reply-To: Adhemerval Zanella Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The nptl already expects a Linux syscall internak. Also __is_internal_signal 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)