xref: /openbsd/lib/libarch/i386/i386_get_gsbase.2 (revision 9b7c3dbb)
1.\"	$OpenBSD: i386_get_gsbase.2,v 1.5 2016/03/30 06:58:06 jmc Exp $
2.\"	$NetBSD: i386_get_ioperm.2,v 1.3 1996/02/27 22:57:17 jtc Exp $
3.\"
4.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by John T. Kohl and Charles M. Hannum.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
23.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE.
30.\"
31.Dd $Mdocdate: March 30 2016 $
32.Dt I386_GET_GSBASE 2 i386
33.Os
34.Sh NAME
35.Nm i386_get_gsbase ,
36.Nm i386_set_gsbase
37.Nd manage i386 per-thread %gs base address
38.Sh SYNOPSIS
39.In sys/types.h
40.In machine/sysarch.h
41.Ft int
42.Fn i386_get_gsbase "void **base"
43.Ft int
44.Fn i386_set_gsbase "void *base"
45.Sh DESCRIPTION
46.Fn i386_get_gsbase
47copies the current base address of the segment that, by default,
48is referenced by the %gs selector into the memory referenced by
49.Fa base .
50.Pp
51.Fn i386_set_gsbase
52sets the base address of the segment that, by default, is referenced
53by %gs to the address
54.Fa base .
55.Pp
56The segment base address is local to each thread.
57The initial thread of a new process inherits its segment base address
58from the parent thread.
59.Xr __tfork 3
60sets the initial segment base address for threads that it creates.
61.Pp
62.Sy Note:
63Code using the
64.Fn i386_get_gsbase
65and
66.Fn i386_set_gsbase
67functions must be compiled using
68.Cm -li386 .
69.Sh RETURN VALUES
70Upon successful completion,
71.Fn i386_get_gsbase
72and
73.Fn i386_set_gsbase
74return 0.
75Otherwise, a value of \-1 is returned and the global variable
76.Va errno
77is set to indicate the error.
78.Sh ERRORS
79.Fn i386_get_gsbase
80will fail if:
81.Bl -tag -width [EINVAL]
82.It Bq Er EFAULT
83.Fa base
84points outside the process's allocated address space.
85.El
86.Sh SEE ALSO
87.Xr fork 2 ,
88.Xr __tfork 3
89.Rs
90.%A Intel
91.%T i386 Microprocessor Programmer's Reference Manual
92.Re
93.Sh WARNING
94The ELF Thread-Local Storage ABI reserves %gs for its own use and
95requires that the dynamic linker and thread library set it to
96reference data-structures internal to and shared between them.
97Programs should use the __thread storage class keyword instead of
98using these calls.
99To be maximally portable,
100programs that require per-thread data should use the
101.Fn pthread_key_create
102interface.
103