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

Make new shared memory duplication and mapping APIs const

Duplicate, Map, and MapAt on these various types do not and should not
need to modify the calling object.

Bug: 826213
Change-Id: Ice07621c23f36da00e20a13076a783cf1e41d7f2
Reviewed-on: https://chromium-review.googlesource.com/990673Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547539}
parent f3acd395
......@@ -157,7 +157,7 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
// invalid region on failure, the current instance remains valid.
// Can be called only in kReadOnly and kUnsafe modes, CHECK-fails if is
// called in kWritable mode.
PlatformSharedMemoryRegion Duplicate();
PlatformSharedMemoryRegion Duplicate() const;
// Converts the region to read-only. Returns whether the operation succeeded.
// Makes the current instance invalid on failure. Can be called only in
......@@ -180,7 +180,10 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
// and leaves output parameters in unspecified state otherwise. The mapped
// address is guaranteed to have an alignment of at least
// |kMapMinimumAlignment|.
bool MapAt(off_t offset, size_t size, void** memory, size_t* mapped_size);
bool MapAt(off_t offset,
size_t size,
void** memory,
size_t* mapped_size) const;
const UnguessableToken& GetGUID() const { return guid_; }
......
......@@ -59,7 +59,7 @@ bool PlatformSharedMemoryRegion::IsValid() const {
return handle_.is_valid();
}
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() {
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
if (!IsValid())
return {};
......@@ -103,7 +103,7 @@ bool PlatformSharedMemoryRegion::ConvertToReadOnly() {
bool PlatformSharedMemoryRegion::MapAt(off_t offset,
size_t size,
void** memory,
size_t* mapped_size) {
size_t* mapped_size) const {
if (!IsValid())
return false;
......
......@@ -44,7 +44,7 @@ bool PlatformSharedMemoryRegion::IsValid() const {
return handle_.is_valid();
}
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() {
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
if (!IsValid())
return {};
......@@ -92,7 +92,7 @@ bool PlatformSharedMemoryRegion::ConvertToReadOnly() {
bool PlatformSharedMemoryRegion::MapAt(off_t offset,
size_t size,
void** memory,
size_t* mapped_size) {
size_t* mapped_size) const {
if (!IsValid())
return false;
......
......@@ -47,7 +47,7 @@ bool PlatformSharedMemoryRegion::IsValid() const {
return handle_.is_valid();
}
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() {
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
if (!IsValid())
return {};
......@@ -114,7 +114,7 @@ bool PlatformSharedMemoryRegion::ConvertToReadOnly(void* mapped_addr) {
bool PlatformSharedMemoryRegion::MapAt(off_t offset,
size_t size,
void** memory,
size_t* mapped_size) {
size_t* mapped_size) const {
if (!IsValid())
return false;
......
......@@ -116,7 +116,7 @@ bool PlatformSharedMemoryRegion::IsValid() const {
(mode_ == Mode::kWritable ? handle_.readonly_fd.is_valid() : true);
}
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() {
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
if (!IsValid())
return {};
......@@ -148,7 +148,7 @@ bool PlatformSharedMemoryRegion::ConvertToReadOnly() {
bool PlatformSharedMemoryRegion::MapAt(off_t offset,
size_t size,
void** memory,
size_t* mapped_size) {
size_t* mapped_size) const {
if (!IsValid())
return false;
......
......@@ -165,7 +165,7 @@ bool PlatformSharedMemoryRegion::IsValid() const {
return handle_.IsValid();
}
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() {
PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Duplicate() const {
if (!IsValid())
return {};
......@@ -209,7 +209,7 @@ bool PlatformSharedMemoryRegion::ConvertToReadOnly() {
bool PlatformSharedMemoryRegion::MapAt(off_t offset,
size_t size,
void** memory,
size_t* mapped_size) {
size_t* mapped_size) const {
if (!IsValid())
return false;
......
......@@ -58,16 +58,17 @@ ReadOnlySharedMemoryRegion& ReadOnlySharedMemoryRegion::operator=(
ReadOnlySharedMemoryRegion&& region) = default;
ReadOnlySharedMemoryRegion::~ReadOnlySharedMemoryRegion() = default;
ReadOnlySharedMemoryRegion ReadOnlySharedMemoryRegion::Duplicate() {
ReadOnlySharedMemoryRegion ReadOnlySharedMemoryRegion::Duplicate() const {
return ReadOnlySharedMemoryRegion(handle_.Duplicate());
}
ReadOnlySharedMemoryMapping ReadOnlySharedMemoryRegion::Map() {
ReadOnlySharedMemoryMapping ReadOnlySharedMemoryRegion::Map() const {
return MapAt(0, handle_.GetSize());
}
ReadOnlySharedMemoryMapping ReadOnlySharedMemoryRegion::MapAt(off_t offset,
size_t size) {
ReadOnlySharedMemoryMapping ReadOnlySharedMemoryRegion::MapAt(
off_t offset,
size_t size) const {
if (!IsValid())
return {};
......
......@@ -62,20 +62,20 @@ class BASE_EXPORT ReadOnlySharedMemoryRegion {
// ReadOnlySharedMemoryRegion instance that owns this handle. Returns a valid
// ReadOnlySharedMemoryRegion on success, invalid otherwise. The current
// region instance remains valid in any case.
ReadOnlySharedMemoryRegion Duplicate();
ReadOnlySharedMemoryRegion Duplicate() const;
// Maps the shared memory region into the caller's address space with
// read-only access. The mapped address is guaranteed to have an alignment of
// at least |subtle::PlatformSharedMemoryRegion::kMapMinimumAlignment|.
// Returns a valid ReadOnlySharedMemoryMapping instance on success, invalid
// otherwise.
ReadOnlySharedMemoryMapping Map();
ReadOnlySharedMemoryMapping Map() const;
// Same as above, but maps only |size| bytes of the shared memory region
// starting with the given |offset|. |offset| must be aligned to value of
// |SysInfo::VMAllocationGranularity()|. Returns an invalid mapping if
// requested bytes are out of the region limits.
ReadOnlySharedMemoryMapping MapAt(off_t offset, size_t size);
ReadOnlySharedMemoryMapping MapAt(off_t offset, size_t size) const;
// Whether the underlying platform handle is valid.
bool IsValid() const;
......
......@@ -38,16 +38,16 @@ UnsafeSharedMemoryRegion& UnsafeSharedMemoryRegion::operator=(
UnsafeSharedMemoryRegion&& region) = default;
UnsafeSharedMemoryRegion::~UnsafeSharedMemoryRegion() = default;
UnsafeSharedMemoryRegion UnsafeSharedMemoryRegion::Duplicate() {
UnsafeSharedMemoryRegion UnsafeSharedMemoryRegion::Duplicate() const {
return UnsafeSharedMemoryRegion(handle_.Duplicate());
}
WritableSharedMemoryMapping UnsafeSharedMemoryRegion::Map() {
WritableSharedMemoryMapping UnsafeSharedMemoryRegion::Map() const {
return MapAt(0, handle_.GetSize());
}
WritableSharedMemoryMapping UnsafeSharedMemoryRegion::MapAt(off_t offset,
size_t size) {
size_t size) const {
if (!IsValid())
return {};
......
......@@ -63,20 +63,20 @@ class BASE_EXPORT UnsafeSharedMemoryRegion {
// UnsafeSharedMemoryRegion instance that owns the newly created handle.
// Returns a valid UnsafeSharedMemoryRegion on success, invalid otherwise.
// The current region instance remains valid in any case.
UnsafeSharedMemoryRegion Duplicate();
UnsafeSharedMemoryRegion Duplicate() const;
// Maps the shared memory region into the caller's address space with write
// access. The mapped address is guaranteed to have an alignment of
// at least |subtle::PlatformSharedMemoryRegion::kMapMinimumAlignment|.
// Returns a valid WritableSharedMemoryMapping instance on success, invalid
// otherwise.
WritableSharedMemoryMapping Map();
WritableSharedMemoryMapping Map() const;
// Same as above, but maps only |size| bytes of the shared memory region
// starting with the given |offset|. |offset| must be aligned to value of
// |SysInfo::VMAllocationGranularity()|. Returns an invalid mapping if
// requested bytes are out of the region limits.
WritableSharedMemoryMapping MapAt(off_t offset, size_t size);
WritableSharedMemoryMapping MapAt(off_t offset, size_t size) const;
// Whether the underlying platform handle is valid.
bool IsValid() const;
......
......@@ -49,12 +49,13 @@ WritableSharedMemoryRegion& WritableSharedMemoryRegion::operator=(
WritableSharedMemoryRegion&& region) = default;
WritableSharedMemoryRegion::~WritableSharedMemoryRegion() = default;
WritableSharedMemoryMapping WritableSharedMemoryRegion::Map() {
WritableSharedMemoryMapping WritableSharedMemoryRegion::Map() const {
return MapAt(0, handle_.GetSize());
}
WritableSharedMemoryMapping WritableSharedMemoryRegion::MapAt(off_t offset,
size_t size) {
WritableSharedMemoryMapping WritableSharedMemoryRegion::MapAt(
off_t offset,
size_t size) const {
if (!IsValid())
return {};
......
......@@ -66,13 +66,13 @@ class BASE_EXPORT WritableSharedMemoryRegion {
// at least |subtle::PlatformSharedMemoryRegion::kMapMinimumAlignment|.
// Returns a valid WritableSharedMemoryMapping instance on success, invalid
// otherwise.
WritableSharedMemoryMapping Map();
WritableSharedMemoryMapping Map() const;
// Same as above, but maps only |size| bytes of the shared memory block
// starting with the given |offset|. |offset| must be aligned to value of
// |SysInfo::VMAllocationGranularity()|. Returns an invalid mapping if
// requested bytes are out of the region limits.
WritableSharedMemoryMapping MapAt(off_t offset, size_t size);
WritableSharedMemoryMapping MapAt(off_t offset, size_t size) const;
// Whether underlying platform handles are valid.
bool IsValid() const;
......
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