Home | History | Annotate | Download | only in zygote
      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 "base/gtest_prod_util.h"
     14 #include "content/public/common/zygote_fork_delegate_linux.h"
     15 
     16 namespace base {
     17 struct LaunchOptions;
     18 }
     19 
     20 template <typename>
     21 class ScopedVector;
     22 
     23 namespace nacl {
     24 
     25 // Appends any ZygoteForkDelegate instances needed by NaCl to |*delegates|.
     26 void AddNaClZygoteForkDelegates(
     27     ScopedVector<content::ZygoteForkDelegate>* delegates);
     28 
     29 // The NaClForkDelegate is created during Chrome linux zygote
     30 // initialization, and provides "fork()" functionality with
     31 // NaCl specific process characteristics (specifically address
     32 // space layout) as an alternative to forking the zygote.
     33 // A new delegate is passed in as an argument to ZygoteMain().
     34 class NaClForkDelegate : public content::ZygoteForkDelegate {
     35  public:
     36   explicit NaClForkDelegate(bool nonsfi_mode);
     37   virtual ~NaClForkDelegate();
     38 
     39   virtual void Init(int sandboxdesc, bool enable_layer1_sandbox) OVERRIDE;
     40   virtual void InitialUMA(std::string* uma_name,
     41                           int* uma_sample,
     42                           int* uma_boundary_value) OVERRIDE;
     43   virtual bool CanHelp(const std::string& process_type, std::string* uma_name,
     44                           int* uma_sample, int* uma_boundary_value) OVERRIDE;
     45   virtual pid_t Fork(const std::string& process_type,
     46                      const std::vector<int>& fds,
     47                      const std::string& channel_id) OVERRIDE;
     48   virtual bool GetTerminationStatus(pid_t pid, bool known_dead,
     49                                     base::TerminationStatus* status,
     50                                     int* exit_code) OVERRIDE;
     51 
     52  private:
     53   static void AddPassthroughEnvToOptions(base::LaunchOptions* options);
     54 
     55   // These values are reported via UMA and hence they become permanent
     56   // constants.  Old values cannot be reused, only new ones added.
     57   enum NaClHelperStatus {
     58     kNaClHelperUnused = 0,
     59     kNaClHelperMissing = 1,
     60     kNaClHelperBootstrapMissing = 2,
     61     kNaClHelperValgrind = 3,
     62     kNaClHelperLaunchFailed = 4,
     63     kNaClHelperAckFailed = 5,
     64     kNaClHelperSuccess = 6,
     65     kNaClHelperStatusBoundary  // Must be one greater than highest value used.
     66   };
     67 
     68   const bool nonsfi_mode_;
     69   NaClHelperStatus status_;
     70   int fd_;
     71 
     72   FRIEND_TEST_ALL_PREFIXES(NaClForkDelegateLinuxTest, EnvPassthrough);
     73 
     74   DISALLOW_COPY_AND_ASSIGN(NaClForkDelegate);
     75 };
     76 
     77 }  // namespace nacl
     78 
     79 #endif  // COMPONENTS_NACL_ZYGOTE_NACL_FORK_DELEGATE_LINUX_H_
     80