X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/a9dafde4e393e0067043a5adb7cf37d3a4a6f3d2..e6c017f510b117f0c41d4feaeab49293e4ce21c1:/target/linux/generic-2.6/patches-2.6.30/027-mips_module_reloc.patch diff --git a/target/linux/generic-2.6/patches-2.6.30/027-mips_module_reloc.patch b/target/linux/generic-2.6/patches-2.6.30/027-mips_module_reloc.patch index 912857b0e..ca8766267 100644 --- a/target/linux/generic-2.6/patches-2.6.30/027-mips_module_reloc.patch +++ b/target/linux/generic-2.6/patches-2.6.30/027-mips_module_reloc.patch @@ -25,7 +25,7 @@ typedef uint8_t Elf64_Byte; /* Type for a 8-bit quantity. */ --- a/arch/mips/kernel/module.c +++ b/arch/mips/kernel/module.c -@@ -43,6 +43,114 @@ static struct mips_hi16 *mips_hi16_list; +@@ -43,6 +43,116 @@ static struct mips_hi16 *mips_hi16_list; static LIST_HEAD(dbe_list); static DEFINE_SPINLOCK(dbe_lock); @@ -35,7 +35,7 @@ + * physically mapped memory to put the module into. + */ +static unsigned int -+get_plt_size(const Elf32_Ehdr *hdr, const Elf32_Shdr *sechdrs, ++get_plt_size(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, + const char *secstrings, unsigned int symindex, bool is_init) +{ + unsigned long ret = 0; @@ -103,6 +103,7 @@ + return ret; +} + ++#ifndef MODULE_START +static void *alloc_phys(unsigned long size) +{ + unsigned order; @@ -124,6 +125,7 @@ + + return page_address(page); +} ++#endif + +static void free_phys(void *ptr, unsigned long size) +{ @@ -140,7 +142,7 @@ void *module_alloc(unsigned long size) { #ifdef MODULE_START -@@ -58,16 +166,41 @@ void *module_alloc(unsigned long size) +@@ -58,16 +168,45 @@ void *module_alloc(unsigned long size) return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL); #else @@ -159,14 +161,18 @@ + return vmalloc(size); + + return ptr; - #endif - } - ++#endif ++} ++ +static inline bool is_phys_addr(void *ptr) +{ ++#ifdef CONFIG_64BIT ++ return (KSEGX((unsigned long)ptr) == CKSEG0); ++#else + return (KSEGX(ptr) == KSEG0); -+} -+ + #endif + } + /* Free memory returned from module_alloc */ void module_free(struct module *mod, void *module_region) { @@ -184,7 +190,7 @@ /* FIXME: If module_region == mod->init_region, trim exception table entries. */ } -@@ -75,6 +208,24 @@ void module_free(struct module *mod, voi +@@ -75,6 +214,24 @@ void module_free(struct module *mod, voi int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, char *secstrings, struct module *mod) { @@ -209,13 +215,13 @@ return 0; } -@@ -97,45 +248,73 @@ static int apply_r_mips_32_rela(struct m +@@ -97,27 +254,41 @@ static int apply_r_mips_32_rela(struct m return 0; } -static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v) +static Elf_Addr add_plt_entry_to(unsigned *plt_offset, -+ void *start, unsigned size, Elf_Addr v) ++ void *start, Elf_Addr v) { - if (v % 4) { - printk(KERN_ERR "module %s: dangerous relocation\n", me->name); @@ -229,22 +235,19 @@ - me->name); - return -ENOEXEC; - } -+ if (*plt_offset == size) -+ return 0; -+ + *plt_offset += 4 * sizeof(int); + + /* adjust carry for addiu */ + if (v & 0x00008000) + v += 0x10000; - -- *location = (*location & ~0x03ffffff) | -- ((*location + (v >> 2)) & 0x03ffffff); ++ + tramp[0] = 0x3c190000 | (v >> 16); /* lui t9, hi16 */ + tramp[1] = 0x27390000 | (v & 0xffff); /* addiu t9, t9, lo16 */ + tramp[2] = 0x03200008; /* jr t9 */ + tramp[3] = 0x00000000; /* nop */ -+ + +- *location = (*location & ~0x03ffffff) | +- ((*location + (v >> 2)) & 0x03ffffff); + return (Elf_Addr) tramp; +} + @@ -253,12 +256,12 @@ + if (location >= me->module_core && + location < me->module_core + me->core_size) + return add_plt_entry_to(&me->arch.core_plt_offset, -+ me->module_core, me->core_size, v); ++ me->arch.plt_tbl, v); + + if (location >= me->module_init && + location < me->module_init + me->init_size) + return add_plt_entry_to(&me->arch.init_plt_offset, -+ me->module_init, me->init_size, v); ++ me->arch.plt_tbl, v); return 0; } @@ -268,16 +271,20 @@ { if (v % 4) { printk(KERN_ERR "module %s: dangerous relocation\n", me->name); - return -ENOEXEC; +@@ -125,17 +296,31 @@ static int apply_r_mips_26_rela(struct m } -- if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) { -+ if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000) && -+ ((v = add_plt_entry(me, location, v + (ofs << 2))) == 0)) { - printk(KERN_ERR + if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) { +- printk(KERN_ERR ++ v = add_plt_entry(me, location, v + (ofs << 2)); ++ if (!v) { ++ printk(KERN_ERR "module %s: relocation overflow\n", me->name); - return -ENOEXEC; +- return -ENOEXEC; ++ return -ENOEXEC; ++ } ++ ofs = 0; } - *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff); @@ -299,7 +306,7 @@ static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v) { struct mips_hi16 *n; -@@ -400,11 +579,23 @@ int module_finalize(const Elf_Ehdr *hdr, +@@ -400,11 +585,23 @@ int module_finalize(const Elf_Ehdr *hdr, list_add(&me->arch.dbe_list, &dbe_list); spin_unlock_irq(&dbe_lock); }