From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6883 Path: news.gmane.org!not-for-mail From: Andy Lutomirski Newsgroups: gmane.linux.lib.musl.general Subject: Re: Custom __set_thread_area for ARM Date: Tue, 27 Jan 2015 15:32:27 -0800 Message-ID: <54C8200B.8060102@mit.edu> References: <20150114030946.GL4574@brightrain.aerifal.cx> <54C05654.7000204@amacapital.net> <20150122051017.GL4574@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1422433969 32710 80.91.229.3 (28 Jan 2015 08:32:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2015 08:32:49 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6896-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jan 28 09:32:49 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 1YGO3I-0004d6-2F for gllmg-musl@m.gmane.org; Wed, 28 Jan 2015 09:32:44 +0100 Original-Received: (qmail 24355 invoked by uid 550); 27 Jan 2015 23:32:42 -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 24331 invoked from network); 27 Jan 2015 23:32:41 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=fWEPzDt/SUK6LPRMrIG/PA8bvxhpCEc+5FzlAqCNweI=; b=bhIYnwnbpvxbIsKj9jp3HYr8vEFbf0bSIWcdaT5cSBCCwzTXcacTMcbGI8HjiNMScP pW6altMsmYOjOZrlqDaTAhV5Fbixyvk3YodZS0hCLGT2YvrclA8xvNeVpA59f1Et7sz+ iN5rMjBryQMAghKm4NNjrCtJFLJHBzlrGHJbVffNGjEFruBgMm1aWn1rIPM07hNHBIy8 KuZguCwC8U2G6x0wsvarbdT1djEywAOAWvLAh9WV/HXb+uQnekyNGcgI7hG6I+wFbKXw CxbvrAfD1eHKkrlQ2PJNG4uOFBCdAhntb2gvHXZDSwU47v1n2605hhbgD1nLEprlLiGJ sNsQ== X-Gm-Message-State: ALoCoQkxbp/mjGFVxJwxvD/7IJvgUiR26fL+pZcLf0SxmFmE2oD3CTKCjqaz4cOjj5rx13PitY9T X-Received: by 10.229.114.137 with SMTP id e9mr7368263qcq.0.1422401549193; Tue, 27 Jan 2015 15:32:29 -0800 (PST) X-Google-Original-From: Andy Lutomirski User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: <20150122051017.GL4574@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:6883 Archived-At: 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