Commit 7ee8798f authored by Steven J. Hill's avatar Steven J. Hill Committed by Ralf Baechle

Until I figure out why NFS filesystems are having problems with

the 'load_irix_binary' and having kernel faults, Irix support is
disabled. I suspect locking of some sort, but I will now have to
investigate further.

Static IRIX binaries are now being detected properly and are using the
ELF interpreter found in this file.
Signed-off-by: default avatarSteven J. Hill <sjhill@realitydiluted.com>
Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent dd193261
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* Copyright (C) 1993 - 1994 Eric Youngdale <ericy@cais.com> * Copyright (C) 1993 - 1994 Eric Youngdale <ericy@cais.com>
* Copyright (C) 1996 - 2004 David S. Miller <dm@engr.sgi.com> * Copyright (C) 1996 - 2004 David S. Miller <dm@engr.sgi.com>
* Copyright (C) 2004 Steven J. Hill <sjhill@realitydiluted.com> * Copyright (C) 2004 - 2005 Steven J. Hill <sjhill@realitydiluted.com>
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
...@@ -31,15 +31,16 @@ ...@@ -31,15 +31,16 @@
#include <linux/elfcore.h> #include <linux/elfcore.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/mipsregs.h> #include <asm/mipsregs.h>
#include <asm/namei.h>
#include <asm/prctl.h> #include <asm/prctl.h>
#include <asm/uaccess.h>
#define DLINFO_ITEMS 12 #define DLINFO_ITEMS 12
#include <linux/elf.h> #include <linux/elf.h>
#undef DEBUG_ELF #undef DEBUG
static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs); static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs);
static int load_irix_library(struct file *); static int load_irix_library(struct file *);
...@@ -55,7 +56,7 @@ static struct linux_binfmt irix_format = { ...@@ -55,7 +56,7 @@ static struct linux_binfmt irix_format = {
#define elf_addr_t unsigned long #define elf_addr_t unsigned long
#endif #endif
#ifdef DEBUG_ELF #ifdef DEBUG
/* Debugging routines. */ /* Debugging routines. */
static char *get_elf_p_type(Elf32_Word p_type) static char *get_elf_p_type(Elf32_Word p_type)
{ {
...@@ -120,7 +121,7 @@ static void dump_phdrs(struct elf_phdr *ep, int pnum) ...@@ -120,7 +121,7 @@ static void dump_phdrs(struct elf_phdr *ep, int pnum)
print_phdr(i, ep); print_phdr(i, ep);
} }
} }
#endif /* (DEBUG_ELF) */ #endif /* DEBUG */
static void set_brk(unsigned long start, unsigned long end) static void set_brk(unsigned long start, unsigned long end)
{ {
...@@ -150,16 +151,16 @@ static void padzero(unsigned long elf_bss) ...@@ -150,16 +151,16 @@ static void padzero(unsigned long elf_bss)
} }
} }
unsigned long * create_irix_tables(char * p, int argc, int envc, static unsigned long * create_irix_tables(char * p, int argc, int envc,
struct elfhdr * exec, unsigned int load_addr, struct elfhdr * exec, unsigned int load_addr,
unsigned int interp_load_addr, unsigned int interp_load_addr, struct pt_regs *regs,
struct pt_regs *regs, struct elf_phdr *ephdr) struct elf_phdr *ephdr)
{ {
elf_addr_t *argv; elf_addr_t *argv;
elf_addr_t *envp; elf_addr_t *envp;
elf_addr_t *sp, *csp; elf_addr_t *sp, *csp;
#ifdef DEBUG_ELF #ifdef DEBUG
printk("create_irix_tables: p[%p] argc[%d] envc[%d] " printk("create_irix_tables: p[%p] argc[%d] envc[%d] "
"load_addr[%08x] interp_load_addr[%08x]\n", "load_addr[%08x] interp_load_addr[%08x]\n",
p, argc, envc, load_addr, interp_load_addr); p, argc, envc, load_addr, interp_load_addr);
...@@ -248,14 +249,13 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex, ...@@ -248,14 +249,13 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
last_bss = 0; last_bss = 0;
error = load_addr = 0; error = load_addr = 0;
#ifdef DEBUG_ELF #ifdef DEBUG
print_elfhdr(interp_elf_ex); print_elfhdr(interp_elf_ex);
#endif #endif
/* First of all, some simple consistency checks */ /* First of all, some simple consistency checks */
if ((interp_elf_ex->e_type != ET_EXEC && if ((interp_elf_ex->e_type != ET_EXEC &&
interp_elf_ex->e_type != ET_DYN) || interp_elf_ex->e_type != ET_DYN) ||
!irix_elf_check_arch(interp_elf_ex) ||
!interpreter->f_op->mmap) { !interpreter->f_op->mmap) {
printk("IRIX interp has bad e_type %d\n", interp_elf_ex->e_type); printk("IRIX interp has bad e_type %d\n", interp_elf_ex->e_type);
return 0xffffffff; return 0xffffffff;
...@@ -290,7 +290,7 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex, ...@@ -290,7 +290,7 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
(char *) elf_phdata, (char *) elf_phdata,
sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
#ifdef DEBUG_ELF #ifdef DEBUG
dump_phdrs(elf_phdata, interp_elf_ex->e_phnum); dump_phdrs(elf_phdata, interp_elf_ex->e_phnum);
#endif #endif
...@@ -306,13 +306,11 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex, ...@@ -306,13 +306,11 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
elf_type |= MAP_FIXED; elf_type |= MAP_FIXED;
vaddr = eppnt->p_vaddr; vaddr = eppnt->p_vaddr;
#ifdef DEBUG_ELF pr_debug("INTERP do_mmap(%p, %08lx, %08lx, %08lx, %08lx, %08lx) ",
printk("INTERP do_mmap(%p, %08lx, %08lx, %08lx, %08lx, %08lx) ",
interpreter, vaddr, interpreter, vaddr,
(unsigned long) (eppnt->p_filesz + (eppnt->p_vaddr & 0xfff)), (unsigned long) (eppnt->p_filesz + (eppnt->p_vaddr & 0xfff)),
(unsigned long) elf_prot, (unsigned long) elf_type, (unsigned long) elf_prot, (unsigned long) elf_type,
(unsigned long) (eppnt->p_offset & 0xfffff000)); (unsigned long) (eppnt->p_offset & 0xfffff000));
#endif
down_write(&current->mm->mmap_sem); down_write(&current->mm->mmap_sem);
error = do_mmap(interpreter, vaddr, error = do_mmap(interpreter, vaddr,
eppnt->p_filesz + (eppnt->p_vaddr & 0xfff), eppnt->p_filesz + (eppnt->p_vaddr & 0xfff),
...@@ -324,14 +322,10 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex, ...@@ -324,14 +322,10 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
printk("Aieee IRIX interp mmap error=%d\n", error); printk("Aieee IRIX interp mmap error=%d\n", error);
break; /* Real error */ break; /* Real error */
} }
#ifdef DEBUG_ELF pr_debug("error=%08lx ", (unsigned long) error);
printk("error=%08lx ", (unsigned long) error);
#endif
if(!load_addr && interp_elf_ex->e_type == ET_DYN) { if(!load_addr && interp_elf_ex->e_type == ET_DYN) {
load_addr = error; load_addr = error;
#ifdef DEBUG_ELF pr_debug("load_addr = error ");
printk("load_addr = error ");
#endif
} }
/* Find the end of the file mapping for this phdr, and keep /* Find the end of the file mapping for this phdr, and keep
...@@ -345,17 +339,13 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex, ...@@ -345,17 +339,13 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
*/ */
k = eppnt->p_memsz + eppnt->p_vaddr; k = eppnt->p_memsz + eppnt->p_vaddr;
if(k > last_bss) last_bss = k; if(k > last_bss) last_bss = k;
#ifdef DEBUG_ELF pr_debug("\n");
printk("\n");
#endif
} }
} }
/* Now use mmap to map the library into memory. */ /* Now use mmap to map the library into memory. */
if(error < 0 && error > -1024) { if(error < 0 && error > -1024) {
#ifdef DEBUG_ELF pr_debug("got error %d\n", error);
printk("got error %d\n", error);
#endif
kfree(elf_phdata); kfree(elf_phdata);
return 0xffffffff; return 0xffffffff;
} }
...@@ -365,16 +355,12 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex, ...@@ -365,16 +355,12 @@ static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
* that there are zero-mapped pages up to and including the * that there are zero-mapped pages up to and including the
* last bss page. * last bss page.
*/ */
#ifdef DEBUG_ELF pr_debug("padzero(%08lx) ", (unsigned long) (elf_bss));
printk("padzero(%08lx) ", (unsigned long) (elf_bss));
#endif
padzero(elf_bss); padzero(elf_bss);
len = (elf_bss + 0xfff) & 0xfffff000; /* What we have mapped so far */ len = (elf_bss + 0xfff) & 0xfffff000; /* What we have mapped so far */
#ifdef DEBUG_ELF pr_debug("last_bss[%08lx] len[%08lx]\n", (unsigned long) last_bss,
printk("last_bss[%08lx] len[%08lx]\n", (unsigned long) last_bss,
(unsigned long) len); (unsigned long) len);
#endif
/* Map the last of the bss segment */ /* Map the last of the bss segment */
if (last_bss > len) { if (last_bss > len) {
...@@ -396,12 +382,7 @@ static int verify_binary(struct elfhdr *ehp, struct linux_binprm *bprm) ...@@ -396,12 +382,7 @@ static int verify_binary(struct elfhdr *ehp, struct linux_binprm *bprm)
/* First of all, some simple consistency checks */ /* First of all, some simple consistency checks */
if((ehp->e_type != ET_EXEC && ehp->e_type != ET_DYN) || if((ehp->e_type != ET_EXEC && ehp->e_type != ET_DYN) ||
!irix_elf_check_arch(ehp) || !bprm->file->f_op->mmap) { !bprm->file->f_op->mmap) {
return -ENOEXEC;
}
/* Only support MIPS ARCH2 or greater IRIX binaries for now. */
if(!(ehp->e_flags & EF_MIPS_ARCH) && !(ehp->e_flags & 0x04)) {
return -ENOEXEC; return -ENOEXEC;
} }
...@@ -411,16 +392,17 @@ static int verify_binary(struct elfhdr *ehp, struct linux_binprm *bprm) ...@@ -411,16 +392,17 @@ static int verify_binary(struct elfhdr *ehp, struct linux_binprm *bprm)
* XXX all registers as 64bits on cpu's capable of this at * XXX all registers as 64bits on cpu's capable of this at
* XXX exception time plus frob the XTLB exception vector. * XXX exception time plus frob the XTLB exception vector.
*/ */
if((ehp->e_flags & 0x20)) { if((ehp->e_flags & EF_MIPS_ABI2))
return -ENOEXEC; return -ENOEXEC;
}
return 0; /* It's ok. */ return 0;
} }
#define IRIX_INTERP_PREFIX "/usr/gnemul/irix" /*
* This is where the detailed check is performed. Irix binaries
/* Look for an IRIX ELF interpreter. */ * use interpreters with 'libc.so' in the name, so this function
* can differentiate between Linux and Irix binaries.
*/
static inline int look_for_irix_interpreter(char **name, static inline int look_for_irix_interpreter(char **name,
struct file **interpreter, struct file **interpreter,
struct elfhdr *interp_elf_ex, struct elfhdr *interp_elf_ex,
...@@ -440,12 +422,13 @@ static inline int look_for_irix_interpreter(char **name, ...@@ -440,12 +422,13 @@ static inline int look_for_irix_interpreter(char **name,
if (*name != NULL) if (*name != NULL)
goto out; goto out;
*name = kmalloc((epp->p_filesz + strlen(IRIX_INTERP_PREFIX)), *name = (char *) kmalloc((epp->p_filesz +
strlen(IRIX_EMUL)),
GFP_KERNEL); GFP_KERNEL);
if (!*name) if (!*name)
return -ENOMEM; return -ENOMEM;
strcpy(*name, IRIX_INTERP_PREFIX); strcpy(*name, IRIX_EMUL);
retval = kernel_read(bprm->file, epp->p_offset, (*name + 16), retval = kernel_read(bprm->file, epp->p_offset, (*name + 16),
epp->p_filesz); epp->p_filesz);
if (retval < 0) if (retval < 0)
...@@ -562,7 +545,7 @@ static inline int map_interpreter(struct elf_phdr *epp, struct elfhdr *ihp, ...@@ -562,7 +545,7 @@ static inline int map_interpreter(struct elf_phdr *epp, struct elfhdr *ihp,
* process and the system, here we map the page and fill the * process and the system, here we map the page and fill the
* structure * structure
*/ */
void irix_map_prda_page (void) static void irix_map_prda_page(void)
{ {
unsigned long v; unsigned long v;
struct prda *pp; struct prda *pp;
...@@ -601,14 +584,33 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -601,14 +584,33 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
load_addr = 0; load_addr = 0;
has_interp = has_ephdr = 0; has_interp = has_ephdr = 0;
elf_ihdr = elf_ephdr = 0; elf_ihdr = elf_ephdr = NULL;
elf_ex = *((struct elfhdr *) bprm->buf); elf_ex = *((struct elfhdr *) bprm->buf);
retval = -ENOEXEC; retval = -ENOEXEC;
if (verify_binary(&elf_ex, bprm)) if (verify_binary(&elf_ex, bprm))
goto out; goto out;
#ifdef DEBUG_ELF /*
* Telling -o32 static binaries from Linux and Irix apart from each
* other is difficult. There are 2 differences to be noted for static
* binaries from the 2 operating systems:
*
* 1) Irix binaries have their .text section before their .init
* section. Linux binaries are just the opposite.
*
* 2) Irix binaries usually have <= 12 sections and Linux
* binaries have > 20.
*
* We will use Method #2 since Method #1 would require us to read in
* the section headers which is way too much overhead. This appears
* to work for everything we have ran into so far. If anyone has a
* better method to tell the binaries apart, I'm listening.
*/
if (elf_ex.e_shnum > 20)
goto out;
#ifdef DEBUG
print_elfhdr(&elf_ex); print_elfhdr(&elf_ex);
#endif #endif
...@@ -623,11 +625,10 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -623,11 +625,10 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
} }
retval = kernel_read(bprm->file, elf_ex.e_phoff, (char *)elf_phdata, size); retval = kernel_read(bprm->file, elf_ex.e_phoff, (char *)elf_phdata, size);
if (retval < 0) if (retval < 0)
goto out_free_ph; goto out_free_ph;
#ifdef DEBUG_ELF #ifdef DEBUG
dump_phdrs(elf_phdata, elf_ex.e_phnum); dump_phdrs(elf_phdata, elf_ex.e_phnum);
#endif #endif
...@@ -644,9 +645,8 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -644,9 +645,8 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
break; break;
}; };
} }
#ifdef DEBUG_ELF
printk("\n"); pr_debug("\n");
#endif
elf_bss = 0; elf_bss = 0;
elf_brk = 0; elf_brk = 0;
...@@ -657,12 +657,19 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -657,12 +657,19 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
end_code = 0; end_code = 0;
end_data = 0; end_data = 0;
retval = look_for_irix_interpreter(&elf_interpreter, /*
&interpreter, * If we get a return value, we change the value to be ENOEXEC
* so that we can exit gracefully and the main binary format
* search loop in 'fs/exec.c' will move onto the next handler
* which should be the normal ELF binary handler.
*/
retval = look_for_irix_interpreter(&elf_interpreter, &interpreter,
&interp_elf_ex, elf_phdata, bprm, &interp_elf_ex, elf_phdata, bprm,
elf_ex.e_phnum); elf_ex.e_phnum);
if (retval) if (retval) {
retval = -ENOEXEC;
goto out_free_file; goto out_free_file;
}
if (elf_interpreter) { if (elf_interpreter) {
retval = verify_irix_interpreter(&interp_elf_ex); retval = verify_irix_interpreter(&interp_elf_ex);
...@@ -746,18 +753,16 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -746,18 +753,16 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
* IRIX maps a page at 0x200000 which holds some system * IRIX maps a page at 0x200000 which holds some system
* information. Programs depend on this. * information. Programs depend on this.
*/ */
irix_map_prda_page (); irix_map_prda_page();
padzero(elf_bss); padzero(elf_bss);
#ifdef DEBUG_ELF pr_debug("(start_brk) %lx\n" , (long) current->mm->start_brk);
printk("(start_brk) %lx\n" , (long) current->mm->start_brk); pr_debug("(end_code) %lx\n" , (long) current->mm->end_code);
printk("(end_code) %lx\n" , (long) current->mm->end_code); pr_debug("(start_code) %lx\n" , (long) current->mm->start_code);
printk("(start_code) %lx\n" , (long) current->mm->start_code); pr_debug("(end_data) %lx\n" , (long) current->mm->end_data);
printk("(end_data) %lx\n" , (long) current->mm->end_data); pr_debug("(start_stack) %lx\n" , (long) current->mm->start_stack);
printk("(start_stack) %lx\n" , (long) current->mm->start_stack); pr_debug("(brk) %lx\n" , (long) current->mm->brk);
printk("(brk) %lx\n" , (long) current->mm->brk);
#endif
#if 0 /* XXX No fucking way dude... */ #if 0 /* XXX No fucking way dude... */
/* Why this, you ask??? Well SVr4 maps page 0 as read-only, /* Why this, you ask??? Well SVr4 maps page 0 as read-only,
...@@ -782,7 +787,6 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -782,7 +787,6 @@ static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
allow_write_access(interpreter); allow_write_access(interpreter);
fput(interpreter); fput(interpreter);
out_free_interp: out_free_interp:
if (elf_interpreter)
kfree(elf_interpreter); kfree(elf_interpreter);
out_free_file: out_free_file:
out_free_ph: out_free_ph:
...@@ -813,7 +817,7 @@ static int load_irix_library(struct file *file) ...@@ -813,7 +817,7 @@ static int load_irix_library(struct file *file)
/* First of all, some simple consistency checks. */ /* First of all, some simple consistency checks. */
if(elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 || if(elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
!irix_elf_check_arch(&elf_ex) || !file->f_op->mmap) !file->f_op->mmap)
return -ENOEXEC; return -ENOEXEC;
/* Now read in all of the header information. */ /* Now read in all of the header information. */
...@@ -876,33 +880,34 @@ static int load_irix_library(struct file *file) ...@@ -876,33 +880,34 @@ static int load_irix_library(struct file *file)
*/ */
unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt) unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
{ {
unsigned long type, vaddr, filesz, offset, flags;
struct elf_phdr *hp; struct elf_phdr *hp;
struct file *filp; struct file *filp;
int i, retval; int i, retval;
#ifdef DEBUG_ELF pr_debug("irix_mapelf: fd[%d] user_phdrp[%p] cnt[%d]\n",
printk("irix_mapelf: fd[%d] user_phdrp[%p] cnt[%d]\n",
fd, user_phdrp, cnt); fd, user_phdrp, cnt);
#endif
/* First get the verification out of the way. */ /* First get the verification out of the way. */
hp = user_phdrp; hp = user_phdrp;
if (!access_ok(VERIFY_READ, hp, (sizeof(struct elf_phdr) * cnt))) { if (!access_ok(VERIFY_READ, hp, (sizeof(struct elf_phdr) * cnt))) {
#ifdef DEBUG_ELF pr_debug("irix_mapelf: bad pointer to ELF PHDR!\n");
printk("irix_mapelf: access_ok fails!\n");
#endif
return -EFAULT; return -EFAULT;
} }
#ifdef DEBUG_ELF #ifdef DEBUG
dump_phdrs(user_phdrp, cnt); dump_phdrs(user_phdrp, cnt);
#endif #endif
for(i = 0; i < cnt; i++, hp++) for (i = 0; i < cnt; i++, hp++) {
if(hp->p_type != PT_LOAD) { if (__get_user(type, &hp->p_type))
return -EFAULT;
if (type != PT_LOAD) {
printk("irix_mapelf: One section is not PT_LOAD!\n"); printk("irix_mapelf: One section is not PT_LOAD!\n");
return -ENOEXEC; return -ENOEXEC;
} }
}
filp = fget(fd); filp = fget(fd);
if (!filp) if (!filp)
...@@ -917,29 +922,40 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt) ...@@ -917,29 +922,40 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
for(i = 0; i < cnt; i++, hp++) { for(i = 0; i < cnt; i++, hp++) {
int prot; int prot;
prot = (hp->p_flags & PF_R) ? PROT_READ : 0; retval = __get_user(vaddr, &hp->p_vaddr);
prot |= (hp->p_flags & PF_W) ? PROT_WRITE : 0; retval |= __get_user(filesz, &hp->p_filesz);
prot |= (hp->p_flags & PF_X) ? PROT_EXEC : 0; retval |= __get_user(offset, &hp->p_offset);
retval |= __get_user(flags, &hp->p_flags);
if (retval)
return retval;
prot = (flags & PF_R) ? PROT_READ : 0;
prot |= (flags & PF_W) ? PROT_WRITE : 0;
prot |= (flags & PF_X) ? PROT_EXEC : 0;
down_write(&current->mm->mmap_sem); down_write(&current->mm->mmap_sem);
retval = do_mmap(filp, (hp->p_vaddr & 0xfffff000), retval = do_mmap(filp, (vaddr & 0xfffff000),
(hp->p_filesz + (hp->p_vaddr & 0xfff)), (filesz + (vaddr & 0xfff)),
prot, (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE), prot, (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE),
(hp->p_offset & 0xfffff000)); (offset & 0xfffff000));
up_write(&current->mm->mmap_sem); up_write(&current->mm->mmap_sem);
if(retval != (hp->p_vaddr & 0xfffff000)) { if (retval != (vaddr & 0xfffff000)) {
printk("irix_mapelf: do_mmap fails with %d!\n", retval); printk("irix_mapelf: do_mmap fails with %d!\n", retval);
fput(filp); fput(filp);
return retval; return retval;
} }
} }
#ifdef DEBUG_ELF pr_debug("irix_mapelf: Success, returning %08lx\n",
printk("irix_mapelf: Success, returning %08lx\n",
(unsigned long) user_phdrp->p_vaddr); (unsigned long) user_phdrp->p_vaddr);
#endif
fput(filp); fput(filp);
return user_phdrp->p_vaddr;
if (__get_user(vaddr, &user_phdrp->p_vaddr))
return -EFAULT;
return vaddr;
} }
/* /*
...@@ -954,7 +970,7 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt) ...@@ -954,7 +970,7 @@ unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
*/ */
static int dump_write(struct file *file, const void *addr, int nr) static int dump_write(struct file *file, const void *addr, int nr)
{ {
return file->f_op->write(file, addr, nr, &file->f_pos) == nr; return file->f_op->write(file, (const char *) addr, nr, &file->f_pos) == nr;
} }
static int dump_seek(struct file *file, off_t off) static int dump_seek(struct file *file, off_t off)
...@@ -1073,7 +1089,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file) ...@@ -1073,7 +1089,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
/* Count what's needed to dump, up to the limit of coredump size. */ /* Count what's needed to dump, up to the limit of coredump size. */
segs = 0; segs = 0;
size = 0; size = 0;
for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) { for (vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
if (maydump(vma)) if (maydump(vma))
{ {
int sz = vma->vm_end-vma->vm_start; int sz = vma->vm_end-vma->vm_start;
...@@ -1187,9 +1203,9 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file) ...@@ -1187,9 +1203,9 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
len = current->mm->arg_end - current->mm->arg_start; len = current->mm->arg_end - current->mm->arg_start;
len = len >= ELF_PRARGSZ ? ELF_PRARGSZ : len; len = len >= ELF_PRARGSZ ? ELF_PRARGSZ : len;
copy_from_user(&psinfo.pr_psargs, (void *) copy_from_user(&psinfo.pr_psargs,
(const char *)current->mm->arg_start, len); (const char *)current->mm->arg_start, len);
for(i = 0; i < len; i++) for (i = 0; i < len; i++)
if (psinfo.pr_psargs[i] == 0) if (psinfo.pr_psargs[i] == 0)
psinfo.pr_psargs[i] = ' '; psinfo.pr_psargs[i] = ' ';
psinfo.pr_psargs[len] = 0; psinfo.pr_psargs[len] = 0;
...@@ -1256,8 +1272,10 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file) ...@@ -1256,8 +1272,10 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
phdr.p_memsz = sz; phdr.p_memsz = sz;
offset += phdr.p_filesz; offset += phdr.p_filesz;
phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0; phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W; if (vma->vm_flags & VM_WRITE)
if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X; phdr.p_flags |= PF_W;
if (vma->vm_flags & VM_EXEC)
phdr.p_flags |= PF_X;
phdr.p_align = PAGE_SIZE; phdr.p_align = PAGE_SIZE;
DUMP_WRITE(&phdr, sizeof(phdr)); DUMP_WRITE(&phdr, sizeof(phdr));
...@@ -1299,7 +1317,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file) ...@@ -1299,7 +1317,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
static int __init init_irix_binfmt(void) static int __init init_irix_binfmt(void)
{ {
int init_inventory(void); extern int init_inventory(void);
extern asmlinkage unsigned long sys_call_table; extern asmlinkage unsigned long sys_call_table;
extern asmlinkage unsigned long sys_call_table_irix5; extern asmlinkage unsigned long sys_call_table_irix5;
...@@ -1318,7 +1336,9 @@ static int __init init_irix_binfmt(void) ...@@ -1318,7 +1336,9 @@ static int __init init_irix_binfmt(void)
static void __exit exit_irix_binfmt(void) static void __exit exit_irix_binfmt(void)
{ {
/* Remove the IRIX ELF loaders. */ /*
* Remove the Irix ELF loader.
*/
unregister_binfmt(&irix_format); unregister_binfmt(&irix_format);
} }
......
...@@ -234,9 +234,6 @@ extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *); ...@@ -234,9 +234,6 @@ extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *);
#endif /* __KERNEL__ */ #endif /* __KERNEL__ */
/* This one accepts IRIX binaries. */
#define irix_elf_check_arch(hdr) ((hdr)->e_flags & RHF_SGI_ONLY)
#define USE_ELF_CORE_DUMP #define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE PAGE_SIZE #define ELF_EXEC_PAGESIZE PAGE_SIZE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment