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() { |
| 69 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 70 switches::kEnableAndroidSeccompBPF)) { |
| 71 return true; |
| 72 } |
| 73 |
| 74 PreSandboxWarmUp(); |
| 75 |
| 76 sandbox::SandboxBPF sandbox; |
| 77 sandbox.SetSandboxPolicy(new SandboxBPFBasePolicyAndroid()); |
| 78 CHECK(sandbox.StartSandbox(sandbox::SandboxBPF::PROCESS_MULTI_THREADED)); |
39 return true; | 79 return true; |
40 } | 80 } |
41 | 81 |
42 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { | 82 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { |
43 } | 83 } |
44 | 84 |
45 } // namespace content | 85 } // namespace content |
OLD | NEW |