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

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: Bugfix 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 /* TODO(ncbray) is there a better way to access validation stats? */
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,
32 void *cache_context) {
29 struct NCValidatorState *vstate; 33 struct NCValidatorState *vstate;
30 int validator_result = 0; 34 int validator_result = 0;
31 35
36 void *query = NULL;
37
38 if (cache)
Mark Seaborn 2012/02/29 21:33:34 if (cache != NULL) same elsewhere
Nick Bray (chromium) 2012/02/29 22:58:09 Done, but why?
39 query = cache->create_query(cache_context);
40
41 if (query) {
42 cache->add_data(query, (uint8_t *) "x86-32", (size_t) 6);
Mark Seaborn 2012/02/29 21:33:34 Use: const char val_type_thing[] = "x86-32"; ... s
Nick Bray (chromium) 2012/02/29 22:58:09 Done.
43 cache->add_data(query, (uint8_t *) cpu_features,
44 sizeof(NaClCPUFeaturesX86));
45 cache->add_data(query, data, size);
46 if (cache->do_query(query)) {
47 cache->destroy_query(query);
48 return NaClValidationSucceeded;
49 }
50 }
51
32 vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features); 52 vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features);
33 if (vstate == NULL) return NaClValidationFailedOutOfMemory; 53 if (vstate == NULL) {
54 if (query)
55 cache->destroy_query(query);
56 return NaClValidationFailedOutOfMemory;
57 }
34 NCValidateSegment(data, guest_addr, size, vstate); 58 NCValidateSegment(data, guest_addr, size, vstate);
35 validator_result = NCValidateFinish(vstate); 59 validator_result = NCValidateFinish(vstate);
60
61 if (query) {
62 /* Don't cache the result if the code is modified. */
63 if (validator_result == 0 && vstate->stats.didstubout == 0)
64 cache->set_validates(query);
65 cache->destroy_query(query);
66 }
67
36 NCValidateFreeState(&vstate); 68 NCValidateFreeState(&vstate);
37 return (validator_result == 0) 69 return (validator_result == 0)
38 ? NaClValidationSucceeded : NaClValidationFailed; 70 ? NaClValidationSucceeded : NaClValidationFailed;
39 } 71 }
40 72
41 NaClValidationStatus NCApplyValidatorStubout_x86_32( 73 NaClValidationStatus NCApplyValidatorStubout_x86_32(
42 uintptr_t guest_addr, 74 uintptr_t guest_addr,
43 uint8_t *data, 75 uint8_t *data,
44 size_t size, 76 size_t size,
45 int bundle_size, 77 int bundle_size,
46 NaClCPUFeaturesX86 *cpu_features) { 78 NaClCPUFeaturesX86 *cpu_features) {
47 struct NCValidatorState *vstate; 79 struct NCValidatorState *vstate;
48 80
49 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features); 81 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features);
50 if (vstate == NULL) return NaClValidationFailedOutOfMemory; 82 if (vstate == NULL) return NaClValidationFailedOutOfMemory;
51 NCValidateSetStubOutMode(vstate, 1); 83 NCValidateSetStubOutMode(vstate, 1);
52 NCValidateSegment(data, guest_addr, size, vstate); 84 NCValidateSegment(data, guest_addr, size, vstate);
53 NCValidateFinish(vstate); 85 NCValidateFinish(vstate);
54 NCValidateFreeState(&vstate); 86 NCValidateFreeState(&vstate);
55 return NaClValidationSucceeded; 87 return NaClValidationSucceeded;
56 } 88 }
57 89
58 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) ( 90 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) (
59 enum NaClSBKind sb_kind, 91 enum NaClSBKind sb_kind,
60 NaClApplyValidationKind kind, 92 NaClApplyValidationKind kind,
61 uintptr_t guest_addr, 93 uintptr_t guest_addr,
62 uint8_t *data, 94 uint8_t *data,
63 size_t size, 95 size_t size,
64 int bundle_size, 96 int bundle_size,
65 NaClCPUFeaturesX86 *cpu_features) { 97 NaClCPUFeaturesX86 *cpu_features,
98 NaClValidationCache *cache,
99 void *cache_context) {
66 NaClValidationStatus status = NaClValidationFailedNotImplemented; 100 NaClValidationStatus status = NaClValidationFailedNotImplemented;
67 assert(NACL_SB_DEFAULT == sb_kind); 101 assert(NACL_SB_DEFAULT == sb_kind);
68 if (bundle_size == 16 || bundle_size == 32) { 102 if (bundle_size == 16 || bundle_size == 32) {
69 if (!NaClArchSupported(cpu_features)) 103 if (!NaClArchSupported(cpu_features))
70 return NaClValidationFailedCpuNotSupported; 104 return NaClValidationFailedCpuNotSupported;
71 switch (kind) { 105 switch (kind) {
72 case NaClApplyCodeValidation: 106 case NaClApplyCodeValidation:
73 status = NCApplyValidatorSilently_x86_32( 107 status = NCApplyValidatorSilently_x86_32(
74 guest_addr, data, size, bundle_size, cpu_features); 108 guest_addr, data, size, bundle_size, cpu_features, cache,
109 cache_context);
75 break; 110 break;
76 case NaClApplyValidationDoStubout: 111 case NaClApplyValidationDoStubout:
77 status = NCApplyValidatorStubout_x86_32( 112 status = NCApplyValidatorStubout_x86_32(
78 guest_addr, data, size, bundle_size, cpu_features); 113 guest_addr, data, size, bundle_size, cpu_features);
79 break; 114 break;
80 default: 115 default:
81 /* If reached, it isn't implemented (yet). */ 116 /* If reached, it isn't implemented (yet). */
82 break; 117 break;
83 } 118 }
84 } 119 }
(...skipping 14 matching lines...) Expand all
99 if (!NaClArchSupported(cpu_features)) { 134 if (!NaClArchSupported(cpu_features)) {
100 status = NaClValidationFailedCpuNotSupported; 135 status = NaClValidationFailedCpuNotSupported;
101 } else { 136 } else {
102 status = NCValidateSegmentPair(data_old, data_new, guest_addr, 137 status = NCValidateSegmentPair(data_old, data_new, guest_addr,
103 size, bundle_size, cpu_features) 138 size, bundle_size, cpu_features)
104 ? NaClValidationSucceeded : NaClValidationFailed; 139 ? NaClValidationSucceeded : NaClValidationFailed;
105 } 140 }
106 } 141 }
107 return status; 142 return status;
108 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698