Index: mojo/edk/embedder/entrypoints.cc |
diff --git a/mojo/edk/embedder/entrypoints.cc b/mojo/edk/embedder/entrypoints.cc |
index fdd881a59980fe1ae9db97e0515709acde1b11ba..697f5f4c1a702ea58e8559d1596d05e61dbd2502 100644 |
--- a/mojo/edk/embedder/entrypoints.cc |
+++ b/mojo/edk/embedder/entrypoints.cc |
@@ -4,7 +4,10 @@ |
#include <stdint.h> |
+#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
|
#include "mojo/edk/embedder/embedder_internal.h" |
+#include "mojo/edk/embedder/platform_shared_buffer.h" |
+#include "mojo/edk/embedder/scoped_platform_handle.h" |
#include "mojo/edk/system/core.h" |
#include "mojo/public/c/system/buffer.h" |
#include "mojo/public/c/system/data_pipe.h" |
@@ -215,4 +218,64 @@ MojoResult MojoUnmapBuffer(void* buffer) { |
return g_core->UnmapBuffer(buffer); |
} |
+MojoResult MojoWrapPlatformHandle(MojoPlatformHandle platform_handle, |
+ MojoHandle* mojo_handle) { |
+ mojo::edk::ScopedPlatformHandle handle(mojo::edk::PlatformHandle( |
+#if defined(OS_POSIX) |
+ // For POSIX this API only supports wrapping file descriptors. |
+ static_cast<int>(platform_handle))); |
+#elif defined(OS_WIN) |
+ static_cast<HADNLE>(platform_handle))); |
+#else |
+ 0)); |
+#error Unsupported platform |
+#endif |
+ |
+ return g_core->CreatePlatformHandleWrapper(std::move(handle), mojo_handle); |
+} |
+ |
+MojoResult MojoUnwrapPlatformHandle(MojoHandle mojo_handle, |
+ MojoPlatformHandle* platform_handle) { |
+ mojo::edk::ScopedPlatformHandle handle; |
+ MojoResult result = g_core->PassWrappedPlatformHandle(mojo_handle, &handle); |
+ if (result == MOJO_RESULT_OK) { |
+ *platform_handle = |
+ static_cast<MojoPlatformHandle>(handle.release().handle); |
+ } |
+ return result; |
+} |
+ |
+MojoResult MojoWrapPlatformSharedBufferHandle( |
+ MojoPlatformHandle platform_handle, |
+ size_t num_bytes, |
+ MojoPlatformSharedBufferHandleFlags flags, |
+ MojoHandle* mojo_handle) { |
+ bool read_only = flags & MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY; |
+ base::SharedMemoryHandle handle( |
+ mojo::edk::PlatformSharedBuffer::GetSharedMemoryHandleFromPlatformHandle( |
+ platform_handle, num_bytes, read_only)); |
+ return g_core->CreateSharedBufferWrapper(handle, num_bytes, read_only, |
+ mojo_handle); |
+} |
+ |
+MojoResult MojoUnwrapPlatformSharedBufferHandle( |
+ MojoHandle mojo_handle, |
+ MojoPlatformHandle* platform_handle, |
+ size_t* num_bytes, |
+ MojoPlatformSharedBufferHandleFlags* flags) { |
+ base::SharedMemoryHandle handle; |
+ bool read_only; |
+ MojoResult result = g_core->PassSharedMemoryHandle(mojo_handle, &handle, |
+ num_bytes, &read_only); |
+ if (result == MOJO_RESULT_OK) { |
+ *flags = MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_NONE; |
+ if (read_only) |
+ *flags |= MOJO_PLATFORM_SHARED_BUFFER_HANDLE_FLAG_READ_ONLY; |
+ *platform_handle = static_cast<MojoPlatformHandle>( |
+ mojo::edk::PlatformSharedBuffer |
+ ::GetPlatformHandleFromSharedMemoryHandle(handle).handle); |
+ } |
+ return result; |
+} |
+ |
} // extern "C" |