#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "content/zygote/zygote_linux.h"
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdint.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <tuple>
#include <utility>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/span.h"
#include "base/files/file_util.h"
#include "base/files/platform_file.h"
#include "base/linux_util.h"
#include "base/logging.h"
#include "base/metrics/histogram_shared_memory.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/pickle.h"
#include "base/posix/eintr_wrapper.h"
#include "base/posix/global_descriptors.h"
#include "base/posix/unix_domain_socket.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/process/process_handle.h"
#include "base/process/set_process_title.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/common/zygote/zygote_commands_linux.h"
#include "content/public/common/content_descriptors.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/zygote/send_zygote_child_ping_linux.h"
#include "content/public/common/zygote/zygote_fork_delegate_linux.h"
#include "ipc/ipc_channel.h"
#include "sandbox/linux/services/credentials.h"
#include "sandbox/linux/services/namespace_sandbox.h"
#include "sandbox/policy/linux/sandbox_linux.h"
#include "sandbox/policy/sandbox.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
namespace content {
namespace {
void SIGCHLDHandler(int signal) { … }
int LookUpFd(const base::GlobalDescriptors::Mapping& fd_mapping, uint32_t key) { … }
void KillAndReap(pid_t pid, ZygoteForkDelegate* helper) { … }
}
Zygote::Zygote(int sandbox_flags,
std::vector<std::unique_ptr<ZygoteForkDelegate>> helpers,
const base::GlobalDescriptors::Descriptor& ipc_backchannel)
: … { … }
Zygote::~Zygote() { … }
bool Zygote::ProcessRequests() { … }
bool Zygote::ReapChild(const base::TimeTicks& now, ZygoteProcessInfo* child) { … }
void Zygote::ReapChildren() { … }
bool Zygote::GetProcessInfo(base::ProcessHandle pid,
ZygoteProcessInfo* process_info) { … }
bool Zygote::UsingSUIDSandbox() const { … }
bool Zygote::UsingNSSandbox() const { … }
bool Zygote::HandleRequestFromBrowser(int fd) { … }
void Zygote::HandleReapRequest(int fd, base::PickleIterator iter) { … }
bool Zygote::GetTerminationStatus(base::ProcessHandle real_pid,
bool known_dead,
base::TerminationStatus* status,
int* exit_code) { … }
void Zygote::HandleGetTerminationStatus(int fd, base::PickleIterator iter) { … }
int Zygote::ForkWithRealPid(const std::string& process_type,
const std::vector<std::string>& args,
const base::GlobalDescriptors::Mapping& fd_mapping,
base::ScopedFD pid_oracle,
std::string* uma_name,
int* uma_sample,
int* uma_boundary_value) { … }
base::ProcessId Zygote::ReadArgsAndFork(base::PickleIterator iter,
std::vector<base::ScopedFD> fds,
std::string* uma_name,
int* uma_sample,
int* uma_boundary_value) { … }
bool Zygote::HandleForkRequest(int fd,
base::PickleIterator iter,
std::vector<base::ScopedFD> fds) { … }
bool Zygote::HandleGetSandboxStatus(int fd, base::PickleIterator iter) { … }
void Zygote::HandleReinitializeLoggingRequest(base::PickleIterator iter,
std::vector<base::ScopedFD> fds) { … }
}