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: stable/10/libexec/rtld-elf/i386/rtld_machdep.h 309061 2016-11-23 17:48:43Z kib $ 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{ 47157220Sdes#ifdef dbg 4885004Sdfr dbg("reloc_jmpslot: *%p = %p", (void *)(where), 4985004Sdfr (void *)(target)); 50157220Sdes#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 64309061Skibextern uint32_t cpu_feature; 65309061Skibextern uint32_t cpu_feature2; 66309061Skibextern uint32_t cpu_stdext_feature; 67309061Skibextern uint32_t cpu_stdext_feature2; 68309061Skib#define call_ifunc_resolver(ptr) \ 69309061Skib (((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, uint32_t))ptr)( \ 70309061Skib cpu_feature, cpu_feature2, cpu_stdext_feature, cpu_stdext_feature2)) 71309061Skib 72133063Sdfr#define round(size, align) \ 73133063Sdfr (((size) + (align) - 1) & ~((align) - 1)) 74133063Sdfr#define calculate_first_tls_offset(size, align) \ 75133063Sdfr round(size, align) 76133063Sdfr#define calculate_tls_offset(prev_offset, prev_size, size, align) \ 77133063Sdfr round((prev_offset) + (size), align) 78133063Sdfr#define calculate_tls_end(off, size) (off) 79133063Sdfr 80133063Sdfrtypedef struct { 81133063Sdfr unsigned long ti_module; 82133063Sdfr unsigned long ti_offset; 83133063Sdfr} tls_index; 84133063Sdfr 85281453Skibvoid *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1))) __exported; 86281453Skibvoid *__tls_get_addr(tls_index *ti) __exported; 87133063Sdfr 88217851Skib#define RTLD_DEFAULT_STACK_PF_EXEC PF_X 89217851Skib#define RTLD_DEFAULT_STACK_EXEC PROT_EXEC 90217851Skib 9145501Sjdp#endif 92