set_thread_area(2) System Calls Manual set_thread_area(2) get_thread_area, set_thread_area - C (libc, -lc) #include /* SYS_* */ #include #if defined __i386__ || defined __x86_64__ # include /* struct user_desc */ int syscall(SYS_get_thread_area, struct user_desc *u_info); int syscall(SYS_set_thread_area, struct user_desc *u_info); #elif defined __m68k__ int syscall(SYS_get_thread_area); int syscall(SYS_set_thread_area, unsigned long tp); #elif defined __mips__ || defined __csky__ int syscall(SYS_set_thread_area, unsigned long addr); #endif : glibc , syscall(2). These calls provide architecture-specific support for a thread-local storage implementation. At the moment, set_thread_area() is available on m68k, MIPS, C-SKY, and x86 (both 32-bit and 64-bit variants); get_thread_area() is available on m68k and x86. On m68k, MIPS and C-SKY, set_thread_area() allows storing an arbitrary pointer (provided in the tp argument on m68k and in the addr argument on MIPS and C-SKY) in the kernel data structure associated with the calling thread; this pointer can later be retrieved using get_thread_area() (see also NOTES for information regarding obtaining the thread pointer on MIPS). x86 Linux (GDT). GDT Intel Software Developer's Manual AMD Architecture Programming Manual. : struct user_desc { unsigned int entry_number; unsigned int base_addr; unsigned int limit; unsigned int seg_32bit:1; unsigned int contents:2; unsigned int read_exec_only:1; unsigned int limit_in_pages:1; unsigned int seg_not_present:1; unsigned int useable:1; #ifdef __x86_64__ unsigned int lm:1; #endif }; get_thread_area() GDT, u_info->entry_number u_info. set_thread_area() TLS GDT. TLS, set_thread_area(), u_info->entry_number, . , set_thread_area() TLS, u_info, TLS . set_thread_area() entry_number -1, TLS. set_thread_area() TLS, u_info->entry_number , . user_desc <<>>, read_exec_only seg_not_present 1, 0. <<>> set_thread_area(), TLS . . Linux 3.19, set_thread_area() , 16- , . On x86, these system calls return 0 on success, and -1 on failure, with errno set to indicate the error. On C-SKY, MIPS and m68k, set_thread_area() always returns 0. On m68k, get_thread_area() returns the thread area pointer value (previously set via set_thread_area()). EFAULT u_info . EINVAL u_info->entry_number . ENOSYS get_thread_area() set_thread_area() 64- . ESRCH (set_thread_area()) TLS. Linux. set_thread_area() Linux 2.5.29. get_thread_area() Linux 2.5.32. These system calls are generally intended for use only by threading libraries. x86 arch_prctl(2) set_thread_area(). arch_prctl(2). , arch_prctl(2) 64- . MIPS : rdhwr dest, $29 . 64- Linux 3.19, user_desc, , ( modify_ldt(2)). , TLS memset(3) user_desc, , read_exec_only seg_not_present. Linux 3.19, user_desc, entry_number, TLS, . Linux 3.19, DS ES TLS. arch_prctl(2), modify_ldt(2), ptrace(2) (PTRACE_GET_THREAD_AREA and PTRACE_SET_THREAD_AREA) () Alexander Golubev , Azamat Hackimov , Hotellook, Nikita , Spiros Georgaras , Vladislav , Yuri Kozlov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 2 2024 . set_thread_area(2)