Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2012 ARM Ltd.
0004  */
0005 #ifndef __ASM_MODULE_H
0006 #define __ASM_MODULE_H
0007 
0008 #include <asm-generic/module.h>
0009 
0010 #ifdef CONFIG_ARM64_MODULE_PLTS
0011 struct mod_plt_sec {
0012     int         plt_shndx;
0013     int         plt_num_entries;
0014     int         plt_max_entries;
0015 };
0016 
0017 struct mod_arch_specific {
0018     struct mod_plt_sec  core;
0019     struct mod_plt_sec  init;
0020 
0021     /* for CONFIG_DYNAMIC_FTRACE */
0022     struct plt_entry    *ftrace_trampolines;
0023 };
0024 #endif
0025 
0026 u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
0027               void *loc, const Elf64_Rela *rela,
0028               Elf64_Sym *sym);
0029 
0030 u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
0031                 void *loc, u64 val);
0032 
0033 #ifdef CONFIG_RANDOMIZE_BASE
0034 extern u64 module_alloc_base;
0035 #else
0036 #define module_alloc_base   ((u64)_etext - MODULES_VSIZE)
0037 #endif
0038 
0039 struct plt_entry {
0040     /*
0041      * A program that conforms to the AArch64 Procedure Call Standard
0042      * (AAPCS64) must assume that a veneer that alters IP0 (x16) and/or
0043      * IP1 (x17) may be inserted at any branch instruction that is
0044      * exposed to a relocation that supports long branches. Since that
0045      * is exactly what we are dealing with here, we are free to use x16
0046      * as a scratch register in the PLT veneers.
0047      */
0048     __le32  adrp;   /* adrp x16, ....           */
0049     __le32  add;    /* add  x16, x16, #0x....       */
0050     __le32  br; /* br   x16             */
0051 };
0052 
0053 static inline bool is_forbidden_offset_for_adrp(void *place)
0054 {
0055     return IS_ENABLED(CONFIG_ARM64_ERRATUM_843419) &&
0056            cpus_have_const_cap(ARM64_WORKAROUND_843419) &&
0057            ((u64)place & 0xfff) >= 0xff8;
0058 }
0059 
0060 struct plt_entry get_plt_entry(u64 dst, void *pc);
0061 bool plt_entries_equal(const struct plt_entry *a, const struct plt_entry *b);
0062 
0063 static inline bool plt_entry_is_initialized(const struct plt_entry *e)
0064 {
0065     return e->adrp || e->add || e->br;
0066 }
0067 
0068 #endif /* __ASM_MODULE_H */