14b1859c0SRuslan Bukin /*- 24b1859c0SRuslan Bukin * Copyright (c) 1999, 2000 John D. Polstra. 34b1859c0SRuslan Bukin * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com> 44b1859c0SRuslan Bukin * All rights reserved. 54b1859c0SRuslan Bukin * 64b1859c0SRuslan Bukin * Portions of this software were developed by SRI International and the 74b1859c0SRuslan Bukin * University of Cambridge Computer Laboratory under DARPA/AFRL contract 84b1859c0SRuslan Bukin * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. 94b1859c0SRuslan Bukin * 104b1859c0SRuslan Bukin * Portions of this software were developed by the University of Cambridge 114b1859c0SRuslan Bukin * Computer Laboratory as part of the CTSRD Project, with support from the 124b1859c0SRuslan Bukin * UK Higher Education Innovation Fund (HEIF). 134b1859c0SRuslan Bukin * 144b1859c0SRuslan Bukin * Redistribution and use in source and binary forms, with or without 154b1859c0SRuslan Bukin * modification, are permitted provided that the following conditions 164b1859c0SRuslan Bukin * are met: 174b1859c0SRuslan Bukin * 1. Redistributions of source code must retain the above copyright 184b1859c0SRuslan Bukin * notice, this list of conditions and the following disclaimer. 194b1859c0SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright 204b1859c0SRuslan Bukin * notice, this list of conditions and the following disclaimer in the 214b1859c0SRuslan Bukin * documentation and/or other materials provided with the distribution. 224b1859c0SRuslan Bukin * 234b1859c0SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 244b1859c0SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 254b1859c0SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 264b1859c0SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 274b1859c0SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 284b1859c0SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 294b1859c0SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 304b1859c0SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 314b1859c0SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 324b1859c0SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 334b1859c0SRuslan Bukin * SUCH DAMAGE. 344b1859c0SRuslan Bukin */ 354b1859c0SRuslan Bukin 364b1859c0SRuslan Bukin #ifndef RTLD_MACHDEP_H 374b1859c0SRuslan Bukin #define RTLD_MACHDEP_H 1 384b1859c0SRuslan Bukin 394b1859c0SRuslan Bukin #include <sys/types.h> 404b1859c0SRuslan Bukin #include <machine/atomic.h> 418bcdb144SJohn Baldwin #include <machine/tls.h> 424b1859c0SRuslan Bukin 434b1859c0SRuslan Bukin struct Struct_Obj_Entry; 444b1859c0SRuslan Bukin 4506db20ffSAndrew Turner #define MD_OBJ_ENTRY 4606db20ffSAndrew Turner 474b1859c0SRuslan Bukin uint64_t set_gp(struct Struct_Obj_Entry *obj); 484b1859c0SRuslan Bukin 494b1859c0SRuslan Bukin /* Return the address of the .dynamic section in the dynamic linker. */ 504b1859c0SRuslan Bukin #define rtld_dynamic(obj) \ 514b1859c0SRuslan Bukin ({ \ 524b1859c0SRuslan Bukin Elf_Addr _dynamic_addr; \ 534b1859c0SRuslan Bukin __asm __volatile("lla %0, _DYNAMIC" : "=r"(_dynamic_addr)); \ 544b1859c0SRuslan Bukin (const Elf_Dyn *)_dynamic_addr; \ 554b1859c0SRuslan Bukin }) 564b1859c0SRuslan Bukin 57dd4155beSAndrew Turner /* No arch-specific dynamic tags */ 58dd4155beSAndrew Turner #define arch_digest_dynamic(obj, dynp) false 59dd4155beSAndrew Turner 60d8925a5fSAndrew Turner /* No architecture specific notes */ 61d8925a5fSAndrew Turner #define arch_digest_note(obj, note) false 62d8925a5fSAndrew Turner 634b1859c0SRuslan Bukin Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target, 64e35ddbe4SKonstantin Belousov const struct Struct_Obj_Entry *defobj, const struct Struct_Obj_Entry *obj, 654b1859c0SRuslan Bukin const Elf_Rel *rel); 664b1859c0SRuslan Bukin 674b1859c0SRuslan Bukin #define make_function_pointer(def, defobj) \ 684b1859c0SRuslan Bukin ((defobj)->relocbase + (def)->st_value) 694b1859c0SRuslan Bukin 704b1859c0SRuslan Bukin #define call_initfini_pointer(obj, target) \ 714b1859c0SRuslan Bukin ({ \ 724b1859c0SRuslan Bukin uint64_t old0; \ 734b1859c0SRuslan Bukin old0 = set_gp(obj); \ 744b1859c0SRuslan Bukin (((InitFunc)(target))()); \ 754b1859c0SRuslan Bukin __asm __volatile("mv gp, %0" :: "r"(old0)); \ 764b1859c0SRuslan Bukin }) 774b1859c0SRuslan Bukin 784b1859c0SRuslan Bukin #define call_init_pointer(obj, target) \ 794b1859c0SRuslan Bukin ({ \ 804b1859c0SRuslan Bukin uint64_t old1; \ 814b1859c0SRuslan Bukin old1 = set_gp(obj); \ 824b1859c0SRuslan Bukin (((InitArrFunc)(target))(main_argc, main_argv, environ)); \ 834b1859c0SRuslan Bukin __asm __volatile("mv gp, %0" :: "r"(old1)); \ 844b1859c0SRuslan Bukin }) 854b1859c0SRuslan Bukin 86*729d2b16SJessica Clarke extern unsigned long elf_hwcap; 874352999eSKonstantin Belousov #define call_ifunc_resolver(ptr) \ 88*729d2b16SJessica Clarke (((Elf_Addr (*)(unsigned long, unsigned long, unsigned long, \ 89*729d2b16SJessica Clarke unsigned long, unsigned long, unsigned long, unsigned long, \ 90*729d2b16SJessica Clarke unsigned long))ptr)(elf_hwcap, 0, 0, 0, 0, 0, 0, 0)) 914352999eSKonstantin Belousov 924b1859c0SRuslan Bukin /* 934b1859c0SRuslan Bukin * TLS 944b1859c0SRuslan Bukin */ 954b1859c0SRuslan Bukin 964b1859c0SRuslan Bukin #define round(size, align) \ 974b1859c0SRuslan Bukin (((size) + (align) - 1) & ~((align) - 1)) 98e5c3405cSKonstantin Belousov #define calculate_first_tls_offset(size, align, offset) \ 9917fb2856SBrooks Davis TLS_TCB_SIZE 100e5c3405cSKonstantin Belousov #define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \ 1014b1859c0SRuslan Bukin round(prev_offset + prev_size, align) 10217fb2856SBrooks Davis #define calculate_tls_post_size(align) 0 1034b1859c0SRuslan Bukin 1044b1859c0SRuslan Bukin typedef struct { 1054b1859c0SRuslan Bukin unsigned long ti_module; 1064b1859c0SRuslan Bukin unsigned long ti_offset; 1074b1859c0SRuslan Bukin } tls_index; 1084b1859c0SRuslan Bukin 1094b1859c0SRuslan Bukin extern void *__tls_get_addr(tls_index* ti); 1104b1859c0SRuslan Bukin 111e0752870SRuslan Bukin #define md_abi_variant_hook(x) 112e0752870SRuslan Bukin 1134b1859c0SRuslan Bukin #endif 114