OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 problem_code.c_str(), ref_vaddr); | 44 problem_code.c_str(), ref_vaddr); |
45 } | 45 } |
46 virtual bool should_continue() { | 46 virtual bool should_continue() { |
47 // Collect *all* problems before returning! | 47 // Collect *all* problems before returning! |
48 return true; | 48 return true; |
49 } | 49 } |
50 }; | 50 }; |
51 | 51 |
52 const uint32_t kOneGig = 1U * 1024 * 1024 * 1024; | 52 const uint32_t kOneGig = 1U * 1024 * 1024 * 1024; |
53 | 53 |
54 int validate(const ncfile *ncf, bool use_zero_masks) { | 54 int validate(const ncfile *ncf, bool use_zero_masks, bool thumb) { |
Karl
2011/09/19 19:56:05
Should this be static?
bsy
2011/09/21 22:32:17
since this is C++ code, put this in a namespace?
jasonwkim
2011/09/26 21:35:52
since this code is already only called by main, pr
jasonwkim
2011/09/26 21:35:52
only called by main - I think its fine
| |
55 nacl_arm_dec::RegisterList roRegs = nacl_arm_dec::Register(9); | |
56 if (thumb) { | |
Karl
2011/09/19 19:56:05
Thumb2?
jasonwkim
2011/09/26 21:35:52
again thumb mode
| |
57 roRegs = nacl_arm_dec::kRegisterListNothing; | |
58 } | |
55 SfiValidator validator( | 59 SfiValidator validator( |
56 16, // bytes per bundle | 60 16, // bytes per bundle |
57 // TODO(cbiffle): maybe check region sizes from ELF headers? | 61 // TODO(cbiffle): maybe check region sizes from ELF headers? |
58 // verify that instructions are in right region | 62 // verify that instructions are in right region |
59 kOneGig, // code region size | 63 kOneGig, // code region size |
60 kOneGig, // data region size | 64 kOneGig, // data region size |
61 nacl_arm_dec::Register(9), // read only register (used for threading) | 65 roRegs, // read only register (used for threading) |
62 nacl_arm_dec::Register(13)); // stack pointer | 66 nacl_arm_dec::Register(13), // stack pointer |
67 thumb); | |
63 | 68 |
64 if (use_zero_masks) { | 69 if (use_zero_masks) { |
65 validator.change_masks(0, 0); | 70 validator.change_masks(0, 0, 0); |
66 } | 71 } |
67 | 72 |
68 CommandLineProblemSink sink; | 73 CommandLineProblemSink sink; |
69 | 74 |
70 Elf_Shdr *shdr = ncf->sheaders; | 75 Elf_Shdr *shdr = ncf->sheaders; |
71 | 76 |
72 vector<CodeSegment> segments; | 77 vector<CodeSegment> segments; |
73 for (int i = 0; i < ncf->shnum; i++) { | 78 for (int i = 0; i < ncf->shnum; i++) { |
74 if ((shdr[i].sh_flags & SHF_EXECINSTR) != SHF_EXECINSTR) { | 79 if ((shdr[i].sh_flags & SHF_EXECINSTR) != SHF_EXECINSTR) { |
75 continue; | 80 continue; |
76 } | 81 } |
77 | 82 fprintf(stderr, "CodeSegment(%x, %x, %x)\n", (unsigned int)(ncf->data + (shdr[ i].sh_addr - ncf->vbase)), |
Karl
2011/09/19 19:56:05
Should this have a DEBUG prefix like line 126?
jasonwkim
2011/09/26 21:35:52
debug printfs killed
| |
83 shdr[i].sh_addr, shdr[i].sh_size); | |
78 CodeSegment segment(ncf->data + (shdr[i].sh_addr - ncf->vbase), | 84 CodeSegment segment(ncf->data + (shdr[i].sh_addr - ncf->vbase), |
79 shdr[i].sh_addr, shdr[i].sh_size); | 85 shdr[i].sh_addr, shdr[i].sh_size); |
80 segments.push_back(segment); | 86 segments.push_back(segment); |
81 } | 87 } |
82 | 88 |
83 std::sort(segments.begin(), segments.end()); | 89 std::sort(segments.begin(), segments.end()); |
84 | 90 |
85 bool success = validator.validate(segments, &sink); | 91 bool success = validator.validate(segments, &sink); |
86 if (!success) return 1; | 92 if (!success) return 1; |
87 return 0; | 93 return 0; |
(...skipping 22 matching lines...) Expand all Loading... | |
110 return 2; | 116 return 2; |
111 } | 117 } |
112 | 118 |
113 ncfile *ncf = nc_loadfile(filename); | 119 ncfile *ncf = nc_loadfile(filename); |
114 if (!ncf) { | 120 if (!ncf) { |
115 fprintf(stderr, "Unable to load %s: %s\n", filename, strerror(errno)); | 121 fprintf(stderr, "Unable to load %s: %s\n", filename, strerror(errno)); |
116 return 1; | 122 return 1; |
117 } | 123 } |
118 | 124 |
119 // TODO(cbiffle): check OS ABI, ABI version, align mask | 125 // TODO(cbiffle): check OS ABI, ABI version, align mask |
126 fprintf(stderr, "mrm DEBUG: Entry: %x\n", ncf->eheader->e_entry); | |
127 int exit_code = validate(ncf, use_zero_masks, ncf->eheader->e_entry & 1); | |
120 | 128 |
121 int exit_code = validate(ncf, use_zero_masks); | |
122 nc_freefile(ncf); | 129 nc_freefile(ncf); |
123 return exit_code; | 130 return exit_code; |
124 } | 131 } |
OLD | NEW |