|
|
Message-ID: <20241224094104.GD10433@brightrain.aerifal.cx>
Date: Tue, 24 Dec 2024 04:41:04 -0500
From: Rich Felker <dalias@...c.org>
To: yan.li.cn@...driver.com
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] add check for pthread_attr_setschedparam().
On Tue, Dec 24, 2024 at 10:03:01AM +0800, yan.li.cn@...driver.com wrote:
> From: Yan Li <yan.li.cn@...driver.com>
>
> ---
> src/thread/pthread_attr_setschedparam.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
> mode change 100644 => 100755 src/thread/pthread_attr_setschedparam.c
>
> diff --git a/src/thread/pthread_attr_setschedparam.c b/src/thread/pthread_attr_setschedparam.c
> old mode 100644
> new mode 100755
> index d4c1204f..4e28415e
> --- a/src/thread/pthread_attr_setschedparam.c
> +++ b/src/thread/pthread_attr_setschedparam.c
> @@ -2,6 +2,13 @@
>
> int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param)
> {
> - a->_a_prio = param->sched_priority;
> - return 0;
> + int min = sched_get_priority_min (a->_a_policy);
> + int max = sched_get_priority_max (a->_a_policy);
> +
> + if (min < 0 || max < 0 || param->sched_priority < min || param->sched_priority > max){
> + return EINVAL;
> + }
> +
> + a->_a_prio = param->sched_priority;
> + return 0;
> }
> --
> 2.34.1
I don't see a good motivation for this change. The error conditions
are MAY FAIL, not SHALL FAIL, and checking for them incurs two useless
syscalls on every call to a function that's otherwise syscall-free.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.