mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-08 17:42:12 +03:00
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. Also return EINVAL if the thread is already terminated at the time of the call. Checked on x86_64-linux-gnu.
This commit is contained in:
@@ -15,24 +15,14 @@
|
|||||||
License along with the GNU C Library; if not, see
|
License along with the GNU C Library; if not, see
|
||||||
<https://www.gnu.org/licenses/>. */
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include <errno.h>
|
#include <libc-lock.h>
|
||||||
#include <string.h>
|
#include <kernel-posix-cpu-timers.h>
|
||||||
#include "pthreadP.h"
|
#include <pthreadP.h>
|
||||||
#include <lowlevellock.h>
|
|
||||||
|
|
||||||
|
static int
|
||||||
int
|
getschedparam (struct pthread *pd, int *policy, struct sched_param *param)
|
||||||
__pthread_getschedparam (pthread_t threadid, int *policy,
|
|
||||||
struct sched_param *param)
|
|
||||||
{
|
{
|
||||||
struct pthread *pd = (struct pthread *) threadid;
|
int r = 0;
|
||||||
|
|
||||||
/* 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. */
|
/* See CREATE THREAD NOTES in nptl/pthread_create.c. */
|
||||||
lll_lock (pd->lock, LLL_PRIVATE);
|
lll_lock (pd->lock, LLL_PRIVATE);
|
||||||
@@ -44,22 +34,18 @@ __pthread_getschedparam (pthread_t threadid, int *policy,
|
|||||||
not yet been retrieved do it now. */
|
not yet been retrieved do it now. */
|
||||||
if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0)
|
if ((pd->flags & ATTR_FLAG_SCHED_SET) == 0)
|
||||||
{
|
{
|
||||||
if (__sched_getparam (pd->tid, &pd->schedparam) != 0)
|
r = INTERNAL_SYSCALL_CALL (sched_getparam, pd->tid, &pd->schedparam);
|
||||||
result = 1;
|
if (r == 0)
|
||||||
else
|
|
||||||
pd->flags |= ATTR_FLAG_SCHED_SET;
|
pd->flags |= ATTR_FLAG_SCHED_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0)
|
if ((pd->flags & ATTR_FLAG_POLICY_SET) == 0)
|
||||||
{
|
{
|
||||||
pd->schedpolicy = __sched_getscheduler (pd->tid);
|
r = pd->schedpolicy = INTERNAL_SYSCALL_CALL (sched_getscheduler, pd->tid);
|
||||||
if (pd->schedpolicy == -1)
|
if (r >= 0)
|
||||||
result = 1;
|
|
||||||
else
|
|
||||||
pd->flags |= ATTR_FLAG_POLICY_SET;
|
pd->flags |= ATTR_FLAG_POLICY_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == 0)
|
if (r >= 0)
|
||||||
{
|
{
|
||||||
*policy = pd->schedpolicy;
|
*policy = pd->schedpolicy;
|
||||||
memcpy (param, &pd->schedparam, sizeof (struct sched_param));
|
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);
|
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. */
|
||||||
|
internal_sigset_t old_mask;
|
||||||
|
internal_signal_block_all (&old_mask);
|
||||||
|
__libc_lock_lock (pd->exit_lock);
|
||||||
|
|
||||||
|
int result = pd->tid != 0 ? getschedparam (pd, policy, param) : EINVAL;
|
||||||
|
|
||||||
|
__libc_lock_unlock (pd->exit_lock);
|
||||||
|
internal_signal_restore_set (&old_mask);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
libc_hidden_def (__pthread_getschedparam)
|
libc_hidden_def (__pthread_getschedparam)
|
||||||
|
@@ -56,6 +56,13 @@ do_test (void)
|
|||||||
TEST_COMPARE (r, EINVAL);
|
TEST_COMPARE (r, EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
struct sched_param sch;
|
||||||
|
int policy;
|
||||||
|
int r = pthread_getschedparam (thr, &policy, &sch);
|
||||||
|
TEST_COMPARE (r, EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
xpthread_join (thr);
|
xpthread_join (thr);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user