15d00c5a6SKonstantin Belousov /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35d00c5a6SKonstantin Belousov * 45d00c5a6SKonstantin Belousov * Copyright (c) 2019 The FreeBSD Foundation 55d00c5a6SKonstantin Belousov * 65d00c5a6SKonstantin Belousov * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 75d00c5a6SKonstantin Belousov * under sponsorship from the FreeBSD Foundation. 85d00c5a6SKonstantin Belousov * 95d00c5a6SKonstantin Belousov * Redistribution and use in source and binary forms, with or without 105d00c5a6SKonstantin Belousov * modification, are permitted provided that the following conditions 115d00c5a6SKonstantin Belousov * are met: 125d00c5a6SKonstantin Belousov * 1. Redistributions of source code must retain the above copyright 135d00c5a6SKonstantin Belousov * notice, this list of conditions and the following disclaimer. 145d00c5a6SKonstantin Belousov * 2. Redistributions in binary form must reproduce the above copyright 155d00c5a6SKonstantin Belousov * notice, this list of conditions and the following disclaimer in the 165d00c5a6SKonstantin Belousov * documentation and/or other materials provided with the distribution. 175d00c5a6SKonstantin Belousov * 185d00c5a6SKonstantin Belousov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 195d00c5a6SKonstantin Belousov * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 205d00c5a6SKonstantin Belousov * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 215d00c5a6SKonstantin Belousov * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 225d00c5a6SKonstantin Belousov * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 235d00c5a6SKonstantin Belousov * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 245d00c5a6SKonstantin Belousov * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 255d00c5a6SKonstantin Belousov * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 265d00c5a6SKonstantin Belousov * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 275d00c5a6SKonstantin Belousov * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 285d00c5a6SKonstantin Belousov * SUCH DAMAGE. 295d00c5a6SKonstantin Belousov * 305d00c5a6SKonstantin Belousov * $FreeBSD$ 315d00c5a6SKonstantin Belousov */ 325d00c5a6SKonstantin Belousov 335d00c5a6SKonstantin Belousov #ifndef _LIBC_I386_STATIC_TLS_H 345d00c5a6SKonstantin Belousov #define _LIBC_I386_STATIC_TLS_H 355d00c5a6SKonstantin Belousov 365d00c5a6SKonstantin Belousov static __inline uintptr_t 375d00c5a6SKonstantin Belousov _libc_get_static_tls_base(size_t offset) 385d00c5a6SKonstantin Belousov { 395d00c5a6SKonstantin Belousov uintptr_t tlsbase; 405d00c5a6SKonstantin Belousov 415d00c5a6SKonstantin Belousov __asm __volatile("movl %%gs:0, %0" : "=r" (tlsbase)); 425d00c5a6SKonstantin Belousov tlsbase -= offset; 435d00c5a6SKonstantin Belousov return (tlsbase); 445d00c5a6SKonstantin Belousov } 455d00c5a6SKonstantin Belousov 465d00c5a6SKonstantin Belousov #endif 47