| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 int err = ashmem_set_prot_region(shm_.GetHandle(), | 36 int err = ashmem_set_prot_region(shm_.GetHandle(), |
| 37 PROT_READ | PROT_WRITE | PROT_EXEC); | 37 PROT_READ | PROT_WRITE | PROT_EXEC); |
| 38 if (err < 0) { | 38 if (err < 0) { |
| 39 DLOG(ERROR) << "Error " << err << " when setting protection of ashmem"; | 39 DLOG(ERROR) << "Error " << err << " when setting protection of ashmem"; |
| 40 return false; | 40 return false; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // Android doesn't appear to have a way to drop write access on an ashmem | 43 // Android doesn't appear to have a way to drop write access on an ashmem |
| 44 // segment for a single descriptor. http://crbug.com/320865 | 44 // segment for a single descriptor. http://crbug.com/320865 |
| 45 readonly_mapped_file_ = dup(shm_.GetHandle()); | 45 readonly_shm_ = SharedMemoryHandle::ImportHandle(dup(shm_.GetHandle())); |
| 46 if (-1 == readonly_mapped_file_) { | 46 if (!readonly_shm_.IsValid()) { |
| 47 DPLOG(ERROR) << "dup() failed"; | 47 DPLOG(ERROR) << "dup() failed"; |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 | 50 |
| 51 requested_size_ = options.size; | 51 requested_size_ = options.size; |
| 52 | 52 |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool SharedMemory::Delete(const std::string& name) { | 56 bool SharedMemory::Delete(const std::string& name) { |
| 57 // Like on Windows, this is intentionally returning true as ashmem will | 57 // Like on Windows, this is intentionally returning true as ashmem will |
| 58 // automatically releases the resource when all FDs on it are closed. | 58 // automatically releases the resource when all FDs on it are closed. |
| 59 return true; | 59 return true; |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool SharedMemory::Open(const std::string& name, bool read_only) { | 62 bool SharedMemory::Open(const std::string& name, bool read_only) { |
| 63 // ashmem doesn't support name mapping | 63 // ashmem doesn't support name mapping |
| 64 NOTIMPLEMENTED(); | 64 NOTIMPLEMENTED(); |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace base | 68 } // namespace base |
| OLD | NEW |