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_shm_ = SharedMemoryHandle::ImportHandle(dup(shm_.GetHandle())); | 45 readonly_shm_ = SharedMemoryHandle( |
| 46 base::FileDescriptor(dup(shm_.GetHandle()), false), shm_.GetGUID()); |
46 if (!readonly_shm_.IsValid()) { | 47 if (!readonly_shm_.IsValid()) { |
47 DPLOG(ERROR) << "dup() failed"; | 48 DPLOG(ERROR) << "dup() failed"; |
48 return false; | 49 return false; |
49 } | 50 } |
50 | 51 |
51 requested_size_ = options.size; | 52 requested_size_ = options.size; |
52 | 53 |
53 return true; | 54 return true; |
54 } | 55 } |
55 | 56 |
56 bool SharedMemory::Delete(const std::string& name) { | 57 bool SharedMemory::Delete(const std::string& name) { |
57 // Like on Windows, this is intentionally returning true as ashmem will | 58 // Like on Windows, this is intentionally returning true as ashmem will |
58 // automatically releases the resource when all FDs on it are closed. | 59 // automatically releases the resource when all FDs on it are closed. |
59 return true; | 60 return true; |
60 } | 61 } |
61 | 62 |
62 bool SharedMemory::Open(const std::string& name, bool read_only) { | 63 bool SharedMemory::Open(const std::string& name, bool read_only) { |
63 // ashmem doesn't support name mapping | 64 // ashmem doesn't support name mapping |
64 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
65 return false; | 66 return false; |
66 } | 67 } |
67 | 68 |
68 } // namespace base | 69 } // namespace base |
OLD | NEW |