| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2008, Google Inc. | |
| 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 are | |
| 7 * met: | |
| 8 * | |
| 9 * * Redistributions of source code must retain the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer. | |
| 11 * * Redistributions in binary form must reproduce the above | |
| 12 * copyright notice, this list of conditions and the following disclaimer | |
| 13 * in the documentation and/or other materials provided with the | |
| 14 * distribution. | |
| 15 * * Neither the name of Google Inc. nor the names of its | |
| 16 * contributors may be used to endorse or promote products derived from | |
| 17 * this software without specific prior written permission. | |
| 18 * | |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 30 */ | |
| 31 | |
| 32 /* | |
| 33 * NaCl Simple/secure ELF loader (NaCl SEL). | |
| 34 */ | |
| 35 | |
| 36 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | |
| 37 | |
| 38 | |
| 39 NaClErrorCode NaClLoadImage(struct Gio *gp, | |
| 40 struct NaClApp *nap) { | |
| 41 int segnum; | |
| 42 Elf32_Phdr *php; | |
| 43 uintptr_t paddr; | |
| 44 uintptr_t end_vaddr; | |
| 45 | |
| 46 for (segnum = 0; segnum < nap->elf_hdr.e_phnum; ++segnum) { | |
| 47 php = &nap->phdrs[segnum]; | |
| 48 | |
| 49 /* did we decide that we will load this segment earlier? */ | |
| 50 if (0 == (php->p_flags & PF_OS_WILL_LOAD)) { | |
| 51 continue; | |
| 52 } | |
| 53 | |
| 54 end_vaddr = php->p_vaddr + php->p_filesz; | |
| 55 /* integer overflow? */ | |
| 56 if (end_vaddr < php->p_vaddr) { | |
| 57 NaClLog(LOG_FATAL, "parameter error should have been detected already\n"); | |
| 58 } | |
| 59 /* | |
| 60 * is the end virtual address within the NaCl application's | |
| 61 * address space? if it is, it implies that the start virtual | |
| 62 * address is also. | |
| 63 */ | |
| 64 if (end_vaddr >= (1U << nap->addr_bits)) { | |
| 65 NaClLog(LOG_FATAL, "parameter error should have been detected already\n"); | |
| 66 } | |
| 67 | |
| 68 paddr = nap->mem_start + php->p_vaddr; | |
| 69 | |
| 70 if ((*gp->vtbl->Seek)(gp, php->p_offset, SEEK_SET) == -1) { | |
| 71 return LOAD_SEGMENT_BAD_PARAM; | |
| 72 } | |
| 73 if ((Elf32_Word) (*gp->vtbl->Read)(gp, (void *) paddr, php->p_filesz) | |
| 74 != php->p_filesz) { | |
| 75 return LOAD_SEGMENT_BAD_PARAM; | |
| 76 } | |
| 77 /* region from p_filesz to p_memsz should already be zero filled */ | |
| 78 } | |
| 79 | |
| 80 NaClFillEndOfTextRegion(nap); | |
| 81 | |
| 82 return LOAD_OK; | |
| 83 } | |
| 84 | |
| OLD | NEW |