From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6878 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Re: Custom __set_thread_area for ARM Date: Thu, 22 Jan 2015 00:10:17 -0500 Message-ID: <20150122051017.GL4574@brightrain.aerifal.cx> References: <20150114030946.GL4574@brightrain.aerifal.cx> <54C05654.7000204@amacapital.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1421903437 28516 80.91.229.3 (22 Jan 2015 05:10:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Jan 2015 05:10:37 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6891-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jan 22 06:10:37 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1YEA2K-0008V5-RH for gllmg-musl@m.gmane.org; Thu, 22 Jan 2015 06:10:32 +0100 Original-Received: (qmail 32358 invoked by uid 550); 22 Jan 2015 05:10:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 32348 invoked from network); 22 Jan 2015 05:10:30 -0000 Content-Disposition: inline In-Reply-To: <54C05654.7000204@amacapital.net> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:6878 Archived-At: 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