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 #ifndef CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_
6 #define CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_
13 // TODO(jln) base::TerminationStatus should be forward declared when switching
15 #include "base/process/kill.h"
19 // The ZygoteForkDelegate allows the Chrome Linux zygote to delegate
20 // fork operations to another class that knows how to do some
21 // specialized version of fork.
22 class ZygoteForkDelegate {
24 // A ZygoteForkDelegate is created during Chrome linux zygote
25 // initialization, and provides "fork()" functionality as an
26 // alternative to forking the zygote. A new delegate is passed in
27 // as an argument to ZygoteMain().
28 virtual ~ZygoteForkDelegate() {}
30 // Initialization happens in the zygote after it has been
31 // started by ZygoteMain.
32 virtual void Init(int sandboxdesc) = 0;
34 // After Init, supply a UMA_HISTOGRAM_ENUMERATION the delegate
35 // would like to supply on the first fork.
36 virtual void InitialUMA(std::string* uma_name,
38 int* uma_boundary_value) = 0;
40 // Returns 'true' if the delegate would like to handle a given fork
41 // request. Otherwise returns false. Optionally, fills in uma_name et al
42 // with a report the helper wants to make via UMA_HISTOGRAM_ENUMERATION.
43 virtual bool CanHelp(const std::string& process_type, std::string* uma_name,
44 int* uma_sample, int* uma_boundary_value) = 0;
46 // Indexes of FDs in the vector passed to Fork().
48 // Used to pass in the descriptor for talking to the Browser
50 // The next two are used in the protocol for discovering the
51 // child processes real PID from within the SUID sandbox. See
52 // http://code.google.com/p/chromium/wiki/LinuxZygote
55 kNumPassedFDs // Number of FDs in the vector passed to Fork().
58 // Delegate forks, returning a -1 on failure. Outside the
59 // suid sandbox, Fork() returns the Linux process ID.
60 // This method is not aware of any potential pid namespaces, so it'll
61 // return a raw pid just like fork() would.
62 virtual pid_t Fork(const std::vector<int>& fds) = 0;
64 // After a successful fork, signal the child to indicate that
65 // the child's PID has been received. Also communicate the
66 // channel switch as a part of acknowledgement message.
67 virtual bool AckChild(int fd, const std::string& channel_switch) = 0;
69 // The fork delegate must also assume the role of waiting for its children
70 // since the caller will not be their parents and cannot do it. |pid| here
71 // should be a pid that has been returned by the Fork() method. i.e. This
72 // method is completely unaware of eventual PID namespaces due to sandboxing.
73 // |known_dead| indicates that the process is already dead and that a
74 // blocking wait() should be performed. In this case, GetTerminationStatus()
75 // will send a SIGKILL to the target process first.
76 virtual bool GetTerminationStatus(pid_t pid, bool known_dead,
77 base::TerminationStatus* status,
81 } // namespace content
83 #endif // CONTENT_PUBLIC_COMMON_ZYGOTE_FORK_DELEGATE_LINUX_H_