xref: /freebsd/libexec/rtld-elf/i386/rtld_machdep.h (revision dd4155bec744acf2ebfd037f7719c4aed9283a73)
1d5b537d0SJohn Polstra /*-
24d846d26SWarner 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  */
28d5b537d0SJohn Polstra 
29d5b537d0SJohn Polstra #ifndef RTLD_MACHDEP_H
30d5b537d0SJohn Polstra #define RTLD_MACHDEP_H	1
31d5b537d0SJohn Polstra 
326d5d786fSAlexander Kabaev #include <sys/types.h>
336d5d786fSAlexander Kabaev #include <machine/atomic.h>
348bcdb144SJohn Baldwin #include <machine/tls.h>
356d5d786fSAlexander Kabaev 
36b5393d9fSDoug Rabson struct Struct_Obj_Entry;
37b5393d9fSDoug Rabson 
3806db20ffSAndrew Turner #define	MD_OBJ_ENTRY
3906db20ffSAndrew Turner 
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 
44*dd4155beSAndrew Turner /* No arch-specific dynamic tags */
45*dd4155beSAndrew Turner #define	arch_digest_dynamic(obj, dynp)	false
46*dd4155beSAndrew Turner 
47d8925a5fSAndrew Turner /* No architecture specific notes */
48d8925a5fSAndrew Turner #define	arch_digest_note(obj, note)	false
49d8925a5fSAndrew Turner 
50e35ddbe4SKonstantin Belousov Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
51e35ddbe4SKonstantin Belousov     const struct Struct_Obj_Entry *obj, const struct Struct_Obj_Entry *refobj,
52e35ddbe4SKonstantin Belousov     const Elf_Rel *rel);
53b5393d9fSDoug Rabson 
54b5393d9fSDoug Rabson #define make_function_pointer(def, defobj)	\
55b5393d9fSDoug Rabson 	((defobj)->relocbase + (def)->st_value)
56962fdc46SJohn Polstra 
5714a55adfSPeter Wemm #define call_initfini_pointer(obj, target) \
5814a55adfSPeter Wemm 	(((InitFunc)(target))())
5914a55adfSPeter Wemm 
6083aa9cc0SKonstantin Belousov #define call_init_pointer(obj, target) \
6183aa9cc0SKonstantin Belousov 	(((InitArrFunc)(target))(main_argc, main_argv, environ))
6283aa9cc0SKonstantin Belousov 
634352999eSKonstantin Belousov extern uint32_t cpu_feature;
644352999eSKonstantin Belousov extern uint32_t cpu_feature2;
654352999eSKonstantin Belousov extern uint32_t cpu_stdext_feature;
664352999eSKonstantin Belousov extern uint32_t cpu_stdext_feature2;
674352999eSKonstantin Belousov #define	call_ifunc_resolver(ptr) \
68903e0ffdSAlex Richardson 	(((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))(ptr))( \
694352999eSKonstantin Belousov 	    cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2))
704352999eSKonstantin Belousov 
71017246d0SDoug Rabson typedef struct {
72017246d0SDoug Rabson     unsigned long ti_module;
73017246d0SDoug Rabson     unsigned long ti_offset;
74017246d0SDoug Rabson } tls_index;
75017246d0SDoug Rabson 
760c4f9ecdSKonstantin Belousov void *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1))) __exported;
770c4f9ecdSKonstantin Belousov void *__tls_get_addr(tls_index *ti) __exported;
78017246d0SDoug Rabson 
798fd53f45SWarner Losh #define md_abi_variant_hook(x)
808fd53f45SWarner Losh 
81e5c3405cSKonstantin Belousov size_t calculate_first_tls_offset(size_t size, size_t align, size_t offset);
82e5c3405cSKonstantin Belousov size_t calculate_tls_offset(size_t prev_offset, size_t prev_size, size_t size,
83e5c3405cSKonstantin Belousov     size_t align, size_t offset);
84d5b537d0SJohn Polstra #endif
85