~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/unicore32/kernel/module.c

Version: ~ [ linux-5.10-rc5 ] ~ [ linux-5.9.10 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.79 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.159 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.208 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.245 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.245 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/arch/unicore32/kernel/module.c
  3  *
  4  * Code specific to PKUnity SoC and UniCore ISA
  5  *
  6  * Copyright (C) 2001-2010 GUAN Xue-tao
  7  *
  8  * This program is free software; you can redistribute it and/or modify
  9  * it under the terms of the GNU General Public License version 2 as
 10  * published by the Free Software Foundation.
 11  */
 12 #include <linux/module.h>
 13 #include <linux/moduleloader.h>
 14 #include <linux/kernel.h>
 15 #include <linux/mm.h>
 16 #include <linux/elf.h>
 17 #include <linux/vmalloc.h>
 18 #include <linux/fs.h>
 19 #include <linux/string.h>
 20 #include <linux/gfp.h>
 21 
 22 #include <asm/pgtable.h>
 23 #include <asm/sections.h>
 24 
 25 void *module_alloc(unsigned long size)
 26 {
 27         struct vm_struct *area;
 28 
 29         size = PAGE_ALIGN(size);
 30         area = __get_vm_area(size, VM_ALLOC, MODULES_VADDR, MODULES_END);
 31         if (!area)
 32                 return NULL;
 33 
 34         return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
 35 }
 36 
 37 int
 38 apply_relocate(Elf32_Shdr *sechdrs, const char *strtab, unsigned int symindex,
 39                unsigned int relindex, struct module *module)
 40 {
 41         Elf32_Shdr *symsec = sechdrs + symindex;
 42         Elf32_Shdr *relsec = sechdrs + relindex;
 43         Elf32_Shdr *dstsec = sechdrs + relsec->sh_info;
 44         Elf32_Rel *rel = (void *)relsec->sh_addr;
 45         unsigned int i;
 46 
 47         for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++, rel++) {
 48                 unsigned long loc;
 49                 Elf32_Sym *sym;
 50                 s32 offset;
 51 
 52                 offset = ELF32_R_SYM(rel->r_info);
 53                 if (offset < 0 || offset >
 54                                 (symsec->sh_size / sizeof(Elf32_Sym))) {
 55                         printk(KERN_ERR "%s: bad relocation, "
 56                                         "section %d reloc %d\n",
 57                                         module->name, relindex, i);
 58                         return -ENOEXEC;
 59                 }
 60 
 61                 sym = ((Elf32_Sym *)symsec->sh_addr) + offset;
 62 
 63                 if (rel->r_offset < 0 || rel->r_offset >
 64                                 dstsec->sh_size - sizeof(u32)) {
 65                         printk(KERN_ERR "%s: out of bounds relocation, "
 66                                 "section %d reloc %d offset %d size %d\n",
 67                                 module->name, relindex, i, rel->r_offset,
 68                                 dstsec->sh_size);
 69                         return -ENOEXEC;
 70                 }
 71 
 72                 loc = dstsec->sh_addr + rel->r_offset;
 73 
 74                 switch (ELF32_R_TYPE(rel->r_info)) {
 75                 case R_UNICORE_NONE:
 76                         /* ignore */
 77                         break;
 78 
 79                 case R_UNICORE_ABS32:
 80                         *(u32 *)loc += sym->st_value;
 81                         break;
 82 
 83                 case R_UNICORE_PC24:
 84                 case R_UNICORE_CALL:
 85                 case R_UNICORE_JUMP24:
 86                         offset = (*(u32 *)loc & 0x00ffffff) << 2;
 87                         if (offset & 0x02000000)
 88                                 offset -= 0x04000000;
 89 
 90                         offset += sym->st_value - loc;
 91                         if (offset & 3 ||
 92                             offset <= (s32)0xfe000000 ||
 93                             offset >= (s32)0x02000000) {
 94                                 printk(KERN_ERR
 95                                        "%s: relocation out of range, section "
 96                                        "%d reloc %d sym '%s'\n", module->name,
 97                                        relindex, i, strtab + sym->st_name);
 98                                 return -ENOEXEC;
 99                         }
100 
101                         offset >>= 2;
102 
103                         *(u32 *)loc &= 0xff000000;
104                         *(u32 *)loc |= offset & 0x00ffffff;
105                         break;
106 
107                 default:
108                         printk(KERN_ERR "%s: unknown relocation: %u\n",
109                                module->name, ELF32_R_TYPE(rel->r_info));
110                         return -ENOEXEC;
111                 }
112         }
113         return 0;
114 }
115 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp