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

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: Review Created 5 years 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
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 "build/build_config.h" 5 #include "build/build_config.h"
6 #include "native_client/src/shared/platform/nacl_log.h" 6 #include "ipc/ipc_listener.h"
7 #include "native_client/src/shared/srpc/nacl_srpc.h" 7 #include "ipc/ipc_sync_channel.h"
8 #include "native_client/src/public/chrome_main.h"
8 #include "native_client/src/untrusted/irt/irt_dev.h" 9 #include "native_client/src/untrusted/irt/irt_dev.h"
9 #include "ppapi/nacl_irt/irt_interfaces.h" 10 #include "ppapi/nacl_irt/irt_interfaces.h"
11 #include "ppapi/nacl_irt/plugin_startup.h"
12 #include "ppapi/proxy/ppapi_messages.h"
10 13
11 #if !defined(OS_NACL_NONSFI) 14 #if !defined(OS_NACL_NONSFI)
12 15
13 namespace { 16 namespace {
14 17
15 const int kMaxObjectFiles = 16; 18 typedef int (*CallbackFunc)(int nexe_fd,
19 const int* obj_file_fds,
20 int obj_file_fd_count);
16 21
17 int (*g_func)(int nexe_fd, 22 class TranslatorListener : public IPC::Listener {
18 const int* obj_file_fds, 23 public:
19 int obj_file_fd_count); 24 TranslatorListener(const IPC::ChannelHandle& handle, CallbackFunc func)
20 25 : func_(func) {
21 void HandleLinkRequest(NaClSrpcRpc* rpc, 26 channel_ = IPC::Channel::Create(handle, IPC::Channel::MODE_SERVER, this);
22 NaClSrpcArg** in_args, 27 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 } 28 }
35 29
36 int result = g_func(nexe_fd, obj_file_fds, obj_file_count); 30 // Needed for handling sync messages in OnMessageReceived().
31 bool Send(IPC::Message* message) {
32 return channel_->Send(message);
33 }
37 34
38 rpc->result = result == 0 ? NACL_SRPC_RESULT_OK : NACL_SRPC_RESULT_APP_ERROR; 35 virtual bool OnMessageReceived(const IPC::Message& msg) {
39 done->Run(done); 36 bool handled = false;
40 } 37 IPC_BEGIN_MESSAGE_MAP(TranslatorListener, msg)
38 IPC_MESSAGE_HANDLER_DELAY_REPLY(PpapiMsg_PnaclTranslatorLink,
39 OnPnaclTranslatorLink)
40 IPC_MESSAGE_UNHANDLED(handled = false)
41 IPC_END_MESSAGE_MAP()
42 return handled;
43 }
41 44
42 const struct NaClSrpcHandlerDesc kSrpcMethods[] = { 45 private:
43 { "RunWithSplit:ihhhhhhhhhhhhhhhhh:", HandleLinkRequest }, 46 void OnPnaclTranslatorLink(
44 { NULL, NULL }, 47 const std::vector<ppapi::proxy::SerializedHandle>& obj_files,
48 ppapi::proxy::SerializedHandle nexe_file,
49 IPC::Message* reply_msg) {
50 CHECK(nexe_file.is_file());
51
52 std::vector<int> obj_file_fds(obj_files.size());
53 for (size_t i = 0; i < obj_files.size(); ++i) {
54 CHECK(obj_files[i].is_file());
55 obj_file_fds[i] = obj_files[i].descriptor().fd;
56 }
57 int result = func_(nexe_file.descriptor().fd,
58 obj_file_fds.data(),
59 obj_file_fds.size());
60 bool success = (result == 0);
61 PpapiMsg_PnaclTranslatorLink::WriteReplyParams(reply_msg, success);
62 Send(reply_msg);
63 }
64
65 scoped_ptr<IPC::Channel> channel_;
66 CallbackFunc func_;
bbudge 2015/12/17 21:17:11 DISALLOW_COPY_AND_ASSIGN ?
Mark Seaborn 2015/12/21 22:58:50 Done.
45 }; 67 };
46 68
47 void ServeLinkRequest(int (*func)(int nexe_fd, 69 void ServeLinkRequest(CallbackFunc func) {
48 const int* obj_file_fds, 70 base::MessageLoop loop;
49 int obj_file_fd_count)) { 71 int fd = ppapi::GetRendererIPCFileDescriptor();
50 g_func = func; 72 IPC::ChannelHandle handle("NaCl IPC", base::FileDescriptor(fd, false));
51 if (!NaClSrpcModuleInit()) { 73 new TranslatorListener(handle, func);
52 NaClLog(LOG_FATAL, "NaClSrpcModuleInit() failed\n"); 74 loop.Run();
53 }
54 if (!NaClSrpcAcceptClientConnection(kSrpcMethods)) {
55 NaClLog(LOG_FATAL, "NaClSrpcAcceptClientConnection() failed\n");
56 }
57 } 75 }
58 76
59 } 77 }
60 78
61 const struct nacl_irt_private_pnacl_translator_link 79 const struct nacl_irt_private_pnacl_translator_link
62 nacl_irt_private_pnacl_translator_link = { 80 nacl_irt_private_pnacl_translator_link = {
63 ServeLinkRequest 81 ServeLinkRequest
64 }; 82 };
65 83
66 #endif // !defined(OS_NACL_NONSFI) 84 #endif // !defined(OS_NACL_NONSFI)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698