nacl_fork_delegate_linux.h revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
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 COMPONENTS_NACL_ZYGOTE_NACL_FORK_DELEGATE_LINUX_H_
6#define COMPONENTS_NACL_ZYGOTE_NACL_FORK_DELEGATE_LINUX_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
13#include "content/public/common/zygote_fork_delegate_linux.h"
14
15// The NaClForkDelegate is created during Chrome linux zygote
16// initialization, and provides "fork()" functionality with
17// NaCl specific process characteristics (specifically address
18// space layout) as an alternative to forking the zygote.
19// A new delegate is passed in as an argument to ZygoteMain().
20class NaClForkDelegate : public content::ZygoteForkDelegate {
21 public:
22  NaClForkDelegate();
23  virtual ~NaClForkDelegate();
24
25  virtual void Init(int sandboxdesc) OVERRIDE;
26  virtual void InitialUMA(std::string* uma_name,
27                          int* uma_sample,
28                          int* uma_boundary_value) OVERRIDE;
29  virtual bool CanHelp(const std::string& process_type, std::string* uma_name,
30                          int* uma_sample, int* uma_boundary_value) OVERRIDE;
31  virtual pid_t Fork(const std::string& process_type,
32                     const std::vector<int>& fds) OVERRIDE;
33  virtual bool AckChild(int fd,
34                        const std::string& channel_switch) OVERRIDE;
35  virtual bool GetTerminationStatus(pid_t pid, bool known_dead,
36                                    base::TerminationStatus* status,
37                                    int* exit_code) OVERRIDE;
38
39 private:
40  // These values are reported via UMA and hence they become permanent
41  // constants.  Old values cannot be reused, only new ones added.
42  enum NaClHelperStatus {
43    kNaClHelperUnused = 0,
44    kNaClHelperMissing = 1,
45    kNaClHelperBootstrapMissing = 2,
46    kNaClHelperValgrind = 3,
47    kNaClHelperLaunchFailed = 4,
48    kNaClHelperAckFailed = 5,
49    kNaClHelperSuccess = 6,
50    kNaClHelperStatusBoundary  // Must be one greater than highest value used.
51  };
52
53  NaClHelperStatus status_;
54  int fd_;
55};
56
57#endif  // COMPONENTS_NACL_ZYGOTE_NACL_FORK_DELEGATE_LINUX_H_
58