OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 /* | 7 /* |
8 * NaCl helper functions to deal with elf images | 8 * NaCl helper functions to deal with elf images |
9 */ | 9 */ |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "native_client/src/shared/gio/gio.h" | 25 #include "native_client/src/shared/gio/gio.h" |
26 #include "native_client/src/shared/platform/nacl_log.h" | 26 #include "native_client/src/shared/platform/nacl_log.h" |
27 | 27 |
28 #include "native_client/src/trusted/service_runtime/elf_util.h" | 28 #include "native_client/src/trusted/service_runtime/elf_util.h" |
29 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" | 29 #include "native_client/src/trusted/service_runtime/include/bits/mman.h" |
30 #include "native_client/src/trusted/service_runtime/nacl_config.h" | 30 #include "native_client/src/trusted/service_runtime/nacl_config.h" |
31 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 31 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
32 #include "native_client/src/trusted/service_runtime/nacl_text.h" | 32 #include "native_client/src/trusted/service_runtime/nacl_text.h" |
33 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" | 33 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" |
34 #include "native_client/src/trusted/service_runtime/sel_memory.h" | 34 #include "native_client/src/trusted/service_runtime/sel_memory.h" |
| 35 #include "native_client/src/trusted/validator/validation_metadata.h" |
35 | 36 |
36 /* private */ | 37 /* private */ |
37 struct NaClElfImage { | 38 struct NaClElfImage { |
38 Elf_Ehdr ehdr; | 39 Elf_Ehdr ehdr; |
39 Elf_Phdr phdrs[NACL_MAX_PROGRAM_HEADERS]; | 40 Elf_Phdr phdrs[NACL_MAX_PROGRAM_HEADERS]; |
40 int loadable[NACL_MAX_PROGRAM_HEADERS]; | 41 int loadable[NACL_MAX_PROGRAM_HEADERS]; |
41 }; | 42 }; |
42 | 43 |
43 | 44 |
44 enum NaClPhdrCheckAction { | 45 enum NaClPhdrCheckAction { |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 /* region from p_filesz to p_memsz should already be zero filled */ | 617 /* region from p_filesz to p_memsz should already be zero filled */ |
617 | 618 |
618 /* Tell Valgrind that we've mapped a segment of nacl_file. */ | 619 /* Tell Valgrind that we've mapped a segment of nacl_file. */ |
619 NaClFileMappingForValgrind(paddr, filesz, offset); | 620 NaClFileMappingForValgrind(paddr, filesz, offset); |
620 } | 621 } |
621 | 622 |
622 return LOAD_OK; | 623 return LOAD_OK; |
623 } | 624 } |
624 | 625 |
625 | 626 |
626 NaClErrorCode NaClElfImageLoadDynamically(struct NaClElfImage *image, | 627 NaClErrorCode NaClElfImageLoadDynamically( |
627 struct NaClApp *nap, | 628 struct NaClElfImage *image, |
628 struct Gio *gfile) { | 629 struct NaClApp *nap, |
| 630 struct Gio *gfile, |
| 631 struct NaClValidationMetadata *metadata) { |
629 int segnum; | 632 int segnum; |
630 for (segnum = 0; segnum < image->ehdr.e_phnum; ++segnum) { | 633 for (segnum = 0; segnum < image->ehdr.e_phnum; ++segnum) { |
631 const Elf_Phdr *php = &image->phdrs[segnum]; | 634 const Elf_Phdr *php = &image->phdrs[segnum]; |
632 Elf_Addr vaddr = php->p_vaddr & ~(NACL_MAP_PAGESIZE - 1); | 635 Elf_Addr vaddr = php->p_vaddr & ~(NACL_MAP_PAGESIZE - 1); |
633 Elf_Off offset = php->p_offset & ~(NACL_MAP_PAGESIZE - 1); | 636 Elf_Off offset = php->p_offset & ~(NACL_MAP_PAGESIZE - 1); |
634 Elf_Off filesz = php->p_offset + php->p_filesz - offset; | 637 Elf_Off filesz = php->p_offset + php->p_filesz - offset; |
635 Elf_Off memsz = php->p_offset + php->p_memsz - offset; | 638 Elf_Off memsz = php->p_offset + php->p_memsz - offset; |
636 int32_t result; | 639 int32_t result; |
637 | 640 |
638 /* | 641 /* |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 if (NULL == code_copy) { | 674 if (NULL == code_copy) { |
672 NaClLog(LOG_ERROR, "NaClElfImageLoadDynamically: malloc failed\n"); | 675 NaClLog(LOG_ERROR, "NaClElfImageLoadDynamically: malloc failed\n"); |
673 return LOAD_NO_MEMORY; | 676 return LOAD_NO_MEMORY; |
674 } | 677 } |
675 if ((Elf_Word) (*gfile->vtbl->Read)(gfile, code_copy, filesz) != filesz) { | 678 if ((Elf_Word) (*gfile->vtbl->Read)(gfile, code_copy, filesz) != filesz) { |
676 free(code_copy); | 679 free(code_copy); |
677 NaClLog(LOG_ERROR, "NaClElfImageLoadDynamically: " | 680 NaClLog(LOG_ERROR, "NaClElfImageLoadDynamically: " |
678 "failed to read code segment\n"); | 681 "failed to read code segment\n"); |
679 return LOAD_READ_ERROR; | 682 return LOAD_READ_ERROR; |
680 } | 683 } |
| 684 if (NULL != metadata) { |
| 685 metadata->code_offset = offset; |
| 686 } |
681 result = NaClTextDyncodeCreate(nap, (uint32_t) vaddr, | 687 result = NaClTextDyncodeCreate(nap, (uint32_t) vaddr, |
682 code_copy, (uint32_t) filesz); | 688 code_copy, (uint32_t) filesz, metadata); |
683 free(code_copy); | 689 free(code_copy); |
684 if (0 != result) { | 690 if (0 != result) { |
685 NaClLog(LOG_ERROR, "NaClElfImageLoadDynamically: " | 691 NaClLog(LOG_ERROR, "NaClElfImageLoadDynamically: " |
686 "failed to load code segment\n"); | 692 "failed to load code segment\n"); |
687 return LOAD_UNLOADABLE; | 693 return LOAD_UNLOADABLE; |
688 } | 694 } |
689 } else { | 695 } else { |
690 /* Load data segment. */ | 696 /* Load data segment. */ |
691 void *paddr = (void *) NaClUserToSys(nap, vaddr); | 697 void *paddr = (void *) NaClUserToSys(nap, vaddr); |
692 size_t mapping_size = NaClRoundAllocPage(memsz); | 698 size_t mapping_size = NaClRoundAllocPage(memsz); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 749 |
744 | 750 |
745 void NaClElfImageDelete(struct NaClElfImage *image) { | 751 void NaClElfImageDelete(struct NaClElfImage *image) { |
746 free(image); | 752 free(image); |
747 } | 753 } |
748 | 754 |
749 | 755 |
750 uintptr_t NaClElfImageGetEntryPoint(struct NaClElfImage *image) { | 756 uintptr_t NaClElfImageGetEntryPoint(struct NaClElfImage *image) { |
751 return image->ehdr.e_entry; | 757 return image->ehdr.e_entry; |
752 } | 758 } |
OLD | NEW |