Commit 9ee73d67 authored by Wez's avatar Wez Committed by Commit Bot

Clean-ups to Fuchsia implementation of PlatformSharedMemoryRegion.

- Define PlatformSharedMemoryRegion::PlatformHandle to use the typed
  zx::unowned_vmo wrapper, rather than raw zx_handle_t.
- Migrate zx_vmar_* call-sites off of *_old() variants, to use zx::vmar
  methods.

Change-Id: Iade0c388c7f593303ad79d2504e438e88ab2807f
Reviewed-on: https://chromium-review.googlesource.com/1199610Reviewed-by: default avatarAlexandr Ilin <alexilin@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588603}
parent d2bf6d33
......@@ -97,7 +97,7 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
using PlatformHandle = mach_port_t;
using ScopedPlatformHandle = mac::ScopedMachSendRight;
#elif defined(OS_FUCHSIA)
using PlatformHandle = zx_handle_t;
using PlatformHandle = zx::unowned_vmo;
using ScopedPlatformHandle = zx::vmo;
#elif defined(OS_WIN)
using PlatformHandle = HANDLE;
......
......@@ -4,9 +4,9 @@
#include "base/memory/platform_shared_memory_region.h"
#include <lib/zx/vmar.h>
#include <zircon/process.h>
#include <zircon/rights.h>
#include <zircon/syscalls.h>
#include "base/bits.h"
#include "base/fuchsia/fuchsia_logging.h"
......@@ -35,8 +35,8 @@ PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Take(
if (size > static_cast<size_t>(std::numeric_limits<int>::max()))
return {};
CHECK(
CheckPlatformHandlePermissionsCorrespondToMode(handle.get(), mode, size));
CHECK(CheckPlatformHandlePermissionsCorrespondToMode(zx::unowned_vmo(handle),
mode, size));
return PlatformSharedMemoryRegion(std::move(handle), mode, size, guid);
}
......@@ -54,8 +54,8 @@ PlatformSharedMemoryRegion::TakeFromSharedMemoryHandle(
handle.GetGUID());
}
zx_handle_t PlatformSharedMemoryRegion::GetPlatformHandle() const {
return handle_.get();
zx::unowned_vmo PlatformSharedMemoryRegion::GetPlatformHandle() const {
return zx::unowned_vmo(handle_);
}
bool PlatformSharedMemoryRegion::IsValid() const {
......@@ -122,8 +122,8 @@ bool PlatformSharedMemoryRegion::MapAt(off_t offset,
bool write_allowed = mode_ != Mode::kReadOnly;
uintptr_t addr;
zx_status_t status = zx_vmar_map_old(
zx_vmar_root_self(), 0, handle_.get(), offset, size,
zx_status_t status = zx::vmar::root_self()->map(
0, handle_, offset, size,
ZX_VM_FLAG_PERM_READ | (write_allowed ? ZX_VM_FLAG_PERM_WRITE : 0),
&addr);
if (status != ZX_OK) {
......@@ -175,8 +175,8 @@ bool PlatformSharedMemoryRegion::CheckPlatformHandlePermissionsCorrespondToMode(
Mode mode,
size_t size) {
zx_info_handle_basic_t basic = {};
zx_status_t status = zx_object_get_info(handle, ZX_INFO_HANDLE_BASIC, &basic,
sizeof(basic), nullptr, nullptr);
zx_status_t status = handle->get_info(ZX_INFO_HANDLE_BASIC, &basic,
sizeof(basic), nullptr, nullptr);
if (status != ZX_OK) {
ZX_DLOG(ERROR, status) << "zx_object_get_info";
return false;
......
......@@ -25,9 +25,8 @@
#endif
#if defined(OS_FUCHSIA)
#include <zircon/process.h>
#include <zircon/status.h>
#include <zircon/syscalls.h>
#include <lib/zx/vmar.h>
#include "base/fuchsia/fuchsia_logging.h"
#endif
namespace base {
......@@ -75,9 +74,8 @@ void SharedMemoryMapping::Unmap() {
DPLOG(ERROR) << "UnmapViewOfFile";
#elif defined(OS_FUCHSIA)
uintptr_t addr = reinterpret_cast<uintptr_t>(memory_);
zx_status_t status = zx_vmar_unmap(zx_vmar_root_self(), addr, size_);
DLOG_IF(ERROR, status != ZX_OK)
<< "zx_vmar_unmap failed: " << zx_status_get_string(status);
zx_status_t status = zx::vmar::root_self()->unmap(addr, size_);
ZX_DLOG_IF(ERROR, status != ZX_OK, status) << "zx_vmar_unmap";
#elif defined(OS_MACOSX) && !defined(OS_IOS)
kern_return_t kr = mach_vm_deallocate(
mach_task_self(), reinterpret_cast<mach_vm_address_t>(memory_), size_);
......
......@@ -20,9 +20,8 @@
#endif
#if defined(OS_FUCHSIA)
#include <zircon/process.h>
#include <lib/zx/vmar.h>
#include <zircon/rights.h>
#include <zircon/syscalls.h>
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
......@@ -67,19 +66,18 @@ static bool CheckReadOnlySharedMemoryFdPosix(int fd) {
}
return true;
}
#endif // OS_POSIX && !OS_FUCHSIA
#endif // OS_POSIX
#if defined(OS_FUCHSIA)
// Fuchsia specific implementation.
bool CheckReadOnlySharedMemoryFuchsiaHandle(zx_handle_t handle) {
bool CheckReadOnlySharedMemoryFuchsiaHandle(zx::unowned_vmo handle) {
const uint32_t flags = ZX_VM_FLAG_PERM_READ | ZX_VM_FLAG_PERM_WRITE;
uintptr_t addr;
const zx_handle_t root = zx_vmar_root_self();
const zx_status_t status =
zx_vmar_map_old(root, 0, handle, 0U, kDataSize, flags, &addr);
zx::vmar::root_self()->map(0, *handle, 0U, kDataSize, flags, &addr);
if (status == ZX_OK) {
LOG(ERROR) << "zx_vmar_map() should have failed!";
zx_vmar_unmap(root, addr, kDataSize);
zx::vmar::root_self()->unmap(addr, kDataSize);
return false;
}
if (status != ZX_ERR_ACCESS_DENIED) {
......@@ -126,7 +124,8 @@ bool CheckReadOnlySharedMemoryHandleForTesting(SharedMemoryHandle handle) {
else
return CheckReadOnlySharedMemoryMachPort(handle.memory_object_);
#elif defined(OS_FUCHSIA)
return CheckReadOnlySharedMemoryFuchsiaHandle(handle.GetHandle());
return CheckReadOnlySharedMemoryFuchsiaHandle(
zx::unowned_vmo(handle.GetHandle()));
#elif defined(OS_WIN)
return CheckReadOnlySharedMemoryWindowsHandle(handle.GetHandle());
#else
......
......@@ -1005,7 +1005,10 @@ bool ParamTraits<base::subtle::PlatformSharedMemoryRegion>::Read(
void ParamTraits<base::subtle::PlatformSharedMemoryRegion>::Log(
const param_type& p,
std::string* l) {
#if defined(OS_FUCHSIA) || defined(OS_WIN)
#if defined(OS_FUCHSIA)
l->append("Handle: ");
LogParam(p.GetPlatformHandle()->get(), l);
#elif defined(OS_WIN)
l->append("Handle: ");
LogParam(p.GetPlatformHandle(), l);
#elif defined(OS_MACOSX) && !defined(OS_IOS)
......
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