| 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 * nccopycode.c | 8 * nccopycode.c |
| 9 * Copies two code streams in a thread-safe way | 9 * Copies two code streams in a thread-safe way |
| 10 * | 10 * |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 NCDecoderInst *dinst_new) { | 254 NCDecoderInst *dinst_new) { |
| 255 NCRemainingMemory* mem_old = &dinst_old->dstate->memory; | 255 NCRemainingMemory* mem_old = &dinst_old->dstate->memory; |
| 256 NCRemainingMemory* mem_new = &dinst_new->dstate->memory; | 256 NCRemainingMemory* mem_new = &dinst_new->dstate->memory; |
| 257 | 257 |
| 258 return CopyInstructionInternal(mem_old->mpc, | 258 return CopyInstructionInternal(mem_old->mpc, |
| 259 mem_new->mpc, | 259 mem_new->mpc, |
| 260 mem_old->read_length); | 260 mem_old->read_length); |
| 261 } | 261 } |
| 262 | 262 |
| 263 int NCCopyCode(uint8_t *dst, uint8_t *src, NaClPcAddress vbase, | 263 int NCCopyCode(uint8_t *dst, uint8_t *src, NaClPcAddress vbase, |
| 264 size_t sz, int bundle_size) { | 264 size_t sz) { |
| 265 NCDecoderState dst_dstate; | 265 NCDecoderState dst_dstate; |
| 266 NCDecoderInst dst_inst; | 266 NCDecoderInst dst_inst; |
| 267 NCDecoderState src_dstate; | 267 NCDecoderState src_dstate; |
| 268 NCDecoderInst src_inst; | 268 NCDecoderInst src_inst; |
| 269 NCDecoderStatePair pair; | 269 NCDecoderStatePair pair; |
| 270 int result = 0; | 270 int result = 0; |
| 271 | 271 |
| 272 NCDecoderStateConstruct(&dst_dstate, dst, vbase, sz, &dst_inst, 1); | 272 NCDecoderStateConstruct(&dst_dstate, dst, vbase, sz, &dst_inst, 1); |
| 273 NCDecoderStateConstruct(&src_dstate, src, vbase, sz, &src_inst, 1); | 273 NCDecoderStateConstruct(&src_dstate, src, vbase, sz, &src_inst, 1); |
| 274 NCDecoderStatePairConstruct(&pair, &dst_dstate, &src_dstate); | 274 NCDecoderStatePairConstruct(&pair, &dst_dstate, &src_dstate); |
| 275 pair.action_fn = CopyInstruction; | 275 pair.action_fn = CopyInstruction; |
| 276 if (NCDecoderStatePairDecode(&pair)) result = 1; | 276 if (NCDecoderStatePairDecode(&pair)) result = 1; |
| 277 NCDecoderStatePairDestruct(&pair); | 277 NCDecoderStatePairDestruct(&pair); |
| 278 NCDecoderStateDestruct(&src_dstate); | 278 NCDecoderStateDestruct(&src_dstate); |
| 279 NCDecoderStateDestruct(&dst_dstate); | 279 NCDecoderStateDestruct(&dst_dstate); |
| 280 | 280 |
| 281 return result; | 281 return result; |
| 282 } | 282 } |
| 283 | 283 |
| 284 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, | 284 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, |
| 285 NACL_TARGET_ARCH, | 285 NACL_TARGET_ARCH, |
| 286 NACL_TARGET_SUBARCH) | 286 NACL_TARGET_SUBARCH) |
| 287 (enum NaClSBKind sb_kind, | 287 (enum NaClSBKind sb_kind, |
| 288 uintptr_t guest_addr, | 288 uintptr_t guest_addr, |
| 289 uint8_t *data_old, | 289 uint8_t *data_old, |
| 290 uint8_t *data_new, | 290 uint8_t *data_new, |
| 291 size_t size, | 291 size_t size, |
| 292 int bundle_size, | |
| 293 const NaClCPUFeaturesX86 *cpu_features) { | 292 const NaClCPUFeaturesX86 *cpu_features) { |
| 294 NaClValidationStatus status = NaClValidationFailedNotImplemented; | |
| 295 assert(NACL_SB_DEFAULT == sb_kind); | 293 assert(NACL_SB_DEFAULT == sb_kind); |
| 296 if (bundle_size == 16 || bundle_size == 32) { | 294 |
| 297 if (!NaClArchSupported(cpu_features)) { | 295 if (!NaClArchSupported(cpu_features)) |
| 298 status = NaClValidationFailedCpuNotSupported; | 296 return NaClValidationFailedCpuNotSupported; |
| 299 } else { | 297 |
| 300 status = ((0 == NCCopyCode(data_old, data_new, guest_addr, | 298 return ((0 == NCCopyCode(data_old, data_new, guest_addr, |
| 301 size, bundle_size)) | 299 size)) |
| 302 ? NaClValidationFailed : NaClValidationSucceeded); | 300 ? NaClValidationFailed : NaClValidationSucceeded); |
| 303 } | |
| 304 } | |
| 305 return status; | |
| 306 } | 301 } |
| 307 | 302 |
| 308 #elif NACL_TARGET_SUBARCH == 64 | 303 #elif NACL_TARGET_SUBARCH == 64 |
| 309 | 304 |
| 310 int NaClCopyCodeIter(uint8_t *dst, uint8_t *src, | 305 int NaClCopyCodeIter(uint8_t *dst, uint8_t *src, |
| 311 NaClPcAddress vbase, size_t size) { | 306 NaClPcAddress vbase, size_t size) { |
| 312 NaClSegment segment_old, segment_new; | 307 NaClSegment segment_old, segment_new; |
| 313 NaClInstIter *iter_old, *iter_new; | 308 NaClInstIter *iter_old, *iter_new; |
| 314 NaClInstState *istate_old, *istate_new; | 309 NaClInstState *istate_old, *istate_new; |
| 315 int still_good = 1; | 310 int still_good = 1; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 369 } |
| 375 | 370 |
| 376 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, | 371 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, |
| 377 NACL_TARGET_ARCH, | 372 NACL_TARGET_ARCH, |
| 378 NACL_TARGET_SUBARCH) | 373 NACL_TARGET_SUBARCH) |
| 379 (enum NaClSBKind sb_kind, | 374 (enum NaClSBKind sb_kind, |
| 380 uintptr_t guest_addr, | 375 uintptr_t guest_addr, |
| 381 uint8_t *data_old, | 376 uint8_t *data_old, |
| 382 uint8_t *data_new, | 377 uint8_t *data_new, |
| 383 size_t size, | 378 size_t size, |
| 384 int bundle_size, | |
| 385 const NaClCPUFeaturesX86 *cpu_features) { | 379 const NaClCPUFeaturesX86 *cpu_features) { |
| 386 NaClValidationStatus status = NaClValidationFailedNotImplemented; | |
| 387 assert(NACL_SB_DEFAULT == sb_kind); | 380 assert(NACL_SB_DEFAULT == sb_kind); |
| 388 if (bundle_size == 16 || bundle_size == 32) { | 381 |
| 389 if (!NaClArchSupported(cpu_features)) { | 382 if (!NaClArchSupported(cpu_features)) |
| 390 status = NaClValidationFailedCpuNotSupported; | 383 return NaClValidationFailedCpuNotSupported; |
| 391 } else { | 384 |
| 392 status = ((0 == NaClCopyCodeIter(data_old, data_new, guest_addr, size)) | 385 return (0 == NaClCopyCodeIter(data_old, data_new, guest_addr, size)) |
| 393 ? NaClValidationFailed : NaClValidationSucceeded); | 386 ? NaClValidationFailed : NaClValidationSucceeded; |
| 394 } | |
| 395 } | |
| 396 return status; | |
| 397 } | 387 } |
| 398 | 388 |
| 399 #endif | 389 #endif |
| OLD | NEW |