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

Unified Diff: src/trusted/validator/validation_cache.c

Issue 12600034: Provide metadata to validator to allow faster caching. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: First fixes Created 7 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 side-by-side diff with in-line comments
Download patch
Index: src/trusted/validator/validation_cache.c
diff --git a/src/trusted/validator/validation_cache.c b/src/trusted/validator/validation_cache.c
new file mode 100644
index 0000000000000000000000000000000000000000..cf4a3aec6bfcba473fd372ccbbb2b7932948a169
--- /dev/null
+++ b/src/trusted/validator/validation_cache.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2013 The Native Client Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "native_client/src/trusted/validator/validation_cache.h"
+
+#include "native_client/src/shared/platform/nacl_check.h"
+#include "native_client/src/trusted/validator/validation_metadata.h"
+
+#define ADD_LITERAL(cache, query, data) \
+ ((cache)->AddData((query), (uint8_t*)&(data), sizeof(data)))
+
+void AddCodeIdentity(uint8_t *data,
+ size_t size,
+ const struct NaClValidationMetadata *metadata,
+ struct NaClValidationCache *cache,
+ void *query) {
+ NaClCodeIdentityType identity_type;
+ if (NULL != metadata) {
+ identity_type = metadata->identity_type;
+ } else {
+ /* Fallback: identity unknown, treat it as anonymous data. */
+ identity_type = NaClCodeIdentityData;
+ }
+ CHECK(identity_type < NaClCodeIdentityMax);
+
+ /*
+ * Explicitly record the type of identity being used to prevent attacks
+ * that confuse the payload of different identity types.
+ */
+ ADD_LITERAL(cache, query, identity_type);
+
+ if (identity_type == NaClCodeIdentityFile) {
+ /* Sanity checks. */
+ CHECK(metadata->file_name);
+ CHECK(metadata->file_name_length);
+ CHECK(metadata->code_offset + (int64_t) size <= metadata->file_size);
+
+ /* The location of the code in the file. */
+ ADD_LITERAL(cache, query, metadata->code_offset);
+ ADD_LITERAL(cache, query, size);
+
+ /* The identity of the file. */
+ cache->AddData(query, (uint8_t *) metadata->file_name,
+ metadata->file_name_length);
+ ADD_LITERAL(cache, query, metadata->file_size);
+ ADD_LITERAL(cache, query, metadata->mtime);
+ } else {
+ /* Hash all the code. */
+ cache->AddData(query, data, size);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698