| OLD | NEW |
| 1 // Copyright (c) 2011, Google Inc. | 1 // Copyright (c) 2011, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Strangely file size can be negative, but we check above that it is not. | 80 // Strangely file size can be negative, but we check above that it is not. |
| 81 size_t file_len = static_cast<size_t>(st.st_size); | 81 size_t file_len = static_cast<size_t>(st.st_size); |
| 82 // If the file does not extend beyond the offset, simply use an empty | 82 // If the file does not extend beyond the offset, simply use an empty |
| 83 // MemoryRange and return true. Don't bother to call mmap() | 83 // MemoryRange and return true. Don't bother to call mmap() |
| 84 // even though mmap() can handle an empty file on some platforms. | 84 // even though mmap() can handle an empty file on some platforms. |
| 85 if (offset >= file_len) { | 85 if (offset >= file_len) { |
| 86 sys_close(fd); | 86 sys_close(fd); |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 #if defined(__x86_64__) || defined(__aarch64__) || \ | |
| 91 (defined(__mips__) && _MIPS_SIM == _ABI64) | |
| 92 void* data = sys_mmap(NULL, file_len, PROT_READ, MAP_PRIVATE, fd, offset); | 90 void* data = sys_mmap(NULL, file_len, PROT_READ, MAP_PRIVATE, fd, offset); |
| 93 #else | |
| 94 if ((offset & 4095) != 0) { | |
| 95 // Not page aligned. | |
| 96 sys_close(fd); | |
| 97 return false; | |
| 98 } | |
| 99 void* data = sys_mmap2( | |
| 100 NULL, file_len, PROT_READ, MAP_PRIVATE, fd, offset >> 12); | |
| 101 #endif | |
| 102 sys_close(fd); | 91 sys_close(fd); |
| 103 if (data == MAP_FAILED) { | 92 if (data == MAP_FAILED) { |
| 104 return false; | 93 return false; |
| 105 } | 94 } |
| 106 | 95 |
| 107 content_.Set(data, file_len - offset); | 96 content_.Set(data, file_len - offset); |
| 108 return true; | 97 return true; |
| 109 } | 98 } |
| 110 | 99 |
| 111 void MemoryMappedFile::Unmap() { | 100 void MemoryMappedFile::Unmap() { |
| 112 if (content_.data()) { | 101 if (content_.data()) { |
| 113 sys_munmap(const_cast<uint8_t*>(content_.data()), content_.length()); | 102 sys_munmap(const_cast<uint8_t*>(content_.data()), content_.length()); |
| 114 content_.Set(NULL, 0); | 103 content_.Set(NULL, 0); |
| 115 } | 104 } |
| 116 } | 105 } |
| 117 | 106 |
| 118 } // namespace google_breakpad | 107 } // namespace google_breakpad |
| OLD | NEW |