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

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

Issue 2873433004: Replace SharedMemory::UniqueID usages with SharedMemoryHandle's guid (Closed)
Patch Set: Address on reviews 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
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 *path = temp_dir.AppendASCII(name_base + ".shmem." + mem_name); 362 *path = temp_dir.AppendASCII(name_base + ".shmem." + mem_name);
363 return true; 363 return true;
364 } 364 }
365 #endif // !defined(OS_ANDROID) 365 #endif // !defined(OS_ANDROID)
366 366
367 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() { 367 SharedMemoryHandle SharedMemory::GetReadOnlyHandle() {
368 CHECK(readonly_shm_.IsValid()); 368 CHECK(readonly_shm_.IsValid());
369 return readonly_shm_.Duplicate(); 369 return readonly_shm_.Duplicate();
370 } 370 }
371 371
372 bool SharedMemory::GetUniqueId(SharedMemory::UniqueId* id) const {
373 // This function is called just after mmap. fstat is a system call that might
374 // cause I/O. It's safe to call fstat here because mmap for shared memory is
375 // called in two cases:
376 // 1) To handle file-mapped memory
377 // 2) To handle annonymous shared memory
378 // In 1), I/O is already permitted. In 2), the backend is on page cache and
379 // fstat doesn't cause I/O access to the disk. See the discussion at
380 // crbug.com/604726#c41.
381 base::ThreadRestrictions::ScopedAllowIO allow_io;
382 struct stat file_stat;
383 if (HANDLE_EINTR(
384 ::fstat(static_cast<int>(handle().GetHandle()), &file_stat)) != 0)
385 return false;
386 id->first = file_stat.st_dev;
387 id->second = file_stat.st_ino;
388 return true;
389 }
390
391 } // namespace base 372 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698