base
breakpad
build
chrome
chrome_frame
cloud_print
content
app
browser
accessibility
appcache
debugger
device_orientation
download
file_system
geolocation
gpu
in_process_webkit
intents
mac
net
renderer_host
sensors
speech
ssl
tab_contents
webui
worker_host
DEPS
OWNERS
browser_child_process_host.cc
browser_child_process_host.h
browser_context.h
browser_main.cc
browser_main.h
browser_main_loop.cc
browser_main_loop.h
browser_message_filter.cc
browser_message_filter.h
browser_process_sub_thread.cc
browser_process_sub_thread.h
browser_thread_impl.cc
browser_thread_impl.h
browser_thread_unittest.cc
browser_url_handler.cc
browser_url_handler.h
browser_url_handler_unittest.cc
browsing_instance.cc
browsing_instance.h
cancelable_request.cc
cancelable_request.h
cert_store.cc
cert_store.h
child_process_launcher.cc
child_process_launcher.h
child_process_security_policy.cc
child_process_security_policy.h
child_process_security_policy_browsertest.cc
child_process_security_policy_unittest.cc
chrome_blob_storage_context.cc
chrome_blob_storage_context.h
clipboard_dispatcher.cc
clipboard_dispatcher.h
cross_site_request_manager.cc
cross_site_request_manager.h
disposition_utils.cc
disposition_utils.h
file_metadata_mac.h
file_metadata_mac.mm
find_pasteboard.h
find_pasteboard.mm
font_list_async.cc
font_list_async.h
gpu.sb
host_zoom_map.cc
host_zoom_map.h
javascript_dialogs.h
load_from_memory_cache_details.cc
load_from_memory_cache_details.h
load_notification_details.h
mach_broker_mac.cc
mach_broker_mac.h
mach_broker_mac_unittest.cc
mime_registry_message_filter.cc
mime_registry_message_filter.h
mock_content_browser_client.cc
mock_content_browser_client.h
mock_resource_context.cc
mock_resource_context.h
notification_service_impl.cc
notification_service_impl.h
notification_service_impl_unittest.cc
plugin_loader_posix.cc
plugin_loader_posix.h
plugin_loader_posix_unittest.cc
plugin_process_host.cc
plugin_process_host.h
plugin_process_host_mac.cc
plugin_service.cc
plugin_service.h
plugin_service_browsertest.cc
plugin_service_filter.h
power_save_blocker.h
power_save_blocker_common.cc
power_save_blocker_mac.cc
power_save_blocker_stub.cc
power_save_blocker_win.cc
ppapi_plugin_process_host.cc
ppapi_plugin_process_host.h
quota_permission_context.h
resolve_proxy_msg_helper.cc
resolve_proxy_msg_helper.h
resolve_proxy_msg_helper_unittest.cc
resource_context.cc
resource_context.h
safe_util_win.cc
safe_util_win.h
site_instance.cc
site_instance.h
site_instance_unittest.cc
trace_controller.cc
trace_controller.h
trace_message_filter.cc
trace_message_filter.h
trace_subscriber_stdio.cc
trace_subscriber_stdio.h
trace_subscriber_stdio_unittest.cc
user_metrics.cc
user_metrics.h
utility_process_host.cc
utility_process_host.h
worker.sb
zygote_host_linux.cc
zygote_host_linux.h
zygote_main_linux.cc
common
gpu
plugin
ppapi_plugin
public
renderer
shell
test
utility
worker
DEPS
content.gyp
content_app.gypi
content_browser.gypi
content_common.gypi
content_gpu.gypi
content_plugin.gypi
content_ppapi_plugin.gypi
content_renderer.gypi
content_shell.gypi
content_tests.gypi
content_utility.gypi
content_worker.gypi
courgette
crypto
dbus
google_update
gpu
ipc
jingle
media
net
ppapi
printing
remoting
sandbox
sdch
skia
sql
testing
third_party
tools
ui
views
webkit
.DEPS.git
.gitignore
AUTHORS
DEPS
LICENSE
OWNERS
PRESUBMIT.py
WATCHLISTS
codereview.settings

R=jam@chromium.org BUG=90442 TEST= Review URL: http://codereview.chromium.org/8113027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103929 0039d316-1c4b-4281-b951-d872f2087c98
104 lines
3.4 KiB
C++
104 lines
3.4 KiB
C++
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef CONTENT_BROWSER_ZYGOTE_HOST_LINUX_H_
|
|
#define CONTENT_BROWSER_ZYGOTE_HOST_LINUX_H_
|
|
#pragma once
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "base/global_descriptors_posix.h"
|
|
#include "base/process.h"
|
|
#include "base/process_util.h"
|
|
#include "base/synchronization/lock.h"
|
|
#include "content/common/content_export.h"
|
|
|
|
template<typename Type>
|
|
struct DefaultSingletonTraits;
|
|
|
|
static const char kZygoteMagic[] = "ZYGOTE_OK";
|
|
|
|
// http://code.google.com/p/chromium/wiki/LinuxZygote
|
|
|
|
// The zygote host is the interface, in the browser process, to the zygote
|
|
// process.
|
|
class CONTENT_EXPORT ZygoteHost {
|
|
public:
|
|
// Returns the singleton instance.
|
|
static ZygoteHost* GetInstance();
|
|
|
|
void Init(const std::string& sandbox_cmd);
|
|
|
|
// Tries to start a process of type indicated by process_type.
|
|
// Returns its pid on success, otherwise
|
|
// base::kNullProcessHandle;
|
|
pid_t ForkRequest(const std::vector<std::string>& command_line,
|
|
const base::GlobalDescriptors::Mapping& mapping,
|
|
const std::string& process_type);
|
|
void EnsureProcessTerminated(pid_t process);
|
|
|
|
// Get the termination status (and, optionally, the exit code) of
|
|
// the process. |exit_code| is set to the exit code of the child
|
|
// process. (|exit_code| may be NULL.)
|
|
base::TerminationStatus GetTerminationStatus(base::ProcessHandle handle,
|
|
int* exit_code);
|
|
|
|
// These are the command codes used on the wire between the browser and the
|
|
// zygote.
|
|
enum {
|
|
kCmdFork = 0, // Fork off a new renderer.
|
|
kCmdReap = 1, // Reap a renderer child.
|
|
kCmdGetTerminationStatus = 2, // Check what happend to a child process.
|
|
kCmdGetSandboxStatus = 3, // Read a bitmask of kSandbox*
|
|
};
|
|
|
|
// These form a bitmask which describes the conditions of the sandbox that
|
|
// the zygote finds itself in.
|
|
enum {
|
|
kSandboxSUID = 1 << 0, // SUID sandbox active
|
|
kSandboxPIDNS = 1 << 1, // SUID sandbox is using the PID namespace
|
|
kSandboxNetNS = 1 << 2, // SUID sandbox is using the network namespace
|
|
kSandboxSeccomp = 1 << 3, // seccomp sandbox active.
|
|
};
|
|
|
|
pid_t pid() const { return pid_; }
|
|
|
|
// Returns an int which is a bitmask of kSandbox* values. Only valid after
|
|
// the first render has been forked.
|
|
int sandbox_status() const {
|
|
if (have_read_sandbox_status_word_)
|
|
return sandbox_status_;
|
|
return 0;
|
|
}
|
|
|
|
// Adjust the OOM score of the given renderer's PID. The allowed
|
|
// range for the score is [0, 1000], where higher values are more
|
|
// likely to be killed by the OOM killer.
|
|
void AdjustRendererOOMScore(base::ProcessHandle process_handle, int score);
|
|
|
|
private:
|
|
friend struct DefaultSingletonTraits<ZygoteHost>;
|
|
ZygoteHost();
|
|
~ZygoteHost();
|
|
|
|
ssize_t ReadReply(void* buf, size_t buflen);
|
|
|
|
int control_fd_; // the socket to the zygote
|
|
// A lock protecting all communication with the zygote. This lock must be
|
|
// acquired before sending a command and released after the result has been
|
|
// received.
|
|
base::Lock control_lock_;
|
|
pid_t pid_;
|
|
bool init_;
|
|
bool using_suid_sandbox_;
|
|
std::string sandbox_binary_;
|
|
bool have_read_sandbox_status_word_;
|
|
int sandbox_status_;
|
|
};
|
|
|
|
#endif // CONTENT_BROWSER_ZYGOTE_HOST_LINUX_H_
|