Revision 5fafdf24 linux-user/elfload.c

b/linux-user/elfload.c
577 577
    size = x86_stack_size;
578 578
    if (size < MAX_ARG_PAGES*TARGET_PAGE_SIZE)
579 579
        size = MAX_ARG_PAGES*TARGET_PAGE_SIZE;
580
    error = target_mmap(0, 
580
    error = target_mmap(0,
581 581
                        size + qemu_host_page_size,
582 582
                        PROT_READ | PROT_WRITE,
583 583
                        MAP_PRIVATE | MAP_ANONYMOUS,
......
637 637
           size must be known */
638 638
        if (qemu_real_host_page_size < qemu_host_page_size) {
639 639
            unsigned long end_addr, end_addr1;
640
            end_addr1 = (elf_bss + qemu_real_host_page_size - 1) & 
640
            end_addr1 = (elf_bss + qemu_real_host_page_size - 1) &
641 641
                ~(qemu_real_host_page_size - 1);
642 642
            end_addr = HOST_PAGE_ALIGN(elf_bss);
643 643
            if (end_addr1 < end_addr) {
......
695 695
        size *= n;
696 696
        if (size & 15)
697 697
            sp -= 16 - (size & 15);
698
        
698
       
699 699
#define NEW_AUX_ENT(id, val) do { \
700 700
            sp -= n; tputl(sp, val); \
701 701
            sp -= n; tputl(sp, id); \
......
718 718
        if (k_platform)
719 719
            NEW_AUX_ENT(AT_PLATFORM, u_platform);
720 720
#ifdef ARCH_DLINFO
721
	/* 
721
	/*
722 722
	 * ARCH_DLINFO must come last so platform specific code can enforce
723 723
	 * special alignment requirements on the AUXV if necessary (eg. PPC).
724 724
	 */
......
743 743
	unsigned long last_bss, elf_bss;
744 744
	unsigned long error;
745 745
	int i;
746
	
746

  
747 747
	elf_bss = 0;
748 748
	last_bss = 0;
749 749
	error = 0;
......
752 752
        bswap_ehdr(interp_elf_ex);
753 753
#endif
754 754
	/* First of all, some simple consistency checks */
755
	if ((interp_elf_ex->e_type != ET_EXEC && 
756
             interp_elf_ex->e_type != ET_DYN) || 
755
	if ((interp_elf_ex->e_type != ET_EXEC &&
756
             interp_elf_ex->e_type != ET_DYN) ||
757 757
	   !elf_check_arch(interp_elf_ex->e_machine)) {
758 758
		return ~0UL;
759 759
	}
760
	
760

  
761 761

  
762 762
	/* Now read in all of the header information */
763
	
763

  
764 764
	if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
765 765
	    return ~0UL;
766
	
767
	elf_phdata =  (struct elf_phdr *) 
766

  
767
	elf_phdata =  (struct elf_phdr *)
768 768
		malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
769 769

  
770 770
	if (!elf_phdata)
771 771
	  return ~0UL;
772
	
772

  
773 773
	/*
774 774
	 * If the size of this structure has changed, then punt, since
775 775
	 * we will be doing the wrong thing.
......
802 802
            /* in order to avoid hardcoding the interpreter load
803 803
               address in qemu, we allocate a big enough memory zone */
804 804
            error = target_mmap(0, INTERP_MAP_SIZE,
805
                                PROT_NONE, MAP_PRIVATE | MAP_ANON, 
805
                                PROT_NONE, MAP_PRIVATE | MAP_ANON,
806 806
                                -1, 0);
807 807
            if (error == -1) {
808 808
                perror("mmap");
......
833 833
		 elf_type,
834 834
		 interpreter_fd,
835 835
		 eppnt->p_offset - TARGET_ELF_PAGEOFFSET(eppnt->p_vaddr));
836
	    
836
	   
837 837
	    if (error == -1) {
838 838
	      /* Real error */
839 839
	      close(interpreter_fd);
......
860 860
	    k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
861 861
	    if (k > last_bss) last_bss = k;
862 862
	  }
863
	
863

  
864 864
	/* Now use mmap to map the library into memory. */
865 865

  
866 866
	close(interpreter_fd);
......
932 932
    s->disas_strtab = strings = malloc(strtab.sh_size);
933 933
    if (!s->disas_symtab || !s->disas_strtab)
934 934
	return;
935
	
935

  
936 936
    lseek(fd, symtab.sh_offset, SEEK_SET);
937 937
    if (read(fd, s->disas_symtab, symtab.sh_size) != symtab.sh_size)
938 938
	return;
......
1019 1019

  
1020 1020
    retval = lseek(bprm->fd, elf_ex.e_phoff, SEEK_SET);
1021 1021
    if(retval > 0) {
1022
	retval = read(bprm->fd, (char *) elf_phdata, 
1022
	retval = read(bprm->fd, (char *) elf_phdata,
1023 1023
				elf_ex.e_phentsize * elf_ex.e_phnum);
1024 1024
    }
1025 1025

  
......
1078 1078
	    if(retval < 0) {
1079 1079
	 	perror("load_elf_binary2");
1080 1080
		exit(-1);
1081
	    }	
1081
	    }
1082 1082

  
1083 1083
	    /* If the program interpreter is one of these two,
1084 1084
	       then assume an iBCS2 image. Otherwise assume
......
1199 1199
        int elf_prot = 0;
1200 1200
        int elf_flags = 0;
1201 1201
        unsigned long error;
1202
        
1202
       
1203 1203
	if (elf_ppnt->p_type != PT_LOAD)
1204 1204
            continue;
1205
        
1205
       
1206 1206
        if (elf_ppnt->p_flags & PF_R) elf_prot |= PROT_READ;
1207 1207
        if (elf_ppnt->p_flags & PF_W) elf_prot |= PROT_WRITE;
1208 1208
        if (elf_ppnt->p_flags & PF_X) elf_prot |= PROT_EXEC;
......
1216 1216
            /* NOTE: for qemu, we do a big mmap to get enough space
1217 1217
               without hardcoding any address */
1218 1218
            error = target_mmap(0, ET_DYN_MAP_SIZE,
1219
                                PROT_NONE, MAP_PRIVATE | MAP_ANON, 
1219
                                PROT_NONE, MAP_PRIVATE | MAP_ANON,
1220 1220
                                -1, 0);
1221 1221
            if (error == -1) {
1222 1222
                perror("mmap");
......
1224 1224
            }
1225 1225
            load_bias = TARGET_ELF_PAGESTART(error - elf_ppnt->p_vaddr);
1226 1226
        }
1227
        
1227
       
1228 1228
        error = target_mmap(TARGET_ELF_PAGESTART(load_bias + elf_ppnt->p_vaddr),
1229 1229
                            (elf_ppnt->p_filesz +
1230 1230
                             TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr)),
1231 1231
                            elf_prot,
1232 1232
                            (MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE),
1233 1233
                            bprm->fd,
1234
                            (elf_ppnt->p_offset - 
1234
                            (elf_ppnt->p_offset -
1235 1235
                             TARGET_ELF_PAGEOFFSET(elf_ppnt->p_vaddr)));
1236 1236
        if (error == -1) {
1237 1237
            perror("mmap");
......
1242 1242
        if (TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr) < elf_stack)
1243 1243
            elf_stack = TARGET_ELF_PAGESTART(elf_ppnt->p_vaddr);
1244 1244
#endif
1245
        
1245
       
1246 1246
        if (!load_addr_set) {
1247 1247
            load_addr_set = 1;
1248 1248
            load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset;
......
1254 1254
            }
1255 1255
        }
1256 1256
        k = elf_ppnt->p_vaddr;
1257
        if (k < start_code) 
1257
        if (k < start_code)
1258 1258
            start_code = k;
1259 1259
        k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz;
1260
        if (k > elf_bss) 
1260
        if (k > elf_bss)
1261 1261
            elf_bss = k;
1262 1262
        if ((elf_ppnt->p_flags & PF_X) && end_code <  k)
1263 1263
            end_code = k;
1264
        if (end_data < k) 
1264
        if (end_data < k)
1265 1265
            end_data = k;
1266 1266
        k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz;
1267 1267
        if (k > elf_brk) elf_brk = k;

Also available in: Unified diff