1178476Sjb/*-
2178476Sjb * Copyright (c) 1999, 2000 John D. Polstra.
3178476Sjb * All rights reserved.
4178476Sjb *
5178476Sjb * Redistribution and use in source and binary forms, with or without
6178476Sjb * modification, are permitted provided that the following conditions
7178476Sjb * are met:
8178476Sjb * 1. Redistributions of source code must retain the above copyright
9178476Sjb *    notice, this list of conditions and the following disclaimer.
10178476Sjb * 2. Redistributions in binary form must reproduce the above copyright
11178476Sjb *    notice, this list of conditions and the following disclaimer in the
12178476Sjb *    documentation and/or other materials provided with the distribution.
13178476Sjb *
14178476Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15178476Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16178476Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17178476Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18178476Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19178476Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20178476Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21178476Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22178476Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23178476Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24178476Sjb * SUCH DAMAGE.
25178476Sjb *
26178476Sjb * $FreeBSD: releng/11.0/libexec/rtld-elf/i386/rtld_machdep.h 293066 2016-01-03 04:32:02Z imp $
27178476Sjb */
28178476Sjb
29178476Sjb#ifndef RTLD_MACHDEP_H
30178476Sjb#define RTLD_MACHDEP_H	1
31178476Sjb
32178476Sjb#include <sys/types.h>
33178476Sjb#include <machine/atomic.h>
34178476Sjb
35178476Sjbstruct Struct_Obj_Entry;
36178476Sjb
37178476Sjb/* Return the address of the .dynamic section in the dynamic linker. */
38178476Sjb#define rtld_dynamic(obj) \
39178476Sjb    ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
40178476Sjb
41178476Sjb/* Fixup the jump slot at "where" to transfer control to "target". */
42178476Sjbstatic inline Elf_Addr
43178476Sjbreloc_jmpslot(Elf_Addr *where, Elf_Addr target,
44178476Sjb	      const struct Struct_Obj_Entry *obj,
45178476Sjb	      const struct Struct_Obj_Entry *refobj, const Elf_Rel *rel)
46178476Sjb{
47178476Sjb#ifdef dbg
48178476Sjb    dbg("reloc_jmpslot: *%p = %p", (void *)(where),
49178476Sjb	(void *)(target));
50178476Sjb#endif
51178476Sjb    (*(Elf_Addr *)(where) = (Elf_Addr)(target));
52178476Sjb    return target;
53178476Sjb}
54
55#define make_function_pointer(def, defobj) \
56	((defobj)->relocbase + (def)->st_value)
57
58#define call_initfini_pointer(obj, target) \
59	(((InitFunc)(target))())
60
61#define call_init_pointer(obj, target) \
62	(((InitArrFunc)(target))(main_argc, main_argv, environ))
63
64#define round(size, align) \
65	(((size) + (align) - 1) & ~((align) - 1))
66#define calculate_first_tls_offset(size, align) \
67	round(size, align)
68#define calculate_tls_offset(prev_offset, prev_size, size, align) \
69	round((prev_offset) + (size), align)
70#define calculate_tls_end(off, size) 	(off)
71
72typedef struct {
73    unsigned long ti_module;
74    unsigned long ti_offset;
75} tls_index;
76
77void *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1))) __exported;
78void *__tls_get_addr(tls_index *ti) __exported;
79
80#define	RTLD_DEFAULT_STACK_PF_EXEC	PF_X
81#define	RTLD_DEFAULT_STACK_EXEC		PROT_EXEC
82
83#define md_abi_variant_hook(x)
84
85#endif
86