The main loop currently uses quite a lot of variables to update the section headers. Some of them are unnecessary. So clean them up a little.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -785,12 +785,8 @@ out: · 784 unmodified lines | ||
| 785 | 785 | static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, |
| 786 | 786 | struct kexec_buf *kbuf) |
| 787 | 787 | { |
| 788 | − unsigned long curr_load_addr; | |
| 789 | − unsigned long load_addr; | |
| 790 | 788 | unsigned long bss_addr; |
| 791 | 789 | unsigned long offset; |
| 792 | − unsigned char *buf_addr; | |
| 793 | − unsigned char *src; | |
| 794 | 790 | Elf_Shdr *sechdrs; |
| 795 | 791 | int i; |
| 796 | 792 | |
| @@ -823,20 +819,18 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, · 26 unmodified lines | ||
| 823 | 819 | sechdrs[i].sh_offset; |
| 824 | 820 | } |
| 825 | 821 | |
| 826 | − /* Load SHF_ALLOC sections */ | |
| 827 | − buf_addr = kbuf->buffer; | |
| 828 | − load_addr = curr_load_addr = kbuf->mem; | |
| 829 | − bss_addr = load_addr + kbuf->bufsz; | |
| 822 | + offset = 0; | |
| 823 | + bss_addr = kbuf->mem + kbuf->bufsz; | |
| 830 | 824 | kbuf->image->start = pi->ehdr->e_entry; |
| 831 | 825 | |
| 832 | 826 | for (i = 0; i < pi->ehdr->e_shnum; i++) { |
| 833 | 827 | unsigned long align; |
| 828 | + void *src, *dst; | |
| 834 | 829 | |
| 835 | 830 | if (!(sechdrs[i].sh_flags & SHF_ALLOC)) |
| 836 | 831 | continue; |
| 837 | 832 | |
| 838 | 833 | align = sechdrs[i].sh_addralign; |
| 839 | − | |
| 840 | 834 | if (sechdrs[i].sh_type == SHT_NOBITS) { |
| 841 | 835 | bss_addr = ALIGN(bss_addr, align); |
| 842 | 836 | sechdrs[i].sh_addr = bss_addr; |
| @@ -844,31 +838,27 @@ static int kexec_purgatory_setup_sechdrs(struct purgatory_info *pi, · 1 unmodified line | ||
| 844 | 838 | continue; |
| 845 | 839 | } |
| 846 | 840 | |
| 847 | − curr_load_addr = ALIGN(curr_load_addr, align); | |
| 848 | − offset = curr_load_addr - load_addr; | |
| 849 | − /* We already modifed ->sh_offset to keep src addr */ | |
| 850 | − src = (char *)sechdrs[i].sh_offset; | |
| 851 | − memcpy(buf_addr + offset, src, sechdrs[i].sh_size); | |
| 852 | − | |
| 841 | + offset = ALIGN(offset, align); | |
| 853 | 842 | if (sechdrs[i].sh_flags & SHF_EXECINSTR && |
| 854 | 843 | pi->ehdr->e_entry >= sechdrs[i].sh_addr && |
| 855 | 844 | pi->ehdr->e_entry < (sechdrs[i].sh_addr |
| 856 | 845 | + sechdrs[i].sh_size)) { |
| 857 | 846 | kbuf->image->start -= sechdrs[i].sh_addr; |
| 858 | − kbuf->image->start += curr_load_addr; | |
| 847 | + kbuf->image->start += kbuf->mem + offset; | |
| 859 | 848 | } |
| 860 | 849 | |
| 861 | − /* Store load address and source address of section */ | |
| 862 | − sechdrs[i].sh_addr = curr_load_addr; | |
| 850 | + src = (void *)sechdrs[i].sh_offset; | |
| 851 | + dst = pi->purgatory_buf + offset; | |
| 852 | + memcpy(dst, src, sechdrs[i].sh_size); | |
| 853 | + | |
| 854 | + sechdrs[i].sh_addr = kbuf->mem + offset; | |
| 863 | 855 | |
| 864 | 856 | /* |
| 865 | 857 | * This section got copied to temporary buffer. Update |
| 866 | 858 | * ->sh_offset accordingly. |
| 867 | 859 | */ |
| 868 | − sechdrs[i].sh_offset = (unsigned long)(buf_addr + offset); | |
| 869 | − | |
| 870 | − /* Advance to the next address */ | |
| 871 | − curr_load_addr += sechdrs[i].sh_size; | |
| 860 | + sechdrs[i].sh_offset = (unsigned long)dst; | |
| 861 | + offset += sechdrs[i].sh_size; | |
| 872 | 862 | } |
| 873 | 863 | |
| 874 | 864 | return 0; |