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

Side by Side Diff: src/platform-macos.cc

Issue 7352007: Add guard pages in front of platform allocations (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 5 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // tools like vmmap(1). 141 // tools like vmmap(1).
142 static const int kMmapFd = VM_MAKE_TAG(255); 142 static const int kMmapFd = VM_MAKE_TAG(255);
143 static const off_t kMmapFdOffset = 0; 143 static const off_t kMmapFdOffset = 0;
144 144
145 145
146 void* OS::Allocate(const size_t requested, 146 void* OS::Allocate(const size_t requested,
147 size_t* allocated, 147 size_t* allocated,
148 bool is_executable) { 148 bool is_executable) {
149 const size_t msize = RoundUp(requested, getpagesize()); 149 const size_t msize = RoundUp(requested, getpagesize());
150 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 150 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
151 void* mbase = mmap(NULL, msize, prot, 151 void* mbase = mmap(NULL, msize + Page::kPageSize, prot,
152 MAP_PRIVATE | MAP_ANON, 152 MAP_PRIVATE | MAP_ANON,
153 kMmapFd, kMmapFdOffset); 153 kMmapFd, kMmapFdOffset);
154 if (mbase == MAP_FAILED) { 154 if (mbase == MAP_FAILED) {
155 LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed")); 155 LOG(Isolate::Current(), StringEvent("OS::Allocate", "mmap failed"));
156 return NULL; 156 return NULL;
157 } 157 }
158 *allocated = msize; 158 *allocated = msize;
159 mprotect(mbase, Page::kPageSize, PROT_NONE);
160 mbase += Page::kPageSize;
159 UpdateAllocatedSpaceLimits(mbase, msize); 161 UpdateAllocatedSpaceLimits(mbase, msize);
160 return mbase; 162 return mbase;
161 } 163 }
162 164
163 165
164 void OS::Free(void* address, const size_t size) { 166 void OS::Free(void* address, const size_t size) {
165 // TODO(1240712): munmap has a return value which is ignored here. 167 // TODO(1240712): munmap has a return value which is ignored here.
166 int result = munmap(address, size); 168 int result = munmap(address - Page::kPageSize, size + Page::kPageSize);
167 USE(result); 169 USE(result);
168 ASSERT(result == 0); 170 ASSERT(result == 0);
169 } 171 }
170 172
171 173
172 #ifdef ENABLE_HEAP_PROTECTION 174 #ifdef ENABLE_HEAP_PROTECTION
173 175
174 void OS::Protect(void* address, size_t size) { 176 void OS::Protect(void* address, size_t size) {
175 UNIMPLEMENTED(); 177 UNIMPLEMENTED();
176 } 178 }
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 819
818 void Sampler::Stop() { 820 void Sampler::Stop() {
819 ASSERT(IsActive()); 821 ASSERT(IsActive());
820 SamplerThread::RemoveActiveSampler(this); 822 SamplerThread::RemoveActiveSampler(this);
821 SetActive(false); 823 SetActive(false);
822 } 824 }
823 825
824 #endif // ENABLE_LOGGING_AND_PROFILING 826 #endif // ENABLE_LOGGING_AND_PROFILING
825 827
826 } } // namespace v8::internal 828 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698