diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc index e1289e7e1da0..aa718957cf26 100644 --- a/base/memory/shared_memory_posix.cc +++ b/base/memory/shared_memory_posix.cc @@ -29,6 +30,8 @@ #if defined(OS_ANDROID) #include "base/os_compat_android.h" +#endif +#if defined(OS_ANDROID) || defined(__ANDROID__) #include "third_party/ashmem/ashmem.h" #endif @@ -80,7 +83,7 @@ bool SharedMemory::CreateAndMapAnonymous(size_t size) { return CreateAnonymous(size) && Map(size); } -#if !defined(OS_ANDROID) +#if !defined(OS_ANDROID) && !defined(__ANDROID__) // Chromium mostly only uses the unique/private shmem as specified by // "name == L"". The exception is in the StatsTable. @@ -252,7 +255,7 @@ bool SharedMemory::Open(const std::string& name, bool read_only) { FileDescriptor(readonly_mapped_file, false), 0, shm_.GetGUID()); return result; } -#endif // !defined(OS_ANDROID) +#endif // !defined(OS_ANDROID) && !defined(__ANDROID__) bool SharedMemory::MapAt(off_t offset, size_t bytes) { if (!shm_.IsValid()) @@ -264,7 +267,7 @@ bool SharedMemory::MapAt(off_t offset, size_t bytes) { if (memory_) return false; -#if defined(OS_ANDROID) +#if defined(OS_ANDROID) || defined(__ANDROID__) // On Android, Map can be called with a size and offset of zero to use the // ashmem-determined size. if (bytes == 0) { @@ -277,19 +280,19 @@ bool SharedMemory::MapAt(off_t offset, size_t bytes) { // Sanity check. This shall catch invalid uses of the SharedMemory APIs // but will not protect against direct mmap() attempts. - if (shm_.IsReadOnly()) { - // Use a DCHECK() to call writable mappings with read-only descriptors - // in debug builds immediately. Return an error for release builds - // or during unit-testing (assuming a ScopedLogAssertHandler was installed). - DCHECK(read_only_) - << "Trying to map a region writable with a read-only descriptor."; - if (!read_only_) { - return false; - } - if (!shm_.SetRegionReadOnly()) { // Ensure the region is read-only. - return false; - } - } + // if (shm_.IsReadOnly()) { + // // Use a DCHECK() to call writable mappings with read-only descriptors + // // in debug builds immediately. Return an error for release builds + // // or during unit-testing (assuming a ScopedLogAssertHandler was installed). + // DCHECK(read_only_) + // << "Trying to map a region writable with a read-only descriptor."; + // if (!read_only_) { + // return false; + // } + // if (!shm_.SetRegionReadOnly()) { // Ensure the region is read-only. + // return false; + // } + // } #endif memory_ = mmap(nullptr, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), @@ -334,7 +339,7 @@ SharedMemoryHandle SharedMemory::TakeHandle() { return handle_copy; } -#if !defined(OS_ANDROID) +#if !defined(OS_ANDROID) && !defined(__ANDROID__) void SharedMemory::Close() { if (shm_.IsValid()) { shm_.Close(); @@ -374,6 +379,6 @@ SharedMemoryHandle SharedMemory::GetReadOnlyHandle() const { CHECK(readonly_shm_.IsValid()); return readonly_shm_.Duplicate(); } -#endif // !defined(OS_ANDROID) +#endif // !defined(OS_ANDROID) && !defined(__ANDROID__) } // namespace base