| 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/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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 new_handle->auto_close = true; | 388 new_handle->auto_close = true; |
| 389 | 389 |
| 390 if (close_self) { | 390 if (close_self) { |
| 391 Unmap(); | 391 Unmap(); |
| 392 Close(); | 392 Close(); |
| 393 } | 393 } |
| 394 | 394 |
| 395 return true; | 395 return true; |
| 396 } | 396 } |
| 397 | 397 |
| 398 bool SharedMemory::GetUniqueId(SharedMemory::UniqueId* id) const { | 398 // static |
| 399 bool SharedMemory::GetUniqueId(const SharedMemoryHandle& handle, |
| 400 SharedMemory::UniqueId* id) { |
| 399 // This function is called just after mmap. fstat is a system call that might | 401 // This function is called just after mmap. fstat is a system call that might |
| 400 // cause I/O. It's safe to call fstat here because mmap for shared memory is | 402 // cause I/O. It's safe to call fstat here because mmap for shared memory is |
| 401 // called in two cases: | 403 // called in two cases: |
| 402 // 1) To handle file-mapped memory | 404 // 1) To handle file-mapped memory |
| 403 // 2) To handle annonymous shared memory | 405 // 2) To handle annonymous shared memory |
| 404 // In 1), I/O is already permitted. In 2), the backend is on page cache and | 406 // In 1), I/O is already permitted. In 2), the backend is on page cache and |
| 405 // fstat doesn't cause I/O access to the disk. See the discussion at | 407 // fstat doesn't cause I/O access to the disk. See the discussion at |
| 406 // crbug.com/604726#c41. | 408 // crbug.com/604726#c41. |
| 407 base::ThreadRestrictions::ScopedAllowIO allow_io; | 409 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 408 struct stat file_stat; | 410 struct stat file_stat; |
| 409 if (HANDLE_EINTR(::fstat(static_cast<int>(handle().fd), &file_stat)) != 0) | 411 if (HANDLE_EINTR(::fstat(static_cast<int>(handle.fd), &file_stat)) != 0) |
| 410 return false; | 412 return false; |
| 411 id->first = file_stat.st_dev; | 413 id->first = file_stat.st_dev; |
| 412 id->second = file_stat.st_ino; | 414 id->second = file_stat.st_ino; |
| 413 return true; | 415 return true; |
| 414 } | 416 } |
| 415 | 417 |
| 416 } // namespace base | 418 } // namespace base |
| OLD | NEW |