OLD | NEW |
---|---|
(Empty) | |
1 /* | |
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 | |
4 * found in the LICENSE file. | |
5 */ | |
6 | |
7 #include "native_client/src/trusted/validator_mips/ncvalidate.h" | |
8 | |
9 #include <vector> | |
10 | |
11 #include "native_client/src/include/nacl_string.h" | |
12 #include "native_client/src/include/portability.h" | |
13 #include "native_client/src/trusted/validator_mips/validator.h" | |
14 #include "native_client/src/trusted/validator_mips/model.h" | |
15 #include "native_client/src/trusted/validator/ncvalidate.h" | |
16 | |
Mark Seaborn
2012/09/18 03:24:34
Nit: remove empty line here to keep native_client
| |
17 #include "native_client/src/trusted/service_runtime/arch/mips/sel_ldr_mips.h" | |
18 | |
19 using nacl_mips_val::SfiValidator; | |
20 using nacl_mips_val::CodeSegment; | |
21 using nacl_mips_dec::Register; | |
22 using nacl_mips_dec::kRegisterStack; | |
23 using nacl_mips_dec::kRegListReserved; | |
24 using std::vector; | |
25 | |
26 | |
27 class EarlyExitProblemSink : public nacl_mips_val::ProblemSink { | |
28 private: | |
29 bool problems_; | |
30 | |
31 public: | |
32 EarlyExitProblemSink() : nacl_mips_val::ProblemSink(), problems_(false) {} | |
33 | |
34 virtual void ReportProblem(uint32_t vaddr, | |
35 nacl_mips_dec::SafetyLevel safety, | |
36 const nacl::string &problem_code, | |
37 uint32_t ref_vaddr) { | |
38 UNREFERENCED_PARAMETER(vaddr); | |
39 UNREFERENCED_PARAMETER(safety); | |
40 UNREFERENCED_PARAMETER(problem_code); | |
41 UNREFERENCED_PARAMETER(ref_vaddr); | |
42 | |
43 problems_ = true; | |
44 } | |
45 virtual bool ShouldContinue() { | |
46 return !problems_; | |
47 } | |
48 }; | |
49 | |
50 | |
51 class StuboutProblemSink : public nacl_mips_val::ProblemSink { | |
52 private: | |
53 bool problems_; | |
54 uint32_t const kNaClFullStop; | |
55 | |
56 public: | |
57 StuboutProblemSink() : nacl_mips_val::ProblemSink(), problems_(false), | |
58 kNaClFullStop(NACL_HALT_OPCODE) {} | |
59 | |
60 virtual void ReportProblem(uint32_t vaddr, | |
61 nacl_mips_dec::SafetyLevel safety, | |
62 const nacl::string &problem_code, | |
63 uint32_t ref_vaddr) { | |
64 UNREFERENCED_PARAMETER(safety); | |
65 UNREFERENCED_PARAMETER(problem_code); | |
66 UNREFERENCED_PARAMETER(ref_vaddr); | |
67 stub_out_instr(vaddr); | |
68 | |
69 problems_ = true; | |
70 } | |
71 virtual bool ShouldContinue() { | |
72 return true; | |
73 } | |
74 | |
75 private: | |
76 void stub_out_instr(uint32_t vaddr) { | |
77 #ifdef __BIG_ENDIAN__ | |
78 assert(0); | |
Mark Seaborn
2012/09/18 03:24:34
Nit: we generally don't use assert() in trusted co
petarj
2012/09/19 17:27:51
Done.
| |
79 #endif | |
80 *reinterpret_cast<uint32_t *>(vaddr) = kNaClFullStop; | |
81 } | |
82 }; | |
83 | |
84 EXTERN_C_BEGIN | |
85 | |
86 int NCValidateSegment(uint8_t *mbase, uint32_t vbase, size_t size, | |
87 bool stubout_mode) { | |
88 SfiValidator validator( | |
89 16, // 64, // bytes per bundle | |
90 1U * NACL_DATA_SEGMENT_START, // bytes of code space | |
91 1U * (1<<NACL_MAX_ADDR_BITS), // bytes of data space // keep in sync w/ | |
92 // SConstruct: irt_compatible_rodata_addr | |
93 kRegListReserved, // read only register(s) | |
94 kRegisterStack); // data addressing register(s) | |
95 bool success = false; | |
96 | |
97 vector<CodeSegment> segments; | |
98 segments.push_back(CodeSegment(mbase, vbase, size)); | |
99 | |
100 if (stubout_mode) { | |
101 StuboutProblemSink sink; | |
102 success = validator.Validate(segments, &sink); | |
103 } else { | |
104 EarlyExitProblemSink sink; | |
105 success = validator.Validate(segments, &sink); | |
106 } | |
107 if (!success) return 2; | |
108 | |
109 return 0; | |
110 } | |
111 | |
112 static NaClValidationStatus ApplyValidatorMips( | |
113 uintptr_t guest_addr, | |
114 uint8_t *data, | |
115 size_t size, | |
116 int stubout_mode, | |
117 int readonly_text, | |
118 const NaClCPUFeaturesMips *cpu_features, | |
119 struct NaClValidationCache *cache) { | |
120 NaClValidationStatus status = NaClValidationFailedNotImplemented; | |
121 UNREFERENCED_PARAMETER(cpu_features); | |
122 UNREFERENCED_PARAMETER(cache); | |
123 if (stubout_mode) { | |
124 NCValidateSegment(data, guest_addr, size, true); | |
125 status = NaClValidationSucceeded; | |
126 } else if (readonly_text) { | |
127 status = NaClValidationFailedNotImplemented; | |
128 } else { | |
129 status = ((0 == NCValidateSegment(data, guest_addr, size, false)) | |
130 ? NaClValidationSucceeded : NaClValidationFailed); | |
131 } | |
132 return status; | |
133 } | |
134 | |
135 static NaClValidationStatus ValidatorCodeReplacementNotImplemented( | |
136 uintptr_t guest_addr, | |
137 uint8_t *data_old, | |
138 uint8_t *data_new, | |
139 size_t size, | |
140 const NaClCPUFeatures *cpu_features) { | |
141 UNREFERENCED_PARAMETER(guest_addr); | |
142 UNREFERENCED_PARAMETER(data_old); | |
143 UNREFERENCED_PARAMETER(data_new); | |
144 UNREFERENCED_PARAMETER(size); | |
145 UNREFERENCED_PARAMETER(cpu_features); | |
146 return NaClValidationFailedNotImplemented; | |
147 } | |
148 | |
149 static NaClValidationStatus ValidatorCopyNotImplemented( | |
150 uintptr_t guest_addr, | |
151 uint8_t *data_old, | |
152 uint8_t *data_new, | |
153 size_t size, | |
154 const NaClCPUFeatures *cpu_features, | |
155 NaClCopyInstructionFunc copy_func) { | |
156 UNREFERENCED_PARAMETER(guest_addr); | |
157 UNREFERENCED_PARAMETER(data_old); | |
158 UNREFERENCED_PARAMETER(data_new); | |
159 UNREFERENCED_PARAMETER(size); | |
160 UNREFERENCED_PARAMETER(cpu_features); | |
161 UNREFERENCED_PARAMETER(copy_func); | |
162 return NaClValidationFailedNotImplemented; | |
163 } | |
164 | |
165 static struct NaClValidatorInterface validator = { | |
166 ApplyValidatorMips, | |
167 ValidatorCopyNotImplemented, | |
168 ValidatorCodeReplacementNotImplemented, | |
169 }; | |
170 | |
171 const struct NaClValidatorInterface *NaClValidatorCreateMips() { | |
172 return &validator; | |
173 } | |
174 | |
175 /* | |
176 * When safe instruction copying gets implemented for MIPS, it should be moved t o | |
Mark Seaborn
2012/09/18 03:24:34
Nit: this line is >80 chars long, please re-wrap
petarj
2012/09/19 17:27:51
Done.
| |
177 * be part of sel_ldr, not the validator. | |
178 */ | |
179 int NaClCopyInstruction(uint8_t *dst, uint8_t *src, uint8_t sz) { | |
180 UNREFERENCED_PARAMETER(dst); | |
181 UNREFERENCED_PARAMETER(src); | |
182 UNREFERENCED_PARAMETER(sz); | |
183 | |
184 return 0; | |
185 } | |
186 | |
187 EXTERN_C_END | |
OLD | NEW |