public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/pthread-multiple-fixes] nptl: Use exit_lock when accessing TID on pthread_getschedparam
@ 2021-09-10 14:38 Adhemerval Zanella
0 siblings, 0 replies; only message in thread
From: Adhemerval Zanella @ 2021-09-10 14:38 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d91ea0ec47b567a36183accbc7e8e10245ecf304
commit d91ea0ec47b567a36183accbc7e8e10245ecf304
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Sep 9 16:24:08 2021 -0300
nptl: Use exit_lock when accessing TID on pthread_getschedparam
The sched_getparam call is also replaced with a INTERNAL_SYSCALL_CALL
to avoid clobbering errno.
Checked on x86_64-linux-gnu.
Diff:
---
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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-10 14:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-10 14:38 [glibc/azanella/pthread-multiple-fixes] nptl: Use exit_lock when accessing TID on pthread_getschedparam Adhemerval Zanella
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).