1.\" $OpenBSD: __get_tcb.2,v 1.4 2012/04/12 14:25:57 deraadt Exp $ 2.\" 3.\" Copyright (c) 2011 Philip Guenther <guenther@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: April 12 2012 $ 18.Dt __GET_TCB 2 19.Os 20.Sh NAME 21.Nm __get_tcb , 22.Nm __set_tcb 23.Nd get and set the address of the thread control block of the current thread 24.Sh SYNOPSIS 25.Ft void * 26.Fn __get_tcb "void" 27.Ft void 28.Fn __set_tcb "void *" 29.Sh DESCRIPTION 30The 31.Fn __get_tcb 32and 33.Fn __set_tcb 34functions are for use by librthread and other parts of the system 35runtime to retrieve and set the address of the current thread's 36thread control block (TCB). 37This is used to locate per-thread data such as 38.Va errno . 39Each kernel-level thread in a process has a separate value for this 40address, which can be obtained and changed via these system calls. 41New threads (including the first thread of a new process) created using 42.Xr fork 2 , 43.Xr vfork 2 , 44or 45.Xr __tfork 2 , 46inherit the TCB address of the thread that created them. 47.Xr execve 2 48resets it to zero. 49.Pp 50On some platforms, this address is also directly mapped to a CPU 51register which can be accessed from userspace. 52.Sh RETURN VALUES 53.Fn __get_tcb 54returns the address of the thread control block of the current thread. 55.Sh SEE ALSO 56.Xr __tfork 2 57.Sh HISTORY 58The 59.Fn __get_tcb 60and 61.Fn __set_tcb 62system calls appeared in 63.Ox 5.1 . 64