Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / renderer / renderer_main_platform_delegate_linux.cc
blobe473ad895f396e65db9bc878663a53c10a713ca6
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
3 // found in the LICENSE file.
5 #include "content/renderer/renderer_main_platform_delegate.h"
7 #include <errno.h>
8 #include <sys/stat.h>
10 #include "base/command_line.h"
11 #include "base/file_util.h"
12 #include "base/logging.h"
13 #include "content/common/sandbox_linux.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/public/common/sandbox_init.h"
17 #ifdef ENABLE_VTUNE_JIT_INTERFACE
18 #include "v8/src/third_party/vtune/v8-vtune.h"
19 #endif
21 namespace content {
23 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
24 const MainFunctionParams& parameters)
25 : parameters_(parameters) {
28 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
31 void RendererMainPlatformDelegate::PlatformInitialize() {
32 #ifdef ENABLE_VTUNE_JIT_INTERFACE
33 const CommandLine& command_line = parameters_.command_line;
34 if (command_line.HasSwitch(switches::kEnableVtune))
35 vTune::InitializeVtuneForV8();
36 #endif
39 void RendererMainPlatformDelegate::PlatformUninitialize() {
42 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
43 // The sandbox is started in the zygote process: zygote_main_linux.cc
44 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox
45 return true;
48 bool RendererMainPlatformDelegate::EnableSandbox() {
49 // The setuid sandbox is started in the zygote process: zygote_main_linux.cc
50 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox
52 // Anything else is started in InitializeSandbox().
53 LinuxSandbox::InitializeSandbox();
54 return true;
57 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) {
58 // The LinuxSandbox class requires going through initialization before
59 // GetStatus() and others can be used. When we are not launched through the
60 // Zygote, this initialization will only happen in the renderer process if
61 // EnableSandbox() above is called, which it won't necesserily be.
62 // This only happens with flags such as --renderer-cmd-prefix which are
63 // for debugging.
64 if (no_sandbox)
65 return;
67 // about:sandbox uses a value returned from LinuxSandbox::GetStatus() before
68 // any renderer has been started.
69 // Here, we test that the status of SeccompBpf in the renderer is consistent
70 // with what LinuxSandbox::GetStatus() said we would do.
71 class LinuxSandbox* linux_sandbox = LinuxSandbox::GetInstance();
72 if (linux_sandbox->GetStatus() & kSandboxLinuxSeccompBpf) {
73 CHECK(linux_sandbox->seccomp_bpf_started());
76 // Under the setuid sandbox, we should not be able to open any file via the
77 // filesystem.
78 if (linux_sandbox->GetStatus() & kSandboxLinuxSUID) {
79 CHECK(!base::PathExists(base::FilePath("/proc/cpuinfo")));
82 #if defined(__x86_64__)
83 // Limit this test to architectures where seccomp BPF is active in renderers.
84 if (linux_sandbox->seccomp_bpf_started()) {
85 errno = 0;
86 // This should normally return EBADF since the first argument is bogus,
87 // but we know that under the seccomp-bpf sandbox, this should return EPERM.
88 CHECK_EQ(fchmod(-1, 07777), -1);
89 CHECK_EQ(errno, EPERM);
91 #endif // __x86_64__
94 } // namespace content