xref: /freebsd/libexec/rtld-elf/i386/rtld_machdep.h (revision e5c3405ce80ade35223a7b6dc21296590cfb7980)
1d5b537d0SJohn Polstra /*-
2e6209940SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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>
366d5d786fSAlexander Kabaev 
37b5393d9fSDoug Rabson struct Struct_Obj_Entry;
38b5393d9fSDoug Rabson 
39d5b537d0SJohn Polstra /* Return the address of the .dynamic section in the dynamic linker. */
40d5b537d0SJohn Polstra #define rtld_dynamic(obj) \
41d5b537d0SJohn Polstra     ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
42d5b537d0SJohn Polstra 
43e35ddbe4SKonstantin Belousov Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
44e35ddbe4SKonstantin Belousov     const struct Struct_Obj_Entry *obj, const struct Struct_Obj_Entry *refobj,
45e35ddbe4SKonstantin Belousov     const Elf_Rel *rel);
46b5393d9fSDoug Rabson 
47b5393d9fSDoug Rabson #define make_function_pointer(def, defobj)	\
48b5393d9fSDoug Rabson 	((defobj)->relocbase + (def)->st_value)
49962fdc46SJohn Polstra 
5014a55adfSPeter Wemm #define call_initfini_pointer(obj, target) \
5114a55adfSPeter Wemm 	(((InitFunc)(target))())
5214a55adfSPeter Wemm 
5383aa9cc0SKonstantin Belousov #define call_init_pointer(obj, target) \
5483aa9cc0SKonstantin Belousov 	(((InitArrFunc)(target))(main_argc, main_argv, environ))
5583aa9cc0SKonstantin Belousov 
564352999eSKonstantin Belousov extern uint32_t cpu_feature;
574352999eSKonstantin Belousov extern uint32_t cpu_feature2;
584352999eSKonstantin Belousov extern uint32_t cpu_stdext_feature;
594352999eSKonstantin Belousov extern uint32_t cpu_stdext_feature2;
604352999eSKonstantin Belousov #define	call_ifunc_resolver(ptr) \
61903e0ffdSAlex Richardson 	(((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))(ptr))( \
624352999eSKonstantin Belousov 	    cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2))
634352999eSKonstantin Belousov 
64017246d0SDoug Rabson typedef struct {
65017246d0SDoug Rabson     unsigned long ti_module;
66017246d0SDoug Rabson     unsigned long ti_offset;
67017246d0SDoug Rabson } tls_index;
68017246d0SDoug Rabson 
690c4f9ecdSKonstantin Belousov void *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1))) __exported;
700c4f9ecdSKonstantin Belousov void *__tls_get_addr(tls_index *ti) __exported;
71017246d0SDoug Rabson 
72cb38d494SKonstantin Belousov #define	RTLD_DEFAULT_STACK_PF_EXEC	PF_X
73cb38d494SKonstantin Belousov #define	RTLD_DEFAULT_STACK_EXEC		PROT_EXEC
74cb38d494SKonstantin Belousov 
758fd53f45SWarner Losh #define md_abi_variant_hook(x)
768fd53f45SWarner Losh 
77*e5c3405cSKonstantin Belousov size_t calculate_first_tls_offset(size_t size, size_t align, size_t offset);
78*e5c3405cSKonstantin Belousov size_t calculate_tls_offset(size_t prev_offset, size_t prev_size, size_t size,
79*e5c3405cSKonstantin Belousov     size_t align, size_t offset);
80*e5c3405cSKonstantin Belousov size_t calculate_tls_end(size_t off, size_t size);
81d5b537d0SJohn Polstra #endif
82