Commit bdc9eaea authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Revert "Introduce public PlatformHandle type"

This reverts commit 1bdfba58.

Reason for revert: broke fuchsia
Original change's description:
> Introduce public PlatformHandle type
> 
> Adds mojo/public/cpp/platform to the public library. This includes
> a new PlatformHandle type, a thin C++ abstraction for platform-specific
> scoped handle values.
> 
> This is a precursor to moving platform channel C++ types out of the EDK
> and into the public library, and ultimately introducing a public C++
> invitation API to replace the EDK invitation API.
> 
> Bug: 844764
> Change-Id: I317decc1deb8cc47eb1000a6a19022465c392d7b
> Reviewed-on: https://chromium-review.googlesource.com/1068688
> Reviewed-by: Jay Civelli <jcivelli@chromium.org>
> Commit-Queue: Ken Rockot <rockot@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#560866}

TBR=jcivelli@chromium.org,rockot@chromium.org

Change-Id: If401afe09a2e91d5e2a0035a75db5490a41259ad
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 844764
Reviewed-on: https://chromium-review.googlesource.com/1068219Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560876}
parent 4563ced3
......@@ -39,7 +39,6 @@ test("mojo_unittests") {
"//mojo/edk/test:run_all_unittests",
"//mojo/public/cpp/base:tests",
"//mojo/public/cpp/bindings/tests",
"//mojo/public/cpp/platform/tests",
"//mojo/public/cpp/system/tests",
]
}
......
......@@ -33,7 +33,6 @@ component("edk") {
public_deps = [
":impl_for_edk",
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
]
}
......@@ -140,7 +139,6 @@ template("core_impl_source_set") {
"//base",
"//mojo/edk/system/ports",
"//mojo/public/c/system:headers",
"//mojo/public/cpp/platform",
]
if (is_fuchsia) {
......
......@@ -11,7 +11,6 @@
#include "mojo/edk/system/system_impl_export.h"
#include "mojo/public/c/system/platform_handle.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/platform/platform_handle.h"
namespace mojo {
namespace edk {
......
......@@ -4,9 +4,6 @@ include_rules = [
"+mojo/public",
"+testing",
"-mojo",
"+mojo/public",
# Temporary until mojom [Native] is gone.
"+ipc/ipc_param_traits.h",
]
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
component("platform") {
output_name = "mojo_cpp_platform"
public = [
"platform_handle.h",
]
sources = [
"platform_handle.cc",
]
public_deps = [
"//base",
]
if (is_fuchsia) {
public_deps += [ "//third_party/fuchsia-sdk:fdio" ]
}
defines = [ "IS_MOJO_CPP_PLATFORM_IMPL" ]
}
include_rules = [
# Mojo platform support must not depend on any other part of the Mojo public
# library.
"-mojo",
"+mojo/public/cpp/platform",
# For some syscalls when building in NaCl toolchains.
"+native_client/src/public",
]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/public/cpp/platform/platform_handle.h"
#include "base/logging.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_FUCHSIA)
#include <fdio/limits.h>
#include <unistd.h>
#include <zircon/status.h>
#include <zircon/syscalls.h>
#elif defined(OS_MACOSX) && !defined(OS_IOS)
#include <mach/mach_vm.h>
#include "base/mac/mach_logging.h"
#endif
#if defined(OS_POSIX)
#include <unistd.h>
#endif
namespace mojo {
namespace {
#if defined(OS_WIN)
base::win::ScopedHandle CloneHandle(const base::win::ScopedHandle& handle) {
DCHECK(handle.IsValid());
HANDLE dupe;
BOOL result = ::DuplicateHandle(::GetCurrentProcess(), handle.Get(),
::GetCurrentProcess(), &dupe, 0, FALSE,
DUPLICATE_SAME_ACCESS);
if (!result)
return base::win::ScopedHandle();
DCHECK_NE(dupe, INVALID_HANDLE_VALUE);
return base::win::ScopedHandle(dupe);
}
#elif defined(OS_FUCHSIA)
base::ScopedZxHandle CloneHandle(const base::ScopedZxHandle& handle) {
DCHECK(handle.is_valid());
zx_handle_t dupe;
zx_status_t result =
zx_handle_duplicate(handle.get(), ZX_RIGHT_SAME_RIGHTS, &dupe);
DLOG_IF(ERROR, result != ZX_OK) << "zx_duplicate_handle failed: " << result;
return base::ScopedZxHandle(dupe);
}
#elif defined(OS_MACOSX) && !defined(OS_IOS)
base::mac::ScopedMachSendRight CloneMachPort(
const base::mac::ScopedMachSendRight& mach_port) {
DCHECK(mach_port.is_valid());
kern_return_t kr = mach_port_mod_refs(mach_task_self(), mach_port.get(),
MACH_PORT_RIGHT_SEND, 1);
if (kr != KERN_SUCCESS) {
MACH_DLOG(ERROR, kr) << "mach_port_mod_refs";
return base::mac::ScopedMachSendRight();
}
return base::mac::ScopedMachSendRight(mach_port.get());
}
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
base::ScopedFD CloneFD(const base::ScopedFD& fd) {
DCHECK(fd.is_valid());
return base::ScopedFD(dup(fd.get()));
}
#endif
} // namespace
PlatformHandle::PlatformHandle() = default;
PlatformHandle::PlatformHandle(PlatformHandle&& other) = default;
#if defined(OS_WIN)
PlatformHandle::PlatformHandle(base::win::ScopedHandle handle)
: handle_(std::move(handle)) {}
#elif defined(OS_FUCHSIA)
PlatformHandle::PlatformHandle(base::ScopedZxHandle handle)
: handle_(std::move(handle)) {}
#elif defined(OS_MACOSX) && !defined(OS_IOS)
PlatformHandle::PlatformHandle(base::mac::ScopedMachSendRight mach_port)
: mach_port_(std::move(mach_port)) {}
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
PlatformHandle::PlatformHandle(base::ScopedFD fd) : fd_(std::move(fd)) {
#if defined(OS_FUCHSIA)
DCHECK_LT(fd_.get(), FDIO_MAX_FD);
#endif
}
#endif
PlatformHandle::~PlatformHandle() = default;
PlatformHandle& PlatformHandle::operator=(PlatformHandle&& other) = default;
void PlatformHandle::reset() {
#if defined(OS_WIN)
handle_.Close();
#elif defined(OS_FUCHSIA)
handle_.reset();
#elif defined(OS_MACOSX) && !defined(OS_IOS)
mach_port_.reset();
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
fd_.reset();
#endif
}
PlatformHandle PlatformHandle::Clone() const {
#if defined(OS_WIN)
return PlatformHandle(CloneHandle(handle_));
#elif defined(OS_FUCHSIA)
if (is_valid_handle())
return PlatformHandle(CloneHandle(handle_));
return PlatformHandle(CloneFD(fd_));
#elif defined(OS_MACOSX) && !defined(OS_IOS)
if (is_valid_mach_port())
return PlatformHandle(CloneMachPort(mach_port_));
return PlatformHandle(CloneFD(fd_));
#elif defined(OS_POSIX)
return PlatformHandle(CloneFD(fd_));
#endif
}
} // namespace mojo
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_PUBLIC_CPP_PLATFORM_PLATFORM_HANDLE_H_
#define MOJO_PUBLIC_CPP_PLATFORM_PLATFORM_HANDLE_H_
#include "base/component_export.h"
#include "base/logging.h"
#include "base/macros.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "base/win/scoped_handle.h"
#elif defined(OS_FUCHSIA)
#include "base/fuchsia/scoped_zx_handle.h"
#elif defined(OS_MACOSX) && !defined(OS_IOS)
#include "base/mac/scoped_mach_port.h"
#endif
#if defined(OS_POSIX)
#include "base/files/scoped_file.h"
#endif
namespace mojo {
// A PlatformHandle is a generic wrapper around a platform-specific system
// handle type, e.g. a POSIX file descriptor or Windows HANDLE. This can wrap
// any of various such types depending on the host platform for which it's
// compiled.
//
// This is useful primarily for two reasons:
//
// - Interacting with the Mojo invitation API, which use OS primitives to
// bootstrap Mojo IPC connections.
// - Interacting with Mojo platform handle wrapping and unwrapping API, which
// allows handles to OS primitives to be transmitted over Mojo IPC with a
// stable wire representation via Mojo handles.
//
// NOTE: This assumes ownership if the handle it represents.
class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle {
public:
PlatformHandle();
PlatformHandle(PlatformHandle&& other);
#if defined(OS_WIN)
explicit PlatformHandle(base::win::ScopedHandle handle);
#elif defined(OS_FUCHSIA)
explicit PlatformHandle(base::ScopedZxHandle handle);
#elif defined(OS_MACOSX) && !defined(OS_IOS)
explicit PlatformHandle(base::mac::ScopedMachSendRight mach_port);
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
explicit PlatformHandle(base::ScopedFD fd);
#endif
~PlatformHandle();
PlatformHandle& operator=(PlatformHandle&& other);
// Closes the underlying platform handle.
void reset();
// Duplicates the underlying platform handle, returning a new PlatformHandle
// which owns it.
PlatformHandle Clone() const;
#if defined(OS_WIN)
bool is_valid() const { return handle_.IsValid(); }
const base::win::ScopedHandle& GetHandle() const { return handle_; }
base::win::ScopedHandle TakeHandle() { return std::move(handle_); }
HANDLE ReleaseHandle() WARN_UNUSED_RESULT { return handle_.Take(); }
#elif defined(OS_FUCHSIA)
bool is_valid() const { return is_valid_fd() || is_valid_handle(); }
bool is_valid_handle() const { return handle_.is_valid(); }
const base::ScopedZxHandle& GetHandle() const { return handle_; }
base::ScopedZxHandle TakeHandle() { return std::move(handle_); }
zx_handle_t ReleaseHandle() WARN_UNUSED_RESULT { return handle_.release(); }
#elif defined(OS_MACOSX) && !defined(OS_IOS)
bool is_valid() const { return is_valid_fd() || is_valid_mach_port(); }
bool is_valid_mach_port() const { return mach_port_.is_valid(); }
const base::mac::ScopedMachSendRight& GetMachPort() const {
return mach_port_;
}
base::mac::ScopedMachSendRight TakeMachPort() {
return std::move(mach_port_);
}
mach_port_t ReleaseMachPort() WARN_UNUSED_RESULT {
return mach_port_.release();
}
#elif defined(OS_POSIX)
bool is_valid() const { return is_valid_fd(); }
#else
#error "Unsupported platform."
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
bool is_valid_fd() const { return fd_.is_valid(); }
const base::ScopedFD& GetFD() const { return fd_; }
base::ScopedFD TakeFD() { return std::move(fd_); }
int ReleaseFD() WARN_UNUSED_RESULT { return fd_.release(); }
#endif
private:
#if defined(OS_WIN)
base::win::ScopedHandle handle_;
#elif defined(OS_FUCHSIA)
base::ScopedZxHandle handle_;
#elif defined(OS_MACOSX) && !defined(OS_IOS)
base::mac::ScopedMachSendRight mach_port_;
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
base::ScopedFD fd_;
#endif
DISALLOW_COPY_AND_ASSIGN(PlatformHandle);
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_PLATFORM_PLATFORM_HANDLE_H_
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("tests") {
testonly = true
sources = [
"platform_handle_unittest.cc",
]
deps = [
"//base",
"//mojo/public/c/system",
"//mojo/public/cpp/platform",
"//mojo/public/cpp/system",
"//testing/gtest",
]
}
include_rules = [
"+mojo/public",
]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/public/cpp/platform/platform_handle.h"
#include "base/files/file.h"
#include "base/files/platform_file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/rand_util.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "mojo/public/c/system/platform_handle.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_MACOSX) && !defined(OS_IOS)
#include <mach/mach_vm.h>
#endif
#if defined(OS_WIN)
#include "base/win/scoped_handle.h"
#else
#include "base/files/scoped_file.h"
#endif
namespace mojo {
namespace {
// Different types of platform handles are supported on different platforms.
// We run all PlatformHandle once for each type of handle available on the
// target platform.
enum class HandleType {
#if defined(OS_WIN) || defined(OS_FUCHSIA)
kHandle,
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
kFileDescriptor,
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
kMachPort,
#endif
};
// Different types of test modes we support in order to exercise the available
// handles types. Fuchsia zx_handle tests and Mac Mach port tests use shared
// memory for setup and validation. Everything else uses platform files.
// See |SetUp()| below.
enum class TestType {
kFile,
kSharedMemory,
};
const std::string kTestData = "some data to validate";
class PlatformHandleTest : public testing::Test,
public testing::WithParamInterface<HandleType> {
public:
PlatformHandleTest() = default;
void SetUp() override {
test_type_ = TestType::kFile;
#if defined(OS_FUCHSIA)
if (GetParam() == HandleType::kHandle)
test_type_ = TestType::kSharedMemory;
#elif defined(OS_MACOSX) && !defined(OS_IOS)
if (GetParam() == HandleType::kMachPort)
test_type_ = TestType::kSharedMemory;
#endif
if (test_type_ == TestType::kFile)
test_handle_ = SetUpFile();
#if defined(OS_FUCHSIA) || (defined(OS_MACOSX) && !defined(OS_IOS))
else
test_handle_ = SetUpSharedMemory();
#endif
}
// Extracts the contents of a file or shared memory object, given a generic
// PlatformHandle wrapping it. Used to verify that a |handle| refers to some
// expected platform object.
std::string GetObjectContents(PlatformHandle& handle) {
if (test_type_ == TestType::kFile)
return GetFileContents(handle);
#if defined(OS_FUCHSIA) || (defined(OS_MACOSX) && !defined(OS_IOS))
else
return GetSharedMemoryContents(handle);
#endif
NOTREACHED();
return std::string();
}
protected:
PlatformHandle& test_handle() { return test_handle_; }
private:
// Creates a platform file with some test data in it. Leaves the file open
// with cursor positioned at the beginning, and returns it as a generic
// PlatformHandle.
PlatformHandle SetUpFile() {
CHECK(temp_dir_.CreateUniqueTempDir());
base::File test_file(temp_dir_.GetPath().AppendASCII("test"),
base::File::FLAG_CREATE | base::File::FLAG_WRITE |
base::File::FLAG_READ);
test_file.WriteAtCurrentPos(kTestData.data(), kTestData.size());
#if defined(OS_WIN)
return PlatformHandle(
base::win::ScopedHandle(test_file.TakePlatformFile()));
#else
return PlatformHandle(base::ScopedFD(test_file.TakePlatformFile()));
#endif
}
// Returns the contents of a platform file referenced by |handle|. Used to
// verify that |handle| is in fact the platform file handle it's expected to
// be. See |GetObjectContents()|.
std::string GetFileContents(PlatformHandle& handle) {
#if defined(OS_WIN)
// We must temporarily release ownership of the handle due to how File
// interacts with ScopedHandle.
base::File file(handle.TakeHandle().Take());
#else
base::File file(handle.GetFD().get());
#endif
std::vector<char> buffer(kTestData.size());
file.Read(0, buffer.data(), buffer.size());
std::string contents(buffer.begin(), buffer.end());
// Let |handle| retain ownership.
#if defined(OS_WIN)
handle = PlatformHandle(base::win::ScopedHandle(file.TakePlatformFile()));
#else
ignore_result(file.TakePlatformFile());
#endif
return contents;
}
#if defined(OS_FUCHSIA) || (defined(OS_MACOSX) && !defined(OS_IOS))
// Creates a shared memory region with some test data in it. Leaves the
// handle open and returns it as a generic PlatformHandle.
PlatformHandle SetUpSharedMemory() {
auto region = base::UnsafeSharedMemoryRegion::Create(kTestData.size());
auto mapping = region.Map();
memcpy(mapping.memory(), kTestData.data(), kTestData.size());
auto generic_region =
base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
std::move(region));
shm_guid_ = generic_region.GetGUID();
return PlatformHandle(generic_region.PassPlatformHandle());
}
// Extracts data stored in a shared memory object referenced by |handle|. Used
// to verify that |handle| does in fact reference a shared memory object when
// expected. See |GetObjectContents()|.
std::string GetSharedMemoryContents(const PlatformHandle& handle) {
base::subtle::PlatformSharedMemoryRegion::ScopedPlatformHandle
region_handle(
#if defined(OS_FUCHSIA)
handle.GetHandle().get()
#elif defined(OS_MACOSX) && !defined(OS_IOS)
handle.GetMachPort().get()
#endif
);
auto generic_region = base::subtle::PlatformSharedMemoryRegion::Take(
std::move(region_handle),
base::subtle::PlatformSharedMemoryRegion::Mode::kUnsafe,
kTestData.size(), shm_guid_);
auto region =
base::UnsafeSharedMemoryRegion::Deserialize(std::move(generic_region));
auto mapping = region.Map();
std::string contents(static_cast<char*>(mapping.memory()),
kTestData.size());
// Let |handle| retain ownership.
generic_region = base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
std::move(region));
region_handle = generic_region.PassPlatformHandle();
ignore_result(region_handle.release());
return contents;
}
#endif // defined(OS_FUCHSIA) || (defined(OS_MACOSX) && !defined(OS_IOS))
base::ScopedTempDir temp_dir_;
TestType test_type_;
PlatformHandle test_handle_;
// Needed to reconstitute a base::PlatformSharedMemoryRegion from an unwrapped
// PlatformHandle.
base::UnguessableToken shm_guid_;
DISALLOW_COPY_AND_ASSIGN(PlatformHandleTest);
};
TEST_P(PlatformHandleTest, BasicConstruction) {
EXPECT_EQ(kTestData, GetObjectContents(test_handle()));
}
TEST_P(PlatformHandleTest, Move) {
EXPECT_EQ(kTestData, GetObjectContents(test_handle()));
auto new_handle = std::move(test_handle());
EXPECT_FALSE(test_handle().is_valid());
EXPECT_TRUE(new_handle.is_valid());
EXPECT_EQ(kTestData, GetObjectContents(new_handle));
}
TEST_P(PlatformHandleTest, Reset) {
auto handle = std::move(test_handle());
EXPECT_TRUE(handle.is_valid());
handle.reset();
EXPECT_FALSE(handle.is_valid());
}
TEST_P(PlatformHandleTest, Clone) {
EXPECT_EQ(kTestData, GetObjectContents(test_handle()));
auto clone = test_handle().Clone();
EXPECT_TRUE(clone.is_valid());
EXPECT_EQ(kTestData, GetObjectContents(clone));
clone.reset();
EXPECT_FALSE(clone.is_valid());
EXPECT_TRUE(test_handle().is_valid());
EXPECT_EQ(kTestData, GetObjectContents(test_handle()));
}
// This is really testing system library stuff, but we conveniently have all
// this handle type parameterization already in place here.
TEST_P(PlatformHandleTest, CStructConversion) {
EXPECT_EQ(kTestData, GetObjectContents(test_handle()));
MojoPlatformHandle c_handle;
PlatformHandleToMojoPlatformHandle(std::move(test_handle()), &c_handle);
PlatformHandle handle = MojoPlatformHandleToPlatformHandle(&c_handle);
EXPECT_EQ(kTestData, GetObjectContents(handle));
}
INSTANTIATE_TEST_CASE_P(,
PlatformHandleTest,
#if defined(OS_WIN)
testing::Values(HandleType::kHandle)
#elif defined(OS_FUCHSIA)
testing::Values(HandleType::kHandle,
HandleType::kFileDescriptor)
#elif defined(OS_MACOSX) && !defined(OS_IOS)
testing::Values(HandleType::kFileDescriptor,
HandleType::kMachPort)
#elif defined(OS_POSIX)
testing::Values(HandleType::kFileDescriptor)
#endif
);
} // namespace
} // namespace mojo
......@@ -61,7 +61,6 @@ component("system") {
public_deps = [
"//base",
"//mojo/public/c/system",
"//mojo/public/cpp/platform",
]
deps = [
":clean_up_old_dylib",
......
......@@ -179,78 +179,6 @@ base::subtle::PlatformSharedMemoryRegion UnwrapPlatformSharedMemoryRegion(
} // namespace
void PlatformHandleToMojoPlatformHandle(PlatformHandle handle,
MojoPlatformHandle* out_handle) {
DCHECK(out_handle);
out_handle->struct_size = sizeof(MojoPlatformHandle);
if (!handle.is_valid()) {
out_handle->type = MOJO_PLATFORM_HANDLE_TYPE_INVALID;
out_handle->value = 0;
return;
}
do {
#if defined(OS_WIN)
out_handle->type = MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE;
out_handle->value =
static_cast<uint64_t>(HandleToLong(handle.TakeHandle().Take()));
break;
#elif defined(OS_FUCHSIA)
if (handle.is_valid_handle()) {
out_handle->type = MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE;
out_handle->value = handle.TakeHandle().release();
break;
}
#elif defined(OS_MACOSX) && !defined(OS_IOS)
if (handle.is_valid_mach_port()) {
out_handle->type = MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT;
out_handle->value =
static_cast<uint64_t>(handle.TakeMachPort().release());
break;
}
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
DCHECK(handle.is_valid_fd());
out_handle->type = MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR;
out_handle->value = static_cast<uint64_t>(handle.TakeFD().release());
#endif
} while (false);
// One of the above cases must take ownership of |handle|.
DCHECK(!handle.is_valid());
}
PlatformHandle MojoPlatformHandleToPlatformHandle(
const MojoPlatformHandle* handle) {
if (handle->struct_size < sizeof(*handle) ||
handle->type == MOJO_PLATFORM_HANDLE_TYPE_INVALID) {
return PlatformHandle();
}
#if defined(OS_WIN)
if (handle->type != MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE)
return PlatformHandle();
return PlatformHandle(
base::win::ScopedHandle(LongToHandle(static_cast<long>(handle->value))));
#elif defined(OS_FUCHSIA)
if (handle->type == MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE)
return PlatformHandle(base::ScopedZxHandle(handle->value));
#elif defined(OS_MACOSX) && !defined(OS_IOS)
if (handle->type == MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT) {
return PlatformHandle(base::mac::ScopedMachSendRight(
static_cast<mach_port_t>(handle->value)));
}
#endif
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
if (handle->type != MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR)
return PlatformHandle();
return PlatformHandle(base::ScopedFD(static_cast<int>(handle->value)));
#endif
}
// Wraps a PlatformFile as a Mojo handle. Takes ownership of the file object.
ScopedHandle WrapPlatformFile(base::PlatformFile platform_file) {
MojoPlatformHandle platform_handle;
platform_handle.struct_size = sizeof(MojoPlatformHandle);
......
......@@ -24,7 +24,6 @@
#include "base/process/process_handle.h"
#include "build/build_config.h"
#include "mojo/public/c/system/platform_handle.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "mojo/public/cpp/system/buffer.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/system_export.h"
......@@ -76,19 +75,6 @@ enum class UnwrappedSharedMemoryHandleProtection {
kReadOnly,
};
// Converts a PlatformHandle to the MojoPlatformHandle C struct for use with
// Mojo APIs. Note that although MojoPlatformHandle has weak ownership, this
// relinquishes ownership from |handle|.
void MOJO_CPP_SYSTEM_EXPORT
PlatformHandleToMojoPlatformHandle(PlatformHandle handle,
MojoPlatformHandle* out_handle);
// Converts a MojoPlatformHandle C struct to a PlatformHandle for use with
// various C++ APIs. Note that although MojoPlatformHandle has weak ownership,
// the new handle assumes ownership of the represented platform handle.
PlatformHandle MOJO_CPP_SYSTEM_EXPORT
MojoPlatformHandleToPlatformHandle(const MojoPlatformHandle* handle);
// Wraps a PlatformFile as a Mojo handle. Takes ownership of the file object.
// If |platform_file| is valid, this will return a valid handle.
MOJO_CPP_SYSTEM_EXPORT
......
include_rules = [
"+mojo/edk",
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment