diff options
-rw-r--r-- | base/sys_info.h | 10 | ||||
-rw-r--r-- | base/sys_info_posix.cc | 13 | ||||
-rw-r--r-- | chrome/renderer/renderer_main_platform_delegate_mac.cc | 6 |
3 files changed, 26 insertions, 3 deletions
diff --git a/base/sys_info.h b/base/sys_info.h index 46029cc..35d371b 100644 --- a/base/sys_info.h +++ b/base/sys_info.h @@ -15,7 +15,7 @@ class SysInfo { public: // Return the number of logical processors/cores on the current machine. static int NumberOfProcessors(); - + // Return the number of bytes of physical memory on the current machine. static int64 AmountOfPhysicalMemory(); @@ -57,6 +57,14 @@ class SysInfo { // Return the smallest amount of memory (in bytes) which the VM system will // allocate. static size_t VMAllocationGranularity(); + +#if defined(OS_MACOSX) + // Under the OS X Sandbox, our access to the system is limited, this call + // caches the system info on startup before we turn the Sandbox on. + // The above functions are all wired up to return the cached value so the rest + // of the code can call them in the Sandbox without worrying. + static void CacheSysInfo(); +#endif }; } // namespace base diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc index 9ea3cab..b46d1b4 100644 --- a/base/sys_info_posix.cc +++ b/base/sys_info_posix.cc @@ -24,7 +24,7 @@ namespace base { int SysInfo::NumberOfProcessors() { // It seems that sysconf returns the number of "logical" processors on both // mac and linux. So we get the number of "online logical" processors. - long res = sysconf(_SC_NPROCESSORS_ONLN); + static long res = sysconf(_SC_NPROCESSORS_ONLN); if (res == -1) { NOTREACHED(); return 1; @@ -48,7 +48,7 @@ int64 SysInfo::AmountOfPhysicalMemory() { NOTREACHED(); return 0; } - + return static_cast<int64>(hostinfo.max_mem); #else long pages = sysconf(_SC_PHYS_PAGES); @@ -134,4 +134,13 @@ size_t SysInfo::VMAllocationGranularity() { return getpagesize(); } +// static +void SysInfo::CacheSysInfo() { + // Due to startup time concerns [premature optimization?] we only cache values + // from functions we know to be called in the renderer & fail when the sandbox + // is enabled. + NumberOfProcessors(); + +} + } // namespace base diff --git a/chrome/renderer/renderer_main_platform_delegate_mac.cc b/chrome/renderer/renderer_main_platform_delegate_mac.cc index cb5e750..0ffbc6b 100644 --- a/chrome/renderer/renderer_main_platform_delegate_mac.cc +++ b/chrome/renderer/renderer_main_platform_delegate_mac.cc @@ -10,6 +10,8 @@ extern "C" { #include <sandbox.h> } +#include "base/sys_info.h" + RendererMainPlatformDelegate::RendererMainPlatformDelegate( const MainFunctionParams& parameters) : parameters_(parameters) { @@ -34,6 +36,10 @@ bool RendererMainPlatformDelegate::EnableSandbox() { // succeed. DebugUtil::BeingDebugged(); + // Cache the System info information, since we can't query certain attributes + // with the Sandbox enabled. + base::SysInfo::CacheSysInfo(); + char* error_buff = NULL; int error = sandbox_init(kSBXProfilePureComputation, SANDBOX_NAMED, &error_buff); |