Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: mandoline/app/desktop/main.cc

Issue 1264463005: mandoline sandbox: prewarm libraries before we raise the sandbox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mandoline/app/desktop/linux_sandbox.cc ('k') | mandoline/services/core_services/main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "mandoline/app/desktop/launcher_process.h" 9 #include "mandoline/app/desktop/launcher_process.h"
10 #include "mojo/runner/child_process.h" 10 #include "mojo/runner/child_process.h"
11 #include "mojo/runner/init.h" 11 #include "mojo/runner/init.h"
12 #include "mojo/runner/native_application_support.h" 12 #include "mojo/runner/native_application_support.h"
13 #include "mojo/runner/switches.h" 13 #include "mojo/runner/switches.h"
14 #include "mojo/shell/native_runner.h" 14 #include "mojo/shell/native_runner.h"
15 15
16 #if defined(OS_LINUX) && !defined(OS_ANDROID) 16 #if defined(OS_LINUX) && !defined(OS_ANDROID)
17 #include "base/rand_util.h"
18 #include "base/sys_info.h"
17 #include "mandoline/app/desktop/linux_sandbox.h" 19 #include "mandoline/app/desktop/linux_sandbox.h"
18 #endif 20 #endif
19 21
20 int main(int argc, char** argv) { 22 int main(int argc, char** argv) {
21 base::CommandLine::Init(argc, argv); 23 base::CommandLine::Init(argc, argv);
22 const base::CommandLine& command_line = 24 const base::CommandLine& command_line =
23 *base::CommandLine::ForCurrentProcess(); 25 *base::CommandLine::ForCurrentProcess();
24 26
27 base::NativeLibrary app_library = 0;
25 #if defined(OS_LINUX) && !defined(OS_ANDROID) 28 #if defined(OS_LINUX) && !defined(OS_ANDROID)
26 using sandbox::syscall_broker::BrokerFilePermission; 29 using sandbox::syscall_broker::BrokerFilePermission;
27 scoped_ptr<mandoline::LinuxSandbox> sandbox; 30 scoped_ptr<mandoline::LinuxSandbox> sandbox;
28 if (command_line.HasSwitch(switches::kChildProcess) && 31 #endif
29 command_line.HasSwitch(switches::kEnableSandbox)) { 32 if (command_line.HasSwitch(switches::kChildProcess)) {
30 std::vector<BrokerFilePermission> permissions = 33 // Load the application library before we engage the sandbox.
31 mandoline::LinuxSandbox::GetPermissions(); 34 mojo::shell::NativeApplicationCleanup cleanup =
32 permissions.push_back(BrokerFilePermission::ReadOnly( 35 command_line.HasSwitch(switches::kDeleteAfterLoad) ?
33 command_line.GetSwitchValueNative(switches::kChildProcess))); 36 mojo::shell::NativeApplicationCleanup::DELETE :
37 mojo::shell::NativeApplicationCleanup::DONT_DELETE;
38 app_library = mojo::runner::LoadNativeApplication(
39 command_line.GetSwitchValuePath(switches::kChildProcess),
40 cleanup);
Elliot Glaysher 2015/07/29 17:36:38 Fun fact: app cleanup was also broken in the previ
41 #if defined(OS_LINUX) && !defined(OS_ANDROID)
42 if (command_line.HasSwitch(switches::kEnableSandbox)) {
43 // Warm parts of base.
44 base::RandUint64();
45 base::SysInfo::AmountOfPhysicalMemory();
46 base::SysInfo::MaxSharedMemorySize();
47 base::SysInfo::NumberOfProcessors();
34 48
35 sandbox.reset(new mandoline::LinuxSandbox(permissions)); 49 // Do whatever warming that the mojo application wants.
36 sandbox->Warmup(); 50 typedef void(*SandboxWarmFunction)();
37 sandbox->EngageNamespaceSandbox(); 51 SandboxWarmFunction sandbox_warm = reinterpret_cast<SandboxWarmFunction>(
38 sandbox->EngageSeccompSandbox(); 52 base::GetFunctionPointerFromNativeLibrary(app_library,
39 sandbox->Seal(); 53 "MojoSandboxWarm"));
54 if (sandbox_warm)
55 sandbox_warm();
56
57 std::vector<BrokerFilePermission> permissions;
58 sandbox.reset(new mandoline::LinuxSandbox(permissions));
59 sandbox->Warmup();
60 sandbox->EngageNamespaceSandbox();
61 sandbox->EngageSeccompSandbox();
62 sandbox->Seal();
63 }
64 #endif
40 } 65 }
41 #endif
42 66
43 base::AtExitManager at_exit; 67 base::AtExitManager at_exit;
44 mojo::runner::InitializeLogging(); 68 mojo::runner::InitializeLogging();
45 mojo::runner::WaitForDebuggerIfNecessary(); 69 mojo::runner::WaitForDebuggerIfNecessary();
46 70
47 if (command_line.HasSwitch(switches::kChildProcess)) 71 if (command_line.HasSwitch(switches::kChildProcess))
48 return mojo::runner::ChildProcessMain(); 72 return mojo::runner::ChildProcessMain(app_library);
49 73
50 return mandoline::LauncherProcessMain(argc, argv); 74 return mandoline::LauncherProcessMain(argc, argv);
51 } 75 }
OLDNEW
« no previous file with comments | « mandoline/app/desktop/linux_sandbox.cc ('k') | mandoline/services/core_services/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698