OpenBSD manual page server

Manual Page Search Parameters

__GET_TCB(2) System Calls Manual __GET_TCB(2)

__get_tcb, __set_tcbget or set the address of the thread control block of the current thread

void *
__get_tcb(void);

void
__set_tcb(void *);

The () and () 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 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.

The initial thread of a new process created using fork(2) or vfork(2) inherits the TCB address of the thread that created it. A thread created using __tfork(3) starts with the TCB address specified in that call. execve(2) resets the thread's TCB address to zero.

On some platforms, this address is also directly mapped to a CPU register which can be accessed from userspace.

__get_tcb() returns the address of the thread control block of the current thread.

__tfork(3)

The __get_tcb() and __set_tcb() system calls appeared in OpenBSD 5.1.

February 22, 2023 OpenBSD-current