(Linux) set_tid_address vs set_thread_area?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
AndrewAPrice
Member
Member
Posts: 2300
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

(Linux) set_tid_address vs set_thread_area?

Post 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?
My OS is Perception.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: (Linux) set_tid_address vs set_thread_area?

Post by Korona »

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].
nullplan
Member
Member
Posts: 1792
Joined: Wed Aug 30, 2017 8:24 am

Re: (Linux) set_tid_address vs set_thread_area?

Post 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.
Carpe diem!
Post Reply