xref: /openbsd-src/lib/libc/sys/__get_tcb.2 (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1.\" $OpenBSD: __get_tcb.2,v 1.6 2016/03/30 06:58:06 jmc 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: March 30 2016 $
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 libpthread and other parts of the C
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.
41.Pp
42The initial thread of a new process created using
43.Xr fork 2
44or
45.Xr vfork 2
46inherits the TCB address of the thread that created it.
47A thread created using
48.Xr __tfork 3
49starts with the TCB address specified in that call.
50.Xr execve 2
51resets the thread's TCB address to zero.
52.Pp
53On some platforms, this address is also directly mapped to a CPU
54register which can be accessed from userspace.
55.Sh RETURN VALUES
56.Fn __get_tcb
57returns the address of the thread control block of the current thread.
58.Sh SEE ALSO
59.Xr __tfork 3
60.Sh HISTORY
61The
62.Fn __get_tcb
63and
64.Fn __set_tcb
65system calls appeared in
66.Ox 5.1 .
67