Index: src/untrusted/init/process_lib.cc |
diff --git a/src/untrusted/init/process_lib.cc b/src/untrusted/init/process_lib.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..783fac4fc9b187a8b922f30cb539319e1748a897 |
--- /dev/null |
+++ b/src/untrusted/init/process_lib.cc |
@@ -0,0 +1,85 @@ |
+// Copyright (c) 2013 The Native Client Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "native_client/src/untrusted/init/process_lib.h" |
+ |
+#include <errno.h> |
+#include <fcntl.h> |
+#include <stdlib.h> |
+#include <unistd.h> |
+ |
+// TODO(bsy) get rid of debug printfs |
+ |
+// The header files below access private, not-guaranteed-to-be-stable |
+// ABIs/APIs. |
+#include "native_client/src/public/imc_syscalls.h" |
+#include "native_client/src/public/name_service.h" |
+#include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h" |
+#include "native_client/src/trusted/service_runtime/include/sys/nacl_kernel_service.h" |
+ |
+// get NACL_SYSCALL_BLOCK_SIZE, NACL_SYSCALL_START_ADDR |
+#include "native_client/src/trusted/service_runtime/nacl_config.h" |
+ |
+namespace nacl { |
+ |
+SrpcClientConnection::SrpcClientConnection() : initialized_(false) {} |
+ |
+SrpcClientConnection::~SrpcClientConnection() { |
+ if (initialized_) { |
+ close(desc_); |
+ NaClSrpcDtor(&chan_); |
+ } |
+} |
+ |
+bool SrpcClientConnection::InitializeFromConnectedDesc(int desc) { |
+ if (!NaClSrpcClientCtor(&chan_, desc)) { |
+ fprintf(stderr, |
+ "SrpcClientConnection::InitializeFromConnectedDesc failed\n"); |
+ return false; |
+ } |
+ desc_ = desc; |
+ initialized_ = true; |
+ return true; |
+} |
+ |
+bool SrpcClientConnection::InitializeFromConnectionCapability(int cap) { |
+ int conn = imc_connect(cap); |
+ if (-1 == conn) { |
+ fprintf(stderr, |
+ "SrpcClientConnection:InitializeFromConnectionCapability" |
+ " imc_connect failed, error %d\n", errno); |
+ return false; |
+ } |
+ return InitializeFromConnectedDesc(conn); |
+} |
+ |
+NaClErrorCode ServiceRuntimeClient::RunNaClModule(int module_descriptor) { |
+ NaClSrpcResultCodes result; |
+ int status; |
+ if (!initialized()) { |
+ return LOAD_INTERNAL; |
+ } |
+ printf("Entered RunNaClModule\n"); |
+ printf("chan: %p\n", (void*) chan()); |
+ // TODO(bsy): srpc signature should be in a header file |
+ result = NaClSrpcInvokeBySignature(chan(), "load_module:hs:", |
+ module_descriptor, "aux info"); |
+ printf("load_module result %d\n", result); |
+ if (NACL_SRPC_RESULT_OK != result) { |
+ fprintf(stderr, "load_module RPC failed (%d): %s\n", |
+ result, NaClSrpcErrorString(result)); |
+ return LOAD_INTERNAL; |
+ } |
+ result = NaClSrpcInvokeBySignature(chan(), "start_module::i", &status); |
+ printf("start_module result %d\n", result); |
+ if (NACL_SRPC_RESULT_OK != result) { |
+ fprintf(stderr, "start_module RPC failed (%d): %s\n", |
+ result, NaClSrpcErrorString(result)); |
+ return LOAD_INTERNAL; |
+ } |
+ printf("start_module status: %d\n", status); |
+ return static_cast<NaClErrorCode>(status); |
+} |
+ |
+} // namespace nacl |