Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: base/mac/scoped_mach_vm.h

Issue 274193007: Back out r269483 and the line of fixes that followed it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/mac/scoped_mach_port.h ('k') | base/mac/scoped_mach_vm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
9 10
10 #include <algorithm> 11 #include <algorithm>
11 12
12 #include "base/base_export.h"
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #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
27 15
28 // Use ScopedMachVM to supervise ownership of pages in the current process 16 // Use ScopedMachVM to supervise ownership of pages in the current process
29 // through the Mach VM subsystem. Pages allocated with mach_vm_allocate can be 17 // through the Mach VM subsystem. Pages allocated with mach_vm_allocate can be
30 // released when exiting a scope with ScopedMachVM. 18 // released when exiting a scope with ScopedMachVM.
31 // 19 //
32 // The Mach VM subsystem operates on a page-by-page basis, and a single VM 20 // The Mach VM subsystem operates on a page-by-page basis, and a single VM
33 // allocation managed by a ScopedMachVM object may span multiple pages. As far 21 // allocation managed by a ScopedMachVM object may span multiple pages. As far
34 // as Mach is concerned, allocated pages may be deallocated individually. This 22 // as Mach is concerned, allocated pages may be deallocated individually. This
35 // is in contrast to higher-level allocators such as malloc, where the base 23 // is in contrast to higher-level allocators such as malloc, where the base
36 // address of an allocation implies the size of an allocated block. 24 // address of an allocation implies the size of an allocated block.
(...skipping 13 matching lines...) Expand all
50 // kern_return_t kr = 38 // kern_return_t kr =
51 // mach_vm_allocate(mach_task_self(), &address, size, VM_FLAGS_ANYWHERE); 39 // mach_vm_allocate(mach_task_self(), &address, size, VM_FLAGS_ANYWHERE);
52 // if (kr != KERN_SUCCESS) { 40 // if (kr != KERN_SUCCESS) {
53 // return false; 41 // return false;
54 // } 42 // }
55 // ScopedMachVM vm_owner(address, mach_vm_round_page(size)); 43 // ScopedMachVM vm_owner(address, mach_vm_round_page(size));
56 44
57 namespace base { 45 namespace base {
58 namespace mac { 46 namespace mac {
59 47
60 class BASE_EXPORT ScopedMachVM { 48 class ScopedMachVM {
61 public: 49 public:
62 explicit ScopedMachVM(mach_vm_address_t address = 0, mach_vm_size_t size = 0) 50 explicit ScopedMachVM(mach_vm_address_t address = 0, mach_vm_size_t size = 0)
63 : address_(address), 51 : address_(address),
64 size_(size) { 52 size_(size) {
65 DCHECK(address % PAGE_SIZE == 0); 53 DCHECK(address % PAGE_SIZE == 0);
66 DCHECK(size % PAGE_SIZE == 0); 54 DCHECK(size % PAGE_SIZE == 0);
67 } 55 }
68 56
69 ~ScopedMachVM() { 57 ~ScopedMachVM() {
70 if (size_) { 58 if (size_) {
(...skipping 24 matching lines...) Expand all
95 private: 83 private:
96 mach_vm_address_t address_; 84 mach_vm_address_t address_;
97 mach_vm_size_t size_; 85 mach_vm_size_t size_;
98 86
99 DISALLOW_COPY_AND_ASSIGN(ScopedMachVM); 87 DISALLOW_COPY_AND_ASSIGN(ScopedMachVM);
100 }; 88 };
101 89
102 } // namespace mac 90 } // namespace mac
103 } // namespace base 91 } // namespace base
104 92
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
111 #endif // BASE_MAC_SCOPED_MACH_VM_H_ 93 #endif // BASE_MAC_SCOPED_MACH_VM_H_
OLDNEW
« no previous file with comments | « base/mac/scoped_mach_port.h ('k') | base/mac/scoped_mach_vm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698