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

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: Bugfix 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..db432aa6df9ab4089b85dc3b705c040d2a69c9bc 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"
+/* TODO(ncbray) is there a better way to access validation stats? */
+#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,44 @@ static NaClValidationStatus NCApplyValidatorSilently_x86_32(
uint8_t *data,
size_t size,
int bundle_size,
- NaClCPUFeaturesX86 *cpu_features) {
+ NaClCPUFeaturesX86 *cpu_features,
+ NaClValidationCache *cache,
+ void *cache_context) {
struct NCValidatorState *vstate;
int validator_result = 0;
+ void *query = NULL;
+
+ 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?
+ query = cache->create_query(cache_context);
+
+ if (query) {
+ 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.
+ cache->add_data(query, (uint8_t *) cpu_features,
+ sizeof(NaClCPUFeaturesX86));
+ cache->add_data(query, data, size);
+ if (cache->do_query(query)) {
+ cache->destroy_query(query);
+ return NaClValidationSucceeded;
+ }
+ }
+
vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features);
- if (vstate == NULL) return NaClValidationFailedOutOfMemory;
+ if (vstate == NULL) {
+ if (query)
+ cache->destroy_query(query);
+ return NaClValidationFailedOutOfMemory;
+ }
NCValidateSegment(data, guest_addr, size, vstate);
validator_result = NCValidateFinish(vstate);
+
+ if (query) {
+ /* Don't cache the result if the code is modified. */
+ if (validator_result == 0 && vstate->stats.didstubout == 0)
+ cache->set_validates(query);
+ cache->destroy_query(query);
+ }
+
NCValidateFreeState(&vstate);
return (validator_result == 0)
? NaClValidationSucceeded : NaClValidationFailed;
@@ -62,7 +94,9 @@ 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,
+ void *cache_context) {
NaClValidationStatus status = NaClValidationFailedNotImplemented;
assert(NACL_SB_DEFAULT == sb_kind);
if (bundle_size == 16 || bundle_size == 32) {
@@ -71,7 +105,8 @@ 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,
+ cache_context);
break;
case NaClApplyValidationDoStubout:
status = NCApplyValidatorStubout_x86_32(

Powered by Google App Engine
This is Rietveld 408576698