Page 1 of 1

(Linux) set_tid_address vs set_thread_area?

Posted: Fri May 22, 2020 12:21 pm
by AndrewAPrice
What is the difference between the two linux syscalls set_tid_address and set_thread_area?

Which one (on x86-64 long mode) updates the fs register?

Re: (Linux) set_tid_address vs set_thread_area?

Posted: Fri May 22, 2020 1:30 pm
by Korona
arch_prctl sets the fs register.

Re: (Linux) set_tid_address vs set_thread_area?

Posted: Sun May 24, 2020 10:54 pm
by nullplan
To expand on Korona's answer: arch_prctl() can set FS on x86_64. set_thread_area() was the old system call for 32-bit applications to install a thread-local GDT segment that can point anywhere, and that you can then load yourself into whatever segment you wish. set_tid_address() is something else entirely. It sets an address meant to hold the thread's TID. When the thread exits, the kernel sets that address to 0 and performs a futex-wake on the address. This can be used to implement threading libraries. For instance, you can implement pthread_join() by having one thread wait on the TID address of the other thread.