| 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 #ifndef BASE_MAC_SCOPED_MACH_VM_H_ | 5 #ifndef BASE_MAC_SCOPED_MACH_VM_H_ |
| 6 #define BASE_MAC_SCOPED_MACH_VM_H_ | 6 #define BASE_MAC_SCOPED_MACH_VM_H_ |
| 7 | 7 |
| 8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
| 9 #include <mach/mach_vm.h> | |
| 10 | 9 |
| 11 #include <algorithm> | 10 #include <algorithm> |
| 12 | 11 |
| 13 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 14 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 15 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "build/build_config.h" |
| 16 |
| 17 #if !defined(OS_IOS) |
| 18 #include <mach/mach_vm.h> |
| 19 #else // OS_IOS |
| 20 // mach_vm.h is forbidden on iOS, but the routines in vm_map.h are a suitable |
| 21 // substitute. |
| 22 #include <mach/vm_map.h> |
| 23 #define mach_vm_address_t vm_address_t |
| 24 #define mach_vm_size_t vm_size_t |
| 25 #define mach_vm_deallocate vm_deallocate |
| 26 #endif // OS_IOS |
| 16 | 27 |
| 17 // Use ScopedMachVM to supervise ownership of pages in the current process | 28 // Use ScopedMachVM to supervise ownership of pages in the current process |
| 18 // through the Mach VM subsystem. Pages allocated with mach_vm_allocate can be | 29 // through the Mach VM subsystem. Pages allocated with mach_vm_allocate can be |
| 19 // released when exiting a scope with ScopedMachVM. | 30 // released when exiting a scope with ScopedMachVM. |
| 20 // | 31 // |
| 21 // The Mach VM subsystem operates on a page-by-page basis, and a single VM | 32 // The Mach VM subsystem operates on a page-by-page basis, and a single VM |
| 22 // allocation managed by a ScopedMachVM object may span multiple pages. As far | 33 // allocation managed by a ScopedMachVM object may span multiple pages. As far |
| 23 // as Mach is concerned, allocated pages may be deallocated individually. This | 34 // as Mach is concerned, allocated pages may be deallocated individually. This |
| 24 // is in contrast to higher-level allocators such as malloc, where the base | 35 // is in contrast to higher-level allocators such as malloc, where the base |
| 25 // address of an allocation implies the size of an allocated block. | 36 // address of an allocation implies the size of an allocated block. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 private: | 95 private: |
| 85 mach_vm_address_t address_; | 96 mach_vm_address_t address_; |
| 86 mach_vm_size_t size_; | 97 mach_vm_size_t size_; |
| 87 | 98 |
| 88 DISALLOW_COPY_AND_ASSIGN(ScopedMachVM); | 99 DISALLOW_COPY_AND_ASSIGN(ScopedMachVM); |
| 89 }; | 100 }; |
| 90 | 101 |
| 91 } // namespace mac | 102 } // namespace mac |
| 92 } // namespace base | 103 } // namespace base |
| 93 | 104 |
| 105 #if defined(OS_IOS) |
| 106 #undef mach_vm_address_t |
| 107 #undef mach_vm_size_t |
| 108 #undef mach_vm_deallocate |
| 109 #endif // OS_IOS |
| 110 |
| 94 #endif // BASE_MAC_SCOPED_MACH_VM_H_ | 111 #endif // BASE_MAC_SCOPED_MACH_VM_H_ |
| OLD | NEW |