OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ppapi/nacl_irt/manifest_service.h" | 5 #include "ppapi/nacl_irt/manifest_service.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "ipc/ipc_channel_handle.h" | 8 #include "ipc/ipc_channel_handle.h" |
9 #include "ipc/ipc_channel_proxy.h" | 9 #include "ipc/ipc_channel_proxy.h" |
10 #include "ipc/ipc_sync_message_filter.h" | 10 #include "ipc/ipc_sync_message_filter.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 } | 73 } |
74 | 74 |
75 ManifestService::~ManifestService() { | 75 ManifestService::~ManifestService() { |
76 } | 76 } |
77 | 77 |
78 void ManifestService::StartupInitializationComplete() { | 78 void ManifestService::StartupInitializationComplete() { |
79 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); | 79 filter_->Send(new PpapiHostMsg_StartupInitializationComplete); |
80 } | 80 } |
81 | 81 |
82 bool ManifestService::OpenResource(const char* file, int* fd) { | 82 bool ManifestService::OpenResource(const char* file, int* fd) { |
83 // We currently restrict to only allow one concurrent open_resource() call | |
84 // per plugin. This could be fixed by doing a token lookup with | |
85 // NaClProcessMsg_ResolveFileTokenAsyncReply instead of using a | |
86 // global inside components/nacl/loader/nacl_listener.cc | |
87 base::AutoLock lock(open_resource_lock_); | |
88 | |
83 // OpenResource will return INVALID SerializedHandle, if it is not supported. | 89 // OpenResource will return INVALID SerializedHandle, if it is not supported. |
84 // Specifically, PNaCl doesn't support open resource. | 90 // Specifically, PNaCl doesn't support open resource. |
85 ppapi::proxy::SerializedHandle ipc_fd; | 91 ppapi::proxy::SerializedHandle ipc_fd; |
92 | |
93 // File tokens are ignored here, but needed when the message is processed | |
94 // inside NaClIPCAdapter. | |
95 uint64_t file_token_lo; | |
96 uint64_t file_token_hi; | |
86 if (!filter_->Send(new PpapiHostMsg_OpenResource( | 97 if (!filter_->Send(new PpapiHostMsg_OpenResource( |
87 std::string(kFilePrefix) + file, &ipc_fd)) || | 98 std::string(kFilePrefix) + file, |
88 !ipc_fd.is_file()) { | 99 &ipc_fd, |
100 &file_token_lo, | |
101 &file_token_hi))) { | |
89 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; | 102 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; |
90 *fd = -1; | 103 *fd = -1; |
91 return false; | 104 return false; |
92 } | 105 } |
93 | 106 |
94 *fd = ipc_fd.descriptor().fd; | 107 // TODO(teravest): Check that file_token_lo and file_token_hi are 0. That |
108 // currently works on Linux, but not on Windows... | |
Mark Seaborn
2014/08/28 21:33:49
Why doesn't it work on Windows?
teravest
2014/09/04 22:13:30
I'm going to debug this. I wanted to get some feed
| |
109 | |
110 // Copy the file if we received a valid file descriptor. Otherwise, if we got | |
111 // a reply, the file doesn't exist, so provide an fd of -1. | |
112 // See ppapi/nacl_irt/manifest_service.cc for how this function's result is | |
Mark Seaborn
2014/08/28 21:33:49
That is this file, in the function immediately bel
teravest
2014/09/04 22:13:30
Thanks, I've worded this a bit better now.
| |
113 // interpreted. | |
114 if (ipc_fd.is_file()) | |
115 *fd = ipc_fd.descriptor().fd; | |
116 else | |
117 *fd = -1; | |
95 return true; | 118 return true; |
96 } | 119 } |
97 | 120 |
98 int IrtOpenResource(const char* file, int* fd) { | 121 int IrtOpenResource(const char* file, int* fd) { |
99 // Remove leading '/' character. | 122 // Remove leading '/' character. |
100 if (file[0] == '/') | 123 if (file[0] == '/') |
101 ++file; | 124 ++file; |
102 | 125 |
103 ManifestService* manifest_service = GetManifestService(); | 126 ManifestService* manifest_service = GetManifestService(); |
104 if (manifest_service == NULL || | 127 if (manifest_service == NULL || |
105 !manifest_service->OpenResource(file, fd)) { | 128 !manifest_service->OpenResource(file, fd)) { |
106 return NACL_ABI_EIO; | 129 return NACL_ABI_EIO; |
107 } | 130 } |
108 | |
109 return (*fd == -1) ? NACL_ABI_ENOENT : 0; | 131 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
110 } | 132 } |
111 | 133 |
112 } // namespace ppapi | 134 } // namespace ppapi |
OLD | NEW |