Path: blob/main/libexec/rtld-elf/riscv/rtld_machdep.h
34923 views
/*-1* Copyright (c) 1999, 2000 John D. Polstra.2* Copyright (c) 2015 Ruslan Bukin <[email protected]>3* All rights reserved.4*5* Portions of this software were developed by SRI International and the6* University of Cambridge Computer Laboratory under DARPA/AFRL contract7* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.8*9* Portions of this software were developed by the University of Cambridge10* Computer Laboratory as part of the CTSRD Project, with support from the11* UK Higher Education Innovation Fund (HEIF).12*13* Redistribution and use in source and binary forms, with or without14* modification, are permitted provided that the following conditions15* are met:16* 1. Redistributions of source code must retain the above copyright17* notice, this list of conditions and the following disclaimer.18* 2. Redistributions in binary form must reproduce the above copyright19* notice, this list of conditions and the following disclaimer in the20* documentation and/or other materials provided with the distribution.21*22* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#ifndef RTLD_MACHDEP_H36#define RTLD_MACHDEP_H 13738#include <sys/types.h>39#include <machine/atomic.h>40#include <machine/tls.h>4142struct Struct_Obj_Entry;4344#define MD_OBJ_ENTRY4546uint64_t set_gp(struct Struct_Obj_Entry *obj);4748/* Return the address of the .dynamic section in the dynamic linker. */49#define rtld_dynamic(obj) \50({ \51Elf_Addr _dynamic_addr; \52__asm __volatile("lla %0, _DYNAMIC" : "=r"(_dynamic_addr)); \53(const Elf_Dyn *)_dynamic_addr; \54})5556/* No arch-specific dynamic tags */57#define arch_digest_dynamic(obj, dynp) false5859/* No architecture specific notes */60#define arch_digest_note(obj, note) false6162Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target,63const struct Struct_Obj_Entry *defobj, const struct Struct_Obj_Entry *obj,64const Elf_Rel *rel);6566#define make_function_pointer(def, defobj) \67((defobj)->relocbase + (def)->st_value)6869#define call_initfini_pointer(obj, target) \70({ \71uint64_t old0; \72old0 = set_gp(obj); \73(((InitFunc)(target))()); \74__asm __volatile("mv gp, %0" :: "r"(old0)); \75})7677#define call_init_pointer(obj, target) \78({ \79uint64_t old1; \80old1 = set_gp(obj); \81(((InitArrFunc)(target))(main_argc, main_argv, environ)); \82__asm __volatile("mv gp, %0" :: "r"(old1)); \83})8485extern unsigned long elf_hwcap;86#define call_ifunc_resolver(ptr) \87(((Elf_Addr (*)(unsigned long, unsigned long, unsigned long, \88unsigned long, unsigned long, unsigned long, unsigned long, \89unsigned long))ptr)(elf_hwcap, 0, 0, 0, 0, 0, 0, 0))9091/*92* TLS93*/9495#define round(size, align) \96(((size) + (align) - 1) & ~((align) - 1))97#define calculate_first_tls_offset(size, align, offset) \98TLS_TCB_SIZE99#define calculate_tls_offset(prev_offset, prev_size, size, align, offset) \100round(prev_offset + prev_size, align)101#define calculate_tls_post_size(align) 0102103typedef struct {104unsigned long ti_module;105unsigned long ti_offset;106} tls_index;107108extern void *__tls_get_addr(tls_index* ti);109110#define md_abi_variant_hook(x)111112#endif113114115