sandbox_init.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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.
4
5#ifndef CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
6#define CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
7
8#include "base/memory/scoped_ptr.h"
9#include "base/process/process.h"
10#include "build/build_config.h"
11#include "content/common/content_export.h"
12
13namespace base {
14class CommandLine;
15class FilePath;
16}
17
18namespace sandbox {
19class SandboxBPFPolicy;
20struct SandboxInterfaceInfo;
21}
22
23namespace content {
24class SandboxedProcessLauncherDelegate;
25
26#if defined(OS_WIN)
27
28// Initialize the sandbox for renderer, gpu, utility, worker, nacl, and plug-in
29// processes, depending on the command line flags. Although The browser process
30// is not sandboxed, this also needs to be called because it will initialize
31// the broker code.
32// Returns true if the sandbox was initialized succesfully, false if an error
33// occurred.  If process_type isn't one that needs sandboxing true is always
34// returned.
35CONTENT_EXPORT bool InitializeSandbox(
36    sandbox::SandboxInterfaceInfo* sandbox_info);
37
38// This is a restricted version of Windows' DuplicateHandle() function
39// that works inside the sandbox and can send handles but not retrieve
40// them.  Unlike DuplicateHandle(), it takes a process ID rather than
41// a process handle.  It returns true on success, false otherwise.
42CONTENT_EXPORT bool BrokerDuplicateHandle(HANDLE source_handle,
43                                          DWORD target_process_id,
44                                          HANDLE* target_handle,
45                                          DWORD desired_access,
46                                          DWORD options);
47
48// Inform the current process's sandbox broker (e.g. the broker for
49// 32-bit processes) about a process created under a different sandbox
50// broker (e.g. the broker for 64-bit processes).  This allows
51// BrokerDuplicateHandle() to send handles to a process managed by
52// another broker.  For example, it allows the 32-bit renderer to send
53// handles to 64-bit NaCl processes.  This returns true on success,
54// false otherwise.
55CONTENT_EXPORT bool BrokerAddTargetPeer(HANDLE peer_process);
56
57// Launch a sandboxed process. |delegate| may be NULL. If |delegate| is non-NULL
58// then it just has to outlive this method call.
59CONTENT_EXPORT base::ProcessHandle StartSandboxedProcess(
60    SandboxedProcessLauncherDelegate* delegate,
61    base::CommandLine* cmd_line);
62
63#elif defined(OS_MACOSX)
64
65// Initialize the sandbox of the given |sandbox_type|, optionally specifying a
66// directory to allow access to. Note specifying a directory needs to be
67// supported by the sandbox profile associated with the given |sandbox_type|.
68// Valid values for |sandbox_type| are defined either by the enum SandboxType,
69// or by ContentClient::GetSandboxProfileForSandboxType().
70//
71// If the |sandbox_type| isn't one of the ones defined by content then the
72// embedder is queried using ContentClient::GetSandboxPolicyForSandboxType().
73// The embedder can use values for |sandbox_type| starting from
74// sandbox::SANDBOX_PROCESS_TYPE_AFTER_LAST_TYPE.
75//
76// Returns true if the sandbox was initialized succesfully, false if an error
77// occurred.  If process_type isn't one that needs sandboxing, no action is
78// taken and true is always returned.
79CONTENT_EXPORT bool InitializeSandbox(int sandbox_type,
80                                      const base::FilePath& allowed_path);
81
82#elif defined(OS_LINUX)
83
84class SandboxInitializerDelegate;
85
86// Initialize a seccomp-bpf sandbox. |policy| may not be NULL.
87// Returns true if the sandbox has been properly engaged.
88CONTENT_EXPORT bool InitializeSandbox(
89    scoped_ptr<sandbox::SandboxBPFPolicy> policy);
90
91// Return a "baseline" policy. This is used by a SandboxInitializerDelegate to
92// implement a policy that is derived from the baseline.
93CONTENT_EXPORT scoped_ptr<sandbox::SandboxBPFPolicy>
94GetBPFSandboxBaselinePolicy();
95#endif  // defined(OS_LINUX)
96
97}  // namespace content
98
99#endif  // CONTENT_PUBLIC_COMMON_SANDBOX_INIT_H_
100