Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 22 Jan 2015 00:10:17 -0500
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: Re: Custom __set_thread_area for ARM

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

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.