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

Side by Side Diff: mojo/edk/embedder/entrypoints.cc

Issue 1995753002: [mojo-edk] Expose portable API for platform handle wrapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/process/process_handle.h"
Anand Mistry (off Chromium) 2016/05/20 06:25:40 This looks unused here.
Ken Rockot(use gerrit already) 2016/05/20 22:19:43 Removed
7 #include "mojo/edk/embedder/embedder_internal.h" 8 #include "mojo/edk/embedder/embedder_internal.h"
9 #include "mojo/edk/embedder/platform_shared_buffer.h"
10 #include "mojo/edk/embedder/scoped_platform_handle.h"
8 #include "mojo/edk/system/core.h" 11 #include "mojo/edk/system/core.h"
9 #include "mojo/public/c/system/buffer.h" 12 #include "mojo/public/c/system/buffer.h"
10 #include "mojo/public/c/system/data_pipe.h" 13 #include "mojo/public/c/system/data_pipe.h"
11 #include "mojo/public/c/system/functions.h" 14 #include "mojo/public/c/system/functions.h"
12 #include "mojo/public/c/system/message_pipe.h" 15 #include "mojo/public/c/system/message_pipe.h"
13 #include "mojo/public/c/system/wait_set.h" 16 #include "mojo/public/c/system/wait_set.h"
14 17
15 using mojo::edk::internal::g_core; 18 using mojo::edk::internal::g_core;
16 19
17 // Definitions of the system functions. 20 // Definitions of the system functions.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 uint64_t num_bytes, 211 uint64_t num_bytes,
209 void** buffer, 212 void** buffer,
210 MojoMapBufferFlags flags) { 213 MojoMapBufferFlags flags) {
211 return g_core->MapBuffer(buffer_handle, offset, num_bytes, buffer, flags); 214 return g_core->MapBuffer(buffer_handle, offset, num_bytes, buffer, flags);
212 } 215 }
213 216
214 MojoResult MojoUnmapBuffer(void* buffer) { 217 MojoResult MojoUnmapBuffer(void* buffer) {
215 return g_core->UnmapBuffer(buffer); 218 return g_core->UnmapBuffer(buffer);
216 } 219 }
217 220
221 MojoResult MojoWrapPlatformHandle(MojoPlatformHandle platform_handle,
222 MojoHandle* mojo_handle) {
223 mojo::edk::ScopedPlatformHandle handle(mojo::edk::PlatformHandle(
224 #if defined(OS_POSIX)
225 // For POSIX this API only supports wrapping file descriptors.
226 static_cast<int>(platform_handle)));
227 #elif defined(OS_WIN)
228 static_cast<HADNLE>(platform_handle)));
229 #else
230 0));
231 #error Unsupported platform
232 #endif
233
234 return g_core->CreatePlatformHandleWrapper(std::move(handle), mojo_handle);
235 }
236
237 MojoResult MojoUnwrapPlatformHandle(MojoHandle mojo_handle,
238 MojoPlatformHandle* platform_handle) {
239 mojo::edk::ScopedPlatformHandle handle;
240 MojoResult result = g_core->PassWrappedPlatformHandle(mojo_handle, &handle);
241 if (result == MOJO_RESULT_OK) {
242 *platform_handle =
243 static_cast<MojoPlatformHandle>(handle.release().handle);
244 }
245 return result;
246 }
247
248 MojoResult MojoWrapPlatformSharedBufferHandle(
249 MojoPlatformHandle platform_handle,
250 size_t num_bytes,
251 MojoPlatformSharedBufferHandleFlags flags,
252 MojoHandle* mojo_handle) {
253 bool read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY;
254 base::SharedMemoryHandle handle(
255 mojo::edk::PlatformSharedBuffer::GetSharedMemoryHandleFromPlatformHandle(
256 platform_handle, num_bytes, read_only));
257 return g_core->CreateSharedBufferWrapper(handle, num_bytes, read_only,
258 mojo_handle);
259 }
260
261 MojoResult MojoUnwrapPlatformSharedBufferHandle(
262 MojoHandle mojo_handle,
263 MojoPlatformHandle* platform_handle,
264 size_t* num_bytes,
265 MojoPlatformSharedBufferHandleFlags* flags) {
266 base::SharedMemoryHandle handle;
267 bool read_only;
268 MojoResult result = g_core->PassSharedMemoryHandle(mojo_handle, &handle,
269 num_bytes, &read_only);
270 if (result == MOJO_RESULT_OK) {
271 *flags = MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE;
272 if (read_only)
273 *flags |= MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY;
274 *platform_handle = static_cast<MojoPlatformHandle>(
275 mojo::edk::PlatformSharedBuffer
276 ::GetPlatformHandleFromSharedMemoryHandle(handle).handle);
277 }
278 return result;
279 }
280
218 } // extern "C" 281 } // extern "C"
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/embedder/platform_shared_buffer.h » ('j') | mojo/edk/embedder/platform_shared_buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698