xref: /freebsd/libexec/rtld-elf/i386/rtld_machdep.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1d5b537d0SJohn Polstra /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e6209940SPedro F. Giffuni  *
4630df077SJohn Polstra  * Copyright (c) 1999, 2000 John D. Polstra.
5d5b537d0SJohn Polstra  * All rights reserved.
6d5b537d0SJohn Polstra  *
7d5b537d0SJohn Polstra  * Redistribution and use in source and binary forms, with or without
8d5b537d0SJohn Polstra  * modification, are permitted provided that the following conditions
9d5b537d0SJohn Polstra  * are met:
10d5b537d0SJohn Polstra  * 1. Redistributions of source code must retain the above copyright
11d5b537d0SJohn Polstra  *    notice, this list of conditions and the following disclaimer.
12d5b537d0SJohn Polstra  * 2. Redistributions in binary form must reproduce the above copyright
13d5b537d0SJohn Polstra  *    notice, this list of conditions and the following disclaimer in the
14d5b537d0SJohn Polstra  *    documentation and/or other materials provided with the distribution.
15d5b537d0SJohn Polstra  *
16d5b537d0SJohn Polstra  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17d5b537d0SJohn Polstra  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18d5b537d0SJohn Polstra  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19d5b537d0SJohn Polstra  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20d5b537d0SJohn Polstra  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21d5b537d0SJohn Polstra  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22d5b537d0SJohn Polstra  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23d5b537d0SJohn Polstra  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24d5b537d0SJohn Polstra  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25d5b537d0SJohn Polstra  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26d5b537d0SJohn Polstra  * SUCH DAMAGE.
27d5b537d0SJohn Polstra  *
287f3dea24SPeter Wemm  * $FreeBSD$
29d5b537d0SJohn Polstra  */
30d5b537d0SJohn Polstra 
31d5b537d0SJohn Polstra #ifndef RTLD_MACHDEP_H
32d5b537d0SJohn Polstra #define RTLD_MACHDEP_H	1
33d5b537d0SJohn Polstra 
346d5d786fSAlexander Kabaev #include <sys/types.h>
356d5d786fSAlexander Kabaev #include <machine/atomic.h>
368bcdb144SJohn Baldwin #include <machine/tls.h>
376d5d786fSAlexander Kabaev 
38b5393d9fSDoug Rabson struct Struct_Obj_Entry;
39b5393d9fSDoug Rabson 
40d5b537d0SJohn Polstra /* Return the address of the .dynamic section in the dynamic linker. */
41d5b537d0SJohn Polstra #define rtld_dynamic(obj) \
42d5b537d0SJohn Polstra     ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
43d5b537d0SJohn Polstra 
44e35ddbe4SKonstantin Belousov Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
45e35ddbe4SKonstantin Belousov     const struct Struct_Obj_Entry *obj, const struct Struct_Obj_Entry *refobj,
46e35ddbe4SKonstantin Belousov     const Elf_Rel *rel);
47b5393d9fSDoug Rabson 
48b5393d9fSDoug Rabson #define make_function_pointer(def, defobj)	\
49b5393d9fSDoug Rabson 	((defobj)->relocbase + (def)->st_value)
50962fdc46SJohn Polstra 
5114a55adfSPeter Wemm #define call_initfini_pointer(obj, target) \
5214a55adfSPeter Wemm 	(((InitFunc)(target))())
5314a55adfSPeter Wemm 
5483aa9cc0SKonstantin Belousov #define call_init_pointer(obj, target) \
5583aa9cc0SKonstantin Belousov 	(((InitArrFunc)(target))(main_argc, main_argv, environ))
5683aa9cc0SKonstantin Belousov 
574352999eSKonstantin Belousov extern uint32_t cpu_feature;
584352999eSKonstantin Belousov extern uint32_t cpu_feature2;
594352999eSKonstantin Belousov extern uint32_t cpu_stdext_feature;
604352999eSKonstantin Belousov extern uint32_t cpu_stdext_feature2;
614352999eSKonstantin Belousov #define	call_ifunc_resolver(ptr) \
62903e0ffdSAlex Richardson 	(((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))(ptr))( \
634352999eSKonstantin Belousov 	    cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2))
644352999eSKonstantin Belousov 
65017246d0SDoug Rabson typedef struct {
66017246d0SDoug Rabson     unsigned long ti_module;
67017246d0SDoug Rabson     unsigned long ti_offset;
68017246d0SDoug Rabson } tls_index;
69017246d0SDoug Rabson 
700c4f9ecdSKonstantin Belousov void *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1))) __exported;
710c4f9ecdSKonstantin Belousov void *__tls_get_addr(tls_index *ti) __exported;
72017246d0SDoug Rabson 
738fd53f45SWarner Losh #define md_abi_variant_hook(x)
748fd53f45SWarner Losh 
75e5c3405cSKonstantin Belousov size_t calculate_first_tls_offset(size_t size, size_t align, size_t offset);
76e5c3405cSKonstantin Belousov size_t calculate_tls_offset(size_t prev_offset, size_t prev_size, size_t size,
77e5c3405cSKonstantin Belousov     size_t align, size_t offset);
78d5b537d0SJohn Polstra #endif
79