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

Side by Side Diff: base/shared_memory_posix.cc

Issue 10174007: Fix shared_memory_posix Map() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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>
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // TODO(port): we set the created size here so that it is available in 232 // TODO(port): we set the created size here so that it is available in
233 // transport_dib_android.cc. We should use ashmem_get_size_region() 233 // transport_dib_android.cc. We should use ashmem_get_size_region()
234 // in transport_dib_android.cc. 234 // in transport_dib_android.cc.
235 created_size_ = bytes; 235 created_size_ = bytes;
236 } 236 }
237 #endif 237 #endif
238 238
239 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE), 239 memory_ = mmap(NULL, bytes, PROT_READ | (read_only_ ? 0 : PROT_WRITE),
240 MAP_SHARED, mapped_file_, 0); 240 MAP_SHARED, mapped_file_, 0);
241 241
242 if (memory_) 242 bool mmap_succeeded = memory_ != (void*)-1 && memory_ != NULL;
243 if (mmap_succeeded)
243 mapped_size_ = bytes; 244 mapped_size_ = bytes;
245 else
246 memory_ = NULL;
244 247
245 bool mmap_succeeded = (memory_ != (void*)-1);
246 DCHECK(mmap_succeeded) << "Call to mmap failed, errno=" << errno;
247 return mmap_succeeded; 248 return mmap_succeeded;
248 } 249 }
249 250
250 bool SharedMemory::Unmap() { 251 bool SharedMemory::Unmap() {
251 if (memory_ == NULL) 252 if (memory_ == NULL)
252 return false; 253 return false;
253 254
254 munmap(memory_, mapped_size_); 255 munmap(memory_, mapped_size_);
255 memory_ = NULL; 256 memory_ = NULL;
256 mapped_size_ = 0; 257 mapped_size_ = 0;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 new_handle->fd = new_fd; 367 new_handle->fd = new_fd;
367 new_handle->auto_close = true; 368 new_handle->auto_close = true;
368 369
369 if (close_self) 370 if (close_self)
370 Close(); 371 Close();
371 372
372 return true; 373 return true;
373 } 374 }
374 375
375 } // namespace base 376 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698