| OLD | NEW |
| 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 #include <assert.h> | 7 #include <assert.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 22 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 23 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 23 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 24 #include "native_client/src/trusted/service_runtime/env_cleanser.h" | 24 #include "native_client/src/trusted/service_runtime/env_cleanser.h" |
| 25 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 25 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
| 26 | 26 |
| 27 using std::vector; | 27 using std::vector; |
| 28 | 28 |
| 29 | 29 |
| 30 namespace nacl { | 30 namespace nacl { |
| 31 | 31 |
| 32 SelLdrLauncher::SelLdrLauncher() | 32 SelLdrLauncherBase::SelLdrLauncherBase() |
| 33 : | 33 : channel_(kInvalidHandle), |
| 34 #if defined(NACL_STANDALONE) | |
| 35 child_process_(kInvalidHandle), | |
| 36 #endif | |
| 37 channel_(kInvalidHandle), | |
| 38 bootstrap_socket_(NULL), | 34 bootstrap_socket_(NULL), |
| 39 socket_addr_(NULL), | 35 socket_addr_(NULL) { |
| 36 } |
| 37 |
| 38 SelLdrLauncherBase::~SelLdrLauncherBase() { |
| 39 if (kInvalidHandle != channel_) { |
| 40 Close(channel_); |
| 41 } |
| 42 } |
| 43 |
| 44 SelLdrLauncherStandalone::SelLdrLauncherStandalone() |
| 45 : child_process_(kInvalidHandle), |
| 40 sel_ldr_locator_(new PluginSelLdrLocator()) { | 46 sel_ldr_locator_(new PluginSelLdrLocator()) { |
| 41 } | 47 } |
| 42 | 48 |
| 43 SelLdrLauncher::SelLdrLauncher(SelLdrLocator* sel_ldr_locator) | 49 void SelLdrLauncherStandalone::GetPluginDirectory(char* buffer, size_t len) { |
| 44 : | |
| 45 #if defined(NACL_STANDALONE) | |
| 46 child_process_(kInvalidHandle), | |
| 47 #endif | |
| 48 channel_(kInvalidHandle), | |
| 49 bootstrap_socket_(NULL), | |
| 50 socket_addr_(NULL), | |
| 51 sel_ldr_locator_(sel_ldr_locator) { | |
| 52 CHECK(sel_ldr_locator != NULL); | |
| 53 } | |
| 54 | |
| 55 void SelLdrLauncher::GetPluginDirectory(char* buffer, size_t len) { | |
| 56 sel_ldr_locator_->GetDirectory(buffer, len); | 50 sel_ldr_locator_->GetDirectory(buffer, len); |
| 57 } | 51 } |
| 58 | 52 |
| 59 static DescWrapper* GetSockAddr(DescWrapper* desc) { | 53 static DescWrapper* GetSockAddr(DescWrapper* desc) { |
| 60 DescWrapper::MsgHeader header; | 54 DescWrapper::MsgHeader header; |
| 61 DescWrapper::MsgIoVec iovec[1]; | 55 DescWrapper::MsgIoVec iovec[1]; |
| 62 DescWrapper* descs[NACL_ABI_IMC_USER_DESC_MAX]; | 56 DescWrapper* descs[NACL_ABI_IMC_USER_DESC_MAX]; |
| 63 scoped_array<unsigned char> bytes( | 57 scoped_array<unsigned char> bytes( |
| 64 new unsigned char[NACL_ABI_IMC_USER_BYTES_MAX]); | 58 new unsigned char[NACL_ABI_IMC_USER_BYTES_MAX]); |
| 65 if (bytes.get() == NULL) { | 59 if (bytes.get() == NULL) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 79 return NULL; | 73 return NULL; |
| 80 } | 74 } |
| 81 // Check that there was exactly one descriptor passed. | 75 // Check that there was exactly one descriptor passed. |
| 82 if (1 != header.ndescv_length) { | 76 if (1 != header.ndescv_length) { |
| 83 return NULL; | 77 return NULL; |
| 84 } | 78 } |
| 85 | 79 |
| 86 return descs[0]; | 80 return descs[0]; |
| 87 } | 81 } |
| 88 | 82 |
| 89 bool SelLdrLauncher::SetupCommandAndLoad(NaClSrpcChannel* command, | 83 bool SelLdrLauncherBase::SetupCommandAndLoad(NaClSrpcChannel* command, |
| 90 DescWrapper* nexe) { | 84 DescWrapper* nexe) { |
| 91 // Get the bootstrap socket. | 85 // Get the bootstrap socket. |
| 92 CHECK(factory_ == NULL); | 86 CHECK(factory_ == NULL); |
| 93 factory_.reset(new DescWrapperFactory); | 87 factory_.reset(new DescWrapperFactory); |
| 94 CHECK(channel_ != kInvalidHandle); | 88 CHECK(channel_ != kInvalidHandle); |
| 95 bootstrap_socket_.reset(factory_->MakeImcSock(channel_)); | 89 bootstrap_socket_.reset(factory_->MakeImcSock(channel_)); |
| 96 if (bootstrap_socket_ == NULL) { | 90 if (bootstrap_socket_ == NULL) { |
| 97 NaClLog(4, ("SelLdrLauncher::SetupCommandAndLoad: " | 91 NaClLog(4, ("SelLdrLauncher::SetupCommandAndLoad: " |
| 98 "getting bootstrap socket failed\n")); | 92 "getting bootstrap socket failed\n")); |
| 99 return false; | 93 return false; |
| 100 } | 94 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 "rpc_result= %d is not successful\n", | 128 "rpc_result= %d is not successful\n", |
| 135 static_cast<int>(rpc_result)); | 129 static_cast<int>(rpc_result)); |
| 136 NaClSrpcDtor(command); | 130 NaClSrpcDtor(command); |
| 137 return false; | 131 return false; |
| 138 } | 132 } |
| 139 } | 133 } |
| 140 return true; | 134 return true; |
| 141 } | 135 } |
| 142 | 136 |
| 143 bool | 137 bool |
| 144 SelLdrLauncher::StartModuleAndSetupAppChannel(NaClSrpcChannel* command, | 138 SelLdrLauncherBase::StartModuleAndSetupAppChannel( |
| 145 NaClSrpcChannel* out_app_chan) { | 139 NaClSrpcChannel* command, |
| 140 NaClSrpcChannel* out_app_chan) { |
| 146 // Start untrusted code module. | 141 // Start untrusted code module. |
| 147 int start_result; | 142 int start_result; |
| 148 NaClSrpcResultCodes rpc_result = NaClSrpcInvokeBySignature(command, | 143 NaClSrpcResultCodes rpc_result = NaClSrpcInvokeBySignature(command, |
| 149 "start_module::i", | 144 "start_module::i", |
| 150 &start_result); | 145 &start_result); |
| 151 NaClLog(4, "SelLdrLauncher::StartModule rpc result %d\n", | 146 NaClLog(4, "SelLdrLauncher::StartModule rpc result %d\n", |
| 152 static_cast<int>(rpc_result)); | 147 static_cast<int>(rpc_result)); |
| 153 if (NACL_SRPC_RESULT_OK != rpc_result && LOAD_OK != start_result) { | 148 if (NACL_SRPC_RESULT_OK != rpc_result && LOAD_OK != start_result) { |
| 154 NaClSrpcDtor(command); | 149 NaClSrpcDtor(command); |
| 155 NaClLog(4, "SelLdrLauncher::StartModuleAndSetupAppChannel: " | 150 NaClLog(4, "SelLdrLauncher::StartModuleAndSetupAppChannel: " |
| (...skipping 26 matching lines...) Expand all Loading... |
| 182 static char **GetEnviron() { | 177 static char **GetEnviron() { |
| 183 #if NACL_OSX | 178 #if NACL_OSX |
| 184 /* Mac dynamic libraries cannot access the environ variable directly. */ | 179 /* Mac dynamic libraries cannot access the environ variable directly. */ |
| 185 return *_NSGetEnviron(); | 180 return *_NSGetEnviron(); |
| 186 #else | 181 #else |
| 187 return environ; | 182 return environ; |
| 188 #endif | 183 #endif |
| 189 } | 184 } |
| 190 #endif | 185 #endif |
| 191 | 186 |
| 192 void SelLdrLauncher::BuildCommandLine(vector<nacl::string>* command) { | 187 void SelLdrLauncherStandalone::BuildCommandLine(vector<nacl::string>* command) { |
| 193 assert(sel_ldr_ != NACL_NO_FILE_PATH); // Set by InitCommandLine(). | 188 assert(sel_ldr_ != NACL_NO_FILE_PATH); // Set by InitCommandLine(). |
| 194 if (!command_prefix_.empty()) | 189 if (!command_prefix_.empty()) |
| 195 command->insert(command->end(), | 190 command->insert(command->end(), |
| 196 command_prefix_.begin(), command_prefix_.end()); | 191 command_prefix_.begin(), command_prefix_.end()); |
| 197 if (!sel_ldr_bootstrap_.empty()) | 192 if (!sel_ldr_bootstrap_.empty()) |
| 198 command->push_back(sel_ldr_bootstrap_); | 193 command->push_back(sel_ldr_bootstrap_); |
| 199 command->push_back(sel_ldr_); | 194 command->push_back(sel_ldr_); |
| 200 if (!sel_ldr_bootstrap_.empty()) | 195 if (!sel_ldr_bootstrap_.empty()) |
| 201 command->push_back("--r_debug=0xXXXXXXXXXXXXXXXX"); | 196 command->push_back("--r_debug=0xXXXXXXXXXXXXXXXX"); |
| 202 command->push_back("-R"); // RPC will be used to point to the nexe. | 197 command->push_back("-R"); // RPC will be used to point to the nexe. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 225 #endif | 220 #endif |
| 226 | 221 |
| 227 if (application_argv_.size() > 0) { | 222 if (application_argv_.size() > 0) { |
| 228 // Separator between sel_universal and app args. | 223 // Separator between sel_universal and app args. |
| 229 command->push_back("--"); | 224 command->push_back("--"); |
| 230 command->insert(command->end(), | 225 command->insert(command->end(), |
| 231 application_argv_.begin(), application_argv_.end()); | 226 application_argv_.begin(), application_argv_.end()); |
| 232 } | 227 } |
| 233 } | 228 } |
| 234 | 229 |
| 235 void SelLdrLauncher::InitCommandLine(const vector<nacl::string>& prefix, | 230 void SelLdrLauncherStandalone::InitCommandLine( |
| 236 const vector<nacl::string>& sel_ldr_argv, | 231 const vector<nacl::string>& prefix, |
| 237 const vector<nacl::string>& app_argv) { | 232 const vector<nacl::string>& sel_ldr_argv, |
| 233 const vector<nacl::string>& app_argv) { |
| 238 assert(sel_ldr_ == NACL_NO_FILE_PATH); // Make sure we don't call this twice. | 234 assert(sel_ldr_ == NACL_NO_FILE_PATH); // Make sure we don't call this twice. |
| 239 | 235 |
| 240 char* var = getenv("NACL_SEL_LDR"); | 236 char* var = getenv("NACL_SEL_LDR"); |
| 241 if (var != NULL) { | 237 if (var != NULL) { |
| 242 sel_ldr_ = var; | 238 sel_ldr_ = var; |
| 243 } else { | 239 } else { |
| 244 sel_ldr_ = GetSelLdrPathName(); | 240 sel_ldr_ = GetSelLdrPathName(); |
| 245 } | 241 } |
| 246 char *bootstrap_var = getenv("NACL_SEL_LDR_BOOTSTRAP"); | 242 char *bootstrap_var = getenv("NACL_SEL_LDR_BOOTSTRAP"); |
| 247 if (bootstrap_var != NULL) { | 243 if (bootstrap_var != NULL) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 267 // NaCl module. | 263 // NaCl module. |
| 268 // "-i" maps the host OS file descriptor dest_fd into the nexe namespace as | 264 // "-i" maps the host OS file descriptor dest_fd into the nexe namespace as |
| 269 // file descriptor 5. | 265 // file descriptor 5. |
| 270 // TODO(sehr): remove the -i option and use the dest_fd directly with -X. | 266 // TODO(sehr): remove the -i option and use the dest_fd directly with -X. |
| 271 sel_ldr_argv_.push_back("-X"); | 267 sel_ldr_argv_.push_back("-X"); |
| 272 sel_ldr_argv_.push_back("5"); | 268 sel_ldr_argv_.push_back("5"); |
| 273 sel_ldr_argv_.push_back("-i"); | 269 sel_ldr_argv_.push_back("-i"); |
| 274 sel_ldr_argv_.push_back(nacl::string("5:") + dest_fd); | 270 sel_ldr_argv_.push_back(nacl::string("5:") + dest_fd); |
| 275 } | 271 } |
| 276 | 272 |
| 277 void SelLdrLauncher::CloseHandlesAfterLaunch() { | 273 void SelLdrLauncherStandalone::CloseHandlesAfterLaunch() { |
| 278 for (size_t i = 0; i < close_after_launch_.size(); i++) { | 274 for (size_t i = 0; i < close_after_launch_.size(); i++) { |
| 279 Close(close_after_launch_[i]); | 275 Close(close_after_launch_[i]); |
| 280 } | 276 } |
| 281 close_after_launch_.clear(); | 277 close_after_launch_.clear(); |
| 282 } | 278 } |
| 283 | 279 |
| 284 DescWrapper* SelLdrLauncher::Wrap(NaClDesc* raw_desc) { | 280 DescWrapper* SelLdrLauncherBase::Wrap(NaClDesc* raw_desc) { |
| 285 CHECK(factory_ != NULL); | 281 CHECK(factory_ != NULL); |
| 286 return factory_->MakeGeneric(raw_desc); | 282 return factory_->MakeGeneric(raw_desc); |
| 287 } | 283 } |
| 288 | 284 |
| 289 DescWrapper* SelLdrLauncher::WrapCleanup(NaClDesc* raw_desc) { | 285 DescWrapper* SelLdrLauncherBase::WrapCleanup(NaClDesc* raw_desc) { |
| 290 CHECK(factory_ != NULL); | 286 CHECK(factory_ != NULL); |
| 291 return factory_->MakeGenericCleanup(raw_desc); | 287 return factory_->MakeGenericCleanup(raw_desc); |
| 292 } | 288 } |
| 293 | 289 |
| 294 #if defined(NACL_STANDALONE) | 290 bool SelLdrLauncherStandalone::Start(const char* url) { |
| 295 bool SelLdrLauncher::Start(const char* url) { | |
| 296 UNREFERENCED_PARAMETER(url); | 291 UNREFERENCED_PARAMETER(url); |
| 297 vector<nacl::string> prefix; | 292 vector<nacl::string> prefix; |
| 298 vector<nacl::string> args_for_sel_ldr; | 293 vector<nacl::string> args_for_sel_ldr; |
| 299 vector<nacl::string> args_for_nexe; | 294 vector<nacl::string> args_for_nexe; |
| 300 const char* irt_library_path = getenv("NACL_IRT_LIBRARY"); | 295 const char* irt_library_path = getenv("NACL_IRT_LIBRARY"); |
| 301 if (NULL != irt_library_path) { | 296 if (NULL != irt_library_path) { |
| 302 args_for_sel_ldr.push_back("-B"); | 297 args_for_sel_ldr.push_back("-B"); |
| 303 args_for_sel_ldr.push_back(irt_library_path); | 298 args_for_sel_ldr.push_back(irt_library_path); |
| 304 } | 299 } |
| 305 if (!StartViaCommandLine(prefix, args_for_sel_ldr, args_for_nexe)) { | 300 if (!StartViaCommandLine(prefix, args_for_sel_ldr, args_for_nexe)) { |
| 306 return false; | 301 return false; |
| 307 } | 302 } |
| 308 return true; | 303 return true; |
| 309 } | 304 } |
| 310 | 305 |
| 311 bool SelLdrLauncher::Start(int socket_count, | |
| 312 Handle* result_sockets, | |
| 313 const char* url) { | |
| 314 UNREFERENCED_PARAMETER(socket_count); | |
| 315 UNREFERENCED_PARAMETER(result_sockets); | |
| 316 return Start(url); | |
| 317 } | |
| 318 #endif // defined(NACL_STANDALONE) | |
| 319 | |
| 320 } // namespace nacl | 306 } // namespace nacl |
| OLD | NEW |