mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Markus Wichmann <nullplan@gmx.net>
To: musl@lists.openwall.com
Subject: Re: [PATCH] Add comments to i386 assembly source
Date: Mon, 1 Jan 2018 20:52:24 +0100	[thread overview]
Message-ID: <20180101195224.tpkl5g5w66rzwzz3@voyager> (raw)
In-Reply-To: <20171231154926.GG1627@brightrain.aerifal.cx>

On Sun, Dec 31, 2017 at 10:49:26AM -0500, Rich Felker wrote:
> I don't follow your reasoning here. Where are you getting the possible
> range of %gs from? If __clone is called with flags relevant to thread
> creation, %gs is necessarily a GDT entry. The LDT stuff in i386's
> __set_thread_area is only used to provide a working %gs for
> single-threaded processes on ancient kernels that lack thread support;
> in this case pthread_create always fails without calling __clone.
> 

First of all, happy new year everybody.

The range of GS is rather simple: GS is a word in Intel-lingo, i.e. 16
bits, so that sets its range. Nothing else limits it down any way
further. Not the interpretation of it (there are 13 bits for selector
index, so enough for 8192 selector entries), not GDT size (the GDTR can
hold a size of at most 65535 bytes, which is enough for 8192 selector
entries if each entry is 8 bytes), not the ABI (kernel returns GDT index
as int), nor the API (set_thread_area(2) is underdocumented, anyway).

Now, __set_thread_area() for i386 only makes sense if Linux has a
different GDT for each thread: In the entire code, you make sure to only
allocate a single TLS array index for the whole process runtime, which
would be nonsense if the GDT were distributed any further. In that case,
exceeding twenty segments would be quite a feat, never mind two hundred.

Also, the thing about the LDT not being used except on kernels that
don't have threading, that should be documented as well. Solves the
question I had in the OP of this thread nicely.

> Thank you and Markus for reminding me why some comments would help
> here. :-)
> 

You're welcome. :-)

Ciao,
Markus


  reply	other threads:[~2018-01-01 19:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-23  9:45 Markus Wichmann
2017-12-31  4:15 ` John Reiser
2017-12-31  6:54   ` Markus Wichmann
2017-12-31 15:49   ` Rich Felker
2018-01-01 19:52     ` Markus Wichmann [this message]
2018-01-01 22:57       ` John Reiser
2018-01-02  1:49         ` Rich Felker
2018-01-02  3:15           ` John Reiser
2018-01-02 19:49             ` Rich Felker
2018-01-02 18:24           ` a third bug in musl clone() John Reiser
2018-01-02 19:58             ` Rich Felker
2018-01-02 22:09               ` Florian Weimer
2018-01-03  2:51                 ` 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=20180101195224.tpkl5g5w66rzwzz3@voyager \
    --to=nullplan@gmx.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).