From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14658 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: =?utf-8?B?562U5aSNOiBbbXVz?= =?utf-8?Q?l=5D_Subject=3A_=5BPATCH=5D_pthread?= =?utf-8?Q?=3A?= Fix bug that pthread_create may cause priority inversion Date: Wed, 11 Sep 2019 13:29:19 -0400 Message-ID: <20190911172919.GZ9017@brightrain.aerifal.cx> References: <59FB1E003EF3A943BD6BAD197ABD4D6A2B5D55@dggemi524-mbx.china.huawei.com> <20190909145429.GG22009@port70.net> <20190909174943.GN9017@brightrain.aerifal.cx> <59FB1E003EF3A943BD6BAD197ABD4D6A2B7D7F@dggemi524-mbx.china.huawei.com> <20190911135200.GV9017@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="bJ3jXuwtxrXxD2iT" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="100328"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14674-gllmg-musl=m.gmane.org@lists.openwall.com Wed Sep 11 19:29:36 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i86Qx-000PyA-1v for gllmg-musl@m.gmane.org; Wed, 11 Sep 2019 19:29:35 +0200 Original-Received: (qmail 1493 invoked by uid 550); 11 Sep 2019 17:29:32 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 1475 invoked from network); 11 Sep 2019 17:29:31 -0000 Content-Disposition: inline In-Reply-To: <20190911135200.GV9017@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14658 Archived-At: --bJ3jXuwtxrXxD2iT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 11, 2019 at 09:52:00AM -0400, Rich Felker wrote: > On Wed, Sep 11, 2019 at 01:38:38PM +0000, zhaohang (F) wrote: > > Thank you Rich for your patch. It helps me a lot. > > > > But I find that 'return 0' is used to let child thread exit. In that > > case, a bad thing will happen that the return address of child > > thread maybe undefined, if caller set prio of child unsuccessfully. > > The code in __clone is supposed to perform SYS_exit if the start > function returns; this actually matters for users of the public > clone() function, I think. I found the problem -- when clone.s is built as thumb, mov lr,pc is invalid for saving the return address (it omits the thumb-mode bit). I have a patch I'll push soon, attached. Thanks again for the report! Rich --bJ3jXuwtxrXxD2iT Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-fix-code-path-where-child-function-returns-in-arm-__.patch" >From 05870abeaac0588fb9115cfd11f96880a0af2108 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 11 Sep 2019 13:13:57 -0400 Subject: [PATCH 1/2] fix code path where child function returns in arm __clone built as thumb mov lr,pc is not a valid way to save the return address in thumb mode since it omits the thumb bit. use a chain of bl and bx to emulate blx. this could be avoided by converting to a .S file with preprocessor conditions to use blx if available, but the time cost here is dominated by the syscall anyway. while making this change, also remove the remnants of support for pre-bx ISA levels. commit 9f290a49bf9ee247d540d3c83875288a7991699c removed the hack from the parent code paths, but left the unnecessary code in the child. keeping it would require rewriting two code paths rather than one, and is useless for reasons described in that commit. --- src/thread/arm/clone.s | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/thread/arm/clone.s b/src/thread/arm/clone.s index e16b1326..bb0965da 100644 --- a/src/thread/arm/clone.s +++ b/src/thread/arm/clone.s @@ -20,13 +20,9 @@ __clone: bx lr 1: mov r0,r6 - tst r5,#1 - bne 1f - mov lr,pc - mov pc,r5 + bl 3f 2: mov r7,#1 svc 0 - -1: mov lr,pc - bx r5 b 2b + +3: bx r5 -- 2.21.0 --bJ3jXuwtxrXxD2iT--