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