Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(816)

Side by Side Diff: src/trusted/validator/x86/32/ncvalidate.c

Issue 9535001: Add validation caching interface. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: More edits Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /* Implement the ApplyValidator API for the x86-32 architecture. */ 7 /* Implement the ApplyValidator API for the x86-32 architecture. */
8 8
9 #include "native_client/src/trusted/validator/ncvalidate.h" 9 #include "native_client/src/trusted/validator/ncvalidate.h"
10 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.h" 10 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.h"
11 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_detai led.h" 11 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_detai led.h"
12 /* HACK to get access to didstubout */
13 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_inter naltypes.h"
12 #include <assert.h> 14 #include <assert.h>
13 15
14 /* Be sure the correct compile flags are defined for this. */ 16 /* Be sure the correct compile flags are defined for this. */
15 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 17 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86
16 # error("Can't compile, target is for x86-32") 18 # error("Can't compile, target is for x86-32")
17 #else 19 #else
18 # if NACL_TARGET_SUBARCH != 32 20 # if NACL_TARGET_SUBARCH != 32
19 # error("Can't compile, target is for x86-32") 21 # error("Can't compile, target is for x86-32")
20 # endif 22 # endif
21 #endif 23 #endif
22 24
23 static NaClValidationStatus NCApplyValidatorSilently_x86_32( 25 static NaClValidationStatus NCApplyValidatorSilently_x86_32(
24 uintptr_t guest_addr, 26 uintptr_t guest_addr,
25 uint8_t *data, 27 uint8_t *data,
26 size_t size, 28 size_t size,
27 int bundle_size, 29 int bundle_size,
28 NaClCPUFeaturesX86 *cpu_features) { 30 NaClCPUFeaturesX86 *cpu_features,
31 NaClValidationCache *cache) {
29 struct NCValidatorState *vstate; 32 struct NCValidatorState *vstate;
30 int validator_result = 0; 33 int validator_result = 0;
34 void *query = NULL;
35
36 if (cache != NULL)
37 query = cache->CreateQuery(cache->handle);
38
39 if (query != NULL) {
40 const char validator_id[] = "x86-32";
41 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id));
42 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features));
43 cache->AddData(query, data, size);
44 if (cache->QueryCodeValidates(query)) {
45 cache->DestroyQuery(query);
bsy 2012/03/01 19:22:50 the cache->DestroyQuery invocations throughout her
46 return NaClValidationSucceeded;
47 }
48 }
31 49
32 vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features); 50 vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features);
33 if (vstate == NULL) return NaClValidationFailedOutOfMemory; 51 if (vstate == NULL) {
52 if (query != NULL)
53 cache->DestroyQuery(query);
54 return NaClValidationFailedOutOfMemory;
55 }
34 NCValidateSegment(data, guest_addr, size, vstate); 56 NCValidateSegment(data, guest_addr, size, vstate);
35 validator_result = NCValidateFinish(vstate); 57 validator_result = NCValidateFinish(vstate);
58
59 if (query != NULL) {
60 /* Don't cache the result if the code is modified. */
61 if (validator_result == 0 && vstate->stats.didstubout == 0)
62 cache->SetCodeValidates(query);
63 cache->DestroyQuery(query);
64 }
65
36 NCValidateFreeState(&vstate); 66 NCValidateFreeState(&vstate);
37 return (validator_result == 0) 67 return (validator_result == 0)
38 ? NaClValidationSucceeded : NaClValidationFailed; 68 ? NaClValidationSucceeded : NaClValidationFailed;
39 } 69 }
40 70
41 NaClValidationStatus NCApplyValidatorStubout_x86_32( 71 NaClValidationStatus NCApplyValidatorStubout_x86_32(
42 uintptr_t guest_addr, 72 uintptr_t guest_addr,
43 uint8_t *data, 73 uint8_t *data,
44 size_t size, 74 size_t size,
45 int bundle_size, 75 int bundle_size,
46 NaClCPUFeaturesX86 *cpu_features) { 76 NaClCPUFeaturesX86 *cpu_features) {
47 struct NCValidatorState *vstate; 77 struct NCValidatorState *vstate;
48 78
49 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features); 79 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features);
50 if (vstate == NULL) return NaClValidationFailedOutOfMemory; 80 if (vstate == NULL) return NaClValidationFailedOutOfMemory;
51 NCValidateSetStubOutMode(vstate, 1); 81 NCValidateSetStubOutMode(vstate, 1);
52 NCValidateSegment(data, guest_addr, size, vstate); 82 NCValidateSegment(data, guest_addr, size, vstate);
53 NCValidateFinish(vstate); 83 NCValidateFinish(vstate);
54 NCValidateFreeState(&vstate); 84 NCValidateFreeState(&vstate);
55 return NaClValidationSucceeded; 85 return NaClValidationSucceeded;
56 } 86 }
57 87
58 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) ( 88 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) (
59 enum NaClSBKind sb_kind, 89 enum NaClSBKind sb_kind,
60 NaClApplyValidationKind kind, 90 NaClApplyValidationKind kind,
61 uintptr_t guest_addr, 91 uintptr_t guest_addr,
62 uint8_t *data, 92 uint8_t *data,
63 size_t size, 93 size_t size,
64 int bundle_size, 94 int bundle_size,
65 NaClCPUFeaturesX86 *cpu_features) { 95 NaClCPUFeaturesX86 *cpu_features,
96 NaClValidationCache *cache) {
66 NaClValidationStatus status = NaClValidationFailedNotImplemented; 97 NaClValidationStatus status = NaClValidationFailedNotImplemented;
67 assert(NACL_SB_DEFAULT == sb_kind); 98 assert(NACL_SB_DEFAULT == sb_kind);
68 if (bundle_size == 16 || bundle_size == 32) { 99 if (bundle_size == 16 || bundle_size == 32) {
69 if (!NaClArchSupported(cpu_features)) 100 if (!NaClArchSupported(cpu_features))
70 return NaClValidationFailedCpuNotSupported; 101 return NaClValidationFailedCpuNotSupported;
71 switch (kind) { 102 switch (kind) {
72 case NaClApplyCodeValidation: 103 case NaClApplyCodeValidation:
73 status = NCApplyValidatorSilently_x86_32( 104 status = NCApplyValidatorSilently_x86_32(
74 guest_addr, data, size, bundle_size, cpu_features); 105 guest_addr, data, size, bundle_size, cpu_features, cache);
75 break; 106 break;
76 case NaClApplyValidationDoStubout: 107 case NaClApplyValidationDoStubout:
77 status = NCApplyValidatorStubout_x86_32( 108 status = NCApplyValidatorStubout_x86_32(
78 guest_addr, data, size, bundle_size, cpu_features); 109 guest_addr, data, size, bundle_size, cpu_features);
79 break; 110 break;
80 default: 111 default:
81 /* If reached, it isn't implemented (yet). */ 112 /* If reached, it isn't implemented (yet). */
82 break; 113 break;
83 } 114 }
84 } 115 }
(...skipping 14 matching lines...) Expand all
99 if (!NaClArchSupported(cpu_features)) { 130 if (!NaClArchSupported(cpu_features)) {
100 status = NaClValidationFailedCpuNotSupported; 131 status = NaClValidationFailedCpuNotSupported;
101 } else { 132 } else {
102 status = NCValidateSegmentPair(data_old, data_new, guest_addr, 133 status = NCValidateSegmentPair(data_old, data_new, guest_addr,
103 size, bundle_size, cpu_features) 134 size, bundle_size, cpu_features)
104 ? NaClValidationSucceeded : NaClValidationFailed; 135 ? NaClValidationSucceeded : NaClValidationFailed;
105 } 136 }
106 } 137 }
107 return status; 138 return status;
108 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698