145501Sjdp/*-
262801Sjdp * Copyright (c) 1999, 2000 John D. Polstra.
345501Sjdp * All rights reserved.
445501Sjdp *
545501Sjdp * Redistribution and use in source and binary forms, with or without
645501Sjdp * modification, are permitted provided that the following conditions
745501Sjdp * are met:
845501Sjdp * 1. Redistributions of source code must retain the above copyright
945501Sjdp *    notice, this list of conditions and the following disclaimer.
1045501Sjdp * 2. Redistributions in binary form must reproduce the above copyright
1145501Sjdp *    notice, this list of conditions and the following disclaimer in the
1245501Sjdp *    documentation and/or other materials provided with the distribution.
1345501Sjdp *
1445501Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1545501Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1645501Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1745501Sjdp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1845501Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1945501Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2045501Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2145501Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2245501Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2345501Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2445501Sjdp * SUCH DAMAGE.
2545501Sjdp *
2650476Speter * $FreeBSD$
2745501Sjdp */
2845501Sjdp
2945501Sjdp#ifndef RTLD_MACHDEP_H
3045501Sjdp#define RTLD_MACHDEP_H	1
3145501Sjdp
32115396Skan#include <sys/types.h>
33115396Skan#include <machine/atomic.h>
34115396Skan
3585004Sdfrstruct Struct_Obj_Entry;
3685004Sdfr
3745501Sjdp/* Return the address of the .dynamic section in the dynamic linker. */
3845501Sjdp#define rtld_dynamic(obj) \
3945501Sjdp    ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
4045501Sjdp
4148205Sjdp/* Fixup the jump slot at "where" to transfer control to "target". */
4285004Sdfrstatic inline Elf_Addr
4385004Sdfrreloc_jmpslot(Elf_Addr *where, Elf_Addr target,
44107071Stmm	      const struct Struct_Obj_Entry *obj,
45107071Stmm	      const struct Struct_Obj_Entry *refobj, const Elf_Rel *rel)
4685004Sdfr{
47157261Sdes#ifdef dbg
4885004Sdfr    dbg("reloc_jmpslot: *%p = %p", (void *)(where),
4985004Sdfr	(void *)(target));
50157261Sdes#endif
5185004Sdfr    (*(Elf_Addr *)(where) = (Elf_Addr)(target));
5285004Sdfr    return target;
5385004Sdfr}
5448205Sjdp
5585004Sdfr#define make_function_pointer(def, defobj) \
5685004Sdfr	((defobj)->relocbase + (def)->st_value)
5785004Sdfr
5885677Speter#define call_initfini_pointer(obj, target) \
5985677Speter	(((InitFunc)(target))())
6085677Speter
61232831Skib#define call_init_pointer(obj, target) \
62232831Skib	(((InitArrFunc)(target))(main_argc, main_argv, environ))
63232831Skib
64133063Sdfr#define round(size, align) \
65133063Sdfr	(((size) + (align) - 1) & ~((align) - 1))
66133063Sdfr#define calculate_first_tls_offset(size, align) \
67133063Sdfr	round(size, align)
68133063Sdfr#define calculate_tls_offset(prev_offset, prev_size, size, align) \
69133063Sdfr	round((prev_offset) + (size), align)
70133063Sdfr#define calculate_tls_end(off, size) 	(off)
71133063Sdfr
72133063Sdfrtypedef struct {
73133063Sdfr    unsigned long ti_module;
74133063Sdfr    unsigned long ti_offset;
75133063Sdfr} tls_index;
76133063Sdfr
77133063Sdfrextern void *__tls_get_addr(tls_index *ti);
78133063Sdfr
79217851Skib#define	RTLD_DEFAULT_STACK_PF_EXEC	PF_X
80217851Skib#define	RTLD_DEFAULT_STACK_EXEC		PROT_EXEC
81217851Skib
8245501Sjdp#endif
83