| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "crazy_linker_elf_loader.h" | 5 #include "crazy_linker_elf_loader.h" |
| 6 | 6 |
| 7 #include <limits.h> // For PAGE_SIZE and PAGE_MASK | 7 #include <limits.h> // For PAGE_SIZE and PAGE_MASK |
| 8 | 8 |
| 9 #include "crazy_linker_debug.h" | 9 #include "crazy_linker_debug.h" |
| 10 #include "linker_phdr.h" | 10 #include "linker_phdr.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // it overlaps an existing, possibly system, mapping. | 186 // it overlaps an existing, possibly system, mapping. |
| 187 bool ElfLoader::ReserveAddressSpace(Error* error) { | 187 bool ElfLoader::ReserveAddressSpace(Error* error) { |
| 188 ELF::Addr min_vaddr; | 188 ELF::Addr min_vaddr; |
| 189 load_size_ = | 189 load_size_ = |
| 190 phdr_table_get_load_size(phdr_table_, phdr_num_, &min_vaddr, NULL); | 190 phdr_table_get_load_size(phdr_table_, phdr_num_, &min_vaddr, NULL); |
| 191 if (load_size_ == 0) { | 191 if (load_size_ == 0) { |
| 192 error->Set("No loadable segments"); | 192 error->Set("No loadable segments"); |
| 193 return false; | 193 return false; |
| 194 } | 194 } |
| 195 | 195 |
| 196 uint8_t* addr = reinterpret_cast<uint8_t*>(min_vaddr); | 196 uint8_t* addr = NULL; |
| 197 int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS; | 197 int mmap_flags = MAP_PRIVATE | MAP_ANONYMOUS; |
| 198 | 198 |
| 199 // Support loading at a fixed address. | 199 // Support loading at a fixed address. |
| 200 if (wanted_load_address_) { | 200 if (wanted_load_address_) { |
| 201 addr = static_cast<uint8_t*>(wanted_load_address_); | 201 addr = static_cast<uint8_t*>(wanted_load_address_); |
| 202 } | 202 } |
| 203 | 203 |
| 204 LOG("%s: address=%p size=%p\n", __FUNCTION__, addr, load_size_); | 204 LOG("%s: address=%p size=%p\n", __FUNCTION__, addr, load_size_); |
| 205 void* start = mmap(addr, load_size_, PROT_NONE, mmap_flags, -1, 0); | 205 void* start = mmap(addr, load_size_, PROT_NONE, mmap_flags, -1, 0); |
| 206 if (start == MAP_FAILED) { | 206 if (start == MAP_FAILED) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (zeromap == MAP_FAILED) { | 340 if (zeromap == MAP_FAILED) { |
| 341 error->Format("Could not zero-fill gap: %s", strerror(errno)); | 341 error->Format("Could not zero-fill gap: %s", strerror(errno)); |
| 342 return false; | 342 return false; |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 return true; | 346 return true; |
| 347 } | 347 } |
| 348 | 348 |
| 349 } // namespace crazy | 349 } // namespace crazy |
| OLD | NEW |