Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Wed, 20 May 2020 02:09:25 +0000
From: tangyizhou <tangyizhou@...wei.com>
To: "musl@...ts.openwall.com" <musl@...ts.openwall.com>
CC: "Wanghui (John)" <john.wanghui@...wei.com>, "Huangshuai (OSLab)"
	<elvis.huang@...wei.com>, "dalias@...ifal.cx" <dalias@...ifal.cx>
Subject: Fix the return value of pthread_getschedparam in musl libc

Hi,

>From the latest upstream, I find the return value of pthread_getschedparam() is wrong when syscall sched_getparam succeeds but sched_getscheduler fails. It is rare to see this situation. When it happens, pthread_getschedparam() will return r which must be 0, that means a success according to POSIX 2017 specification. It's wrong.

Also, POSIX 2017 specification says an error number shall be returned to indicate the error. I think returning -*policy is appropriate because syscall sched_getscheduler returns an negative error code in kernel like Linux when it fails.

Here is my patch. I want to be Cc'd on replies. Thanks.

diff --git a/src/thread/pthread_getschedparam.c b/src/thread/pthread_getschedparam.c
index 1cba073d..8203d609 100644
--- a/src/thread/pthread_getschedparam.c
+++ b/src/thread/pthread_getschedparam.c
@@ -12,6 +12,9 @@ int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param
                if (!r) {
                        *policy = __syscall(SYS_sched_getscheduler, t->tid);
                }
+               if (*policy < 0) {
+                       r = -*policy;
+               }
        }
        UNLOCK(t->killlock);
        return r;


Content of type "text/html" skipped

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.