From 80a086c59537a006c36c8433a011f0a76e8a84d4 Mon Sep 17 00:00:00 2001 From: "agl@chromium.org" Date: Tue, 4 Aug 2009 17:52:04 +0000 Subject: Linux: don't try and read shmmax in the sandbox. In the sandbox, reading shmmax from proc always fails. Thus, we move the function into base and call it before starting the sandbox. The value is then cached. http://codereview.chromium.org/159843 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22393 0039d316-1c4b-4281-b951-d872f2087c98 --- base/sys_info.h | 5 +++++ base/sys_info_posix.cc | 18 ++++++++++++++++++ chrome/browser/zygote_main_linux.cc | 3 +++ chrome/renderer/render_process.cc | 14 +------------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/base/sys_info.h b/base/sys_info.h index 581720d..5469da54 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -65,6 +65,11 @@ class SysInfo { // allocate. static size_t VMAllocationGranularity(); +#if defined(OS_LINUX) + // Returns the maximum SysV shared memory segment size. + static size_t MaxSharedMemorySize(); +#endif + #if defined(OS_CHROMEOS) // Returns the name of the version entry we wish to look up in the // Linux Standard Base release information file. diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc index 388ccba..23156e2 100644 --- a/base/sys_info_posix.cc +++ b/base/sys_info_posix.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/file_util.h" #include "base/sys_info.h" #include "base/basictypes.h" @@ -150,4 +151,21 @@ size_t SysInfo::VMAllocationGranularity() { return getpagesize(); } +#if defined(OS_LINUX) +// static +size_t SysInfo::MaxSharedMemorySize() { + static size_t limit; + static bool limit_valid = false; + + if (!limit_valid) { + std::string contents; + file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); + limit = strtoul(contents.c_str(), NULL, 0); + limit_valid = true; + } + + return limit; +} +#endif + } // namespace base diff --git a/chrome/browser/zygote_main_linux.cc b/chrome/browser/zygote_main_linux.cc index 01eb837..6752a06 100644 --- a/chrome/browser/zygote_main_linux.cc +++ b/chrome/browser/zygote_main_linux.cc @@ -17,6 +17,7 @@ #include "base/path_service.h" #include "base/pickle.h" #include "base/rand_util.h" +#include "base/sys_info.h" #include "base/unix_domain_socket_posix.h" #include "chrome/browser/zygote_host_linux.h" @@ -313,6 +314,8 @@ static bool MaybeEnterChroot() { // files and cache the results or the descriptors. base::RandUint64(); + base::SysInfo::MaxSharedMemorySize(); + // To make wcstombs/mbstowcs work in a renderer, setlocale() has to be // called before the sandbox is triggered. It's possible to avoid calling // setlocale() by pulling out the conversion between FilePath and diff --git a/chrome/renderer/render_process.cc b/chrome/renderer/render_process.cc index 2718d37..d670a25 100644 --- a/chrome/renderer/render_process.cc +++ b/chrome/renderer/render_process.cc @@ -32,18 +32,6 @@ #include "media/base/media.h" #include "webkit/glue/webkit_glue.h" -static size_t GetMaxSharedMemorySize() { - static int size = 0; -#if defined(OS_LINUX) - if (size == 0) { - std::string contents; - file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents); - size = strtoul(contents.c_str(), NULL, 0); - } -#endif - return size; -} - //----------------------------------------------------------------------------- RenderProcess::RenderProcess() @@ -166,7 +154,7 @@ skia::PlatformCanvas* RenderProcess::GetDrawingCanvas( int width = rect.width(); int height = rect.height(); const size_t stride = skia::PlatformCanvas::StrideForWidth(rect.width()); - const size_t max_size = GetMaxSharedMemorySize(); + const size_t max_size = base::SysInfo::MaxSharedMemorySize(); // If the requested size is too big, reduce the height. Ideally we might like // to reduce the width as well to make the size reduction more "balanced", but -- cgit v1.1