I386_GET_GSBASE(2)

NAME
i386_get_gsbase, i386_set_gsbase - manage i386 per-thread %gs base address

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

DESCRIPTION
i386_get_gsbase() copies the current base address of the segment that, by default, is referenced by the %gs selector into the memory referenced by base.

i386_set_gsbase() sets the base address of the segment that, by default, is referenced by %gs 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(3) sets the initial segment base address for threads that it creates.

Note: Code using the i386_get_gsbase() and i386_set_gsbase() functions must be compiled using -li386.

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

ERRORS
i386_get_gsbase() will fail if:

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

SEE ALSO
fork(2), __tfork(3) Intel, i386 Microprocessor Programmer's Reference Manual.

WARNING
The ELF Thread-Local Storage ABI reserves %gs 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.