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

Side by Side Diff: base/memory/shared_memory_posix.cc

Issue 2847033003: Get rid of SharedMemory::GiveToProcess. (Closed)
Patch Set: Comments from avi. Created 3 years, 7 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 | « base/memory/shared_memory_nacl.cc ('k') | base/memory/shared_memory_win.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) 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/memory/shared_memory.h" 5 #include "base/memory/shared_memory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <sys/mman.h> 10 #include <sys/mman.h>
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 return true; 354 return true;
355 } 355 }
356 #endif // !defined(OS_ANDROID) 356 #endif // !defined(OS_ANDROID)
357 357
358 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() { 358 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() {
359 CHECK(readonly_shm_.IsValid()); 359 CHECK(readonly_shm_.IsValid());
360 return readonly_shm_.Duplicate(); 360 return readonly_shm_.Duplicate();
361 } 361 }
362 362
363 bool SharedMemory::ShareToProcessCommon(ProcessHandle process, 363 bool SharedMemory::ShareToProcessCommon(ProcessHandle process,
364 SharedMemoryHandle* new_handle, 364 SharedMemoryHandle* new_handle) {
365 bool close_self) {
366 *new_handle = shm_.Duplicate(); 365 *new_handle = shm_.Duplicate();
367 if (close_self) {
368 Unmap();
369 Close();
370 }
371 return new_handle->IsValid(); 366 return new_handle->IsValid();
372 } 367 }
373 368
374 bool SharedMemory::GetUniqueId(SharedMemory::UniqueId* id) const { 369 bool SharedMemory::GetUniqueId(SharedMemory::UniqueId* id) const {
375 // This function is called just after mmap. fstat is a system call that might 370 // This function is called just after mmap. fstat is a system call that might
376 // cause I/O. It's safe to call fstat here because mmap for shared memory is 371 // cause I/O. It's safe to call fstat here because mmap for shared memory is
377 // called in two cases: 372 // called in two cases:
378 // 1) To handle file-mapped memory 373 // 1) To handle file-mapped memory
379 // 2) To handle annonymous shared memory 374 // 2) To handle annonymous shared memory
380 // In 1), I/O is already permitted. In 2), the backend is on page cache and 375 // In 1), I/O is already permitted. In 2), the backend is on page cache and
381 // fstat doesn't cause I/O access to the disk. See the discussion at 376 // fstat doesn't cause I/O access to the disk. See the discussion at
382 // crbug.com/604726#c41. 377 // crbug.com/604726#c41.
383 base::ThreadRestrictions::ScopedAllowIO allow_io; 378 base::ThreadRestrictions::ScopedAllowIO allow_io;
384 struct stat file_stat; 379 struct stat file_stat;
385 if (HANDLE_EINTR( 380 if (HANDLE_EINTR(
386 ::fstat(static_cast<int>(handle().GetHandle()), &file_stat)) != 0) 381 ::fstat(static_cast<int>(handle().GetHandle()), &file_stat)) != 0)
387 return false; 382 return false;
388 id->first = file_stat.st_dev; 383 id->first = file_stat.st_dev;
389 id->second = file_stat.st_ino; 384 id->second = file_stat.st_ino;
390 return true; 385 return true;
391 } 386 }
392 387
393 } // namespace base 388 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_nacl.cc ('k') | base/memory/shared_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698