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

Side by Side Diff: ppapi/nacl_irt/irt_pnacl_translator_link.cc

Issue 1512733003: PNaCl: Use Chrome IPC to talk to the linker process, instead of SRPC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 4 years, 11 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
« no previous file with comments | « components/nacl/renderer/ppb_nacl_private_impl.cc ('k') | ppapi/proxy/nacl_message_scanner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h"
5 #include "build/build_config.h" 6 #include "build/build_config.h"
6 #include "native_client/src/shared/platform/nacl_log.h" 7 #include "ipc/ipc_listener.h"
7 #include "native_client/src/shared/srpc/nacl_srpc.h" 8 #include "ipc/ipc_sync_channel.h"
9 #include "native_client/src/public/chrome_main.h"
8 #include "native_client/src/untrusted/irt/irt_dev.h" 10 #include "native_client/src/untrusted/irt/irt_dev.h"
9 #include "ppapi/nacl_irt/irt_interfaces.h" 11 #include "ppapi/nacl_irt/irt_interfaces.h"
12 #include "ppapi/nacl_irt/plugin_startup.h"
13 #include "ppapi/proxy/ppapi_messages.h"
10 14
11 #if !defined(OS_NACL_NONSFI) 15 #if !defined(OS_NACL_NONSFI)
12 16
13 namespace { 17 namespace {
14 18
15 const int kMaxObjectFiles = 16; 19 typedef int (*CallbackFunc)(int nexe_fd,
20 const int* obj_file_fds,
21 int obj_file_fd_count);
16 22
17 int (*g_func)(int nexe_fd, 23 class TranslatorLinkListener : public IPC::Listener {
18 const int* obj_file_fds, 24 public:
19 int obj_file_fd_count); 25 TranslatorLinkListener(const IPC::ChannelHandle& handle, CallbackFunc func)
20 26 : func_(func) {
21 void HandleLinkRequest(NaClSrpcRpc* rpc, 27 channel_ = IPC::Channel::Create(handle, IPC::Channel::MODE_SERVER, this);
22 NaClSrpcArg** in_args, 28 CHECK(channel_->Connect());
23 NaClSrpcArg** out_args,
24 NaClSrpcClosure* done) {
25 int obj_file_count = in_args[0]->u.ival;
26 int nexe_fd = in_args[kMaxObjectFiles + 1]->u.hval;
27
28 if (obj_file_count < 1 || obj_file_count > kMaxObjectFiles) {
29 NaClLog(LOG_FATAL, "Bad object file count (%i)\n", obj_file_count);
30 }
31 int obj_file_fds[obj_file_count];
32 for (int i = 0; i < obj_file_count; i++) {
33 obj_file_fds[i] = in_args[i + 1]->u.hval;
34 } 29 }
35 30
36 int result = g_func(nexe_fd, obj_file_fds, obj_file_count); 31 // Needed for handling sync messages in OnMessageReceived().
32 bool Send(IPC::Message* message) {
33 return channel_->Send(message);
34 }
37 35
38 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; 36 virtual bool OnMessageReceived(const IPC::Message& msg) {
39 done->Run(done); 37 bool handled = false;
40 } 38 IPC_BEGIN_MESSAGE_MAP(TranslatorLinkListener, msg)
39 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiMsg_PnaclTranslatorLink,
40 OnPnaclTranslatorLink)
41 IPC_MESSAGE_UNHANDLED(handled = false)
42 IPC_END_MESSAGE_MAP()
43 return handled;
44 }
41 45
42 const struct NaClSrpcHandlerDesc kSrpcMethods[] = { 46 private:
43 { "RunWithSplit:ihhhhhhhhhhhhhhhhh:", HandleLinkRequest }, 47 void OnPnaclTranslatorLink(
44 { NULL, NULL }, 48 const std::vector<ppapi::proxy::SerializedHandle>& obj_files,
49 ppapi::proxy::SerializedHandle nexe_file,
50 IPC::Message* reply_msg) {
51 CHECK(nexe_file.is_file());
52
53 std::vector<int> obj_file_fds(obj_files.size());
54 for (size_t i = 0; i < obj_files.size(); ++i) {
55 CHECK(obj_files[i].is_file());
56 obj_file_fds[i] = obj_files[i].descriptor().fd;
57 }
58 int result = func_(nexe_file.descriptor().fd,
59 obj_file_fds.data(),
60 obj_file_fds.size());
61 bool success = (result == 0);
62 PpapiMsg_PnaclTranslatorLink::WriteReplyParams(reply_msg, success);
63 Send(reply_msg);
64 }
65
66 scoped_ptr<IPC::Channel> channel_;
67 CallbackFunc func_;
68
69 DISALLOW_COPY_AND_ASSIGN(TranslatorLinkListener);
45 }; 70 };
46 71
47 void ServeLinkRequest(int (*func)(int nexe_fd, 72 void ServeLinkRequest(CallbackFunc func) {
48 const int* obj_file_fds, 73 base::MessageLoop loop;
49 int obj_file_fd_count)) { 74 int fd = ppapi::GetRendererIPCFileDescriptor();
50 g_func = func; 75 IPC::ChannelHandle handle("NaCl IPC", base::FileDescriptor(fd, false));
51 if (!NaClSrpcModuleInit()) { 76 new TranslatorLinkListener(handle, func);
52 NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); 77 loop.Run();
53 }
54 if (!NaClSrpcAcceptClientConnection(kSrpcMethods)) {
55 NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n");
56 }
57 } 78 }
58 79
59 } 80 }
60 81
61 const struct nacl_irt_private_pnacl_translator_link 82 const struct nacl_irt_private_pnacl_translator_link
62 nacl_irt_private_pnacl_translator_link = { 83 nacl_irt_private_pnacl_translator_link = {
63 ServeLinkRequest 84 ServeLinkRequest
64 }; 85 };
65 86
66 #endif // !defined(OS_NACL_NONSFI) 87 #endif // !defined(OS_NACL_NONSFI)
OLDNEW
« no previous file with comments | « components/nacl/renderer/ppb_nacl_private_impl.cc ('k') | ppapi/proxy/nacl_message_scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698