Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: base/shared_memory_posix.cc

Issue 21238: Fix error checking for mmap() for POSIX shared memory. (Closed)
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/ipc_send_fds_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 10
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 bool SharedMemory::Map(size_t bytes) { 207 bool SharedMemory::Map(size_t bytes) {
208 if (mapped_file_ == -1) 208 if (mapped_file_ == -1)
209 return false; 209 return false;
210 210
211 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), 211 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
212 MAP_SHARED, mapped_file_, 0); 212 MAP_SHARED, mapped_file_, 0);
213 213
214 if (memory_) 214 if (memory_)
215 max_size_ = bytes; 215 max_size_ = bytes;
216 216
217 return (memory_ != NULL); 217 bool mmap_succeeded = (memory_ != (void*)-1);
218 DCHECK(mmap_succeeded) << "Call to mmap failed, errno=" << errno;
219 return mmap_succeeded;
218 } 220 }
219 221
220 bool SharedMemory::Unmap() { 222 bool SharedMemory::Unmap() {
221 if (memory_ == NULL) 223 if (memory_ == NULL)
222 return false; 224 return false;
223 225
224 munmap(memory_, max_size_); 226 munmap(memory_, max_size_);
225 memory_ = NULL; 227 memory_ = NULL;
226 max_size_ = 0; 228 max_size_ = 0;
227 return true; 229 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 271
270 void SharedMemory::Lock() { 272 void SharedMemory::Lock() {
271 LockOrUnlockCommon(F_LOCK); 273 LockOrUnlockCommon(F_LOCK);
272 } 274 }
273 275
274 void SharedMemory::Unlock() { 276 void SharedMemory::Unlock() {
275 LockOrUnlockCommon(F_ULOCK); 277 LockOrUnlockCommon(F_ULOCK);
276 } 278 }
277 279
278 } // namespace base 280 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/common/ipc_send_fds_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698