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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // NaClProcessMsg_ResolveFileTokenAsyncReply instead of using a | 85 // NaClProcessMsg_ResolveFileTokenAsyncReply instead of using a |
86 // global inside components/nacl/loader/nacl_listener.cc | 86 // global inside components/nacl/loader/nacl_listener.cc |
87 base::AutoLock lock(open_resource_lock_); | 87 base::AutoLock lock(open_resource_lock_); |
88 | 88 |
89 // OpenResource will return INVALID SerializedHandle, if it is not supported. | 89 // OpenResource will return INVALID SerializedHandle, if it is not supported. |
90 // Specifically, PNaCl doesn't support open resource. | 90 // Specifically, PNaCl doesn't support open resource. |
91 ppapi::proxy::SerializedHandle ipc_fd; | 91 ppapi::proxy::SerializedHandle ipc_fd; |
92 | 92 |
93 // File tokens are ignored here, but needed when the message is processed | 93 // File tokens are ignored here, but needed when the message is processed |
94 // inside NaClIPCAdapter. | 94 // inside NaClIPCAdapter. |
95 uint64_t file_token_lo; | 95 uint64_t file_token_lo = 0; |
96 uint64_t file_token_hi; | 96 uint64_t file_token_hi = 0; |
97 if (!filter_->Send(new PpapiHostMsg_OpenResource( | 97 if (!filter_->Send(new PpapiHostMsg_OpenResource( |
98 std::string(kFilePrefix) + file, | 98 std::string(kFilePrefix) + file, |
99 &ipc_fd, | 99 &ipc_fd, |
100 &file_token_lo, | 100 &file_token_lo, |
101 &file_token_hi))) { | 101 &file_token_hi))) { |
102 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; | 102 LOG(ERROR) << "ManifestService::OpenResource failed:" << file; |
103 *fd = -1; | 103 *fd = -1; |
104 return false; | 104 return false; |
105 } | 105 } |
106 | 106 |
107 #if defined(OS_NACL_SFI) | |
108 // File tokens are used internally by NaClIPCAdapter and should have | 107 // File tokens are used internally by NaClIPCAdapter and should have |
109 // been cleared from the message when it is received here. | 108 // been cleared from the message when it is received here. |
110 // Note that, on Non-SFI NaCl, the IPC channel is directly connected to the | 109 // These tokens should never be set for Non-SFI mode. |
111 // renderer process, so NaClIPCAdapter does not work. It means, | |
112 // file_token_{lo,hi} fields may be properly filled, although it is just | |
113 // ignored here. | |
114 CHECK(file_token_lo == 0); | 110 CHECK(file_token_lo == 0); |
115 CHECK(file_token_hi == 0); | 111 CHECK(file_token_hi == 0); |
116 #endif | |
117 | 112 |
118 // Copy the file if we received a valid file descriptor. Otherwise, if we got | 113 // Copy the file if we received a valid file descriptor. Otherwise, if we got |
119 // a reply, the file doesn't exist, so provide an fd of -1. | 114 // a reply, the file doesn't exist, so provide an fd of -1. |
120 // See IrtOpenResource() for how this function's result is interpreted. | 115 // See IrtOpenResource() for how this function's result is interpreted. |
121 if (ipc_fd.is_file()) | 116 if (ipc_fd.is_file()) |
122 *fd = ipc_fd.descriptor().fd; | 117 *fd = ipc_fd.descriptor().fd; |
123 else | 118 else |
124 *fd = -1; | 119 *fd = -1; |
125 return true; | 120 return true; |
126 } | 121 } |
127 | 122 |
128 int IrtOpenResource(const char* file, int* fd) { | 123 int IrtOpenResource(const char* file, int* fd) { |
129 // Remove leading '/' character. | 124 // Remove leading '/' character. |
130 if (file[0] == '/') | 125 if (file[0] == '/') |
131 ++file; | 126 ++file; |
132 | 127 |
133 ManifestService* manifest_service = GetManifestService(); | 128 ManifestService* manifest_service = GetManifestService(); |
134 if (manifest_service == NULL || | 129 if (manifest_service == NULL || |
135 !manifest_service->OpenResource(file, fd)) { | 130 !manifest_service->OpenResource(file, fd)) { |
136 return NACL_ABI_EIO; | 131 return NACL_ABI_EIO; |
137 } | 132 } |
138 return (*fd == -1) ? NACL_ABI_ENOENT : 0; | 133 return (*fd == -1) ? NACL_ABI_ENOENT : 0; |
139 } | 134 } |
140 | 135 |
141 } // namespace ppapi | 136 } // namespace ppapi |
OLD | NEW |