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?
(Linux) set_tid_address vs set_thread_area?
- AndrewAPrice
- Member
- Posts: 2300
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Re: (Linux) set_tid_address vs set_thread_area?
arch_prctl sets the fs register.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Re: (Linux) set_tid_address vs set_thread_area?
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.
Carpe diem!