Commit eb02d477 authored by teravest@chromium.org's avatar teravest@chromium.org

Trusted plugin: Break up InitCommunication().

ServiceRuntime::InitCommunication is a large method that does several things:
  - Sets up a command channel.
  - Loads a module (nexe).
  - Sets up a reverse channel.
  - Starts a module (nexe).

This change breaks this up into smaller methods. As part of the trusted plugin
refactor, we'll probably move setting up the reverse channel before loading the
module, and join loading and starting the module into one step.

This change should make the changes to use Chromium IPC easier to follow.

BUG=333950

Review URL: https://codereview.chromium.org/133073005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245555 0039d316-1c4b-4281-b951-d872f2087c98
parent 2df0c245
...@@ -490,18 +490,29 @@ ServiceRuntime::ServiceRuntime(Plugin* plugin, ...@@ -490,18 +490,29 @@ ServiceRuntime::ServiceRuntime(Plugin* plugin,
NaClXCondVarCtor(&cond_); NaClXCondVarCtor(&cond_);
} }
bool ServiceRuntime::InitCommunication(nacl::DescWrapper* nacl_desc, bool ServiceRuntime::LoadModule(nacl::DescWrapper* nacl_desc,
ErrorInfo* error_info) { ErrorInfo* error_info) {
NaClLog(4, "ServiceRuntime::InitCommunication" NaClLog(4, "ServiceRuntime::LoadModule"
" (this=%p, subprocess=%p)\n", " (this=%p, subprocess=%p)\n",
static_cast<void*>(this), static_cast<void*>(this),
static_cast<void*>(subprocess_.get())); static_cast<void*>(subprocess_.get()));
CHECK(nacl_desc);
// Create the command channel to the sel_ldr and load the nexe from nacl_desc. // Create the command channel to the sel_ldr and load the nexe from nacl_desc.
if (!subprocess_->SetupCommandAndLoad(&command_channel_, nacl_desc)) { if (!subprocess_->SetupCommand(&command_channel_)) {
error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL, error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL,
"ServiceRuntime: command channel creation failed"); "ServiceRuntime: command channel creation failed");
return false; return false;
} }
if (!subprocess_->LoadModule(&command_channel_, nacl_desc)) {
error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL,
"ServiceRuntime: load module failed");
return false;
}
return true;
}
bool ServiceRuntime::InitReverseService(ErrorInfo* error_info) {
// Hook up the reverse service channel. We are the IMC client, but // Hook up the reverse service channel. We are the IMC client, but
// provide SRPC service. // provide SRPC service.
NaClDesc* out_conn_cap; NaClDesc* out_conn_cap;
...@@ -527,19 +538,22 @@ bool ServiceRuntime::InitCommunication(nacl::DescWrapper* nacl_desc, ...@@ -527,19 +538,22 @@ bool ServiceRuntime::InitCommunication(nacl::DescWrapper* nacl_desc,
return false; return false;
} }
out_conn_cap = NULL; // ownership passed out_conn_cap = NULL; // ownership passed
NaClLog(4, "ServiceRuntime::InitCommunication: starting reverse service\n"); NaClLog(4, "ServiceRuntime::InitReverseService: starting reverse service\n");
reverse_service_ = new nacl::ReverseService(conn_cap, rev_interface_->Ref()); reverse_service_ = new nacl::ReverseService(conn_cap, rev_interface_->Ref());
if (!reverse_service_->Start()) { if (!reverse_service_->Start()) {
error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE, error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE,
"ServiceRuntime: starting reverse services failed"); "ServiceRuntime: starting reverse services failed");
return false; return false;
} }
return true;
}
bool ServiceRuntime::StartModule(ErrorInfo* error_info) {
// start the module. otherwise we cannot connect for multimedia // start the module. otherwise we cannot connect for multimedia
// subsystem since that is handled by user-level code (not secure!) // subsystem since that is handled by user-level code (not secure!)
// in libsrpc. // in libsrpc.
int load_status = -1; int load_status = -1;
rpc_result = NaClSrpcResultCodes rpc_result =
NaClSrpcInvokeBySignature(&command_channel_, NaClSrpcInvokeBySignature(&command_channel_,
"start_module::i", "start_module::i",
&load_status); &load_status);
...@@ -549,7 +563,7 @@ bool ServiceRuntime::InitCommunication(nacl::DescWrapper* nacl_desc, ...@@ -549,7 +563,7 @@ bool ServiceRuntime::InitCommunication(nacl::DescWrapper* nacl_desc,
"ServiceRuntime: could not start nacl module"); "ServiceRuntime: could not start nacl module");
return false; return false;
} }
NaClLog(4, "ServiceRuntime::InitCommunication (load_status=%d)\n", NaClLog(4, "ServiceRuntime::StartModule (load_status=%d)\n",
load_status); load_status);
if (main_service_runtime_) { if (main_service_runtime_) {
plugin_->ReportSelLdrLoadStatus(load_status); plugin_->ReportSelLdrLoadStatus(load_status);
...@@ -617,7 +631,10 @@ bool ServiceRuntime::LoadNexeAndStart(nacl::DescWrapper* nacl_desc, ...@@ -617,7 +631,10 @@ bool ServiceRuntime::LoadNexeAndStart(nacl::DescWrapper* nacl_desc,
const pp::CompletionCallback& crash_cb) { const pp::CompletionCallback& crash_cb) {
NaClLog(4, "ServiceRuntime::LoadNexeAndStart (nacl_desc=%p)\n", NaClLog(4, "ServiceRuntime::LoadNexeAndStart (nacl_desc=%p)\n",
reinterpret_cast<void*>(nacl_desc)); reinterpret_cast<void*>(nacl_desc));
if (!InitCommunication(nacl_desc, error_info)) { bool ok = LoadModule(nacl_desc, error_info) &&
InitReverseService(error_info) &&
StartModule(error_info);
if (!ok) {
// On a load failure the service runtime does not crash itself to // On a load failure the service runtime does not crash itself to
// avoid a race where the no-more-senders error on the reverse // avoid a race where the no-more-senders error on the reverse
// channel esrvice thread might cause the crash-detection logic to // channel esrvice thread might cause the crash-detection logic to
......
...@@ -276,7 +276,9 @@ class ServiceRuntime { ...@@ -276,7 +276,9 @@ class ServiceRuntime {
private: private:
NACL_DISALLOW_COPY_AND_ASSIGN(ServiceRuntime); NACL_DISALLOW_COPY_AND_ASSIGN(ServiceRuntime);
bool InitCommunication(nacl::DescWrapper* shm, ErrorInfo* error_info); bool LoadModule(nacl::DescWrapper* shm, ErrorInfo* error_info);
bool InitReverseService(ErrorInfo* error_info);
bool StartModule(ErrorInfo* error_info);
NaClSrpcChannel command_channel_; NaClSrpcChannel command_channel_;
Plugin* plugin_; Plugin* plugin_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment