1107572Sgrehan/*-
2107572Sgrehan * Copyright (c) 1999, 2000 John D. Polstra.
3107572Sgrehan * All rights reserved.
4107572Sgrehan *
5107572Sgrehan * Redistribution and use in source and binary forms, with or without
6107572Sgrehan * modification, are permitted provided that the following conditions
7107572Sgrehan * are met:
8107572Sgrehan * 1. Redistributions of source code must retain the above copyright
9107572Sgrehan *    notice, this list of conditions and the following disclaimer.
10107572Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
11107572Sgrehan *    notice, this list of conditions and the following disclaimer in the
12107572Sgrehan *    documentation and/or other materials provided with the distribution.
13107572Sgrehan *
14107572Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15107572Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16107572Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17107572Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18107572Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19107572Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20107572Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21107572Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22107572Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23107572Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24107572Sgrehan * SUCH DAMAGE.
25107572Sgrehan *
26107572Sgrehan * $FreeBSD$
27107572Sgrehan */
28107572Sgrehan
29107572Sgrehan#ifndef RTLD_MACHDEP_H
30107572Sgrehan#define RTLD_MACHDEP_H	1
31107572Sgrehan
32115396Skan#include <sys/types.h>
33107572Sgrehan#include <machine/atomic.h>
34107572Sgrehan
35107572Sgrehanstruct Struct_Obj_Entry;
36107572Sgrehan
37107572Sgrehan/* Return the address of the .dynamic section in the dynamic linker. */
38107572Sgrehan#define rtld_dynamic(obj)    (&_DYNAMIC)
39107572Sgrehan
40107572SgrehanElf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,
41107572Sgrehan		       const struct Struct_Obj_Entry *defobj,
42107572Sgrehan		       const struct Struct_Obj_Entry *obj,
43107572Sgrehan		       const Elf_Rel *rel);
44107572Sgrehan
45107572Sgrehan#define make_function_pointer(def, defobj) \
46107572Sgrehan	((defobj)->relocbase + (def)->st_value)
47107572Sgrehan
48107572Sgrehan#define call_initfini_pointer(obj, target) \
49107572Sgrehan	(((InitFunc)(target))())
50107572Sgrehan
51233694Skib#define call_init_pointer(obj, target) \
52233694Skib	(((InitArrFunc)(target))(main_argc, main_argv, environ))
53233694Skib
54107572Sgrehan/*
55115396Skan * Lazy binding entry point, called via PLT.
56107572Sgrehan */
57107572Sgrehanvoid _rtld_bind_start(void);
58107572Sgrehan
59107572Sgrehan/*
60137122Sssouhlal * TLS
61137122Sssouhlal */
62137122Sssouhlal
63137122Sssouhlal#define TLS_TP_OFFSET	0x7000
64137122Sssouhlal#define TLS_DTV_OFFSET	0x8000
65209885Snwhitehorn#define TLS_TCB_SIZE	16
66137122Sssouhlal
67133133Sdfr#define round(size, align) \
68133133Sdfr    (((size) + (align) - 1) & ~((align) - 1))
69133133Sdfr#define calculate_first_tls_offset(size, align) \
70209885Snwhitehorn    round(16, align)
71133133Sdfr#define calculate_tls_offset(prev_offset, prev_size, size, align) \
72133133Sdfr    round(prev_offset + prev_size, align)
73133133Sdfr#define calculate_tls_end(off, size)    ((off) + (size))
74133133Sdfr
75133133Sdfrtypedef struct {
76133133Sdfr	unsigned long ti_module;
77133133Sdfr	unsigned long ti_offset;
78133133Sdfr} tls_index;
79133133Sdfr
80133133Sdfrextern void *__tls_get_addr(tls_index* ti);
81133133Sdfr
82217851Skib#define	RTLD_DEFAULT_STACK_PF_EXEC	PF_X
83217851Skib#define	RTLD_DEFAULT_STACK_EXEC		PROT_EXEC
84217851Skib
85107572Sgrehan#endif
86