Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: src/trusted/nonnacl_util/sel_ldr_launcher.h

Issue 10180015: Split SelLdrLauncher into SelLdrLauncher{Standalone,Chrome} classes (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Copyright Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 7
8 // Utility class for launching sel_ldr. 8 // Utility class for launching sel_ldr.
9 9
10 #ifndef NATIVE_CLIENT_SRC_TRUSTED_NONNACL_UTIL_SEL_LDR_LAUNCHER_H_ 10 #ifndef NATIVE_CLIENT_SRC_TRUSTED_NONNACL_UTIL_SEL_LDR_LAUNCHER_H_
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 DISALLOW_COPY_AND_ASSIGN(PluginSelLdrLocator); 59 DISALLOW_COPY_AND_ASSIGN(PluginSelLdrLocator);
60 }; 60 };
61 61
62 /* 62 /*
63 * This class encapsulates the process of launching an instance of sel_ldr 63 * This class encapsulates the process of launching an instance of sel_ldr
64 * to communicate with the NaCl plugin over an IMC channel. 64 * to communicate with the NaCl plugin over an IMC channel.
65 * 65 *
66 * The sel_ldr process can be forked directly using a command line of args 66 * The sel_ldr process can be forked directly using a command line of args
67 * or by sending a message to the (Chrome) browser process. 67 * or by sending a message to the (Chrome) browser process.
68 */ 68 */
69 struct SelLdrLauncher { 69 class SelLdrLauncherBase {
70 public: 70 public:
71 SelLdrLauncher(); 71 SelLdrLauncherBase();
72 72 virtual ~SelLdrLauncherBase();
73 explicit SelLdrLauncher(SelLdrLocator* sel_ldr_locator);
74 ~SelLdrLauncher();
75
76 /////////////////////////////////////////////////////////////////////////////
77 // Command line start-up: (Only used by sel_universal.)
78 //
79 // The command line must include a file path for the nexe application or an
80 // indicator that a reference will be supplied after the launch over RPC.
81 /////////////////////////////////////////////////////////////////////////////
82
83 // Starts a sel_ldr process. If |prefix| is not empty, adds prefix arguments,
84 // like using 'time', to run the sel_ldr within. This is primarily intended
85 // to provide a hook for qemu emulation or for timing. |sel_ldr_argv|
86 // specifies the arguments to be passed to sel_ldr itself, while
87 // |application_argv| specifies the arguments to be passed to the nexe.
88 // If subprocess creation fails, returns false and both child_process_ and
89 // channel_ are set to kInvalidHandle.
90 bool StartViaCommandLine(const std::vector<nacl::string>& prefix,
91 const std::vector<nacl::string>& sel_ldr_argv,
92 const std::vector<nacl::string>& application_argv);
93 73
94 ///////////////////////////////////////////////////////////////////////////// 74 /////////////////////////////////////////////////////////////////////////////
95 // Browser start-up: (used by the plugin inside or outside of Chrome build.) 75 // Browser start-up: (used by the plugin inside or outside of Chrome build.)
96 ///////////////////////////////////////////////////////////////////////////// 76 /////////////////////////////////////////////////////////////////////////////
97 77
98 bool Start(const char* url); 78 virtual bool Start(const char* url) = 0;
99 // TODO(sehr): remove this obsolete interface. The parameters are useless.
100 bool Start(int socket_count, Handle* result_sockets, const char* url);
101
102 79
103 ///////////////////////////////////////////////////////////////////////////// 80 /////////////////////////////////////////////////////////////////////////////
104 // After starting the sel_ldr process. 81 // After starting the sel_ldr process.
105 ///////////////////////////////////////////////////////////////////////////// 82 /////////////////////////////////////////////////////////////////////////////
106 83
107 // Sets up the command channel |command| and sends the SRPC to load |nexe|. 84 // Sets up the command channel |command| and sends the SRPC to load |nexe|.
108 bool SetupCommandAndLoad(NaClSrpcChannel* command, DescWrapper* nexe); 85 bool SetupCommandAndLoad(NaClSrpcChannel* command, DescWrapper* nexe);
109 86
110 // Sends the SRPC to start the nexe over |command| and sets up the application 87 // Sends the SRPC to start the nexe over |command| and sets up the application
111 // SRPC chanel |out_app_chan|. 88 // SRPC chanel |out_app_chan|.
112 bool StartModuleAndSetupAppChannel(NaClSrpcChannel* command, 89 bool StartModuleAndSetupAppChannel(NaClSrpcChannel* command,
113 NaClSrpcChannel* out_app_chan); 90 NaClSrpcChannel* out_app_chan);
114 91
115 // Kill the child process. The channel() remains valid, but nobody
116 // is talking on the other end. Returns true if successful.
117 bool KillChildProcess();
118
119 // Returns the socket address used to connect to the sel_ldr. 92 // Returns the socket address used to connect to the sel_ldr.
120 DescWrapper* socket_addr() const { return socket_addr_.get(); } 93 DescWrapper* socket_addr() const { return socket_addr_.get(); }
121 94
122 // Wraps a raw NaClDesc descriptor. If NULL is returned, caller retains 95 // Wraps a raw NaClDesc descriptor. If NULL is returned, caller retains
123 // ownership of the reference. 96 // ownership of the reference.
124 DescWrapper* Wrap(NaClDesc* raw_desc); 97 DescWrapper* Wrap(NaClDesc* raw_desc);
125 98
126 // As above, but raw_desc is Unref'd on failure. 99 // As above, but raw_desc is Unref'd on failure.
127 DescWrapper* WrapCleanup(NaClDesc* raw_desc); 100 DescWrapper* WrapCleanup(NaClDesc* raw_desc);
128 101
102 protected:
103 Handle channel_;
104
105 private:
106 // lifetime of bootstrap_socket_ must be at least that of factory_
107 scoped_ptr<DescWrapperFactory> factory_;
108 scoped_ptr<DescWrapper> bootstrap_socket_;
109 // The socket address returned from sel_ldr for connects.
110 scoped_ptr<DescWrapper> socket_addr_;
111 };
112
113 class SelLdrLauncherStandalone : public SelLdrLauncherBase {
114 public:
115 SelLdrLauncherStandalone();
116 ~SelLdrLauncherStandalone();
117
118 virtual bool Start(const char* url);
119
120 /////////////////////////////////////////////////////////////////////////////
121 // Command line start-up: (Only used by sel_universal.)
122 //
123 // The command line must include a file path for the nexe application or an
124 // indicator that a reference will be supplied after the launch over RPC.
125 /////////////////////////////////////////////////////////////////////////////
126
127 // Starts a sel_ldr process. If |prefix| is not empty, adds prefix arguments,
128 // like using 'time', to run the sel_ldr within. This is primarily intended
129 // to provide a hook for qemu emulation or for timing. |sel_ldr_argv|
130 // specifies the arguments to be passed to sel_ldr itself, while
131 // |application_argv| specifies the arguments to be passed to the nexe.
132 // If subprocess creation fails, returns false and both child_process_ and
133 // channel_ are set to kInvalidHandle.
134 bool StartViaCommandLine(const std::vector<nacl::string>& prefix,
135 const std::vector<nacl::string>& sel_ldr_argv,
136 const std::vector<nacl::string>& application_argv);
137
129 private: 138 private:
130 // Builds a command line out of the prepopulated args. 139 // Builds a command line out of the prepopulated args.
131 void BuildCommandLine(std::vector<nacl::string>* command); 140 void BuildCommandLine(std::vector<nacl::string>* command);
132 141
133 // Sets up the command line to start a sel_ldr. |prefix| specifies the 142 // Sets up the command line to start a sel_ldr. |prefix| specifies the
134 // set of prefixes to apply to the sel_ldr invocation (e.g., 'time' or 143 // set of prefixes to apply to the sel_ldr invocation (e.g., 'time' or
135 // 'qemu'). |sel_ldr_argv| specifies the arguments to be passed to sel_ldr 144 // 'qemu'). |sel_ldr_argv| specifies the arguments to be passed to sel_ldr
136 // itself, while |application_argv| specifies the arguments to be passed to 145 // itself, while |application_argv| specifies the arguments to be passed to
137 // the nexe. 146 // the nexe.
138 void InitCommandLine(const std::vector<nacl::string>& prefix, 147 void InitCommandLine(const std::vector<nacl::string>& prefix,
139 const std::vector<nacl::string>& sel_ldr_argv, 148 const std::vector<nacl::string>& sel_ldr_argv,
140 const std::vector<nacl::string>& app_argv); 149 const std::vector<nacl::string>& app_argv);
141 150
142 // Creates a socket pair. Dups the first socket into the NaCl subprocess as 151 // Creates a socket pair. Dups the first socket into the NaCl subprocess as
143 // dest_fd. Returns the second socket or kInvalidHandle on failure. 152 // dest_fd. Returns the second socket or kInvalidHandle on failure.
144 Handle CreateBootstrapSocket(nacl::string* dest_fd); 153 Handle CreateBootstrapSocket(nacl::string* dest_fd);
145 154
146 void GetPluginDirectory(char* buffer, size_t len); 155 void GetPluginDirectory(char* buffer, size_t len);
147 nacl::string GetSelLdrPathName(); 156 nacl::string GetSelLdrPathName();
148 nacl::string GetSelLdrBootstrapPathName(); 157 nacl::string GetSelLdrBootstrapPathName();
149 void CloseHandlesAfterLaunch(); 158 void CloseHandlesAfterLaunch();
150 159
160 // Kill the child process. The channel() remains valid, but nobody
161 // is talking on the other end. Returns true if successful.
162 bool KillChildProcess();
163
151 // On Windows, child_process_ is a handle for the process. On Unix, 164 // On Windows, child_process_ is a handle for the process. On Unix,
152 // child_process_ is a process ID. Inside Chromium, we don't get a 165 // child_process_ is a process ID.
153 // handle or a process ID for the process.
154 #if defined(NACL_STANDALONE)
155 Handle child_process_; 166 Handle child_process_;
156 #endif
157
158 Handle channel_;
159 167
160 // The following members are used to initialize and build the command line. 168 // The following members are used to initialize and build the command line.
161 // The detailed magic is in BuildCommandLine() but roughly we run 169 // The detailed magic is in BuildCommandLine() but roughly we run
162 // <prefix> <sel_ldr> <extra stuff> <sel_ldr_argv> -- <nexe_args> 170 // <prefix> <sel_ldr> <extra stuff> <sel_ldr_argv> -- <nexe_args>
163 // Prefix parameters or empty if not used. 171 // Prefix parameters or empty if not used.
164 std::vector<nacl::string> command_prefix_; 172 std::vector<nacl::string> command_prefix_;
165 // Path to the sel_ldr chain loader executable. 173 // Path to the sel_ldr chain loader executable.
166 nacl::string sel_ldr_bootstrap_; 174 nacl::string sel_ldr_bootstrap_;
167 // Path to the sel_ldr executable 175 // Path to the sel_ldr executable
168 nacl::string sel_ldr_; 176 nacl::string sel_ldr_;
169 // arguments to sel_ldr 177 // arguments to sel_ldr
170 std::vector<nacl::string> sel_ldr_argv_; 178 std::vector<nacl::string> sel_ldr_argv_;
171 // arguments to the nexe 179 // arguments to the nexe
172 std::vector<nacl::string> application_argv_; 180 std::vector<nacl::string> application_argv_;
173 181
174 std::vector<Handle> close_after_launch_; 182 std::vector<Handle> close_after_launch_;
175 183
176 // lifetime of bootstrap_socket_ must be at least that of factory_
177 scoped_ptr<DescWrapperFactory> factory_;
178 scoped_ptr<DescWrapper> bootstrap_socket_;
179 // The socket address returned from sel_ldr for connects.
180 scoped_ptr<DescWrapper> socket_addr_;
181 scoped_ptr<SelLdrLocator> sel_ldr_locator_; 184 scoped_ptr<SelLdrLocator> sel_ldr_locator_;
182 }; 185 };
183 186
187 // TODO(mseaborn): Move this class (and sel_ldr_launcher_chrome.cc)
188 // into the Chromium repo. There will be two copies present during
189 // this process, but there should not be a naming conflict because
190 // this copy is in the "nacl" namespace.
191 class SelLdrLauncherChrome : public SelLdrLauncherBase {
192 public:
193 virtual bool Start(const char* url);
194 };
195
196 // TODO(mseaborn): Remove this typedef. This typedef is currently
197 // provided because the NaCl plugin in the Chromium repo refers to
198 // SelLdrLauncher.
199 #if defined(NACL_STANDALONE)
200 typedef SelLdrLauncherStandalone SelLdrLauncher;
201 #else
202 typedef SelLdrLauncherChrome SelLdrLauncher;
203 #endif
204
184 } // namespace nacl 205 } // namespace nacl
185 206
186 #endif // NATIVE_CLIENT_SRC_TRUSTED_NONNACL_UTIL_SEL_LDR_LAUNCHER_H_ 207 #endif // NATIVE_CLIENT_SRC_TRUSTED_NONNACL_UTIL_SEL_LDR_LAUNCHER_H_
OLDNEW
« no previous file with comments | « src/trusted/nonnacl_util/posix/sel_ldr_launcher_posix.cc ('k') | src/trusted/nonnacl_util/sel_ldr_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698