From patchwork Thu Sep 30 20:00:45 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: 45631 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 C9F1A3857C71 for ; Thu, 30 Sep 2021 20:07:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9F1A3857C71 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633032470; bh=SO2veMYLGehM7MDG+iWNlZU9U0x8pZJ0hwuO/t7d1r4=; 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=D7Uhb9ADofeBrCBLUZzmFUhXfWVKiJARdorVobADrUwStpgA2s767cti5uvi/nX+t YmtOw1q4NtHdufDPVYBIUG1KK/uE6/5UwMiQdWzT7ZwM7eK0ubodQaETqm8Y1QEaex iJK9i1Iz9W+MxPWchaxVER4XJ5yBC/227eeHpjcs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id 411E03857C5B for ; Thu, 30 Sep 2021 20:01:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 411E03857C5B Received: by mail-qt1-x829.google.com with SMTP id j13so6906216qtq.6 for ; Thu, 30 Sep 2021 13:01:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SO2veMYLGehM7MDG+iWNlZU9U0x8pZJ0hwuO/t7d1r4=; b=hgw1OaF/MAJ/CKHRGyEb+ohp+hkRw7+m9tx2M92gEq9Vq4pmBUbVb3Jh/Hdz7r06/s 1J+Q+MUSjW21kUntZ1z2jI/EJt3pasNTmwGIOhiyPbnk1JPF1kFpjLiUaYK74qKKgEcH 8vfhHCfpSGkfojIntX2ZLAJEHwC/fzNTy6aqimrtMUs7/PTprE9YfkaeLynJXeDYwfrh plvczZxSZqcmSduwdBS7cieamV+8cSZP1uH4BmDcQd5xGnaiKkZKtkqGY10+q+zyW+aC fYdIbivae4C9IN1ENyLZzoGVC1N6VnjmAWk1fikMAkh8TrqWptsy6w4RNRb/UcGlBAhj jKGQ== X-Gm-Message-State: AOAM531OW2VyE8vQb9RU9rpnk59mU2lsUUSzGlYkuRh4aUXQ7uq91Njw E+i8o9K5KtX0Fy+w7egdmgSHrOn298E6pw== X-Google-Smtp-Source: ABdhPJxo1xoXJ1ouo5mcaKXPoyArQ4Q7/GwA+HDIDkXTlDoSEYeAVWVziX1UjJ39BWhPnijasyeOPw== X-Received: by 2002:ac8:4156:: with SMTP id e22mr1215671qtm.14.1633032066539; Thu, 30 Sep 2021 13:01:06 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b338:b20e:53f8:8b5:1bb2]) by smtp.gmail.com with ESMTPSA id r196sm1910203qka.119.2021.09.30.13.01.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 13:01:06 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 09/15] nptl: Use exit_lock when accessing TID on pthread_setschedparam Date: Thu, 30 Sep 2021 17:00:45 -0300 Message-Id: <20210930200051.1017457-10-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210930200051.1017457-1-adhemerval.zanella@linaro.org> References: <20210930200051.1017457-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The sched_getparam call is also replaced with a INTERNAL_SYSCALL_CALL to avoid clobbering errno. Checked on x86_64-linux-gnu. --- nptl/pthread_setschedparam.c | 51 +++++++++++++++------------- sysdeps/pthread/tst-pthread-exited.c | 6 ++++ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/nptl/pthread_setschedparam.c b/nptl/pthread_setschedparam.c index f38bd788af..d6027824db 100644 --- a/nptl/pthread_setschedparam.c +++ b/nptl/pthread_setschedparam.c @@ -15,26 +15,15 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include "pthreadP.h" -#include +#include +#include +#include -int -__pthread_setschedparam (pthread_t threadid, int policy, - const struct sched_param *param) +static int +setschedparam (struct pthread *pd, int policy, + const struct sched_param *param) { - struct pthread *pd = (struct pthread *) threadid; - - /* Make sure the descriptor is valid. */ - if (INVALID_TD_P (pd)) - /* Not a valid thread handle. */ - return ESRCH; - - int result = 0; - /* See CREATE THREAD NOTES in nptl/pthread_create.c. */ lll_lock (pd->lock, LLL_PRIVATE); @@ -43,8 +32,7 @@ __pthread_setschedparam (pthread_t threadid, int policy, /* If the thread should have higher priority because of some PTHREAD_PRIO_PROTECT mutexes it holds, adjust the priority. */ - if (__builtin_expect (pd->tpp != NULL, 0) - && pd->tpp->priomax > param->sched_priority) + if (pd->tpp != NULL && pd->tpp->priomax > param->sched_priority) { p = *param; p.sched_priority = pd->tpp->priomax; @@ -52,10 +40,8 @@ __pthread_setschedparam (pthread_t threadid, int policy, } /* Try to set the scheduler information. */ - if (__builtin_expect (__sched_setscheduler (pd->tid, policy, - param) == -1, 0)) - result = errno; - else + int r = INTERNAL_SYSCALL_CALL (sched_setscheduler, pd->tid, policy, param); + if (r == 0) { /* We succeeded changing the kernel information. Reflect this change in the thread descriptor. */ @@ -66,6 +52,25 @@ __pthread_setschedparam (pthread_t threadid, int policy, lll_unlock (pd->lock, LLL_PRIVATE); + return -r; +} + +int +__pthread_setschedparam (pthread_t threadid, int policy, + const struct sched_param *param) +{ + struct pthread *pd = (struct pthread *) threadid; + + /* Block all signals, as required by pd->exit_lock. */ + sigset_t old_mask; + __libc_signal_block_all (&old_mask); + __libc_lock_lock (pd->exit_lock); + + int result = pd->tid != 0 ? setschedparam (pd, policy, param) : ESRCH; + + __libc_lock_unlock (pd->exit_lock); + __libc_signal_restore_set (&old_mask); + return result; } strong_alias (__pthread_setschedparam, pthread_setschedparam) diff --git a/sysdeps/pthread/tst-pthread-exited.c b/sysdeps/pthread/tst-pthread-exited.c index d33e6b28fe..208546a546 100644 --- a/sysdeps/pthread/tst-pthread-exited.c +++ b/sysdeps/pthread/tst-pthread-exited.c @@ -57,6 +57,12 @@ do_test (void) TEST_COMPARE (r, ESRCH); } + { + struct sched_param sch = { 0 }; + int r = pthread_setschedparam (thr, SCHED_FIFO, &sch); + TEST_COMPARE (r, ESRCH); + } + xpthread_join (thr); return 0;