mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Re: 答复: [musl] Subject: [PATCH] pthread: Fix bug that pthread_create may cause priority inversion
Date: Wed, 11 Sep 2019 13:29:19 -0400	[thread overview]
Message-ID: <20190911172919.GZ9017@brightrain.aerifal.cx> (raw)
In-Reply-To: <20190911135200.GV9017@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 775 bytes --]

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

[-- Attachment #2: 0001-fix-code-path-where-child-function-returns-in-arm-__.patch --]
[-- Type: text/plain, Size: 1316 bytes --]

From 05870abeaac0588fb9115cfd11f96880a0af2108 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
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


  reply	other threads:[~2019-09-11 17:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09 13:57 zhaohang (F)
2019-09-09 14:01 ` 答复: " zhaohang (F)
2019-09-09 14:54 ` Szabolcs Nagy
2019-09-09 17:49   ` Rich Felker
2019-09-11 13:38     ` 答复: [musl] " zhaohang (F)
2019-09-11 13:52       ` Rich Felker
2019-09-11 17:29         ` Rich Felker [this message]
2019-09-16  2:27           ` 答复: [musl] " zhaohang (F)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190911172919.GZ9017@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).