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

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

Issue 9535001: Add validation caching interface. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Header update 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-64 architecture. */ 7 /* Implement the ApplyValidator API for the x86-64 architecture. */
8 #include <assert.h> 8 #include <assert.h>
9 #include "native_client/src/trusted/validator/ncvalidate.h" 9 #include "native_client/src/trusted/validator/ncvalidate.h"
10 10
11 #include "native_client/src/shared/platform/nacl_log.h" 11 #include "native_client/src/shared/platform/nacl_log.h"
12 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter. h" 12 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter. h"
13 /* HACK to get access to did_stub_out */
Mark Seaborn 2012/03/01 19:23:12 Ditto. Add an accessor function? (At least you s
Nick Bray (chromium) 2012/03/01 21:16:58 Done.
14 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter_ internal.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-64") 18 # error("Can't compile, target is for x86-64")
17 #else 19 #else
18 # if NACL_TARGET_SUBARCH != 64 20 # if NACL_TARGET_SUBARCH != 64
19 # error("Can't compile, target is for x86-64") 21 # error("Can't compile, target is for x86-64")
20 # endif 22 # endif
21 #endif 23 #endif
22 24
23 NaClValidationStatus NaClValidatorSetup_x86_64( 25 NaClValidationStatus NaClValidatorSetup_x86_64(
24 uintptr_t guest_addr, 26 uintptr_t guest_addr,
25 size_t size, 27 size_t size,
26 int bundle_size, 28 int bundle_size,
27 NaClCPUFeaturesX86 *cpu_features, 29 NaClCPUFeaturesX86 *cpu_features,
28 struct NaClValidatorState** vstate_ptr) { 30 struct NaClValidatorState** vstate_ptr) {
29 *vstate_ptr = NaClValidatorStateCreate(guest_addr, size, bundle_size, RegR15, 31 *vstate_ptr = NaClValidatorStateCreate(guest_addr, size, bundle_size, RegR15,
30 cpu_features); 32 cpu_features);
31 return (*vstate_ptr == NULL) 33 return (*vstate_ptr == NULL)
32 ? NaClValidationFailedOutOfMemory 34 ? NaClValidationFailedOutOfMemory
33 : NaClValidationSucceeded; /* or at least to this point! */ 35 : NaClValidationSucceeded; /* or at least to this point! */
34 } 36 }
35 37
36 Bool NaClSegmentValidate_x86_64(
37 uintptr_t guest_addr,
38 uint8_t *data,
39 size_t size,
40 struct NaClValidatorState* vstate) {
41 Bool is_ok;
42 NaClValidateSegment(data, guest_addr, size, vstate);
43 is_ok = NaClValidatesOk(vstate);
44 NaClValidatorStateDestroy(vstate);
45 return is_ok;
46 }
47
48 static NaClValidationStatus NaClApplyValidatorSilently_x86_64( 38 static NaClValidationStatus NaClApplyValidatorSilently_x86_64(
49 uintptr_t guest_addr, 39 uintptr_t guest_addr,
50 uint8_t *data, 40 uint8_t *data,
51 size_t size, 41 size_t size,
52 int bundle_size, 42 int bundle_size,
53 NaClCPUFeaturesX86 *cpu_features) { 43 NaClCPUFeaturesX86 *cpu_features,
44 NaClValidationCache *cache) {
54 struct NaClValidatorState *vstate; 45 struct NaClValidatorState *vstate;
55 NaClValidationStatus status = 46 NaClValidationStatus status;
47 void *query = NULL;
48
49 if (cache != NULL)
50 query = cache->CreateQuery(cache->handle);
51
52 if (query != NULL) {
53 const char validator_id[] = "x86-64";
54 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id));
55 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features));
56 cache->AddData(query, data, size);
57 if (cache->QueryCodeValidates(query)) {
58 cache->DestroyQuery(query);
59 return NaClValidationSucceeded;
60 }
61 }
62
63 status =
56 NaClValidatorSetup_x86_64(guest_addr, size, bundle_size, cpu_features, 64 NaClValidatorSetup_x86_64(guest_addr, size, bundle_size, cpu_features,
57 &vstate); 65 &vstate);
58 if (status != NaClValidationSucceeded) return status; 66
67 if (status != NaClValidationSucceeded) {
68 if (query != NULL)
69 cache->DestroyQuery(query);
70 return status;
71 }
59 NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR); 72 NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR);
60 return NaClSegmentValidate_x86_64(guest_addr, data, size, vstate) 73 NaClValidateSegment(data, guest_addr, size, vstate);
61 ? NaClValidationSucceeded : NaClValidationFailed; 74 status =
75 NaClValidatesOk(vstate) ? NaClValidationSucceeded : NaClValidationFailed;
76
77 if (query != NULL) {
78 /* Don't cache the result if the code is modified. */
79 if (status == NaClValidationSucceeded && vstate->did_stub_out == 0)
80 cache->SetCodeValidates(query);
81 cache->DestroyQuery(query);
82 }
83 NaClValidatorStateDestroy(vstate);
84 return status;
62 } 85 }
63 86
64 NaClValidationStatus NaClApplyValidatorStubout_x86_64( 87 NaClValidationStatus NaClApplyValidatorStubout_x86_64(
65 uintptr_t guest_addr, 88 uintptr_t guest_addr,
66 uint8_t *data, 89 uint8_t *data,
67 size_t size, 90 size_t size,
68 int bundle_size, 91 int bundle_size,
69 NaClCPUFeaturesX86 *cpu_features) { 92 NaClCPUFeaturesX86 *cpu_features) {
70 struct NaClValidatorState *vstate; 93 struct NaClValidatorState *vstate;
71 NaClValidationStatus status = 94 NaClValidationStatus status =
72 NaClValidatorSetup_x86_64(guest_addr, size, bundle_size, cpu_features, 95 NaClValidatorSetup_x86_64(guest_addr, size, bundle_size, cpu_features,
73 &vstate); 96 &vstate);
74 if (status != NaClValidationSucceeded) return status; 97 if (status != NaClValidationSucceeded) return status;
75 NaClValidatorStateSetDoStubOut(vstate, TRUE); 98 NaClValidatorStateSetDoStubOut(vstate, TRUE);
76 NaClSegmentValidate_x86_64(guest_addr, data, size, vstate); 99 NaClValidateSegment(data, guest_addr, size, vstate);
100 NaClValidatorStateDestroy(vstate);
77 return NaClValidationSucceeded; 101 return NaClValidationSucceeded;
78 } 102 }
79 103
80 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, x86, 64) ( 104 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, x86, 64) (
81 enum NaClSBKind sb_kind, 105 enum NaClSBKind sb_kind,
82 NaClApplyValidationKind kind, 106 NaClApplyValidationKind kind,
83 uintptr_t guest_addr, 107 uintptr_t guest_addr,
84 uint8_t *data, 108 uint8_t *data,
85 size_t size, 109 size_t size,
86 int bundle_size, 110 int bundle_size,
87 NaClCPUFeaturesX86 *cpu_features) { 111 NaClCPUFeaturesX86 *cpu_features,
112 NaClValidationCache *cache) {
88 NaClValidationStatus status = NaClValidationFailedNotImplemented; 113 NaClValidationStatus status = NaClValidationFailedNotImplemented;
89 assert(NACL_SB_DEFAULT == sb_kind); 114 assert(NACL_SB_DEFAULT == sb_kind);
90 if (bundle_size == 16 || bundle_size == 32) { 115 if (bundle_size == 16 || bundle_size == 32) {
91 if (!NaClArchSupported(cpu_features)) 116 if (!NaClArchSupported(cpu_features))
92 return NaClValidationFailedCpuNotSupported; 117 return NaClValidationFailedCpuNotSupported;
93 switch (kind) { 118 switch (kind) {
94 case NaClApplyCodeValidation: 119 case NaClApplyCodeValidation:
95 status = NaClApplyValidatorSilently_x86_64( 120 status = NaClApplyValidatorSilently_x86_64(
96 guest_addr, data, size, bundle_size, cpu_features); 121 guest_addr, data, size, bundle_size, cpu_features, cache);
97 break; 122 break;
98 case NaClApplyValidationDoStubout: 123 case NaClApplyValidationDoStubout:
99 status = NaClApplyValidatorStubout_x86_64( 124 status = NaClApplyValidatorStubout_x86_64(
100 guest_addr, data, size, bundle_size, cpu_features); 125 guest_addr, data, size, bundle_size, cpu_features);
101 break; 126 break;
102 default: 127 default:
103 break; 128 break;
104 } 129 }
105 } 130 }
106 return status; 131 return status;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if (bundle_size == 16 || bundle_size == 32) { 164 if (bundle_size == 16 || bundle_size == 32) {
140 if (!NaClArchSupported(cpu_features)) { 165 if (!NaClArchSupported(cpu_features)) {
141 status = NaClValidationFailedCpuNotSupported; 166 status = NaClValidationFailedCpuNotSupported;
142 } else { 167 } else {
143 status = NaClApplyValidatorPair(guest_addr, data_old, data_new, 168 status = NaClApplyValidatorPair(guest_addr, data_old, data_new,
144 size, bundle_size, cpu_features); 169 size, bundle_size, cpu_features);
145 } 170 }
146 } 171 }
147 return status; 172 return status;
148 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698