AMD64_GET_FSBASE(2)

NAME
amd64_get_fsbase, amd64_set_fsbase - manage amd64 per-thread %fs base address

SYNOPSIS
#include <sys/types.h>
#include <machine/sysarch.h>
int
amd64_get_fsbase(void **base);
int
amd64_set_fsbase(void *base);

DESCRIPTION
amd64_get_fsbase() copies the current base address of the %fs segment into the memory referenced by base.

amd64_set_fsbase() sets the base address of the %fs segment to the address base.

The segment base address is local to each thread. The initial thread of a new process inherits its segment base address from the parent thread. __tfork(2) sets the initial segment base address for threads that it creates.

Note: Code using the amd64_get_fsbase() and amd64_set_fsbase() functions must be compiled using -lamd64.

RETURN VALUES
Upon successful completion, amd64_get_fsbase() and amd64_set_fsbase() return 0. Otherwise, a value of -1 is returned and the global variable errno is set to indicate the error.

ERRORS
amd64_get_fsbase() will fail if:

[EFAULT]
    base points outside the process's allocated address space.

SEE ALSO
__tfork(2), fork(2)

WARNING
The ELF Thread-Local Storage ABI reserves %fs for its own use and requires that the dynamic linker and thread library set it to reference data-structures internal to and shared between them. Programs should use the __thread storage class keyword instead of using these calls. To be maximally portable, programs that require per-thread data should use the pthread_key_create() interface.