| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/files/memory_mapped_file.h" | 5 #include "base/files/memory_mapped_file.h" |
| 6 | 6 |
| 7 #include <sys/mman.h> | 7 #include <sys/mman.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 | 15 |
| 16 MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) { | 16 MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 #if !defined(OS_NACL) |
| 19 bool MemoryMappedFile::MapFileRegionToMemory( | 20 bool MemoryMappedFile::MapFileRegionToMemory( |
| 20 const MemoryMappedFile::Region& region) { | 21 const MemoryMappedFile::Region& region) { |
| 21 ThreadRestrictions::AssertIOAllowed(); | 22 ThreadRestrictions::AssertIOAllowed(); |
| 22 | 23 |
| 23 off_t map_start = 0; | 24 off_t map_start = 0; |
| 24 size_t map_size = 0; | 25 size_t map_size = 0; |
| 25 int32 data_offset = 0; | 26 int32 data_offset = 0; |
| 26 | 27 |
| 27 if (region == MemoryMappedFile::Region::kWholeFile) { | 28 if (region == MemoryMappedFile::Region::kWholeFile) { |
| 28 int64 file_len = file_.GetLength(); | 29 int64 file_len = file_.GetLength(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 file_.GetPlatformFile(), | 68 file_.GetPlatformFile(), |
| 68 map_start)); | 69 map_start)); |
| 69 if (data_ == MAP_FAILED) { | 70 if (data_ == MAP_FAILED) { |
| 70 DPLOG(ERROR) << "mmap " << file_.GetPlatformFile(); | 71 DPLOG(ERROR) << "mmap " << file_.GetPlatformFile(); |
| 71 return false; | 72 return false; |
| 72 } | 73 } |
| 73 | 74 |
| 74 data_ += data_offset; | 75 data_ += data_offset; |
| 75 return true; | 76 return true; |
| 76 } | 77 } |
| 78 #endif |
| 77 | 79 |
| 78 void MemoryMappedFile::CloseHandles() { | 80 void MemoryMappedFile::CloseHandles() { |
| 79 ThreadRestrictions::AssertIOAllowed(); | 81 ThreadRestrictions::AssertIOAllowed(); |
| 80 | 82 |
| 81 if (data_ != NULL) | 83 if (data_ != NULL) |
| 82 munmap(data_, length_); | 84 munmap(data_, length_); |
| 83 file_.Close(); | 85 file_.Close(); |
| 84 | 86 |
| 85 data_ = NULL; | 87 data_ = NULL; |
| 86 length_ = 0; | 88 length_ = 0; |
| 87 } | 89 } |
| 88 | 90 |
| 89 } // namespace base | 91 } // namespace base |
| OLD | NEW |