From patchwork Mon May 3 21:00:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 43242 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 1107B3958C03; Mon, 3 May 2021 21:00:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1107B3958C03 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620075623; bh=BkayxVZyH3ixzLYPlVCwYPbxIlZPgyyoTHQsPG6tKiU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=p02R3GiM1i6c6X0OqCuRjO6KPr/xRPmP/14v8BWJhMRAqCpK7PfQ9YWrYjdRFn5+1 oJ2DNqH08vAmnAYQ6MdqaK+7i03A5GX1IIno8u91kRQ/+W8cAkwINxIXk4k2y332MC YJ1k5IzFzapdx1b0DbeOuCrD3vELxHTxveGiaDgM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by sourceware.org (Postfix) with ESMTPS id DA75F3957425 for ; Mon, 3 May 2021 21:00:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DA75F3957425 Received: by mail-qv1-xf35.google.com with SMTP id j3so3370333qvs.1 for ; Mon, 03 May 2021 14:00:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BkayxVZyH3ixzLYPlVCwYPbxIlZPgyyoTHQsPG6tKiU=; b=UYlsYxVpELeyd/GFSLJ5lRi/ME+oe+lgWoyTYqbXBJP2s1zHnewYTJVFHsTvWRFLoH nYk0YzsIf+gC1G9jB/6zhNXls4P8uoBoZfKzeLU96d5SjT5h1zZjtJn0F0dnS6G5jo3R Ze/+91XQ0ntJO9ZeqiXgGTDXudkE57qaT8H4eaVgFJbCu1v7hnJTI52rYww0GZYvjFqg VxRkQuWi/LMh5DGycQREp4zy708Oty+DzDdS1omci6FZBgSEjMExwcTq5LX4Z4Rizr5I d427M9TZYYfYdZB4fxaHXv2F5c/BZDbGHN/XRMNPgWcHzLlg0BVnienxjbNh+Uittkwa s4+g== X-Gm-Message-State: AOAM533IAAWkGd6uxo3t+cRkzlP/4jAFcM/TpDo//9U0QVOdyJM3cCmt Lugc3j16N4XkIocp4r9v6rLOLa8Whd2ssw== X-Google-Smtp-Source: ABdhPJxY26xpLyjER8ioZ/TI7CljH4kY3DEjpJKh5knQaOXFC7n1Bd2hTUVPWD6PBv5Z+bbZWHf7/A== X-Received: by 2002:a05:6214:248e:: with SMTP id gi14mr5483959qvb.7.1620075617244; Mon, 03 May 2021 14:00:17 -0700 (PDT) Received: from birita.. ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id w196sm4578090qkb.90.2021.05.03.14.00.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 May 2021 14:00:17 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 6/6] nptl: Use pthread_kill on pthread_cancel Date: Mon, 3 May 2021 18:00:05 -0300 Message-Id: <20210503210005.2891859-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210503210005.2891859-1-adhemerval.zanella@linaro.org> References: <20210503210005.2891859-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes from v2: * Rebased against master. --- It consolidates the tgkill call and it is the first step of making pthread_cancel async-signal-safe. Checked on x86_64-linux-gnu. --- nptl/Versions | 2 ++ nptl/pthreadP.h | 2 ++ nptl/pthread_cancel.c | 7 +------ nptl/pthread_kill.c | 19 +++++++++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/nptl/Versions b/nptl/Versions index b0c575e30f..42a07c9ca3 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -291,6 +291,8 @@ libc { __pthread_testcancel; __sched_fifo_max_prio; __sched_fifo_min_prio; + # Used for thread cancellation. + __pthread_kill_internal; } } diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 7d2f33be0d..ee92217598 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -552,6 +552,8 @@ extern int __pthread_equal (pthread_t thread1, pthread_t thread2); extern int __pthread_detach (pthread_t th); extern int __pthread_cancel (pthread_t th); libc_hidden_proto (__pthread_kill) +extern int __pthread_kill_internal (pthread_t threadid, int signo); +libc_hidden_proto (__pthread_kill_internal); extern void __pthread_exit (void *value) __attribute__ ((__noreturn__)); libc_hidden_proto (__pthread_exit) extern int __pthread_join (pthread_t threadid, void **thread_return); diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index d48d04881c..8dc1f23fdb 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -78,12 +78,7 @@ __pthread_cancel (pthread_t th) /* The cancellation handler will take care of marking the thread as canceled. */ - pid_t pid = __getpid (); - - int val = INTERNAL_SYSCALL_CALL (tgkill, pid, pd->tid, - SIGCANCEL); - if (INTERNAL_SYSCALL_ERROR_P (val)) - result = INTERNAL_SYSCALL_ERRNO (val); + __pthread_kill_internal (th, SIGCANCEL); break; } diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index d79531c10c..b1411f46b6 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -21,13 +21,8 @@ #include int -__pthread_kill (pthread_t threadid, int signo) +__pthread_kill_internal (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; - sigset_t set; __libc_signal_block_all (&set); @@ -58,6 +53,18 @@ __pthread_kill (pthread_t threadid, int signo) return val; } +libc_hidden_def (__pthread_kill_internal) + +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; + + return __pthread_kill_internal (threadid, signo); +} /* Some architectures (for instance arm) might pull raise through libgcc, so avoid the symbol version if it ends up being used on ld.so. */ #if !IS_IN(rtld)