| 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 #ifndef NACL_TRUSTED_BUT_NOT_TCB | 7 #ifndef NACL_TRUSTED_BUT_NOT_TCB |
| 8 #error("This file is not meant for use in the TCB") | 8 #error("This file is not meant for use in the TCB") |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 uint8_t size, | 128 uint8_t size, |
| 129 NaClPcAddress vbase, | 129 NaClPcAddress vbase, |
| 130 NaClInstStruct* inst) { | 130 NaClInstStruct* inst) { |
| 131 NaClSegment segment; | 131 NaClSegment segment; |
| 132 NaClInstIter* iter; | 132 NaClInstIter* iter; |
| 133 NaClValidatorState* state; | 133 NaClValidatorState* state; |
| 134 Bool validates = FALSE; | 134 Bool validates = FALSE; |
| 135 NaClCPUFeaturesX86 cpu_features; | 135 NaClCPUFeaturesX86 cpu_features; |
| 136 | 136 |
| 137 NaClGetCurrentCPUFeatures(&cpu_features); | 137 NaClGetCurrentCPUFeatures(&cpu_features); |
| 138 state = NaClValidatorStateCreate(vbase, (NaClMemorySize) size, | 138 state = NaClValidatorStateCreate(vbase, (NaClMemorySize) size, RegR15, FALSE, |
| 139 32, RegR15, FALSE, &cpu_features); | 139 &cpu_features); |
| 140 do { | 140 do { |
| 141 NaClSegmentInitialize(mbase, vbase, (NaClMemorySize) size, &segment); | 141 NaClSegmentInitialize(mbase, vbase, (NaClMemorySize) size, &segment); |
| 142 iter = NaClInstIterCreate(kNaClDecoderTables, &segment); | 142 iter = NaClInstIterCreate(kNaClDecoderTables, &segment); |
| 143 if (NULL == iter) break; | 143 if (NULL == iter) break; |
| 144 state->cur_inst_state = NaClInstIterGetState(iter); | 144 state->cur_inst_state = NaClInstIterGetState(iter); |
| 145 state->cur_inst = NaClInstStateInst(state->cur_inst_state); | 145 state->cur_inst = NaClInstStateInst(state->cur_inst_state); |
| 146 state->cur_inst_vector = NaClInstStateExpVector(state->cur_inst_state); | 146 state->cur_inst_vector = NaClInstStateExpVector(state->cur_inst_state); |
| 147 NaClValidateInstructionLegal(state); | 147 NaClValidateInstructionLegal(state); |
| 148 NaClSafeSegmentReference(state, iter, NULL); | 148 NaClSafeSegmentReference(state, iter, NULL); |
| 149 validates = NaClValidatesOk(state); | 149 validates = NaClValidatesOk(state); |
| 150 state->cur_inst_state = NULL; | 150 state->cur_inst_state = NULL; |
| 151 state->cur_inst = NULL; | 151 state->cur_inst = NULL; |
| 152 state->cur_inst_vector = NULL; | 152 state->cur_inst_vector = NULL; |
| 153 NaClInstIterDestroy(iter); | 153 NaClInstIterDestroy(iter); |
| 154 } while(0); | 154 } while(0); |
| 155 NaClValidatorStateDestroy(state); | 155 NaClValidatorStateDestroy(state); |
| 156 return validates; | 156 return validates; |
| 157 } | 157 } |
| 158 | 158 |
| 159 Bool NaClSegmentValidates(uint8_t* mbase, | 159 Bool NaClSegmentValidates(uint8_t* mbase, |
| 160 uint8_t size, | 160 uint8_t size, |
| 161 NaClPcAddress vbase) { | 161 NaClPcAddress vbase) { |
| 162 NaClCPUFeaturesX86 cpu_features; | 162 NaClCPUFeaturesX86 cpu_features; |
| 163 NaClValidationStatus status; | 163 NaClValidationStatus status; |
| 164 | 164 |
| 165 /* check if NaCl thinks the given code segment is valid. */ | 165 /* check if NaCl thinks the given code segment is valid. */ |
| 166 NaClSetAllCPUFeatures(&cpu_features); | 166 NaClSetAllCPUFeatures(&cpu_features); |
| 167 status = NaCl_ApplyValidator_x86_64( | 167 status = NaCl_ApplyValidator_x86_64( |
| 168 NACL_SB_DEFAULT, vbase, mbase, size, 32, | 168 NACL_SB_DEFAULT, vbase, mbase, size, |
| 169 /* stubout_mode= */ FALSE, /* readonly_text= */ FALSE, &cpu_features, | 169 /* stubout_mode= */ FALSE, /* readonly_text= */ FALSE, &cpu_features, |
| 170 NULL); | 170 NULL); |
| 171 switch (status) { | 171 switch (status) { |
| 172 case NaClValidationSucceeded: | 172 case NaClValidationSucceeded: |
| 173 return TRUE; | 173 return TRUE; |
| 174 default: | 174 default: |
| 175 return FALSE; | 175 return FALSE; |
| 176 } | 176 } |
| 177 } | 177 } |
| OLD | NEW |