summaryrefslogtreecommitdiffstats
path: root/fs/binfmt_flat.c
diff options
context:
space:
mode:
authorNicolas Pitre <nicolas.pitre@linaro.org>2016-07-24 11:30:15 -0400
committerGreg Ungerer <gerg@linux-m68k.org>2016-07-25 02:51:30 -0400
commit13c3f50c914e6a51d11e1aba4a85c2223e197e13 (patch)
treefb490a294f003989a12d4217440322b7ca8ba0eb /fs/binfmt_flat.c
parentf987e5a13c55e65df6a03677dda38c8e5fb47029 (diff)
binfmt_flat: assorted cleanups
Remove excessive casts, do some code grouping, fix most important checkpatch.pl complaints, etc. No functional changes. Signed-off-by: Nicolas Pitre <nico@linaro.org> Reviewed-by: Greg Ungerer <gerg@linux-m68k.org> Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
Diffstat (limited to 'fs/binfmt_flat.c')
-rw-r--r--fs/binfmt_flat.c230
1 files changed, 109 insertions, 121 deletions
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index caf9e39bb82b..892dba62bf2e 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -15,7 +15,6 @@
15 * JAN/99 -- coded full program relocation (gerg@snapgear.com) 15 * JAN/99 -- coded full program relocation (gerg@snapgear.com)
16 */ 16 */
17 17
18#include <linux/export.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/sched.h> 19#include <linux/sched.h>
21#include <linux/mm.h> 20#include <linux/mm.h>
@@ -25,8 +24,6 @@
25#include <linux/string.h> 24#include <linux/string.h>
26#include <linux/fs.h> 25#include <linux/fs.h>
27#include <linux/file.h> 26#include <linux/file.h>
28#include <linux/stat.h>
29#include <linux/fcntl.h>
30#include <linux/ptrace.h> 27#include <linux/ptrace.h>
31#include <linux/user.h> 28#include <linux/user.h>
32#include <linux/slab.h> 29#include <linux/slab.h>
@@ -34,10 +31,9 @@
34#include <linux/personality.h> 31#include <linux/personality.h>
35#include <linux/init.h> 32#include <linux/init.h>
36#include <linux/flat.h> 33#include <linux/flat.h>
37#include <linux/syscalls.h> 34#include <linux/uaccess.h>
38 35
39#include <asm/byteorder.h> 36#include <asm/byteorder.h>
40#include <asm/uaccess.h>
41#include <asm/unaligned.h> 37#include <asm/unaligned.h>
42#include <asm/cacheflush.h> 38#include <asm/cacheflush.h>
43#include <asm/page.h> 39#include <asm/page.h>
@@ -80,7 +76,7 @@ struct lib_info {
80 unsigned long text_len; /* Length of text segment */ 76 unsigned long text_len; /* Length of text segment */
81 unsigned long entry; /* Start address for this module */ 77 unsigned long entry; /* Start address for this module */
82 unsigned long build_date; /* When this one was compiled */ 78 unsigned long build_date; /* When this one was compiled */
83 short loaded; /* Has this library been loaded? */ 79 bool loaded; /* Has this library been loaded? */
84 } lib_list[MAX_SHARED_LIBS]; 80 } lib_list[MAX_SHARED_LIBS];
85}; 81};
86 82
@@ -107,8 +103,8 @@ static struct linux_binfmt flat_format = {
107static int flat_core_dump(struct coredump_params *cprm) 103static int flat_core_dump(struct coredump_params *cprm)
108{ 104{
109 printk("Process %s:%d received signr %d and should have core dumped\n", 105 printk("Process %s:%d received signr %d and should have core dumped\n",
110 current->comm, current->pid, (int) cprm->siginfo->si_signo); 106 current->comm, current->pid, cprm->siginfo->si_signo);
111 return(1); 107 return 1;
112} 108}
113 109
114/****************************************************************************/ 110/****************************************************************************/
@@ -120,11 +116,11 @@ static int flat_core_dump(struct coredump_params *cprm)
120 116
121static unsigned long create_flat_tables( 117static unsigned long create_flat_tables(
122 unsigned long pp, 118 unsigned long pp,
123 struct linux_binprm * bprm) 119 struct linux_binprm *bprm)
124{ 120{
125 unsigned long *argv,*envp; 121 unsigned long *argv, *envp;
126 unsigned long * sp; 122 unsigned long *sp;
127 char * p = (char*)pp; 123 char *p = (char *)pp;
128 int argc = bprm->argc; 124 int argc = bprm->argc;
129 int envc = bprm->envc; 125 int envc = bprm->envc;
130 char uninitialized_var(dummy); 126 char uninitialized_var(dummy);
@@ -142,7 +138,7 @@ static unsigned long create_flat_tables(
142 138
143 put_user(argc, sp); 139 put_user(argc, sp);
144 current->mm->arg_start = (unsigned long) p; 140 current->mm->arg_start = (unsigned long) p;
145 while (argc-->0) { 141 while (argc-- > 0) {
146 put_user((unsigned long) p, argv++); 142 put_user((unsigned long) p, argv++);
147 do { 143 do {
148 get_user(dummy, p); p++; 144 get_user(dummy, p); p++;
@@ -150,7 +146,7 @@ static unsigned long create_flat_tables(
150 } 146 }
151 put_user((unsigned long) NULL, argv); 147 put_user((unsigned long) NULL, argv);
152 current->mm->arg_end = current->mm->env_start = (unsigned long) p; 148 current->mm->arg_end = current->mm->env_start = (unsigned long) p;
153 while (envc-->0) { 149 while (envc-- > 0) {
154 put_user((unsigned long)p, envp); envp++; 150 put_user((unsigned long)p, envp); envp++;
155 do { 151 do {
156 get_user(dummy, p); p++; 152 get_user(dummy, p); p++;
@@ -190,7 +186,7 @@ static int decompress_exec(
190 loff_t fpos; 186 loff_t fpos;
191 int ret, retval; 187 int ret, retval;
192 188
193 DBG_FLT("decompress_exec(offset=%x,buf=%x,len=%x)\n",(int)offset, (int)dst, (int)len); 189 DBG_FLT("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len);
194 190
195 memset(&strm, 0, sizeof(strm)); 191 memset(&strm, 0, sizeof(strm));
196 strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); 192 strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
@@ -243,7 +239,7 @@ static int decompress_exec(
243 ret = 10; 239 ret = 10;
244 if (buf[3] & EXTRA_FIELD) { 240 if (buf[3] & EXTRA_FIELD) {
245 ret += 2 + buf[10] + (buf[11] << 8); 241 ret += 2 + buf[10] + (buf[11] << 8);
246 if (unlikely(LBUFSIZE <= ret)) { 242 if (unlikely(ret >= LBUFSIZE)) {
247 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); 243 DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n");
248 goto out_free_buf; 244 goto out_free_buf;
249 } 245 }
@@ -251,7 +247,7 @@ static int decompress_exec(
251 if (buf[3] & ORIG_NAME) { 247 if (buf[3] & ORIG_NAME) {
252 while (ret < LBUFSIZE && buf[ret++] != 0) 248 while (ret < LBUFSIZE && buf[ret++] != 0)
253 ; 249 ;
254 if (unlikely(LBUFSIZE == ret)) { 250 if (unlikely(ret == LBUFSIZE)) {
255 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); 251 DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n");
256 goto out_free_buf; 252 goto out_free_buf;
257 } 253 }
@@ -259,7 +255,7 @@ static int decompress_exec(
259 if (buf[3] & COMMENT) { 255 if (buf[3] & COMMENT) {
260 while (ret < LBUFSIZE && buf[ret++] != 0) 256 while (ret < LBUFSIZE && buf[ret++] != 0)
261 ; 257 ;
262 if (unlikely(LBUFSIZE == ret)) { 258 if (unlikely(ret == LBUFSIZE)) {
263 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); 259 DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n");
264 goto out_free_buf; 260 goto out_free_buf;
265 } 261 }
@@ -327,17 +323,17 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
327 r &= 0x00ffffff; /* Trim ID off here */ 323 r &= 0x00ffffff; /* Trim ID off here */
328 } 324 }
329 if (id >= MAX_SHARED_LIBS) { 325 if (id >= MAX_SHARED_LIBS) {
330 printk("BINFMT_FLAT: reference 0x%x to shared library %d", 326 printk("BINFMT_FLAT: reference 0x%lx to shared library %d",
331 (unsigned) r, id); 327 r, id);
332 goto failed; 328 goto failed;
333 } 329 }
334 if (curid != id) { 330 if (curid != id) {
335 if (internalp) { 331 if (internalp) {
336 printk("BINFMT_FLAT: reloc address 0x%x not in same module " 332 printk("BINFMT_FLAT: reloc address 0x%lx not in same module "
337 "(%d != %d)", (unsigned) r, curid, id); 333 "(%d != %d)", r, curid, id);
338 goto failed; 334 goto failed;
339 } else if ( ! p->lib_list[id].loaded && 335 } else if (!p->lib_list[id].loaded &&
340 load_flat_shared_library(id, p) < 0) { 336 load_flat_shared_library(id, p) < 0) {
341 printk("BINFMT_FLAT: failed to load library %d", id); 337 printk("BINFMT_FLAT: failed to load library %d", id);
342 goto failed; 338 goto failed;
343 } 339 }
@@ -358,8 +354,8 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
358 text_len = p->lib_list[id].text_len; 354 text_len = p->lib_list[id].text_len;
359 355
360 if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { 356 if (!flat_reloc_valid(r, start_brk - start_data + text_len)) {
361 printk("BINFMT_FLAT: reloc outside program 0x%x (0 - 0x%x/0x%x)", 357 printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)",
362 (int) r,(int)(start_brk-start_data+text_len),(int)text_len); 358 r, start_brk-start_data+text_len, text_len);
363 goto failed; 359 goto failed;
364 } 360 }
365 361
@@ -369,7 +365,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp)
369 addr = r - text_len + start_data; 365 addr = r - text_len + start_data;
370 366
371 /* Range checked already above so doing the range tests is redundant...*/ 367 /* Range checked already above so doing the range tests is redundant...*/
372 return(addr); 368 return addr;
373 369
374failed: 370failed:
375 printk(", killing %s!\n", current->comm); 371 printk(", killing %s!\n", current->comm);
@@ -383,11 +379,11 @@ failed:
383static void old_reloc(unsigned long rl) 379static void old_reloc(unsigned long rl)
384{ 380{
385#ifdef DEBUG 381#ifdef DEBUG
386 char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; 382 static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" };
387#endif 383#endif
388 flat_v2_reloc_t r; 384 flat_v2_reloc_t r;
389 unsigned long *ptr; 385 unsigned long *ptr;
390 386
391 r.value = rl; 387 r.value = rl;
392#if defined(CONFIG_COLDFIRE) 388#if defined(CONFIG_COLDFIRE)
393 ptr = (unsigned long *) (current->mm->start_code + r.reloc.offset); 389 ptr = (unsigned long *) (current->mm->start_code + r.reloc.offset);
@@ -397,10 +393,10 @@ static void old_reloc(unsigned long rl)
397 393
398#ifdef DEBUG 394#ifdef DEBUG
399 printk("Relocation of variable at DATASEG+%x " 395 printk("Relocation of variable at DATASEG+%x "
400 "(address %p, currently %x) into segment %s\n", 396 "(address %p, currently %lx) into segment %s\n",
401 r.reloc.offset, ptr, (int)*ptr, segment[r.reloc.type]); 397 r.reloc.offset, ptr, *ptr, segment[r.reloc.type]);
402#endif 398#endif
403 399
404 switch (r.reloc.type) { 400 switch (r.reloc.type) {
405 case OLD_FLAT_RELOC_TYPE_TEXT: 401 case OLD_FLAT_RELOC_TYPE_TEXT:
406 *ptr += current->mm->start_code; 402 *ptr += current->mm->start_code;
@@ -417,27 +413,25 @@ static void old_reloc(unsigned long rl)
417 } 413 }
418 414
419#ifdef DEBUG 415#ifdef DEBUG
420 printk("Relocation became %x\n", (int)*ptr); 416 printk("Relocation became %lx\n", *ptr);
421#endif 417#endif
422} 418}
423 419
424/****************************************************************************/ 420/****************************************************************************/
425 421
426static int load_flat_file(struct linux_binprm * bprm, 422static int load_flat_file(struct linux_binprm *bprm,
427 struct lib_info *libinfo, int id, unsigned long *extra_stack) 423 struct lib_info *libinfo, int id, unsigned long *extra_stack)
428{ 424{
429 struct flat_hdr * hdr; 425 struct flat_hdr *hdr;
430 unsigned long textpos = 0, datapos = 0, result; 426 unsigned long textpos, datapos, realdatastart;
431 unsigned long realdatastart = 0; 427 unsigned long text_len, data_len, bss_len, stack_len, full_data, flags;
432 unsigned long text_len, data_len, bss_len, stack_len, flags; 428 unsigned long len, memp, memp_size, extra, rlim;
433 unsigned long full_data; 429 unsigned long *reloc, *rp;
434 unsigned long len, memp = 0;
435 unsigned long memp_size, extra, rlim;
436 unsigned long *reloc = 0, *rp;
437 struct inode *inode; 430 struct inode *inode;
438 int i, rev, relocs = 0; 431 int i, rev, relocs;
439 loff_t fpos; 432 loff_t fpos;
440 unsigned long start_code, end_code; 433 unsigned long start_code, end_code;
434 ssize_t result;
441 int ret; 435 int ret;
442 436
443 hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */ 437 hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */
@@ -478,11 +472,11 @@ static int load_flat_file(struct linux_binprm * bprm,
478 ret = -ENOEXEC; 472 ret = -ENOEXEC;
479 goto err; 473 goto err;
480 } 474 }
481 475
482 /* Don't allow old format executables to use shared libraries */ 476 /* Don't allow old format executables to use shared libraries */
483 if (rev == OLD_FLAT_VERSION && id != 0) { 477 if (rev == OLD_FLAT_VERSION && id != 0) {
484 printk("BINFMT_FLAT: shared libraries are not available before rev 0x%x\n", 478 printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n",
485 (int) FLAT_VERSION); 479 FLAT_VERSION);
486 ret = -ENOEXEC; 480 ret = -ENOEXEC;
487 goto err; 481 goto err;
488 } 482 }
@@ -517,11 +511,9 @@ static int load_flat_file(struct linux_binprm * bprm,
517 511
518 /* Flush all traces of the currently running executable */ 512 /* Flush all traces of the currently running executable */
519 if (id == 0) { 513 if (id == 0) {
520 result = flush_old_exec(bprm); 514 ret = flush_old_exec(bprm);
521 if (result) { 515 if (ret)
522 ret = result;
523 goto err; 516 goto err;
524 }
525 517
526 /* OK, This is the point of no return */ 518 /* OK, This is the point of no return */
527 set_personality(PER_LINUX_32BIT); 519 set_personality(PER_LINUX_32BIT);
@@ -549,38 +541,38 @@ static int load_flat_file(struct linux_binprm * bprm,
549 textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, 541 textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC,
550 MAP_PRIVATE|MAP_EXECUTABLE, 0); 542 MAP_PRIVATE|MAP_EXECUTABLE, 0);
551 if (!textpos || IS_ERR_VALUE(textpos)) { 543 if (!textpos || IS_ERR_VALUE(textpos)) {
552 if (!textpos)
553 textpos = (unsigned long) -ENOMEM;
554 printk("Unable to mmap process text, errno %d\n", (int)-textpos);
555 ret = textpos; 544 ret = textpos;
545 if (!textpos)
546 ret = -ENOMEM;
547 printk("Unable to mmap process text, errno %d\n", ret);
556 goto err; 548 goto err;
557 } 549 }
558 550
559 len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); 551 len = data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
560 len = PAGE_ALIGN(len); 552 len = PAGE_ALIGN(len);
561 realdatastart = vm_mmap(0, 0, len, 553 realdatastart = vm_mmap(NULL, 0, len,
562 PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0); 554 PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 0);
563 555
564 if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) { 556 if (realdatastart == 0 || IS_ERR_VALUE(realdatastart)) {
557 ret = realdatastart;
565 if (!realdatastart) 558 if (!realdatastart)
566 realdatastart = (unsigned long) -ENOMEM; 559 ret = -ENOMEM;
567 printk("Unable to allocate RAM for process data, errno %d\n", 560 printk("Unable to allocate RAM for process data, "
568 (int)-realdatastart); 561 "errno %d\n", ret);
569 vm_munmap(textpos, text_len); 562 vm_munmap(textpos, text_len);
570 ret = realdatastart;
571 goto err; 563 goto err;
572 } 564 }
573 datapos = ALIGN(realdatastart + 565 datapos = ALIGN(realdatastart +
574 MAX_SHARED_LIBS * sizeof(unsigned long), 566 MAX_SHARED_LIBS * sizeof(unsigned long),
575 FLAT_DATA_ALIGN); 567 FLAT_DATA_ALIGN);
576 568
577 DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n", 569 DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n",
578 (int)(data_len + bss_len + stack_len), (int)datapos); 570 data_len + bss_len + stack_len, datapos);
579 571
580 fpos = ntohl(hdr->data_start); 572 fpos = ntohl(hdr->data_start);
581#ifdef CONFIG_BINFMT_ZFLAT 573#ifdef CONFIG_BINFMT_ZFLAT
582 if (flags & FLAT_FLAG_GZDATA) { 574 if (flags & FLAT_FLAG_GZDATA) {
583 result = decompress_exec(bprm, fpos, (char *) datapos, 575 result = decompress_exec(bprm, fpos, (char *)datapos,
584 full_data, 0); 576 full_data, 0);
585 } else 577 } else
586#endif 578#endif
@@ -589,29 +581,30 @@ static int load_flat_file(struct linux_binprm * bprm,
589 full_data); 581 full_data);
590 } 582 }
591 if (IS_ERR_VALUE(result)) { 583 if (IS_ERR_VALUE(result)) {
592 printk("Unable to read data+bss, errno %d\n", (int)-result); 584 ret = result;
585 printk("Unable to read data+bss, errno %d\n", ret);
593 vm_munmap(textpos, text_len); 586 vm_munmap(textpos, text_len);
594 vm_munmap(realdatastart, len); 587 vm_munmap(realdatastart, len);
595 ret = result;
596 goto err; 588 goto err;
597 } 589 }
598 590
599 reloc = (unsigned long *) (datapos+(ntohl(hdr->reloc_start)-text_len)); 591 reloc = (unsigned long *)
592 (datapos + (ntohl(hdr->reloc_start) - text_len));
600 memp = realdatastart; 593 memp = realdatastart;
601 memp_size = len; 594 memp_size = len;
602 } else { 595 } else {
603 596
604 len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long); 597 len = text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long);
605 len = PAGE_ALIGN(len); 598 len = PAGE_ALIGN(len);
606 textpos = vm_mmap(0, 0, len, 599 textpos = vm_mmap(NULL, 0, len,
607 PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0); 600 PROT_READ | PROT_EXEC | PROT_WRITE, MAP_PRIVATE, 0);
608 601
609 if (!textpos || IS_ERR_VALUE(textpos)) { 602 if (!textpos || IS_ERR_VALUE(textpos)) {
610 if (!textpos)
611 textpos = (unsigned long) -ENOMEM;
612 printk("Unable to allocate RAM for process text/data, errno %d\n",
613 (int)-textpos);
614 ret = textpos; 603 ret = textpos;
604 if (!textpos)
605 ret = -ENOMEM;
606 printk("Unable to allocate RAM for process text/data, "
607 "errno %d\n", ret);
615 goto err; 608 goto err;
616 } 609 }
617 610
@@ -629,10 +622,10 @@ static int load_flat_file(struct linux_binprm * bprm,
629 * load it all in and treat it like a RAM load from now on 622 * load it all in and treat it like a RAM load from now on
630 */ 623 */
631 if (flags & FLAT_FLAG_GZIP) { 624 if (flags & FLAT_FLAG_GZIP) {
632 result = decompress_exec(bprm, sizeof (struct flat_hdr), 625 result = decompress_exec(bprm, sizeof(struct flat_hdr),
633 (((char *) textpos) + sizeof (struct flat_hdr)), 626 (((char *)textpos) + sizeof(struct flat_hdr)),
634 (text_len + full_data 627 (text_len + full_data
635 - sizeof (struct flat_hdr)), 628 - sizeof(struct flat_hdr)),
636 0); 629 0);
637 memmove((void *) datapos, (void *) realdatastart, 630 memmove((void *) datapos, (void *) realdatastart,
638 full_data); 631 full_data);
@@ -641,8 +634,7 @@ static int load_flat_file(struct linux_binprm * bprm,
641 if (!IS_ERR_VALUE(result)) 634 if (!IS_ERR_VALUE(result))
642 result = decompress_exec(bprm, text_len, (char *) datapos, 635 result = decompress_exec(bprm, text_len, (char *) datapos,
643 full_data, 0); 636 full_data, 0);
644 } 637 } else
645 else
646#endif 638#endif
647 { 639 {
648 result = read_code(bprm->file, textpos, 0, text_len); 640 result = read_code(bprm->file, textpos, 0, text_len);
@@ -652,21 +644,19 @@ static int load_flat_file(struct linux_binprm * bprm,
652 full_data); 644 full_data);
653 } 645 }
654 if (IS_ERR_VALUE(result)) { 646 if (IS_ERR_VALUE(result)) {
655 printk("Unable to read code+data+bss, errno %d\n",(int)-result); 647 ret = result;
648 printk("Unable to read code+data+bss, errno %d\n", ret);
656 vm_munmap(textpos, text_len + data_len + extra + 649 vm_munmap(textpos, text_len + data_len + extra +
657 MAX_SHARED_LIBS * sizeof(unsigned long)); 650 MAX_SHARED_LIBS * sizeof(unsigned long));
658 ret = result;
659 goto err; 651 goto err;
660 } 652 }
661 } 653 }
662 654
663 if (flags & FLAT_FLAG_KTRACE) 655 start_code = textpos + sizeof(struct flat_hdr);
664 printk("Mapping is %x, Entry point is %x, data_start is %x\n", 656 end_code = textpos + text_len;
665 (int)textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); 657 text_len -= sizeof(struct flat_hdr); /* the real code len */
666 658
667 /* The main program needs a little extra setup in the task structure */ 659 /* The main program needs a little extra setup in the task structure */
668 start_code = textpos + sizeof (struct flat_hdr);
669 end_code = textpos + text_len;
670 if (id == 0) { 660 if (id == 0) {
671 current->mm->start_code = start_code; 661 current->mm->start_code = start_code;
672 current->mm->end_code = end_code; 662 current->mm->end_code = end_code;
@@ -684,16 +674,14 @@ static int load_flat_file(struct linux_binprm * bprm,
684 current->mm->context.end_brk = memp + memp_size - stack_len; 674 current->mm->context.end_brk = memp + memp_size - stack_len;
685 } 675 }
686 676
687 if (flags & FLAT_FLAG_KTRACE) 677 if (flags & FLAT_FLAG_KTRACE) {
688 printk("%s %s: TEXT=%x-%x DATA=%x-%x BSS=%x-%x\n", 678 printk("Mapping is %lx, Entry point is %x, data_start is %x\n",
689 id ? "Lib" : "Load", bprm->filename, 679 textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start));
690 (int) start_code, (int) end_code, 680 printk("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n",
691 (int) datapos, 681 id ? "Lib" : "Load", bprm->filename,
692 (int) (datapos + data_len), 682 start_code, end_code, datapos, datapos + data_len,
693 (int) (datapos + data_len), 683 datapos + data_len, (datapos + data_len + bss_len + 3) & ~3);
694 (int) (((datapos + data_len + bss_len) + 3) & ~3)); 684 }
695
696 text_len -= sizeof(struct flat_hdr); /* the real code len */
697 685
698 /* Store the current module values into the global library structure */ 686 /* Store the current module values into the global library structure */
699 libinfo->lib_list[id].start_code = start_code; 687 libinfo->lib_list[id].start_code = start_code;
@@ -703,7 +691,7 @@ static int load_flat_file(struct linux_binprm * bprm,
703 libinfo->lib_list[id].loaded = 1; 691 libinfo->lib_list[id].loaded = 1;
704 libinfo->lib_list[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos; 692 libinfo->lib_list[id].entry = (0x00ffffff & ntohl(hdr->entry)) + textpos;
705 libinfo->lib_list[id].build_date = ntohl(hdr->build_date); 693 libinfo->lib_list[id].build_date = ntohl(hdr->build_date);
706 694
707 /* 695 /*
708 * We just load the allocations into some temporary memory to 696 * We just load the allocations into some temporary memory to
709 * help simplify all this mumbo jumbo 697 * help simplify all this mumbo jumbo
@@ -743,14 +731,16 @@ static int load_flat_file(struct linux_binprm * bprm,
743 */ 731 */
744 if (rev > OLD_FLAT_VERSION) { 732 if (rev > OLD_FLAT_VERSION) {
745 unsigned long persistent = 0; 733 unsigned long persistent = 0;
746 for (i=0; i < relocs; i++) { 734 for (i = 0; i < relocs; i++) {
747 unsigned long addr, relval; 735 unsigned long addr, relval;
748 736
749 /* Get the address of the pointer to be 737 /*
750 relocated (of course, the address has to be 738 * Get the address of the pointer to be
751 relocated first). */ 739 * relocated (of course, the address has to be
740 * relocated first).
741 */
752 relval = ntohl(reloc[i]); 742 relval = ntohl(reloc[i]);
753 if (flat_set_persistent (relval, &persistent)) 743 if (flat_set_persistent(relval, &persistent))
754 continue; 744 continue;
755 addr = flat_get_relocate_addr(relval); 745 addr = flat_get_relocate_addr(relval);
756 rp = (unsigned long *) calc_reloc(addr, libinfo, id, 1); 746 rp = (unsigned long *) calc_reloc(addr, libinfo, id, 1);
@@ -780,14 +770,14 @@ static int load_flat_file(struct linux_binprm * bprm,
780 } 770 }
781 } 771 }
782 } else { 772 } else {
783 for (i=0; i < relocs; i++) 773 for (i = 0; i < relocs; i++)
784 old_reloc(ntohl(reloc[i])); 774 old_reloc(ntohl(reloc[i]));
785 } 775 }
786 776
787 flush_icache_range(start_code, end_code); 777 flush_icache_range(start_code, end_code);
788 778
789 /* zero the BSS, BRK and stack areas */ 779 /* zero the BSS, BRK and stack areas */
790 memset((void*)(datapos + data_len), 0, bss_len + 780 memset((void *)(datapos + data_len), 0, bss_len +
791 (memp + memp_size - stack_len - /* end brk */ 781 (memp + memp_size - stack_len - /* end brk */
792 libinfo->lib_list[id].start_brk) + /* start brk */ 782 libinfo->lib_list[id].start_brk) + /* start brk */
793 stack_len); 783 stack_len);
@@ -846,7 +836,7 @@ out:
846 allow_write_access(bprm.file); 836 allow_write_access(bprm.file);
847 fput(bprm.file); 837 fput(bprm.file);
848 838
849 return(res); 839 return res;
850} 840}
851 841
852#endif /* CONFIG_BINFMT_SHARED_FLAT */ 842#endif /* CONFIG_BINFMT_SHARED_FLAT */
@@ -857,7 +847,7 @@ out:
857 * libraries. There is no binary dependent code anywhere else. 847 * libraries. There is no binary dependent code anywhere else.
858 */ 848 */
859 849
860static int load_flat_binary(struct linux_binprm * bprm) 850static int load_flat_binary(struct linux_binprm *bprm)
861{ 851{
862 struct lib_info libinfo; 852 struct lib_info libinfo;
863 struct pt_regs *regs = current_pt_regs(); 853 struct pt_regs *regs = current_pt_regs();
@@ -869,6 +859,7 @@ static int load_flat_binary(struct linux_binprm * bprm)
869 int i, j; 859 int i, j;
870 860
871 memset(&libinfo, 0, sizeof(libinfo)); 861 memset(&libinfo, 0, sizeof(libinfo));
862
872 /* 863 /*
873 * We have to add the size of our arguments to our stack size 864 * We have to add the size of our arguments to our stack size
874 * otherwise it's too easy for users to create stack overflows 865 * otherwise it's too easy for users to create stack overflows
@@ -881,33 +872,33 @@ static int load_flat_binary(struct linux_binprm * bprm)
881 stack_len += (bprm->argc + 1) * sizeof(char *); /* the argv array */ 872 stack_len += (bprm->argc + 1) * sizeof(char *); /* the argv array */
882 stack_len += (bprm->envc + 1) * sizeof(char *); /* the envp array */ 873 stack_len += (bprm->envc + 1) * sizeof(char *); /* the envp array */
883 stack_len += FLAT_STACK_ALIGN - 1; /* reserve for upcoming alignment */ 874 stack_len += FLAT_STACK_ALIGN - 1; /* reserve for upcoming alignment */
884 875
885 res = load_flat_file(bprm, &libinfo, 0, &stack_len); 876 res = load_flat_file(bprm, &libinfo, 0, &stack_len);
886 if (res < 0) 877 if (res < 0)
887 return res; 878 return res;
888 879
889 /* Update data segment pointers for all libraries */ 880 /* Update data segment pointers for all libraries */
890 for (i=0; i<MAX_SHARED_LIBS; i++) 881 for (i = 0; i < MAX_SHARED_LIBS; i++)
891 if (libinfo.lib_list[i].loaded) 882 if (libinfo.lib_list[i].loaded)
892 for (j=0; j<MAX_SHARED_LIBS; j++) 883 for (j = 0; j < MAX_SHARED_LIBS; j++)
893 (-(j+1))[(unsigned long *)(libinfo.lib_list[i].start_data)] = 884 (-(j+1))[(unsigned long *)(libinfo.lib_list[i].start_data)] =
894 (libinfo.lib_list[j].loaded)? 885 (libinfo.lib_list[j].loaded) ?
895 libinfo.lib_list[j].start_data:UNLOADED_LIB; 886 libinfo.lib_list[j].start_data : UNLOADED_LIB;
896 887
897 install_exec_creds(bprm); 888 install_exec_creds(bprm);
898 889
899 set_binfmt(&flat_format); 890 set_binfmt(&flat_format);
900 891
901 p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; 892 p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4;
902 DBG_FLT("p=%x\n", (int)p); 893 DBG_FLT("p=%lx\n", p);
903 894
904 /* copy the arg pages onto the stack, this could be more efficient :-) */ 895 /* copy the arg pages onto the stack, this could be more efficient :-) */
905 for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) 896 for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--)
906 * (char *) --p = 897 *(char *) --p =
907 ((char *) page_address(bprm->page[i/PAGE_SIZE]))[i % PAGE_SIZE]; 898 ((char *) page_address(bprm->page[i/PAGE_SIZE]))[i % PAGE_SIZE];
908 899
909 sp = (unsigned long *) create_flat_tables(p, bprm); 900 sp = (unsigned long *) create_flat_tables(p, bprm);
910 901
911 /* Fake some return addresses to ensure the call chain will 902 /* Fake some return addresses to ensure the call chain will
912 * initialise library in order for us. We are required to call 903 * initialise library in order for us. We are required to call
913 * lib 1 first, then 2, ... and finally the main program (id 0). 904 * lib 1 first, then 2, ... and finally the main program (id 0).
@@ -915,7 +906,7 @@ static int load_flat_binary(struct linux_binprm * bprm)
915 start_addr = libinfo.lib_list[0].entry; 906 start_addr = libinfo.lib_list[0].entry;
916 907
917#ifdef CONFIG_BINFMT_SHARED_FLAT 908#ifdef CONFIG_BINFMT_SHARED_FLAT
918 for (i = MAX_SHARED_LIBS-1; i>0; i--) { 909 for (i = MAX_SHARED_LIBS-1; i > 0; i--) {
919 if (libinfo.lib_list[i].loaded) { 910 if (libinfo.lib_list[i].loaded) {
920 /* Push previos first to call address */ 911 /* Push previos first to call address */
921 --sp; put_user(start_addr, sp); 912 --sp; put_user(start_addr, sp);
@@ -923,16 +914,16 @@ static int load_flat_binary(struct linux_binprm * bprm)
923 } 914 }
924 } 915 }
925#endif 916#endif
926 917
927 /* Stash our initial stack pointer into the mm structure */ 918 /* Stash our initial stack pointer into the mm structure */
928 current->mm->start_stack = (unsigned long )sp; 919 current->mm->start_stack = (unsigned long)sp;
929 920
930#ifdef FLAT_PLAT_INIT 921#ifdef FLAT_PLAT_INIT
931 FLAT_PLAT_INIT(regs); 922 FLAT_PLAT_INIT(regs);
932#endif 923#endif
933 DBG_FLT("start_thread(regs=0x%x, entry=0x%x, start_stack=0x%x)\n", 924
934 (int)regs, (int)start_addr, (int)current->mm->start_stack); 925 DBG_FLT("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
935 926 regs, start_addr, current->mm->start_stack);
936 start_thread(regs, start_addr, current->mm->start_stack); 927 start_thread(regs, start_addr, current->mm->start_stack);
937 928
938 return 0; 929 return 0;
@@ -945,9 +936,6 @@ static int __init init_flat_binfmt(void)
945 register_binfmt(&flat_format); 936 register_binfmt(&flat_format);
946 return 0; 937 return 0;
947} 938}
948
949/****************************************************************************/
950
951core_initcall(init_flat_binfmt); 939core_initcall(init_flat_binfmt);
952 940
953/****************************************************************************/ 941/****************************************************************************/