Hello,
I will try to answer with my limited knowledge of the Linux kernel
internals. It would be nice if kernel gurus could infirm or confirm my
explanations.
Mulyadi Santosa wrote:
1. What is the purpose of allocating new LDT entry? Is it to provide new
segment for freshly created thread to store its thread-local data?
A new LDT entry is allocated for each TLS (Thread Local Storage) because
we want to allow each thread to access its TLS regardless of the storage
address of the data in memory.
The 'gs' segment register always point to the LDT segment that
correspond to the TLS of the current. So by accessing %gs:0, a thread
can access the first word of its TLS, without knowing exactly where it
is in memory.
2. Is the format of LDT entry 100% similar with GDT entry? If yes, what
is the advantage of using LDT for this threading purpose instead of
GDT?
As far as I remember they are identical, or at least very similar. See
the reference provided by Christophe Lucas for more information.
GDT is the Global Descriptor Table, while LDT is the local descriptor
table. It seems coherent to use the GDT for global segments and the LDT
for local (per-task) segments.
4. I read somewhere on the Internet that gs register is used to point on
the currently used LDT entry related with currently running thread. Is
this just a convention which is used inside the libpthread? or is there
other explanation on why using gs register for this purpose?
I think this is just a convention used by the Linux implementation of TLS.
You'll find more information about TLS at
http://people.redhat.com/drepper/tls.pdf. You can also read
http://people.redhat.com/drepper/nptl-design.pdf, and particularly
section 6.
Sincerly,
Thomas
--
Thomas Petazzoni
thomas.petazzoni@xxxxxxxx
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/