From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [PATCH 10/15] nptl: Use exit_lock when accessing TID on pthread_getschedparam
Date: Thu, 30 Sep 2021 17:00:46 -0300 [thread overview]
Message-ID: <20210930200051.1017457-11-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20210930200051.1017457-1-adhemerval.zanella@linaro.org>
The sched_getparam call is also replaced with a INTERNAL_SYSCALL_CALL
to avoid clobbering errno.
Checked on x86_64-linux-gnu.
---
nptl/pthread_getschedparam.c | 55 +++++++++++++++-------------
sysdeps/pthread/tst-pthread-exited.c | 7 ++++
2 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/nptl/pthread_getschedparam.c b/nptl/pthread_getschedparam.c
index ef4022b8ac..09d07c8a17 100644
--- a/nptl/pthread_getschedparam.c
+++ b/nptl/pthread_getschedparam.c
@@ -15,24 +15,14 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <errno.h>
-#include <string.h>
-#include "pthreadP.h"
-#include <lowlevellock.h>
+#include <libc-lock.h>
+#include <kernel-posix-cpu-timers.h>
+#include <pthreadP.h>
-
-int
-__pthread_getschedparam (pthread_t threadid, int *policy,
- struct sched_param *param)
+static int
+getschedparam (struct pthread *pd, int *policy, 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;
+ int r = 0;
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
lll_lock (pd->lock, LLL_PRIVATE);
@@ -44,22 +34,18 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
not yet been retrieved do it now. */
if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0)
{
- if (__sched_getparam (pd->tid, &pd->schedparam) != 0)
- result = 1;
- else
+ r = INTERNAL_SYSCALL_CALL (sched_getparam, pd->tid, &pd->schedparam);
+ if (r == 0)
pd->flags |= ATTR_FLAG_SCHED_SET;
}
-
if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0)
{
- pd->schedpolicy = __sched_getscheduler (pd->tid);
- if (pd->schedpolicy == -1)
- result = 1;
- else
+ r = pd->schedpolicy = INTERNAL_SYSCALL_CALL (sched_getscheduler, pd->tid);
+ if (r >= 0)
pd->flags |= ATTR_FLAG_POLICY_SET;
}
- if (result == 0)
+ if (r >= 0)
{
*policy = pd->schedpolicy;
memcpy (param, &pd->schedparam, sizeof (struct sched_param));
@@ -67,6 +53,25 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
lll_unlock (pd->lock, LLL_PRIVATE);
+ return -r;
+}
+
+int
+__pthread_getschedparam (pthread_t threadid, int *policy,
+ 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 ? getschedparam (pd, policy, param) : ESRCH;
+
+ __libc_lock_unlock (pd->exit_lock);
+ __libc_signal_restore_set (&old_mask);
+
return result;
}
libc_hidden_def (__pthread_getschedparam)
diff --git a/sysdeps/pthread/tst-pthread-exited.c b/sysdeps/pthread/tst-pthread-exited.c
index 208546a546..25015d4f74 100644
--- a/sysdeps/pthread/tst-pthread-exited.c
+++ b/sysdeps/pthread/tst-pthread-exited.c
@@ -63,6 +63,13 @@ do_test (void)
TEST_COMPARE (r, ESRCH);
}
+ {
+ struct sched_param sch;
+ int policy;
+ int r = pthread_getschedparam (thr, &policy, &sch);
+ TEST_COMPARE (r, ESRCH);
+ }
+
xpthread_join (thr);
return 0;
--
2.30.2
next prev parent reply other threads:[~2021-09-30 20:01 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-30 20:00 [PATCH 00/15] Fix various NPTL synchronization issues Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 01/15] nptl: Set cancellation type and state on pthread_exit (BZ #28267) Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 02/15] nptl: Handle robust PI mutexes for !__ASSUME_SET_ROBUST_LIST (BZ #28268) Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 03/15] nptl: Do not use pthread set_tid_address as state synchronization (BZ #19951) Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 04/15] nptl: Move setxid flag out of cancelhandling Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 05/15] nptl: Replace struct thread cancelhandling field Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 06/15] nptl: Use exit_lock when accessing TID on pthread_getaffinity_np Adhemerval Zanella
2021-09-30 20:54 ` Florian Weimer
2021-10-04 12:45 ` Cyril Hrubis
2021-10-04 19:27 ` Florian Weimer
2021-10-04 19:53 ` Adhemerval Zanella
2021-10-05 7:35 ` Cyril Hrubis
2021-10-05 13:47 ` Adhemerval Zanella
2021-10-10 14:37 ` Florian Weimer
2021-09-30 20:00 ` [PATCH 07/15] nptl: Use exit_lock when accessing TID on pthread_setaffinity Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 08/15] nptl: Use exit_lock when accessing TID on pthread_getcpuclockid Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 09/15] nptl: Use exit_lock when accessing TID on pthread_setschedparam Adhemerval Zanella
2021-09-30 20:00 ` Adhemerval Zanella [this message]
2021-09-30 20:00 ` [PATCH 11/15] nptl: Use exit_lock when accessing TID on pthread_getname_np Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 12/15] nptl: Use exit_lock when accessing TID on pthread_setname_np Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 13/15] nptl: Use exit_lock when accessing TID on pthread_sigqueue Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 14/15] nptl: Use exit_lock when accessing TID on pthread_setschedprio Adhemerval Zanella
2021-09-30 20:00 ` [PATCH 15/15] nptl: Remove INVALID_TD_P Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210930200051.1017457-11-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).