Index: ppapi/nacl_irt/irt_pnacl_translator_link.cc |
diff --git a/ppapi/nacl_irt/irt_pnacl_translator_link.cc b/ppapi/nacl_irt/irt_pnacl_translator_link.cc |
index af31fd464b60c889cff8bb141efb4f439ba6f8b1..514d5f1019197973e4c1d304442571517067f0aa 100644 |
--- a/ppapi/nacl_irt/irt_pnacl_translator_link.cc |
+++ b/ppapi/nacl_irt/irt_pnacl_translator_link.cc |
@@ -3,57 +3,75 @@ |
// found in the LICENSE file. |
#include "build/build_config.h" |
-#include "native_client/src/shared/platform/nacl_log.h" |
-#include "native_client/src/shared/srpc/nacl_srpc.h" |
+#include "ipc/ipc_listener.h" |
+#include "ipc/ipc_sync_channel.h" |
+#include "native_client/src/public/chrome_main.h" |
#include "native_client/src/untrusted/irt/irt_dev.h" |
#include "ppapi/nacl_irt/irt_interfaces.h" |
+#include "ppapi/nacl_irt/plugin_startup.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
#if !defined(OS_NACL_NONSFI) |
namespace { |
-const int kMaxObjectFiles = 16; |
+typedef int (*CallbackFunc)(int nexe_fd, |
+ const int* obj_file_fds, |
+ int obj_file_fd_count); |
-int (*g_func)(int nexe_fd, |
- const int* obj_file_fds, |
- int obj_file_fd_count); |
- |
-void HandleLinkRequest(NaClSrpcRpc* rpc, |
- NaClSrpcArg** in_args, |
- NaClSrpcArg** out_args, |
- NaClSrpcClosure* done) { |
- int obj_file_count = in_args[0]->u.ival; |
- int nexe_fd = in_args[kMaxObjectFiles + 1]->u.hval; |
+class TranslatorListener : public IPC::Listener { |
+ public: |
+ TranslatorListener(const IPC::ChannelHandle& handle, CallbackFunc func) |
+ : func_(func) { |
+ channel_ = IPC::Channel::Create(handle, IPC::Channel::MODE_SERVER, this); |
+ CHECK(channel_->Connect()); |
+ } |
- if (obj_file_count < 1 || obj_file_count > kMaxObjectFiles) { |
- NaClLog(LOG_FATAL, "Bad object file count (%i)\n", obj_file_count); |
+ // Needed for handling sync messages in OnMessageReceived(). |
+ bool Send(IPC::Message* message) { |
+ return channel_->Send(message); |
} |
- int obj_file_fds[obj_file_count]; |
- for (int i = 0; i < obj_file_count; i++) { |
- obj_file_fds[i] = in_args[i + 1]->u.hval; |
+ |
+ virtual bool OnMessageReceived(const IPC::Message& msg) { |
+ bool handled = false; |
+ IPC_BEGIN_MESSAGE_MAP(TranslatorListener, msg) |
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiMsg_PnaclTranslatorLink, |
+ OnPnaclTranslatorLink) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
} |
- int result = g_func(nexe_fd, obj_file_fds, obj_file_count); |
+ private: |
+ void OnPnaclTranslatorLink( |
+ const std::vector<ppapi::proxy::SerializedHandle>& obj_files, |
+ ppapi::proxy::SerializedHandle nexe_file, |
+ IPC::Message* reply_msg) { |
+ CHECK(nexe_file.is_file()); |
- rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; |
- done->Run(done); |
-} |
+ std::vector<int> obj_file_fds(obj_files.size()); |
+ for (size_t i = 0; i < obj_files.size(); ++i) { |
+ CHECK(obj_files[i].is_file()); |
+ obj_file_fds[i] = obj_files[i].descriptor().fd; |
+ } |
+ int result = func_(nexe_file.descriptor().fd, |
+ obj_file_fds.data(), |
+ obj_file_fds.size()); |
+ bool success = (result == 0); |
+ PpapiMsg_PnaclTranslatorLink::WriteReplyParams(reply_msg, success); |
+ Send(reply_msg); |
+ } |
-const struct NaClSrpcHandlerDesc kSrpcMethods[] = { |
- { "RunWithSplit:ihhhhhhhhhhhhhhhhh:", HandleLinkRequest }, |
- { NULL, NULL }, |
+ scoped_ptr<IPC::Channel> channel_; |
+ CallbackFunc func_; |
bbudge
2015/12/17 21:17:11
DISALLOW_COPY_AND_ASSIGN ?
Mark Seaborn
2015/12/21 22:58:50
Done.
|
}; |
-void ServeLinkRequest(int (*func)(int nexe_fd, |
- const int* obj_file_fds, |
- int obj_file_fd_count)) { |
- g_func = func; |
- if (!NaClSrpcModuleInit()) { |
- NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); |
- } |
- if (!NaClSrpcAcceptClientConnection(kSrpcMethods)) { |
- NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n"); |
- } |
+void ServeLinkRequest(CallbackFunc func) { |
+ base::MessageLoop loop; |
+ int fd = ppapi::GetRendererIPCFileDescriptor(); |
+ IPC::ChannelHandle handle("NaCl IPC", base::FileDescriptor(fd, false)); |
+ new TranslatorListener(handle, func); |
+ loop.Run(); |
} |
} |