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