mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Dominic Chen <d.c.ddcc@gmail.com>
Cc: fweimer@redhat.com, musl@lists.openwall.com
Subject: Re: [musl] Incorrect thread TID caching
Date: Mon, 15 Feb 2021 11:56:22 -0500	[thread overview]
Message-ID: <20210215165622.GF11590@brightrain.aerifal.cx> (raw)
In-Reply-To: <20210203225518.GY23432@brightrain.aerifal.cx>

On Wed, Feb 03, 2021 at 05:55:18PM -0500, Rich Felker wrote:
> On Wed, Feb 03, 2021 at 05:30:01PM -0500, Dominic Chen wrote:
> > 
> > On 2/3/2021 4:01 PM, Rich Felker wrote:
> > >OK, raise should probably just be changed here to work even in vforked
> > >child since it seems plausible someone will use it there. It's not
> > >like saving the syscall actually matters here. But that's independent
> > >of the clone() issue.
> > 
> > Sounds good, thanks!
> 
> Hm, looking at how to do this now, and if clone is going to behave
> like _Fork, it needs to be able to run code in the child (to restore
> the signals is masked, etc.), which means it needs to wrap the child
> function passed to it. I think this is doable, but it's not entirely
> trivial.

Following up on this now, the code in _Fork is something I really
don't want to duplicate for clone() for risk of forgetting there's a
copy in the latter and letting it bitrot there. I'd rather refactor
things so the same logic can be shared.

In theory we don't need __clone and the above-mentioned callback
wrapper machinery for the non-CLONE_VM case (the only one that's safe
anyway) and can just use __syscall(SYS_clone, ...) from C, and then
the code from _Fork.c can just be generalized to take a function
pointer and arg pointer to call back to instead of directly making the
SYS_fork syscall. However, the fact that SYS_clone has arch-dependent
argument order makes this painful. The extended arguments whose order
vary are *mostly* invalid (you can't set a custom TLS pointer or exit
futex address, at least) so perhaps we could just EINVAL them in
clone().

The other option looks like it's to split the pre/post logic for _Fork
out into separate functions; then clone can call the pre logic in the
parent and the child function passed to __clone can call the post
logic for the child. This is uglier and more costly to _Fork, and I'd
like to avoid it, but not as much as I'd like to avoid duplicating
logic for per-arch argument order. Hopefully we can avoid both..

Rich

  reply	other threads:[~2021-02-15 16:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03  4:04 Dominic Chen
2021-02-03  7:16 ` Florian Weimer
2021-02-03 19:21 ` Rich Felker
2021-02-03 20:21   ` Dominic Chen
2021-02-03 21:01     ` Rich Felker
2021-02-03 22:30       ` Dominic Chen
2021-02-03 22:55         ` Rich Felker
2021-02-15 16:56           ` Rich Felker [this message]
2021-02-17 19:49             ` Dominic Chen
2021-02-17 20:11               ` Rich Felker
2021-02-17 21:07                 ` Rich Felker
2021-03-12 21:14                   ` Dominic Chen
2021-02-04  3:28     ` Carlos O'Donell
2021-02-04  4:22       ` Dominic Chen
2021-02-04 16:15         ` Rich Felker

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=20210215165622.GF11590@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=d.c.ddcc@gmail.com \
    --cc=fweimer@redhat.com \
    --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).