Deleted Added
sdiff udiff text old ( 215811 ) new ( 220311 )
full compact
1/*-
2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 1998 Peter Wemm <peter@freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/boot/common/load_elf.c 215811 2010-11-25 03:16:31Z emaste $");
30
31#include <sys/param.h>
32#include <sys/exec.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/stdint.h>
36#include <string.h>
37#include <machine/elf.h>

--- 54 unchanged lines hidden (view full) ---

92 */
93int
94__elfN(loadfile)(char *filename, u_int64_t dest, struct preloaded_file **result)
95{
96 struct preloaded_file *fp, *kfp;
97 struct elf_file ef;
98 Elf_Ehdr *ehdr;
99 int err;
100 u_int pad;
101 ssize_t bytes_read;
102
103 fp = NULL;
104 bzero(&ef, sizeof(struct elf_file));
105
106 /*
107 * Open the image, read and validate the ELF header
108 */

--- 43 unchanged lines hidden (view full) ---

152 if (strcmp(__elfN(kerneltype), kfp->f_type)) {
153 printf("elf" __XSTRING(__ELF_WORD_SIZE) "_loadfile: can't load module with kernel type '%s'\n", kfp->f_type);
154 err = EPERM;
155 goto oerr;
156 }
157 /* Looks OK, got ahead */
158 ef.kernel = 0;
159
160 /* Page-align the load address */
161 pad = (u_int)dest & PAGE_MASK;
162 if (pad != 0) {
163 pad = PAGE_SIZE - pad;
164 dest += pad;
165 }
166 } else if (ehdr->e_type == ET_EXEC) {
167 /* Looks like a kernel */
168 if (kfp != NULL) {
169 printf("elf" __XSTRING(__ELF_WORD_SIZE) "_loadfile: kernel already loaded\n");
170 err = EPERM;
171 goto oerr;
172 }
173 /*
174 * Calculate destination address based on kernel entrypoint
175 */
176 dest = ehdr->e_entry;
177 if (dest == 0) {
178 printf("elf" __XSTRING(__ELF_WORD_SIZE) "_loadfile: not a kernel (maybe static binary?)\n");
179 err = EPERM;
180 goto oerr;
181 }
182 ef.kernel = 1;
183
184 } else {
185 err = EFTYPE;
186 goto oerr;
187 }
188
189 /*
190 * Ok, we think we should handle this.
191 */
192 fp = file_alloc();
193 if (fp == NULL) {
194 printf("elf" __XSTRING(__ELF_WORD_SIZE) "_loadfile: cannot allocate module info\n");
195 err = EPERM;
196 goto out;
197 }
198 if (ef.kernel)
199 setenv("kernelname", filename, 1);
200 fp->f_name = strdup(filename);
201 fp->f_type = strdup(ef.kernel ? __elfN(kerneltype) : __elfN(moduletype));
202
203#ifdef ELF_VERBOSE
204 if (ef.kernel)
205 printf("%s entry at 0x%jx\n", filename, (uintmax_t)dest);
206#else
207 printf("%s ", filename);
208#endif
209
210 fp->f_size = __elfN(loadimage)(fp, &ef, dest);
211 if (fp->f_size == 0 || fp->f_addr == 0)
212 goto ioerr;
213

--- 143 unchanged lines hidden (view full) ---

357
358 kern_bzero(phdr[i].p_vaddr + off + phdr[i].p_filesz,
359 phdr[i].p_memsz - phdr[i].p_filesz);
360 }
361#ifdef ELF_VERBOSE
362 printf("\n");
363#endif
364
365 if (firstaddr == 0 || firstaddr > (phdr[i].p_vaddr + off))
366 firstaddr = phdr[i].p_vaddr + off;
367 if (lastaddr == 0 || lastaddr < (phdr[i].p_vaddr + off + phdr[i].p_memsz))
368 lastaddr = phdr[i].p_vaddr + off + phdr[i].p_memsz;
369 }
370 lastaddr = roundup(lastaddr, sizeof(long));
371
372 /*

--- 417 unchanged lines hidden ---