kernel.org linux-2.6.10
[linux-2.6.git] / arch / mips / kernel / irixelf.c
1 /*
2  * irixelf.c: Code to load IRIX ELF executables which conform to
3  *            the MIPS ABI.
4  *
5  * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
6  *
7  * Based upon work which is:
8  * Copyright 1993, 1994: Eric Youngdale (ericy@cais.com).
9  */
10
11 #include <linux/module.h>
12
13 #include <linux/fs.h>
14 #include <linux/stat.h>
15 #include <linux/sched.h>
16 #include <linux/mm.h>
17 #include <linux/mman.h>
18 #include <linux/a.out.h>
19 #include <linux/errno.h>
20 #include <linux/init.h>
21 #include <linux/signal.h>
22 #include <linux/binfmts.h>
23 #include <linux/string.h>
24 #include <linux/file.h>
25 #include <linux/fcntl.h>
26 #include <linux/ptrace.h>
27 #include <linux/slab.h>
28 #include <linux/shm.h>
29 #include <linux/personality.h>
30 #include <linux/elfcore.h>
31 #include <linux/smp_lock.h>
32
33 #include <asm/uaccess.h>
34 #include <asm/mipsregs.h>
35 #include <asm/prctl.h>
36
37 #define DLINFO_ITEMS 12
38
39 #include <linux/elf.h>
40
41 #undef DEBUG_ELF
42
43 static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs);
44 static int load_irix_library(struct file *);
45 static int irix_core_dump(long signr, struct pt_regs * regs,
46                           struct file *file);
47
48 static struct linux_binfmt irix_format = {
49         NULL, THIS_MODULE, load_irix_binary, load_irix_library,
50         irix_core_dump, PAGE_SIZE
51 };
52
53 #ifndef elf_addr_t
54 #define elf_addr_t unsigned long
55 #endif
56
57 #ifdef DEBUG_ELF
58 /* Debugging routines. */
59 static char *get_elf_p_type(Elf32_Word p_type)
60 {
61         int i = (int) p_type;
62
63         switch(i) {
64         case PT_NULL: return("PT_NULL"); break;
65         case PT_LOAD: return("PT_LOAD"); break;
66         case PT_DYNAMIC: return("PT_DYNAMIC"); break;
67         case PT_INTERP: return("PT_INTERP"); break;
68         case PT_NOTE: return("PT_NOTE"); break;
69         case PT_SHLIB: return("PT_SHLIB"); break;
70         case PT_PHDR: return("PT_PHDR"); break;
71         case PT_LOPROC: return("PT_LOPROC/REGINFO"); break;
72         case PT_HIPROC: return("PT_HIPROC"); break;
73         default: return("PT_BOGUS"); break;
74         }
75 }
76
77 static void print_elfhdr(struct elfhdr *ehp)
78 {
79         int i;
80
81         printk("ELFHDR: e_ident<");
82         for(i = 0; i < (EI_NIDENT - 1); i++) printk("%x ", ehp->e_ident[i]);
83         printk("%x>\n", ehp->e_ident[i]);
84         printk("        e_type[%04x] e_machine[%04x] e_version[%08lx]\n",
85                (unsigned short) ehp->e_type, (unsigned short) ehp->e_machine,
86                (unsigned long) ehp->e_version);
87         printk("        e_entry[%08lx] e_phoff[%08lx] e_shoff[%08lx] "
88                "e_flags[%08lx]\n",
89                (unsigned long) ehp->e_entry, (unsigned long) ehp->e_phoff,
90                (unsigned long) ehp->e_shoff, (unsigned long) ehp->e_flags);
91         printk("        e_ehsize[%04x] e_phentsize[%04x] e_phnum[%04x]\n",
92                (unsigned short) ehp->e_ehsize, (unsigned short) ehp->e_phentsize,
93                (unsigned short) ehp->e_phnum);
94         printk("        e_shentsize[%04x] e_shnum[%04x] e_shstrndx[%04x]\n",
95                (unsigned short) ehp->e_shentsize, (unsigned short) ehp->e_shnum,
96                (unsigned short) ehp->e_shstrndx);
97 }
98
99 static void print_phdr(int i, struct elf_phdr *ep)
100 {
101         printk("PHDR[%d]: p_type[%s] p_offset[%08lx] p_vaddr[%08lx] "
102                "p_paddr[%08lx]\n", i, get_elf_p_type(ep->p_type),
103                (unsigned long) ep->p_offset, (unsigned long) ep->p_vaddr,
104                (unsigned long) ep->p_paddr);
105         printk("         p_filesz[%08lx] p_memsz[%08lx] p_flags[%08lx] "
106                "p_align[%08lx]\n", (unsigned long) ep->p_filesz,
107                (unsigned long) ep->p_memsz, (unsigned long) ep->p_flags,
108                (unsigned long) ep->p_align);
109 }
110
111 static void dump_phdrs(struct elf_phdr *ep, int pnum)
112 {
113         int i;
114
115         for(i = 0; i < pnum; i++, ep++) {
116                 if((ep->p_type == PT_LOAD) ||
117                    (ep->p_type == PT_INTERP) ||
118                    (ep->p_type == PT_PHDR))
119                         print_phdr(i, ep);
120         }
121 }
122 #endif /* (DEBUG_ELF) */
123
124 static void set_brk(unsigned long start, unsigned long end)
125 {
126         start = PAGE_ALIGN(start);
127         end = PAGE_ALIGN(end);
128         if (end <= start)
129                 return;
130         do_brk(start, end - start);
131 }
132
133
134 /* We need to explicitly zero any fractional pages
135  * after the data section (i.e. bss).  This would
136  * contain the junk from the file that should not
137  * be in memory.
138  */
139 static void padzero(unsigned long elf_bss)
140 {
141         unsigned long nbyte;
142
143         nbyte = elf_bss & (PAGE_SIZE-1);
144         if (nbyte) {
145                 nbyte = PAGE_SIZE - nbyte;
146                 clear_user((void *) elf_bss, nbyte);
147         }
148 }
149
150 unsigned long * create_irix_tables(char * p, int argc, int envc,
151                                    struct elfhdr * exec, unsigned int load_addr,
152                                    unsigned int interp_load_addr,
153                                    struct pt_regs *regs, struct elf_phdr *ephdr)
154 {
155         elf_addr_t *argv;
156         elf_addr_t *envp;
157         elf_addr_t *sp, *csp;
158
159 #ifdef DEBUG_ELF
160         printk("create_irix_tables: p[%p] argc[%d] envc[%d] "
161                "load_addr[%08x] interp_load_addr[%08x]\n",
162                p, argc, envc, load_addr, interp_load_addr);
163 #endif
164         sp = (elf_addr_t *) (~15UL & (unsigned long) p);
165         csp = sp;
166         csp -= exec ? DLINFO_ITEMS*2 : 2;
167         csp -= envc+1;
168         csp -= argc+1;
169         csp -= 1;               /* argc itself */
170         if ((unsigned long)csp & 15UL) {
171                 sp -= (16UL - ((unsigned long)csp & 15UL)) / sizeof(*sp);
172         }
173
174         /*
175          * Put the ELF interpreter info on the stack
176          */
177 #define NEW_AUX_ENT(nr, id, val) \
178           __put_user ((id), sp+(nr*2)); \
179           __put_user ((val), sp+(nr*2+1)); \
180
181         sp -= 2;
182         NEW_AUX_ENT(0, AT_NULL, 0);
183
184         if(exec) {
185                 sp -= 11*2;
186
187                 NEW_AUX_ENT (0, AT_PHDR, load_addr + exec->e_phoff);
188                 NEW_AUX_ENT (1, AT_PHENT, sizeof (struct elf_phdr));
189                 NEW_AUX_ENT (2, AT_PHNUM, exec->e_phnum);
190                 NEW_AUX_ENT (3, AT_PAGESZ, ELF_EXEC_PAGESIZE);
191                 NEW_AUX_ENT (4, AT_BASE, interp_load_addr);
192                 NEW_AUX_ENT (5, AT_FLAGS, 0);
193                 NEW_AUX_ENT (6, AT_ENTRY, (elf_addr_t) exec->e_entry);
194                 NEW_AUX_ENT (7, AT_UID, (elf_addr_t) current->uid);
195                 NEW_AUX_ENT (8, AT_EUID, (elf_addr_t) current->euid);
196                 NEW_AUX_ENT (9, AT_GID, (elf_addr_t) current->gid);
197                 NEW_AUX_ENT (10, AT_EGID, (elf_addr_t) current->egid);
198         }
199 #undef NEW_AUX_ENT
200
201         sp -= envc+1;
202         envp = sp;
203         sp -= argc+1;
204         argv = sp;
205
206         __put_user((elf_addr_t)argc,--sp);
207         current->mm->arg_start = (unsigned long) p;
208         while (argc-->0) {
209                 __put_user((unsigned long)p,argv++);
210                 p += strlen_user(p);
211         }
212         __put_user(NULL, argv);
213         current->mm->arg_end = current->mm->env_start = (unsigned long) p;
214         while (envc-->0) {
215                 __put_user((unsigned long)p,envp++);
216                 p += strlen_user(p);
217         }
218         __put_user(NULL, envp);
219         current->mm->env_end = (unsigned long) p;
220         return sp;
221 }
222
223
224 /* This is much more generalized than the library routine read function,
225  * so we keep this separate.  Technically the library read function
226  * is only provided so that we can read a.out libraries that have
227  * an ELF header.
228  */
229 static unsigned int load_irix_interp(struct elfhdr * interp_elf_ex,
230                                      struct file * interpreter,
231                                      unsigned int *interp_load_addr)
232 {
233         struct elf_phdr *elf_phdata  =  NULL;
234         struct elf_phdr *eppnt;
235         unsigned int len;
236         unsigned int load_addr;
237         int elf_bss;
238         int retval;
239         unsigned int last_bss;
240         int error;
241         int i;
242         unsigned int k;
243
244         elf_bss = 0;
245         last_bss = 0;
246         error = load_addr = 0;
247
248 #ifdef DEBUG_ELF
249         print_elfhdr(interp_elf_ex);
250 #endif
251
252         /* First of all, some simple consistency checks */
253         if ((interp_elf_ex->e_type != ET_EXEC &&
254              interp_elf_ex->e_type != ET_DYN) ||
255              !irix_elf_check_arch(interp_elf_ex) ||
256              !interpreter->f_op->mmap) {
257                 printk("IRIX interp has bad e_type %d\n", interp_elf_ex->e_type);
258                 return 0xffffffff;
259         }
260
261         /* Now read in all of the header information */
262         if(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > PAGE_SIZE) {
263             printk("IRIX interp header bigger than a page (%d)\n",
264                    (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum));
265             return 0xffffffff;
266         }
267
268         elf_phdata = kmalloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum,
269                              GFP_KERNEL);
270
271         if(!elf_phdata) {
272           printk("Cannot kmalloc phdata for IRIX interp.\n");
273           return 0xffffffff;
274         }
275
276         /* If the size of this structure has changed, then punt, since
277          * we will be doing the wrong thing.
278          */
279         if(interp_elf_ex->e_phentsize != 32) {
280                 printk("IRIX interp e_phentsize == %d != 32 ",
281                        interp_elf_ex->e_phentsize);
282                 kfree(elf_phdata);
283                 return 0xffffffff;
284         }
285
286         retval = kernel_read(interpreter, interp_elf_ex->e_phoff,
287                            (char *) elf_phdata,
288                            sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
289
290 #ifdef DEBUG_ELF
291         dump_phdrs(elf_phdata, interp_elf_ex->e_phnum);
292 #endif
293
294         eppnt = elf_phdata;
295         for(i=0; i<interp_elf_ex->e_phnum; i++, eppnt++) {
296           if(eppnt->p_type == PT_LOAD) {
297             int elf_type = MAP_PRIVATE | MAP_DENYWRITE;
298             int elf_prot = 0;
299             unsigned long vaddr = 0;
300             if (eppnt->p_flags & PF_R) elf_prot =  PROT_READ;
301             if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
302             if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
303             elf_type |= MAP_FIXED;
304             vaddr = eppnt->p_vaddr;
305
306 #ifdef DEBUG_ELF
307             printk("INTERP do_mmap(%p, %08lx, %08lx, %08lx, %08lx, %08lx) ",
308                    interpreter, vaddr,
309                    (unsigned long) (eppnt->p_filesz + (eppnt->p_vaddr & 0xfff)),
310                    (unsigned long) elf_prot, (unsigned long) elf_type,
311                    (unsigned long) (eppnt->p_offset & 0xfffff000));
312 #endif
313             down_write(&current->mm->mmap_sem);
314             error = do_mmap(interpreter, vaddr,
315                             eppnt->p_filesz + (eppnt->p_vaddr & 0xfff),
316                             elf_prot, elf_type,
317                             eppnt->p_offset & 0xfffff000);
318             up_write(&current->mm->mmap_sem);
319
320             if(error < 0 && error > -1024) {
321                     printk("Aieee IRIX interp mmap error=%d\n", error);
322                     break;  /* Real error */
323             }
324 #ifdef DEBUG_ELF
325             printk("error=%08lx ", (unsigned long) error);
326 #endif
327             if(!load_addr && interp_elf_ex->e_type == ET_DYN) {
328               load_addr = error;
329 #ifdef DEBUG_ELF
330               printk("load_addr = error ");
331 #endif
332             }
333
334             /* Find the end of the file  mapping for this phdr, and keep
335              * track of the largest address we see for this.
336              */
337             k = eppnt->p_vaddr + eppnt->p_filesz;
338             if(k > elf_bss) elf_bss = k;
339
340             /* Do the same thing for the memory mapping - between
341              * elf_bss and last_bss is the bss section.
342              */
343             k = eppnt->p_memsz + eppnt->p_vaddr;
344             if(k > last_bss) last_bss = k;
345 #ifdef DEBUG_ELF
346             printk("\n");
347 #endif
348           }
349         }
350
351         /* Now use mmap to map the library into memory. */
352         if(error < 0 && error > -1024) {
353 #ifdef DEBUG_ELF
354                 printk("got error %d\n", error);
355 #endif
356                 kfree(elf_phdata);
357                 return 0xffffffff;
358         }
359
360         /* Now fill out the bss section.  First pad the last page up
361          * to the page boundary, and then perform a mmap to make sure
362          * that there are zero-mapped pages up to and including the
363          * last bss page.
364          */
365 #ifdef DEBUG_ELF
366         printk("padzero(%08lx) ", (unsigned long) (elf_bss));
367 #endif
368         padzero(elf_bss);
369         len = (elf_bss + 0xfff) & 0xfffff000; /* What we have mapped so far */
370
371 #ifdef DEBUG_ELF
372         printk("last_bss[%08lx] len[%08lx]\n", (unsigned long) last_bss,
373                (unsigned long) len);
374 #endif
375
376         /* Map the last of the bss segment */
377         if (last_bss > len) {
378                 do_brk(len, (last_bss - len));
379         }
380         kfree(elf_phdata);
381
382         *interp_load_addr = load_addr;
383         return ((unsigned int) interp_elf_ex->e_entry);
384 }
385
386 /* Check sanity of IRIX elf executable header. */
387 static int verify_binary(struct elfhdr *ehp, struct linux_binprm *bprm)
388 {
389         if (memcmp(ehp->e_ident, ELFMAG, SELFMAG) != 0)
390                 return -ENOEXEC;
391
392         /* First of all, some simple consistency checks */
393         if((ehp->e_type != ET_EXEC && ehp->e_type != ET_DYN) ||
394             !irix_elf_check_arch(ehp) || !bprm->file->f_op->mmap) {
395                 return -ENOEXEC;
396         }
397
398         /* Only support MIPS ARCH2 or greater IRIX binaries for now. */
399         if(!(ehp->e_flags & EF_MIPS_ARCH) && !(ehp->e_flags & 0x04)) {
400                 return -ENOEXEC;
401         }
402
403         /* XXX Don't support N32 or 64bit binaries yet because they can
404          * XXX and do execute 64 bit instructions and expect all registers
405          * XXX to be 64 bit as well.  We need to make the kernel save
406          * XXX all registers as 64bits on cpu's capable of this at
407          * XXX exception time plus frob the XTLB exception vector.
408          */
409         if((ehp->e_flags & 0x20)) {
410                 return -ENOEXEC;
411         }
412
413         return 0; /* It's ok. */
414 }
415
416 #define IRIX_INTERP_PREFIX "/usr/gnemul/irix"
417
418 /* Look for an IRIX ELF interpreter. */
419 static inline int look_for_irix_interpreter(char **name,
420                                             struct file **interpreter,
421                                             struct elfhdr *interp_elf_ex,
422                                             struct elf_phdr *epp,
423                                             struct linux_binprm *bprm, int pnum)
424 {
425         int i;
426         int retval = -EINVAL;
427         struct file *file = NULL;
428
429         *name = NULL;
430         for(i = 0; i < pnum; i++, epp++) {
431                 if (epp->p_type != PT_INTERP)
432                         continue;
433
434                 /* It is illegal to have two interpreters for one executable. */
435                 if (*name != NULL)
436                         goto out;
437
438                 *name = kmalloc((epp->p_filesz + strlen(IRIX_INTERP_PREFIX)),
439                                 GFP_KERNEL);
440                 if (!*name)
441                         return -ENOMEM;
442
443                 strcpy(*name, IRIX_INTERP_PREFIX);
444                 retval = kernel_read(bprm->file, epp->p_offset, (*name + 16),
445                                      epp->p_filesz);
446                 if (retval < 0)
447                         goto out;
448
449                 file = open_exec(*name);
450                 if (IS_ERR(file)) {
451                         retval = PTR_ERR(file);
452                         goto out;
453                 }
454                 retval = kernel_read(file, 0, bprm->buf, 128);
455                 if (retval < 0)
456                         goto dput_and_out;
457
458                 *interp_elf_ex = *(struct elfhdr *) bprm->buf;
459         }
460         *interpreter = file;
461         return 0;
462
463 dput_and_out:
464         fput(file);
465 out:
466         kfree(*name);
467         return retval;
468 }
469
470 static inline int verify_irix_interpreter(struct elfhdr *ihp)
471 {
472         if (memcmp(ihp->e_ident, ELFMAG, SELFMAG) != 0)
473                 return -ELIBBAD;
474         return 0;
475 }
476
477 #define EXEC_MAP_FLAGS (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE)
478
479 static inline void map_executable(struct file *fp, struct elf_phdr *epp, int pnum,
480                                   unsigned int *estack, unsigned int *laddr,
481                                   unsigned int *scode, unsigned int *ebss,
482                                   unsigned int *ecode, unsigned int *edata,
483                                   unsigned int *ebrk)
484 {
485         unsigned int tmp;
486         int i, prot;
487
488         for(i = 0; i < pnum; i++, epp++) {
489                 if(epp->p_type != PT_LOAD)
490                         continue;
491
492                 /* Map it. */
493                 prot  = (epp->p_flags & PF_R) ? PROT_READ : 0;
494                 prot |= (epp->p_flags & PF_W) ? PROT_WRITE : 0;
495                 prot |= (epp->p_flags & PF_X) ? PROT_EXEC : 0;
496                 down_write(&current->mm->mmap_sem);
497                 (void) do_mmap(fp, (epp->p_vaddr & 0xfffff000),
498                                (epp->p_filesz + (epp->p_vaddr & 0xfff)),
499                                prot, EXEC_MAP_FLAGS,
500                                (epp->p_offset & 0xfffff000));
501                 up_write(&current->mm->mmap_sem);
502
503                 /* Fixup location tracking vars. */
504                 if((epp->p_vaddr & 0xfffff000) < *estack)
505                         *estack = (epp->p_vaddr & 0xfffff000);
506                 if(!*laddr)
507                         *laddr = epp->p_vaddr - epp->p_offset;
508                 if(epp->p_vaddr < *scode)
509                         *scode = epp->p_vaddr;
510
511                 tmp = epp->p_vaddr + epp->p_filesz;
512                 if(tmp > *ebss)
513                         *ebss = tmp;
514                 if((epp->p_flags & PF_X) && *ecode < tmp)
515                         *ecode = tmp;
516                 if(*edata < tmp)
517                         *edata = tmp;
518
519                 tmp = epp->p_vaddr + epp->p_memsz;
520                 if(tmp > *ebrk)
521                         *ebrk = tmp;
522         }
523
524 }
525
526 static inline int map_interpreter(struct elf_phdr *epp, struct elfhdr *ihp,
527                                   struct file *interp, unsigned int *iladdr,
528                                   int pnum, mm_segment_t old_fs,
529                                   unsigned int *eentry)
530 {
531         int i;
532
533         *eentry = 0xffffffff;
534         for(i = 0; i < pnum; i++, epp++) {
535                 if(epp->p_type != PT_INTERP)
536                         continue;
537
538                 /* We should have fielded this error elsewhere... */
539                 if(*eentry != 0xffffffff)
540                         return -1;
541
542                 set_fs(old_fs);
543                 *eentry = load_irix_interp(ihp, interp, iladdr);
544                 old_fs = get_fs();
545                 set_fs(get_ds());
546
547                 fput(interp);
548
549                 if (*eentry == 0xffffffff)
550                         return -1;
551         }
552         return 0;
553 }
554
555 /*
556  * IRIX maps a page at 0x200000 that holds information about the
557  * process and the system, here we map the page and fill the
558  * structure
559  */
560 void irix_map_prda_page (void)
561 {
562         unsigned long v;
563         struct prda *pp;
564
565         v =  do_brk (PRDA_ADDRESS, PAGE_SIZE);
566
567         if (v < 0)
568                 return;
569
570         pp = (struct prda *) v;
571         pp->prda_sys.t_pid  = current->pid;
572         pp->prda_sys.t_prid = read_c0_prid();
573         pp->prda_sys.t_rpid = current->pid;
574
575         /* We leave the rest set to zero */
576 }
577
578
579
580 /* These are the functions used to load ELF style executables and shared
581  * libraries.  There is no binary dependent code anywhere else.
582  */
583 static int load_irix_binary(struct linux_binprm * bprm, struct pt_regs * regs)
584 {
585         struct elfhdr elf_ex, interp_elf_ex;
586         struct file *interpreter;
587         struct elf_phdr *elf_phdata, *elf_ihdr, *elf_ephdr;
588         unsigned int load_addr, elf_bss, elf_brk;
589         unsigned int elf_entry, interp_load_addr = 0;
590         unsigned int start_code, end_code, end_data, elf_stack;
591         int retval, has_interp, has_ephdr, size, i;
592         char *elf_interpreter;
593         mm_segment_t old_fs;
594
595         load_addr = 0;
596         has_interp = has_ephdr = 0;
597         elf_ihdr = elf_ephdr = 0;
598         elf_ex = *((struct elfhdr *) bprm->buf);
599         retval = -ENOEXEC;
600
601         if (verify_binary(&elf_ex, bprm))
602                 goto out;
603
604 #ifdef DEBUG_ELF
605         print_elfhdr(&elf_ex);
606 #endif
607
608         /* Now read in all of the header information */
609         size = elf_ex.e_phentsize * elf_ex.e_phnum;
610         if (size > 65536)
611                 goto out;
612         elf_phdata = kmalloc(size, GFP_KERNEL);
613         if (elf_phdata == NULL) {
614                 retval = -ENOMEM;
615                 goto out;
616         }
617
618         retval = kernel_read(bprm->file, elf_ex.e_phoff, (char *)elf_phdata, size);
619         if (retval < 0)
620                 goto out_free_ph;
621
622 #ifdef DEBUG_ELF
623         dump_phdrs(elf_phdata, elf_ex.e_phnum);
624 #endif
625
626         /* Set some things for later. */
627         for(i = 0; i < elf_ex.e_phnum; i++) {
628                 switch(elf_phdata[i].p_type) {
629                 case PT_INTERP:
630                         has_interp = 1;
631                         elf_ihdr = &elf_phdata[i];
632                         break;
633                 case PT_PHDR:
634                         has_ephdr = 1;
635                         elf_ephdr = &elf_phdata[i];
636                         break;
637                 };
638         }
639 #ifdef DEBUG_ELF
640         printk("\n");
641 #endif
642
643         elf_bss = 0;
644         elf_brk = 0;
645
646         elf_stack = 0xffffffff;
647         elf_interpreter = NULL;
648         start_code = 0xffffffff;
649         end_code = 0;
650         end_data = 0;
651
652         retval = look_for_irix_interpreter(&elf_interpreter,
653                                            &interpreter,
654                                            &interp_elf_ex, elf_phdata, bprm,
655                                            elf_ex.e_phnum);
656         if (retval)
657                 goto out_free_file;
658
659         if (elf_interpreter) {
660                 retval = verify_irix_interpreter(&interp_elf_ex);
661                 if(retval)
662                         goto out_free_interp;
663         }
664
665         /* OK, we are done with that, now set up the arg stuff,
666          * and then start this sucker up.
667          */
668         retval = -E2BIG;
669         if (!bprm->sh_bang && !bprm->p)
670                 goto out_free_interp;
671
672         /* Flush all traces of the currently running executable */
673         retval = flush_old_exec(bprm);
674         if (retval)
675                 goto out_free_dentry;
676
677         /* OK, This is the point of no return */
678         current->mm->end_data = 0;
679         current->mm->end_code = 0;
680         current->mm->mmap = NULL;
681         current->flags &= ~PF_FORKNOEXEC;
682         elf_entry = (unsigned int) elf_ex.e_entry;
683
684         /* Do this so that we can load the interpreter, if need be.  We will
685          * change some of these later.
686          */
687         current->mm->rss = 0;
688         setup_arg_pages(bprm, EXSTACK_DEFAULT);
689         current->mm->start_stack = bprm->p;
690
691         /* At this point, we assume that the image should be loaded at
692          * fixed address, not at a variable address.
693          */
694         old_fs = get_fs();
695         set_fs(get_ds());
696
697         map_executable(bprm->file, elf_phdata, elf_ex.e_phnum, &elf_stack,
698                        &load_addr, &start_code, &elf_bss, &end_code,
699                        &end_data, &elf_brk);
700
701         if(elf_interpreter) {
702                 retval = map_interpreter(elf_phdata, &interp_elf_ex,
703                                          interpreter, &interp_load_addr,
704                                          elf_ex.e_phnum, old_fs, &elf_entry);
705                 kfree(elf_interpreter);
706                 if(retval) {
707                         set_fs(old_fs);
708                         printk("Unable to load IRIX ELF interpreter\n");
709                         send_sig(SIGSEGV, current, 0);
710                         retval = 0;
711                         goto out_free_file;
712                 }
713         }
714
715         set_fs(old_fs);
716
717         kfree(elf_phdata);
718         set_personality(PER_IRIX32);
719         set_binfmt(&irix_format);
720         compute_creds(bprm);
721         current->flags &= ~PF_FORKNOEXEC;
722         bprm->p = (unsigned long)
723           create_irix_tables((char *)bprm->p, bprm->argc, bprm->envc,
724                         (elf_interpreter ? &elf_ex : NULL),
725                         load_addr, interp_load_addr, regs, elf_ephdr);
726         current->mm->start_brk = current->mm->brk = elf_brk;
727         current->mm->end_code = end_code;
728         current->mm->start_code = start_code;
729         current->mm->end_data = end_data;
730         current->mm->start_stack = bprm->p;
731
732         /* Calling set_brk effectively mmaps the pages that we need for the
733          * bss and break sections.
734          */
735         set_brk(elf_bss, elf_brk);
736
737         /*
738          * IRIX maps a page at 0x200000 which holds some system
739          * information.  Programs depend on this.
740          */
741         irix_map_prda_page ();
742
743         padzero(elf_bss);
744
745 #ifdef DEBUG_ELF
746         printk("(start_brk) %lx\n" , (long) current->mm->start_brk);
747         printk("(end_code) %lx\n" , (long) current->mm->end_code);
748         printk("(start_code) %lx\n" , (long) current->mm->start_code);
749         printk("(end_data) %lx\n" , (long) current->mm->end_data);
750         printk("(start_stack) %lx\n" , (long) current->mm->start_stack);
751         printk("(brk) %lx\n" , (long) current->mm->brk);
752 #endif
753
754 #if 0 /* XXX No fucking way dude... */
755         /* Why this, you ask???  Well SVr4 maps page 0 as read-only,
756          * and some applications "depend" upon this behavior.
757          * Since we do not have the power to recompile these, we
758          * emulate the SVr4 behavior.  Sigh.
759          */
760         down_write(&current->mm->mmap_sem);
761         (void) do_mmap(NULL, 0, 4096, PROT_READ | PROT_EXEC,
762                        MAP_FIXED | MAP_PRIVATE, 0);
763         up_write(&current->mm->mmap_sem);
764 #endif
765
766         start_thread(regs, elf_entry, bprm->p);
767         if (current->ptrace & PT_PTRACED)
768                 send_sig(SIGTRAP, current, 0);
769         return 0;
770 out:
771         return retval;
772
773 out_free_dentry:
774         allow_write_access(interpreter);
775         fput(interpreter);
776 out_free_interp:
777         if (elf_interpreter)
778                 kfree(elf_interpreter);
779 out_free_file:
780 out_free_ph:
781         kfree (elf_phdata);
782         goto out;
783 }
784
785 /* This is really simpleminded and specialized - we are loading an
786  * a.out library that is given an ELF header.
787  */
788 static int load_irix_library(struct file *file)
789 {
790         struct elfhdr elf_ex;
791         struct elf_phdr *elf_phdata  =  NULL;
792         unsigned int len = 0;
793         int elf_bss = 0;
794         int retval;
795         unsigned int bss;
796         int error;
797         int i,j, k;
798
799         error = kernel_read(file, 0, (char *) &elf_ex, sizeof(elf_ex));
800         if (error != sizeof(elf_ex))
801                 return -ENOEXEC;
802
803         if (memcmp(elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
804                 return -ENOEXEC;
805
806         /* First of all, some simple consistency checks. */
807         if(elf_ex.e_type != ET_EXEC || elf_ex.e_phnum > 2 ||
808            !irix_elf_check_arch(&elf_ex) || !file->f_op->mmap)
809                 return -ENOEXEC;
810
811         /* Now read in all of the header information. */
812         if(sizeof(struct elf_phdr) * elf_ex.e_phnum > PAGE_SIZE)
813                 return -ENOEXEC;
814
815         elf_phdata = kmalloc(sizeof(struct elf_phdr) * elf_ex.e_phnum, GFP_KERNEL);
816         if (elf_phdata == NULL)
817                 return -ENOMEM;
818
819         retval = kernel_read(file, elf_ex.e_phoff, (char *) elf_phdata,
820                            sizeof(struct elf_phdr) * elf_ex.e_phnum);
821
822         j = 0;
823         for(i=0; i<elf_ex.e_phnum; i++)
824                 if((elf_phdata + i)->p_type == PT_LOAD) j++;
825
826         if(j != 1)  {
827                 kfree(elf_phdata);
828                 return -ENOEXEC;
829         }
830
831         while(elf_phdata->p_type != PT_LOAD) elf_phdata++;
832
833         /* Now use mmap to map the library into memory. */
834         down_write(&current->mm->mmap_sem);
835         error = do_mmap(file,
836                         elf_phdata->p_vaddr & 0xfffff000,
837                         elf_phdata->p_filesz + (elf_phdata->p_vaddr & 0xfff),
838                         PROT_READ | PROT_WRITE | PROT_EXEC,
839                         MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE,
840                         elf_phdata->p_offset & 0xfffff000);
841         up_write(&current->mm->mmap_sem);
842
843         k = elf_phdata->p_vaddr + elf_phdata->p_filesz;
844         if (k > elf_bss) elf_bss = k;
845
846         if (error != (elf_phdata->p_vaddr & 0xfffff000)) {
847                 kfree(elf_phdata);
848                 return error;
849         }
850
851         padzero(elf_bss);
852
853         len = (elf_phdata->p_filesz + elf_phdata->p_vaddr+ 0xfff) & 0xfffff000;
854         bss = elf_phdata->p_memsz + elf_phdata->p_vaddr;
855         if (bss > len)
856           do_brk(len, bss-len);
857         kfree(elf_phdata);
858         return 0;
859 }
860
861 /* Called through irix_syssgi() to map an elf image given an FD,
862  * a phdr ptr USER_PHDRP in userspace, and a count CNT telling how many
863  * phdrs there are in the USER_PHDRP array.  We return the vaddr the
864  * first phdr was successfully mapped to.
865  */
866 unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt)
867 {
868         struct elf_phdr *hp;
869         struct file *filp;
870         int i, retval;
871
872 #ifdef DEBUG_ELF
873         printk("irix_mapelf: fd[%d] user_phdrp[%p] cnt[%d]\n",
874                fd, user_phdrp, cnt);
875 #endif
876
877         /* First get the verification out of the way. */
878         hp = user_phdrp;
879         retval = verify_area(VERIFY_READ, hp, (sizeof(struct elf_phdr) * cnt));
880         if(retval) {
881 #ifdef DEBUG_ELF
882                 printk("irix_mapelf: verify_area fails!\n");
883 #endif
884                 return retval;
885         }
886
887 #ifdef DEBUG_ELF
888         dump_phdrs(user_phdrp, cnt);
889 #endif
890
891         for(i = 0; i < cnt; i++, hp++)
892                 if(hp->p_type != PT_LOAD) {
893                         printk("irix_mapelf: One section is not PT_LOAD!\n");
894                         return -ENOEXEC;
895                 }
896
897         filp = fget(fd);
898         if (!filp)
899                 return -EACCES;
900         if(!filp->f_op) {
901                 printk("irix_mapelf: Bogon filp!\n");
902                 fput(filp);
903                 return -EACCES;
904         }
905
906         hp = user_phdrp;
907         for(i = 0; i < cnt; i++, hp++) {
908                 int prot;
909
910                 prot  = (hp->p_flags & PF_R) ? PROT_READ : 0;
911                 prot |= (hp->p_flags & PF_W) ? PROT_WRITE : 0;
912                 prot |= (hp->p_flags & PF_X) ? PROT_EXEC : 0;
913                 down_write(&current->mm->mmap_sem);
914                 retval = do_mmap(filp, (hp->p_vaddr & 0xfffff000),
915                                  (hp->p_filesz + (hp->p_vaddr & 0xfff)),
916                                  prot, (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE),
917                                  (hp->p_offset & 0xfffff000));
918                 up_write(&current->mm->mmap_sem);
919
920                 if(retval != (hp->p_vaddr & 0xfffff000)) {
921                         printk("irix_mapelf: do_mmap fails with %d!\n", retval);
922                         fput(filp);
923                         return retval;
924                 }
925         }
926
927 #ifdef DEBUG_ELF
928         printk("irix_mapelf: Success, returning %08lx\n", user_phdrp->p_vaddr);
929 #endif
930         fput(filp);
931         return user_phdrp->p_vaddr;
932 }
933
934 /*
935  * ELF core dumper
936  *
937  * Modelled on fs/exec.c:aout_core_dump()
938  * Jeremy Fitzhardinge <jeremy@sw.oz.au>
939  */
940
941 /* These are the only things you should do on a core-file: use only these
942  * functions to write out all the necessary info.
943  */
944 static int dump_write(struct file *file, const void *addr, int nr)
945 {
946         return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
947 }
948
949 static int dump_seek(struct file *file, off_t off)
950 {
951         if (file->f_op->llseek) {
952                 if (file->f_op->llseek(file, off, 0) != off)
953                         return 0;
954         } else
955                 file->f_pos = off;
956         return 1;
957 }
958
959 /* Decide whether a segment is worth dumping; default is yes to be
960  * sure (missing info is worse than too much; etc).
961  * Personally I'd include everything, and use the coredump limit...
962  *
963  * I think we should skip something. But I am not sure how. H.J.
964  */
965 static inline int maydump(struct vm_area_struct *vma)
966 {
967         if (!(vma->vm_flags & (VM_READ|VM_WRITE|VM_EXEC)))
968                 return 0;
969 #if 1
970         if (vma->vm_flags & (VM_WRITE|VM_GROWSUP|VM_GROWSDOWN))
971                 return 1;
972         if (vma->vm_flags & (VM_READ|VM_EXEC|VM_EXECUTABLE|VM_SHARED))
973                 return 0;
974 #endif
975         return 1;
976 }
977
978 #define roundup(x, y)  ((((x)+((y)-1))/(y))*(y))
979
980 /* An ELF note in memory. */
981 struct memelfnote
982 {
983         const char *name;
984         int type;
985         unsigned int datasz;
986         void *data;
987 };
988
989 static int notesize(struct memelfnote *en)
990 {
991         int sz;
992
993         sz = sizeof(struct elf_note);
994         sz += roundup(strlen(en->name), 4);
995         sz += roundup(en->datasz, 4);
996
997         return sz;
998 }
999
1000 /* #define DEBUG */
1001
1002 #define DUMP_WRITE(addr, nr)    \
1003         if (!dump_write(file, (addr), (nr))) \
1004                 goto end_coredump;
1005 #define DUMP_SEEK(off)  \
1006         if (!dump_seek(file, (off))) \
1007                 goto end_coredump;
1008
1009 static int writenote(struct memelfnote *men, struct file *file)
1010 {
1011         struct elf_note en;
1012
1013         en.n_namesz = strlen(men->name);
1014         en.n_descsz = men->datasz;
1015         en.n_type = men->type;
1016
1017         DUMP_WRITE(&en, sizeof(en));
1018         DUMP_WRITE(men->name, en.n_namesz);
1019         /* XXX - cast from long long to long to avoid need for libgcc.a */
1020         DUMP_SEEK(roundup((unsigned long)file->f_pos, 4));      /* XXX */
1021         DUMP_WRITE(men->data, men->datasz);
1022         DUMP_SEEK(roundup((unsigned long)file->f_pos, 4));      /* XXX */
1023
1024         return 1;
1025
1026 end_coredump:
1027         return 0;
1028 }
1029 #undef DUMP_WRITE
1030 #undef DUMP_SEEK
1031
1032 #define DUMP_WRITE(addr, nr)    \
1033         if (!dump_write(file, (addr), (nr))) \
1034                 goto end_coredump;
1035 #define DUMP_SEEK(off)  \
1036         if (!dump_seek(file, (off))) \
1037                 goto end_coredump;
1038
1039 /* Actual dumper.
1040  *
1041  * This is a two-pass process; first we find the offsets of the bits,
1042  * and then they are actually written out.  If we run out of core limit
1043  * we just truncate.
1044  */
1045 static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
1046 {
1047         int has_dumped = 0;
1048         mm_segment_t fs;
1049         int segs;
1050         int i;
1051         size_t size;
1052         struct vm_area_struct *vma;
1053         struct elfhdr elf;
1054         off_t offset = 0, dataoff;
1055         int limit = current->signal->rlim[RLIMIT_CORE].rlim_cur;
1056         int numnote = 4;
1057         struct memelfnote notes[4];
1058         struct elf_prstatus prstatus;   /* NT_PRSTATUS */
1059         elf_fpregset_t fpu;             /* NT_PRFPREG */
1060         struct elf_prpsinfo psinfo;     /* NT_PRPSINFO */
1061
1062         /* Count what's needed to dump, up to the limit of coredump size. */
1063         segs = 0;
1064         size = 0;
1065         for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
1066                 if (maydump(vma))
1067                 {
1068                         int sz = vma->vm_end-vma->vm_start;
1069
1070                         if (size+sz >= limit)
1071                                 break;
1072                         else
1073                                 size += sz;
1074                 }
1075
1076                 segs++;
1077         }
1078 #ifdef DEBUG
1079         printk("irix_core_dump: %d segs taking %d bytes\n", segs, size);
1080 #endif
1081
1082         /* Set up header. */
1083         memcpy(elf.e_ident, ELFMAG, SELFMAG);
1084         elf.e_ident[EI_CLASS] = ELFCLASS32;
1085         elf.e_ident[EI_DATA] = ELFDATA2LSB;
1086         elf.e_ident[EI_VERSION] = EV_CURRENT;
1087         elf.e_ident[EI_OSABI] = ELF_OSABI;
1088         memset(elf.e_ident+EI_PAD, 0, EI_NIDENT-EI_PAD);
1089
1090         elf.e_type = ET_CORE;
1091         elf.e_machine = ELF_ARCH;
1092         elf.e_version = EV_CURRENT;
1093         elf.e_entry = 0;
1094         elf.e_phoff = sizeof(elf);
1095         elf.e_shoff = 0;
1096         elf.e_flags = 0;
1097         elf.e_ehsize = sizeof(elf);
1098         elf.e_phentsize = sizeof(struct elf_phdr);
1099         elf.e_phnum = segs+1;           /* Include notes. */
1100         elf.e_shentsize = 0;
1101         elf.e_shnum = 0;
1102         elf.e_shstrndx = 0;
1103
1104         fs = get_fs();
1105         set_fs(KERNEL_DS);
1106
1107         has_dumped = 1;
1108         current->flags |= PF_DUMPCORE;
1109
1110         DUMP_WRITE(&elf, sizeof(elf));
1111         offset += sizeof(elf);                          /* Elf header. */
1112         offset += (segs+1) * sizeof(struct elf_phdr);   /* Program headers. */
1113
1114         /* Set up the notes in similar form to SVR4 core dumps made
1115          * with info from their /proc.
1116          */
1117         memset(&psinfo, 0, sizeof(psinfo));
1118         memset(&prstatus, 0, sizeof(prstatus));
1119
1120         notes[0].name = "CORE";
1121         notes[0].type = NT_PRSTATUS;
1122         notes[0].datasz = sizeof(prstatus);
1123         notes[0].data = &prstatus;
1124         prstatus.pr_info.si_signo = prstatus.pr_cursig = signr;
1125         prstatus.pr_sigpend = current->pending.signal.sig[0];
1126         prstatus.pr_sighold = current->blocked.sig[0];
1127         psinfo.pr_pid = prstatus.pr_pid = current->pid;
1128         psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid;
1129         psinfo.pr_pgrp = prstatus.pr_pgrp = process_group(current);
1130         psinfo.pr_sid = prstatus.pr_sid = current->signal->session;
1131         if (current->pid == current->tgid) {
1132                 /*
1133                  * This is the record for the group leader.  Add in the
1134                  * cumulative times of previous dead threads.  This total
1135                  * won't include the time of each live thread whose state
1136                  * is included in the core dump.  The final total reported
1137                  * to our parent process when it calls wait4 will include
1138                  * those sums as well as the little bit more time it takes
1139                  * this and each other thread to finish dying after the
1140                  * core dump synchronization phase.
1141                  */
1142                 jiffies_to_timeval(current->utime + current->signal->utime,
1143                                    &prstatus.pr_utime);
1144                 jiffies_to_timeval(current->stime + current->signal->stime,
1145                                    &prstatus.pr_stime);
1146         } else {
1147                 jiffies_to_timeval(current->utime, &prstatus.pr_utime);
1148                 jiffies_to_timeval(current->stime, &prstatus.pr_stime);
1149         }
1150         jiffies_to_timeval(current->signal->cutime, &prstatus.pr_cutime);
1151         jiffies_to_timeval(current->signal->cstime, &prstatus.pr_cstime);
1152
1153         if (sizeof(elf_gregset_t) != sizeof(struct pt_regs)) {
1154                 printk("sizeof(elf_gregset_t) (%d) != sizeof(struct pt_regs) "
1155                        "(%d)\n", sizeof(elf_gregset_t), sizeof(struct pt_regs));
1156         } else {
1157                 *(struct pt_regs *)&prstatus.pr_reg = *regs;
1158         }
1159
1160         notes[1].name = "CORE";
1161         notes[1].type = NT_PRPSINFO;
1162         notes[1].datasz = sizeof(psinfo);
1163         notes[1].data = &psinfo;
1164         i = current->state ? ffz(~current->state) + 1 : 0;
1165         psinfo.pr_state = i;
1166         psinfo.pr_sname = (i < 0 || i > 5) ? '.' : "RSDZTD"[i];
1167         psinfo.pr_zomb = psinfo.pr_sname == 'Z';
1168         psinfo.pr_nice = task_nice(current);
1169         psinfo.pr_flag = current->flags;
1170         psinfo.pr_uid = current->uid;
1171         psinfo.pr_gid = current->gid;
1172         {
1173                 int i, len;
1174
1175                 set_fs(fs);
1176
1177                 len = current->mm->arg_end - current->mm->arg_start;
1178                 len = len >= ELF_PRARGSZ ? ELF_PRARGSZ : len;
1179                 copy_from_user(&psinfo.pr_psargs,
1180                                (const char *)current->mm->arg_start, len);
1181                 for(i = 0; i < len; i++)
1182                         if (psinfo.pr_psargs[i] == 0)
1183                                 psinfo.pr_psargs[i] = ' ';
1184                 psinfo.pr_psargs[len] = 0;
1185
1186                 set_fs(KERNEL_DS);
1187         }
1188         strlcpy(psinfo.pr_fname, current->comm, sizeof(psinfo.pr_fname));
1189
1190         notes[2].name = "CORE";
1191         notes[2].type = NT_TASKSTRUCT;
1192         notes[2].datasz = sizeof(*current);
1193         notes[2].data = current;
1194
1195         /* Try to dump the FPU. */
1196         prstatus.pr_fpvalid = dump_fpu (regs, &fpu);
1197         if (!prstatus.pr_fpvalid) {
1198                 numnote--;
1199         } else {
1200                 notes[3].name = "CORE";
1201                 notes[3].type = NT_PRFPREG;
1202                 notes[3].datasz = sizeof(fpu);
1203                 notes[3].data = &fpu;
1204         }
1205
1206         /* Write notes phdr entry. */
1207         {
1208                 struct elf_phdr phdr;
1209                 int sz = 0;
1210
1211                 for(i = 0; i < numnote; i++)
1212                         sz += notesize(&notes[i]);
1213
1214                 phdr.p_type = PT_NOTE;
1215                 phdr.p_offset = offset;
1216                 phdr.p_vaddr = 0;
1217                 phdr.p_paddr = 0;
1218                 phdr.p_filesz = sz;
1219                 phdr.p_memsz = 0;
1220                 phdr.p_flags = 0;
1221                 phdr.p_align = 0;
1222
1223                 offset += phdr.p_filesz;
1224                 DUMP_WRITE(&phdr, sizeof(phdr));
1225         }
1226
1227         /* Page-align dumped data. */
1228         dataoff = offset = roundup(offset, PAGE_SIZE);
1229
1230         /* Write program headers for segments dump. */
1231         for(vma = current->mm->mmap, i = 0;
1232                 i < segs && vma != NULL; vma = vma->vm_next) {
1233                 struct elf_phdr phdr;
1234                 size_t sz;
1235
1236                 i++;
1237
1238                 sz = vma->vm_end - vma->vm_start;
1239
1240                 phdr.p_type = PT_LOAD;
1241                 phdr.p_offset = offset;
1242                 phdr.p_vaddr = vma->vm_start;
1243                 phdr.p_paddr = 0;
1244                 phdr.p_filesz = maydump(vma) ? sz : 0;
1245                 phdr.p_memsz = sz;
1246                 offset += phdr.p_filesz;
1247                 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
1248                 if (vma->vm_flags & VM_WRITE) phdr.p_flags |= PF_W;
1249                 if (vma->vm_flags & VM_EXEC) phdr.p_flags |= PF_X;
1250                 phdr.p_align = PAGE_SIZE;
1251
1252                 DUMP_WRITE(&phdr, sizeof(phdr));
1253         }
1254
1255         for(i = 0; i < numnote; i++)
1256                 if (!writenote(&notes[i], file))
1257                         goto end_coredump;
1258
1259         set_fs(fs);
1260
1261         DUMP_SEEK(dataoff);
1262
1263         for(i = 0, vma = current->mm->mmap;
1264             i < segs && vma != NULL;
1265             vma = vma->vm_next) {
1266                 unsigned long addr = vma->vm_start;
1267                 unsigned long len = vma->vm_end - vma->vm_start;
1268
1269                 if (!maydump(vma))
1270                         continue;
1271                 i++;
1272 #ifdef DEBUG
1273                 printk("elf_core_dump: writing %08lx %lx\n", addr, len);
1274 #endif
1275                 DUMP_WRITE((void *)addr, len);
1276         }
1277
1278         if ((off_t) file->f_pos != offset) {
1279                 /* Sanity check. */
1280                 printk("elf_core_dump: file->f_pos (%ld) != offset (%ld)\n",
1281                        (off_t) file->f_pos, offset);
1282         }
1283
1284 end_coredump:
1285         set_fs(fs);
1286         return has_dumped;
1287 }
1288
1289 static int __init init_irix_binfmt(void)
1290 {
1291         return register_binfmt(&irix_format);
1292 }
1293
1294 static void __exit exit_irix_binfmt(void)
1295 {
1296         /* Remove the IRIX ELF loaders. */
1297         unregister_binfmt(&irix_format);
1298 }
1299
1300 module_init(init_irix_binfmt)
1301 module_exit(exit_irix_binfmt)