Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/renderer_main_platform_delegate.h" | 5 #include "content/renderer/renderer_main_platform_delegate.h" |
| 6 | |
| 7 #include "base/command_line.h" | |
| 6 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/rand_util.h" | |
| 10 #include "base/sys_info.h" | |
| 11 #include "content/common/android/sandbox_bpf_base_policy_android.h" | |
| 12 #include "content/public/common/content_switches.h" | |
| 13 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | |
| 14 #include "third_party/skia/include/ports/SkFontConfigInterface.h" | |
| 15 #include "v8/include/v8.h" | |
| 7 | 16 |
| 8 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 17 #ifdef ENABLE_VTUNE_JIT_INTERFACE |
| 9 #include "content/public/common/content_switches.h" | |
| 10 #include "v8/src/third_party/vtune/v8-vtune.h" | 18 #include "v8/src/third_party/vtune/v8-vtune.h" |
| 11 #endif | 19 #endif |
| 12 | 20 |
| 13 namespace content { | 21 namespace content { |
| 14 | 22 |
| 23 namespace { | |
| 24 | |
| 25 bool GenerateEntropy(unsigned char* buffer, size_t length) { | |
| 26 base::RandBytes(buffer, length); | |
| 27 return true; | |
| 28 } | |
| 29 | |
| 30 void PreSandboxWarmUp() { | |
| 31 base::RandUint64(); | |
| 32 | |
| 33 base::SysInfo::AmountOfPhysicalMemory(); | |
| 34 base::SysInfo::MaxSharedMemorySize(); | |
| 35 base::SysInfo::NumberOfProcessors(); | |
| 36 | |
| 37 v8::V8::SetEntropySource(&GenerateEntropy); | |
| 38 v8::V8::Initialize(); | |
| 39 | |
| 40 SkFontConfigInterface::GetSingletonDirectInterface(); | |
| 41 } | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 15 RendererMainPlatformDelegate::RendererMainPlatformDelegate( | 45 RendererMainPlatformDelegate::RendererMainPlatformDelegate( |
| 16 const MainFunctionParams& parameters) | 46 const MainFunctionParams& parameters) |
| 17 : parameters_(parameters) { | 47 : parameters_(parameters) { |
| 18 } | 48 } |
| 19 | 49 |
| 20 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 50 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
| 21 } | 51 } |
| 22 | 52 |
| 23 void RendererMainPlatformDelegate::PlatformInitialize() { | 53 void RendererMainPlatformDelegate::PlatformInitialize() { |
| 24 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 54 #ifdef ENABLE_VTUNE_JIT_INTERFACE |
| 25 const CommandLine& command_line = parameters_.command_line; | 55 const CommandLine& command_line = parameters_.command_line; |
| 26 if (command_line.HasSwitch(switches::kEnableVtune)) | 56 if (command_line.HasSwitch(switches::kEnableVtune)) |
| 27 vTune::InitializeVtuneForV8(); | 57 vTune::InitializeVtuneForV8(); |
| 28 #endif | 58 #endif |
| 29 } | 59 } |
| 30 | 60 |
| 31 void RendererMainPlatformDelegate::PlatformUninitialize() { | 61 void RendererMainPlatformDelegate::PlatformUninitialize() { |
| 32 } | 62 } |
| 33 | 63 |
| 34 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { | 64 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { |
| 35 return true; | 65 return true; |
| 36 } | 66 } |
| 37 | 67 |
| 38 bool RendererMainPlatformDelegate::EnableSandbox() { | 68 bool RendererMainPlatformDelegate::EnableSandbox() { |
| 39 return true; | 69 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 70 switches::kEnableAndroidSeccompBPF)) { | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 PreSandboxWarmUp(); | |
| 75 | |
| 76 sandbox::SandboxBPF sandbox; | |
|
jln (very slow on Chromium)
2014/03/31 22:57:43
I would rather not duplicate this.
Could you use
Robert Sesek
2014/04/08 20:33:45
StartSandboxWithExternalPolicy() will call through
jln (very slow on Chromium)
2014/04/09 05:11:07
I'm on the fence (we could add a parameter to Star
| |
| 77 sandbox.SetSandboxPolicy(new SandboxBPFBasePolicyAndroid()); | |
| 78 sandbox.StartSandbox(); | |
| 79 bool enabled = sandbox.SupportsSeccompSandbox(-1) == | |
| 80 sandbox::SandboxBPF::STATUS_ENABLED; | |
|
jln (very slow on Chromium)
2014/03/31 22:57:43
Let's try and fix StartSandbox() to return a bool
Robert Sesek
2014/04/08 20:33:45
Done.
| |
| 81 CHECK(enabled); | |
| 82 return enabled; | |
| 40 } | 83 } |
| 41 | 84 |
| 42 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { | 85 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { |
| 43 } | 86 } |
| 44 | 87 |
| 45 } // namespace content | 88 } // namespace content |
| OLD | NEW |