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

Unified 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: Header update Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: src/trusted/validator/x86/32/ncvalidate.c
diff --git a/src/trusted/validator/x86/32/ncvalidate.c b/src/trusted/validator/x86/32/ncvalidate.c
index 5b00fc6540bd7a98e7bc7a028dbdd15577820033..09101708c768701c83b1c05a2a644ac01f21f7ca 100644
--- a/src/trusted/validator/x86/32/ncvalidate.c
+++ b/src/trusted/validator/x86/32/ncvalidate.c
@@ -9,6 +9,8 @@
#include "native_client/src/trusted/validator/ncvalidate.h"
#include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.h"
#include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_detailed.h"
+/* HACK to get access to didstubout */
Mark Seaborn 2012/03/01 19:23:12 I thought you were going to add a getter function
Nick Bray (chromium) 2012/03/01 21:16:58 Done.
+#include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_internaltypes.h"
#include <assert.h>
/* Be sure the correct compile flags are defined for this. */
@@ -25,14 +27,42 @@ static NaClValidationStatus NCApplyValidatorSilently_x86_32(
uint8_t *data,
size_t size,
int bundle_size,
- NaClCPUFeaturesX86 *cpu_features) {
+ NaClCPUFeaturesX86 *cpu_features,
+ NaClValidationCache *cache) {
struct NCValidatorState *vstate;
int validator_result = 0;
+ void *query = NULL;
+
+ if (cache != NULL)
+ query = cache->CreateQuery(cache->handle);
+
+ if (query != NULL) {
+ const char validator_id[] = "x86-32";
+ cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id));
+ cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features));
+ cache->AddData(query, data, size);
+ if (cache->QueryCodeValidates(query)) {
+ cache->DestroyQuery(query);
+ return NaClValidationSucceeded;
+ }
+ }
vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features);
- if (vstate == NULL) return NaClValidationFailedOutOfMemory;
+ if (vstate == NULL) {
+ if (query != NULL)
+ cache->DestroyQuery(query);
+ return NaClValidationFailedOutOfMemory;
+ }
NCValidateSegment(data, guest_addr, size, vstate);
validator_result = NCValidateFinish(vstate);
+
+ if (query != NULL) {
+ /* Don't cache the result if the code is modified. */
+ if (validator_result == 0 && vstate->stats.didstubout == 0)
+ cache->SetCodeValidates(query);
+ cache->DestroyQuery(query);
+ }
+
NCValidateFreeState(&vstate);
return (validator_result == 0)
? NaClValidationSucceeded : NaClValidationFailed;
@@ -62,7 +92,8 @@ NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) (
uint8_t *data,
size_t size,
int bundle_size,
- NaClCPUFeaturesX86 *cpu_features) {
+ NaClCPUFeaturesX86 *cpu_features,
+ NaClValidationCache *cache) {
NaClValidationStatus status = NaClValidationFailedNotImplemented;
assert(NACL_SB_DEFAULT == sb_kind);
if (bundle_size == 16 || bundle_size == 32) {
@@ -71,7 +102,7 @@ NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) (
switch (kind) {
case NaClApplyCodeValidation:
status = NCApplyValidatorSilently_x86_32(
- guest_addr, data, size, bundle_size, cpu_features);
+ guest_addr, data, size, bundle_size, cpu_features, cache);
break;
case NaClApplyValidationDoStubout:
status = NCApplyValidatorStubout_x86_32(

Powered by Google App Engine
This is Rietveld 408576698