Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / arch / cris / kernel / module.c
index 052c003..11b867d 100644 (file)
@@ -32,7 +32,7 @@ void *module_alloc(unsigned long size)
 {
        if (size == 0)
                return NULL;
-       return vmalloc(size);
+       return vmalloc_exec(size);
 }
 
 
@@ -59,28 +59,8 @@ int apply_relocate(Elf32_Shdr *sechdrs,
                   unsigned int relsec,
                   struct module *me)
 {
-       unsigned int i;
-       Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
-       Elf32_Sym *sym;
-       uint32_t *location;
-
-       DEBUGP("Applying relocate section %u to %u\n", relsec,
-              sechdrs[relsec].sh_info);
-       for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
-               /* This is where to make the change */
-               location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_offset
-                       + rel[i].r_offset;
-               /* This is the symbol it is referring to.  Note that all
-                  undefined symbols have been resolved.  */
-               sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
-                       + ELF32_R_SYM(rel[i].r_info);
-
-                /* TODO: This is probably not correct */
-                printk("Beware: untested code in module.c!\n");
-                /* We add the value into the location given */
-                *location += sym->st_value;
-       }
-       return 0;
+       printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
+       return -ENOEXEC;
 }
 
 int apply_relocate_add(Elf32_Shdr *sechdrs,
@@ -89,9 +69,37 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
                       unsigned int relsec,
                       struct module *me)
 {
-       printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n",
-              me->name);
-       return -ENOEXEC;
+       unsigned int i;
+       Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
+
+       DEBUGP ("Applying add relocate section %u to %u\n", relsec,
+               sechdrs[relsec].sh_info);
+
+       for (i = 0; i < sechdrs[relsec].sh_size / sizeof (*rela); i++) {
+               /* This is where to make the change */
+               uint32_t *loc
+                       = ((void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
+                          + rela[i].r_offset);
+               /* This is the symbol it is referring to.  Note that all
+                  undefined symbols have been resolved.  */
+               Elf32_Sym *sym
+                       = ((Elf32_Sym *)sechdrs[symindex].sh_addr
+                          + ELF32_R_SYM (rela[i].r_info));
+               switch (ELF32_R_TYPE(rela[i].r_info)) {
+               case R_CRIS_32:
+                       *loc = sym->st_value + rela[i].r_addend;
+                       break;
+               case R_CRIS_32_PCREL:
+                       *loc = sym->st_value - (unsigned)loc + rela[i].r_addend - 4;
+                        break;
+               default:
+                       printk(KERN_ERR "module %s: Unknown relocation: %u\n",
+                              me->name, ELF32_R_TYPE(rela[i].r_info));
+                       return -ENOEXEC;
+               }
+       }
+
+       return 0;
 }
 
 int module_finalize(const Elf_Ehdr *hdr,