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

Side by Side Diff: runtime/vm/virtual_memory_macos.cc

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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
« no previous file with comments | « runtime/vm/virtual_memory_linux.cc ('k') | runtime/vm/virtual_memory_win.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_MACOS) 6 #if defined(TARGET_OS_MACOS)
7 7
8 #include "vm/virtual_memory.h" 8 #include "vm/virtual_memory.h"
9 9
10 #include <sys/mman.h> // NOLINT 10 #include <sys/mman.h> // NOLINT
11 #include <unistd.h> // NOLINT 11 #include <unistd.h> // NOLINT
12 12
13 #include "platform/assert.h" 13 #include "platform/assert.h"
14 #include "platform/utils.h" 14 #include "platform/utils.h"
15 15
16 #include "vm/isolate.h" 16 #include "vm/isolate.h"
17 17
18 namespace dart { 18 namespace dart {
19 19
20 // standard MAP_FAILED causes "error: use of old-style cast" as it 20 // standard MAP_FAILED causes "error: use of old-style cast" as it
21 // defines MAP_FAILED as ((void *) -1) 21 // defines MAP_FAILED as ((void *) -1)
22 #undef MAP_FAILED 22 #undef MAP_FAILED
23 #define MAP_FAILED reinterpret_cast<void*>(-1) 23 #define MAP_FAILED reinterpret_cast<void*>(-1)
24 24
25 uword VirtualMemory::page_size_ = 0; 25 uword VirtualMemory::page_size_ = 0;
26 26
27 27
28 void VirtualMemory::InitOnce() { 28 void VirtualMemory::InitOnce() {
29 page_size_ = getpagesize(); 29 page_size_ = getpagesize();
30 } 30 }
31 31
32 32
33 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) { 33 VirtualMemory* VirtualMemory::ReserveInternal(intptr_t size) {
34 ASSERT((size & (PageSize() - 1)) == 0); 34 ASSERT((size & (PageSize() - 1)) == 0);
35 void* address = mmap(NULL, size, PROT_NONE, 35 void* address = mmap(NULL, size, PROT_NONE,
36 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, 36 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
37 -1, 0);
38 if (address == MAP_FAILED) { 37 if (address == MAP_FAILED) {
39 return NULL; 38 return NULL;
40 } 39 }
41 MemoryRegion region(address, size); 40 MemoryRegion region(address, size);
42 return new VirtualMemory(region); 41 return new VirtualMemory(region);
43 } 42 }
44 43
45 44
46 static void unmap(void* address, intptr_t size) { 45 static void unmap(void* address, intptr_t size) {
47 if (size == 0) { 46 if (size == 0) {
(...skipping 17 matching lines...) Expand all
65 unmap(address, size); 64 unmap(address, size);
66 return true; 65 return true;
67 } 66 }
68 67
69 68
70 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) { 69 bool VirtualMemory::Commit(uword addr, intptr_t size, bool executable) {
71 ASSERT(Contains(addr)); 70 ASSERT(Contains(addr));
72 ASSERT(Contains(addr + size) || (addr + size == end())); 71 ASSERT(Contains(addr + size) || (addr + size == end()));
73 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); 72 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0);
74 void* address = mmap(reinterpret_cast<void*>(addr), size, prot, 73 void* address = mmap(reinterpret_cast<void*>(addr), size, prot,
75 MAP_PRIVATE | MAP_ANON | MAP_FIXED, 74 MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
76 -1, 0);
77 if (address == MAP_FAILED) { 75 if (address == MAP_FAILED) {
78 return false; 76 return false;
79 } 77 }
80 return true; 78 return true;
81 } 79 }
82 80
83 81
84 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) { 82 bool VirtualMemory::Protect(void* address, intptr_t size, Protection mode) {
85 ASSERT(Thread::Current()->IsMutatorThread() || 83 ASSERT(Thread::Current()->IsMutatorThread() ||
86 Isolate::Current()->mutator_thread()->IsAtSafepoint()); 84 Isolate::Current()->mutator_thread()->IsAtSafepoint());
(...skipping 12 matching lines...) Expand all
99 prot = PROT_READ | PROT_WRITE; 97 prot = PROT_READ | PROT_WRITE;
100 break; 98 break;
101 case kReadExecute: 99 case kReadExecute:
102 prot = PROT_READ | PROT_EXEC; 100 prot = PROT_READ | PROT_EXEC;
103 break; 101 break;
104 case kReadWriteExecute: 102 case kReadWriteExecute:
105 prot = PROT_READ | PROT_WRITE | PROT_EXEC; 103 prot = PROT_READ | PROT_WRITE | PROT_EXEC;
106 break; 104 break;
107 } 105 }
108 return (mprotect(reinterpret_cast<void*>(page_address), 106 return (mprotect(reinterpret_cast<void*>(page_address),
109 end_address - page_address, 107 end_address - page_address, prot) == 0);
110 prot) == 0);
111 } 108 }
112 109
113 } // namespace dart 110 } // namespace dart
114 111
115 #endif // defined(TARGET_OS_MACOS) 112 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/vm/virtual_memory_linux.cc ('k') | runtime/vm/virtual_memory_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698