[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: where to set the initial value to %gs ?



Thanks for so much kind help and sorry to ask such a junior question here.
Actually I spent quite a lot of time on it. :p
Let me summarize %gs usage to share between newbies like me.  :)

%gs  usage

0. What %gs contains
     It contains the segment selector of the thread GDT description. The
content of %gs remains the same when the pthread library initializes. While
the GDT description varies with different thread, its base adress equals to
struct pthread pointer address.

1. How to initialize %gs
call stack 
__pthread_initialize_minimal()  [nptl/init.c]
    --> __libc_setup_tls() [libc-tls.c]
           --> TLS_INIT_TP() [nptl/sysdeps/i386/tls.h]
__pthread_initialize_minimal() will be called only once when the pthread
library initlize. 

2. How to access %gs
During pthread_create(), %gs and struct pthread *pd composes a
user_desc_init variable. The variable will be transfered to sys_clone() ->
do_fork()->copy_process()->copy_thread(), the content will be copied into
the new thread's task_struct member  thread.tls_array. Then it leaves to
kernel. 

During kernel::__switch_to(), the kernel will backup original %gs and load
new process/thread %gs.

We could use %gs:offset_of_member to access member of struct pthread. And
there are many useful macroes in nptl/sysdeps/i386/tls.h, such as
THREAD_SELF, THREAD_GETMEM,...

any mistake, pls let me know. thanks :)

boris

-----Original Message-----
From: Ulrich Drepper [mailto:drepper redhat com]
Sent: 2002?11?27? 17:08
To: phil-list redhat com
Subject: Re: where to set the initial value to %gs ?


Hu, Boris wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> Do I miss sth? Thanks a lot.

Instead of asking questions you should invest some time in understanding
how the kernel and the ABI works.  %gs only has to be set once because
the value never changes and clones inherit the register content.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE95Itc2ijCOnn/RHQRAgUTAKCELW8h4Y5uJyHPq0usKQSCM1EBbwCgi0tO
ZHTD7dImi8MYTiqJOzPVzTM=
=UBbs
-----END PGP SIGNATURE-----



-- 
Phil-list mailing list
Phil-list redhat com
https://listman.redhat.com/mailman/listinfo/phil-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]