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

Side by Side Diff: src/base/platform/platform-posix.cc

Issue 2396433008: [wasm] Add guard regions to end of WebAssembly.Memory buffers (Closed)
Patch Set: Merging with master 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 | « src/base/platform/platform-linux.cc ('k') | src/base/platform/platform-win32.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 // Platform-specific code for POSIX goes here. This is not a platform on its 5 // Platform-specific code for POSIX goes here. This is not a platform on its
6 // own, but contains the parts which are the same across the POSIX platforms 6 // own, but contains the parts which are the same across the POSIX platforms
7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. 7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX.
8 8
9 #include <errno.h> 9 #include <errno.h>
10 #include <limits.h> 10 #include <limits.h>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return 16; 92 return 16;
93 #endif 93 #endif
94 } 94 }
95 95
96 96
97 intptr_t OS::CommitPageSize() { 97 intptr_t OS::CommitPageSize() {
98 static intptr_t page_size = getpagesize(); 98 static intptr_t page_size = getpagesize();
99 return page_size; 99 return page_size;
100 } 100 }
101 101
102 void* OS::AllocateGuarded(const size_t requested) {
103 size_t allocated = 0;
104 const bool is_executable = false;
105 void* mbase = OS::Allocate(requested, &allocated, is_executable);
106 if (allocated != requested) {
107 OS::Free(mbase, allocated);
108 return nullptr;
109 }
110 if (mbase == nullptr) {
111 return nullptr;
112 }
113 OS::Guard(mbase, requested);
114 return mbase;
115 }
102 116
103 void OS::Free(void* address, const size_t size) { 117 void OS::Free(void* address, const size_t size) {
104 // TODO(1240712): munmap has a return value which is ignored here. 118 // TODO(1240712): munmap has a return value which is ignored here.
105 int result = munmap(address, size); 119 int result = munmap(address, size);
106 USE(result); 120 USE(result);
107 DCHECK(result == 0); 121 DCHECK(result == 0);
108 } 122 }
109 123
110 124
111 // Get rid of writable permission on code allocations. 125 // Get rid of writable permission on code allocations.
(...skipping 10 matching lines...) Expand all
122 // Create guard pages. 136 // Create guard pages.
123 void OS::Guard(void* address, const size_t size) { 137 void OS::Guard(void* address, const size_t size) {
124 #if V8_OS_CYGWIN 138 #if V8_OS_CYGWIN
125 DWORD oldprotect; 139 DWORD oldprotect;
126 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect); 140 VirtualProtect(address, size, PAGE_NOACCESS, &oldprotect);
127 #else 141 #else
128 mprotect(address, size, PROT_NONE); 142 mprotect(address, size, PROT_NONE);
129 #endif 143 #endif
130 } 144 }
131 145
146 // Make a region of memory readable and writable.
147 void OS::Unprotect(void* address, const size_t size) {
148 #if V8_OS_CYGWIN
149 DWORD oldprotect;
150 VirtualProtect(address, size, PAGE_READWRITE, &oldprotect);
151 #else
152 mprotect(address, size, PROT_READ | PROT_WRITE);
153 #endif
154 }
132 155
133 static LazyInstance<RandomNumberGenerator>::type 156 static LazyInstance<RandomNumberGenerator>::type
134 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER; 157 platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
135 158
136 159
137 void OS::Initialize(int64_t random_seed, bool hard_abort, 160 void OS::Initialize(int64_t random_seed, bool hard_abort,
138 const char* const gc_fake_mmap) { 161 const char* const gc_fake_mmap) {
139 if (random_seed) { 162 if (random_seed) {
140 platform_random_number_generator.Pointer()->SetSeed(random_seed); 163 platform_random_number_generator.Pointer()->SetSeed(random_seed);
141 } 164 }
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 765
743 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 766 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
744 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 767 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
745 int result = pthread_setspecific(pthread_key, value); 768 int result = pthread_setspecific(pthread_key, value);
746 DCHECK_EQ(0, result); 769 DCHECK_EQ(0, result);
747 USE(result); 770 USE(result);
748 } 771 }
749 772
750 } // namespace base 773 } // namespace base
751 } // namespace v8 774 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/platform/platform-linux.cc ('k') | src/base/platform/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698