map_object.c (50609) | map_object.c (50610) |
---|---|
1/*- 2 * Copyright 1996-1998 John D. Polstra. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * | 1/*- 2 * Copyright 1996-1998 John D. Polstra. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 8 unchanged lines hidden (view full) --- 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * |
25 * $FreeBSD: head/libexec/rtld-elf/map_object.c 50609 1999-08-30 01:50:41Z jdp $ | 25 * $FreeBSD: head/libexec/rtld-elf/map_object.c 50610 1999-08-30 01:54:13Z jdp $ |
26 */ 27 28#include <sys/param.h> 29#include <sys/mman.h> 30#include <sys/stat.h> 31 32#include <errno.h> 33#include <stddef.h> --- 23 unchanged lines hidden (view full) --- 57 } u; 58 int nbytes; 59 Elf_Phdr *phdr; 60 Elf_Phdr *phlimit; 61 Elf_Phdr *segs[2]; 62 int nsegs; 63 Elf_Phdr *phdyn; 64 Elf_Phdr *phphdr; | 26 */ 27 28#include <sys/param.h> 29#include <sys/mman.h> 30#include <sys/stat.h> 31 32#include <errno.h> 33#include <stddef.h> --- 23 unchanged lines hidden (view full) --- 57 } u; 58 int nbytes; 59 Elf_Phdr *phdr; 60 Elf_Phdr *phlimit; 61 Elf_Phdr *segs[2]; 62 int nsegs; 63 Elf_Phdr *phdyn; 64 Elf_Phdr *phphdr; |
65 Elf_Phdr *phinterp; |
|
65 caddr_t mapbase; 66 size_t mapsize; 67 Elf_Off base_offset; 68 Elf_Addr base_vaddr; 69 Elf_Addr base_vlimit; 70 caddr_t base_addr; 71 Elf_Off data_offset; 72 Elf_Addr data_vaddr; --- 58 unchanged lines hidden (view full) --- 131 * Scan the program header entries, and save key information. 132 * 133 * We rely on there being exactly two load segments, text and data, 134 * in that order. 135 */ 136 phdr = (Elf_Phdr *) (u.buf + u.hdr.e_phoff); 137 phlimit = phdr + u.hdr.e_phnum; 138 nsegs = 0; | 66 caddr_t mapbase; 67 size_t mapsize; 68 Elf_Off base_offset; 69 Elf_Addr base_vaddr; 70 Elf_Addr base_vlimit; 71 caddr_t base_addr; 72 Elf_Off data_offset; 73 Elf_Addr data_vaddr; --- 58 unchanged lines hidden (view full) --- 132 * Scan the program header entries, and save key information. 133 * 134 * We rely on there being exactly two load segments, text and data, 135 * in that order. 136 */ 137 phdr = (Elf_Phdr *) (u.buf + u.hdr.e_phoff); 138 phlimit = phdr + u.hdr.e_phnum; 139 nsegs = 0; |
139 phdyn = NULL; 140 phphdr = NULL; | 140 phdyn = phphdr = phinterp = NULL; |
141 while (phdr < phlimit) { 142 switch (phdr->p_type) { 143 | 141 while (phdr < phlimit) { 142 switch (phdr->p_type) { 143 |
144 case PT_INTERP: 145 phinterp = phdr; 146 break; 147 |
|
144 case PT_LOAD: 145 if (nsegs >= 2) { 146 _rtld_error("%s: too many PT_LOAD segments", path); 147 return NULL; 148 } 149 segs[nsegs] = phdr; 150 ++nsegs; 151 break; --- 82 unchanged lines hidden (view full) --- 234 obj->ino = sb->st_ino; 235 } 236 obj->mapbase = mapbase; 237 obj->mapsize = mapsize; 238 obj->textsize = round_page(segs[0]->p_vaddr + segs[0]->p_memsz) - 239 base_vaddr; 240 obj->vaddrbase = base_vaddr; 241 obj->relocbase = mapbase - base_vaddr; | 148 case PT_LOAD: 149 if (nsegs >= 2) { 150 _rtld_error("%s: too many PT_LOAD segments", path); 151 return NULL; 152 } 153 segs[nsegs] = phdr; 154 ++nsegs; 155 break; --- 82 unchanged lines hidden (view full) --- 238 obj->ino = sb->st_ino; 239 } 240 obj->mapbase = mapbase; 241 obj->mapsize = mapsize; 242 obj->textsize = round_page(segs[0]->p_vaddr + segs[0]->p_memsz) - 243 base_vaddr; 244 obj->vaddrbase = base_vaddr; 245 obj->relocbase = mapbase - base_vaddr; |
242 obj->dynamic = (const Elf_Dyn *) 243 (mapbase + (phdyn->p_vaddr - base_vaddr)); | 246 obj->dynamic = (const Elf_Dyn *) (obj->relocbase + phdyn->p_vaddr); |
244 if (u.hdr.e_entry != 0) | 247 if (u.hdr.e_entry != 0) |
245 obj->entry = (caddr_t) (mapbase + (u.hdr.e_entry - base_vaddr)); | 248 obj->entry = (caddr_t) (obj->relocbase + u.hdr.e_entry); |
246 if (phphdr != NULL) { | 249 if (phphdr != NULL) { |
247 obj->phdr = (const Elf_Phdr *) 248 (mapbase + (phphdr->p_vaddr - base_vaddr)); | 250 obj->phdr = (const Elf_Phdr *) (obj->relocbase + phphdr->p_vaddr); |
249 obj->phsize = phphdr->p_memsz; 250 } | 251 obj->phsize = phphdr->p_memsz; 252 } |
253 if (phinterp != NULL) 254 obj->interp = (const char *) (obj->relocbase + phinterp->p_vaddr); |
|
251 252 return obj; 253} 254 255void 256obj_free(Obj_Entry *obj) 257{ 258 Objlist_Entry *elm; --- 47 unchanged lines hidden --- | 255 256 return obj; 257} 258 259void 260obj_free(Obj_Entry *obj) 261{ 262 Objlist_Entry *elm; --- 47 unchanged lines hidden --- |