From 94d3be01b6628b7b324c0d737d7634795a23c3d6 Mon Sep 17 00:00:00 2001 From: "ncbray@chromium.org" Date: Wed, 16 May 2012 01:06:48 +0000 Subject: Give browser process the ability to enable and disable NaCl's validation cache. This is groundwork for persisting the cache to disk. The browser needs to know when the cache is disabled so that it can avoid reading it off disk. This will help keep work on the cache from affecting Chrome before the cache is enabled. BUG= http://code.google.com/p/nativeclient/issues/detail?id=2515 TEST= none Review URL: https://chromiumcodereview.appspot.com/10377156 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137329 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/nacl_host/nacl_process_host.cc | 1 + chrome/browser/nacl_host/nacl_validation_cache.cc | 12 +++++++++++- chrome/browser/nacl_host/nacl_validation_cache.h | 7 +++++++ chrome/common/nacl_messages.h | 1 + chrome/common/nacl_types.h | 5 +++-- chrome/nacl/nacl_listener.cc | 14 +++----------- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc index ccb54a1..e1faeba 100644 --- a/chrome/browser/nacl_host/nacl_process_host.cc +++ b/chrome/browser/nacl_host/nacl_process_host.cc @@ -605,6 +605,7 @@ bool NaClProcessHost::StartNaClExecution() { NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); nacl::NaClStartParams params; + params.validation_cache_enabled = nacl_browser->validation_cache.IsEnabled(); params.validation_cache_key = nacl_browser->validation_cache.GetValidationCacheKey(); params.version = chrome::VersionInfo().CreateVersionString(); diff --git a/chrome/browser/nacl_host/nacl_validation_cache.cc b/chrome/browser/nacl_host/nacl_validation_cache.cc index 5916b09..84c45ab 100644 --- a/chrome/browser/nacl_host/nacl_validation_cache.cc +++ b/chrome/browser/nacl_host/nacl_validation_cache.cc @@ -32,11 +32,21 @@ void LogCacheSet(ValidationCacheStatus status) { UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, CACHE_MAX); } +bool CheckEnvVar(const char* name, bool default_value) { + bool result = default_value; + const char* var = getenv(name); + if (var && strlen(var) > 0) { + result = var[0] != '0'; + } + return result; +} + } // namespace NaClValidationCache::NaClValidationCache() : validation_cache_(kValidationCacheCacheSize), - validation_cache_key_(base::RandBytesAsString(kValidationCacheKeySize)){ + validation_cache_key_(base::RandBytesAsString(kValidationCacheKeySize)), + enabled_(CheckEnvVar("NACL_VALIDATION_CACHE", false)){ } NaClValidationCache::~NaClValidationCache() { diff --git a/chrome/browser/nacl_host/nacl_validation_cache.h b/chrome/browser/nacl_host/nacl_validation_cache.h index 8ceb9a7..eace325 100644 --- a/chrome/browser/nacl_host/nacl_validation_cache.h +++ b/chrome/browser/nacl_host/nacl_validation_cache.h @@ -27,12 +27,19 @@ class NaClValidationCache { // Put the validation signature in the database. void SetKnownToValidate(const std::string& signature); + // Should the cache be used? + bool IsEnabled() { + return enabled_; + } + private: typedef base::HashingMRUCache ValidationCacheType; ValidationCacheType validation_cache_; std::string validation_cache_key_; + bool enabled_; + DISALLOW_COPY_AND_ASSIGN(NaClValidationCache); }; diff --git a/chrome/common/nacl_messages.h b/chrome/common/nacl_messages.h index 8200d65..4c8ac1c 100644 --- a/chrome/common/nacl_messages.h +++ b/chrome/common/nacl_messages.h @@ -13,6 +13,7 @@ IPC_STRUCT_TRAITS_BEGIN(nacl::NaClStartParams) IPC_STRUCT_TRAITS_MEMBER(handles) + IPC_STRUCT_TRAITS_MEMBER(validation_cache_enabled) IPC_STRUCT_TRAITS_MEMBER(validation_cache_key) IPC_STRUCT_TRAITS_MEMBER(version) IPC_STRUCT_TRAITS_MEMBER(enable_exception_handling) diff --git a/chrome/common/nacl_types.h b/chrome/common/nacl_types.h index 02b1fda..b374341 100644 --- a/chrome/common/nacl_types.h +++ b/chrome/common/nacl_types.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -45,8 +45,9 @@ struct NaClStartParams { ~NaClStartParams(); std::vector handles; - std::string validation_cache_key; + bool validation_cache_enabled; + std::string validation_cache_key; // Chrome version string. Sending the version string over IPC avoids linkage // issues in cases where NaCl is not compiled into the main Chromium // executable or DLL. diff --git a/chrome/nacl/nacl_listener.cc b/chrome/nacl/nacl_listener.cc index b48555b..e2c2ed2 100644 --- a/chrome/nacl/nacl_listener.cc +++ b/chrome/nacl/nacl_listener.cc @@ -95,16 +95,6 @@ int AttachDebugExceptionHandler(const void* info, size_t info_size) { #endif -// Use an env var because command line args are eaten by nacl_helper. -bool CheckEnvVar(const char* name, bool default_value) { - bool result = default_value; - const char* var = getenv(name); - if (var && strlen(var) > 0) { - result = var[0] != '0'; - } - return result; -} - } // namespace class BrowserValidationDBProxy : public NaClValidationDB { @@ -224,7 +214,9 @@ void NaClListener::OnMsgStart(const nacl::NaClStartParams& params) { args->irt_fd = irt_handle; #endif - if (CheckEnvVar("NACL_VALIDATION_CACHE", false)) { + if (params.validation_cache_enabled) { + // SHA256 block size. + CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); LOG(INFO) << "NaCl validation cache enabled."; // The cache structure is not freed and exists until the NaCl process exits. args->validation_cache = CreateValidationCache( -- cgit v1.1