From: Andy Lutomirski <luto@amacapital.net>
To: musl@lists.openwall.com
Subject: Re: Custom __set_thread_area for ARM
Date: Tue, 27 Jan 2015 15:32:27 -0800 [thread overview]
Message-ID: <54C8200B.8060102@mit.edu> (raw)
In-Reply-To: <20150122051017.GL4574@brightrain.aerifal.cx>
On 01/21/2015 09:10 PM, Rich Felker wrote:
> On Wed, Jan 21, 2015 at 05:45:56PM -0800, Andy Lutomirski wrote:
>> On 01/13/2015 07:09 PM, Rich Felker wrote:
>>> On Tue, Jan 13, 2015 at 11:19:44PM +0300, Oleg Ranevskyy wrote:
>>>> Dear community,
>>>>
>>>> Musl has a generic implementation of the __set_thread_area function in
>>>> src/thread/__set_thread_area.c. It is not used for ARM though. There is a
>>>> custom ARM implementation in src/thread/arm/__set_thread_area.s.
>>>>
>>>> Would you be able to clarify the following question please?
>>>> Why musl doesn't define SYS_set_thread_area for ARM to utilize the generic
>>>> function and uses custom __set_thread_area instead?
>>>
>>> The ARM kernel does not implement SYS_set_thread_area. Instead it
>>> provides an ARM-specific syscall. The asm file you're looking at uses
>>> that instead.
>>>
>>> BTW, this code is replaced in git master and the pending 1.1.6
>>> release. It's part of the ARM atomics/TLS access overhaul.
>>
>> As the sort-of-maintainer of the kernel side of this on x86, I have to
>> ask: why is the i386 __set_thread_area function written in assembly?
>
> First, there's the musl-technical answer: the build system's per-arch
> replacement files are asm, not C. It's possible to use C by making an
> empty asm file and putting the replacement C file in the arch dir, but
> it's not as obvious what's going on. This could be changed if it
> helped, but...
>
> For __set_thread_area, there are good reasons for it to be asm. The
> x86 set_thread_area syscall is not usable without asm because you have
> to load the resulting segment into %gs. And as for musl in particular,
> we don't want an arch-specific function signature like the kernel has
> for this one on x86, taking a pointer to a user_desc struct. We want
> the function to simply take the desired thread pointer value and load
> it. On some archs that doesn't even need a syscall; it's just loading
> the argument into a GPR. On x86, however, it requires setting up a
> user_desc structure, passing that to the kernel, then loading %gs
> based on the result. Since we also want binaries that don't crash on
> ancient (2.4) kernels (even though they can't support threads), we
> also need the fallback code to use the modify_ldt syscall when
> set_thread_area is not available.
>
> BTW you can find some documentation of the history of musl's
> __set_thread_area via:
>
> git log -p src/thread/i386/__set_thread_area.s
Does musl not use inline asm? ISTM something like:
struct user_desc desc;
memset(&desc, 0, sizeof(desc));
desc.base = whatever;
// assign other fields
if (set_thread_area(&desc) != 0)
handle error;
asm volatile ("mov %0,%%fs" : : "=rm" ((desc.entry_number << 3) | 3));
would be a lot more comprehensible.
--Andy
next prev parent reply other threads:[~2015-01-27 23:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-13 20:19 Oleg Ranevskyy
2015-01-14 3:09 ` Rich Felker
2015-01-22 1:45 ` Andy Lutomirski
2015-01-22 5:10 ` Rich Felker
2015-01-27 23:32 ` Andy Lutomirski [this message]
2015-01-28 8:59 ` Szabolcs Nagy
2015-01-28 14:47 ` 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=54C8200B.8060102@mit.edu \
--to=luto@amacapital.net \
--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).