DragonFly On-Line Manual Pages
TLS(2) DragonFly System Calls Manual TLS(2)
NAME
set_tls_area, get_tls_area -- kernel TLS (thread local storage) support
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/tls.h>
int
set_tls_area(int which, struct tls_info *info, size_t infosize);
int
get_tls_area(int which, struct tls_info *info, size_t infosize);
DESCRIPTION
The set_tls_area() system call creates an entry for the TLS facility
which representing thread local storage as specified by the info
structure. A descriptor representing the facility is returned, or -1 if
an error occurred. The facility may be cleared by specifying a NULL
pointer and an infosize of 0. The get_tls_area() system call retrieves
the requested TLS facility. A descriptor representing the facility is
returned, or -1 if an error occurred. If you simply want the descriptor
you may specify a NULL pointer and an infosize of 0.
The returned descriptor and the TLS mechanism is machine-dependent. On
IA32 three global segment descriptors are supported (0, 1, and 2) and
the %gs load value is returned.
The tls_info structure passed to set_tls_area() should first be zerod (to
remain compatible with future extensions) and then initialized.
struct tls_info {
void *base; /* base address of TLS area */
int size; /* size of TLS area in bytes */
};
The actual implementation of the area is machine-dependent. If the
kernel is unable to accommodate the supplied size it may create a larger
area. If the kernel is unable to accommodate the supplied base address
an error will be returned.
RETURN VALUES
A return value of 0 is returned on success, -1 on error.
EXAMPLES
/*
* Pseudo example showing how the TLS system calls work on IA32.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/tls.h>
int X;
static int getdata(int offset);
int
main(int ac, char **av)
{
int i;
int gs;
struct tls_info info;
info.base = &X;
info.size = sizeof(X);
if ((gs = set_tls_area(0, &info, sizeof(info))) < 0) {
perror("setarea");
exit(1);
}
printf("gs = %04x\n", gs);
__asm __volatile("mov %0,%%gs" : : "g" (gs) );
if (get_tls_area(0, &info, sizeof(info)) < 0) {
perror("getarea");
exit(1);
}
printf("%p/%d\n", info.base, info.size);
X = 1;
printf("should be 1: %d\n", getdata(0));
X = 2;
printf("should be 2: %d\n", getdata(0));
printf("this should fault:\n");
fflush(stdout);
getdata(4);
return(0);
}
static int
getdata(int offset)
{
int rv;
__asm __volatile("movl %%gs:(%0),%%eax; movl %%eax,%1" : "+r" (offset) : "m"
(rv) : "ax");
return (rv);
}
ERRORS
[ERANGE] The specified facility index, which, is not supported.
[EINVAL] An invalid parameter has been specified.
[ENOENT] (get_tls_area) The specified facility has not been
initialized with sys_set_tls_area().
SEE ALSO
umtx(2)
HISTORY
The set_tls_area(), and get_tls_area() function calls first appeared in
DragonFly 1.1.
DragonFly 5.5 February 21, 2005 DragonFly 5.5
TLS_CONFIG_SET_SES... DragonFly Library Functions Manual TLS_CONFIG_SET_SES...
NAME
tls_config_set_session_fd, tls_config_set_session_id,
tls_config_set_session_lifetime, tls_config_add_ticket_key -- configure
resuming of TLS handshakes
SYNOPSIS
#include <tls.h>
int
tls_config_set_session_fd(struct tls_config *config, int session_fd);
int
tls_config_set_session_id(struct tls_config *config,
const unsigned char *session_id, size_t len);
int
tls_config_set_session_lifetime(struct tls_config *config, int lifetime);
int
tls_config_add_ticket_key(struct tls_config *config, uint32_t keyrev,
unsigned char *key, size_t keylen);
DESCRIPTION
tls_config_set_session_fd() sets a file descriptor to be used to manage
data for TLS sessions (client only). The given file descriptor must be a
regular file and be owned by the current user, with permissions being
restricted to only allow the owner to read and write the file (0600). If
the file has a non-zero length, the client will attempt to read session
data from this file and resume the previous TLS session with the server.
Upon a successful handshake the file will be updated with current session
data, if available. The caller is responsible for closing this file
descriptor, after all TLS contexts that have been configured to use it
have been freed via tls_free().
tls_config_set_session_id() sets the session identifier that will be used
by the TLS server when sessions are enabled (server only). By default a
random value is used.
tls_config_set_session_lifetime() sets the lifetime to be used for TLS
sessions (server only). Session support is disabled if a lifetime of
zero is specified, which is the default.
tls_config_add_ticket_key() adds a key used for the encryption and
authentication of TLS tickets (server only). By default keys are gener-
ated and rotated automatically based on their lifetime. This function
should only be used to synchronise ticket encryption key across multiple
processes. Re-adding a known key will result in an error, unless it is
the most recently added key.
RETURN VALUES
These functions return 0 on success or -1 on error.
SEE ALSO
tls_accept_socket(3), tls_config_set_protocols(3), tls_init(3),
tls_load_file(3), tls_server(3)
HISTORY
tls_config_set_session_id(), tls_config_set_session_lifetime() and
tls_config_add_ticket_key() appeared in OpenBSD 6.1.
tls_config_set_session_fd() appeared in OpenBSD 6.3.
AUTHORS
Claudio Jeker <claudio@openbsd.org>
Joel Sing <jsing@openbsd.org>
DragonFly 5.5 February 10, 2018 DragonFly 5.5