OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shared_memory.h" | 5 #include "base/shared_memory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
| 13 #include <limits> |
| 14 |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 | 16 |
15 namespace base { | 17 namespace base { |
16 | 18 |
17 SharedMemory::SharedMemory() | 19 SharedMemory::SharedMemory() |
18 : mapped_file_(-1), | 20 : mapped_file_(-1), |
19 mapped_size_(0), | 21 mapped_size_(0), |
20 inode_(0), | 22 inode_(0), |
21 memory_(NULL), | 23 memory_(NULL), |
22 read_only_(false), | 24 read_only_(false), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return SharedMemoryHandle(); | 59 return SharedMemoryHandle(); |
58 } | 60 } |
59 | 61 |
60 // static | 62 // static |
61 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { | 63 void SharedMemory::CloseHandle(const SharedMemoryHandle& handle) { |
62 DCHECK_GE(handle.fd, 0); | 64 DCHECK_GE(handle.fd, 0); |
63 if (close(handle.fd) < 0) | 65 if (close(handle.fd) < 0) |
64 DPLOG(ERROR) << "close"; | 66 DPLOG(ERROR) << "close"; |
65 } | 67 } |
66 | 68 |
67 bool SharedMemory::CreateAndMapAnonymous(uint32 size) { | 69 bool SharedMemory::CreateAndMapAnonymous(size_t size) { |
68 // Untrusted code can't create descriptors or handles. | 70 // Untrusted code can't create descriptors or handles. |
69 return false; | 71 return false; |
70 } | 72 } |
71 | 73 |
72 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { | 74 bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { |
73 // Untrusted code can't create descriptors or handles. | 75 // Untrusted code can't create descriptors or handles. |
74 return false; | 76 return false; |
75 } | 77 } |
76 | 78 |
77 bool SharedMemory::Delete(const std::string& name) { | 79 bool SharedMemory::Delete(const std::string& name) { |
78 return false; | 80 return false; |
79 } | 81 } |
80 | 82 |
81 bool SharedMemory::Open(const std::string& name, bool read_only) { | 83 bool SharedMemory::Open(const std::string& name, bool read_only) { |
82 return false; | 84 return false; |
83 } | 85 } |
84 | 86 |
85 bool SharedMemory::Map(uint32 bytes) { | 87 bool SharedMemory::Map(size_t bytes) { |
86 if (mapped_file_ == -1) | 88 if (mapped_file_ == -1) |
87 return false; | 89 return false; |
88 | 90 |
| 91 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) |
| 92 return false; |
| 93 |
89 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), | 94 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), |
90 MAP_SHARED, mapped_file_, 0); | 95 MAP_SHARED, mapped_file_, 0); |
91 | 96 |
92 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; | 97 bool mmap_succeeded = memory_ != MAP_FAILED && memory_ != NULL; |
93 if (mmap_succeeded) { | 98 if (mmap_succeeded) { |
94 mapped_size_ = bytes; | 99 mapped_size_ = bytes; |
95 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & | 100 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & |
96 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); | 101 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); |
97 } else { | 102 } else { |
98 memory_ = NULL; | 103 memory_ = NULL; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 NOTIMPLEMENTED(); | 139 NOTIMPLEMENTED(); |
135 } | 140 } |
136 | 141 |
137 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, | 142 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, |
138 SharedMemoryHandle *new_handle, | 143 SharedMemoryHandle *new_handle, |
139 bool close_self) { | 144 bool close_self) { |
140 return false; | 145 return false; |
141 } | 146 } |
142 | 147 |
143 } // namespace base | 148 } // namespace base |
OLD | NEW |