scoped_mach_vm.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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
  3. // found in the LICENSE file.
  4. #include "base/mac/scoped_mach_vm.h"
  5. #include "base/mac/mach_logging.h"
  6. namespace base::mac {
  7. void ScopedMachVM::reset(vm_address_t address, vm_size_t size) {
  8. DCHECK_EQ(address % PAGE_SIZE, 0u);
  9. DCHECK_EQ(size % PAGE_SIZE, 0u);
  10. reset_unaligned(address, size);
  11. }
  12. void ScopedMachVM::reset_unaligned(vm_address_t address, vm_size_t size) {
  13. if (size_) {
  14. if (address_ < address) {
  15. kern_return_t kr = vm_deallocate(mach_task_self(), address_,
  16. std::min(size_, address - address_));
  17. MACH_DCHECK(kr == KERN_SUCCESS, kr) << "vm_deallocate";
  18. }
  19. if (address_ + size_ > address + size) {
  20. vm_address_t deallocate_start = std::max(address_, address + size);
  21. kern_return_t kr = vm_deallocate(mach_task_self(), deallocate_start,
  22. address_ + size_ - deallocate_start);
  23. MACH_DCHECK(kr == KERN_SUCCESS, kr) << "vm_deallocate";
  24. }
  25. }
  26. address_ = address;
  27. size_ = size;
  28. }
  29. } // namespace base::mac