1017246d0SDoug Rabson /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3e6209940SPedro F. Giffuni * 4017246d0SDoug Rabson * Copyright (c) 2004 Doug Rabson 5017246d0SDoug Rabson * All rights reserved. 6017246d0SDoug Rabson * 7017246d0SDoug Rabson * Redistribution and use in source and binary forms, with or without 8017246d0SDoug Rabson * modification, are permitted provided that the following conditions 9017246d0SDoug Rabson * are met: 10017246d0SDoug Rabson * 1. Redistributions of source code must retain the above copyright 11017246d0SDoug Rabson * notice, this list of conditions and the following disclaimer. 12017246d0SDoug Rabson * 2. Redistributions in binary form must reproduce the above copyright 13017246d0SDoug Rabson * notice, this list of conditions and the following disclaimer in the 14017246d0SDoug Rabson * documentation and/or other materials provided with the distribution. 15017246d0SDoug Rabson * 16017246d0SDoug Rabson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17017246d0SDoug Rabson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18017246d0SDoug Rabson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19017246d0SDoug Rabson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20017246d0SDoug Rabson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21017246d0SDoug Rabson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22017246d0SDoug Rabson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23017246d0SDoug Rabson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24017246d0SDoug Rabson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25017246d0SDoug Rabson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26017246d0SDoug Rabson * SUCH DAMAGE. 27017246d0SDoug Rabson */ 28017246d0SDoug Rabson 29017246d0SDoug Rabson /* 30017246d0SDoug Rabson * Semi-public interface from thread libraries to rtld for managing 31017246d0SDoug Rabson * TLS. 32017246d0SDoug Rabson */ 33017246d0SDoug Rabson 34017246d0SDoug Rabson #ifndef _RTLD_TLS_H_ 35017246d0SDoug Rabson #define _RTLD_TLS_H_ 36017246d0SDoug Rabson 37017246d0SDoug Rabson /* 38017246d0SDoug Rabson * Allocate a TLS block for a new thread. The memory allocated will 39017246d0SDoug Rabson * include 'tcbsize' bytes aligned to a 'tcbalign' boundary (in bytes) 40017246d0SDoug Rabson * for the thread library's private purposes. The location of the TCB 41017246d0SDoug Rabson * block is returned by this function. For architectures using 42017246d0SDoug Rabson * 'Variant I' TLS, the thread local storage follows the TCB, and for 43017246d0SDoug Rabson * 'Variant II', the thread local storage precedes it. For 448e0ff10dSWarner Losh * architectures using the 'Variant II' model (e.g. i386, amd64) the 458e0ff10dSWarner Losh * TCB must begin with two pointer fields which are used by rtld for 468e0ff10dSWarner Losh * its TLS implementation. For the 'Variant I' model, the TCB must 478e0ff10dSWarner Losh * begin with a single pointer field for rtld's implementation. 48017246d0SDoug Rabson * 49017246d0SDoug Rabson * If the value of 'oldtls' is non-NULL, the new TLS block will be 50017246d0SDoug Rabson * initialised using the values contained in 'oldtls' and 'oldtls' 51017246d0SDoug Rabson * will be freed. This is typically used when initialising a thread 52017246d0SDoug Rabson * library to migrate from using the initial bootstrap TLS block 53017246d0SDoug Rabson * created by rtld to one which contains suitable thread library 54017246d0SDoug Rabson * private data. 55017246d0SDoug Rabson * 56017246d0SDoug Rabson * The value returned from this function is suitable for installing 57017246d0SDoug Rabson * directly into the thread pointer register. 58017246d0SDoug Rabson */ 590c4f9ecdSKonstantin Belousov void *_rtld_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign) 600c4f9ecdSKonstantin Belousov __exported; 61017246d0SDoug Rabson 62017246d0SDoug Rabson /* 63017246d0SDoug Rabson * Free a TLS block allocated using _rtld_allocate_tls(). The tcbsize 64017246d0SDoug Rabson * and tcbalign parameters must be the same as those used to allocate 65017246d0SDoug Rabson * the block. 66017246d0SDoug Rabson */ 670c4f9ecdSKonstantin Belousov void _rtld_free_tls(void *tcb, size_t tcbsize, size_t tcbalign) __exported; 68017246d0SDoug Rabson 69017246d0SDoug Rabson #endif 70