From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=HTML_MESSAGE, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16854 invoked from network); 20 May 2020 09:53:38 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 20 May 2020 09:53:38 -0000 Received: (qmail 1072 invoked by uid 550); 20 May 2020 09:53:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 18048 invoked from network); 20 May 2020 02:09:48 -0000 From: tangyizhou To: "musl@lists.openwall.com" CC: "Wanghui (John)" , "Huangshuai (OSLab)" , "dalias@aerifal.cx" Thread-Topic: Fix the return value of pthread_getschedparam in musl libc Thread-Index: AdYt7wSQbHOmwtVNSA+FzM3+dE/lsw== Date: Wed, 20 May 2020 02:09:25 +0000 Message-ID: <4EB7132F5A45D144AC896FC29A83F192011602E1@DGGEML521-MBS.china.huawei.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.166.213.6] Content-Type: multipart/alternative; boundary="_000_4EB7132F5A45D144AC896FC29A83F192011602E1DGGEML521MBSchi_" MIME-Version: 1.0 X-CFilter-Loop: Reflected Subject: [musl] Fix the return value of pthread_getschedparam in musl libc --_000_4EB7132F5A45D144AC896FC29A83F192011602E1DGGEML521MBSchi_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, >From the latest upstream, I find the return value of pthread_getschedparam(= ) is wrong when syscall sched_getparam succeeds but sched_getscheduler fail= s. 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 2= 017 specification. It's wrong. Also, POSIX 2017 specification says an error number shall be returned to in= dicate the error. I think returning -*policy is appropriate because syscall= sched_getscheduler returns an negative error code in kernel like Linux whe= n 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_getsch= edparam.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 poli= cy, struct sched_param if (!r) { *policy =3D __syscall(SYS_sched_getscheduler, t->ti= d); } + if (*policy < 0) { + r =3D -*policy; + } } UNLOCK(t->killlock); return r; --_000_4EB7132F5A45D144AC896FC29A83F192011602E1DGGEML521MBSchi_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

From the latest upstream, I find the return value = of pthread_getschedparam() is wrong when syscall sched_getparam succeeds bu= t sched_getscheduler fails. It is rare to see this situation. When it happens, pthread_getschedparam() will return r which mu= st be 0, that means a success according to POSIX 2017 specification. ItR= 17;s wrong.

 

Also, POSIX 2017 specification says an error numbe= r shall be returned to indicate the error. I think returning -*policy is ap= propriate 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<= /p>

--- a/src/thread/pthread_getschedparam.c

+++ b/src/thread/pthread_getschedparam= .c

@@ -12,6 +12,9 @@ int pthread_getschedparam(pt= hread_t t, int *restrict policy, struct sched_param

        &n= bsp;       if (!r) {

        &n= bsp;            = ;   *policy =3D __syscall(SYS_sched_getscheduler, t->tid);

        &n= bsp;       }

+       &nb= sp;       if (*policy < 0) {

+       &nb= sp;            =    r =3D -*policy;

+       &nb= sp;       }

        }<= /o:p>

        UNLOCK(= t->killlock);

        return = r;

 

--_000_4EB7132F5A45D144AC896FC29A83F192011602E1DGGEML521MBSchi_--