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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include "native_client/src/trusted/validator/validation_cache.h"
8
9 #include "native_client/src/shared/platform/nacl_check.h"
10 #include "native_client/src/trusted/validator/validation_metadata.h"
11
12 #define ADD_LITERAL(cache, query, data) \
13 ((cache)->AddData((query), (uint8_t*)&(data), sizeof(data)))
14
15 void AddCodeIdentity(uint8_t *data,
16 size_t size,
17 const struct NaClValidationMetadata *metadata,
18 struct NaClValidationCache *cache,
19 void *query) {
20 NaClCodeIdentityType identity_type;
21 if (NULL != metadata) {
22 identity_type = metadata->identity_type;
23 } else {
24 /* Fallback: identity unknown, treat it as anonymous data. */
25 identity_type = NaClCodeIdentityData;
26 }
27 CHECK(identity_type < NaClCodeIdentityMax);
28
29 /*
30 * Explicitly record the type of identity being used to prevent attacks
31 * that confuse the payload of different identity types.
32 */
33 ADD_LITERAL(cache, query, identity_type);
34
35 if (identity_type == NaClCodeIdentityFile) {
36 /* Sanity checks. */
37 CHECK(metadata->file_name);
38 CHECK(metadata->file_name_length);
39 CHECK(metadata->code_offset + (int64_t) size <= metadata->file_size);
40
41 /* The location of the code in the file. */
42 ADD_LITERAL(cache, query, metadata->code_offset);
43 ADD_LITERAL(cache, query, size);
44
45 /* The identity of the file. */
46 cache->AddData(query, (uint8_t *) metadata->file_name,
47 metadata->file_name_length);
48 ADD_LITERAL(cache, query, metadata->file_size);
49 ADD_LITERAL(cache, query, metadata->mtime);
50 } else {
51 /* Hash all the code. */
52 cache->AddData(query, data, size);
53 }
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698