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" |
11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" | 11 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
12 #include "ppapi/nacl_irt/irt_manifest.h" | 12 #include "ppapi/nacl_irt/irt_manifest.h" |
13 #include "ppapi/nacl_irt/plugin_startup.h" | 13 #include "ppapi/nacl_irt/plugin_startup.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
15 | 15 |
| 16 #if !defined(OS_NACL_SFI) |
| 17 #include <pthread.h> |
| 18 #include <map> |
| 19 #include <string> |
| 20 #endif |
| 21 |
16 namespace ppapi { | 22 namespace ppapi { |
17 | 23 |
18 const char kFilePrefix[] = "files/"; | 24 const char kFilePrefix[] = "files/"; |
19 | 25 |
20 // IPC channel is asynchronously set up. So, the NaCl process may try to | 26 // IPC channel is asynchronously set up. So, the NaCl process may try to |
21 // send a OpenResource message to the host before the connection is | 27 // send a OpenResource message to the host before the connection is |
22 // established. In such a case, it is necessary to wait for the set up | 28 // established. In such a case, it is necessary to wait for the set up |
23 // completion. | 29 // completion. |
24 class ManifestMessageFilter : public IPC::SyncMessageFilter { | 30 class ManifestMessageFilter : public IPC::SyncMessageFilter { |
25 public: | 31 public: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Copy the file if we received a valid file descriptor. Otherwise, if we got | 119 // Copy the file if we received a valid file descriptor. Otherwise, if we got |
114 // a reply, the file doesn't exist, so provide an fd of -1. | 120 // a reply, the file doesn't exist, so provide an fd of -1. |
115 // See IrtOpenResource() for how this function's result is interpreted. | 121 // See IrtOpenResource() for how this function's result is interpreted. |
116 if (ipc_fd.is_file()) | 122 if (ipc_fd.is_file()) |
117 *fd = ipc_fd.descriptor().fd; | 123 *fd = ipc_fd.descriptor().fd; |
118 else | 124 else |
119 *fd = -1; | 125 *fd = -1; |
120 return true; | 126 return true; |
121 } | 127 } |
122 | 128 |
| 129 #if !defined(OS_NACL_SFI) |
| 130 namespace { |
| 131 |
| 132 pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER; |
| 133 std::map<std::string, int>* g_prefetched_fds; |
| 134 |
| 135 } // namespace |
| 136 |
| 137 void RegisterPreopenedDescriptorsNonSfi( |
| 138 std::map<std::string, int>* key_fd_map) { |
| 139 pthread_mutex_lock(&g_mu); |
| 140 DCHECK(!g_prefetched_fds); |
| 141 g_prefetched_fds = key_fd_map; |
| 142 pthread_mutex_unlock(&g_mu); |
| 143 } |
| 144 #endif |
| 145 |
123 int IrtOpenResource(const char* file, int* fd) { | 146 int IrtOpenResource(const char* file, int* fd) { |
124 // Remove leading '/' character. | 147 // Remove leading '/' character. |
125 if (file[0] == '/') | 148 if (file[0] == '/') |
126 ++file; | 149 ++file; |
127 | 150 |
| 151 #if !defined(OS_NACL_SFI) |
| 152 // Fast path for prefetched FDs. |
| 153 pthread_mutex_lock(&g_mu); |
| 154 if (g_prefetched_fds) { |
| 155 std::map<std::string, int>::iterator it = g_prefetched_fds->find(file); |
| 156 if (it != g_prefetched_fds->end()) { |
| 157 *fd = it->second; |
| 158 g_prefetched_fds->erase(it); |
| 159 pthread_mutex_unlock(&g_mu); |
| 160 return 0; |
| 161 } |
| 162 } |
| 163 pthread_mutex_unlock(&g_mu); |
| 164 #endif |
| 165 |
128 ManifestService* manifest_service = GetManifestService(); | 166 ManifestService* manifest_service = GetManifestService(); |
129 if (manifest_service == NULL || | 167 if (manifest_service == NULL || |
130 !manifest_service->OpenResource(file, fd)) { | 168 !manifest_service->OpenResource(file, fd)) { |
131 return NACL_ABI_EIO; | 169 return NACL_ABI_EIO; |
132 } | 170 } |
133 return (*fd == -1) ? NACL_ABI_ENOENT : 0; | 171 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
134 } | 172 } |
135 | 173 |
136 } // namespace ppapi | 174 } // namespace ppapi |
OLD | NEW |